--- nfo/projects/netfraggle/bin/fraggleDialogPrefs.py 2004/08/25 16:56:59 1.2 +++ nfo/projects/netfraggle/bin/fraggleDialogPrefs.py 2004/08/27 21:14:02 1.6 @@ -1,20 +1,25 @@ #Boa:Dialog:fraggleDialogPrefs from wxPython.wx import * +from fraggleEngine import * def create(parent): return fraggleDialogPrefs(parent) + + [wxID_FRAGGLEDIALOGPREFS, wxID_FRAGGLEDIALOGPREFSBTSAVE, - wxID_FRAGGLEDIALOGPREFSBUTTON1, wxID_FRAGGLEDIALOGPREFSSTATICLINE1, - wxID_FRAGGLEDIALOGPREFSSTATICLINE2, wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, + wxID_FRAGGLEDIALOGPREFSBUTTON1, wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, + wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, + wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, wxID_FRAGGLEDIALOGPREFSSTATICTEXT2, wxID_FRAGGLEDIALOGPREFSSTATICTEXT3, wxID_FRAGGLEDIALOGPREFSSTATICTEXT4, wxID_FRAGGLEDIALOGPREFSSTATICTEXT5, - wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, + wxID_FRAGGLEDIALOGPREFSSTATICTEXT6, wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, wxID_FRAGGLEDIALOGPREFSTEXTCTRLRETRIEVAL, wxID_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, wxID_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, -] = map(lambda _init_ctrls: wxNewId(), range(14)) +] = map(lambda _init_ctrls: wxNewId(), range(17)) class fraggleDialogPrefs(wxDialog): def _init_utils(self): @@ -25,43 +30,45 @@ # generated method, don't edit wxDialog.__init__(self, id=wxID_FRAGGLEDIALOGPREFS, name='fraggleDialogPrefs', parent=prnt, pos=wxPoint(283, 313), - size=wxSize(366, 188), style=wxDEFAULT_DIALOG_STYLE, + size=wxSize(366, 233), style=wxDEFAULT_DIALOG_STYLE, title='Netfraggle Preferences') self._init_utils() - self.SetClientSize(wxSize(366, 188)) + self.SetClientSize(wxSize(366, 233)) - self.btsave = wxButton(id=wxID_FRAGGLEDIALOGPREFSBTSAVE, label='Save', - name='btsave', parent=self, pos=wxPoint(8, 168), size=wxSize(64, - 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(80, 168), - size=wxSize(56, 16), style=0) + 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_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_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_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, - name='textCtrlUsername', parent=self, pos=wxPoint(80, 16), - size=wxSize(80, 16), style=0, value='') + name='textCtrlUsername', parent=self, pos=wxPoint(80, 72), + size=wxSize(88, 16), style=0, value='') self.textCtrlPassword = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, - name='textCtrlPassword', parent=self, pos=wxPoint(80, 40), - size=wxSize(80, 16), style=0, value='') + name='textCtrlPassword', parent=self, pos=wxPoint(80, 96), + size=wxSize(88, 16), style=0, value='') 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_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, - name='textCtrlServer', parent=self, pos=wxPoint(80, 64), + name='textCtrlServer', parent=self, pos=wxPoint(80, 120), size=wxSize(272, 16), style=0, value='http://your.server.com/netfraggle.php') @@ -77,20 +84,62 @@ label='Seconds', name='staticText5', parent=self, pos=wxPoint(176, 144), size=wxSize(56, 16), style=0) - self.staticLine1 = wxStaticLine(id=wxID_FRAGGLEDIALOGPREFSSTATICLINE1, - name='staticLine1', parent=self, pos=wxPoint(0, 144), - size=wxSize(368, 0), style=0) - - self.staticLine2 = wxStaticLine(id=wxID_FRAGGLEDIALOGPREFSSTATICLINE2, - 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, 16), style=0, + validator=wxDefaultValidator, value='') + self.comboBoxProfile.SetLabel('') + + 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) + + self.buttonProfileDel = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, + label='Delete', name='buttonProfileDel', parent=self, + pos=wxPoint(320, 8), size=wxSize(40, 16), style=0) + + self.buttonProfileLoad = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, + label='Load', name='buttonProfileLoad', parent=self, + pos=wxPoint(216, 8), size=wxSize(48, 16), style=0) def __init__(self, parent): self.parent = parent self._init_ctrls(parent) def OnBtsaveButton(self, event): - self.parent.preferencesCtl.setConfig(self.textCtrlUsername.GetValue(),self.textCtrlPassword.GetValue(), - self.textCtrlServer.GetValue(),self.textCtrlRetrieval.GetValue()) + + # 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): + engine = FraggleEngine() + prefsfile = os.path.join(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"]) + + def OnButton1Button(self, event): + self.Hide() event.Skip() + \ No newline at end of file