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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1010 - (show annotations)
Fri May 23 08:27:20 2003 UTC (21 years, 9 months ago) by frank
Original Path: trunk/thuban/Thuban/UI/join.py
File MIME type: text/x-python
File size: 7213 byte(s)
(JoinDialog.__init__): Checkbox for outer join.
(JoinDialog.OnJoin): Consider outer join check box.

1 # Copyright (c) 2003 by Intevation GmbH
2 # Authors:
3 # Jonathan Coles <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 import os, sys, math
9 from wxPython.wx import *
10
11 from Thuban import _
12
13 from Thuban.Model.transientdb import TransientJoinedTable
14 from Thuban.UI.tableview import TableFrame, LayerTableFrame
15
16 ID_LEFT_TABLE = 4001
17 ID_RIGHT_TABLE = 4002
18
19 CHOICE_WIDTH = 150
20
21 class JoinDialog(wxDialog):
22
23 """Table join dialog.
24
25 Join two tables (left/right) based on the user selected fields.
26 Opens a TableFrame and registers the new table with the session.
27 """
28
29 def __init__(self, parent, title, session, layer = None):
30 wxDialog.__init__(self, parent, -1, title,
31 style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
32
33 self.choice_left_table = wxChoice(self, ID_LEFT_TABLE)
34 width, height = self.choice_left_table.GetSizeTuple()
35 self.choice_left_table.SetSize(wxSize(CHOICE_WIDTH, height))
36 self.choice_right_table = wxChoice(self, ID_RIGHT_TABLE)
37 width, height = self.choice_right_table.GetSizeTuple()
38 self.choice_right_table.SetSize(wxSize(CHOICE_WIDTH, height))
39
40 self.choice_left_field = wxChoice(self, -1)
41 width, height = self.choice_left_field.GetSizeTuple()
42 self.choice_left_field.SetSize(wxSize(CHOICE_WIDTH, height))
43 self.choice_right_field = wxChoice(self, -1)
44 width, height = self.choice_right_field.GetSizeTuple()
45 self.choice_right_field.SetSize(wxSize(CHOICE_WIDTH, height))
46
47 self.button_join = wxButton(self, wxID_OK, _("Join"))
48 self.button_join.SetDefault()
49 self.button_close = wxButton(self, wxID_CANCEL, _("Close"))
50
51 EVT_BUTTON(self, wxID_OK, self.OnJoin)
52 #EVT_BUTTON(self, wxID_CANCEL, self.OnClose)
53
54 self.choice_left_table.Append('Select ...', None)
55 self.choice_right_table.Append('Select ...', None)
56
57 for t in session.Tables():
58 self.choice_left_table.Append(t.transient_table().Title(), t)
59 self.choice_right_table.Append(t.transient_table().Title(), t)
60
61 EVT_CHOICE(self, ID_LEFT_TABLE, self.OnLeftTable)
62 EVT_CHOICE(self, ID_RIGHT_TABLE, self.OnRightTable)
63
64 self.choice_left_table.SetSelection(0)
65 self.choice_right_table.SetSelection(0)
66 self.button_join.Enable(False)
67
68 topBox = wxBoxSizer(wxVERTICAL)
69
70 sizer = wxFlexGridSizer(2, 4)
71 sizer.Add(wxStaticText(self, -1, _("Table:")), 0, wxALL, 4)
72 sizer.Add(self.choice_left_table, 1,
73 wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4)
74 sizer.Add(wxStaticText(self, -1, _("Table:")), 0, wxALL, 4)
75 sizer.Add(self.choice_right_table, 1,
76 wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4)
77 sizer.Add(wxStaticText(self, -1, _("Field:")), 0, wxALL, 4)
78 sizer.Add(self.choice_left_field, 1,
79 wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4)
80 sizer.Add(wxStaticText(self, -1, _("Field:")), 0, wxALL, 4)
81 sizer.Add(self.choice_right_field, 1,
82 wxEXPAND|wxALL|wxALIGN_CENTER_VERTICAL, 4)
83
84 sizer.AddGrowableCol(1)
85 sizer.AddGrowableCol(3)
86
87 topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)
88
89 sizer = wxBoxSizer(wxHORIZONTAL)
90 self.check_outer_join = wxCheckBox(self,-1,
91 _("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 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)
102 self.SetSizer(topBox)
103 topBox.Fit(self)
104 topBox.SetSizeHints(self)
105
106 self.valid = False
107
108 # Save same parameters for later use.
109 self.db = session.TransientDB()
110 self.parent = parent
111 self.session = session
112
113 def OnJoin(self, event):
114 """Get the table and field selections and perform the join."""
115 # left
116 i = self.choice_left_table.GetSelection()
117 left_table = self.choice_left_table.GetClientData(i)
118 i = self.choice_left_field.GetSelection()
119 left_field = self.choice_left_field.GetString(i)
120 # right
121 i = self.choice_right_table.GetSelection()
122 right_table = self.choice_right_table.GetClientData(i)
123 i = self.choice_right_field.GetSelection()
124 right_field = self.choice_right_field.GetString(i)
125
126 outer_join = self.check_outer_join.IsChecked()
127
128 result = True
129 try:
130 joined_table = TransientJoinedTable(self.db,
131 left_table, left_field,
132 right_table, right_field,
133 outer_join)
134 except:
135 dlg = wxMessageDialog(None, 'Join failed:\n %s'%sys.exc_info()[1],
136 'Info',wxOK|wxICON_ERROR)
137 dlg.ShowModal()
138 dlg.Destroy()
139 result = False
140
141 if result:
142 self.session.AddTable(joined_table)
143 name = joined_table.tablename
144 dialog = TableFrame(self.parent, name,
145 _("Table: %s") % name, joined_table)
146 self.parent.add_dialog(name, dialog)
147 dialog.Show(true)
148
149 self.Close()
150
151 def OnClose(self, event):
152 """Close the dialog."""
153 self.Close()
154
155 def OnLeftTable(self, event):
156 """Get the selected table and fill the field choice."""
157 i = self.choice_left_table.GetSelection()
158 table = self.choice_left_table.GetClientData(i)
159 self.choice_left_field.Clear()
160 for col in table.Columns():
161 self.choice_left_field.Append(col.name, col)
162
163 sel = self.choice_left_table.GetSelection()
164 rsel = self.choice_right_table.GetSelection()
165 self.valid = sel != -1 and (sel != rsel and rsel != 0)
166 self.button_join.Enable(self.valid)
167
168 def OnRightTable(self, event):
169 """Get the selected table and fill the field choice."""
170 i = self.choice_right_table.GetSelection()
171 table = self.choice_right_table.GetClientData(i)
172 self.choice_right_field.Clear()
173 for col in table.Columns():
174 self.choice_right_field.Append(col.name, col)
175
176 sel = self.choice_right_table.GetSelection()
177 lsel = self.choice_left_table.GetSelection()
178 self.valid = sel != -1 and (sel != lsel and lsel != 0)
179 self.button_join.Enable(self.valid)
180

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26