pgconsole/app.py
changeset 76 3a41b351b122
parent 11 bc69eca59041
--- a/pgconsole/app.py	Thu Mar 07 18:26:52 2013 +0100
+++ b/pgconsole/app.py	Sun Mar 10 16:14:53 2013 +0100
@@ -1,11 +1,15 @@
-import time
-import gobject, gtk, pango, cairo
-import gtksourceview2 as gtksourceview
+from gi.repository import GObject
+from gi.repository import Gtk, Gdk
+from gi.repository import GdkPixbuf
+from gi.repository import cairo, Pango
+from gi.repository import GtkSource
 
 import psycopg2
 import psycopg2.extensions
 import psycopg2.extras
 
+import time
+
 from pgconsole.config import cfg
 from pgconsole.editor import Editor
 from pgconsole.dataview import DataView
@@ -19,7 +23,7 @@
         self.db = Database()
         self.conn = None
 
-        win = gtk.Window(gtk.WINDOW_TOPLEVEL)
+        win = Gtk.Window()
         self.win = win
         win.set_title('PostgreSQL Console')
         win.set_size_request(300, 200)  # minimal size
@@ -30,18 +34,18 @@
         win.connect('configure-event', self.on_configure)
 
         # toolbar
-        toolbar = gtk.Toolbar()
-        toolbar.set_style(gtk.TOOLBAR_ICONS)
-        toolbar.set_property("icon-size", gtk.ICON_SIZE_SMALL_TOOLBAR)
+        toolbar = Gtk.Toolbar()
+        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
+        toolbar.set_property("icon-size", Gtk.IconSize.SMALL_TOOLBAR)
 
-        tb = gtk.ToolButton(gtk.STOCK_PREFERENCES)
+        tb = Gtk.ToolButton(Gtk.STOCK_PREFERENCES)
         tb.set_label('Settings')
         tb.set_tooltip_text('Settings')
         tb.connect('clicked', self.settings)
         self.tb_settings = tb
         toolbar.add(tb)
 
-        self.cb_server = gtk.combo_box_entry_new_text()
+        self.cb_server = Gtk.ComboBoxText.new_with_entry()
         self.cb_server.set_tooltip_text('Server')
         self.cb_server.get_child().set_property("editable", False)
         self.cb_server.set_property("add_tearoffs", True)
@@ -49,52 +53,52 @@
         self.cb_server.set_property("can-focus", True)
         self.cb_server.connect('changed', self.on_server_changed)
         self.cb_server.connect("key_press_event", self.toolbar_server_keypress)
-        ti = gtk.ToolItem()
+        ti = Gtk.ToolItem()
         ti.add(self.cb_server)
         toolbar.add(ti)
 
-        self.cb_dbname = gtk.combo_box_entry_new_text()
+        self.cb_dbname = Gtk.ComboBoxText.new_with_entry()
         self.cb_dbname.set_tooltip_text('Database')
         self.cb_dbname.get_child().set_property("editable", False)
         self.cb_dbname.set_property("add_tearoffs", True)
         #self.cb_dbname.set_property("focus-on-click", False)
         self.cb_dbname.set_property("can-focus", True)
-        ti = gtk.ToolItem()
+        ti = Gtk.ToolItem()
         ti.add(self.cb_dbname)
         toolbar.add(ti)
 
-        tb = gtk.ToolButton(gtk.STOCK_CONNECT)
+        tb = Gtk.ToolButton(Gtk.STOCK_CONNECT)
         tb.set_label('Connect')
         tb.set_tooltip_text('Connect')
         tb.connect('clicked', self.connect)
         toolbar.add(tb)
         self.tb_connect = tb
 
-        sep = gtk.SeparatorToolItem()
+        sep = Gtk.SeparatorToolItem()
         toolbar.add(sep)
 
-        tb = gtk.ToolButton(gtk.STOCK_EXECUTE)
+        tb = Gtk.ToolButton(Gtk.STOCK_EXECUTE)
         tb.set_label('Execute')
         tb.set_tooltip_text('Execute')
         tb.connect('clicked', self.execute)
         toolbar.add(tb)
         tb.set_sensitive(False)
         self.tb_execute = tb
-        tb = gtk.ToolButton(gtk.STOCK_NEW)
+        tb = Gtk.ToolButton(Gtk.STOCK_NEW)
         tb.set_label('Begin transaction')
         tb.set_tooltip_text('Begin transaction')
         tb.connect('clicked', self.begin)
         tb.set_sensitive(False)
         toolbar.add(tb)
         self.tb_begin = tb
-        tb = gtk.ToolButton(gtk.STOCK_APPLY)
+        tb = Gtk.ToolButton(Gtk.STOCK_APPLY)
         tb.set_label('Commit')
         tb.set_tooltip_text('Commit')
         tb.connect('clicked', self.commit)
         tb.set_sensitive(False)
         self.tb_commit = tb
         toolbar.add(tb)
-        tb = gtk.ToolButton(gtk.STOCK_CANCEL)
+        tb = Gtk.ToolButton(Gtk.STOCK_CANCEL)
         tb.set_label('Rollback')
         tb.set_tooltip_text('Rollback')
         tb.connect('clicked', self.rollback)
@@ -102,7 +106,7 @@
         self.tb_rollback = tb
         toolbar.add(tb)
 
