13 |
|
|
14 |
|
|
15 |
import sys |
import sys |
16 |
from wxPython.wx import * |
import wx |
17 |
|
|
18 |
from Thuban import _ |
from Thuban import _ |
19 |
|
|
28 |
|
|
29 |
CHOICE_WIDTH = 150 |
CHOICE_WIDTH = 150 |
30 |
|
|
31 |
class JoinDialog(wxDialog): |
class JoinDialog(wx.Dialog): |
32 |
|
|
33 |
"""Table join dialog. |
"""Table join dialog. |
34 |
|
|
37 |
""" |
""" |
38 |
|
|
39 |
def __init__(self, parent, title, session, layer = None): |
def __init__(self, parent, title, session, layer = None): |
40 |
wxDialog.__init__(self, parent, -1, title, |
wx.Dialog.__init__(self, parent, -1, title, |
41 |
style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) |
style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) |
42 |
self.layer = layer |
self.layer = layer |
43 |
|
|
44 |
if not layer: |
if not layer: |
45 |
self.choice_left_table = wxChoice(self, ID_LEFT_TABLE) |
self.choice_left_table = wx.Choice(self, ID_LEFT_TABLE) |
46 |
width, height = self.choice_left_table.GetSizeTuple() |
width, height = self.choice_left_table.GetSizeTuple() |
47 |
self.choice_left_table.SetSize(wxSize(CHOICE_WIDTH, height)) |
self.choice_left_table.SetSize(wx.Size(CHOICE_WIDTH, height)) |
48 |
self.left_table = None |
self.left_table = None |
49 |
else: |
else: |
50 |
self.choice_left_table = None |
self.choice_left_table = None |
51 |
self.left_table = layer.ShapeStore().Table() |
self.left_table = layer.ShapeStore().Table() |
52 |
|
|
53 |
self.choice_right_table = wxChoice(self, ID_RIGHT_TABLE) |
self.choice_right_table = wx.Choice(self, ID_RIGHT_TABLE) |
54 |
width, height = self.choice_right_table.GetSizeTuple() |
width, height = self.choice_right_table.GetSizeTuple() |
55 |
self.choice_right_table.SetSize(wxSize(CHOICE_WIDTH, height)) |
self.choice_right_table.SetSize(wx.Size(CHOICE_WIDTH, height)) |
56 |
|
|
57 |
self.choice_left_field = wxChoice(self, -1) |
self.choice_left_field = wx.Choice(self, -1) |
58 |
width, height = self.choice_left_field.GetSizeTuple() |
width, height = self.choice_left_field.GetSizeTuple() |
59 |
self.choice_left_field.SetSize(wxSize(CHOICE_WIDTH, height)) |
self.choice_left_field.SetSize(wx.Size(CHOICE_WIDTH, height)) |
60 |
self.choice_right_field = wxChoice(self, -1) |
self.choice_right_field = wx.Choice(self, -1) |
61 |
width, height = self.choice_right_field.GetSizeTuple() |
width, height = self.choice_right_field.GetSizeTuple() |
62 |
self.choice_right_field.SetSize(wxSize(CHOICE_WIDTH, height)) |
self.choice_right_field.SetSize(wx.Size(CHOICE_WIDTH, height)) |
63 |
|
|
64 |
self.button_join = wxButton(self, wxID_OK, _("Join")) |
self.button_join = wx.Button(self, wx.ID_OK, _("Join")) |
65 |
self.button_join.SetDefault() |
self.button_join.SetDefault() |
66 |
self.button_close = wxButton(self, wxID_CANCEL, _("Close")) |
self.button_close = wx.Button(self, wx.ID_CANCEL, _("Close")) |
67 |
|
|
68 |
EVT_BUTTON(self, wxID_OK, self.OnJoin) |
self.Bind(wx.EVT_BUTTON, self.OnJoin, id=wx.ID_OK) |
69 |
|
|
70 |
if self.choice_left_table is not None: |
if self.choice_left_table is not None: |
71 |
self.choice_left_table.Append(_('Select...'), None) |
self.choice_left_table.Append(_('Select...'), None) |
86 |
self.choice_left_field.Append(col.name, col) |
self.choice_left_field.Append(col.name, col) |
87 |
|
|
88 |
if self.choice_left_table is not None: |
if self.choice_left_table is not None: |
89 |
EVT_CHOICE(self, ID_LEFT_TABLE, self.OnLeftTable) |
self.Bind(wx.EVT_CHOICE, self.OnLeftTable, id=ID_LEFT_TABLE) |
90 |
EVT_CHOICE(self, ID_RIGHT_TABLE, self.OnRightTable) |
self.Bind(wx.EVT_CHOICE, self.OnRightTable, id=ID_RIGHT_TABLE) |
91 |
|
|
92 |
if self.choice_left_table is not None: |
if self.choice_left_table is not None: |
93 |
self.choice_left_table.SetSelection(0) |
self.choice_left_table.SetSelection(0) |
94 |
self.choice_right_table.SetSelection(0) |
self.choice_right_table.SetSelection(0) |
95 |
self.button_join.Enable(False) |
self.button_join.Enable(False) |
96 |
|
|
97 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wx.BoxSizer(wx.VERTICAL) |
98 |
|
|
99 |
sizer = wxFlexGridSizer(2, 4) |
sizer = wx.FlexGridSizer(2, 4) |
100 |
sizer.Add(wxStaticText(self, -1, _("Table:")), 0, wxALL, 4) |
sizer.Add(wx.StaticText(self, -1, _("Table:")), 0, wx.ALL, 4) |
101 |
if self.choice_left_table is not None: |
if self.choice_left_table is not None: |
102 |
sizer.Add(self.choice_left_table, 1, |
sizer.Add(self.choice_left_table, 1, |
103 |
wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4) |
104 |
else: |
else: |
105 |
sizer.Add(wxStaticText(self, -1, self.left_table.Title()), 0, |
sizer.Add(wx.StaticText(self, -1, self.left_table.Title()), 0, |
106 |
wxALL, 4) |
wx.ALL, 4) |
107 |
|
|
108 |
sizer.Add(wxStaticText(self, -1, _("Table:")), 0, wxALL, 4) |
sizer.Add(wx.StaticText(self, -1, _("Table:")), 0, wx.ALL, 4) |
109 |
sizer.Add(self.choice_right_table, 1, |
sizer.Add(self.choice_right_table, 1, |
110 |
wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4) |
111 |
sizer.Add(wxStaticText(self, -1, _("Field:")), 0, wxALL, 4) |
sizer.Add(wx.StaticText(self, -1, _("Field:")), 0, wx.ALL, 4) |
112 |
sizer.Add(self.choice_left_field, 1, |
sizer.Add(self.choice_left_field, 1, |
113 |
wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4) |
114 |
sizer.Add(wxStaticText(self, -1, _("Field:")), 0, wxALL, 4) |
sizer.Add(wx.StaticText(self, -1, _("Field:")), 0, wx.ALL, 4) |
115 |
sizer.Add(self.choice_right_field, 1, |
sizer.Add(self.choice_right_field, 1, |
116 |
wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4) |
117 |
|
|
118 |
sizer.AddGrowableCol(1) |
sizer.AddGrowableCol(1) |
119 |
sizer.AddGrowableCol(3) |
sizer.AddGrowableCol(3) |
120 |
|
|
121 |
topBox.Add(sizer, 0, wxEXPAND|wxALL, 4) |
topBox.Add(sizer, 0, wx.EXPAND|wx.ALL, 4) |
122 |
|
|
123 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
124 |
self.check_outer_join = wxCheckBox(self,-1, |
self.check_outer_join = wx.CheckBox(self,-1, |
125 |
_("Outer Join (preserves left table records)")) |
_("Outer Join (preserves left table records)")) |
126 |
sizer.Add(self.check_outer_join, 1, wxALL,4) |
sizer.Add(self.check_outer_join, 1, wx.ALL,4) |
127 |
topBox.Add(sizer, 0, wxALIGN_LEFT|wxALIGN_TOP, 4) |
topBox.Add(sizer, 0, wx.ALIGN_LEFT|wx.ALIGN_TOP, 4) |
128 |
|
|
129 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
130 |
sizer.Add(self.button_join, 0, wxALIGN_RIGHT|wxALIGN_BOTTOM|wxRIGHT, |
sizer.Add(self.button_join, 0, wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM|wx.RIGHT, |
131 |
10) |
10) |
132 |
sizer.Add(self.button_close, 0, wxALIGN_RIGHT|wxALIGN_BOTTOM|wxRIGHT, |
sizer.Add(self.button_close, 0, wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM|wx.RIGHT, |
133 |
10) |
10) |
134 |
|
|
135 |
topBox.Add(sizer, 1, wxALIGN_RIGHT|wxALIGN_BOTTOM|wxBOTTOM|wxTOP, 10) |
topBox.Add(sizer, 1, wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM|wx.BOTTOM|wx.TOP, 10) |
136 |
|
|
137 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
138 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
160 |
right_table = self.choice_right_table.GetClientData(i) |
right_table = self.choice_right_table.GetClientData(i) |
161 |
i = self.choice_right_field.GetSelection() |
i = self.choice_right_field.GetSelection() |
162 |
right_field = self.choice_right_field.GetString(i) |
right_field = self.choice_right_field.GetString(i) |
163 |
|
|
164 |
outer_join = self.check_outer_join.IsChecked() |
outer_join = self.check_outer_join.IsChecked() |
165 |
|
|
166 |
try: |
try: |
167 |
joined_table = TransientJoinedTable(self.session.TransientDB(), |
joined_table = TransientJoinedTable(self.session.TransientDB(), |
168 |
left_table, left_field, |
left_table, left_field, |
169 |
right_table, right_field, |
right_table, right_field, |
170 |
outer_join) |
outer_join) |
171 |
except: |
except: |
172 |
dlg = wxMessageDialog(None, |
dlg = wx.MessageDialog(None, |
173 |
_('Join failed:\n %s') % sys.exc_info()[1], |
_('Join failed:\n %s') % sys.exc_info()[1], |
174 |
_('Info'), wxOK|wxICON_ERROR) |
_('Info'), wx.OK|wx.ICON_ERROR) |
175 |
dlg.ShowModal() |
dlg.ShowModal() |
176 |
dlg.Destroy() |
dlg.Destroy() |
177 |
return |
return |
178 |
|
|
179 |
joined_table = self.session.AddTable(joined_table) |
joined_table = self.session.AddTable(joined_table) |
180 |
|
|
181 |
if self.layer is not None: |
if self.layer is not None: |
197 |
" to be used with the selected layer") \ |
" to be used with the selected layer") \ |
198 |
% {"joined": joined_rows, |
% {"joined": joined_rows, |
199 |
"needed": needed_rows} |
"needed": needed_rows} |
200 |
dlg = wxMessageDialog(None, msg, _('Join Failed'), |
dlg = wx.MessageDialog(None, msg, _('Join Failed'), |
201 |
wxOK|wxICON_ERROR) |
wx.OK|wx.ICON_ERROR) |
202 |
dlg.ShowModal() |
dlg.ShowModal() |
203 |
dlg.Destroy() |
dlg.Destroy() |
204 |
return |
return |
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): |