| 1 |
xabbu |
1.2 |
#Boa:Dialog:fraggleDialogPrefs |
| 2 |
xabbu |
1.1 |
|
| 3 |
|
|
from wxPython.wx import * |
| 4 |
xabbu |
1.4 |
from fraggleEngine import * |
| 5 |
xabbu |
1.1 |
|
| 6 |
|
|
def create(parent): |
| 7 |
xabbu |
1.2 |
return fraggleDialogPrefs(parent) |
| 8 |
xabbu |
1.1 |
|
| 9 |
xabbu |
1.4 |
|
| 10 |
|
|
|
| 11 |
xabbu |
1.2 |
[wxID_FRAGGLEDIALOGPREFS, wxID_FRAGGLEDIALOGPREFSBTSAVE, |
| 12 |
xabbu |
1.6 |
wxID_FRAGGLEDIALOGPREFSBUTTON1, wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, |
| 13 |
|
|
wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, |
| 14 |
|
|
wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, |
| 15 |
|
|
wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, |
| 16 |
xabbu |
1.2 |
wxID_FRAGGLEDIALOGPREFSSTATICTEXT2, wxID_FRAGGLEDIALOGPREFSSTATICTEXT3, |
| 17 |
|
|
wxID_FRAGGLEDIALOGPREFSSTATICTEXT4, wxID_FRAGGLEDIALOGPREFSSTATICTEXT5, |
| 18 |
xabbu |
1.6 |
wxID_FRAGGLEDIALOGPREFSSTATICTEXT6, wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, |
| 19 |
xabbu |
1.2 |
wxID_FRAGGLEDIALOGPREFSTEXTCTRLRETRIEVAL, |
| 20 |
|
|
wxID_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, |
| 21 |
|
|
wxID_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, |
| 22 |
xabbu |
1.6 |
] = map(lambda _init_ctrls: wxNewId(), range(17)) |
| 23 |
xabbu |
1.1 |
|
| 24 |
xabbu |
1.2 |
class fraggleDialogPrefs(wxDialog): |
| 25 |
xabbu |
1.1 |
def _init_utils(self): |
| 26 |
|
|
# generated method, don't edit |
| 27 |
|
|
pass |
| 28 |
|
|
|
| 29 |
|
|
def _init_ctrls(self, prnt): |
| 30 |
|
|
# generated method, don't edit |
| 31 |
xabbu |
1.2 |
wxDialog.__init__(self, id=wxID_FRAGGLEDIALOGPREFS, |
| 32 |
|
|
name='fraggleDialogPrefs', parent=prnt, pos=wxPoint(283, 313), |
| 33 |
xabbu |
1.6 |
size=wxSize(366, 233), style=wxDEFAULT_DIALOG_STYLE, |
| 34 |
xabbu |
1.2 |
title='Netfraggle Preferences') |
| 35 |
xabbu |
1.1 |
self._init_utils() |
| 36 |
xabbu |
1.6 |
self.SetClientSize(wxSize(366, 233)) |
| 37 |
xabbu |
1.1 |
|
| 38 |
xabbu |
1.5 |
self.btsave = wxButton(id=wxID_FRAGGLEDIALOGPREFSBTSAVE, |
| 39 |
|
|
label='Save and Close', name='btsave', parent=self, |
| 40 |
xabbu |
1.6 |
pos=wxPoint(8, 208), size=wxSize(96, 16), style=0) |
| 41 |
xabbu |
1.2 |
EVT_BUTTON(self.btsave, wxID_FRAGGLEDIALOGPREFSBTSAVE, |
| 42 |
|
|
self.OnBtsaveButton) |
| 43 |
xabbu |
1.1 |
|
| 44 |
xabbu |
1.2 |
self.button1 = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTON1, |
| 45 |
xabbu |
1.5 |
label='Cancel', name='button1', parent=self, pos=wxPoint(112, |
| 46 |
xabbu |
1.6 |
208), size=wxSize(56, 16), style=0) |
| 47 |
xabbu |
1.4 |
EVT_BUTTON(self.button1, wxID_FRAGGLEDIALOGPREFSBUTTON1, |
| 48 |
|
|
self.OnButton1Button) |
| 49 |
xabbu |
1.1 |
|
| 50 |
xabbu |
1.2 |
self.staticText1 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT1, |
| 51 |
xabbu |
1.1 |
label='Username', name='staticText1', parent=self, pos=wxPoint(16, |
| 52 |
xabbu |
1.6 |
72), size=wxSize(47, 16), style=0) |
| 53 |
xabbu |
1.1 |
|
| 54 |
xabbu |
1.2 |
self.staticText2 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT2, |
| 55 |
xabbu |
1.1 |
label='Password', name='staticText2', parent=self, pos=wxPoint(16, |
| 56 |
xabbu |
1.6 |
96), size=wxSize(53, 16), style=0) |
| 57 |
xabbu |
1.1 |
|
| 58 |
xabbu |
1.2 |
self.textCtrlUsername = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLUSERNAME, |
| 59 |
xabbu |
1.6 |
name='textCtrlUsername', parent=self, pos=wxPoint(80, 72), |
| 60 |
|
|
size=wxSize(88, 16), style=0, value='') |
| 61 |
xabbu |
1.1 |
|
| 62 |
xabbu |
1.2 |
self.textCtrlPassword = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLPASSWORD, |
| 63 |
xabbu |
1.6 |
name='textCtrlPassword', parent=self, pos=wxPoint(80, 96), |
| 64 |
|
|
size=wxSize(88, 16), style=0, value='') |
| 65 |
xabbu |
1.1 |
|
| 66 |
xabbu |
1.2 |
self.staticText3 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT3, |
| 67 |
xabbu |
1.1 |
label='Server URL', name='staticText3', parent=self, |
| 68 |
xabbu |
1.6 |
pos=wxPoint(16, 120), size=wxSize(58, 16), style=0) |
| 69 |
xabbu |
1.1 |
|
| 70 |
xabbu |
1.2 |
self.textCtrlServer = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLSERVER, |
| 71 |
xabbu |
1.6 |
name='textCtrlServer', parent=self, pos=wxPoint(80, 120), |
| 72 |
xabbu |
1.1 |
size=wxSize(272, 16), style=0, |
| 73 |
|
|
value='http://your.server.com/netfraggle.php') |
| 74 |
|
|
|
| 75 |
xabbu |
1.2 |
self.staticText4 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT4, |
| 76 |
xabbu |
1.1 |
label='Topic Retrieval Interval', name='staticText4', parent=self, |
| 77 |
|
|
pos=wxPoint(16, 144), size=wxSize(120, 16), style=0) |
| 78 |
|
|
|
| 79 |
xabbu |
1.2 |
self.textCtrlRetrieval = wxTextCtrl(id=wxID_FRAGGLEDIALOGPREFSTEXTCTRLRETRIEVAL, |
| 80 |
xabbu |
1.1 |
name='textCtrlRetrieval', parent=self, pos=wxPoint(128, 144), |
| 81 |
|
|
size=wxSize(40, 16), style=0, value='') |
| 82 |
|
|
|
| 83 |
xabbu |
1.2 |
self.staticText5 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT5, |
| 84 |
xabbu |
1.1 |
label='Seconds', name='staticText5', parent=self, pos=wxPoint(176, |
| 85 |
|
|
144), size=wxSize(56, 16), style=0) |
| 86 |
|
|
|
| 87 |
xabbu |
1.6 |
self.comboBoxProfile = wxComboBox(choices=[], |
| 88 |
|
|
id=wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, name='comboBoxProfile', |
| 89 |
|
|
parent=self, pos=wxPoint(80, 8), size=wxSize(124, 16), style=0, |
| 90 |
|
|
validator=wxDefaultValidator, value='') |
| 91 |
|
|
self.comboBoxProfile.SetLabel('') |
| 92 |
xabbu |
1.8 |
EVT_COMBOBOX(self.comboBoxProfile, |
| 93 |
|
|
wxID_FRAGGLEDIALOGPREFSCOMBOBOXPROFILE, |
| 94 |
|
|
self.OnComboboxprofileCombobox) |
| 95 |
xabbu |
1.6 |
|
| 96 |
|
|
self.staticText6 = wxStaticText(id=wxID_FRAGGLEDIALOGPREFSSTATICTEXT6, |
| 97 |
|
|
label='Profile', name='staticText6', parent=self, pos=wxPoint(16, |
| 98 |
|
|
8), size=wxSize(48, 16), style=0) |
| 99 |
|
|
|
| 100 |
|
|
self.buttonProfileSave = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, |
| 101 |
|
|
label='Save', name='buttonProfileSave', parent=self, |
| 102 |
|
|
pos=wxPoint(272, 8), size=wxSize(40, 16), style=0) |
| 103 |
xabbu |
1.7 |
EVT_BUTTON(self.buttonProfileSave, |
| 104 |
|
|
wxID_FRAGGLEDIALOGPREFSBUTTONPROFILESAVE, |
| 105 |
|
|
self.OnButtonprofilesaveButton) |
| 106 |
xabbu |
1.6 |
|
| 107 |
|
|
self.buttonProfileDel = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, |
| 108 |
|
|
label='Delete', name='buttonProfileDel', parent=self, |
| 109 |
|
|
pos=wxPoint(320, 8), size=wxSize(40, 16), style=0) |
| 110 |
xabbu |
1.7 |
EVT_BUTTON(self.buttonProfileDel, |
| 111 |
|
|
wxID_FRAGGLEDIALOGPREFSBUTTONPROFILEDEL, |
| 112 |
|
|
self.OnButtonprofiledelButton) |
| 113 |
xabbu |
1.6 |
|
| 114 |
|
|
self.buttonProfileLoad = wxButton(id=wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, |
| 115 |
|
|
label='Load', name='buttonProfileLoad', parent=self, |
| 116 |
|
|
pos=wxPoint(216, 8), size=wxSize(48, 16), style=0) |
| 117 |
xabbu |
1.7 |
EVT_BUTTON(self.buttonProfileLoad, |
| 118 |
|
|
wxID_FRAGGLEDIALOGPREFSBUTTONPROFILELOAD, |
| 119 |
|
|
self.OnButtonprofileloadButton) |
| 120 |
|
|
|
| 121 |
|
|
def __init_profiles(self): |
| 122 |
|
|
list = self.parent.preferencesCtl.getProfileList() |
| 123 |
|
|
print list |
| 124 |
|
|
for i in list: |
| 125 |
|
|
self.comboBoxProfile.Append(i) |
| 126 |
|
|
|
| 127 |
xabbu |
1.1 |
def __init__(self, parent): |
| 128 |
xabbu |
1.2 |
self.parent = parent |
| 129 |
xabbu |
1.1 |
self._init_ctrls(parent) |
| 130 |
xabbu |
1.7 |
self.__init_profiles() |
| 131 |
|
|
|
| 132 |
xabbu |
1.2 |
def OnBtsaveButton(self, event): |
| 133 |
joko |
1.3 |
|
| 134 |
|
|
# convert from utf-8: required for win32 |
| 135 |
|
|
import codecs |
| 136 |
|
|
(UTF8_encode, UTF8_decode, |
| 137 |
|
|
UTF8_streamreader, UTF8_streamwriter) = codecs.lookup('UTF-8') |
| 138 |
|
|
self.parent.preferencesCtl.setConfig( |
| 139 |
|
|
UTF8_encode(self.textCtrlUsername.GetValue())[0], |
| 140 |
|
|
UTF8_encode(self.textCtrlPassword.GetValue())[0], |
| 141 |
|
|
UTF8_encode(self.textCtrlServer.GetValue())[0], |
| 142 |
|
|
UTF8_encode(self.textCtrlRetrieval.GetValue())[0] |
| 143 |
|
|
) |
| 144 |
|
|
|
| 145 |
xabbu |
1.2 |
self.parent.preferencesCtl.saveConfig() |
| 146 |
xabbu |
1.5 |
self.Hide() |
| 147 |
xabbu |
1.2 |
event.Skip() |
| 148 |
xabbu |
1.4 |
|
| 149 |
|
|
def loadConfig(self): |
| 150 |
|
|
engine = FraggleEngine() |
| 151 |
|
|
prefsfile = os.path.join(engine.getDefaultDir(), 'prefs.xml') |
| 152 |
|
|
self.parent.preferencesCtl.loadConfig(prefsfile) |
| 153 |
|
|
|
| 154 |
|
|
def updateConfig(self): |
| 155 |
|
|
config = self.parent.preferencesCtl.getConfig() |
| 156 |
xabbu |
1.7 |
try: |
| 157 |
|
|
self.textCtrlUsername.SetValue(config["username"]) |
| 158 |
|
|
self.textCtrlPassword.SetValue(config["password"]) |
| 159 |
|
|
self.textCtrlServer.SetValue(config["url"]) |
| 160 |
|
|
self.textCtrlRetrieval.SetValue(config["retrieval"]) |
| 161 |
|
|
except TypeError: |
| 162 |
|
|
self.textCtrlUsername.SetValue("username") |
| 163 |
|
|
self.textCtrlPassword.SetValue("password") |
| 164 |
|
|
self.textCtrlServer.SetValue("url") |
| 165 |
|
|
self.textCtrlRetrieval.SetValue("retrieval") |
| 166 |
|
|
|
| 167 |
xabbu |
1.4 |
def OnButton1Button(self, event): |
| 168 |
|
|
self.Hide() |
| 169 |
xabbu |
1.7 |
event.Skip() |
| 170 |
|
|
|
| 171 |
|
|
def OnButtonprofilesaveButton(self, event): |
| 172 |
|
|
username = self.textCtrlUsername.GetValue() |
| 173 |
|
|
password = self.textCtrlPassword.GetValue() |
| 174 |
|
|
url = self.textCtrlServer.GetValue() |
| 175 |
|
|
retrieval = self.textCtrlRetrieval.GetValue() |
| 176 |
|
|
self.parent.preferencesCtl.setConfig(username,password,url,retrieval) |
| 177 |
|
|
i = self.parent.preferencesCtl.appendProfile(self.comboBoxProfile.GetValue(),self.parent.preferencesCtl.configList) |
| 178 |
|
|
if i == 0: |
| 179 |
|
|
self.comboBoxProfile.Append(self.comboBoxProfile.GetValue()) |
| 180 |
|
|
|
| 181 |
|
|
self.parent.preferencesCtl.saveProfiles() |
| 182 |
|
|
event.Skip() |
| 183 |
|
|
|
| 184 |
|
|
def OnButtonprofileloadButton(self, event): |
| 185 |
|
|
self.parent.preferencesCtl.loadProfile(self.comboBoxProfile.GetValue()) |
| 186 |
|
|
self.updateConfig() |
| 187 |
|
|
event.Skip() |
| 188 |
|
|
|
| 189 |
|
|
def OnButtonprofiledelButton(self, event): |
| 190 |
xabbu |
1.8 |
self.parent.preferencesCtl.deleteProfile(self.comboBoxProfile.GetValue()) |
| 191 |
|
|
self.comboBoxProfile.Delete(self.comboBoxProfile.FindString(self.comboBoxProfile.GetValue())) |
| 192 |
|
|
self.parent.preferencesCtl.saveProfiles() |
| 193 |
|
|
self.updateConfig() |
| 194 |
|
|
event.Skip() |
| 195 |
|
|
|
| 196 |
|
|
def OnComboboxprofileCombobox(self, event): |
| 197 |
xabbu |
1.4 |
event.Skip() |
| 198 |
|
|
|