1 |
# Copyright (c) 2001, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2003, 2004 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Martin Mueller <[email protected]> |
# Martin Mueller <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
20 |
|
|
21 |
from Thuban import _ |
from Thuban import _ |
22 |
from Thuban.UI.dialogs import NonModalDialog |
from Thuban.UI.dialogs import NonModalDialog |
23 |
from Thuban.Model.postgisdb import PostGISConnection |
from Thuban.Model.table import FIELDTYPE_INT |
24 |
|
from Thuban.Model.postgisdb import ConnectionError, PostGISConnection |
25 |
from Thuban.Model.messages import DBCONN_ADDED, DBCONN_REMOVED |
from Thuban.Model.messages import DBCONN_ADDED, DBCONN_REMOVED |
26 |
from messages import SESSION_REPLACED |
from messages import SESSION_REPLACED |
27 |
|
|
|
ID_DBADD_OK = 9001 |
|
|
ID_DBADD_CANCEL = 9002 |
|
28 |
|
|
29 |
ID_DB_ADD = 9101 |
ID_DB_ADD = 9101 |
30 |
ID_DB_REMOVE = 9102 |
ID_DB_REMOVE = 9102 |
37 |
|
|
38 |
class ChooseDBTableDialog(wxDialog): |
class ChooseDBTableDialog(wxDialog): |
39 |
|
|
40 |
def __init__(self, session, *args, **kwds): |
def __init__(self, parent, session): |
41 |
kwds["style"] = wxDIALOG_MODAL|wxCAPTION |
wxDialog.__init__(self, parent, -1, _("Choose layer from database"), |
42 |
wxDialog.__init__(self, *args, **kwds) |
style = wxDIALOG_MODAL|wxCAPTION) |
43 |
self.session = session |
self.session = session |
44 |
self.dbconns = self.session.DBConnections() |
self.dbconns = self.session.DBConnections() |
45 |
self.tables = [] |
self.tables = [] |
|
self.list_box_4 = wxListBox(self, -1) |
|
|
for i in range(len(self.dbconns)): |
|
|
self.list_box_4.Append(self.dbconns[i].BriefDescription()) |
|
|
self.DB_CHOOSE_RETRIEVE = wxButton(self, ID_DBCHOOSE_RETRIEVE, |
|
|
_("Retrieve")) |
|
|
self.list_box_5 = wxListBox(self, ID_LB_DCLICK) |
|
|
self.DB_CHOOSE_OK = wxButton(self, ID_DBCHOOSE_OK, _("OK")) |
|
|
self.DB_CHOOSE_CANCEL = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel")) |
|
|
self.__set_properties() |
|
|
self.__do_layout() |
|
46 |
|
|
47 |
EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK) |
# |
48 |
EVT_BUTTON(self, ID_DBCHOOSE_CANCEL, self.OnCancel) |
# Build the dialog |
49 |
EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve) |
# |
50 |
EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick) |
|
51 |
|
# Sizer for the entire dialog |
52 |
|
top = wxFlexGridSizer(2, 1, 0, 0) |
53 |
|
|
54 |
|
# Sizer for the main part with the list boxes |
55 |
|
main_sizer = wxBoxSizer(wxHORIZONTAL) |
56 |
|
top.Add(main_sizer, 1, wxEXPAND, 0) |
57 |
|
|
58 |
|
# The list box with the connections |
59 |
|
static_box = wxStaticBoxSizer(wxStaticBox(self, -1, _("Databases")), |
60 |
|
wxHORIZONTAL) |
61 |
|
self.lb_connections = wxListBox(self, -1) |
62 |
|
static_box.Add(self.lb_connections, 0, wxEXPAND, 0) |
63 |
|
main_sizer.Add(static_box, 1, wxEXPAND, 0) |
64 |
|
|
65 |
def __set_properties(self): |
for i in range(len(self.dbconns)): |
66 |
self.SetTitle(_("Choose layer from database")) |
self.lb_connections.Append(self.dbconns[i].BriefDescription()) |
67 |
self.list_box_4.SetSelection(0) |
if self.lb_connections.GetCount() > 0: |
68 |
self.list_box_5.SetSelection(0) |
self.lb_connections.SetSelection(0, True) |
69 |
|
|
70 |
|
# The button box between the connections list box and the table |
71 |
|
# list box |
72 |
|
buttons = wxFlexGridSizer(3, 1, 0, 0) |
73 |
|
buttons.Add( (20, 80), 0, wxEXPAND, 0) |
74 |
|
retrieve_button = wxButton(self, ID_DBCHOOSE_RETRIEVE, _("Retrieve")) |
75 |
|
EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve) |
76 |
|
buttons.Add(retrieve_button, 0, wxALL |
77 |
|
|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4) |
78 |
|
buttons.Add( (20, 80), 0, wxEXPAND, 0) |
79 |
|
main_sizer.Add(buttons, 0, wxEXPAND, 0) |
80 |
|
|
81 |
def __do_layout(self): |
# The list box with the tables |
82 |
grid_sizer_1 = wxFlexGridSizer(2, 1, 0, 0) |
static_box = wxStaticBoxSizer(wxStaticBox(self, -1, _("Tables")), |
|
grid_sizer_3 = wxFlexGridSizer(1, 2, 0, 0) |
|
|
grid_sizer_2 = wxFlexGridSizer(1, 3, 0, 0) |
|
|
sizer_4 = wxStaticBoxSizer(wxStaticBox(self, -1, _("Tables")), |
|
83 |
wxHORIZONTAL) |
wxHORIZONTAL) |
84 |
grid_sizer_4 = wxFlexGridSizer(3, 1, 0, 0) |
self.lb_tables = wxListBox(self, ID_LB_DCLICK) |
85 |
sizer_3 = wxStaticBoxSizer(wxStaticBox(self, -1, _("Databases")), |
EVT_LISTBOX(self, ID_LB_DCLICK, self.OnTableSelect) |
86 |
wxHORIZONTAL) |
EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick) |
87 |
sizer_3.Add(self.list_box_4, 0, wxEXPAND, 0) |
static_box.Add(self.lb_tables, 0, wxEXPAND, 0) |
88 |
grid_sizer_2.Add(sizer_3, 1, wxEXPAND, 0) |
main_sizer.Add(static_box, 1, wxEXPAND, 0) |
89 |
grid_sizer_4.Add(20, 80, 0, wxEXPAND, 0) |
|
90 |
grid_sizer_4.Add(self.DB_CHOOSE_RETRIEVE, 0, wxALL |
# id column and geometry column selection |
91 |
|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4) |
box = wxBoxSizer(wxVERTICAL) |
92 |
grid_sizer_4.Add(20, 80, 0, wxEXPAND, 0) |
box.Add(wxStaticText(self, -1, _("ID Column")), 0, |
93 |
grid_sizer_2.Add(grid_sizer_4, 1, wxEXPAND, 0) |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
94 |
sizer_4.Add(self.list_box_5, 0, wxEXPAND, 0) |
self.text_id_column = wxComboBox(self, -1, "") |
95 |
grid_sizer_2.Add(sizer_4, 1, wxEXPAND, 0) |
box.Add(self.text_id_column, 0, |
96 |
grid_sizer_1.Add(grid_sizer_2, 1, wxEXPAND, 0) |
wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4) |
97 |
grid_sizer_3.Add(self.DB_CHOOSE_OK, 0, wxALL|wxALIGN_RIGHT, 4) |
|
98 |
grid_sizer_3.Add(self.DB_CHOOSE_CANCEL, 0, wxALL, 4) |
box.Add(wxStaticText(self, -1, _("Geometry Column")), 0, |
99 |
grid_sizer_1.Add(grid_sizer_3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 4) |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
100 |
|
self.text_geo_column = wxComboBox(self, -1, "") |
101 |
|
box.Add(self.text_geo_column, 0, |
102 |
|
wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4) |
103 |
|
main_sizer.Add(box, 1, wxEXPAND, 0) |
104 |
|
|
105 |
|
# The standard button box at the bottom of the dialog |
106 |
|
buttons = wxFlexGridSizer(1, 2, 0, 0) |
107 |
|
ok_button = wxButton(self, ID_DBCHOOSE_OK, _("OK")) |
108 |
|
EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK) |
109 |
|
buttons.Add(ok_button, 0, wxALL|wxALIGN_RIGHT, 4) |
110 |
|
cancel_button = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel")) |
111 |
|
EVT_BUTTON(self, ID_DBCHOOSE_CANCEL, self.OnCancel) |
112 |
|
buttons.Add(cancel_button, 0, wxALL, 4) |
113 |
|
top.Add(buttons, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 4) |
114 |
|
|
115 |
|
# Autosizing |
116 |
self.SetAutoLayout(1) |
self.SetAutoLayout(1) |
117 |
self.SetSizer(grid_sizer_1) |
self.SetSizer(top) |
118 |
grid_sizer_1.Fit(self) |
top.Fit(self) |
119 |
grid_sizer_1.SetSizeHints(self) |
top.SetSizeHints(self) |
120 |
self.Layout() |
self.Layout() |
121 |
|
|
122 |
|
|
123 |
def GetTable(self): |
def GetTable(self): |
124 |
i = self.list_box_5.GetSelection() |
i = self.lb_tables.GetSelection() |
125 |
if i >= 0: |
if i >= 0: |
126 |
return self.selected_conn, self.tables[i] |
return (self.selected_conn, self.tables[i], |
127 |
|
self.text_id_column.GetValue(), |
128 |
|
self.text_geo_column.GetValue()) |
129 |
return None |
return None |
130 |
|
|
131 |
def OnRetrieve(self, event): |
def OnRetrieve(self, event): |
132 |
i = self.list_box_4.GetSelection() |
i = self.lb_connections.GetSelection() |
133 |
if i >= 0: |
if i >= 0: |
134 |
self.selected_conn = self.dbconns[i] |
self.selected_conn = self.dbconns[i] |
135 |
self.tables = self.selected_conn.GeometryTables() |
self.tables = self.selected_conn.GeometryTables() |
136 |
self.list_box_5.Set(self.tables) |
self.lb_tables.Set(self.tables) |
137 |
|
|
138 |
|
def OnTableSelect(self, event): |
139 |
|
i = self.lb_tables.GetSelection() |
140 |
|
self.text_id_column.Clear() |
141 |
|
self.text_geo_column.Clear() |
142 |
|
if i >= 0: |
143 |
|
for name, typ in self.selected_conn.table_columns(self.tables[i]): |
144 |
|
if typ == "geometry": |
145 |
|
self.text_geo_column.Append(name) |
146 |
|
elif typ == FIELDTYPE_INT: |
147 |
|
self.text_id_column.Append(name) |
148 |
|
|
149 |
def OnLBDClick(self, event): |
def OnLBDClick(self, event): |
150 |
if self.list_box_5.GetSelection() >= 0: |
if self.lb_tables.GetSelection() >= 0: |
151 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
152 |
self.Show(false) |
self.Show(False) |
153 |
|
|
154 |
def OnOK(self, event): |
def OnOK(self, event): |
155 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
156 |
self.Show(false) |
self.Show(False) |
157 |
|
|
158 |
def OnCancel(self, event): |
def OnCancel(self, event): |
159 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
160 |
self.Show(false) |
self.Show(False) |
161 |
|
|
162 |
|
|
163 |
class DBDialog(wxDialog): |
class DBDialog(wxDialog): |
164 |
|
|
165 |
"""Dialog for the parameters of a database connection""" |
"""Dialog for the parameters of a database connection""" |
166 |
|
|
167 |
def __init__(self, selection=None, *args, **kwds): |
def __init__(self, parent, title, parameters, message = ""): |
168 |
kwds["style"] = wxDEFAULT_DIALOG_STYLE |
"""Initialize the dialog box. |
|
wxDialog.__init__(self, *args, **kwds) |
|
|
self.DBAdd_Label_Host = wxStaticText(self, -1, _("Hostname:")) |
|
|
self.DBAdd_Host = wxTextCtrl(self, -1, "") |
|
|
self.DBAdd_Label_Port = wxStaticText(self, -1, _("Port:")) |
|
|
self.DBAdd_Port = wxTextCtrl(self, -1, "") |
|
|
self.DBAdd_Label_Database = wxStaticText(self, -1, _("Database:")) |
|
|
self.DBAdd_Database = wxTextCtrl(self, -1, "") |
|
|
self.DBAdd_Label_User = wxStaticText(self, -1, _("User:")) |
|
|
self.DBAdd_User = wxTextCtrl(self, -1, "") |
|
|
self.DBAdd_Label_Pwd = wxStaticText(self, -1, _("Password:")) |
|
|
self.DBAdd_Pwd = wxTextCtrl(self, -1, "", style=wxTE_PASSWORD) |
|
|
self.DBAdd_OK = wxButton(self, ID_DBADD_OK, _("OK")) |
|
|
self.DBAdd_Cancel = wxButton(self, ID_DBADD_CANCEL, _("Cancel")) |
|
|
if selection != None: |
|
|
self.DBAdd_Host.SetEditable(false) |
|
|
self.DBAdd_Host.SetValue(selection.host) |
|
|
self.DBAdd_Port.SetValue(selection.port) |
|
|
self.DBAdd_Database.SetEditable(false) |
|
|
self.DBAdd_Database.SetValue(selection.dbname()) |
|
|
self.DBAdd_User.SetValue(selection.user) |
|
|
self.__set_properties() |
|
|
self.__do_layout() |
|
|
EVT_BUTTON(self, ID_DBADD_OK, self.OnOK) |
|
|
EVT_BUTTON(self, ID_DBADD_CANCEL, self.OnCancel) |
|
169 |
|
|
170 |
def __set_properties(self): |
The parameters argument should be a dictionary containing known |
171 |
self.SetTitle(_("Add database")) |
connection parameters. |
|
self.SetSize((480, 185)) |
|
|
self.DBAdd_Label_Host.SetSize((60, 16)) |
|
|
self.DBAdd_Host.SetSize((200, 22)) |
|
|
self.DBAdd_Label_Database.SetSize((60, 16)) |
|
|
self.DBAdd_Label_User.SetSize((60, 16)) |
|
172 |
|
|
173 |
def __do_layout(self): |
The optional message parameter will be displayed at the top of |
174 |
grid_sizer_1 = wxFlexGridSizer(4, 1, 0, 0) |
the dialog box and can be used to display error messages when |
175 |
grid_sizer_2 = wxGridSizer(1, 2, 0, 0) |
using the dialog to ask for correct parameters when the |
176 |
grid_sizer_5 = wxFlexGridSizer(1, 5, 0, 0) |
connection can't be established. |
177 |
grid_sizer_6 = wxFlexGridSizer(1, 5, 0, 0) |
""" |
178 |
grid_sizer_3 = wxFlexGridSizer(1, 5, 0, 0) |
wxDialog.__init__(self, parent, -1, title) |
179 |
grid_sizer_3.Add(self.DBAdd_Label_Host, 0, |
|
180 |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
top = wxBoxSizer(wxVERTICAL) |
181 |
grid_sizer_3.Add(self.DBAdd_Host, 0, wxALL, 4) |
|
182 |
grid_sizer_3.Add(20, 20, 0, wxALL|wxEXPAND, 4) |
if message: |
183 |
grid_sizer_3.Add(self.DBAdd_Label_Port, 0, |
top.Add(wxStaticText(self, -1, message), 0, |
184 |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
185 |
grid_sizer_3.Add(self.DBAdd_Port, 0, wxALL, 4) |
|
186 |
grid_sizer_1.Add(grid_sizer_3, 1, wxALL|wxEXPAND, 4) |
box = wxBoxSizer(wxHORIZONTAL) |
187 |
grid_sizer_6.Add(self.DBAdd_Label_Database, 0, |
box.Add(wxStaticText(self, -1, _("Hostname:")), 0, |
188 |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
189 |
grid_sizer_6.Add(self.DBAdd_Database, 0, wxALL, 4) |
self.text_host = wxTextCtrl(self, -1, parameters.get("host", "")) |
190 |
grid_sizer_6.Add(20, 20, 0, wxALL|wxEXPAND, 4) |
box.Add(self.text_host, 2, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4) |
191 |
grid_sizer_1.Add(grid_sizer_6, 1, wxALL|wxEXPAND, 4) |
box.Add(wxStaticText(self, -1, _("Port:")), 0, |
192 |
grid_sizer_5.Add(self.DBAdd_Label_User, 0, |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
193 |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
self.text_port = wxTextCtrl(self, -1, parameters.get("port", "")) |
194 |
grid_sizer_5.Add(self.DBAdd_User, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
box.Add(self.text_port, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4) |
195 |
grid_sizer_5.Add(20, 20, 0, wxALL|wxEXPAND, 4) |
top.Add(box, 0, wxEXPAND) |
|
grid_sizer_5.Add(self.DBAdd_Label_Pwd, 0, |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
|
|
grid_sizer_5.Add(self.DBAdd_Pwd, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
|
|
grid_sizer_1.Add(grid_sizer_5, 1, wxALL|wxEXPAND, 4) |
|
|
grid_sizer_2.Add(self.DBAdd_OK, 0, |
|
|
wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 4) |
|
|
grid_sizer_2.Add(self.DBAdd_Cancel, 0, wxALL|wxALIGN_CENTER_VERTICAL, |
|
|
4) |
|
|
grid_sizer_1.Add(grid_sizer_2, 1, wxALL|wxEXPAND, 4) |
|
|
self.SetAutoLayout(1) |
|
|
self.SetSizer(grid_sizer_1) |
|
|
self.Layout() |
|
196 |
|
|
197 |
|
box = wxBoxSizer(wxHORIZONTAL) |
198 |
|
box.Add(wxStaticText(self, -1, _("Database Name:")), 0, |
199 |
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
200 |
|
self.text_dbname = wxTextCtrl(self, -1, |
201 |
|
parameters.get("dbname", "")) |
202 |
|
box.Add(self.text_dbname, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4) |
203 |
|
top.Add(box, 0, wxEXPAND) |
204 |
|
|
205 |
def GetHostname(self): |
box = wxBoxSizer(wxHORIZONTAL) |
206 |
return self.DBAdd_Host.GetValue() |
box.Add(wxStaticText(self, -1, _("User:")), 0, |
207 |
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
208 |
|
self.text_user = wxTextCtrl(self, -1, |
209 |
|
parameters.get("user", "")) |
210 |
|
box.Add(self.text_user, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 4) |
211 |
|
box.Add(wxStaticText(self, -1, _("Password:")), 0, |
212 |
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
213 |
|
self.text_password = wxTextCtrl(self, -1, |
214 |
|
parameters.get("password", ""), |
215 |
|
style = wxTE_PASSWORD) |
216 |
|
box.Add(self.text_password, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, |
217 |
|
4) |
218 |
|
top.Add(box, 0, wxEXPAND) |
219 |
|
|
220 |
def GetPort(self): |
buttons = wxBoxSizer(wxHORIZONTAL) |
221 |
return self.DBAdd_Port.GetValue() |
button = wxButton(self, wxID_OK, _("OK")) |
222 |
|
buttons.Add(button, 0, wxALL, 4) |
223 |
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
224 |
|
buttons.Add(button, 0, wxALL, 4) |
225 |
|
top.Add(buttons, 0, wxALIGN_RIGHT, 4) |
226 |
|
|
227 |
def GetDatabase(self): |
self.SetAutoLayout(1) |
228 |
return self.DBAdd_Database.GetValue() |
self.SetSizer(top) |
229 |
|
top.Fit(self) |
230 |
|
top.SetSizeHints(self) |
231 |
|
|
232 |
def GetUser(self): |
EVT_BUTTON(self, wxID_OK, self.OnOK) |
233 |
return self.DBAdd_User.GetValue() |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
234 |
|
|
235 |
def GetPassword(self): |
def RunDialog(self): |
236 |
return self.DBAdd_Pwd.GetValue() |
self.ShowModal() |
237 |
|
self.Destroy() |
238 |
|
return self.result |
239 |
|
|
240 |
|
def end_dialog(self, result): |
241 |
|
self.result = result |
242 |
|
if result is not None: |
243 |
|
self.EndModal(wxID_OK) |
244 |
|
else: |
245 |
|
self.EndModal(wxID_CANCEL) |
246 |
|
self.Show(False) |
247 |
|
|
248 |
def OnOK(self, event): |
def OnOK(self, event): |
249 |
self.EndModal(wxID_OK) |
result = {} |
250 |
self.Show(false) |
for name in ("host", "port", "dbname", "user", "password"): |
251 |
|
result[name] = getattr(self, "text_" + name).GetValue() |
252 |
|
self.end_dialog(result) |
253 |
|
|
254 |
def OnCancel(self, event): |
def OnCancel(self, event): |
255 |
self.EndModal(wxID_CANCEL) |
self.end_dialog(None) |
256 |
self.Show(false) |
|
257 |
|
|
258 |
|
|
259 |
class DBFrame(NonModalDialog): |
class DBFrame(NonModalDialog): |
285 |
def __set_properties(self): |
def __set_properties(self): |
286 |
self.SetTitle(_("Database Management")) |
self.SetTitle(_("Database Management")) |
287 |
self.DB_ListBox.SetSize((200, 157)) |
self.DB_ListBox.SetSize((200, 157)) |
|
self.DB_ListBox.SetSelection(0) |
|
288 |
|
|
289 |
def __do_layout(self): |
def __do_layout(self): |
290 |
top = wxBoxSizer(wxVERTICAL) |
top = wxBoxSizer(wxVERTICAL) |
334 |
def conns_changed(self, *args): |
def conns_changed(self, *args): |
335 |
"""Internal: update the db connection list box |
"""Internal: update the db connection list box |
336 |
|
|
337 |
Subscribed to the DBCONN_REMOVED and DBCONN_REMOVED. |
Subscribed to the DBCONN_ADDED and DBCONN_REMOVED messages. |
338 |
""" |
""" |
339 |
self.DB_ListBox.Clear() |
self.DB_ListBox.Clear() |
340 |
for conn in self.session.DBConnections(): |
for conn in self.session.DBConnections(): |
355 |
return result |
return result |
356 |
|
|
357 |
def OnAdd(self, event): |
def OnAdd(self, event): |
358 |
adddialog = DBDialog(None, self, -1, "") |
message = "" |
359 |
|
parameters = {} |
360 |
while 1: |
while 1: |
361 |
if adddialog.ShowModal() == wxID_OK: |
dialog = DBDialog(self, _("Add Database"), parameters, message) |
362 |
host = adddialog.GetHostname() |
parameters = dialog.RunDialog() |
363 |
port = adddialog.GetPort() |
if parameters is not None: |
|
database = adddialog.GetDatabase() |
|
|
user = adddialog.GetUser() |
|
|
password = adddialog.GetPassword() |
|
364 |
for conn in self.session.DBConnections(): |
for conn in self.session.DBConnections(): |
365 |
if (host == conn.host and |
if conn.MatchesParameters(parameters): |
|
database == conn.dbname): |
|
366 |
self.RunMessageBox(_("Add Database"), |
self.RunMessageBox(_("Add Database"), |
367 |
_("Connection to '%s' already exists") |
_("Connection '%s' already exists") |
368 |
% database) |
% conn.BriefDescription()) |
369 |
|
break |
370 |
|
else: |
371 |
|
try: |
372 |
|
conn = PostGISConnection(**parameters) |
373 |
|
except ConnectionError, val: |
374 |
|
message = str(val) |
375 |
|
else: |
376 |
|
self.session.AddDBConnection(conn) |
377 |
break |
break |
|
try: |
|
|
conn = PostGISConnection(database, host = host, port=port, |
|
|
user = user, password = password) |
|
|
self.session.AddDBConnection(conn) |
|
|
break |
|
|
except psycopg.OperationalError, strerror: |
|
|
self.RunMessageBox(_("Error"), str(strerror)) |
|
|
except: |
|
|
self.RunMessageBox(_("Add Database"), |
|
|
_("Can't establish connection to '%s'." |
|
|
% database)) |
|
378 |
else: |
else: |
379 |
break |
break |
|
adddialog.Destroy() |
|
380 |
|
|
381 |
def OnRemove(self, event): |
def OnRemove(self, event): |
382 |
i = self.DB_ListBox.GetSelection() |
i = self.DB_ListBox.GetSelection() |