-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmakerController.py
executable file
·358 lines (300 loc) · 12.5 KB
/
makerController.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
from Cocoa import NSOpenPanel, NSOKButton
class SuperController:
"""
A super class for all makerControllers
all controllers will inherit from this one
It provides general purpose GUI interaction methods
this class is also meant to serve as an abstraction layer
"""
def __init__(self, model, view):
self.view = view
self.model = model
self.createAbstractNameForViewObjects()
self.bindActions()
self.treeItems = []
self.treeFolders = []
self.progressBars = []
# important 'cause of the custom drawing code
# this needs to be done in general so its in this super controller
# just do this in the "right" controllers
if hasattr(self.view, 'tree'):
self.view.tree.Bind(self.view.wx.EVT_TREE_ITEM_COLLAPSED,
self.treeFixAfterProjectCollapsed)
def treeFixAfterProjectCollapsed(self, event):
""" refresh tree view """
self.view.tree.Refresh()
def bindActions(self):
""" please override """
pass
def killProgressBar(self):
try:
bar = self.getLastProgressBar()
self.deleteProgressBar(bar)
bar.Destroy()
#if self.keepGoing:
# self.StopPulse()
except Exception, e:
print "unable to Kill Progress Bar", str(e)
def deleteProgressBar(self,thisOne):
"""
! is deleting the instance from the stack
"""
self.progressBars.remove(thisOne)
def addProgressBar(self, progressBar):
self.progressBars.append(progressBar)
def getLastProgressBar(self):
"""
returns the instance of the progressbar that was last added to the stack
"""
try:
return self.progressBars[-1]
except:
return None
def getAllProgressBars(self):
return self.progressBars
def showProgress(self, limit, Message="", title=None):
if not title:
title = Message
progress = self.view.wx.ProgressDialog(title,
Message,
maximum = limit,
parent=self.view,
style = self.view.wx.PD_ESTIMATED_TIME)
self.addProgressBar(progress)
progress.SetInitialSize(self.view.wx.Size(400, 160))
progress.Center()
def updateProgress(self, count):
bar = self.getLastProgressBar()
bar.Update(count)
def updateProgressPulse(self, msg=None):
bar = self.getLastProgressBar()
if msg:
bar.UpdatePulse(msg)
else:
bar.UpdatePulse()
def updateProgressMessage(self, count , message):
bar = self.getLastProgressBar()
bar.Update(count,message)
def fitRefreshAndCenter(self, widget):
"""
is calling .Fit(), .Refresh() and .CenterOnScreen() for the widget
"""
widget.Fit()
widget.Refresh()
widget.CenterOnScreen()
def password(self, Message="Enter password:"):
return self.view.Password(Message)
def infoMessage(self, message):
self.view.Message(str(message))
def infoMessageNotModal(self, message):
self.view.MessageNotModal(str(message))
def warningMessage(self, error):
self.view.Warning(str(error))
def errorMessage(self, error):
self.view.Error(str(error))
def destroyView(self):
""" overridden in some views """
print "SuperController: Destroying Views"
self.progress.Destroy()
self.view.Destroy()
def askYesOrNo(self, question):
return self.view.Ask_YesOrNo(question)
def input(self, question="?", title="Question:"):
return self.view.Input(question, title)
def inputWithValue(self, question, value):
return self.view.InputWithValue(question, value)
def colorDialog(self):
""" bring up a color picker dialog"""
self.view.ColorDialog()
color = self.view.color_data
return color
def importProjectDialog(self):
project = self.view.SelectProject()
if not project:
return None
else:
return project
def _fileDialog(self, message = None):
panel = NSOpenPanel.openPanel()
panel.setCanCreateDirectories_(False)
panel.setCanChooseDirectories_(False)
panel.setCanChooseFiles_(True)
panel.setAllowsMultipleSelection_(True)
if panel.runModal() == NSOKButton:
for item in panel.URLs():
print item
return panel.URLs()
def fileDialog(self, message = None):
"""
returns a list(!) of pathnames or None when canceled
"""
return self.view.getFileFromUser(prompt = message)
def imageDialog(self, path):
"""
returns a pathname or None when canceled
"""
return self.view.ImageDialogWithDir(path)
def resetAllViews(self):
"""
this will set all controls and views to their default state
"""
# Tools
self.view.toolBar.EnableTool(10, False) # Save
self.view.toolBar.EnableTool(20, False) # Publish
self.view.toolBar.EnableTool(30, False) # Preview
self.view.toolBar.EnableTool(40, False) # Make All
# FTP menu
self.view.MenuItemEditDist.Enable(False)
self.view.MenuItemPublish.Enable(False)
self.view.MenuItemFullUpload.Enable(False)
self.view.MenuItemBrowseFtp.Enable(False)
# Project Menu
self.view.MenuItemSetupFTP.Enable(False)
# View Menu
self.view.MenuItemWrapWord.Enable(False)
self.view.MenuItemFontInc.Enable(False)
self.view.MenuItemFontDec.Enable(False)
self.view.MenuItemFontNormal.Enable(False)
self.view.MenuItemEditorStyles.Enable(False)
# Edit Menu
self.view.MenuItemUndo.Enable(False)
self.view.MenuItemRedo.Enable(False)
self.view.MenuItemCut.Enable(False)
self.view.MenuItemCopy.Enable(False)
self.view.MenuItemPaste.Enable(False)
self.view.MenuItemReplace.Enable(False)
self.view.MenuItemFind.Enable(False)
self.view.MenuItemFindNext.Enable(False)
# Tools Menu
self.view.MenuItemEditHead.Enable(False)
self.view.MenuItemLanguages.Enable(False)
self.view.MenuItemSelectColor.Enable(False)
self.view.MenuItemUnderline.Enable(False)
self.view.MenuItemOblique.Enable(False)
self.view.MenuItemBold.Enable(False)
self.view.MenuItemLine_through.Enable(False)
# File Menu
self.view.MenuItemNewFiles.Enable(False)
self.view.MenuItemSaveFile.Enable(False)
self.view.MenuItemDeleteFile.Enable(False)
self.view.MenuItemRenameFile.Enable(False)
self.view.MenuItemSaveAsTemplate.Enable(False)
self.view.MenuItemAddToFTPQueue.Enable(False)
self.view.MenuItemCloseFile.Enable(False)
self.view.MenuItemPreview.Enable(False)
self.view.MenuItemImportFile.Enable(False)
self.view.MenuItemImportProject.Enable(True)
self.view.MenuItemOpenProject.Enable(True)
self.view.MenuItemAddProject.Enable(True)
self.view.MenuItemSaveProjectAsTemplate.Enable(False)
self.view.MenuItemPrint.Enable(False)
self.view.MenuItemQuit.Enable(True)
# Tree Contextual Menu
self.view.treePopUpMenuItemDeleteFile.Enable(False)
self.view.treePopUpMenuItemRenameFile.Enable(False)
self.view.treePopUpMenuItemCloseFile.Enable(False)
self.view.treePopUpMenuItemPreview.Enable(False)
self.view.treePopUpMenuItemPrint.Enable(False)
self.view.treePopUpMenuItemCollapseOther.Enable(False)
# Insert Menu
self.view.MenuItemHTML.Enable(False)
self.view.MenuItemCSS.Enable(False)
self.view.MenuItemMarkers.Enable(False)
self.view.MenuItemMarkdown.Enable(False)
# Parts Menu
self.view.MenuItemEditRssHead.Enable(False)
# Images Menu
self.view.MenuItemImportImage.Enable(False)
self.view.MenuItemDeleteImage.Enable(False)
self.view.MenuItemSyncImages.Enable(False)
# Status Bar
self.view.statusBar1.SetStatusText(number = 1, text='Project: ')
self.view.statusBar1.SetStatusText(number = 2, text='Language: ')
self.view.statusBar1.SetStatusText(number = 3, text='File: ')
self.view.statusBar1.SetStatusText(number = 4, text="FTP Queue: ")
def createAbstractNameForViewObjects(self):
"""
This method is called from inside __init__
Please override
In controller classes inheriting from this super class, you will
do things like:
self.tree = self.view.wxTreeCtrl1
Creating an abstract name for view objects used by a corresponding
model class
"""
def singleChoice(self, choices, title="", message=""):
return self.view.SingleChoiceDialog(choices, title, message)
def dirDialog(self, message="Choose a directory:"):
"""
returns a path or None when canceled
"""
self.view.getDirFromUser(message)
if self.view.dirDialog.ShowModal() == self.view.wx.ID_OK:
path = self.view.dirDialog.GetPath()
self.view.dirDialog.Destroy()
return path
else:
return None
def treeViewExpandItem(self, item):
try:
self.view.tree.Expand(item)
except Exception, e:
print str(e)
def treeViewCollapseItem(self, item):
try:
self.view.tree.Collapse(item)
except Exception, e:
print str(e)
def treeViewGotoRoot(self):
self.view.tree.EnsureVisible(self.view.treeGetRoot())
def treeViewGetRoot(self):
return self.view.tree.GetRootItem()
def treeViewReset(self):
if self.view.tree.GetCount() !=0:
self.view.tree.DeleteAllItems()
self.treeItems = []
def treeViewDeleteItem(self, item):
""" remove item from tree view as well as from self.treeItem"""
self.view.tree.Delete(item)
print "tree items:", self.treeItems
self.treeItems.remove(item)
def treeViewAppendItem(self, parent , itemText, type="Folder"):
newItem = self.view.tree.AppendItem(parent, itemText)
self.treeItems.append(newItem)
# set the icons for when this item is either collapsed
# or expanded
parts = [".content", ".dynamic", ".nav", ".body", ".foot", ".head"]
if type == "Folder":
self.treeFolders.append(itemText)
if itemText in parts:
self.view.tree.SetItemImage(newItem,
self.view.part,
self.view.wx.TreeItemIcon_Normal
)
self.view.tree.SetItemImage(newItem,
self.view.part,
self.view.wx.TreeItemIcon_Expanded)
else:
self.view.tree.SetItemImage(newItem,
self.view.fldridx,
self.view.wx.TreeItemIcon_Normal
)
self.view.tree.SetItemImage(newItem,
self.view.fldropenidx,
self.view.wx.TreeItemIcon_Expanded)
elif type == "Project":
# add icon for projects
self.view.tree.SetItemImage(newItem,
self.view.projidx,
self.view.wx.TreeItemIcon_Normal
)
self.view.tree.SetItemImage(newItem,
self.view.projidx,
self.view.wx.TreeItemIcon_Expanded)
# make projects more distinct
self.view.tree.SetItemBold(newItem, True)
self.view.tree.SetItemTextColour(newItem, "#333333")
else:
self.view.tree.SetItemImage(newItem, self.view.fileidx,
self.view.wx.TreeItemIcon_Normal)
return newItem