pygabriel-blogging / pygtkhelpers / source / main_win.py

from pygtkhelpers.delegates import WindowView,SlaveView
from collections import namedtuple
import gtk

# Menu section
class Menu(SlaveView):
    
    builder_file = "menu.glade"

    def __init__(self, parent):
        SlaveView.__init__(self)
        self.parent = parent

    def on_quit__activate(self,*a):
        self.parent.hide_and_quit()

    def on_sendfile__activate(self, *a):
        self.parent.send_file()

# Defining a user container
User = namedtuple("User", "name icon address port")

# UserList section
class UserList(SlaveView):

    def create_ui(self):
        model = gtk.ListStore(object)
        treeview = gtk.TreeView(model)
        treeview.set_name("User List")

        iconrend = gtk.CellRendererPixbuf()
        inforend = gtk.CellRendererText()

        iconcol = gtk.TreeViewColumn('Icon', iconrend)
        infocol = gtk.TreeViewColumn('Info', inforend)

        iconcol.set_cell_data_func(iconrend, self._icon_data)
        infocol.set_cell_data_func(inforend, self._info_data)

        treeview.append_column(iconcol)
        treeview.append_column(infocol)
        treeview.set_headers_visible(False)

        self.store = model
        self.treeview = treeview
        self.widget.add(treeview)

    def _icon_data(self, column, cell, model, iter):

        row = model[iter]
        user = row[0]
        cell.set_property("pixbuf",gtk.gdk.pixbuf_new_from_file(user.icon))

    def _info_data(self, column, cell, model, iter):

        row = model[iter]
        user = row[0]

        template = "<big><b>{user}</b></big>\n<small><i>{address}:{port}</i></small>"
        label = template.format(user=user.name,
                                address=user.address,
                                port=user.port)
        cell.set_property("markup",label)

    def add_user(self, user):

        self.store.append([user])

class Statusbar(SlaveView):
    def __init__(self, parent):
        self.parent = parent
        SlaveView.__init__(self)
        
    def create_ui(self):
        statusbar = gtk.StatusBar()
        self.widget.add(statusbar)

class FileSnakeGUI(WindowView):
    
    builder_file = "main_win.glade"
    
    def create_ui(self):
        self.userlist = UserList()
        
        self.add_slave("statusbar_cont", Statusbar())
        self.add_slave("menu_cont", Menu(self))
        self.add_slave("userlist_cont", self.userlist)
        
    def on_window1__delete_event(self, *a):
        self.hide_and_quit()

def test_run():
    fs = FileSnakeGUI()
    fs.show_and_run()

if __name__ == '__main__':
    test_run()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.