29 |
|
|
30 |
ID_DB_ADD = 9101 |
ID_DB_ADD = 9101 |
31 |
ID_DB_REMOVE = 9102 |
ID_DB_REMOVE = 9102 |
|
ID_DB_EDIT = 9103 |
|
32 |
|
|
33 |
ID_DBCHOOSE_RETRIEVE = 9201 |
ID_DBCHOOSE_RETRIEVE = 9201 |
34 |
ID_DBCHOOSE_OK = 9202 |
ID_DBCHOOSE_OK = 9202 |
35 |
ID_DBCHOOSE_CANCEL = 9203 |
ID_DBCHOOSE_CANCEL = 9203 |
36 |
ID_LB_DCLICK = 9204 |
ID_LB_DCLICK = 9204 |
37 |
|
|
|
ID_DBPASSWD_OK = 9301 |
|
|
ID_DBPASSWD_CANCEL = 9202 |
|
|
|
|
|
|
|
|
class DBPwdDlg(wxDialog): |
|
|
|
|
|
def __init__(self, user, *args, **kwds): |
|
|
kwds["style"] = wxDIALOG_MODAL|wxCAPTION |
|
|
wxDialog.__init__(self, *args, **kwds) |
|
|
self.DBPWD_label = wxStaticText(self, -1, |
|
|
_("Please enter the password:")) |
|
|
self.DBPWD_label_user = wxStaticText(self, -1, _("User:")) |
|
|
self.DBPWD_user = wxTextCtrl(self, -1, user) |
|
|
self.DBPWD_label_passwd = wxStaticText(self, -1, _("Password:")) |
|
|
self.DBPWD_passwd = wxTextCtrl(self, -1, "", style=wxTE_PASSWORD) |
|
|
self.DBPWD_button_ok = wxButton(self, ID_DBPASSWD_OK, _("OK")) |
|
|
self.DBPWD_button_cancel = wxButton(self, ID_DBPASSWD_CANCEL, |
|
|
_("Cancel")) |
|
|
|
|
|
EVT_BUTTON(self, ID_DBPASSWD_OK, self.OnOK) |
|
|
EVT_BUTTON(self, ID_DBPASSWD_CANCEL, self.OnCancel) |
|
|
|
|
|
self.__set_properties() |
|
|
self.__do_layout() |
|
|
|
|
|
def __set_properties(self): |
|
|
self.SetTitle(_("Enter Password")) |
|
|
self.DBPWD_button_ok.SetDefault() |
|
|
|
|
|
def __do_layout(self): |
|
|
grid_sizer_1 = wxFlexGridSizer(3, 1, 0, 0) |
|
|
grid_sizer_3 = wxFlexGridSizer(1, 2, 0, 0) |
|
|
grid_sizer_2 = wxFlexGridSizer(2, 2, 0, 0) |
|
|
grid_sizer_1.Add(self.DBPWD_label, 0, wxALL, 4) |
|
|
grid_sizer_2.Add(self.DBPWD_label_user, 0, wxALL, 4) |
|
|
grid_sizer_2.Add(self.DBPWD_user, 0, wxALL, 4) |
|
|
grid_sizer_2.Add(self.DBPWD_label_passwd, 0, wxALL, 4) |
|
|
grid_sizer_2.Add(self.DBPWD_passwd, 0, wxALL, 4) |
|
|
grid_sizer_1.Add(grid_sizer_2, 1, wxALIGN_CENTER_HORIZONTAL, 0) |
|
|
grid_sizer_3.Add(self.DBPWD_button_ok, 0, |
|
|
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4) |
|
|
grid_sizer_3.Add(self.DBPWD_button_cancel, 0, |
|
|
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4) |
|
|
grid_sizer_1.Add(grid_sizer_3, 1, |
|
|
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4) |
|
|
self.SetAutoLayout(1) |
|
|
self.SetSizer(grid_sizer_1) |
|
|
grid_sizer_1.Fit(self) |
|
|
grid_sizer_1.SetSizeHints(self) |
|
|
self.Layout() |
|
|
|
|
|
def OnOK(self, event): |
|
|
self.EndModal(wxID_OK) |
|
|
self.Show(false) |
|
|
|
|
|
def OnCancel(self, event): |
|
|
self.EndModal(wxID_CANCEL) |
|
|
self.Show(false) |
|
|
|
|
|
def GetUser(self): |
|
|
return self.DBPWD_user.GetValue() |
|
|
|
|
|
def GetPasswd(self): |
|
|
return self.DBPWD_passwd.GetValue() |
|
|
|
|
38 |
|
|
39 |
class ChooseDBTableDialog(wxDialog): |
class ChooseDBTableDialog(wxDialog): |
40 |
|
|
238 |
style=wxLB_SINGLE|wxLB_HSCROLL|wxLB_ALWAYS_SB) |
style=wxLB_SINGLE|wxLB_HSCROLL|wxLB_ALWAYS_SB) |
239 |
self.DB_Add = wxButton(self, ID_DB_ADD, _("Add")) |
self.DB_Add = wxButton(self, ID_DB_ADD, _("Add")) |
240 |
self.DB_Remove = wxButton(self, ID_DB_REMOVE, _("Remove")) |
self.DB_Remove = wxButton(self, ID_DB_REMOVE, _("Remove")) |
|
#self.DB_Edit = wxButton(self, ID_DB_EDIT, _("Edit")) |
|
241 |
self.DB_CLOSE = wxButton(self, wxID_CLOSE, _("Close")) |
self.DB_CLOSE = wxButton(self, wxID_CLOSE, _("Close")) |
242 |
self.__set_properties() |
self.__set_properties() |
243 |
self.__do_layout() |
self.__do_layout() |
244 |
EVT_BUTTON(self, ID_DB_ADD, self.OnAdd) |
EVT_BUTTON(self, ID_DB_ADD, self.OnAdd) |
245 |
EVT_BUTTON(self, ID_DB_REMOVE, self.OnRemove) |
EVT_BUTTON(self, ID_DB_REMOVE, self.OnRemove) |
|
#EVT_BUTTON(self, ID_DB_EDIT, self.OnEdit) |
|
246 |
EVT_BUTTON(self, wxID_CLOSE, self.OnClose) |
EVT_BUTTON(self, wxID_CLOSE, self.OnClose) |
247 |
|
|
248 |
self.conns_changed() |
self.conns_changed() |
263 |
buttons = wxBoxSizer(wxVERTICAL) |
buttons = wxBoxSizer(wxVERTICAL) |
264 |
buttons.Add(self.DB_Add, 0, wxALL, 4) |
buttons.Add(self.DB_Add, 0, wxALL, 4) |
265 |
buttons.Add(self.DB_Remove, 0, wxALL, 4) |
buttons.Add(self.DB_Remove, 0, wxALL, 4) |
|
#buttons.Add(self.DB_Edit, 0, wxALL, 4) |
|
266 |
|
|
267 |
box.Add(buttons, 0, wxEXPAND) |
box.Add(buttons, 0, wxEXPAND) |
268 |
top.Add(box, 1, wxEXPAND) |
top.Add(box, 1, wxEXPAND) |
354 |
def OnRemove(self, event): |
def OnRemove(self, event): |
355 |
i = self.DB_ListBox.GetSelection() |
i = self.DB_ListBox.GetSelection() |
356 |
if i >= 0: |
if i >= 0: |
357 |
self.session.RemoveDBConnection(self.DB_ListBox.GetClientData(i)) |
conn = self.DB_ListBox.GetClientData(i) |
358 |
|
if self.session.CanRemoveDBConnection(conn): |
359 |
def OnEdit(self, event): |
self.session.RemoveDBConnection(conn) |
360 |
i = self.DB_ListBox.GetSelection() |
else: |
361 |
if i >= 0: |
self.RunMessageBox(_("Remove Database Connection"), |
362 |
editdialog = DBDialog(self.DB_ListBox.GetClientData(i), self, -1, |
_("The connection %s\nis still in use") |
363 |
"") |
% conn.BriefDescription()) |
|
while 1: |
|
|
if editdialog.ShowModal() == wxID_OK: |
|
|
host = editdialog.GetHostname() |
|
|
database = editdialog.GetDatabase() |
|
|
port = editdialog.GetPort() |
|
|
user = editdialog.GetUser() |
|
|
password = editdialog.GetPassword() |
|
|
try: |
|
|
conn = PostGISConnection(database, host = host, |
|
|
port = port, user = user, |
|
|
password = password) |
|
|
self.session.ChangeDBConnection(conn) |
|
|
break |
|
|
except psycopg.OperationalError, r: |
|
|
self.RunMessageBox(_("Add Database"), |
|
|
_("An exception occurred: '%s'." |
|
|
% r)) |
|
|
except: |
|
|
self.RunMessageBox(_("Add Database"), |
|
|
_("Can't establish connection to '%s'." |
|
|
% database)) |
|
|
else: |
|
|
break |
|
|
editdialog.Destroy() |
|