-        sep = gtk.SeparatorToolItem()
+        sep = Gtk.SeparatorToolItem()
         toolbar.add(sep)
 
         # editor
@@ -112,19 +116,19 @@
         self.dataview = DataView()
 
 
-        vbox = gtk.VBox(False, 2)
+        vbox = Gtk.VBox(False, 2)
 
-        sep = gtk.SeparatorToolItem()
+        sep = Gtk.SeparatorToolItem()
         sep.set_expand(True)
         sep.set_draw(False)
         toolbar.add(sep)
 
-        self.throbber_anim = gtk.gdk.PixbufAnimation('data/Throbber.gif')
-        self.throbber = gtk.Image()
-        tb = gtk.ToolItem()
+        self.throbber_anim = GdkPixbuf.PixbufAnimation.new_from_file('data/Throbber.gif')
+        self.throbber = Gtk.Image()
+        tb = Gtk.ToolItem()
         tb.add(self.throbber)
         toolbar.add(tb)
-        sep = gtk.SeparatorToolItem()
+        sep = Gtk.SeparatorToolItem()
         sep.set_draw(False)
         toolbar.add(sep)
 
@@ -151,20 +155,20 @@
         self.hpaned = hpaned
 
         # log
-        self.logbuf = gtk.TextBuffer()
-        view = gtk.TextView(self.logbuf)
+        self.logbuf = Gtk.TextBuffer()
+        view = Gtk.TextView.new_with_buffer(self.logbuf)
         view.set_editable(False)
-        font_desc = pango.FontDescription('monospace')
+        font_desc = Pango.FontDescription('monospace')
         if font_desc:
             view.modify_font(font_desc)
 
-        sw = gtk.ScrolledWindow()
-        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
-        sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
+        sw = Gtk.ScrolledWindow()
+        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
         sw.add(view)
         hpaned.add2(sw)
 
-        vbox.pack_start(vpaned, padding=0)
+        vbox.pack_start(vpaned, expand=True, fill=True, padding=0)
 
         win.add(vbox)
 
@@ -178,13 +182,13 @@
 
 
     def main(self):
-        gtk.main()
+        Gtk.main()
 
 
     def destroy(self, widget, data=None):
         self.save_win_state()
         cfg.save()
-        gtk.main_quit()
+        Gtk.main_quit()
 
 
     def on_configure(self, w, ev):
@@ -251,7 +255,7 @@
             self.conn = None
             self.cb_server.set_sensitive(True)
             self.cb_dbname.set_sensitive(True)
-            self.tb_connect.set_stock_id(gtk.STOCK_CONNECT)
+            self.tb_connect.set_stock_id(Gtk.STOCK_CONNECT)
             self.tb_connect.set_label('Connect')
             self.tb_connect.set_tooltip_text('Connect')
             self.tb_execute.set_sensitive(False)
@@ -266,7 +270,7 @@
                 return
             self.cb_server.set_sensitive(False)
             self.cb_dbname.set_sensitive(False)
-            self.tb_connect.set_stock_id(gtk.STOCK_DISCONNECT)
+            self.tb_connect.set_stock_id(Gtk.STOCK_DISCONNECT)
             self.tb_connect.set_label('Disconnect')
             self.tb_connect.set_tooltip_text('Disconnect')
             self.tb_execute.set_sensitive(True)
@@ -341,9 +345,9 @@
         if state == psycopg2.extensions.POLL_OK:
             self.execute_finish()
         elif state == psycopg2.extensions.POLL_WRITE:
-            gobject.io_add_watch(self.conn.fileno(), gobject.IO_OUT, self.execute_poll)
+            GObject.io_add_watch(self.conn.fileno(), GObject.IO_OUT, self.execute_poll)
         elif state == psycopg2.extensions.POLL_READ:
-            gobject.io_add_watch(self.conn.fileno(), gobject.IO_IN, self.execute_poll)
+            GObject.io_add_watch(self.conn.fileno(), GObject.IO_IN, self.execute_poll)
         else:
             self.logbuf.insert(self.logbuf.get_end_iter(), "poll() returned %s" % state)
             return
@@ -388,7 +392,7 @@
 
 
     def keypress(self, w, event):
-        keyname = gtk.gdk.keyval_name(event.keyval)
+        keyname = Gdk.keyval_name(event.keyval)
         if keyname == 'F1':
             self.simulate_click(self.tb_settings)
             return True
@@ -418,7 +422,7 @@
 
 
     def toolbar_server_keypress(self, w, event):
-        keyname = gtk.gdk.keyval_name(event.keyval)
+        keyname = Gdk.keyval_name(event.keyval)
         if keyname == 'Tab':
             self.populate_db_list()
             self.cb_dbname.grab_focus()
@@ -446,7 +450,7 @@
         self.db.put_conn(conninfo, conn)
 
         for i in range(self.cb_dbname.get_model().iter_n_children(None)):
-            self.cb_dbname.remove_text(0)
+            self.cb_dbname.remove(0)
 
         for row in rows:
             self.cb_dbname.append_text(row[0])
@@ -457,7 +461,7 @@
     def reload_server_list(self, sel=None):
         # clean
         for i in range(self.cb_server.get_model().iter_n_children(None)):
-            self.cb_server.remove_text(0)
+            self.cb_server.remove(0)
         self.cb_server.get_child().set_text('')
 
         try: