basichttp server (забыл git add .)
[chanspy.git] / gui.shit / gui.py
blob900b84bd463c4db700406a57beb566841dfe4955
1 import pygtk
2 pygtk.require("2.0")
3 import gtk
4 import gtk.glade
6 import client
8 class GUI:
9 """GUI class. Processed all signals and get data via dbus from daemon."""
11 def __init__(self, path):
12 """Set starting gui parametrs and load some data -- chans and boards."""
14 self.wTree = gtk.glade.XML(path)
15 self.wTree.signal_autoconnect({ 'on_main_destroy': gtk.main_quit
16 , 'on_chans_view_cursor_changed': self.board_selected
17 , 'on_chans_view_row_activated': self.board_activated
20 # toolbar
21 toolbar = self.wTree.get_widget('toolbar')
22 bSettings = gtk.ToolButton(label='settings')
23 bSettings.show()
24 bExit = gtk.ToolButton(label='exit')
25 bExit.show()
26 bExit.connect('clicked', gtk.main_quit)
27 toolbar.insert(bSettings, 0)
28 toolbar.insert(bExit, 1)
30 # statusbar
31 self.statusbar = self.wTree.get_widget('statusbar')
32 self.statusbar.push(0, 'Stop.')
34 # chans_view
35 chans_view = self.wTree.get_widget('chans_view')
36 chans_tree = gtk.TreeStore(str)
37 tvcolumn = gtk.TreeViewColumn('Chans')
38 chans_view.append_column(tvcolumn)
39 cell = gtk.CellRendererText()
40 tvcolumn.pack_start(cell, True)
41 tvcolumn.add_attribute(cell, 'text', 0)
42 chans_view.set_model(chans_tree)
44 chans = client.get_chans()
45 for chan in chans:
46 parent = chans_tree.append(None, [chan])
47 boards = client.get_boards(chan)
48 for board in boards:
49 chans_tree.append(parent, [board])
51 # threads_view
52 threads_view = self.wTree.get_widget('threads_view')
53 self.threads_list = gtk.ListStore(str, str)
54 tvcolumn1 = gtk.TreeViewColumn('id')
55 tvcolumn2 = gtk.TreeViewColumn('name')
56 threads_view.append_column(tvcolumn1)
57 threads_view.append_column(tvcolumn2)
58 tvcolumn1.pack_start(cell, True)
59 tvcolumn2.pack_start(cell, True)
60 tvcolumn1.add_attribute(cell, 'text', 0)
61 tvcolumn2.add_attribute(cell, 'text', 0)
62 threads_view.set_model(self.threads_list)
64 def main(self):
65 """Starting gtk main loop."""
67 gtk.main()
69 def board_selected(self, treeview):
70 """Select board."""
72 model, path = treeview.get_selection().get_selected_rows()
73 self.board_activated(treeview, path[0], None, False)
75 def board_activated(self, treeview, path, view_column, refresh=True):
76 """Load threads list into threads_view then we clicked on board in chans_view."""
78 if len(path) == 2:
79 model = treeview.get_model()
80 chan_pos, board_pos = path
82 iter_chan = model.get_iter((chan_pos,))
83 chan = model.get_value(iter_chan, 0)
84 iter_board = model.get_iter(path)
85 board = model.get_value(iter_board, 0)
87 if refresh: client.refresh_board(chan, board)
88 threads = client.get_threads(chan, board)
90 self.threads_list.clear()
91 for thread in threads:
92 self.threads_list.append([thread, 'nyaa'])