1 # (c) Yves Fischer yvesf - xapek org, 2007, License: GPL-2
5 from pgw
.Plugin
import SidebarPlugin
;
8 class ListBox(gtk
.ScrolledWindow
):
10 gtk
.ScrolledWindow
.__init
__(self
,ui
)
11 self
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
12 self
.set_shadow_type(gtk
.SHADOW_NONE
)
14 self
.store
= gtk
.ListStore(str)
15 self
.view
= gtk
.TreeView(self
.store
)
17 cell
= gtk
.CellRendererText()
18 column
= gtk
.TreeViewColumn("Functions")
19 column
.pack_start(cell
, True)
20 column
.add_attribute(cell
, 'text', 0)
21 column
.set_sort_column_id(0)
22 self
.view
.append_column(column
)
26 def set_array(self
, array
):
29 self
.store
.append(item
)
32 tuple, treeview
= self
.view
.get_cursor()
35 return self
.store
[tuple[0]]
37 class TextWidget(gtk
.ScrolledWindow
):
39 gtk
.ScrolledWindow
.__init
__(self
)
40 self
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_AUTOMATIC
)
41 self
.set_shadow_type(gtk
.SHADOW_NONE
)
43 self
.buffer = gtk
.TextBuffer()
44 self
.syntax
= pgw
.Syntax
.Syntax(self
.buffer)
46 self
.buffer.connect('delete-range', self
.syntax
.text_deleted
)
47 self
.buffer.connect('insert-text', self
.syntax
.text_inserted
)
48 self
.buffer.connect('changed', self
.syntax
.text_changed
)
50 self
.view
= gtk
.TextView(self
.buffer)
55 def set_text(self
, text
):
56 self
.buffer.set_text(text
)
58 return self
.buffer.get_text( \
59 self
.buffer.get_start_iter(), self
.buffer.get_end_iter() )
61 class FunctionBrowserPlugin(SidebarPlugin
):
62 name
= "Function Browser"
64 SidebarPlugin
.__init
__(self
)
65 self
.vpaned
= gtk
.VPaned()
67 self
.hcontainer
= gtk
.HBox()
69 self
.button
= gtk
.Button("Reload")
70 self
.button
.set_property("height-request", 30)
71 self
.button
.set_property("width-request", 50)
72 self
.button
.connect("clicked", self
.refresh
)
73 self
.hcontainer
.add(self
.button
)
75 self
.liststore
= gtk
.ListStore(str);
76 self
.combobox
= gtk
.ComboBox(self
.liststore
)
77 cell
= gtk
.CellRendererText()
78 self
.combobox
.pack_start(cell
, True)
79 self
.combobox
.add_attribute(cell
, 'text', 0)
81 self
.hcontainer
.add(self
.combobox
)
82 self
.liststore
.append(["asdf"]);
83 self
.liststore
.append(["asdf"]);
84 self
.liststore
.append(["asdf"]);
85 self
.liststore
.append(["asdf"]);
89 self
.pack_start(self
.hcontainer
, False, True)
90 self
.listbox
= ListBox()
91 self
.listbox
.view
.set_property("height-request", 200)
92 self
.vpaned
.pack1(self
.listbox
)
94 self
.text
= TextWidget()
95 self
.vpaned
.pack2(self
.text
)
99 self
.listbox
.view
.connect("cursor-changed", self
.cursor
)
104 def on_connection(self
):
107 def cursor(self
, widget
, data
=None):
108 name
= self
.listbox
.get()[0]
109 if not vars(self
.app
).has_key("db") or not self
.app
.db
.is_connected
:
110 print "FunctionBrowser: No Connection!"
112 query
= self
.app
.db
.query("SELECT prosrc AS sprache FROM pg_catalog.pg_proc WHERE proname = '%s'" %(name))
113 result
= query
['cursor'].fetchall()
114 self
.text
.set_text(result
[0][0])
116 def refresh(self
, widget
=None):
117 if not vars(self
.app
).has_key("db") or not self
.app
.db
.is_connected
:
119 self
.button
.set_relief( gtk
.RELIEF_NONE
)
122 sql
= """SELECT DISTINCT(lanname)
123 FROM pg_catalog.pg_language AS L, pg_catalog.pg_proc AS P
124 WHERE int4(L.lanplcallfoid)+1 = int4(P.prolang);"""
125 query
= self
.app
.db
.query(sql
);
127 results
= query
['cursor'].fetchall()
128 active
= self
.combobox
.get_active_text()
129 self
.liststore
.clear()
130 self
.liststore
.append([_("All")])
133 for result
in results
:
135 self
.liststore
.append([result
[0]])
136 if result
[0] == active
: #take-over old selection
140 print "FunctionBrowser: Error, unexpected result" + str(result
)
141 self
.combobox
.set_active(j
)
144 filter = self
.combobox
.get_active_text()
145 if filter == _("All") or filter == None:
147 sql
= """SELECT proname
148 FROM pg_catalog.pg_language AS L, pg_catalog.pg_proc AS P
150 int4(L.lanplcallfoid)+1 = int4(P.prolang)
151 AND L.lanname LIKE '%s';""" % filter
152 got
= self
.app
.db
.query(sql
)
153 cursor
= got
['cursor']
154 results
= cursor
.fetchall()
158 store
.append([line
[0]])
160 self
.listbox
.set_array(store
)
162 self
.button
.set_relief( gtk
.RELIEF_NORMAL
)
165 EXPORTS
=[FunctionBrowserPlugin
]