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