[go: up one dir, main page]

Menu

[r2]: / bin / editorClass.py  Maximize  Restore  History

Download this file

650 lines (491 with data), 25.9 kB

  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
import wx.lib.inspection
import sys, time
import wx.richtext
from configClass import *
from logClass import *
from aboutClass import *
from AutoIndentation import *
from LineFold import *
from BraceMatch import *
from SyntaxHighlight import *
from Fonts import *
from ConfigWindow import *
from PrintDialog import *
from FindReplaceText import *
from SourceBrowser import *
from AutoCompletition import *
from ShellEmulator import *
class Editor(wx.Frame):
def __init__(self,id,parent):
SHELLTAB_ID = 4002
BASH_ID = 4000
PY_ID = 4001
self.FindRepl = SearchReplace()
self.AutoComp = AutoComplet()
self.Config = ConfigNanny()
self.Log = Logger()
self.SyntCol = SyntaxColorizer()
pathname = os.path.abspath(os.path.dirname(sys.argv[0])) # Finding where
os.chdir(pathname) # gEcrit is running
self.PathIndex = {}
self.PageIndex = {}
self.CharCount = {}
self.SaveRecord = {}
self.IdRange = []
self.GoConfWin = ConfFrame = CfgFrame(self.IdRange, None)
if "editorClass.py" not in sys.argv[-1]:
self.TargetFile = sys.argv[-1]
self.job_file = True
Name = self.TargetFile.split("/")[-1]
else:
self.job_file = False
self.TargetFile = "" #Default Name
Name = "New Document"
self.MainFrame = wx.Frame.__init__(self,parent,1000,'gEcrit', size=(700,600))
self.Bind(wx.EVT_CLOSE, self.OnQuit)
self.NewTabImage = wx.Image('icons/newtab.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.OpenImage = wx.Image('icons/open.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.SaveImage = wx.Image('icons/save.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.SaveAsImage = wx.Image('icons/saveas.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.ConfigImage = wx.Image('icons/config.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.QuitImage = wx.Image('icons/quit.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.CloseImage = wx.Image("icons/close.png",wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.PrintImage = wx.Image("icons/printer.bmp",wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.RunImage = wx.Image("icons/run.png",wx.BITMAP_TYPE_ANY).ConvertToBitmap()
if self.Config.GetOption("StatusBar"):
self.StatusBar = self.CreateStatusBar()
self.StatusBar.SetStatusText("Done")
self.StatusBar.SetFieldsCount(2)
self.StatusBar.SetId(999)
menubar = wx.MenuBar()
file = wx.Menu()
edit = wx.Menu()
help = wx.Menu()
search = wx.Menu()
view = wx.Menu()
file.Append(500, '&New Tab\tCtrl+N', 'Open a new tab.')
file.Append(501, '&Open\tCtrl+O', 'Open a new document.')
file.Append(502, '&Save\tCtrl+S', 'Save the document.')
file.Append(503, 'Save As', 'Save the document under a different name.')
file.Append(504, '&Print\tCtrl+P', 'Print the current document.')
file.Append(505, 'Close &Tab\tCtrl+W', 'Close the current tab.')
file.AppendSeparator()
quit = wx.MenuItem(file, 506, '&Quit\tCtrl+Q', 'Quit gEcrit.')
file.AppendItem(quit)
edit.Append(520,"&Undo\tCtrl+Z","Cancel the last action.")
edit.Append(521,"&Redo\tCtrl+Y","Bring back the last action.")
edit.AppendSeparator()
edit.Append(522,"&Cut\tCtrl+X","Cut the selection.")
edit.Append(523,"C&opy\tCtrl+C","Copy the selection.")
edit.Append(524,"P&aste\tCtrl+V","Paste the selection.")
edit.AppendSeparator()
edit.Append(525,"Select All\tCtrl+A","Select all the document.")
edit.AppendSeparator()
edit.Append(526,"Insert date","Insert the date at cursor position.")
edit.AppendSeparator()
edit.Append(527,"Preferences\tCtrl+E","Open the configuration window.")
search.Append(530,"Find\tCtrl+F","Search text in the current document.")
search.Append(531,"Find and Replace\tCtrl+H","Search and replace text in the current document.")
view.Append(535, "Zoom In\tCtrl++","Increase the size of the text.")
view.Append(536, "Zoom Out\tCtrl+-","Decrease the size of the text.")
view.Append(537,"Normal Size\tCtrl+0","Set the size of the text to normal.")
view.AppendSeparator()
view.AppendCheckItem(538, "Line Numbers", "Show/Hide line numbers.").Check(self.Config.GetOption("LineNumbers"))
view.AppendCheckItem(539, "Fold Marks", "Show/Hide fold marks.").Check(self.Config.GetOption("FoldMarks"))
view.AppendCheckItem(540, "White Space", "Show/Hide white spaces.").Check(self.Config.GetOption("Whitespace"))
view.AppendCheckItem(541, "Indentation Guides", "Show/Hide indentation guides.").Check(self.Config.GetOption("IndetationGuides"))
view.AppendCheckItem(546,"Edge Line","Show/Hide the edge line.").Check(self.Config.GetOption("EdgeLine"))
view.AppendSeparator()
view.AppendCheckItem(542,"Pyton Shell","Stop/Start a python shell.").Check(self.Config.GetOption("PythonShell"))
view.AppendCheckItem(543, "OS Shell", "Stop/Start an OS shell.").Check(self.Config.GetOption("BashShell"))
view.AppendCheckItem(544, "Source Browser", "Show/Hide the source browser.").Check(self.Config.GetOption("SourceBrowser"))
view.AppendCheckItem(545, "Statusbar", "Show/Hide statusbar.").Check(self.Config.GetOption("StatusBar"))
help.Append(550,"About","Open the about window.")
menubar.Append(file, '&File')
menubar.Append(edit, '&Edit')
menubar.Append(search,"&Search")
menubar.Append(view, "&View")
menubar.Append(help, '&Help')
self.SetMenuBar(menubar)
mega_sizer = wx.BoxSizer(wx.VERTICAL)
#tsk_icon = wx.TaskBarIcon()
#tsk_icon.SetIcon(wx.Icon('icons/gEcrit.png', wx.BITMAP_TYPE_PNG))
self.SetIcon(wx.Icon('icons/gEcrit.png', wx.BITMAP_TYPE_PNG))
self.text_id = 0
main_splitter = wx.SplitterWindow(self,-1, style=wx.SP_3D|wx.SP_BORDER)
tab_panel = wx.Panel(main_splitter)
nb_panel = wx.Panel(main_splitter)
nb_panel.SetId(998)
HOMEDIR = os.path.expanduser('~')
os.chdir(os.path.abspath(HOMEDIR))
ShellTabs = wx.Notebook(tab_panel, id = SHELLTAB_ID,size = (700,100), style =wx.BORDER_SUNKEN)
BashPanel = wx.Panel(ShellTabs)
PythonPanel = wx.Panel(ShellTabs)
self.BashShell = ShellEmulator(BashPanel, self.Config.GetOption("OSPath"), BASH_ID)
self.PythonShell = ShellEmulator(PythonPanel, self.Config.GetOption("PyPath"), PY_ID)
if self.Config.GetOption("PythonShell") or self.Config.GetOption("BashShell"):
if self.Config.GetOption("BashShell"):
self.BashShell.OnRun(0, self.Config.GetOption("OSPath"))
bash_sizer = wx.BoxSizer(wx.VERTICAL)
bash_sizer.Add(self.BashShell,1,wx.EXPAND)
BashPanel.SetSizer(bash_sizer)
ShellTabs.AddPage(BashPanel,"OS Shell")
if self.Config.GetOption("PythonShell"):
self.PythonShell.OnRun(0, self.Config.GetOption("PyPath"))
python_sizer = wx.BoxSizer(wx.VERTICAL)
python_sizer.Add(self.PythonShell,1,wx.EXPAND)
PythonPanel.SetSizer(python_sizer)
ShellTabs.AddPage(PythonPanel, "Python")
will_split = True
else:
will_split = False
self.nb = wx.aui.AuiNotebook(nb_panel,style= wx.aui.AUI_NB_TOP )
nb_sizer = wx.BoxSizer(wx.VERTICAL)
nb_sizer.Add(self.nb,1,wx.EXPAND)
nb_panel.SetSizer(nb_sizer)
nb_panel.Fit()
tab_sizer = wx.BoxSizer(wx.VERTICAL)
tab_sizer.Add(ShellTabs,1,wx.EXPAND)
tab_panel.SetSizer(tab_sizer)
tab_panel.Fit()
main_splitter_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_splitter_sizer.Add(nb_sizer,0,wx.EXPAND)
main_splitter_sizer.Add(tab_sizer)
main_splitter.SetSizer(main_splitter_sizer)
main_splitter.Fit()
os.chdir(pathname)
main_splitter.SplitHorizontally(nb_panel,tab_panel)
if not will_split:
main_splitter.Unsplit(tab_panel)
##FILE
self.Bind(wx.EVT_MENU, lambda event: self.NewTab(event,"New Document","New Document"),id=500)
self.Bind(wx.EVT_MENU, lambda event: self.OpenFile(event),id=501)
self.Bind(wx.EVT_MENU, lambda event: self.Save(event,self.PageIndex[self.nb.GetSelection()]),id=502)
self.Bind(wx.EVT_MENU, lambda event: self.SaveAs(event,self.PageIndex[self.nb.GetSelection()]),id=503)
self.Bind(wx.EVT_MENU, lambda event: self.OnPrint(event,self.PageIndex[self.nb.GetSelection()]),id=504)
self.Bind(wx.EVT_MENU, lambda event: self.ManageCloseTab(event,self.PageIndex[self.nb.GetSelection()]),id=505)
self.Bind(wx.EVT_MENU, lambda event: self.OnQuit(event),id=506)
##EDIT
self.Bind(wx.EVT_MENU, lambda event: self.OnUndo(event,self.PageIndex[self.nb.GetSelection()]),id=520)
self.Bind(wx.EVT_MENU, lambda event: self.OnRedo(event,self.PageIndex[self.nb.GetSelection()]),id=521)
self.Bind(wx.EVT_MENU, lambda event: self.OnCut(event,self.PageIndex[self.nb.GetSelection()]),id=522)
self.Bind(wx.EVT_MENU, lambda event: self.OnCopy(event,self.PageIndex[self.nb.GetSelection()]),id=523)
self.Bind(wx.EVT_MENU, lambda event: self.OnPaste(event,self.PageIndex[self.nb.GetSelection()]),id=524)
self.Bind(wx.EVT_MENU, lambda event: self.OnSelectAll(event,self.PageIndex[self.nb.GetSelection()]),id=525)
self.Bind(wx.EVT_MENU, lambda event: self.OnInsertDate(event,self.PageIndex[self.nb.GetSelection()]),id=526)
self.Bind(wx.EVT_MENU, lambda event: self.OnPrefs(event),id=527)
##SEARCH
self.Bind(wx.EVT_MENU, lambda event: self.FindRepl.FindDocText(self.PageIndex[self.nb.GetSelection()]),id = 530)
self.Bind(wx.EVT_MENU, lambda event: self.FindRepl.ReplaceDocText(self.PageIndex[self.nb.GetSelection()]),id = 531)
##VIEW
self.Bind(wx.EVT_MENU, lambda event: self.OnZoomIn(event,self.PageIndex[self.nb.GetSelection()]),id = 535)
self.Bind(wx.EVT_MENU, lambda event: self.OnZoomOut(event,self.PageIndex[self.nb.GetSelection()]),id = 536)
self.Bind(wx.EVT_MENU, lambda event: self.OnResetZoom(event,self.PageIndex[self.nb.GetSelection()]),id = 537)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("LineNumbers", view.IsChecked(538),self.IdRange),id = 538)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("FoldMarks", view.IsChecked(539),self.IdRange),id = 539)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("Whitespace", view.IsChecked(540),self.IdRange),id = 540)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("IndetationGuides", view.IsChecked(541),self.IdRange),id = 541)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("EdgeLine", view.IsChecked(546),self.IdRange),id = 546)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("PythonShell", view.IsChecked(542),self.IdRange),id = 542)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("BashShell", view.IsChecked(543),self.IdRange),id = 543)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("SourceBrowser", view.IsChecked(544),self.IdRange),id = 544)
self.Bind(wx.EVT_MENU,lambda event: self.Config.ChangeOption("StatusBar", view.IsChecked(545),self.IdRange),id = 545)
##HELP
self.Bind(wx.EVT_MENU, lambda event: self.OnAbout(event), id = 550)
toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
toolbar.AddSimpleTool(600, self.NewTabImage, 'New', 'Open a new tab.')
toolbar.AddSimpleTool(601, self.OpenImage, 'Open', 'Open a new document.')
toolbar.AddSimpleTool(602, self.SaveImage, 'Save', 'Save the current document.')
toolbar.AddSimpleTool(603, self.SaveAsImage, 'Save As', 'Save the current document under a differend name.')
toolbar.AddSimpleTool(604, self.ConfigImage, 'Settings', 'Open the configuration window.')
toolbar.AddSeparator()
toolbar.AddSimpleTool(605, self.QuitImage, 'Quit', 'Quit gEcrit')
toolbar.AddSeparator()
toolbar.AddSimpleTool(606, self.CloseImage, 'Close tab', 'Close the current tab.')
self.FontCtrl = wx.FontPickerCtrl(toolbar, 607,size=(100,30))
#self.FontCtrl.SetSelectedFont()
self.Bind(wx.EVT_FONTPICKER_CHANGED,lambda event: ChangeFont(event, self.FontCtrl.GetSelectedFont(), self.IdRange))
toolbar.AddControl(self.FontCtrl)
toolbar.AddControl(wx.TextCtrl(toolbar, 608, size =(-1,-1), style = wx.TE_PROCESS_ENTER))
toolbar.AddSeparator()
toolbar.AddSimpleTool(609,self.PrintImage,"Print","Print the current document.")
toolbar.AddSimpleTool(610,self.RunImage,"Run","Run the current file.(Python only)")
toolbar.Realize()
self.Bind(wx.EVT_TOOL,lambda event: self.NewTab(event,"New Document","New Document"), id=600)
self.Bind(wx.EVT_TOOL, self.OpenFile, id=601)
self.Bind(wx.EVT_TOOL,lambda event: self.Save(event,self.PageIndex[self.nb.GetSelection()]), id=602)
self.Bind(wx.EVT_TOOL,lambda event: self.SaveAs(event,self.PageIndex[self.nb.GetSelection()]), id=603)
self.Bind(wx.EVT_TOOL, self.OnPrefs, id=604)
self.Bind(wx.EVT_TOOL, self.OnQuit, id=605)
self.Bind(wx.EVT_TOOL, lambda event: self.ManageCloseTab(event,self.PageIndex[self.nb.GetSelection()]),id=606)
self.Bind(wx.EVT_TEXT_ENTER , lambda event: self.OnGotoBox(event,self.PageIndex[self.nb.GetSelection()]),id=608)
self.Bind(wx.EVT_TOOL, lambda event: self.OnPrint(event,self.PageIndex[self.nb.GetSelection()]),id=609)
self.Bind(wx.EVT_TOOL, lambda event: self.OnRun(event,self.PageIndex[self.nb.GetSelection()]),id=610)
self.NewTab(0,Name,self.TargetFile)
mega_sizer.Add(toolbar,0)
mega_sizer.Add(main_splitter, 1, wx.EXPAND)
#~
#~ mega_sizer.Add(ShellTabs,0,wx.EXPAND)
self.SetSizer(mega_sizer)
self.Centre()
def OnZoomIn(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.ZoomIn()
def OnZoomOut(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.ZoomOut()
def OnResetZoom(self, event, text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.SetZoom(0)
def OnRedo(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
if CurrentWidget.CanRedo(): CurrentWidget.Redo()
def OnUndo(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
if CurrentWidget.CanUndo(): CurrentWidget.Undo()
def OnCut(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.Cut()
def OnCopy(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.Copy()
def OnSelectAll(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.SelectAll()
def OnPaste(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.Paste()
def OnInsertDate(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.AddText(str(time.ctime()))
def OnPrefs(self,event):
self.GoConfWin.ShowMe(0)
def UpdateCords(self,event,text_id):
CurrentWidget = wx.FindWindowById(text_id)
if self.Config.GetOption("StatusBar"):
self.StatusBar.SetStatusText("line: "+str(CurrentWidget.GetCurrentLine())\
+" col: "+str(CurrentWidget.GetColumn(CurrentWidget.GetCurrentPos())),1)
def NewTab(self,event,nb,TargetFile):
panel = wx.Panel(self)
panel.identifierTag = nb
TABBER = self.nb
# Put text_id into a local variable.
# We do this so that the lambda takes the current value,
# and not the constantly-incrementing one.
text_id = self.text_id
splitter = wx.SplitterWindow(panel, -1, style=wx.SP_3D|wx.SP_BORDER)
src_br_panel = wx.Panel(splitter)
text_panel = wx.Panel(splitter)
text_panel.SetId(997)
splitter.SplitVertically(src_br_panel, text_panel,20)
self.h, self.y = self.GetSize() #Get height and width of MainFrame
self.y -= 230 #Adjusting the height of TextWidget
self.h -=300 #Adjusting the width of TextWidget
self.TextWidget = wx.stc.StyledTextCtrl(text_panel,self.text_id,pos =(0,0), size = (1,1))
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
text_sizer.Add(self.TextWidget,1,wx.EXPAND)
text_panel.SetSizer(text_sizer)
text_panel.Fit()
self.IdRange.append(self.text_id)
self.TextWidget.SetBufferedDraw(True)
self.TextWidget.StyleSetFont(0, self.FontCtrl.GetSelectedFont())
CurrentWidget = wx.FindWindowById(text_id)
self.Config.ApplyIDEConfig(text_id, TargetFile.split(".")[-1])
CurrentWidget.SetXOffset(1)
CurrentWidget.Bind(wx.EVT_KEY_DOWN, lambda event: self.AutoComp.OnKeyPressed(event, text_id))
CurrentWidget.Bind(wx.stc.EVT_STC_UPDATEUI, lambda event: self.UpdateCords(event, text_id))
if self.Config.GetOption("Autosave") == True:
wx.stc.EVT_STC_CHARADDED(self, text_id, lambda event : self.Autosave(event,self.Config.GetOption("Autosave Interval"),text_id))
text = ""
if TargetFile != "" and nb != "New Document":
try:
text_file = open(TargetFile,"r")
for line in text_file.readlines():
text+=line
except:
text = ""
self.TextWidget.AppendText(text)
self.PathIndex[text_id] = TargetFile
self.CharCount[text_id] = 0
self.TabCount = self.text_id
self.SaveRecord[text_id] = wx.FindWindowById(text_id).GetText()
CurrentWidget.Bind(wx.EVT_KEY_UP, lambda event: AutoIndent(event,text_id))
self.InitSrcBr = SrcBrowser(TargetFile, nb, text_id,src_br_panel)
src_sizer = wx.BoxSizer(wx.HORIZONTAL)
src_sizer.Add(self.InitSrcBr,1,wx.EXPAND)
src_br_panel.SetSizer(src_sizer)
src_br_panel.Fit()
# Vertical sizer for text
widget_sizer = wx.BoxSizer(wx.HORIZONTAL)
widget_sizer.Add(src_sizer,0, wx.EXPAND)
widget_sizer.Add(text_sizer,0, wx.EXPAND)
splitter.SetSizer(widget_sizer)
splitter.Fit()
will_split = self.Config.GetOption("SourceBrowser")
if not will_split:
splitter.Unsplit(src_br_panel)
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(splitter, 1,wx.EXPAND)
# Assign the sizer to the panel, and resize it
panel.SetSizer(main_sizer)
main_sizer.Fit(panel)
self.nb.AddPage(panel, nb, select = True)
self.PageIndex[self.nb.GetSelection()] = text_id
#Increment the ID.
self.text_id += 1
def OnRun(self,event, text_id):
self.Save(0,text_id)
os.system("xterm -e python "+self.PathIndex[text_id])
def OnGotoBox(self, event, text_id):
CurrentWidget = wx.FindWindowById(text_id)
Goto = wx.FindWindowById(608)
try:
scroll_pos = int(Goto.GetLineText(0))
except:
pass #User entered non numerical value
CurrentWidget.ScrollToLine(scroll_pos-1)
def OnPrint(self ,event, text_id):
FileName = self.PathIndex[text_id]
if "/" not in FileName:
FileName = "ForPrint"
GoPrint = PrettyPrinter(FileName, text_id, self)
def OnAbout(self,event):
ShowAbout = AboutWindow
ShowAbout()
def OnQuit(self,event):
Warn = wx.MessageDialog(None,"Please make sure that your data is\
saved.\nAre you sure you want to quit?","Are you sure?",style = wx.YES_NO)
WarnAnswer = Warn.ShowModal()
if WarnAnswer != 5104:
if self.Config.GetOption("BashShell"):
self.BashShell.OnClose(event)
if self.Config.GetOption("PythonShell"):
self.PythonShell.OnClose(event)
quit()
def ManageCloseTab(self,event,text_id):
TextCheck = wx.FindWindowById(text_id).GetText()
if self.SaveRecord[text_id] != TextCheck:
SavePrompt = wx.MessageDialog(None, "The file "\
+self.PathIndex[text_id].split("/")[-1]+" is not saved.\n\
Do you wish to save it?","",style = wx.CANCEL | wx.YES| wx.NO )
PromptValue = SavePrompt.ShowModal()
if PromptValue == 5103: #yes
if not self.Save(0,text_id):
return
elif PromptValue == 5101: #Cancel
Cancel = True
if self.TabCount == 0:
StopQuit = True
else:
StopQuit = False
elif PromptValue == 5102:
if self.TabCount == 0:
StopQuit = False
Cancel = False
else:
Cancel = False
else:
Cancel = False
SavePrompt.Destroy()
if self.TabCount == 0:
try:
if StopQuit != True:
try:
if self.Config.GetOption("BashShell"):
self.BashShell.OnClose(event)
if self.Config.GetOption("PythonShell"):
self.PythonShell.OnClose(event)
except: pass
quit()
except:
try:
if self.Config.GetOption("BashShell"):
self.BashShell.OnClose(event)
if self.Config.GetOption("PythonShell"):
self.PythonShell.OnClose(event)
except: pass
quit()
else:
self.TabCount -= 1
if Cancel != True:
self.IdRange.remove(text_id)
self.nb.RemovePage(self.nb.GetSelection())
def SetStatus(self,event,Text):
self.StatusBar.SetStatusText(Text)
event.Skip()
def ResetStatus(self,event):
self.StatusBar.SetStatusText("")
event.Skip()
def OpenFile(self,event):
OpenFileGetPath = wx.FileDialog(None, style = wx.OPEN)
if OpenFileGetPath.ShowModal() == wx.ID_OK:
FilePath = OpenFileGetPath.GetDirectory() + "/" + OpenFileGetPath.GetFilename()
self.NewTab(0,OpenFileGetPath.GetFilename(), FilePath)
self.Log.AddLogEntry(time.ctime() + ": Opened file "+FilePath)
OpenFileGetPath.Destroy()
def Autosave(self,event,interval ,text_id):
if self.CharCount[text_id] == interval:
self.Save(0,text_id)
self.CharCount[text_id] = 0
else:
self.CharCount[text_id] += 1
def Save(self,event,text_id):
try:
SaveTarget = self.PathIndex[text_id]
if SaveTarget =="New Document" or SaveTarget == "":
raise "ERROR"
except:
self.SaveAs(0,text_id)
return
try:
SaveFile = open(SaveTarget,"w")
SaveContent = wx.FindWindowById(text_id).GetText()
SaveFile.write(SaveContent)
SaveFile.close()
if self.Config.GetOption("StatusBar")== True:
self.StatusBar.SetStatusText("Saved")
self.Log.AddLogEntry(time.ctime() + ": Saved file "+SaveTarget)
self.InitSrcBr.RefreshTree(text_id, SaveTarget)
if SaveTarget.split(".")[-1] == "py":
self.SyntCol.ActivateSyntaxHighLight(text_id)
else:
wx.FindWindowById(text_id).StyleClearAll()
except:
self.SaveAs(0,text_id)
try:
self.SaveRecord[text_id] = SaveContent
except:
pass
def SaveAs(self,event,text_id):
SaveFileAs = wx.FileDialog(None, style = wx.SAVE)
if SaveFileAs.ShowModal() == wx.ID_OK:
SaveAsFileName = SaveFileAs.GetFilename()
SaveAsPath = SaveFileAs.GetDirectory()+"/"+ SaveAsFileName
SaveFile = open(SaveAsPath,"w")
SaveContent = wx.FindWindowById(text_id).GetText()
SaveFile.write(SaveContent)
SaveFile.close()
self.PathIndex[text_id] = SaveAsPath
self.TargetFile = SaveAsPath
if self.Config.GetOption("StatusBar")== True:
self.StatusBar.SetStatusText("Saved as"+ SaveAsPath)
self.nb.SetPageText(self.nb.GetSelection(), SaveAsFileName)
self.InitSrcBr.RefreshTree(text_id, SaveAsPath)
if SaveAsFileName.split(".")[-1] == "py":
ActivateSyntaxHighLight(text_id)
else:
wx.FindWindowById(text_id).StyleClearAll()
try:
self.SaveRecord[text_id] = SaveContent
except:
pass
SaveFileAs.Destroy()
return True
else:
SaveFileAs.Destroy()
return False
if __name__ == '__main__':
app=wx.PySimpleApp()
frame=Editor(parent=None,id=-1)
frame.Show()
app.MainLoop()