-
Notifications
You must be signed in to change notification settings - Fork 8
/
projectbundleConversion_spec.py
451 lines (323 loc) · 12.7 KB
/
projectbundleConversion_spec.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/usr/bin/python
# -*- coding: utf-8 -*-
import unittest
import os
import shutil
import makerProjectManager
import makerWxGUI
import makerEditorWxView
import wx
import sys
import makerVersion
from random import randint
class TestApp(wx.App):
def OnInit(self):
self.mainView = self.create(None)
return True
def create(self, parent):
return TestView(parent)
class ProjectManagerTestController(makerProjectManager.ProjectManagerController):
def importProjectDialog(self):
project = self.view.getDirFromUser()
if not project:
return None
else:
print "import Dialog returning:", project
return project
def showProgress(self, limit, Message, title):
print Message
def updateProgressPulse(self, foo):
print "updating progress pulse"
def infoMessage(self, message):
self.view.Message(message)
print "Info Message:", message
def errorMessage(self, message):
self.view.Error(str(message))
print "Error Message:", message
def dirDialog(self, message):
return self.view.getDirFromUser(message)
class TestProjectManager(makerProjectManager.ProjectManager):
def __init__(self, view):
self.controller = ProjectManagerTestController(self, view)
self.linkedProjectPaths = []
self.loadLinkedProjects()
self.linkedProjects = {}
self.controller.listProjectsInTree(self.getProjects())
self.openProjects = []
self.openFiles = []
self.projectConvertRepoName = "Test-YourMakerProjects"
self.loadArgumentPassedProject()
# call converter manually for testing
# self.checkForSandboxedProjects()
def getSystemPath(self):
""" get system path """
return os.path.join(os.getcwd(), "system/")
def getApplicationPath(self):
""" get path where the maker executable resides """
appPath = os.path.join(os.getcwd(), ".")
return appPath
def getApplicationSupportDir(self):
try:
theDir = os.environ["HOME"]
except:
theDir = os.environ["HOMEPATH"]
return os.path.join(theDir, "Library/Application Support/TheMaker-TESTING/")
class TestView(makerWxGUI.wxPythonGUI):
def _init_ctrls(self, prnt):
wx.Frame.__init__(
self,
id=-1,
name="",
parent=prnt,
pos=wx.Point(0, 0),
size=wx.Size(1200, 700),
style=wx.DEFAULT_FRAME_STYLE,
title=u"the maker",
)
self.base = "/Users/maker/Documents/workspace/TheMaker"
try: # - don't sweat it if it doesn't load
self.SetIcon(
wx.Icon(os.path.join(self.base, "system/tags.ico"), wx.BITMAP_TYPE_ICO)
)
finally:
pass
self._init_utils()
self.SetMenuBar(self.mainMenuBar)
self.SetStatusBarPane(0)
# the other splitter
# self.splitter2 = MySplitter(self, -1,None)
# the top splitter
self.splitter = makerWxGUI.MySplitter(self, -1, None)
# and the stc is added to it
# it is very importat to keep the NODRAG style
#
# if dragging is added at some point the
# makerProjectController.py method noteBookPageClosed has to be
# changed where the noteBoolPages dict is updated
#
# self.noteBook = nb.FlatNotebook(self.splitter, -1, style= wx.lib.flatnotebook.FNB_NODRAG
# | wx.lib.flatnotebook.FNB_X_ON_TAB)
self.noteBook = makerWxGUI.MyCustomNoteBook(self.splitter, -1, None, None)
self.noteBook.SetPadding(wx.Size(20))
# add a welcome message to the noteBook
self.styledTextCtrl1 = (makerEditorWxView.editorView(self, "default")).editor
self.welcomeId = self.styledTextCtrl1.GetId()
self.noteBook.AddPage(self.styledTextCtrl1, "Thank you for using The Maker.")
self.styledTextCtrl1.SetText(self.BoilerPlate)
# switch off popup
# self.styledTextCtrl1.Bind(wx.EVT_RIGHT_DOWN, self.OnSTCRightDown)
# add widgets to the first splitter
self.listWindow = wx.Panel(self.splitter, -1, style=wx.NO_BORDER)
# self.listWindow.SetBackgroundColour(wx.RED)
self.listSizer = wx.BoxSizer(orient=wx.VERTICAL)
# the listbox is added to the splitter too
self.tree = wx.TreeCtrl(
self.listWindow,
-1,
style=wx.TR_HAS_BUTTONS | wx.TR_LINES_AT_ROOT | wx.TR_DEFAULT_STYLE,
)
def drawAfterPaint(evt):
Size = self.tree.GetClientSizeTuple()
dc = wx.ClientDC(self.tree)
dc.SetPen(self.treePen)
dc.DrawLine(Size[0] - 1, 0, Size[0] - 1, Size[1])
def onTreePaint(evt):
wx.CallAfter(drawAfterPaint, evt)
evt.Skip()
self.treePen = wx.Pen("#666666", 1)
self.tree.Bind(wx.EVT_PAINT, onTreePaint)
image_size = (16, 16)
projectArt = (
wx.Image(
os.path.join(self.base, "./system/ToolBarIcons/114.png"),
wx.BITMAP_TYPE_PNG,
)
.Scale(16, 16)
.ConvertToBitmap()
)
folderArt = (
wx.Image(
os.path.join(self.base, "./system/ToolBarIcons/99.png"),
wx.BITMAP_TYPE_PNG,
)
.Scale(16, 16)
.ConvertToBitmap()
)
folderOpenArt = (
wx.Image(
os.path.join(self.base, "./system/ToolBarIcons/107.png"),
wx.BITMAP_TYPE_PNG,
)
.Scale(16, 16)
.ConvertToBitmap()
)
fileArt = (
wx.Image(
os.path.join(self.base, "./system/ToolBarIcons/93.png"),
wx.BITMAP_TYPE_PNG,
)
.Scale(16, 16)
.ConvertToBitmap()
)
fileChangeArt = (
wx.Image(
os.path.join(self.base, "./system/ToolBarIcons/118.png"),
wx.BITMAP_TYPE_PNG,
)
.Scale(16, 16)
.ConvertToBitmap()
)
partArt = (
wx.Image(
os.path.join(self.base, "./system/ToolBarIcons/24-16.png"),
wx.BITMAP_TYPE_PNG,
)
.Scale(16, 16)
.ConvertToBitmap()
)
il = wx.ImageList(image_size[0], image_size[1])
self.projidx = il.Add(projectArt)
self.fldridx = il.Add(folderArt)
self.fldropenidx = il.Add(folderOpenArt)
self.fileidx = il.Add(fileArt)
self.filechange = il.Add(fileChangeArt)
self.part = il.Add(partArt)
# self.partArt(il, image_size)
self.tree.SetImageList(il)
self.il = il
self.listSizer.Add(self.tree, 1, border=0, flag=wx.EXPAND)
self.listWindow.SetAutoLayout(True)
self.listWindow.SetSizer(self.listSizer)
self.listSizer.Fit(self.listWindow)
self.splitter.SetMinimumPaneSize(200)
self.splitter.SplitVertically(self.listWindow, self.noteBook, 180)
self.toolBar = self.CreateToolBar(
style=wx.TB_HORIZONTAL
| wx.NO_BORDER
# | wx.TB_FLAT
| wx.TB_TEXT
)
self.search = wx.SearchCtrl(
self.toolBar,
id=-1,
pos=(750, -1),
size=(180, 25),
style=wx.TE_PROCESS_ENTER,
)
# extract the searchCtrl's textCtrl
self.searchStatus = wx.StaticText(
self.toolBar, -1, size=wx.DefaultSize, pos=wx.DefaultPosition, style=0
)
self.searchStatus.SetLabel(" ")
saveArt = wx.Bitmap(os.path.join(self.base, "./system/ToolBarIcons/23.png"))
publishArt = wx.Bitmap(os.path.join(self.base, "./system/ToolBarIcons/53.png"))
previewArt = wx.Bitmap(os.path.join(self.base, "./system/ToolBarIcons/25.png"))
makeAllArt = wx.Bitmap(os.path.join(self.base, "./system/ToolBarIcons/24.png"))
self.toolBar.AddSeparator()
self.toolBar.AddLabelTool(10, "Save", saveArt)
self.toolBar.AddLabelTool(20, "Publish", publishArt)
self.toolBar.AddLabelTool(30, "Preview", previewArt)
self.toolBar.AddLabelTool(40, "Make All", makeAllArt)
self.toolBar.AddStretchableSpace()
self.toolBar.AddControl(self.searchStatus)
self.toolBar.AddControl(self.search)
self.toolBar.Realize()
self.statusBar1 = wx.StatusBar(
id=-1, name="statusBar1", parent=self, style=wx.ST_SIZEGRIP
)
# self.statusBar1.SetConstraints(LayoutAnchors(self.statusBar1, True,
# True, False, False))
self._init_coll_statusBar1_Fields(self.statusBar1)
self.SetStatusBar(self.statusBar1)
self.styledTextCtrl1.Bind(wx.EVT_PAINT, self.OnStyledTextCtrl1Paint)
self.styledTextCtrl1.Bind(
wx.EVT_ERASE_BACKGROUND, self.OnStyledTextCtrl1EraseBackground
)
def Show(self):
pass
def Ask_YesOrNo(self, question):
return self.choiceReturnString
def Message(self, message):
self._lastInfoMessage = message
def Input(self, Question="?", title=None):
print "Input string was:", self.inputReturnString
return self.inputReturnString
def partArt(self, il, image_size):
""" don't need no custom art in this mock class """
pass
def getDirFromUser(self, dialogMessage=None):
return self.userSelectedDir
def Error(self, Message):
self._lastErrorMessage = Message
def setInputReturnString(self, string):
self.inputReturnString = string
def setChoiceReturnString(self, string):
self.choiceReturnString = string
def setUserSelectedDir(self, string):
self.userSelectedDir = string
def initError(self):
self._lastErrorMessage = ""
class MakerTest(unittest.TestCase):
def tearMeDown(self):
shutil.rmtree(self.convertedProjectsPath, True)
self.app.Destroy()
def setMeUp(self):
self.user_home = "/Users/maker/"
self.app = TestApp()
self.pm = TestProjectManager(self.app.mainView)
self.pm.controller.testing = True
self.projectPath = os.path.join(
self.pm.getApplicationSupportDir(), "makerProjects"
)
self.sandBox = self.projectPath
self.convertedProjectsPath = os.path.join(
self.user_home, self.pm.projectConvertRepoName
)
def test_importAndConvertClassicProject(self):
self.setMeUp()
testProjectBefore = os.path.join(
self.user_home, "/Users/maker/testing-makerProjects/testProject"
)
if os.path.isdir(testProjectBefore):
shutil.rmtree(testProjectBefore, ignore_errors=True)
if not os.path.isdir(testProjectBefore):
os.mkdir(testProjectBefore)
os.mkdir(os.path.join(testProjectBefore, "parts"))
testProjectAfter = os.path.join(
self.user_home,
"/Users/maker/testing-makerProjects/testProject.makerProject",
)
notAProject = os.path.join(
self.user_home, "/Users/maker/testing-makerProjects/"
)
targetDir = os.path.join(self.user_home, "/Users/maker/Desktop/")
if os.path.isdir(testProjectAfter):
os.rename(testProjectAfter, testProjectBefore)
# =======================================================================
# not a project given but wrong dir
# =======================================================================
self.app.mainView.initError()
self.app.mainView.setUserSelectedDir(notAProject)
self.pm.importClassicProject(event=None)
self.assertTrue(
"not a TheMaker" in self.app.mainView._lastErrorMessage,
"If wrong dir given - Error and return",
)
# =======================================================================
# correct classic project given
# =======================================================================
self.app.mainView.setUserSelectedDir(testProjectBefore)
self.pm.importClassicProject(event=None)
self.assertTrue(
os.path.isdir(testProjectAfter), "Project has been renamed correctly..."
)
self.assertTrue(
testProjectAfter in self.pm.linkedProjectPaths,
"Project has been linked correctly...",
)
# cleaning up
if os.path.isdir(testProjectAfter):
os.rename(testProjectAfter, testProjectBefore)
self.tearMeDown()
if __name__ == "__main__":
unittest.main()