--- nfo/projects/netfraggle/bin/fraggleDialogPrefs.py 2004/08/25 13:53:48 1.1.1.1 +++ nfo/projects/netfraggle/bin/fraggleDialogPrefs.py 2004/09/01 20:56:32 1.11 @@ -1,84 +1,211 @@ -#Boa:Dialog:wxDialog1 +#Boa:Dialog:fraggleDialogPrefs from wxPython.wx import * +from fraggleEngine import * def create(parent): - return wxDialog1(parent) + return fraggleDialogPrefs(parent) -[wxID_WXDIALOG1, wxID_WXDIALOG1BTSAVE, wxID_WXDIALOG1BUTTON1, - wxID_WXDIALOG1STATICLINE1, wxID_WXDIALOG1STATICLINE2, - wxID_WXDIALOG1STATICTEXT1, wxID_WXDIALOG1STATICTEXT2, - wxID_WXDIALOG1STATICTEXT3, wxID_WXDIALOG1STATICTEXT4, - wxID_WXDIALOG1STATICTEXT5, wxID_WXDIALOG1TEXTCTRLPASSWORD, - wxID_WXDIALOG1TEXTCTRLRETRIEVAL, wxID_WXDIALOG1TEXTCTRLSERVER, - wxID_WXDIALOG1TEXTCTRLUSERNAME, -] = map(lambda _init_ctrls: wxNewId(), range(14)) -class wxDialog1(wxDialog): - def _init_utils(self): - # generated method, don't edit - pass +[wxID_FRAGGLEDIALOGPREFS, wxID_FRAGGLEDIALOGPREFSBTSAVE, + wxID_FRAGGLEDIALOGPREFSBUTTON1, wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, wxID_FRAGGLEDIALOGPREFSBUTTONTEST, + wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, + wxID_FRAGGLEDIALOGPREFSSTATICTEXT2, wxID_FRAGGLEDIALOGPREFSSTATICTEXT3, + wxID_FRAGGLEDIALOGPREFSSTATICTEXT4, wxID_FRAGGLEDIALOGPREFSSTATICTEXT5, + wxID_FRAGGLEDIALOGPREFSSTATICTEXT6, wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, + wxID_FRAGGLEDIALOGPREFSTEXTCTRLRETRIEVAL, + wxID_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, + wxID_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, +] = map(lambda _init_ctrls: wxNewId(), range(18)) + +class fraggleDialogPrefs(wxDialog): def _init_ctrls(self, prnt): # generated method, don't edit - wxDialog.__init__(self, id=wxID_WXDIALOG1, name='', parent=prnt, - pos=wxPoint(344, 319), size=wxSize(366, 188), - style=wxDEFAULT_DIALOG_STYLE, title='Netfraggle Preferences') + wxDialog.__init__(self, id=wxID_FRAGGLEDIALOGPREFS, + name='fraggleDialogPrefs', parent=prnt, pos=wxPoint(482, 310), + size=wxSize(366, 233), style=wxDEFAULT_DIALOG_STYLE, + title='Netfraggle Preferences') self._init_utils() - self.SetClientSize(wxSize(366, 188)) - - self.btsave = wxButton(id=wxID_WXDIALOG1BTSAVE, label='Save', - name='btsave', parent=self, pos=wxPoint(8, 168), size=wxSize(64, - 16), style=0) + self.SetClientSize(wxSize(366, 233)) - self.button1 = wxButton(id=wxID_WXDIALOG1BUTTON1, label='Cancel', - name='button1', parent=self, pos=wxPoint(80, 168), size=wxSize(56, - 16), style=0) + self.btsave = wxButton(id=wxID_FRAGGLEDIALOGPREFSBTSAVE, + label='Save and Close', name='btsave', parent=self, + pos=wxPoint(8, 208), size=wxSize(96, 16), style=0) + EVT_BUTTON(self.btsave, wxID_FRAGGLEDIALOGPREFSBTSAVE, + self.OnBtsaveButton) + + self.button1 = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTON1, + label='Cancel', name='button1', parent=self, pos=wxPoint(112, + 208), size=wxSize(56, 16), style=0) + EVT_BUTTON(self.button1, wxID_FRAGGLEDIALOGPREFSBUTTON1, + self.OnButton1Button) - self.staticText1 = wxStaticText(id=wxID_WXDIALOG1STATICTEXT1, + self.staticText1 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, label='Username', name='staticText1', parent=self, pos=wxPoint(16, - 16), size=wxSize(47, 13), style=0) + 72), size=wxSize(47, 16), style=0) - self.staticText2 = wxStaticText(id=wxID_WXDIALOG1STATICTEXT2, + self.staticText2 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT2, label='Password', name='staticText2', parent=self, pos=wxPoint(16, - 40), size=wxSize(53, 16), style=0) + 96), size=wxSize(53, 16), style=0) - self.textCtrlUsername = wxTextCtrl(id=wxID_WXDIALOG1TEXTCTRLUSERNAME, - name='textCtrlUsername', parent=self, pos=wxPoint(80, 16), - size=wxSize(80, 16), style=0, value='') + self.textCtrlUsername = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, + name='textCtrlUsername', parent=self, pos=wxPoint(80, 72), + size=wxSize(88, 16), style=0, value='') - self.textCtrlPassword = wxTextCtrl(id=wxID_WXDIALOG1TEXTCTRLPASSWORD, - name='textCtrlPassword', parent=self, pos=wxPoint(80, 40), - size=wxSize(80, 16), style=0, value='') + self.textCtrlPassword = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, + name='textCtrlPassword', parent=self, pos=wxPoint(80, 96), + size=wxSize(88, 16), style=0, value='') - self.staticText3 = wxStaticText(id=wxID_WXDIALOG1STATICTEXT3, + self.staticText3 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT3, label='Server URL', name='staticText3', parent=self, - pos=wxPoint(16, 64), size=wxSize(58, 16), style=0) + pos=wxPoint(16, 120), size=wxSize(58, 16), style=0) - self.textCtrlServer = wxTextCtrl(id=wxID_WXDIALOG1TEXTCTRLSERVER, - name='textCtrlServer', parent=self, pos=wxPoint(80, 64), + self.textCtrlServer = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, + name='textCtrlServer', parent=self, pos=wxPoint(80, 120), size=wxSize(272, 16), style=0, value='http://your.server.com/netfraggle.php') - self.staticText4 = wxStaticText(id=wxID_WXDIALOG1STATICTEXT4, + self.staticText4 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT4, label='Topic Retrieval Interval', name='staticText4', parent=self, pos=wxPoint(16, 144), size=wxSize(120, 16), style=0) - self.textCtrlRetrieval = wxTextCtrl(id=wxID_WXDIALOG1TEXTCTRLRETRIEVAL, + self.textCtrlRetrieval = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLRETRIEVAL, name='textCtrlRetrieval', parent=self, pos=wxPoint(128, 144), size=wxSize(40, 16), style=0, value='') - self.staticText5 = wxStaticText(id=wxID_WXDIALOG1STATICTEXT5, + self.staticText5 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT5, label='Seconds', name='staticText5', parent=self, pos=wxPoint(176, 144), size=wxSize(56, 16), style=0) - self.staticLine1 = wxStaticLine(id=wxID_WXDIALOG1STATICLINE1, - name='staticLine1', parent=self, pos=wxPoint(0, 144), - size=wxSize(368, 0), style=0) - - self.staticLine2 = wxStaticLine(id=wxID_WXDIALOG1STATICLINE2, - name='staticLine2', parent=self, pos=wxPoint(0, 56), - size=wxSize(368, 8), style=0) + self.comboBoxProfile = wxComboBox(choices=[], + id=wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, name='comboBoxProfile', + 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, + 8), size=wxSize(48, 16), style=0) + + 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_utils(self): + # generated method, don't edit + pass + def __init_profiles(self): + list = self.parent.preferencesCtl.getProfileList() + print list + for i in list: + self.comboBoxProfile.Append(i) + 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 + import codecs + (UTF8_encode, UTF8_decode, + UTF8_streamreader, UTF8_streamwriter) = codecs.lookup('UTF-8') + self.parent.preferencesCtl.setConfig( + UTF8_encode(self.textCtrlUsername.GetValue())[0], + UTF8_encode(self.textCtrlPassword.GetValue())[0], + UTF8_encode(self.textCtrlServer.GetValue())[0], + UTF8_encode(self.textCtrlRetrieval.GetValue())[0] + ) + + self.parent.preferencesCtl.saveConfig() + self.Hide() + event.Skip() + + def loadConfig(self): + prefsfile = os.path.join(self.parent.preferencesCtl.getDefaultDir(), 'prefs.xml') + self.parent.preferencesCtl.loadConfig(prefsfile) + + def updateConfig(self): + config = self.parent.preferencesCtl.getConfig() + 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() + + 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!")