/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/dbdialog.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/dbdialog.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1695 by bh, Mon Sep 1 12:45:07 2003 UTC revision 2700 by dpinte, Mon Sep 18 14:27:02 2006 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2003 by Intevation GmbH  # Copyright (c) 2001, 2003, 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Martin Mueller <[email protected]>  # Martin Mueller <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 11  Line 11 
11    
12  import sys, traceback  import sys, traceback
13    
14  from wxPython.wx import *  import wx
15    
16  try:  try:
17      import psycopg      import psycopg
# Line 20  except ImportError: Line 20  except ImportError:
20    
21  from Thuban import _  from Thuban import _
22  from Thuban.UI.dialogs import NonModalDialog  from Thuban.UI.dialogs import NonModalDialog
23    from Thuban.Model.table import FIELDTYPE_INT
24  from Thuban.Model.postgisdb import ConnectionError, PostGISConnection  from Thuban.Model.postgisdb import ConnectionError, PostGISConnection
25  from Thuban.Model.messages import DBCONN_ADDED, DBCONN_REMOVED  from Thuban.Model.messages import DBCONN_ADDED, DBCONN_REMOVED
26  from messages import SESSION_REPLACED  from messages import SESSION_REPLACED
# Line 34  ID_DBCHOOSE_CANCEL   = 9203 Line 35  ID_DBCHOOSE_CANCEL   = 9203
35  ID_LB_DCLICK         = 9204  ID_LB_DCLICK         = 9204
36    
37    
38  class ChooseDBTableDialog(wxDialog):  class ChooseDBTableDialog(wx.Dialog):
39    
40      def __init__(self, parent, session):      def __init__(self, parent, session):
41          wxDialog.__init__(self, parent, -1, _("Choose layer from database"),          wx.Dialog.__init__(self, parent, -1, _("Choose layer from database"),
42                            style = wxDIALOG_MODAL|wxCAPTION)                            style = wx.DIALOG_MODAL|wx.CAPTION)
43          self.session = session          self.session = session
44          self.dbconns = self.session.DBConnections()          self.dbconns = self.session.DBConnections()
45          self.tables = []          self.tables = []
         self.list_box_4 = wxListBox(self, -1)  
         for i in range(len(self.dbconns)):  
             self.list_box_4.Append(self.dbconns[i].BriefDescription())  
         if self.list_box_4.GetCount() > 0:  
             self.list_box_4.SetSelection(0, True)  
         self.DB_CHOOSE_RETRIEVE = wxButton(self, ID_DBCHOOSE_RETRIEVE,  
                                            _("Retrieve"))  
         self.list_box_5 = wxListBox(self, ID_LB_DCLICK)  
         self.DB_CHOOSE_OK = wxButton(self, ID_DBCHOOSE_OK, _("OK"))  
         self.DB_CHOOSE_CANCEL = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel"))  
         self.__do_layout()  
