11 class ListBox(gtk
.ScrolledWindow
):
12 def __init__(self
, store
=None):
13 gtk
.ScrolledWindow
.__init
__(self
)
14 self
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
15 self
.set_shadow_type(gtk
.SHADOW_NONE
)
20 self
.store
= gtk
.ListStore(str)
21 self
.view
= gtk
.TreeView(self
.store
)
23 cell
= gtk
.CellRendererText()
24 column
= gtk
.TreeViewColumn(_('Ansicht'))
25 column
.pack_start(cell
, True)
26 column
.add_attribute(cell
, 'text', 0)
27 column
.set_sort_column_id(0)
28 self
.view
.append_column(column
)
32 def set_array(self
, array
):
35 self
.store
.append(item
)
38 tuple, treeview
= self
.view
.get_cursor()
41 return self
.store
[tuple[0]]
45 class ResultViewTable(pgw
.Plugin
.ResultViewPlugin
):
46 name
= _('Tabellenansicht')
47 def __init__(self
, ui
, result
):
48 pgw
.Plugin
.ResultViewPlugin
.__init
__(self
, ui
, result
)
50 sql
= result
.sql
.strip()
51 scroll
= gtk
.ScrolledWindow()
57 cell
= gtk
.CellRendererText()
59 for col
in result
.description
:
60 column
= gtk
.TreeViewColumn(string
.replace(col
.name
, "_", "__"))
61 column
.pack_start(cell
, True)
62 column
.add_attribute(cell
, 'text', ncol
)
63 column
.set_sort_column_id(ncol
)
64 tvw
.append_column(column
)
69 type_str
= type_str
+ ",str"
71 # dynamically create the liststore, crazy
72 code
= "liststore = gtk.ListStore(" + type_str
+ ")"
74 exec compile(code
, "<string>", 'exec')
76 for row
in result
.rows
:
84 tvw
.set_model(liststore
)
85 tvw
.set_reorderable(True)
86 tvw
.columns_autosize()
92 cell
= gtk
.CellRendererText()
94 for col
in self
.result
.description
:
95 column
= gtk
.TreeViewColumn(string
.replace(col
.name
, "_", "__"))
96 column
.pack_start(cell
, True)
97 column
.add_attribute(cell
, 'text', ncol
)
98 column
.set_sort_column_id(ncol
)
99 tvw
.append_column(column
)
104 type_str
= type_str
+ ",str"
106 # dynamically create the liststore, crazy
107 code
= "liststore = gtk.ListStore(" + type_str
+ ")"
109 exec compile(code
, "<string>", 'exec')
111 for row
in self
.result
.rows
:
117 liststore
.append(row
)
119 tvw
.set_model(liststore
)
120 tvw
.set_reorderable(True)
121 tvw
.columns_autosize()
125 class GObjectContainer(gobject
.GObject
):
126 def __init__(self
, data
):
127 gobject
.GObject
.__init
__(self
)
128 self
.set_data("key", data
)
131 return self
.get_data("key")
134 self
.set_data("key", data
)
137 class ResultViewPluginContainer(gtk
.HPaned
):
138 def __init__(self
,app
, result
):
139 gtk
.HPaned
.__init
__(self
)
142 self
.is_persistent
= False
143 self
.plugins
= [ResultViewTable
]
144 for plugin
in pgw
.Plugin
.fromPath(sys
.path
[0] + "/plugins/", pgw
.Plugin
.ResultViewPlugin
):
145 self
.plugins
.append(plugin
)
147 self
.listbox
= ListBox(gtk
.ListStore(str,GObjectContainer
))
149 for plugin
in self
.plugins
:
150 data
.append([plugin
.name
, GObjectContainer(plugin
)])
151 self
.listbox
.set_array(data
)
152 self
.listbox
.view
.set_property("width-request", 170)
153 self
.listbox
.view
.connect("cursor-changed", self
.set_plugin
)
155 self
.persistent
= gtk
.CheckButton(_('Persistent'))
156 self
.persistent
.connect("clicked", self
.sig_set_persistense
)
157 self
.persistent
.set_property("height-request", 30)
159 self
.suicide
= gtk
.Button(_('Close'))
160 self
.suicide
.connect("clicked", self
.remove_myself
)
161 self
.suicide
.set_property("height-request", 30)
163 self
.vbox_hbox
= gtk
.HBox()
164 self
.vbox_hbox
.add(self
.persistent
)
165 self
.vbox_hbox
.add(self
.suicide
)
167 self
.vbox
= gtk
.VBox()
168 self
.vbox
.pack_start(self
.vbox_hbox
, False, False)
169 self
.vbox
.pack_start(self
.listbox
, True, True)
171 self
.pack2(self
.vbox
, False, True)
176 self
.set_plugin() #set default plugin
178 def remove_myself(self
, widget
=None):
179 self
.parent
.remove(self
)
181 def sig_set_persistense(self
, widget
=None):
182 self
.is_persistent
= self
.persistent
.get_property("active")
184 def set_plugin(self
, widget
=None):
185 print str(self
) + "set_plugin"
186 tuple, tvw
= self
.listbox
.view
.get_cursor()
187 if tuple == None: #nothin selected
188 tuple = (0,) #select 0
189 plugin_class
= self
.listbox
.store
[tuple[0]][1].get()
191 if plugin_class
== None: #Plugin is in ListBox but not registered, should never happen
192 print "plugin_class == None"
193 raise Exception("plugin_class should contain a plugin and not None")
195 oldchild
= self
.get_child1()
197 self
.remove(oldchild
)
199 self
.plugin
= plugin_class(self
.app
, self
.result
)
200 self
.pack1(self
.plugin
, resize
=True, shrink
=True)
202 class CloseLabel(gtk
.HBox
):
203 def __init__(self
, widget
, caption
):
204 gtk
.HBox
.__init
__(self
)
207 self
.label
= gtk
.Label(_('No Title'))
208 if type(caption
) == str:
209 self
.label
.set_text(caption
)
210 elif type(caption
) == gtk
.Label
:
211 self
.label
.set_text(caption
.get_text())
213 self
.label
.set_property("height-request", 20)
216 self
.button
= gtk
.Button("x")
217 self
.button
.connect("clicked", self
.on_button_close
)
218 self
.button
.set_property("height-request", 25)
220 self
.add(self
.button
)
223 def on_button_close(self
, widget
=None):
224 self
.parent
.remove(self
.page
)
227 class ResultView(gtk
.Notebook
):
228 def __init__(self
, app
):
229 gtk
.Notebook
.__init
__(self
)
231 # self.connect("page-added", self.check_hiding)
232 # self.connect("page-removed", self.check_hiding)
235 def check_hiding(self
, notebook
=None, child
=None, page_num
=None):
236 print self
.get_n_pages()
237 if self
.get_n_pages() == 0:
242 def add_results(self
, result
):
243 new_page
= ResultViewPluginContainer(self
.app
, result
)
244 self
.append_page(new_page
, None)
245 n
=self
.page_num(new_page
) + 1
246 sql
= result
.sql
.strip()
247 title
= "%d: %s"%(n
, sql
)
248 self
.set_tab_label(new_page
, CloseLabel(new_page
, title
))
251 def add_widget(self
, widget
, label
=None):
253 label
= _('No Title')
254 self
.append_page(widget
, CloseLabel(widget
,label
))
256 def add_error(self
, msg
, title
=None):
259 scroll
= gtk
.ScrolledWindow()
261 txt
.get_buffer().set_text(unicode(msg
, pgw
.get_user_encoding()))
262 pgw
.set_proportional(txt
.get_buffer())
263 txt
.set_editable(False)
270 scroll
.is_persistent
= False
272 def anon_closure(widget
=None):
274 button_close
= gtk
.Button("Close")
275 button_close
.connect("clicked", anon_closure
)
278 box
.add(button_close
)
279 self
.append_page(box
, CloseLabel(box
, title
))
281 def append_page(self
, widget
, label
):
282 gtk
.Notebook
.append_page(self
, widget
, label
)
283 n
= self
.page_num(widget
)
284 self
.set_current_page(n
)
287 for child
in self
.get_children():
288 if not child
.is_persistent
: