/[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 2101 by bh, Tue Nov 18 15:37:38 2003 UTC revision 2102 by bh, Thu Mar 11 21:04:30 2004 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 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 42  class ChooseDBTableDialog(wxDialog): Line 43  class ChooseDBTableDialog(wxDialog):
43          self.session = session          self.session = session
44          self.dbconns = self.session.DBConnections()          self.dbconns = self.session.DBConnections()
45          self.tables = []          self.tables = []
46          self.list_box_4 = wxListBox(self, -1)  
47            #
48            # Build the dialog
49            #
50    
51            # Sizer for the entire dialog
52            top = wxFlexGridSizer(2, 1, 0, 0)
53    
54            # Sizer for the main part with the list boxes
55            main_sizer = wxBoxSizer(wxHORIZONTAL)
56            top.Add(main_sizer, 1, wxEXPAND, 0)
57    
58            # The list box with the connections
59            static_box = wxStaticBoxSizer(wxStaticBox(self, -1, _("Databases")),
60                                       wxHORIZONTAL)
61            self.lb_connections = wxListBox(self, -1)
62            static_box.Add(self.lb_connections, 0, wxEXPAND, 0)
63            main_sizer.Add(static_box, 1, wxEXPAND, 0)
64    
65          for i in range(len(self.dbconns)):          for i in range(len(self.dbconns)):
66              self.list_box_4.Append(self.dbconns[i].BriefDescription())              self.lb_connections.Append(self.dbconns[i].BriefDescription())
67          if self.list_box_4.GetCount() > 0:          if self.lb_connections.GetCount() > 0:
68              self.list_box_4.SetSelection(0, True)              self.lb_connections.SetSelection(0, True)
69          self.DB_CHOOSE_RETRIEVE = wxButton(self, ID_DBCHOOSE_RETRIEVE,  
70                                             _("Retrieve"))          # The button box between the connections list box and the table
71          self.list_box_5 = wxListBox(self, ID_LB_DCLICK)          # list box
72          self.DB_CHOOSE_OK = wxButton(self, ID_DBCHOOSE_OK, _("OK"))          buttons = wxFlexGridSizer(3, 1, 0, 0)
73          self.DB_CHOOSE_CANCEL = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel"))          buttons.Add(20, 80, 0, wxEXPAND, 0)
74          self.__do_layout()          retrieve_button = wxButton(self, ID_DBCHOOSE_RETRIEVE, _("Retrieve"))
75            EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve)
76            buttons.Add(retrieve_button, 0, wxALL
77                        |wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4)
78            buttons.Add(20, 80, 0, wxEXPAND, 0)
79            main_sizer.Add(buttons, 0, wxEXPAND, 0)
80    
81            # The list box with the tables
82            static_box = wxStaticBoxSizer(wxStaticBox(self, -1, _("Tables")),
83                                       wxHORIZONTAL)
84            self.lb_tables = wxListBox(self, ID_LB_DCLICK)
85            EVT_LISTBOX(self, ID_LB_DCLICK, self.OnTableSelect)
86            EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick)
87            static_box.Add(self.lb_tables, 0, wxEXPAND, 0)
88            main_sizer.Add(static_box, 1, wxEXPAND, 0)
89    
90            # id column and geometry column selection
91            box = wxBoxSizer(wxVERTICAL)
92            box.Add(wxStaticText(self, -1, _("ID Column")), 0,
93                    wxALL|wxALIGN_CENTER_VERTICAL, 4)
94            self.text_id_column = wxComboBox(self, -1, "")
95            box.Add(self.text_id_column, 0,
96                    wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)
97    
98            box.Add(wxStaticText(self, -1, _("Geometry Column")), 0,
99                    wxALL|wxALIGN_CENTER_VERTICAL, 4)
100            self.text_geo_column = wxComboBox(self, -1, "")
101            box.Add(self.text_geo_column, 0,
102                    wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4)
103            main_sizer.Add(box, 1, wxEXPAND, 0)
104    
105            # The standard button box at the bottom of the dialog
106            buttons = wxFlexGridSizer(1, 2, 0, 0)
107            ok_button = wxButton(self, ID_DBCHOOSE_OK, _("OK"))
108          EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK)          EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK)
109            buttons.Add(ok_button, 0, wxALL|wxALIGN_RIGHT, 4)
110            cancel_button = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel"))
111          EVT_BUTTON(self, ID_DBCHOOSE_CANCEL, self.OnCancel)          EVT_BUTTON(self, ID_DBCHOOSE_CANCEL, self.OnCancel)
112          EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve)          buttons.Add(cancel_button, 0, wxALL, 4)
113          EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick)          top.Add(buttons, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 4)
114    
115      def __do_layout(self):          # Autosizing
         grid_sizer_1 = wxFlexGridSizer(2, 1, 0, 0)  
         grid_sizer_3 = wxFlexGridSizer(1, 2, 0, 0)  
         grid_sizer_2 = wxFlexGridSizer(1, 3, 0, 0)  
         sizer_4 = wxStaticBoxSizer(wxStaticBox(self, -1, _("Tables")),  
                                    wxHORIZONTAL)  
         grid_sizer_4 = wxFlexGridSizer(3, 1, 0, 0)  
         sizer_3 = wxStaticBoxSizer(wxStaticBox(self, -1, _("Databases")),  
                                    wxHORIZONTAL)  
         sizer_3.Add(self.list_box_4, 0, wxEXPAND, 0)  
         grid_sizer_2.Add(sizer_3, 1, wxEXPAND, 0)  
         grid_sizer_4.Add(20, 80, 0, wxEXPAND, 0)  
         grid_sizer_4.Add(self.DB_CHOOSE_RETRIEVE, 0, wxALL  
                         |wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4)  
         grid_sizer_4.Add(20, 80, 0, wxEXPAND, 0)  
         grid_sizer_2.Add(grid_sizer_4, 1, wxEXPAND, 0)  
         sizer_4.Add(self.list_box_5, 0, wxEXPAND, 0)  
         grid_sizer_2.Add(sizer_4, 1, wxEXPAND, 0)  
         grid_sizer_1.Add(grid_sizer_2, 1, wxEXPAND, 0)  
         grid_sizer_3.Add(self.DB_CHOOSE_OK, 0, wxALL|wxALIGN_RIGHT, 4)  
         grid_sizer_3.Add(self.DB_CHOOSE_CANCEL, 0, wxALL, 4)  
         grid_sizer_1.Add(grid_sizer_3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 4)  
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(wxID_OK)
152              self.Show(False)              self.Show(False)
153    

Legend:
Removed from v.2101  
changed lines
  Added in v.2102

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26