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

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

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

revision 1000 by frank, Thu May 22 19:40:06 2003 UTC revision 1022 by jan, Fri May 23 14:17:50 2003 UTC
# Line 11  from wxPython.wx import * Line 11  from wxPython.wx import *
11  from Thuban import _  from Thuban import _
12    
13  from Thuban.Model.transientdb import TransientJoinedTable  from Thuban.Model.transientdb import TransientJoinedTable
14  from Thuban.UI.tableview import TableFrame, LayerTableFrame  from Thuban.UI.tableview import QueryTableFrame, LayerTableFrame
15                                                                                                                                                                    
16  ID_LEFT_TABLE = 4001  ID_LEFT_TABLE = 4001
17  ID_RIGHT_TABLE = 4002  ID_RIGHT_TABLE = 4002
# Line 23  class JoinDialog(wxDialog): Line 23  class JoinDialog(wxDialog):
23      """Table join dialog.      """Table join dialog.
24    
25      Join two tables (left/right) based on the user selected fields.      Join two tables (left/right) based on the user selected fields.
26      Opens a TableFrame and registers the new table with the session.      Opens a QueryTableFrame and registers the new table with the session.
27      """      """
28    
29      def __init__(self, parent, title, session, layer = None):      def __init__(self, parent, title, session, layer = None):
# Line 55  class JoinDialog(wxDialog): Line 55  class JoinDialog(wxDialog):
55          self.choice_right_table.Append('Select ...', None)          self.choice_right_table.Append('Select ...', None)
56                    
57          for t in session.Tables():          for t in session.Tables():
58              self.choice_left_table.Append(t.transient_table().tablename, t)              self.choice_left_table.Append(t.transient_table().Title(), t)
59              self.choice_right_table.Append(t.transient_table().tablename, t)              self.choice_right_table.Append(t.transient_table().Title(), t)
60    
61          EVT_CHOICE(self, ID_LEFT_TABLE, self.OnLeftTable)          EVT_CHOICE(self, ID_LEFT_TABLE, self.OnLeftTable)
62          EVT_CHOICE(self, ID_RIGHT_TABLE, self.OnRightTable)          EVT_CHOICE(self, ID_RIGHT_TABLE, self.OnRightTable)
# Line 84  class JoinDialog(wxDialog): Line 84  class JoinDialog(wxDialog):
84          sizer.AddGrowableCol(1)          sizer.AddGrowableCol(1)
85          sizer.AddGrowableCol(3)          sizer.AddGrowableCol(3)
86    
87          topBox.Add(sizer, 1, wxEXPAND|wxALL, 4)          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)
88    
89          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
90          sizer.Add(self.button_join, 0, wxEXPAND|wxRIGHT, 10)          self.check_outer_join = wxCheckBox(self,-1,
91          sizer.Add(self.button_close, 0, wxEXPAND|wxRIGHT, 10)                                  _("Outer Join (preserves left table records)"))
92            sizer.Add(self.check_outer_join, 1, wxALL,4)
93            topBox.Add(sizer, 0, wxALIGN_LEFT|wxALIGN_TOP, 4)
94    
95          topBox.Add(sizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10)          sizer = wxBoxSizer(wxHORIZONTAL)
96            sizer.Add(self.button_join, 0, wxALIGN_RIGHT|wxALIGN_BOTTOM|wxRIGHT, 10)
97            sizer.Add(self.button_close, 0, wxALIGN_RIGHT|wxALIGN_BOTTOM|wxRIGHT, 10)
98    
99            topBox.Add(sizer, 1, wxALIGN_RIGHT|wxALIGN_BOTTOM|wxBOTTOM|wxTOP, 10)
100    
101          self.SetAutoLayout(True)          self.SetAutoLayout(True)
102          self.SetSizer(topBox)          self.SetSizer(topBox)
# Line 117  class JoinDialog(wxDialog): Line 123  class JoinDialog(wxDialog):
123          i = self.choice_right_field.GetSelection()          i = self.choice_right_field.GetSelection()
124          right_field  = self.choice_right_field.GetString(i)          right_field  = self.choice_right_field.GetString(i)
125    
126            outer_join = self.check_outer_join.IsChecked()
127    
128          result = True          result = True
129          try:          try:
130              joined_table = TransientJoinedTable(self.db, left_table, left_field,              joined_table = TransientJoinedTable(self.db,
131                                              right_table, right_field)                                              left_table,  left_field,
132                                                right_table, right_field,
133                                                outer_join)
134          except:          except:
135              exc_type, exc_value, exc_traceback = sys.exc_info()              dlg = wxMessageDialog(None,
136              dlg = wxMessageDialog(None, 'Join failed:\n  %s' % exc_value,                                    _('Join failed:\n  %s') % sys.exc_info()[1],
137                                          'Info',wxOK|wxICON_ERROR)                                    _('Info'), wxOK|wxICON_ERROR)
138              dlg.ShowModal()              dlg.ShowModal()
139              dlg.Destroy              dlg.Destroy()
140              result = False              result = False
141            
142          if result:          if result:
143              self.session.AddTable(joined_table)              self.session.AddTable(joined_table)
144              name = joined_table.tablename              name = joined_table.tablename
145              dialog = TableFrame(self.parent, name,              dialog = QueryTableFrame(self.parent, name,
146                                        _("Table: %s") % name, joined_table)                                  _('Table: %s') % joined_table.Title(),
147                                    joined_table)
148              self.parent.add_dialog(name, dialog)              self.parent.add_dialog(name, dialog)
149              dialog.Show(true)              dialog.Show(true)
150    

Legend:
Removed from v.1000  
changed lines
  Added in v.1022

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26