/[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 2561 by bh, Tue Feb 8 20:34:29 2005 UTC revision 2700 by dpinte, Mon Sep 18 14:27:02 2006 UTC
# 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 35  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 = []
# Line 49  class ChooseDBTableDialog(wxDialog): Line 49  class ChooseDBTableDialog(wxDialog):
49          #          #
50    
51          # Sizer for the entire dialog          # Sizer for the entire dialog
52          top = wxFlexGridSizer(2, 1, 0, 0)          top = wx.FlexGridSizer(2, 1, 0, 0)
53    
54          # Sizer for the main part with the list boxes          # Sizer for the main part with the list boxes
55          main_sizer = wxBoxSizer(wxHORIZONTAL)          main_sizer = wx.BoxSizer(wx.HORIZONTAL)
56          top.Add(main_sizer, 1, wxEXPAND, 0)          top.Add(main_sizer, 1, wx.EXPAND, 0)
57    
58          # The list box with the connections          # The list box with the connections
59          static_box = wxStaticBoxSizer(wxStaticBox(self, -1, _("Databases")),          static_box = wx.StaticBoxSizer(wx.StaticBox(self, -1, _("Databases")),
60                                     wxHORIZONTAL)                                     wx.HORIZONTAL)
61          self.lb_connections = wxListBox(self, -1)          self.lb_connections = wx.ListBox(self, -1)
62          static_box.Add(self.lb_connections, 0, wxEXPAND, 0)          static_box.Add(self.lb_connections, 0, wx.EXPAND, 0)
63          main_sizer.Add(static_box, 1, wxEXPAND, 0)          main_sizer.Add(static_box, 1, wx.EXPAND, 0)
64    
65          for i in range(len(self.dbconns)):          for i in range(len(self.dbconns)):
66              self.lb_connections.Append(self.dbconns[i].BriefDescription())              self.lb_connections.Append(self.dbconns[i].BriefDescription())
# Line 69  class ChooseDBTableDialog(wxDialog): Line 69  class ChooseDBTableDialog(wxDialog):
69    
70          # The button box between the connections list box and the table          # The button box between the connections list box and the table
71          # list box          # list box
72          buttons = wxFlexGridSizer(3, 1, 0, 0)          buttons = wx.FlexGridSizer(3, 1, 0, 0)
73          buttons.Add( (20, 80), 0, wxEXPAND, 0)          buttons.Add( (20, 80), 0, wx.EXPAND, 0)
74          retrieve_button = wxButton(self, ID_DBCHOOSE_RETRIEVE, _("Retrieve"))          retrieve_button = wx.Button(self, ID_DBCHOOSE_RETRIEVE, _("Retrieve"))
75          EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve)          self.Bind(wx.EVT_BUTTON, self.OnRetrieve, id=ID_DBCHOOSE_RETRIEVE)
76          buttons.Add(retrieve_button, 0, wxALL          buttons.Add(retrieve_button, 0, wx.ALL
77                      |wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4)                      |wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 4)
78          buttons.Add( (20, 80), 0, wxEXPAND, 0)          buttons.Add( (20, 80), 0, wx.EXPAND, 0)
79          main_sizer.Add(buttons, 0, wxEXPAND, 0)          main_sizer.Add(buttons, 0, wx.EXPAND, 0)
80    
81          # The list box with the tables          # The list box with the tables
82          static_box = wxStaticBoxSizer(wxStaticBox(self, -1, _("Tables")),          static_box = wx.StaticBoxSizer(wx.StaticBox(self, -1, _("Tables")),
83                                     wxHORIZONTAL)                                     wx.HORIZONTAL)
84          self.lb_tables = wxListBox(self, ID_LB_DCLICK)          self.lb_tables = wx.ListBox(self, ID_LB_DCLICK)
85          EVT_LISTBOX(self, ID_LB_DCLICK, self.OnTableSelect)          self.Bind(wx.EVT_LISTBOX, self.OnTableSelect, id=ID_LB_DCLICK)
86          EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick)          self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnLBDClick, id=ID_LB_DCLICK)
87          static_box.Add(self.lb_tables, 0, wxEXPAND, 0)          static_box.Add(self.lb_tables, 0, wx.EXPAND, 0)
88          main_sizer.Add(static_box, 1, wxEXPAND, 0)          main_sizer.Add(static_box, 1, wx.EXPAND, 0)
89    
90          # id column and geometry column selection          # id column and geometry column selection
91          box = wxBoxSizer(wxVERTICAL)          box = wx.BoxSizer(wx.VERTICAL)
92          box.Add(wxStaticText(self, -1, _("ID Column")), 0,          box.Add(wx.StaticText(self, -1, _("ID Column")), 0,
93                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
94          self.text_id_column = wxComboBox(self, -1, "")          self.text_id_column = wx.ComboBox(self, -1, "")
95          box.Add(self.text_id_column, 0,          box.Add(self.text_id_column, 0,
96                  wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
97    
98          box.Add(wxStaticText(self, -1, _("Geometry Column")), 0,          box.Add(wx.StaticText(self, -1, _("Geometry Column")), 0,
99                  wxALL|wxALIGN_CENTER_VERTICAL, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
100          self.text_geo_column = wxComboBox(self, -1, "")          self.text_geo_column = wx.ComboBox(self, -1, "")
101          box.Add(self.text_geo_column, 0,          box.Add(self.text_geo_column, 0,
102                  wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)                  wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 4)
103          main_sizer.Add(box, 1, wxEXPAND, 0)          main_sizer.Add(box, 1, wx.EXPAND, 0)
104    
105          # The standard button box at the bottom of the dialog          # The standard button box at the bottom of the dialog
106          buttons = wxFlexGridSizer(1, 2, 0, 0)          buttons = wx.FlexGridSizer(1, 2, 0, 0)
107          ok_button = wxButton(self, ID_DBCHOOSE_OK, _("OK"))          ok_button = wx.Button(self, ID_DBCHOOSE_OK, _("OK"))
108          EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK)          self.Bind(wx.EVT_BUTTON, self.OnOK, id=ID_DBCHOOSE_OK)
109          buttons.Add(ok_button, 0, wxALL|wxALIGN_RIGHT, 4)          buttons.Add(ok_button, 0, wx.ALL|wx.ALIGN_RIGHT, 4)
110          cancel_button = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel"))          cancel_button = wx.Button(self, ID_DBCHOOSE_CANCEL, _("Cancel"))
111          EVT_BUTTON(self, ID_DBCHOOSE_CANCEL, self.OnCancel)          self.Bind(wx.EVT_BUTTON, self.OnCancel, id=ID_DBCHOOSE_CANCEL)
112          buttons.Add(cancel_button, 0, wxALL, 4)          buttons.Add(cancel_button, 0, wx.ALL, 4)
113          top.Add(buttons, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 4)          top.Add(buttons, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
114    
115          # Autosizing          # Autosizing
116          self.SetAutoLayout(1)          self.SetAutoLayout(1)
# Line 148  class ChooseDBTableDialog(wxDialog): Line 148  class ChooseDBTableDialog(wxDialog):
148    
149      def OnLBDClick(self, event):      def OnLBDClick(self, event):
150          if self.lb_tables.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 175  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 240  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 261  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 269  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 287  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 345  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)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26