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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1003 - (hide annotations)
Thu May 22 19:46:34 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: 6780 byte(s)
(JoinDialog.__init__): Make use of TransientTable.Title()

1 jonathan 888 # 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 frank 1000
13     from Thuban.Model.transientdb import TransientJoinedTable
14     from Thuban.UI.tableview import TableFrame, LayerTableFrame
15 jonathan 888
16 frank 1000 ID_LEFT_TABLE = 4001
17     ID_RIGHT_TABLE = 4002
18 jonathan 888
19 frank 1000 CHOICE_WIDTH = 150
20    
21 jonathan 888 class JoinDialog(wxDialog):
22 frank 1000
23     """Table join dialog.
24 jonathan 888
25 frank 1000 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 jonathan 888 def __init__(self, parent, title, session, layer = None):
30     wxDialog.__init__(self, parent, -1, title,
31     style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
32    
33 frank 1000 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 jonathan 888
40 frank 1000 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 jonathan 888
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 frank 1000 EVT_BUTTON(self, wxID_OK, self.OnJoin)
52     #EVT_BUTTON(self, wxID_CANCEL, self.OnClose)
53 jonathan 888
54 frank 1000 self.choice_left_table.Append('Select ...', None)
55     self.choice_right_table.Append('Select ...', None)
56    
57     for t in session.Tables():
58 frank 1003 self.choice_left_table.Append(t.transient_table().Title(), t)
59     self.choice_right_table.Append(t.transient_table().Title(), t)
60 jonathan 888
61 frank 1000 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 jonathan 888 self.button_join.Enable(False)
67    
68     topBox = wxBoxSizer(wxVERTICAL)
69    
70     sizer = wxFlexGridSizer(2, 4)
71 frank 1000 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 jonathan 888
84     sizer.AddGrowableCol(1)
85     sizer.AddGrowableCol(3)
86    
87     topBox.Add(sizer, 1, wxEXPAND|wxALL, 4)
88    
89     sizer = wxBoxSizer(wxHORIZONTAL)
90 frank 1000 sizer.Add(self.button_join, 0, wxEXPAND|wxRIGHT, 10)
91     sizer.Add(self.button_close, 0, wxEXPAND|wxRIGHT, 10)
92 jonathan 888
93 frank 1000 topBox.Add(sizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10)
94 jonathan 888
95     self.SetAutoLayout(True)
96     self.SetSizer(topBox)
97     topBox.Fit(self)
98     topBox.SetSizeHints(self)
99    
100     self.valid = False
101    
102 frank 1000 # Save same parameters for later use.
103     self.db = session.TransientDB()
104     self.parent = parent
105     self.session = session
106 jonathan 888
107 frank 1000 def OnJoin(self, event):
108     """Get the table and field selections and perform the join."""
109     # left
110     i = self.choice_left_table.GetSelection()
111     left_table = self.choice_left_table.GetClientData(i)
112     i = self.choice_left_field.GetSelection()
113     left_field = self.choice_left_field.GetString(i)
114     # right
115     i = self.choice_right_table.GetSelection()
116     right_table = self.choice_right_table.GetClientData(i)
117     i = self.choice_right_field.GetSelection()
118     right_field = self.choice_right_field.GetString(i)
119 jonathan 888
120 frank 1000 result = True
121     try:
122     joined_table = TransientJoinedTable(self.db, left_table, left_field,
123     right_table, right_field)
124     except:
125     exc_type, exc_value, exc_traceback = sys.exc_info()
126     dlg = wxMessageDialog(None, 'Join failed:\n %s' % exc_value,
127     'Info',wxOK|wxICON_ERROR)
128     dlg.ShowModal()
129     dlg.Destroy
130     result = False
131    
132     if result:
133     self.session.AddTable(joined_table)
134     name = joined_table.tablename
135     dialog = TableFrame(self.parent, name,
136     _("Table: %s") % name, joined_table)
137     self.parent.add_dialog(name, dialog)
138     dialog.Show(true)
139    
140     self.Close()
141    
142     def OnClose(self, event):
143     """Close the dialog."""
144     self.Close()
145    
146     def OnLeftTable(self, event):
147     """Get the selected table and fill the field choice."""
148     i = self.choice_left_table.GetSelection()
149     table = self.choice_left_table.GetClientData(i)
150     self.choice_left_field.Clear()
151     for col in table.Columns():
152     self.choice_left_field.Append(col.name, col)
153 jonathan 888
154 frank 1000 sel = self.choice_left_table.GetSelection()
155     rsel = self.choice_right_table.GetSelection()
156     self.valid = sel != -1 and (sel != rsel and rsel != 0)
157 jonathan 888 self.button_join.Enable(self.valid)
158    
159 frank 1000 def OnRightTable(self, event):
160     """Get the selected table and fill the field choice."""
161     i = self.choice_right_table.GetSelection()
162     table = self.choice_right_table.GetClientData(i)
163     self.choice_right_field.Clear()
164     for col in table.Columns():
165     self.choice_right_field.Append(col.name, col)
166 jonathan 888
167 frank 1000 sel = self.choice_right_table.GetSelection()
168     lsel = self.choice_left_table.GetSelection()
169     self.valid = sel != -1 and (sel != lsel and lsel != 0)
170 jonathan 888 self.button_join.Enable(self.valid)
171    

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26