-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmakerProjectSetup.py
executable file
·330 lines (284 loc) · 14.3 KB
/
makerProjectSetup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import wx
from makerWidgets import MakerDialog
import makerFtpBrowser
import makerCheckInternetConnection
def checkFtpSettings(func):
"""Tests if FTP Host, FTP User and FTP Root are OK."""
def wrapper(self, evt):
if "not set" in [self.ftp_host.GetValue(),
self.ftp_user.GetValue(),
self.ftp_root.GetValue()]:
self.controller.errorMessage('"not set" is an illegal FTP value!')
self.Close()
evt.Skip()
return
root = self.ftp_root.GetValue()
newroot = root
if not root.startswith('/'):
newroot = '/' + root
self.ftp_root.SetValue(newroot)
if not newroot.endswith('/'):
newroot += '/'
self.ftp_root.SetValue(newroot)
passw = self.controller.model.getRemotePassword()
result = self.controller.actionTestFtp(self.ftp_host.GetValue(),
self.ftp_user.GetValue(),
self.ftp_root.GetValue(),
passw)
if result: return func(self, evt)
self.controller.errorMessage(result)
evt.Skip()
return
return wrapper
# ------------------------------------------------------------
# ------------------------------------------------------------
# ------------------------------------------------------------
class ProjectSetup(MakerDialog):
def __init__(self, parent, controller):
"""parent is the main GUI. controller refers to makerController."""
self.parent = parent
self.controller = controller
self.projectModel = controller.model
self.createDialog(parent)
self.choices_sprache = ['en', 'de']
self.choices_add_lang = ['en', 'de', 'None']
self.saved = None
self.keepGoodPassword(None)
def createDialog(self, prnt):
MakerDialog.__init__(self,
{'name' : 'ProjectSetup',
'parent' : prnt,
'pos' : wx.Point(439, 179),
'size' : wx.Size(394, 380),
'style' : wx.DEFAULT_DIALOG_STYLE,
'title' : 'Setup FTP Connection...',
'clientSize' : wx.Size(394, 355),
'centerPos' : wx.BOTH})
self.ftp_host = self.add('textCtrl',
{'name' : 'ftp_host_ctl',
'parent' : self,
'pos' : wx.Point(136, 116),
'size' : wx.Size(232, 21),
'style' : 0,
'value' : 'www.myhost.com'
})
self.ftp_user = self.add('textCtrl',
{'name' : 'ftp_user_ctl',
'parent' : self,
'pos' : wx.Point(136, 156),
'size' : wx.Size(232, 21),
'style' : 0,
'value' : 'ftpuser'
})
self.browse_server = self.add('button',
{'label' : 'Browse',
'name' : 'browse',
'parent' : self,
'pos' : wx.Point(280, 190),
'size' : wx.Size(80, 23),
'style' : 0,
'handler' : self.onBrowseButton
})
self.ftp_root = self.add('textCtrl',
{'name' : 'ftp_root_ctl',
'parent' : self,
'pos' : wx.Point(136, 196),
'size' : wx.Size(132, 21),
'style' : 0,
'value' : '/path_to_my_project/'
})
self.url = self.add('textCtrl',
{'name' : 'url_ctl',
'parent' : self,
'pos' : wx.Point(136, 238),
'size' : wx.Size(232, 21),
'style' : 0,
'value' : 'http://www.myurl.com'
})
self.cancel = self.add('button',
{'label' : 'Cancel',
'name' : 'cancel',
'parent' : self,
'pos' : wx.Point(208, 308),
'size' : wx.Size(75, 23),
'style' : 0,
'handler' : self.onCancelButton
})
self.Ok = self.add('button',
{'label' : 'OK',
'name' : 'ok',
'parent' : self,
'pos' : wx.Point(296, 308),
'size' : wx.Size(75, 23),
'style' : 0,
'handler' : self.onOkButton
})
self.gfx_label = self.add('staticText',
{'label' : 'Name for remote graphics folder:',
'name' : 'gfx_label',
'parent' : self,
'pos' : wx.Point(24, 24),
'size' : wx.Size(230, 18),
'style' : 0})
self.gfxFolder = self.add('textCtrl',
{'name' : 'rem_gfx_folder',
'parent' : self,
'pos' : wx.Point(136, 54),
'size' : wx.Size(232, 21),
'style' : 0,
'value' : ''
})
self.staticLine1 = self.add('staticLine',
{'name' : 'staticLine1',
'parent' : self,
'pos' : wx.Point(24, 90),
'size' : wx.Size(336, 2),
'style' : 0})
self.help = self.add('button',
{'label' : 'Help',
'name' : 'help',
'parent' : self,
'pos' : wx.Point(16, 308),
'size' : wx.Size(75, 23),
'style' : 0,
'handler' : self.onHelpButton
})
self.staticText3 = self.add('staticText',
{'label' : 'FTP Host:',
'name' : 'staticText3',
'parent' : self,
'pos' : wx.Point(24, 116),
'size' : wx.Size(99, 20),
'style' : 0})
self.staticText4 = self.add('staticText',
{'label' : 'FTP User:',
'name' : 'staticText4',
'parent' : self,
'pos' : wx.Point(24, 156),
'size' : wx.Size(106, 20),
'style' : 0})
self.staticText6 = self.add('staticText',
{'label' : 'Path to Project:',
'name' : 'staticText6',
'parent' : self,
'pos' : wx.Point(24, 196),
'size' : wx.Size(100, 20),
'style' : 0})
self.staticText7 = self.add('staticText',
{'label' : 'Project url:',
'name' : 'staticText7',
'parent' : self,
'pos' : wx.Point(24, 238),
'size' : wx.Size(100, 20),
'style' : 0})
def setValues(self, theInformation):
"""Information is a dictionary with the current Projects information"""
self.ftp_host.SetValue(theInformation['ftp_host'])
self.ftp_user.SetValue(theInformation['ftp_user'])
self.ftp_root.SetValue(theInformation['ftp_root'])
self.gfxFolder.SetValue(theInformation['gfx_folder'])
self.url.SetValue(theInformation['url'])
self.theInformation = theInformation # save for later
# ------------------------------------------------------------
# BUTTON BOUND METHODS
# ------------------------------------------------------------
def doFTPCheck(self):
if "not set" in [self.ftp_host.GetValue(),
self.ftp_user.GetValue(),
self.ftp_root.GetValue()]:
self.controller.errorMessage('"not set" is an illegal FTP value!')
return False
root = self.ftp_root.GetValue()
newroot = root
if not newroot.endswith('/'):
if not newroot == ".":
newroot += '/'
self.ftp_root.SetValue(newroot)
if self.getGoodPassword() != None:
passw = self.getGoodPassword()
else:
passw = self.controller.password("Please enter FTP password...")
if passw != None:
result = self.projectModel.testFtp(self.ftp_host.GetValue(),
self.ftp_user.GetValue(),
self.ftp_root.GetValue(),
passw)
if result==True:
self.keepGoodPassword(passw)
self.projectModel.setRemotePassword(passw)
return True
else:
return result
else:
# if we return false the password dialog disappears and the check is
# cancelled
return False
def keepGoodPassword(self, passw):
self.goodPassword = passw
def getGoodPassword(self):
return self.goodPassword
def onOkButton(self, event):
if not makerCheckInternetConnection.check():
self.controller.infoMessage("No Internet Connection! Unable to test settings!")
self.saved = False
self.Close()
else:
result = self.doFTPCheck()
if result != True:
if result != False:
self.controller.errorMessage(str(result))
return
self.theInformation["ftp_host"] = self.ftp_host.GetValue()
self.theInformation["ftp_user"] = self.ftp_user.GetValue()
self.theInformation["ftp_root"] = self.ftp_root.GetValue()
value = self.gfxFolder.GetValue()
# make sure it is just a foldername
if "/" in value:
if value.count("/") == 1 and value.endswith("/"):
pass
else:
self.controller.errorMessage("The image folder is just a NAME for a folder, not a path.")
return
if value == "":
self.controller.errorMessage('"Name for remote graphics folder:" cannot be empty!')
return
bad = [" ", "."]
for x in bad:
if x in value:
self.controller.errorMessage('Please do not use . or spaces in the "Name for remote graphics folder:" field!')
return
self.theInformation["gfx_folder"] = value
self.gfxFolder.SetValue(value)
self.theInformation["url"]= self.url.GetValue()
if not self.url.GetValue().endswith('/'):
self.theInformation["url"] = self.url.GetValue() + '/'
self.saved = True
self.Close()
self.controller.model.setRemotePassword(self.getGoodPassword())
event.Skip()
def onBrowseButton(self, event):
if not makerCheckInternetConnection.check():
self.controller.infoMessage("Unable to browse remote server! No internet connection! ")
return
passw = self.controller.password()
if not passw:
return
self.ftpBrowser = makerFtpBrowser.FTPBrowser(self.parent)
if not self.ftpBrowser.ftpBrowserAction_connect_(self.ftp_host.GetValue(),
self.ftp_user.GetValue(),
self.ftp_root.GetValue(),
passw):
return None
self.keepGoodPassword(passw)
self.ftpBrowser.ftpBrowserAction_ls_()
pathName = self.ftpBrowser.ftpBrowserShow()
if pathName:
self.ftp_root.SetValue(pathName)
event.Skip()
def onCancelButton(self, event):
self.saved = False
self.Close()
event.Skip()
def onHelpButton(self, event):
self.projectModel.help('#setup')
event.Skip()