pgconsole/settings.py
changeset 76 3a41b351b122
parent 10 f3a1b9792cc9
--- a/pgconsole/settings.py	Thu Mar 07 18:26:52 2013 +0100
+++ b/pgconsole/settings.py	Sun Mar 10 16:14:53 2013 +0100
@@ -1,44 +1,45 @@
-import gtk
+from gi.repository import Gtk
+from gi.repository import Gdk
 
-from config import cfg
+from pgconsole.config import cfg
 
 
-class Settings(gtk.Window):
+class Settings(Gtk.Window):
     def __init__(self, parent):
-        super(Settings, self).__init__(gtk.WINDOW_TOPLEVEL)
+        super(Settings, self).__init__()
 
         self._parent = parent
 
         self.set_title('Settings')
         self.set_modal(True)
         self.set_transient_for(parent.win)
-        self.set_position(gtk.WIN_POS_CENTER)
+        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
         #self.set_border_width(10)
         self.connect("key_press_event", self.on_keypress)
         self.connect("destroy", self.on_destroy)
 
-        self.tabs = gtk.Notebook()
+        self.tabs = Gtk.Notebook()
         self.add(self.tabs)
 
         ### Servers
-        vbox = gtk.VBox(spacing=10)
+        vbox = Gtk.VBox(spacing=10)
         vbox.set_border_width(10)
-        self.tabs.append_page(vbox, gtk.Label('Servers'))
+        self.tabs.append_page(vbox, Gtk.Label('Servers'))
 
-        hbox = gtk.HBox(spacing=10)
-        vbox.pack_start(hbox)
-        sw = gtk.ScrolledWindow()
-        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
-        sw.set_shadow_type(gtk.SHADOW_IN)
-        hbox.pack_start(sw)
-        tree = gtk.TreeView()
+        hbox = Gtk.HBox(spacing=10)
+        vbox.pack_start(hbox, expand=True, fill=True, padding=0)
+        sw = Gtk.ScrolledWindow()
+        sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+        sw.set_shadow_type(Gtk.ShadowType.IN)
+        hbox.pack_start(sw, expand=True, fill=True, padding=0)
+        tree = Gtk.TreeView()
         tree.set_headers_visible(False)
         sw.add(tree)
-        tree.get_selection().set_mode(gtk.SELECTION_BROWSE)
+        tree.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
 
-        model = gtk.ListStore(str, object)
+        model = Gtk.ListStore(str, object)
         tree.set_model(model)
-        column = gtk.TreeViewColumn("Server", gtk.CellRendererText(), text=0)
+        column = Gtk.TreeViewColumn("Server", Gtk.CellRendererText(), text=0)
         tree.append_column(column)
         tree.get_selection().connect('changed', self.item_change)
         tree.set_size_request(100, -1)
@@ -55,69 +56,69 @@
 
         self.itemtree = tree
 
-        vbox = gtk.VBox(spacing=10)
-        hbox.pack_start(vbox)
+        vbox = Gtk.VBox(spacing=10)
+        hbox.pack_start(vbox, expand=True, fill=True, padding=0)
 
-        table = gtk.Table(5, 2)
+        table = Gtk.Table(5, 2)
         table.set_row_spacings(4)
         table.set_col_spacings(10)
-        vbox.pack_start(table)
+        vbox.pack_start(table, expand=True, fill=True, padding=0)
 
-        label = gtk.Label("Name:")
+        label = Gtk.Label("Name:")
         label.set_alignment(0.0, 0.5)
         table.attach(label, 0, 1, 0, 1)
-        entry = gtk.Entry()
+        entry = Gtk.Entry()
         table.attach(entry, 1, 2, 0, 1)
         self.entry_name = entry
 
-        label = gtk.Label("Host:")
+        label = Gtk.Label("Host:")
         label.set_alignment(0.0, 0.5)
         table.attach(label, 0, 1, 1, 2)
-        entry = gtk.Entry()
+        entry = Gtk.Entry()
         entry.set_text('127.0.0.1')
         table.attach(entry, 1, 2, 1, 2)
         self.entry_host = entry
 
-        label = gtk.Label("Port:")
+        label = Gtk.Label("Port:")
         label.set_alignment(0.0, 0.5)
         table.attach(label, 0, 1, 2, 3)
-        entry = gtk.Entry()
+        entry = Gtk.Entry()
         entry.set_text('5432')
         table.attach(entry, 1, 2, 2, 3)
         self.entry_port = entry
 
-        label = gtk.Label("User:")
+        label = Gtk.Label("User:")
         label.set_alignment(0.0, 0.5)
         table.attach(label, 0, 1, 3, 4)
-        entry = gtk.Entry()
+        entry = Gtk.Entry()
         entry.set_text('postgres')
         table.attach(entry, 1, 2, 3, 4)
         self.entry_user = entry
 
-        label = gtk.Label("Password:")
+        label = Gtk.Label("Password:")
         label.set_alignment(0.0, 0.5)
         table.attach(label, 0, 1, 4, 5)
-        entry = gtk.Entry()
+        entry = Gtk.Entry()
         table.attach(entry, 1, 2, 4, 5)
         self.entry_password = entry
 
-        hbox = gtk.HBox()
-        vbox.pack_start(hbox)
+        hbox = Gtk.HBox()
+        vbox.pack_start(hbox, expand=True, fill=True, padding=0)
 
-        btn = gtk.Button('Add')
+        btn = Gtk.Button('Add')
         btn.connect('clicked', self.item_add)
-        hbox.pack_start(btn)
-        btn = gtk.Button('Save')
+        hbox.pack_start(btn, expand=True, fill=True, padding=0)
+        btn = Gtk.Button('Save')
         btn.connect('clicked', self.item_save)
-        hbox.pack_start(btn)
-        btn = gtk.Button('Remove')
+        hbox.pack_start(btn, expand=True, fill=True, padding=0)
+        btn = Gtk.Button('Remove')
         btn.connect('clicked', self.item_remove)
-        hbox.pack_start(btn)
+        hbox.pack_start(btn, expand=True, fill=True, padding=0)
 
         ### Editor
-        vbox = gtk.VBox(spacing=10)
+        vbox = Gtk.VBox(spacing=10)
         vbox.set_border_width(10)
-        self.tabs.append_page(vbox, gtk.Label('Editor'))
+        self.tabs.append_page(vbox, Gtk.Label('Editor'))
 
         self.show_all()
         self.itemtree.grab_focus()
@@ -180,7 +181,7 @@
 
 
     def on_keypress(self, w, event):
-        keyname = gtk.gdk.keyval_name(event.keyval)
+        keyname = Gdk.keyval_name(event.keyval)
 
         if keyname == 'Escape':
             self.destroy()
@@ -191,7 +192,7 @@
     def on_destroy(self, w):
         model, sel = self.itemtree.get_selection().get_selected_rows()
         if sel:
-            sel = sel[0][0]
+            sel = sel[0].get_indices()[0]
         else:
             sel = None
         self._parent.reload_server_list(sel)