pgconsole/settings.py
author Radek Brich <radek.brich@devl.cz>
Fri, 25 Jan 2013 17:44:49 +0100
changeset 60 bb6b20106ff5
parent 10 f3a1b9792cc9
child 76 3a41b351b122
permissions -rw-r--r--
PgDiff: Update patch for table column changed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
import gtk
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from config import cfg
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
class Settings(gtk.Window):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
    def __init__(self, parent):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
        super(Settings, self).__init__(gtk.WINDOW_TOPLEVEL)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
        self._parent = parent
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        self.set_title('Settings')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        self.set_modal(True)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
        self.set_transient_for(parent.win)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        self.set_position(gtk.WIN_POS_CENTER)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        #self.set_border_width(10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        self.connect("key_press_event", self.on_keypress)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
        self.connect("destroy", self.on_destroy)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
        self.tabs = gtk.Notebook()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
        self.add(self.tabs)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        ### Servers
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
        vbox = gtk.VBox(spacing=10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
        vbox.set_border_width(10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
        self.tabs.append_page(vbox, gtk.Label('Servers'))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
        hbox = gtk.HBox(spacing=10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
        vbox.pack_start(hbox)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        sw = gtk.ScrolledWindow()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
        sw.set_shadow_type(gtk.SHADOW_IN)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
        hbox.pack_start(sw)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
        tree = gtk.TreeView()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
        tree.set_headers_visible(False)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
        sw.add(tree)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
        tree.get_selection().set_mode(gtk.SELECTION_BROWSE)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
        model = gtk.ListStore(str, object)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
        tree.set_model(model)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
        column = gtk.TreeViewColumn("Server", gtk.CellRendererText(), text=0)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
        tree.append_column(column)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
        tree.get_selection().connect('changed', self.item_change)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
        tree.set_size_request(100, -1)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
        try:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
            for server in cfg.servers.server:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
                if str(server.name):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
                    title = '%s (%s)' % (str(server.name), str(server.host))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
                else:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
                    title = str(server.host)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
                model.append([title, server])
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
        except AttributeError:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
            pass
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
        self.itemtree = tree
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
        vbox = gtk.VBox(spacing=10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
        hbox.pack_start(vbox)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
        table = gtk.Table(5, 2)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
        table.set_row_spacings(4)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
        table.set_col_spacings(10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
        vbox.pack_start(table)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
        label = gtk.Label("Name:")
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
        label.set_alignment(0.0, 0.5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
        table.attach(label, 0, 1, 0, 1)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
        entry = gtk.Entry()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    70
        table.attach(entry, 1, 2, 0, 1)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
        self.entry_name = entry
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
        label = gtk.Label("Host:")
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
        label.set_alignment(0.0, 0.5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    75
        table.attach(label, 0, 1, 1, 2)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
        entry = gtk.Entry()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    77
        entry.set_text('127.0.0.1')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    78
        table.attach(entry, 1, 2, 1, 2)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    79
        self.entry_host = entry
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
        label = gtk.Label("Port:")
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
        label.set_alignment(0.0, 0.5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
        table.attach(label, 0, 1, 2, 3)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
        entry = gtk.Entry()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    85
        entry.set_text('5432')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
        table.attach(entry, 1, 2, 2, 3)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
        self.entry_port = entry
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
        label = gtk.Label("User:")
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
        label.set_alignment(0.0, 0.5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
        table.attach(label, 0, 1, 3, 4)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
        entry = gtk.Entry()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    93
        entry.set_text('postgres')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    94
        table.attach(entry, 1, 2, 3, 4)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    95
        self.entry_user = entry
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
        label = gtk.Label("Password:")
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    98
        label.set_alignment(0.0, 0.5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
        table.attach(label, 0, 1, 4, 5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
        entry = gtk.Entry()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
        table.attach(entry, 1, 2, 4, 5)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
        self.entry_password = entry
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   104
        hbox = gtk.HBox()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   105
        vbox.pack_start(hbox)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   106
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
        btn = gtk.Button('Add')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
        btn.connect('clicked', self.item_add)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   109
        hbox.pack_start(btn)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
        btn = gtk.Button('Save')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   111
        btn.connect('clicked', self.item_save)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
        hbox.pack_start(btn)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
        btn = gtk.Button('Remove')
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   114
        btn.connect('clicked', self.item_remove)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
        hbox.pack_start(btn)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
        ### Editor
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
        vbox = gtk.VBox(spacing=10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   119
        vbox.set_border_width(10)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
        self.tabs.append_page(vbox, gtk.Label('Editor'))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   121
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
        self.show_all()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
        self.itemtree.grab_focus()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   124
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   126
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
    def item_change(self, w):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   128
        model, sel = self.itemtree.get_selection().get_selected_rows()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   129
        if not sel:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   130
            return
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   131
        el, = model.get(model.get_iter(sel[0]), 1)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   132
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   133
        self.entry_name.set_text(str(el.name))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   134
        self.entry_host.set_text(str(el.host))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   135
        self.entry_port.set_text(str(el.port))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   136
        self.entry_user.set_text(str(el.user))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   137
        self.entry_password.set_text(str(el.password))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   138
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
    def item_add(self, w):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   141
        el = cfg.add_server(
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   142
            self.entry_name.get_text(),
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
            self.entry_host.get_text(),
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
            self.entry_port.get_text(),
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
            self.entry_user.get_text(),
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
            self.entry_password.get_text())
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   147
        if str(el.name):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
            title = '%s (%s)' % (str(el.name), str(el.host))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
        else:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
            title = str(el.host)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
        iter = self.itemtree.get_model().append([title, el])
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
        self.itemtree.get_selection().select_iter(iter)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   153
        cfg.save()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   154
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
    def item_save(self, w):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
        model, sel = self.itemtree.get_selection().get_selected_rows()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
        el = cfg.servers.server[sel[0][0]]
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
        el.name = self.entry_name.get_text()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   160
        el.host = self.entry_host.get_text()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   161
        el.port = self.entry_port.get_text()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   162
        el.user = self.entry_user.get_text()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
        el.password = self.entry_password.get_text()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
        cfg.save()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   165
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
        if str(el.name):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
            title = '%s (%s)' % (str(el.name), str(el.host))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   168
        else:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   169
            title = str(el.host)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   170
        model.set(model.get_iter(sel[0]), 0, title)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   173
    def item_remove(self, w):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
        model, sel = self.itemtree.get_selection().get_selected_rows()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
        model.remove(model.get_iter(sel[0]))
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   176
        if model.get_iter_first():
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   177
            self.itemtree.get_selection().select_iter(model.get_iter_first())
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   178
        del cfg.servers.server[sel[0][0]]
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   179
        cfg.save()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   180
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   181
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   182
    def on_keypress(self, w, event):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   183
        keyname = gtk.gdk.keyval_name(event.keyval)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   184
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   185
        if keyname == 'Escape':
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   186
            self.destroy()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   187
            return True
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   188
        return False
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   189
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   190
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
    def on_destroy(self, w):
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   192
        model, sel = self.itemtree.get_selection().get_selected_rows()
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   193
        if sel:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   194
            sel = sel[0][0]
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   195
        else:
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   196
            sel = None
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   197
        self._parent.reload_server_list(sel)
f3a1b9792cc9 Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   198