del net-oscar
[learning-git.git] / pgworksheet_yvesf / plugins / sidebar / ShowConfig.py
blobfc3bd602e1a1b310e352eb0b2de92060b1d4e207
1 # (c) Yves Fischer yvesf - xapek org, 2007, License: GPL-2
4 import pygtk;
5 import gtk;
6 from pgw.Plugin import SidebarPlugin;
8 class ShowConfigPlugin(SidebarPlugin):
9 name = "Configuration"
10 def __init__(self, ui):
11 SidebarPlugin.__init__(self, ui)
13 self.vbox = gtk.VBox()
14 self.button = gtk.Button("Reload")
15 self.button.set_property("height-request", 30)
16 self.vbox.pack_start(self.button, expand=False, fill=True, padding=0)
18 self.scroll = gtk.ScrolledWindow()
20 self.table = gtk.Table(rows=1, columns=2, homogeneous=True)
22 self.scroll.add_with_viewport(self.table)
24 self.vbox.add(self.scroll)
26 self.add(self.vbox)
28 self.button.connect("clicked", self.button_pressed)
30 def on_init(self):
31 pass
33 def on_connection(self):
34 self.button_pressed(None)
36 def clear_table(self, widget, data=None):
37 self.table.remove(widget)
39 def button_pressed(self, button, Data=None):
40 #SHOW ALL
41 if self.db.is_connected():
42 print "connected"
43 cursor = self.db.query("SHOW ALL")['cursor']
44 if not cursor:
45 print "cursor == None"
46 return
47 ret = cursor.fetchall()
49 #tabelle loeschen
50 self.table.foreach(self.clear_table)
52 print len(ret)
53 self.table.resize(rows=len(ret), columns=2)
55 n=0
56 for line in ret:
57 self.table.attach(self.get_cell(line[0]), \
58 left_attach=0, right_attach=1, \
59 top_attach=n, bottom_attach=n+1, \
60 ) #xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
62 self.table.attach(self.get_cell(line[1]), \
63 left_attach=1, right_attach=2, \
64 top_attach=n, bottom_attach=n+1, \
65 ) #xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
66 n += 1
67 self.table.show_all()
68 else:
69 self.table.foreach(self.clear_table)
70 self.table.resize(1,2)
71 self.table.attach(self.get_cell("Not Connected"), \
72 left_attach=0, right_attach=2, \
73 top_attach=0, bottom_attach=1,)
74 self.table.show_all()
76 def get_cell(self, caption):
77 hbox = gtk.HBox()
78 label = gtk.Label(caption)
79 label.set_property("justify", gtk.JUSTIFY_LEFT)
80 hbox.pack_start(label, expand=False)
81 return hbox
85 EXPORTS=[ShowConfigPlugin]