--- nfo/projects/netfraggle/bin/fraggleDialogPrefs.py 2004/08/27 21:14:02 1.6 +++ nfo/projects/netfraggle/bin/fraggleDialogPrefs.py 2004/09/05 00:21:10 1.14 @@ -3,6 +3,8 @@ from wxPython.wx import * from fraggleEngine import * +import FraggleDialogModules + def create(parent): return fraggleDialogPrefs(parent) @@ -11,7 +13,7 @@ [wxID_FRAGGLEDIALOGPREFS, wxID_FRAGGLEDIALOGPREFSBTSAVE, wxID_FRAGGLEDIALOGPREFSBUTTON1, wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, - wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, wxID_FRAGGLEDIALOGPREFSBUTTONTEST, wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, wxID_FRAGGLEDIALOGPREFSSTATICTEXT2, wxID_FRAGGLEDIALOGPREFSSTATICTEXT3, wxID_FRAGGLEDIALOGPREFSSTATICTEXT4, wxID_FRAGGLEDIALOGPREFSSTATICTEXT5, @@ -19,17 +21,13 @@ wxID_FRAGGLEDIALOGPREFSTEXTCTRLRETRIEVAL, wxID_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, wxID_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, -] = map(lambda _init_ctrls: wxNewId(), range(17)) +] = map(lambda _init_ctrls: wxNewId(), range(18)) class fraggleDialogPrefs(wxDialog): - def _init_utils(self): - # generated method, don't edit - pass - def _init_ctrls(self, prnt): # generated method, don't edit wxDialog.__init__(self, id=wxID_FRAGGLEDIALOGPREFS, - name='fraggleDialogPrefs', parent=prnt, pos=wxPoint(283, 313), + name='fraggleDialogPrefs', parent=prnt, pos=wxPoint(482, 310), size=wxSize(366, 233), style=wxDEFAULT_DIALOG_STYLE, title='Netfraggle Preferences') self._init_utils() @@ -86,9 +84,12 @@ self.comboBoxProfile = wxComboBox(choices=[], id=wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, name='comboBoxProfile', - parent=self, pos=wxPoint(80, 8), size=wxSize(124, 16), style=0, + parent=self, pos=wxPoint(80, 8), size=wxSize(124, 21), style=0, validator=wxDefaultValidator, value='') self.comboBoxProfile.SetLabel('') + EVT_COMBOBOX(self.comboBoxProfile, + wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, + self.OnComboboxprofileCombobox) self.staticText6 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT6, label='Profile', name='staticText6', parent=self, pos=wxPoint(16, @@ -97,19 +98,47 @@ self.buttonProfileSave = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, label='Save', name='buttonProfileSave', parent=self, pos=wxPoint(272, 8), size=wxSize(40, 16), style=0) + EVT_BUTTON(self.buttonProfileSave, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, + self.OnButtonprofilesaveButton) self.buttonProfileDel = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, label='Delete', name='buttonProfileDel', parent=self, pos=wxPoint(320, 8), size=wxSize(40, 16), style=0) + EVT_BUTTON(self.buttonProfileDel, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, + self.OnButtonprofiledelButton) self.buttonProfileLoad = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, label='Load', name='buttonProfileLoad', parent=self, pos=wxPoint(216, 8), size=wxSize(48, 16), style=0) + EVT_BUTTON(self.buttonProfileLoad, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, + self.OnButtonprofileloadButton) + + self.buttonTest = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONTEST, + label=u'&Test Account', name=u'buttonTest', parent=self, + pos=wxPoint(264, 208), size=wxSize(96, 16), style=0) + EVT_BUTTON(self.buttonTest, wxID_FRAGGLEDIALOGPREFSBUTTONTEST, + self.OnButtonTestButton) + + def __init_profiles(self): + list = self.parent.preferencesCtl.getProfileList() + print list + for i in list: + self.comboBoxProfile.Append(i) + + def _init_utils(self): + # generated method, don't edit + pass def __init__(self, parent): self.parent = parent + import __main__ + self.engine = __main__.engine self._init_ctrls(parent) - + self.__init_profiles() + def OnBtsaveButton(self, event): # convert from utf-8: required for win32 @@ -128,18 +157,62 @@ event.Skip() def loadConfig(self): - engine = FraggleEngine() - prefsfile = os.path.join(engine.getDefaultDir(), 'prefs.xml') + prefsfile = os.path.join(self.parent.engine.getDefaultDir(), 'prefs.xml') self.parent.preferencesCtl.loadConfig(prefsfile) def updateConfig(self): config = self.parent.preferencesCtl.getConfig() - self.textCtrlUsername.SetValue(config["username"]) - self.textCtrlPassword.SetValue(config["password"]) - self.textCtrlServer.SetValue(config["url"]) - self.textCtrlRetrieval.SetValue(config["retrieval"]) - + try: + self.textCtrlUsername.SetValue(config["username"]) + self.textCtrlPassword.SetValue(config["password"]) + self.textCtrlServer.SetValue(config["url"]) + self.textCtrlRetrieval.SetValue(config["retrieval"]) + except TypeError: + self.textCtrlUsername.SetValue("username") + self.textCtrlPassword.SetValue("password") + self.textCtrlServer.SetValue("url") + self.textCtrlRetrieval.SetValue("retrieval") + def OnButton1Button(self, event): self.Hide() event.Skip() - \ No newline at end of file + + def OnButtonprofilesaveButton(self, event): + username = self.textCtrlUsername.GetValue() + password = self.textCtrlPassword.GetValue() + url = self.textCtrlServer.GetValue() + retrieval = self.textCtrlRetrieval.GetValue() + self.parent.preferencesCtl.setConfig(username,password,url,retrieval) + i = self.parent.preferencesCtl.appendProfile(self.comboBoxProfile.GetValue(),self.parent.preferencesCtl.configList) + if i == 0: + self.comboBoxProfile.Append(self.comboBoxProfile.GetValue()) + + self.parent.preferencesCtl.saveProfiles() + event.Skip() + + def OnButtonprofileloadButton(self, event): + self.parent.preferencesCtl.loadProfile(self.comboBoxProfile.GetValue()) + self.updateConfig() + event.Skip() + + def OnButtonprofiledelButton(self, event): + self.parent.preferencesCtl.deleteProfile(self.comboBoxProfile.GetValue()) + self.comboBoxProfile.Delete(self.comboBoxProfile.FindString(self.comboBoxProfile.GetValue())) + self.parent.preferencesCtl.saveProfiles() + self.updateConfig() + event.Skip() + + def OnComboboxprofileCombobox(self, event): + event.Skip() + + def OnButtonTestButton(self, event): + #event.Skip() + if self.engine.authenticate(self.textCtrlServer.GetValue(), self.textCtrlUsername.GetValue(), self.textCtrlPassword.GetValue()): + wxMessageBox("Authentication successful!") + else: + wxMessageBox("Authentication failed!") + + def OnButtonModulesButton(self, event): + #self.dialogModules.Show() + #self.parent.dialogModules.Hide() + event.Skip()