36 |
|
|
37 |
class ChooseDBTableDialog(wxDialog): |
class ChooseDBTableDialog(wxDialog): |
38 |
|
|
39 |
def __init__(self, session, *args, **kwds): |
def __init__(self, parent, session): |
40 |
kwds["style"] = wxDIALOG_MODAL|wxCAPTION |
wxDialog.__init__(self, parent, -1, _("Choose layer from database"), |
41 |
wxDialog.__init__(self, *args, **kwds) |
style = wxDIALOG_MODAL|wxCAPTION) |
42 |
self.session = session |
self.session = session |
43 |
self.dbconns = self.session.DBConnections() |
self.dbconns = self.session.DBConnections() |
44 |
self.tables = [] |
self.tables = [] |
45 |
self.list_box_4 = wxListBox(self, -1) |
self.list_box_4 = wxListBox(self, -1) |
46 |
for i in range(len(self.dbconns)): |
for i in range(len(self.dbconns)): |
47 |
self.list_box_4.Append(self.dbconns[i].BriefDescription()) |
self.list_box_4.Append(self.dbconns[i].BriefDescription()) |
48 |
|
if self.list_box_4.GetCount() > 0: |
49 |
|
self.list_box_4.SetSelection(0, True) |
50 |
self.DB_CHOOSE_RETRIEVE = wxButton(self, ID_DBCHOOSE_RETRIEVE, |
self.DB_CHOOSE_RETRIEVE = wxButton(self, ID_DBCHOOSE_RETRIEVE, |
51 |
_("Retrieve")) |
_("Retrieve")) |
52 |
self.list_box_5 = wxListBox(self, ID_LB_DCLICK) |
self.list_box_5 = wxListBox(self, ID_LB_DCLICK) |
53 |
self.DB_CHOOSE_OK = wxButton(self, ID_DBCHOOSE_OK, _("OK")) |
self.DB_CHOOSE_OK = wxButton(self, ID_DBCHOOSE_OK, _("OK")) |
54 |
self.DB_CHOOSE_CANCEL = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel")) |
self.DB_CHOOSE_CANCEL = wxButton(self, ID_DBCHOOSE_CANCEL, _("Cancel")) |
|
self.__set_properties() |
|
55 |
self.__do_layout() |
self.__do_layout() |
56 |
|
|
57 |
EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK) |
EVT_BUTTON(self, ID_DBCHOOSE_OK, self.OnOK) |
59 |
EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve) |
EVT_BUTTON(self, ID_DBCHOOSE_RETRIEVE, self.OnRetrieve) |
60 |
EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick) |
EVT_LISTBOX_DCLICK(self, ID_LB_DCLICK, self.OnLBDClick) |
61 |
|
|
|
|
|
|
def __set_properties(self): |
|
|
self.SetTitle(_("Choose layer from database")) |
|
|
self.list_box_4.SetSelection(0) |
|
|
self.list_box_5.SetSelection(0) |
|
|
|
|
62 |
def __do_layout(self): |
def __do_layout(self): |
63 |
grid_sizer_1 = wxFlexGridSizer(2, 1, 0, 0) |
grid_sizer_1 = wxFlexGridSizer(2, 1, 0, 0) |
64 |
grid_sizer_3 = wxFlexGridSizer(1, 2, 0, 0) |
grid_sizer_3 = wxFlexGridSizer(1, 2, 0, 0) |
103 |
def OnLBDClick(self, event): |
def OnLBDClick(self, event): |
104 |
if self.list_box_5.GetSelection() >= 0: |
if self.list_box_5.GetSelection() >= 0: |
105 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
106 |
self.Show(false) |
self.Show(False) |
107 |
|
|
108 |
def OnOK(self, event): |
def OnOK(self, event): |
109 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
110 |
self.Show(false) |
self.Show(False) |
111 |
|
|
112 |
def OnCancel(self, event): |
def OnCancel(self, event): |
113 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
114 |
self.Show(false) |
self.Show(False) |
115 |
|
|
116 |
|
|
117 |
class DBDialog(wxDialog): |
class DBDialog(wxDialog): |
197 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
198 |
else: |
else: |
199 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
200 |
self.Show(false) |
self.Show(False) |
201 |
|
|
202 |
def OnOK(self, event): |
def OnOK(self, event): |
203 |
result = {} |
result = {} |
239 |
def __set_properties(self): |
def __set_properties(self): |
240 |
self.SetTitle(_("Database Management")) |
self.SetTitle(_("Database Management")) |
241 |
self.DB_ListBox.SetSize((200, 157)) |
self.DB_ListBox.SetSize((200, 157)) |
|
self.DB_ListBox.SetSelection(0) |
|
242 |
|
|
243 |
def __do_layout(self): |
def __do_layout(self): |
244 |
top = wxBoxSizer(wxVERTICAL) |
top = wxBoxSizer(wxVERTICAL) |
288 |
def conns_changed(self, *args): |
def conns_changed(self, *args): |
289 |
"""Internal: update the db connection list box |
"""Internal: update the db connection list box |
290 |
|
|
291 |
Subscribed to the DBCONN_REMOVED and DBCONN_REMOVED. |
Subscribed to the DBCONN_ADDED and DBCONN_REMOVED messages. |
292 |
""" |
""" |
293 |
self.DB_ListBox.Clear() |
self.DB_ListBox.Clear() |
294 |
for conn in self.session.DBConnections(): |
for conn in self.session.DBConnections(): |
315 |
dialog = DBDialog(self, _("Add Database"), parameters, message) |
dialog = DBDialog(self, _("Add Database"), parameters, message) |
316 |
parameters = dialog.RunDialog() |
parameters = dialog.RunDialog() |
317 |
if parameters is not None: |
if parameters is not None: |
|
host = parameters["host"] |
|
|
database = parameters["dbname"] |
|
318 |
for conn in self.session.DBConnections(): |
for conn in self.session.DBConnections(): |
319 |
if (host == conn.host and |
if conn.MatchesParameters(parameters): |
|
database == conn.dbname): |
|
320 |
self.RunMessageBox(_("Add Database"), |
self.RunMessageBox(_("Add Database"), |
321 |
_("Connection to '%s' already exists") |
_("Connection '%s' already exists") |
322 |
% database) |
% conn.BriefDescription()) |
323 |
break |
break |
|
try: |
|
|
conn = PostGISConnection(**parameters) |
|
|
except ConnectionError, val: |
|
|
message = str(val) |
|
324 |
else: |
else: |
325 |
self.session.AddDBConnection(conn) |
try: |
326 |
break |
conn = PostGISConnection(**parameters) |
327 |
|
except ConnectionError, val: |
328 |
|
message = str(val) |
329 |
|
else: |
330 |
|
self.session.AddDBConnection(conn) |
331 |
|
break |
332 |
else: |
else: |
333 |
break |
break |
334 |
|
|