Skip to content

Instantly share code, notes, and snippets.

@ork
Created August 7, 2016 16:04
Show Gist options
  • Save ork/a849cd5fc18ef8792f7472822e5fe2fc to your computer and use it in GitHub Desktop.
Save ork/a849cd5fc18ef8792f7472822e5fe2fc to your computer and use it in GitHub Desktop.
Python Gtk3 Steam client
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GdkPixbuf, Gtk, Soup
import glob
class LocalSteam:
@property
def installed_games(self):
"""List of identifiers for installed games"""
for game in glob.glob('/home/ork/.local/share/Steam/steamapps/common/*/steam_appid.txt'):
with open(game, 'rb') as f:
yield int(f.readlines()[0])
def add_cb(source_object, res, flowbox):
data = source_object.send_finish(res)
pix = GdkPixbuf.Pixbuf.new_from_stream(data)
print(pix.get_width())
flowbox.add(Gtk.Image.new_from_pixbuf(pix))
flowbox.show_all()
class Cornichon:
handlers = {
"onDeleteWindow": Gtk.main_quit
}
def __init__(self):
self.session = Soup.Session()
self._build('interface.glade')
self.window.show_all()
Gtk.main()
def _build(self, interface_file):
builder = Gtk.Builder()
builder.add_from_file(interface_file)
builder.connect_signals(self.handlers)
self.window = builder.get_object('window')
self.flowbox = builder.get_object('flowbox')
for banner in glob.glob('banners/*'):
# self.flowbox.add(Gtk.Image.new_from_file(banner))
pass
steam = LocalSteam()
for game in steam.installed_games:
res = self.session.request_http('GET', "http://cdn.akamai.steamstatic.com/steam/apps/{}/header.jpg".format(game))
ins = res.send_async(callback=add_cb, user_data=self.flowbox)
if __name__ == '__main__':
Cornichon()
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Cornichon</property>
<signal name="destroy" handler="onDeleteWindow" swapped="no"/>
<child>
<object class="GtkFlowBox" id="flowbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
</object>
</child>
</object>
</interface>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment