Skip to content

Instantly share code, notes, and snippets.

@jacobmischka
Created August 15, 2015 01:17
Show Gist options
  • Save jacobmischka/c658d927848cd0b3b7d8 to your computer and use it in GitHub Desktop.
Save jacobmischka/c658d927848cd0b3b7d8 to your computer and use it in GitHub Desktop.
okay...
#!/usr/bin/python
from gi.repository import Gtk, GdkPixbuf
# this will be a twitter thing and objects will be created there of course
class Account():
def __init__(self, avatar, handle):
self.avatar = avatar
self.handle = handle
# other things
a1 = Account("./icon.png", "@alliepaca")
a2 = Account("./icon.png", "Another account")
class Tweet():
def __init__(self):
self.icon = GdkPixbuf.Pixbuf.new_from_file_at_size("./icon.png", 20,20)
self.name = "allie"
self.user = "@alliepaca"
self.message = "testing 1 2 3"
self.date = "00:44"
class SidebarTree(Gtk.TreeView):
def __init__(self):
Gtk.TreeView.__init__(self)
self.set_model(Gtk.TreeStore(GdkPixbuf.Pixbuf, str))
def add_account(self, account):
model = self.get_model()
icon = GdkPixbuf.Pixbuf.new_from_file_at_size(account.avatar, 20,20)
a = model.append(None, [icon, account.handle])
model.append(a, [None, "Timeline"])
model.append(a, [None, "Notifications"])
model.append(a, [None, "Messages"])
class AccountsColumn(Gtk.TreeViewColumn):
def __init__(self):
Gtk.TreeViewColumn.__init__(self, "Accounts")
accicon = Gtk.CellRendererPixbuf()
accounts = Gtk.CellRendererText()
self.pack_start(accicon, False)
self.pack_start(accounts, False)
self.add_attribute(accicon, "pixbuf", 0)
self.add_attribute(accounts, "text", 1)
class FromColumn(Gtk.TreeViewColumn):
def __init__(self):
Gtk.TreeViewColumn.__init__(self, "From")
r_icon = Gtk.CellRendererPixbuf()
r_from = Gtk.CellRendererText()
r_handle = Gtk.CellRendererText()
r_from.set_property("weight", 600)
r_handle.set_property("foreground", "#A0A0A0")
self.pack_start(r_icon, False)
self.pack_start(r_from, False)
self.pack_start(r_handle, False)
self.add_attribute(r_icon, "pixbuf", 0)
self.add_attribute(r_from, "text", 1)
self.add_attribute(r_handle, "text", 2)
class MessageColumn(Gtk.TreeViewColumn):
def __init__(self):
Gtk.TreeViewColumn.__init__(self, "Message")
self.set_expand(True)
r_text = Gtk.CellRendererText()
#r_text.set_property("yalign", 0)
self.pack_start(r_text, True)
self.add_attribute(r_text, "text", 3)
class TimeColumn(Gtk.TreeViewColumn):
def __init__(self):
Gtk.TreeViewColumn.__init__(self, "Time")
r_time = Gtk.CellRendererText()
#r_time.set_property("yalign", 0)
self.pack_start(r_time, True)
self.add_attribute(r_time, "text", 4)
class TweetsTree(Gtk.TreeView):
def __init__(self):
Gtk.TreeView.__init__(self)
self.set_model(Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, str, str))
self.set_rules_hint(True)
def add_tweet(self, tweet):
model = self.get_model()
model.prepend([tweet.icon, tweet.name, tweet.user, tweet.message, tweet.date])
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="bird")
self.connect("delete-event", Gtk.main_quit)
self.set_default_size(1280, 720)
# Horizontal splitter
self.main_pane = Gtk.Paned()
self.main_pane.set_orientation(Gtk.Orientation.HORIZONTAL)
self.main_pane.set_position(200)
self.add(self.main_pane)
# Vertical splitter
self.secondary_pane = Gtk.Paned()
self.secondary_pane.set_orientation(Gtk.Orientation.VERTICAL)
self.secondary_pane.set_position(300)
self.main_pane.add2(self.secondary_pane)
# Sidebar tree
self.sidebar = SidebarTree()
self.sidebar.add_account(a1)
self.sidebar.add_account(a2)
self.main_pane.add1(self.sidebar)
self.sidebar.append_column(AccountsColumn())
self.sidebar.expand_all()
# Main tweet list
self.tweets = TweetsTree()
self.secondary_pane.add(self.tweets)
self.tweets.append_column(FromColumn())
self.tweets.append_column(MessageColumn())
self.tweets.append_column(TimeColumn())
def add_tweet(self, tweet):
self.tweets_store.prepend([tweet.icon, tweet.name, tweet.user, tweet.message, tweet.date])
class Tweet():
def __init__(self):
self.icon = GdkPixbuf.Pixbuf.new_from_file_at_size("./icon.png", 20,20)
self.name = "allie"
self.user = "@alliepaca"
self.message = "testing 1 2 3"
self.date = "00:44"
win = MainWindow()
win.show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment