-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathParent.py
1517 lines (1387 loc) · 58.3 KB
/
Parent.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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
####(c)www.stani.be
import _spe.info as info
INFO=info.copy()
INFO['description']=\
"""Subclassed smdi Parent frame."""
__doc__=INFO['doc']%INFO
####Importing modules-----------------------------------------------------------
#---general modules
import ConfigParser,os,string,sys,thread,time,types,webbrowser, pprint
import _spe,sm.scriptutils,sm.wxp
import dialogs.stcStyleEditor
#---wxPython
import wx
import wx.stc
from wx.lib.evtmgr import eventManager
BLENDER_MESSAGE = 'Spe must be launched within Blender for this feature.'
STATUS_TEXT_WORKSPACE_POS = 2 # Todo: can this be done more dynamic?
import Child
####Constants-------------------------------------------------------------------
DEFAULT = "<default>"
FIREFOX = '/usr/bin/firefox'
NAUTILUS = '/usr/bin/nautilus'
DOLPHIN = '/usr/bin/dolphin'
KONQUEROR = '/usr/bin/konqueror'
THUNAR = '/usr/bin/thunar'
PCMANFM = '/usr/bin/pcmanfm'
HELP_SORRY = "Sorry, '%s' was not found on your system, getting it from internet instead."
HELP_WWW = 'http://www.python.org/doc/current/%s/%s.html'
MAIL = 'mailto:[email protected]?subject=About spe...'
PATH = info.dirname(__file__)
PLATFORM = sys.platform
PREFIX = sys.prefix
SIZE = (600,1)
SKIN = 'default'
TABS = ['Shell','Locals','Session','Output','Find','Browser','Recent','Todo','Index','Notes','Donate']
TITLE = 'SPE %s'
UNNAMED = 'unnamed'
RECENT = 'recent.txt'
FOLDERS = 'folders.txt'
NOTES = 'notes.txt'
REMEMBER = 'remember.txt'
if info.LINUX:
STYLE = wx.NB_TOP
else:
STYLE = wx.NB_BOTTOM
BLENDER_SHORTCUT_SPE = "spe_blender.py" #a shortcut to SPE from Blender
BLENDER_SHORTCUT_WINPDB = "winpdb_blender.py" #a shortcut to Winpdb from Blender
####Subclassed Parent class-----------------------------------------------------
class Panel(wx.Notebook):
####Constructors
def __init__(self, parent, openFiles=[], splash=None, redirect=1, path=PATH,
size = SIZE,**settings):
wx.Notebook.__init__(self,parent=parent,id=wx.ID_ANY,style=STYLE,size=size)
self.__paths__(path)
self.__settings__(openFiles,redirect,**settings)
self.__findReplaceEvents__()
# Todo: make this a real class instead of this lazy one
self.workspace=self.emptyWorkspace()
def __timer__(self):
self.lock = thread.allocate_lock()
#self.Bind(wx.EVT_IDLE,self.onIdle)
self.Bind(wx.EVT_TIMER,self.onTimer)
#self.was_idle = False
self.timer = wx.Timer(self)
wx.CallAfter(self.timer.Start,self.getValue('Redraw'))
def __paths__(self,path,skin='default'):
self.path = path
self.pathDoc = os.path.join(self.path, 'doc')
self.pathSkins = os.path.join(self.path, 'skins')
self.pathImages = os.path.join(self.pathSkins, skin)
self.pathPlugins = os.path.join(self.path, 'plugins')
self.pathTabs = os.path.join(self.path, 'tabs')
if self.pathPlugins not in sys.path:
sys.path.insert(0,self.pathPlugins)
try:
os.mkdir(INFO['userPath'])
except:
if not os.path.exists(INFO['userPath']):
print 'Warning: could not find or create user path (%s).'%INFO['userPath']
def __settings__(self,openFiles,redirect,redraw=None,Blender=None,**kwds):
#arguments
self._openFiles = openFiles
self._redirect = redirect
self._simultaneous = False
self.redraw = redraw
self.Blender = Blender
#panel
self.argumentsPrevious = []
self.beepPrevious = False
self.defaultEncoding = None
self.findDialog = None
self.folders = []
self.kiki = None
self.remember = 0
self.restartMessage = ''
self.runner = None
if PLATFORM == 'win32':
self.LIST_STYLE = wx.LC_SMALL_ICON# todo: verify this better |wx.LC_LIST
else:
self.LIST_STYLE = wx.LC_LIST
def __findReplaceEvents__(self):
self.findStr=''
self.replaceStr=''
self.findFlags=1
self.stcFindFlags=0
#This can't be done with the eventManager unfortunately ;-(
wx.EVT_COMMAND_FIND(self,-1,self.onFind)
wx.EVT_COMMAND_FIND_NEXT(self, -1,self.onFind)
wx.EVT_COMMAND_FIND_REPLACE(self, -1,self.onReplace)
wx.EVT_COMMAND_FIND_REPLACE_ALL(self, -1,self.onReplaceAll)
wx.EVT_COMMAND_FIND_CLOSE(self, -1,self.onFindClose)
#---finish
def __finish__(self):
self.__icons__()
self.__sash__()
self.__frame__()
#self.app.childActive.source.SetFocus()
def __icons__(self):
self.iconsList=wx.ImageList(16,16)
self.icons={}
self.iconsListIndex={}
iconFiles=sm.osx.listdir(self.pathImages,extensions=['.png'])
iconFiles.sort()
for icon in iconFiles:
self.icons[icon]=self.app.bitmap(icon)
if self.icons[icon].GetHeight() == 16:
self.iconsListIndex[icon]=self.iconsList.Add(self.icons[icon])
def __sash__(self):
if self.app.DEBUG: print 'Creating tabs...'
self.config = self.app.config
self.AssignImageList(self.iconsList)
tabs = [os.path.splitext(x)[0] for x in sm.osx.listdir(self.pathTabs,extensions=['.py']) if x[:1]!='_']
tabs.sort()
tabs = TABS[:-1] + [x for x in tabs if x not in TABS] + [TABS[-1]]
if not self.app.Blender:
tabs.remove('Blender')
self.tabPanel = {}
for tab in tabs:
if self.app.DEBUG: print '\t',tab
__import__('_spe.tabs.'+tab)
page = self.__dict__[tab.lower()] = eval('_spe.tabs.%s.Panel'%tab)(self)
if info.DARWIN and tab!='Shell': text = ''
else: text = tab
self.AddPage(page=page,text=text,imageId=self.iconsListIndex[tab.lower()+'.png'])
self.tabPanel[tab] = page
self.tabs = tabs
if self.get('version')!=INFO['version']:
self.SetSelection(self.GetPageCount()-1)
self.set('version',INFO['version'])
eventManager.Register(self.onTab,wx.EVT_NOTEBOOK_PAGE_CHANGED,self)
if self.getValue('Redraw') < 10:
self.set('Redraw',self.getValue('Redraw')*1000)
self.__timer__()
def __frame__(self):
#parent frame
frame = self.frame
frame.SetDropTarget(Child.DropOpen(self.openList))
icon = wx.Icon(os.path.join(self.pathImages,'favicon.ico'),wx.BITMAP_TYPE_ICO)
frame.SetIcon(icon)
if hasattr(frame,'panelFrame'):
frame.panelFrame.SetIcon(icon)
#constructors
self.preferencesSave()
self.__remember__(openFiles=self._openFiles)
self.__menus__()
def __menus__(self):
#parentInit.importMenus
menuBar = self.frame.menuBar
if self.app.mdi:
#d#self.frame.menuBar.parentPanel = self
menuBar.check_sidebar()
menuBar.check_view()
if not self.app.children:
menuBar.enable(0)
def __remember__(self,openFiles=[]):
self.__openWorkspace__() #this prepares the currentworkspace to be used
try:
self.get("currentworkspace") #This will fail if there is no current workspace to get
except:
pass # Open default workspace?
self.loadWorkspace()
if len(openFiles)>0:
self.rememberSet(1)
self.openList(openFiles)
if len(self.app.children)==0:
self.new(maximize = self.getValue("MaxChildren"))
#---Workspace
def _createNewDefaultWorkspace(self):
#if not os.path.exists(self.workspace['file']):
file=os.path.join(INFO['userPath'],'defaults.sws')
if not os.path.isfile(file):
new_cf=ConfigParser.ConfigParser()
# Recent
new_cf.add_section("recent")
try:
new_cf.set("recent","1",self.userOpen(RECENT))
except:
new_cf.set("recent","1","")
# Folders
new_cf.add_section("folders")
try:
new_cf.set("folders","1",self.userOpen(FOLDERS))
except:
new_cf.set("folders","1","")
# Notes
new_cf.add_section("notes")
try:
new_cf.set("notes","1",self.userOpen(NOTES))
except:
new_cf.set("notes","1","")
# OpenFiles
new_cf.add_section("openfiles")
try:
new_cf.set("openfiles","1",self.userOpen(REMEMBER))
except:
new_cf.set("openfiles","1","")
f=open(file,"w")
new_cf.write(f)
f.close()
return file
def __openWorkspace__(self):
#read the default workspace for the 'global' items
file=INFO['defaultWorkspace']
if not os.path.isfile(file):
self._createNewDefaultWorkspace()
self.workspace['defaultconfig']=ConfigParser.ConfigParser()
self.workspace['defaultconfig'].read(file)
#read the specific workspace for the 'local' items
#this can be blocked in two ways:
# 1 self.getValue('RememberLastWorkspace') is False
# 2 incorrect workspace files
self.workspace['config']=ConfigParser.ConfigParser()
if self.getValue('RememberLastWorkspace'):
try:
file = self.get("currentworkspace")
if not os.path.exists(file): file = ''
except:
file = ''
try:
self.workspace['config'].read(file)
self.workspace['file']=file
except:
file = ''
else:
file = ''
if file is '':
self.workspace['config']=self.workspace['defaultconfig']
self.workspace['file']=INFO['defaultWorkspace']
self.workspace['openfiles']=[]
if self.getValue('RememberLastWorkspace'):
#open the workspace files in SPE
try:
openFiles=eval(self.getWorkspaceValue("OpenFiles"))
for i in openFiles:
self.workspace['openfiles'].append(i[0])
except Exception,e:
if self.app.DEBUG:
self.SetStatusText("Error opening workspace file %s: %s"%(file,e))
else:
self.setWorkspaceValue("openfiles",str([]))
def applyWorkspaceTab(self,child):
""" this function will change the child tab to indicate that it is part of the workspace """
self.name = os.path.basename(child.fileName)
if not (self.frame.dead or child.frame.dead):
try:
child.frame.setTitle(self.name,colour=wx.WHITE)
except Exception, e:
print e
def loadWorkspace(self):
try:
if self.getValue('CloseChildrenOnNewWorkspace'):
#Close all open children
for child in self.app.children: #this doesn't loop through all the children (leaves one left)
child.frame.onFrameClose()
except:
pass
#load the Recent Files
self.recent.files=[]
default=False
if self.getValue('globalRecent'): default=True
try:
files=eval(self.getWorkspaceValue("Recent",default))
self.recent.add([file for file in files if file and os.path.exists(file)])
except:
pass
#load the Folders
default=False
if self.getValue('globalFolders'): default=True
try:
folders=eval(self.getWorkspaceValue("Folders",default))
self.browser.depth.SetValue(folders[0])
self.browser.add([file for file in folders[1:] if file])
except:
pass
#load the Notes
default=False
if self.getValue('globalNotes'): default=True
try:
notes=self.getWorkspaceValue("Notes",default)
self.notes.SetValue(notes)
except:
pass
#load the openfiles (the old 'remember.txt')
fileList=[]
default=False
if self.getValue('globalFileList'): default=True
try:
files=eval(self.getWorkspaceValue("OpenFiles",default))
fileList=[file for file in files if file]
except:
pass
if fileList:
self.rememberSet(1)
self.openList(fileList,
message = 0,
select = None,
maximize = self.getValue("MaxChildren"),
verbose = True)
self.setWorkspaceStatusBarText(self.workspace['file'])
def setWorkspaceStatusBarText(self,file):
self.SetActiveStatusText(os.path.basename(file)[:-4],STATUS_TEXT_WORKSPACE_POS)
def emptyWorkspace(self):
return { 'config' : ConfigParser.ConfigParser() ,
'file' : "" ,
'openfiles' : [],
'defaultconfig' : ConfigParser.ConfigParser()
}
def saveWorkspace(self,filelocation=None):
if filelocation is '': return
if self.app.children:
childActive = self.app.childActive
fileList=[]
if self.app.children:
self.workspace['openfiles']=[]
for child in self.app.children:
if child.fileName != Child.NEWFILE:
pos = child.source.GetCurrentPos()
lineno = child.source.LineFromPosition(pos)
col = child.source.GetColumn(pos)
fileList.append((child.fileName,lineno,col))
self.workspace['openfiles'].append(child.fileName)
self.applyWorkspaceTab(child)
self.setWorkspaceValue("notes",self.notes.GetValue())
self.setWorkspaceValue("openfiles",str(fileList))
self.setWorkspaceValue("recent",str(self.recent.files[:self.getValue('RecentFileAmount')]))
self.setWorkspaceValue("folders",str([self.browser.depth.GetValue()]+self.browser.getFolders()[1:]))
if not filelocation: filelocation=self.workspace['file']
try:
file=open(filelocation,'w')
self.workspace['config'].write(file)
file.close()
self.workspace['file']=filelocation
self.setWorkspaceStatusBarText(filelocation)
except Exception, message:
print 'Spe warning: could not save workspace options in',filelocation
print message
self.applyWorkspaceTab(childActive)
def getWorkspaceValue(self,type,default=False):
""" returns the value of the workspace config file key """
if default:
return self.workspace['defaultconfig'].get(type.lower(),"1")
else:
return self.workspace['config'].get(type.lower(),"1")
def setWorkspaceValue(self,type,value):
""" sets the workspace config file key to a specific value """
if not self.workspace['config'].has_section(type): self.workspace['config'].add_section(type)
self.workspace['config'].set(type.lower(),"1",value)
####Menu
#---File
def new(self,name=UNNAMED,source='',maximize=None):
"""Create a new empty script window.?"""
app = self.app
child = app.ChildFrame(self.frame,
page = os.path.basename(name),
extra = name,
fileName = name,
source = source,
size = app.size,
maximize = maximize)
self.frame.menuBar.enable(1)
return child.panel
def open(self, event=None):
"""Open file(s) dialog."""
try:
defaultDir = info.dirname(self.app.childActive.fileName)
except:
defaultDir = ''
dlg = wx.FileDialog(self, "Choose a file - www.stani.be",
defaultDir=defaultDir, defaultFile="",
wildcard=info.WILDCARD,
style=wx.OPEN|wx.MULTIPLE)
if dlg.ShowModal() == wx.ID_OK:
fileList = dlg.GetPaths()
if fileList and self.app.children:
child = self.app.childActive
if child and child.fileName==Child.NEWFILE and not child.changed:
child.frame.onFrameClose()
self.openList(fileList)
dlg.Destroy()
def open_workspace(self):
"""Open file dialog."""
try:
defaultDir=info.dirname(self.workspace['file'])
except:
defaultDir=''
dlg = wx.FileDialog(self, "Choose a file - www.stani.be",
defaultDir=defaultDir, defaultFile="",
wildcard=info.WORKSPACE_WILDCARD,
style=wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
file = dlg.GetPath()
try:
self.set("currentworkspace",file)
self.__openWorkspace__()
self.loadWorkspace()
except Exception,e:
self.message("Could not open workspace:%s\n%s"%(file,e))
dlg.Destroy()
def save_workspace(self):
"""Save file dialog."""
try:
self.saveWorkspace()
except Exception,e:
self.message("Could not save workspace:%s\n%s"%(file,e))
def save_workspace_as(self):
"""Save file dialog."""
try:
defaultFile = self.workspace['file']
except:
defaultFile = ''
if info.WIN:
defaultFile = defaultFile.replace("/","\\")
dlg = wx.FileDialog(self, "Save Workspace As - www.stani.be",
defaultFile = defaultFile,
defaultDir = info.dirname(defaultFile),
wildcard = info.WORKSPACE_WILDCARD,
style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR)
if dlg.ShowModal() == wx.ID_OK:
file = dlg.GetPath()
try:
self.set("currentworkspace",file)
self.saveWorkspace(file)
except Exception,e:
self.message("Could not save workspace:%s\n%s"%(file,e))
dlg.Destroy()
def save(self):
if self.getValue('SaveWorkspaceOnFileSave'):
self.saveWorkspace()
#---Edit
def browse_source(self, event=None):
"""Locate source file of word and open it."""
if self.app.children:
fileName=self.app.childActive.source.getWordFileName(whole=1)
if fileName and fileName[0]!='"':
self.openList(fileName)
else:
if not fileName: fileName=''
self.SetActiveStatusText('Sorry, can not locate file %s'%fileName)
def find_replace(self, event=None):
"""Find and Replace dialog and action."""
if self.app.children:
#find string
findStr = self.app.childActive.source.GetSelectedText()
if findStr and self.findDialog:
self.findDialog.Destroy()
self.findDialog = None
#dialog already open, if yes give focus
if self.findDialog:
self.findDialog.Show(1)
self.findDialog.Raise()
return
if not findStr:
findStr = self.findStr
self.numberMessages=0
#find data
data = wx.FindReplaceData(self.findFlags)
data.SetFindString(findStr)
data.SetReplaceString(self.replaceStr)
#dialog
self.findDialog = wx.FindReplaceDialog(self, data, "Find & Replace",
wx.FR_REPLACEDIALOG|wx.FR_NOUPDOWN)
x, y = self.frame.GetPosition()
self.findDialog.SetPosition((x+5,y+200))
self.findDialog.Show(1)
self.findDialog.Raise()
self.findDialog.data = data # save a reference to it...
def execute(self):
"""Execute"""
if self.app.children:
child = self.app.childActive
source = child.source
code = source.GetSelectedText()
if not code.strip():
if self.getValue('ExecuteWarning') and not self.messageConfirm('As there is no code selected,\nSPE will run the whole script.\n\nAre sure you want to continue?'):
return
if self.getValue('SaveBeforeRun') and not child.confirmSave():
return
child.setStatus('As there is no code selected, SPE will run the whole script.')
code = source.GetText()
self.shell.Execute(code)
#thread.start_new_thread(self.shell.Execute,(code,))
def preferences(self):
"""Show preferences dialog box."""
from dialogs import preferencesDialog
prefs=preferencesDialog.Create(self,-1,'')
prefs.ShowModal()
#---Blender
def add_spe_to_blender(self):
"""Adds SPE and Winpdb shortcuts to Blender menu"""
from distutils.file_util import copy_file
import Blender
#important local variables
#
srcdir = info.PATH #_spe directory
dstdir = Blender.Get('uscriptsdir') #preferred Blender script directory (can be '')
altdir = Blender.Get('scriptsdir') #the other Blender script directory
#'uscriptsdir' can be empty - in such case use 'scriptsdir':
if not dstdir: dstdir, altdir = altdir, None
#
#2. Main operation: try to update the *.py file at dstdir,
# optionally remove eventual old location from altdir:
#
cpyresult = rmresult = mresult = "" #helpers for message fromatting
for fname in (BLENDER_SHORTCUT_SPE,BLENDER_SHORTCUT_WINPDB):
src = os.path.join(srcdir,fname)
result = copy_file(src, os.path.join(dstdir,fname),update=1)
if result[1]: #copied!
cpyresult += ", " + fname #if suceeded: add fname to the message
#
#if we have copied fname with success - there should not be
# two fname scripts (one for every Blender scripts directory):
# try to remove the unwanted one from the altdir (Blender 'scriptsdir')
#
if altdir and os.access(altdir,os.W_OK):
try: #let's try to remove it from unused dir:
os.remove(os.path.join(altdir, fname))
rmresult += ", " + fname #OK, succeed: add fname to the message
except:
pass #just continue - it is not a big problem
#
#3. Update Blender:
#
Blender.UpdateMenus()
#
#4. Final message to the user:
#
#([2:] is used in strings to discard leading ", "):
msg = "Blender menu updated.\n\n"
if cpyresult: msg+= "Copied %s to %s.\n\n" % (cpyresult[2:], dstdir)
if rmresult: msg+= "Removed %s from %s. " % (rmresult[2:], altdir)
self.message(msg)
#self.SetStatusText(msg,1)
#---View
def whitespace(self,event):
"""Toggle visibility white space."""
for child in self.app.children:
child.source.SetViewWhiteSpace(event.IsChecked())
self.set('ViewWhiteSpace',event.IsChecked())
def linenumbers(self,event):
"""Toggle visibility line numbers."""
for child in self.app.children:
if event.IsChecked():
child.source.SetMarginWidth(1, 50)
else:
child.source.SetMarginWidth(1, 0)
self.set('ViewLineNumbers',event.IsChecked())
def indentation_guides(self,event):
"""Toggle visibility indentation guides."""
for child in self.app.children:
child.source.SetIndentationGuides(event.IsChecked())
self.set('IndentationGuides',event.IsChecked())
def right_edge_indicator(self,event):
"""Toggle visibility right edge indicator."""
for child in self.app.children:
child.source.SetViewEdge(event.IsChecked())
self.set('ViewEdge',event.IsChecked())
def end_of_line_marker(self,event):
"""Toggle visibility end of line marker."""
for child in self.app.children:
child.source.SetViewEOL(event.IsChecked())
self.set('ViewEol',event.IsChecked())
def as_notebook(self,event):
if hasattr(self.frame,'Tile'):
if self.app.children:
self.app.childActive.frame.Maximize()
else:
tabs = getattr(self.frame,'tabs',None)
if tabs:
tabs.Tile(False)
def as_columns(self,event):
if hasattr(self.frame,'Tile'):
self.frame.Tile(wx.VERTICAL)
else:
tabs = getattr(self.frame,'tabs',None)
if tabs:
tabs.Tile(True, wx.VERTICAL)
def as_rows(self,event):
if hasattr(self.frame,'Tile'):
self.frame.Maximize(wx.HORIZONTAL)
else:
tabs = getattr(self.frame,'tabs',None)
if tabs:
tabs.Tile(True, wx.HORIZONTAL)
def toggle_shell(self):
"""Show/hide shell"""
frame = self.frame
if hasattr(frame,'sash'):
height = frame.sash.GetSize()[1]
if height<10:
hidden = 1
else:
hidden = 0
elif hasattr(frame,'panelFrame'):
hidden = not frame.panelFrame.IsShown()
elif hasattr(frame,'split'):
hidden = not frame.split.IsSplit()
else: return False
self.showShell(hidden,save=True)
return hidden
def showShell(self,show,save=False):
if save: self.set('ShowShell',show)
frame = self.frame
if hasattr(frame,'sash'):
if show:
frame.sash.SetDefaultSize(wx.Size(1000,200))
else:
frame.sash.SetDefaultSize(wx.Size(1000,1))
wx.LayoutAlgorithm().LayoutMDIFrame(frame)
elif hasattr(frame,'panelFrame'):
frame.panelFrame.Show(show)
frame.panelFrame.Activate()
elif hasattr(frame,'split'):
if show:
frame.split.SplitHorizontally(frame.tabs, self, -200)
else:
frame.split.Unsplit()
## def showToolbar(self,show,save=False):
## if save: self.set('ShowToolbar',show)
## frame = self.frame
## if hasattr(frame,'toolBar'):
## if show:
## frame.sash.SetDefaultSize(wx.Size(1000,200))
## else:
## frame.sash.SetDefaultSize(wx.Size(1000,1))
## wx.LayoutAlgorithm().LayoutMDIFrame(frame)
#---Tools
def browse_folder(self):
"""Browse folder"""
if self.app.children:
child = self.app.childActive
if hasattr(child,'fileName'):
path = info.dirname(child.fileName)
if not os.path.exists(path):
path = os.getcwd()
else:
path = os.getcwd()
if os.path.exists(THUNAR):
os.system('%s "%s" &'%(THUNAR,path))
elif os.path.exists(NAUTILUS):
os.system('%s --no-desktop "%s" &'%(NAUTILUS,path))
elif os.path.exists(DOLPHIN):
os.system('%s "%s" &'%(DOLPHIN,path))
elif os.path.exists(KONQUEROR):
os.system('%s "%s" &'%(KONQUEROR,path))
elif os.path.exists(PCMANFM):
os.system('%s "%s" &'%(PCMANFM,path))
else:
if path[0] == '/': path = 'file://'+path
webbrowser.open(path)
def run(self):
if self.output.IsBusy():
if self.messageConfirm('SPE will try to kill the running script.\n\nWarning:this might kill SPE as well.\nIt is highly recommended to save all scripts first.\n\nAre you sure you want to continue?'):
self.output.Kill()
else:
self.output._check_run(False)
return
if self.app.children:
child = self.app.childActive
if not child.confirmSave():
self.output._check_run(False)
return
if child.isNew():
self.output._check_run(False)
return
from _spe.dialogs.runDialog import RunDialog
runDialog = RunDialog(child.fileName,
self.argumentsPrevious,
self.beepPrevious,
parent=self.frame,
id=-1)
answer = runDialog.ShowModal()
arguments = runDialog.arguments.GetValue()
beep = runDialog.beep.GetValue()
runDialog.Destroy()
if answer == wx.ID_OK:
if not (arguments in self.argumentsPrevious):
self.argumentsPrevious.insert(0,arguments)
self.beepPrevious = beep
self.run_with_arguments(arguments,beep=beep,confirm=False)
else:
self.output._check_run(False)
def run_with_arguments(self,arguments='',beep=True,confirm=True):
if self.output.IsBusy():
self.output.Kill()
return
if self.app.children:
child = self.app.childActive
if confirm and not child.confirmSave():
return
if child.isNew(): return
# todo: input stuff from preferences dialog box!
path, fileName = os.path.split(child.fileName)
params = { 'file': info.path(child.fileName),
'path': path,
'arguments': arguments,
'python': info.PYTHON_EXEC}
#label = params['label'] = '"%(file)s" %(arguments)s'%params
label = params['label'] = '%(file)s %(arguments)s'%params
os.chdir(path)
self.output.Execute("""%(python)s -u %(label)s"""%params,label=label,beep=beep)
def run_debug(self):
"""Run file"""
if not self.runner:
try:
from _spe.plugins.spe_winpdb import Runner
except ImportError:
self.messageError('You need to install\n'
'winpdb for this feature.')
return
self.runner = Runner(self.app)
self.runner.switch()
def import_(self):
"""Import"""
if self.app.children:
child = self.app.childActive
if not self.getValue('SaveBeforeRun') or child.confirmSave():
if child.isNew(): return
self.busyShow()
name = child.fileName
self.shell.write('Importing "%s" ...'%name)
self.shell.waiting = 1
sm.scriptutils.importMod(name,mainDict=self.shell.locals)
self.shell.waiting = 0
self.shell.prompt()
if self.redraw: self.redraw()
self.activateShell()
self.busyHide()
def debug(self):
child = self.app.childActive
if not child.confirmSave():
return
if child.isNew(): return
if not self.runner:
try:
from _spe.plugins.spe_winpdb import Runner
except ImportError:
self.messageError('You need to install\n'
'winpdb for this feature.')
return
self.runner = Runner(self.app)
self.runner.debug()
def browse_object_with_pyfilling(self):
"""Browse object with pyfilling"""
from wx.py.filling import FillingFrame
name=self.messageEntry('Enter object:')
try:
object=self.shell.interp.locals[name]
except:
self.SetActiveStatusText('%s is not defined'%name,1)
return
filling=FillingFrame(parent=self, id=-1, title='PyFilling',
pos=wx.DefaultPosition, size=wx.Size(600,300),
style=wx.DEFAULT_FRAME_STYLE, rootObject=object,
rootLabel=str(object), rootIsNamespace=0, static=0)
filling.Show(1)
wx.FutureCall(1000,filling.Raise)
def test_regular_expression_with_kiki(self):
"""Test regular expression with Kiki..."""
try:
self.kiki.Raise()
except:
try:
from kiki import kiki
except ImportError:
from plugins.kiki import kiki
INFO['kikiPath']=info.dirname(kiki.__file__)
self.kiki=kiki.speCreate(self,info=INFO)
self.SetStatusText('Kiki is succesfully started.',1)
def design_a_gui_with_wxglade(self):
try:
import subprocess
glade = subprocess.Popen(['which','wxglade'],
stdout=subprocess.PIPE).stdout.read().strip()
os.spawnl(os.P_NOWAIT,glade,glade)
return
except:
pass
try:
from wxglade import __file__ as fileName
except ImportError:
from plugins.wxGlade import __file__ as fileName
except:
self.messageError('You need to install\n'
'wxglade (python-wxglade)\n'
'for this feature.')
return
path = info.dirname(fileName)
glade = '%s'%os.path.join(path,'wxglade.py')
if info.WIN and ' ' in glade:
glade = '"%s"'%glade
os.spawnl(os.P_NOWAIT,info.PYTHON_EXEC,info.PYTHON_EXEC,glade)
self.SetStatusText('wxGlade is succesfully started.',1)
def design_a_gui_with_xrc(self):
try:
from wx.tools.XRCed import xrced
except ImportError:
from plugins.XRCed import xrced
except:
self.messageError('You need to install\n'
'the wxpython tools (python-wxtools)\n'
'for this feature.')
return
import plugins
path = os.path.dirname(plugins.__file__)
xrced = '%s'%os.path.join(path,'spe_xrced.py')
if info.WIN and ' ' in xrced:
xrced = '"%s"'%xrced
os.spawnl(os.P_NOWAIT,info.PYTHON_EXEC,info.PYTHON_EXEC,xrced)
self.SetStatusText('XRC editor is succesfully started.',1)
#---Links
def contact_author(self):
WebBrowser=self.get('WebBrowser')
if WebBrowser==DEFAULT:
webbrowser.open(MAIL)
else:
os.system("%s '%s'"%(WebBrowser,MAIL))
#---Help
def keyboard_shortcuts(self):
from dialogs import helpShortcutsDialog
helpShortcutsDialog.create(self,path=self.path).Show(1)
def python_help(self,what):
pythonDocs = self.get('PythonDocs')
wwwHelp = HELP_WWW%(what,what)
if pythonDocs==DEFAULT:
if sys.platform=='win32':
helpActivePython=os.path.join(PREFIX,"Doc","ActivePython.chm")
helpEntoughtPython=os.path.join(PREFIX,"Enthought","Doc","enthought_python.chm")
if os.path.exists(helpActivePython):
self.messageHtml(helpActivePython)
elif os.path.exists(helpEntoughtPython):
self.messageHtml(helpEntoughtPython)
else:
library=os.path.join(PREFIX,"Doc",what,"index.html")
if os.path.exists(library):
self.messageHtml(library)
else:
self.messageHtml(wwwHelp)
self.SetStatusText(HELP_SORRY%library,1)
else:
linux1=''.join([PREFIX, "/share/doc/python", str(sys.version_info[0]),
".", str(sys.version_info[1]), "/html/%s/index.html"%what])
linux2=''.join([PREFIX, "/share/doc/python-docs-",
str(sys.version_info[0]), ".", str(sys.version_info[1]), ".",
str(sys.version_info[2]), "/html/%s/index.html"%what])
if os.path.exists(linux1):self.messageHtml(linux1)
elif os.path.exists(linux2):self.messageHtml(linux2)
else:
self.messageHtml(wwwHelp)
self.SetStatusText(HELP_SORRY%linux1,1)
else:
# TODO: pythondocs laten loopen over alle mogelijkheden, dit iets eleganter.
helpActivePython=os.path.join(pythonDocs,"Doc","ActivePython.chm")
if sys.platform=='win32' and os.path.exists(helpActivePython):
library = helpActivePython
else:
library = os.path.join(pythonDocs,what,"index.html")
if os.path.exists(library):
self.messageHtml(library)
else:
self.messageHtml(wwwHelp)
self.SetStatusText(HELP_SORRY%library,1)
def python_documentation_server(self):
from pydoc import __file__ as fileName
os.spawnl(os.P_NOWAIT,info.PYTHON_EXEC,info.PYTHON_EXEC,fileName,'-g')
self.messageHtml('http://localhost:7464/')
def wxwindows_documentation(self):
WxPythonDocs=self.get('WxPythonDocs')
if WxPythonDocs==DEFAULT:
WxPythonDocs = os.path.join(info.dirname(wx.__file__),'docs')
WxPythonDocs2 = os.path.join(info.dirname(WxPythonDocs),'docs')
WxPythonDocs3 = 'C:\\Program Files\\wxPython2.8 Docs and Demos\\docs'
path = None
for dir in [WxPythonDocs,WxPythonDocs2,WxPythonDocs3]:
for docs in ['wx.chm','wxPythonDocs.html','wxPythonManual.html']:
if not path:
p = os.path.join(dir,docs)
if os.path.exists(p):
path = p
if path:
self.messageHtml(path)
elif os.path.exists(os.path.join(WxPythonDocs2,"wxDocsViewer.app")):
os.spawnl(os.P_NOWAIT,info.PYTHON_EXEC,info.PYTHON_EXEC,
os.path.join(WxPythonDocs,"wxDocsViewer.app/Contents/Resources/viewdocs.py"))
else:
self.SetActiveStatusText('wxPython documentation could not be found. Check the path in the preferences dialog.')
def about(self):
from dialogs import helpDialog
helpDialog.create(self,self.path,'about.htm', replacements=INFO)
#---Backstage
def openList(self,fileList,lineno=None,col=1,message=1,select='line',\
maximize=None, verbose=False):
"""Open a list of files."""
if type(fileList)!=types.ListType:
fileList=[fileList]
child = None
for fileName in fileList:
if type(fileName)==types.TupleType:
fileName, lineno, col = fileName
if not os.path.exists(fileName): continue