46    
47          EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK)          #
48          EVT_BUTTON(self, ID_DBCHOOSE_CANCEL, self.OnCancel)          # Build the dialog
49          EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve)          #
50          EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick)  
51            # Sizer for the entire dialog
52            top = wx.FlexGridSizer(2, 1, 0, 0)
53    
54            # Sizer for the main part with the list boxes
55            main_sizer = wx.BoxSizer(wx.HORIZONTAL)
56            top.Add(main_sizer, 1, wx.EXPAND, 0)
57    
58            # The list box with the connections
59            static_box = wx.StaticBoxSizer(wx.StaticBox(self, -1, _("Databases")),
60                                       wx.HORIZONTAL)
61            self.lb_connections = wx.ListBox(self, -1)
62            static_box.Add(self.lb_connections, 0, wx.EXPAND, 0)
63            main_sizer.Add(static_box, 1, wx.EXPAND, 0)
64    
65      def __do_layout(self):          for i in range(len(self.dbconns)):
66          grid_sizer_1 = wxFlexGridSizer(2, 1, 0, 0)              self.lb_connections.Append(self.dbconns[i].BriefDescription())
67          grid_sizer_3 = wxFlexGridSizer(1, 2, 0, 0)          if self.lb_connections.GetCount() > 0:
68          grid_sizer_2 = wxFlexGridSizer(1, 3, 0, 0)              self.lb_connections.SetSelection(0, True)
69          sizer_4 = wxStaticBoxSizer(wxStaticBox(self, -1, _("Tables")),  
70                                     wxHORIZONTAL)          # The button box between the connections list box and the table
71          grid_sizer_4 = wxFlexGridSizer(3, 1, 0, 0)          # list box
72          sizer_3 = wxStaticBoxSizer(wxStaticBox(self, -1, _("Databases")),          buttons = wx.FlexGridSizer(3, 1, 0, 0)
73                                     wxHORIZONTAL)          buttons.Add( (20, 80), 0, wx.EXPAND, 0)
74          sizer_3.Add(self.list_box_4, 0, wxEXPAND, 0)          retrieve_button = wx.Button(self, ID_DBCHOOSE_RETRIEVE, _("Retrieve"))
75          grid_sizer_2.Add(sizer_3, 1, wxEXPAND, 0)          self.Bind(wx.EVT_BUTTON, self.OnRetrieve, id=ID_DBCHOOSE_RETRIEVE)
76          grid_sizer_4.Add(20, 80, 0, wxEXPAND, 0)          buttons.Add(retrieve_button, 0, wx.ALL
77          grid_sizer_4.Add(self.DB_CHOOSE_RETRIEVE, 0, wxALL                      |wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 4)
78                          |wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4)          buttons.Add( (20, 80), 0, wx.EXPAND, 0)
79          grid_sizer_4.Add(20, 80, 0, wxEXPAND, 0)          main_sizer.Add(buttons, 0, wx.EXPAND, 0)
80          grid_sizer_2.Add(grid_sizer_4, 1, wxEXPAND, 0)  
81          sizer_4.Add(self.list_box_5, 0, wxEXPAND, 0)          # The list box with the tables
82          grid_sizer_2.Add(sizer_4, 1, wxEXPAND, 0)          static_box = wx.StaticBoxSizer(wx.StaticBox(self, -1, _("Tables")),
83          grid_sizer_1.Add(grid_sizer_2, 1, wxEXPAND, 0)                                     wx.HORIZONTAL)
84          grid_sizer_3.Add(self.DB_CHOOSE_OK, 0, wxALL|wxALIGN_RIGHT, 4)          self.lb_tables = wx.ListBox(self, ID_LB_DCLICK)
85          grid_sizer_3.Add(self.DB_CHOOSE_CANCEL, 0, wxALL, 4)          self.Bind(wx.EVT_LISTBOX, self.OnTableSelect, id=ID_LB_DCLICK)
86          grid_sizer_1.Add(grid_sizer_3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 4)          self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnLBDClick, id=ID_LB_DCLICK)
87            static_box.Add(self.lb_tables, 0, wx.EXPAND, 0)
88            main_sizer.Add(static_box, 1, wx.EXPAND, 0)
89    
90            # id column and geometry column selection
91            box = wx.BoxSizer(wx.VERTICAL)
92            box.Add(wx.StaticText(self, -1, _("ID Column")), 0,
93                    wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
94            self.text_id_column = wx.ComboBox(self, -1, "")
95            box.Add(self.text_id_column, 0,
96                    wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
97    
98            box.Add(wx.StaticText(self, -1, _("Geometry Column")), 0,
99                    wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
100            self.text_geo_column = wx.ComboBox(self, -1, "")
101            box.Add(self.text_geo_column, 0,
102                    wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
103            main_sizer.Add(box, 1, wx.EXPAND, 0)
104    
105            # The standard button box at the bottom of the dialog
106            buttons = wx.FlexGridSizer(1, 2, 0, 0)
107            ok_button = wx.Button(self, ID_DBCHOOSE_OK, _("OK"))
108            self.Bind(wx.EVT_BUTTON, self.OnOK, id=ID_DBCHOOSE_OK)
109            buttons.Add(ok_button, 0, wx.ALL|wx.ALIGN_RIGHT, 4)
110            cancel_button = wx.Button(self, ID_DBCHOOSE_CANCEL, _("Cancel"))
111            self.Bind(wx.EVT_BUTTON, self.OnCancel, id=ID_DBCHOOSE_CANCEL)
112            buttons.Add(cancel_button, 0, wx.ALL, 4)
113            top.Add(buttons, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
114    
115            # Autosizing
116          self.SetAutoLayout(1)          self.SetAutoLayout(1)
117          self.SetSizer(grid_sizer_1)          self.SetSizer(top)
118          grid_sizer_1.Fit(self)          top.Fit(self)
119          grid_sizer_1.SetSizeHints(self)          top.SetSizeHints(self)
120          self.Layout()          self.Layout()
121    
122    
123      def GetTable(self):      def GetTable(self):
124          i = self.list_box_5.GetSelection()          i = self.lb_tables.GetSelection()
125          if i >= 0:          if i >= 0:
126              return self.selected_conn, self.tables[i]              return (self.selected_conn, self.tables[i],
127                        self.text_id_column.GetValue(),
128                        self.text_geo_column.GetValue())
129          return None          return None
130    
131      def OnRetrieve(self, event):      def OnRetrieve(self, event):
132          i = self.list_box_4.GetSelection()          i = self.lb_connections.GetSelection()
133          if i >= 0:          if i >= 0:
134              self.selected_conn = self.dbconns[i]              self.selected_conn = self.dbconns[i]
135              self.tables = self.selected_conn.GeometryTables()              self.tables = self.selected_conn.GeometryTables()
136              self.list_box_5.Set(self.tables)              self.lb_tables.Set(self.tables)
137    
138        def OnTableSelect(self, event):
139            i = self.lb_tables.GetSelection()
140            self.text_id_column.Clear()
141            self.text_geo_column.Clear()
142            if i >= 0:
143                for name, typ in self.selected_conn.table_columns(self.tables[i]):
144                    if typ == "geometry":
145                        self.text_geo_column.Append(name)
146                    elif typ == FIELDTYPE_INT:
147                        self.text_id_column.Append(name)
148    
149      def OnLBDClick(self, event):      def OnLBDClick(self, event):
150          if self.list_box_5.GetSelection() >= 0:          if self.lb_tables.GetSelection() >= 0:
151              self.EndModal(wxID_OK)              self.EndModal(wx.ID_OK)
152              self.Show(False)              self.Show(False)
153    
154      def OnOK(self, event):      def OnOK(self, event):
155          self.EndModal(wxID_OK)          self.EndModal(wx.ID_OK)
156          self.Show(False)          self.Show(False)
157    
158      def OnCancel(self, event):      def OnCancel(self, event):
159          self.EndModal(wxID_CANCEL)          self.EndModal(wx.ID_CANCEL)
160          self.Show(False)          self.Show(False)
161    
162    
163  class DBDialog(wxDialog):  class DBDialog(wx.Dialog):
164    
165      """Dialog for the parameters of a database connection"""      """Dialog for the parameters of a database connection"""
166    
# Line 129  class DBDialog(wxDialog): Line 175  class DBDialog(wxDialog):
175          using the dialog to ask for correct parameters when the          using the dialog to ask for correct parameters when the
176          connection can't be established.          connection can't be established.
177          """          """
178          wxDialog.__init__(self, parent, -1, title)          wx.Dialog.__init__(self, parent, -1, title)
179    
180          top = wxBoxSizer(wxVERTICAL)          top = wx.BoxSizer(wx.VERTICAL)
181    
182          if message:          if message:
183              top.Add(wxStaticText(self, -1, message), 0,              top.Add(wx.StaticText(self, -1, message), 0,
184                      wxALL|wxALIGN_CENTER_VERTICAL, 4)                      wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
185    
186          box = wxBoxSizer(wxHORIZONTAL)          box = wx.BoxSizer(wx.HORIZONTAL)
187          box.Add(wxStaticText(self, -1, _("Hostname:")), 0,          box.Add(wx.StaticText(self, -1, _("Hostname:")), 0,
188                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
189          self.text_host = wxTextCtrl(self, -1, parameters.get("host", ""))          self.text_host = wx.TextCtrl(self, -1, parameters.get("host", ""))
190          box.Add(self.text_host, 2, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)          box.Add(self.text_host, 2, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
191          box.Add(wxStaticText(self, -1, _("Port:")), 0,          box.Add(wx.StaticText(self, -1, _("Port:")), 0,
192                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
193          self.text_port = wxTextCtrl(self, -1, parameters.get("port", ""))          self.text_port = wx.TextCtrl(self, -1, parameters.get("port", ""))
194          box.Add(self.text_port, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)          box.Add(self.text_port, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
195          top.Add(box, 0, wxEXPAND)          top.Add(box, 0, wx.EXPAND)
196    
197          box = wxBoxSizer(wxHORIZONTAL)          box = wx.BoxSizer(wx.HORIZONTAL)
198          box.Add(wxStaticText(self, -1, _("Database Name:")), 0,          box.Add(wx.StaticText(self, -1, _("Database Name:")), 0,
199                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
200          self.text_dbname = wxTextCtrl(self, -1,          self.text_dbname = wx.TextCtrl(self, -1,
201                                        parameters.get("dbname", ""))                                        parameters.get("dbname", ""))
202          box.Add(self.text_dbname, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)          box.Add(self.text_dbname, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
203          top.Add(box, 0, wxEXPAND)          top.Add(box, 0, wx.EXPAND)
204    
205          box = wxBoxSizer(wxHORIZONTAL)          box = wx.BoxSizer(wx.HORIZONTAL)
206          box.Add(wxStaticText(self, -1, _("User:")), 0,          box.Add(wx.StaticText(self, -1, _("User:")), 0,
207                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
208          self.text_user = wxTextCtrl(self, -1,          self.text_user = wx.TextCtrl(self, -1,
209                                      parameters.get("user", ""))                                      parameters.get("user", ""))
210          box.Add(self.text_user, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)          box.Add(self.text_user, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
211          box.Add(wxStaticText(self, -1, _("Password:")), 0,          box.Add(wx.StaticText(self, -1, _("Password:")), 0,
212                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
213          self.text_password = wxTextCtrl(self, -1,          self.text_password = wx.TextCtrl(self, -1,
214                                          parameters.get("password", ""),                                          parameters.get("password", ""),
215                                          style = wxTE_PASSWORD)                                          style = wx.TE_PASSWORD)
216          box.Add(self.text_password, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND,          box.Add(self.text_password, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
217                  4)                  4)
218          top.Add(box, 0, wxEXPAND)          top.Add(box, 0, wx.EXPAND)
219    
220          buttons = wxBoxSizer(wxHORIZONTAL)          buttons = wx.BoxSizer(wx.HORIZONTAL)
221          button = wxButton(self, wxID_OK, _("OK"))          button = wx.Button(self, wx.ID_OK, _("OK"))
222          buttons.Add(button, 0, wxALL, 4)          buttons.Add(button, 0, wx.ALL, 4)
223          button = wxButton(self, wxID_CANCEL, _("Cancel"))          button = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
224          buttons.Add(button, 0, wxALL, 4)          buttons.Add(button, 0, wx.ALL, 4)
225          top.Add(buttons, 0, wxALIGN_RIGHT, 4)          top.Add(buttons, 0, wx.ALIGN_RIGHT, 4)
226    
227          self.SetAutoLayout(1)          self.SetAutoLayout(1)
228          self.SetSizer(top)          self.SetSizer(top)
229          top.Fit(self)          top.Fit(self)
230          top.SetSizeHints(self)          top.SetSizeHints(self)
231    
232          EVT_BUTTON(self, wxID_OK, self.OnOK)          self.Bind(wx.EVT_BUTTON, self.OnOK, id=wx.ID_OK)
233          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)          self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
234    
235      def RunDialog(self):      def RunDialog(self):
236          self.ShowModal()          self.ShowModal()
# Line 194  class DBDialog(wxDialog): Line 240  class DBDialog(wxDialog):
240      def end_dialog(self, result):      def end_dialog(self, result):
241          self.result = result          self.result = result
242          if result is not None:          if result is not None:
243              self.EndModal(wxID_OK)              self.EndModal(wx.ID_OK)
244          else:          else:
245              self.EndModal(wxID_CANCEL)              self.EndModal(wx.ID_CANCEL)
246          self.Show(False)          self.Show(False)
247    
248      def OnOK(self, event):      def OnOK(self, event):
# Line 215  class DBFrame(NonModalDialog): Line 261  class DBFrame(NonModalDialog):
261      """Databse connection management dialog"""      """Databse connection management dialog"""
262    
263      def __init__(self, parent, name, session, *args, **kwds):      def __init__(self, parent, name, session, *args, **kwds):
264          kwds["style"] = wxICONIZE|wxCAPTION|wxMINIMIZE          kwds["style"] = wx.ICONIZE|wx.CAPTION|wx.MINIMIZE
265          NonModalDialog.__init__(self, parent, name, "")          NonModalDialog.__init__(self, parent, name, "")
266          self.session = session          self.session = session
267          self.app = self.parent.application          self.app = self.parent.application
# Line 223  class DBFrame(NonModalDialog): Line 269  class DBFrame(NonModalDialog):
269          self.app.Subscribe(SESSION_REPLACED, self.session_replaced)          self.app.Subscribe(SESSION_REPLACED, self.session_replaced)
270          self.subscribe_session()          self.subscribe_session()
271    
272          self.DB_ListBox = wxListBox(self, -1,          self.DB_ListBox = wx.ListBox(self, -1,
273                                style=wxLB_SINGLE|wxLB_HSCROLL|wxLB_ALWAYS_SB)                                style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
274          self.DB_Add = wxButton(self, ID_DB_ADD, _("Add"))          self.DB_Add = wx.Button(self, ID_DB_ADD, _("Add"))
275          self.DB_Remove = wxButton(self, ID_DB_REMOVE, _("Remove"))          self.DB_Remove = wx.Button(self, ID_DB_REMOVE, _("Remove"))
276          self.DB_CLOSE = wxButton(self, wxID_CLOSE, _("Close"))          self.DB_CLOSE = wx.Button(self, wx.ID_CLOSE, _("Close"))
277          self.__set_properties()          self.__set_properties()
278          self.__do_layout()          self.__do_layout()
279          EVT_BUTTON(self, ID_DB_ADD, self.OnAdd)          self.Bind(wx.EVT_BUTTON, self.OnAdd, id=ID_DB_ADD)
280          EVT_BUTTON(self, ID_DB_REMOVE, self.OnRemove)          self.Bind(wx.EVT_BUTTON, self.OnRemove, id=ID_DB_REMOVE)
281          EVT_BUTTON(self, wxID_CLOSE, self.OnClose)          self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
282    
283          self.conns_changed()          self.conns_changed()
284    
# Line 241  class DBFrame(NonModalDialog): Line 287  class DBFrame(NonModalDialog):
287          self.DB_ListBox.SetSize((200, 157))          self.DB_ListBox.SetSize((200, 157))
288    
289      def __do_layout(self):      def __do_layout(self):
290          top = wxBoxSizer(wxVERTICAL)          top = wx.BoxSizer(wx.VERTICAL)
291    
292          box = wxBoxSizer(wxHORIZONTAL)          box = wx.BoxSizer(wx.HORIZONTAL)
293    
294          box.Add(self.DB_ListBox, 1, wxALL|wxEXPAND          box.Add(self.DB_ListBox, 1, wx.ALL|wx.EXPAND
295                  |wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4)                  |wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 4)
296    
297          buttons = wxBoxSizer(wxVERTICAL)          buttons = wx.BoxSizer(wx.VERTICAL)
298          buttons.Add(self.DB_Add, 0, wxALL, 4)          buttons.Add(self.DB_Add, 0, wx.ALL, 4)
299          buttons.Add(self.DB_Remove, 0, wxALL, 4)          buttons.Add(self.DB_Remove, 0, wx.ALL, 4)
300    
301          box.Add(buttons, 0, wxEXPAND)          box.Add(buttons, 0, wx.EXPAND)
302          top.Add(box, 1, wxEXPAND)          top.Add(box, 1, wx.EXPAND)
303    
304          buttons = wxBoxSizer(wxHORIZONTAL)          buttons = wx.BoxSizer(wx.HORIZONTAL)
305          buttons.Add(self.DB_CLOSE, 1, wxALL|wxALIGN_RIGHT, 4)          buttons.Add(self.DB_CLOSE, 1, wx.ALL|wx.ALIGN_RIGHT, 4)
306          top.Add(buttons, 0, wxALIGN_RIGHT)          top.Add(buttons, 0, wx.ALIGN_RIGHT)
307    
308          self.SetAutoLayout(1)          self.SetAutoLayout(1)
309          self.SetSizer(top)          self.SetSizer(top)
# Line 288  class DBFrame(NonModalDialog): Line 334  class DBFrame(NonModalDialog):
334      def conns_changed(self, *args):      def conns_changed(self, *args):
335          """Internal: update the db connection list box          """Internal: update the db connection list box
336    
337          Subscribed to the DBCONN_REMOVED and DBCONN_REMOVED.          Subscribed to the DBCONN_ADDED and DBCONN_REMOVED messages.
338          """          """
339          self.DB_ListBox.Clear()          self.DB_ListBox.Clear()
340          for conn in self.session.DBConnections():          for conn in self.session.DBConnections():
# Line 299  class DBFrame(NonModalDialog): Line 345  class DBFrame(NonModalDialog):
345          self.app.Unsubscribe(SESSION_REPLACED, self.session_replaced)          self.app.Unsubscribe(SESSION_REPLACED, self.session_replaced)
346          NonModalDialog.OnClose(self, event)          NonModalDialog.OnClose(self, event)
347    
348      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wx.OK | wx.ICON_INFORMATION):
349          """Run a modal message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
350          and return the result"""          and return the result"""
351          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
# Line 315  class DBFrame(NonModalDialog): Line 361  class DBFrame(NonModalDialog):
361              dialog = DBDialog(self, _("Add Database"), parameters, message)              dialog = DBDialog(self, _("Add Database"), parameters, message)
362              parameters = dialog.RunDialog()              parameters = dialog.RunDialog()
363              if parameters is not None:              if parameters is not None:
                 host = parameters["host"]  
                 database = parameters["dbname"]  
364                  for conn in self.session.DBConnections():                  for conn in self.session.DBConnections():
365                      if (host == conn.host and                      if conn.MatchesParameters(parameters):
                         database == conn.dbname):  
366                          self.RunMessageBox(_("Add Database"),                          self.RunMessageBox(_("Add Database"),
367                                           _("Connection to '%s' already exists")                                           _("Connection '%s' already exists")
368                                             % database)                                             % conn.BriefDescription())
369                          break                          break
                 try:  
                     conn = PostGISConnection(**parameters)  
                 except ConnectionError, val:  
                     message = str(val)  
370                  else:                  else:
371                      self.session.AddDBConnection(conn)                      try:
372                      break                          conn = PostGISConnection(**parameters)
373                        except ConnectionError, val:
374                            message = str(val)
375                        else:
376                            self.session.AddDBConnection(conn)
377                            break
378              else:              else:
379                  break                  break
380    

Legend:
Removed from v.1695  
changed lines
  Added in v.2700

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26