21 |
from Thuban.Model.data import DerivedShapeStore |
from Thuban.Model.data import DerivedShapeStore |
22 |
from Thuban.UI.tableview import QueryTableFrame |
from Thuban.UI.tableview import QueryTableFrame |
23 |
|
|
24 |
|
from common import ThubanBeginBusyCursor, ThubanEndBusyCursor |
25 |
|
|
26 |
ID_LEFT_TABLE = 4001 |
ID_LEFT_TABLE = 4001 |
27 |
ID_RIGHT_TABLE = 4002 |
ID_RIGHT_TABLE = 4002 |
28 |
|
|
145 |
|
|
146 |
def OnJoin(self, event): |
def OnJoin(self, event): |
147 |
"""Get the table and field selections and perform the join.""" |
"""Get the table and field selections and perform the join.""" |
148 |
# left |
ThubanBeginBusyCursor() |
149 |
if self.choice_left_table is not None: |
try: |
150 |
i = self.choice_left_table.GetSelection() |
# left |
151 |
left_table = self.choice_left_table.GetClientData(i) |
if self.choice_left_table is not None: |
152 |
else: |
i = self.choice_left_table.GetSelection() |
153 |
left_table = self.left_table |
left_table = self.choice_left_table.GetClientData(i) |
154 |
i = self.choice_left_field.GetSelection() |
else: |
155 |
left_field = self.choice_left_field.GetString(i) |
left_table = self.left_table |
156 |
# right |
i = self.choice_left_field.GetSelection() |
157 |
i = self.choice_right_table.GetSelection() |
left_field = self.choice_left_field.GetString(i) |
158 |
right_table = self.choice_right_table.GetClientData(i) |
# right |
159 |
i = self.choice_right_field.GetSelection() |
i = self.choice_right_table.GetSelection() |
160 |
right_field = self.choice_right_field.GetString(i) |
right_table = self.choice_right_table.GetClientData(i) |
161 |
|
i = self.choice_right_field.GetSelection() |
162 |
|
right_field = self.choice_right_field.GetString(i) |
163 |
|
|
164 |
|
outer_join = self.check_outer_join.IsChecked() |
165 |
|
|
166 |
|
try: |
167 |
|
joined_table = TransientJoinedTable(self.session.TransientDB(), |
168 |
|
left_table, left_field, |
169 |
|
right_table, right_field, |
170 |
|
outer_join) |
171 |
|
except: |
172 |
|
dlg = wxMessageDialog(None, |
173 |
|
_('Join failed:\n %s') % sys.exc_info()[1], |
174 |
|
_('Info'), wxOK|wxICON_ERROR) |
175 |
|
dlg.ShowModal() |
176 |
|
dlg.Destroy() |
177 |
|
return |
178 |
|
|
179 |
|
joined_table = self.session.AddTable(joined_table) |
180 |
|
|
181 |
outer_join = self.check_outer_join.IsChecked() |
if self.layer is not None: |
182 |
|
needed_rows = self.layer.ShapeStore().Table().NumRows() |
183 |
|
joined_rows = joined_table.NumRows() |
184 |
|
if needed_rows == joined_rows: |
185 |
|
store = DerivedShapeStore(self.layer.ShapeStore(), |
186 |
|
joined_table) |
187 |
|
self.session.AddShapeStore(store) |
188 |
|
self.layer.SetShapeStore(store) |
189 |
|
|
190 |
try: |
finally: |
191 |
joined_table = TransientJoinedTable(self.session.TransientDB(), |
ThubanEndBusyCursor() |
|
left_table, left_field, |
|
|
right_table, right_field, |
|
|
outer_join) |
|
|
except: |
|
|
dlg = wxMessageDialog(None, |
|
|
_('Join failed:\n %s') % sys.exc_info()[1], |
|
|
_('Info'), wxOK|wxICON_ERROR) |
|
|
dlg.ShowModal() |
|
|
dlg.Destroy() |
|
|
return |
|
192 |
|
|
|
joined_table = self.session.AddTable(joined_table) |
|
193 |
if self.layer is not None: |
if self.layer is not None: |
|
needed_rows = self.layer.ShapeStore().Table().NumRows() |
|
|
joined_rows = joined_table.NumRows() |
|
194 |
if needed_rows != joined_rows: |
if needed_rows != joined_rows: |
195 |
msg = _("The joined table has %(joined)d rows but" |
msg = _("The joined table has %(joined)d rows but" |
196 |
" it must have %(needed)d rows" |
" it must have %(needed)d rows" |
202 |
dlg.ShowModal() |
dlg.ShowModal() |
203 |
dlg.Destroy() |
dlg.Destroy() |
204 |
return |
return |
205 |
else: |
|
|
store = DerivedShapeStore(self.layer.ShapeStore(), |
|
|
joined_table) |
|
|
self.session.AddShapeStore(store) |
|
|
self.layer.SetShapeStore(store) |
|
206 |
else: |
else: |
207 |
name = joined_table.tablename |
name = joined_table.tablename |
208 |
dialog = QueryTableFrame(self.parent, name, |
dialog = QueryTableFrame(self.parent, name, |
210 |
joined_table) |
joined_table) |
211 |
self.parent.add_dialog(name, dialog) |
self.parent.add_dialog(name, dialog) |
212 |
dialog.Show(True) |
dialog.Show(True) |
213 |
|
|
214 |
self.Close() |
self.Close() |
215 |
|
|
216 |
def OnClose(self, event): |
def OnClose(self, event): |