31
31
import drFileDialog
33
33
def GetToolBarLabels(filename, frame):
35
f = file(filename, 'r')
39
drScrolledMessageDialog.ShowMessage(frame, 'File error with: "' + filename + '".', "ERROR")
42
rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddToolBarFunction\(.*\)', re.MULTILINE)
44
allPopUps = rePopUpMenu.findall(text)
49
#From the Left most '('
51
#To the Right most ')'
54
if (start > -1) and (end > -1):
57
e = i + 1 + s[i+1:].find(',')
58
arglabel = s[i+1:e].strip().strip('"')
60
PopUpArray.append("<Plugin>:"+arglabel)
35
f = file(filename, 'r')
39
drScrolledMessageDialog.ShowMessage(frame, 'File error with: "' + filename + '".', "ERROR")
42
# modified 22/10/2006 Jean-Pierre MANDON
43
# line: rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddToolBarFunction\(.*\)', re.MULTILINE)
45
rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddPluginToolBarFunction\(.*\)', re.MULTILINE)
47
allPopUps = rePopUpMenu.findall(text)
52
#From the Left most '('
54
#To the Right most ')'
57
if (start > -1) and (end > -1):
60
# modified 22/10/2006 Jean-Pierre MANDON
62
e = i + 1 + s[i+1:].find(',')
63
arglabel = s[i+1:e].strip().strip('"')
67
arglabel=arglabel.strip().strip('"')
69
PopUpArray.append("<Plugin>:"+arglabel)
64
73
class drToolBarDialog(wx.Dialog):
66
def __init__(self, parent):
67
wx.Dialog.__init__(self, parent, -1, "Customize ToolBar", wx.DefaultPosition, wx.Size(-1, -1), wx.DEFAULT_DIALOG_STYLE | wx.THICK_FRAME)
72
self.ID_PROGRAM = 1001
88
self.theSizer = wx.FlexGridSizer(5, 4, 5, 10)
89
self.menubuttonSizer = wx.BoxSizer(wx.VERTICAL)
90
self.listSizer = wx.BoxSizer(wx.HORIZONTAL)
92
self.userpreferencesdirectory = parent.userpreferencesdirectory
96
map(ToolBarList.append, parent.ToolBarList)
100
self.customNames, self.customFiles16, self.customFiles24 = drToolBarFile.getCustomBitmaps(self.parent.userpreferencesdirectory)
104
ToolBarList.insert(0, "<ROOT>")
106
programmenulist = drShortcutsFile.GetShortcutList()
108
i = programmenulist.index("Toggle Maximize")
109
programmenulist.pop(i)
113
programmenulist.sort()
115
programmenulist.insert(0, "<Insert Separator>")
118
self.ListArray.append(programmenulist)
123
map(stclist.append, drShortcutsFile.GetSTCShortcutList())
124
stclist.insert(0, "<Insert Separator>")
125
self.ListArray.append(stclist)
130
map(drscriptlist.append, parent.drscriptmenu.titles)
132
l = len(drscriptlist)
134
drscriptlist[x] = "<DrScript>:" + drscriptlist[x]
136
drscriptlist.insert(0, "<Insert Separator>")
137
self.ListArray.append(drscriptlist)
140
plist = os.listdir(parent.userpreferencesdirectory + "/plugins")
147
if i > -1 and (i + 3 == l):
148
self.PluginList.append("<Plugin>:" + p[:i])
149
plugins.append(p[:i])
152
for plugin in plugins:
153
pluginfile = self.parent.userpreferencesdirectory + "/plugins/" + plugin + ".py"
154
pluginlist = GetToolBarLabels(pluginfile, self)
155
plist = self.parent.GetPluginLabels(pluginfile)
157
if not (p in pluginlist):
159
if len(pluginlist) > 0:
160
pluginlist.insert(0, "<Insert Separator>")
161
self.ListArray.append(pluginlist)
163
poplist.append("<Plugin>:" + plugin)
166
i = self.PluginList.index(popl)
167
self.PluginList.pop(i)
169
list = ["Standard", "Text Control", "DrScript"]
170
list.extend(self.PluginList)
172
self.cboList = wx.ComboBox(self, self.ID_LIST, "Standard", wx.DefaultPosition, (200, -1), list, wx.CB_DROPDOWN|wx.CB_READONLY)
174
self.programmenu = wx.ListBox(self, self.ID_PROGRAM, wx.DefaultPosition, wx.Size(250, 250), programmenulist)
176
self.toolbaritems = wx.ListBox(self, self.ID_POPUP, wx.DefaultPosition, wx.Size(250, 250), ToolBarList)
178
self.btnUp = wx.Button(self, self.ID_UP, " Up ")
179
self.btnAdd = wx.Button(self, self.ID_ADD, " ---> ")
180
self.btnRemove = wx.Button(self, self.ID_REMOVE, " Remove ")
181
self.btnDown = wx.Button(self, self.ID_DOWN, " Down ")
183
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
184
self.menubuttonSizer.Add(self.btnAdd, 0, wx.SHAPED)
185
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
186
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
187
self.menubuttonSizer.Add(self.btnUp, 0, wx.SHAPED)
188
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
189
self.menubuttonSizer.Add(self.btnDown, 0, wx.SHAPED)
190
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
191
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
192
self.menubuttonSizer.Add(self.btnRemove, 0, wx.SHAPED)
194
self.listSizer.Add(wx.StaticText(self, -1, "List: "), 0, wx.ALIGN_CENTER | wx.SHAPED)
195
self.listSizer.Add(self.cboList, 0, wx.ALIGN_CENTER | wx.SHAPED)
197
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
198
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
199
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
200
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
202
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
203
self.theSizer.Add(self.listSizer, 0, wx.ALIGN_CENTER | wx.SHAPED)
204
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
205
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
207
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
208
self.theSizer.Add(wx.StaticText(self, -1, "Current List:"), 0, wx.ALIGN_CENTER | wx.SHAPED)
209
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
210
self.theSizer.Add(wx.StaticText(self, -1, "ToolBar:"), 0, wx.ALIGN_CENTER | wx.SHAPED)
211
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
212
self.theSizer.Add(self.programmenu, 0, wx.SHAPED | wx.ALIGN_CENTER)
213
self.theSizer.Add(self.menubuttonSizer, 0, wx.SHAPED | wx.ALIGN_CENTER)
214
self.theSizer.Add(self.toolbaritems, 0, wx.SHAPED | wx.ALIGN_CENTER)
216
self.txt16 = wx.TextCtrl(self, -1, "<Default>", wx.DefaultPosition, wx.Size(200, -1), wx.TE_READONLY)
217
self.btn16 = wx.Button(self, self.ID_16, "Change")
219
self.txt24 = wx.TextCtrl(self, -1, "<Default>", wx.DefaultPosition, wx.Size(200, -1), wx.TE_READONLY)
220
self.btn24 = wx.Button(self, self.ID_24, "Change")
222
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
223
self.theSizer.Add(wx.StaticText(self, -1, "Icon 16x16:"), 0, wx.ALIGN_LEFT | wx.SHAPED)
224
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
225
self.theSizer.Add(wx.StaticText(self, -1, "Icon 24x24:"), 0, wx.ALIGN_LEFT | wx.SHAPED)
227
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
228
self.theSizer.Add(self.txt16, 0, wx.ALIGN_LEFT | wx.SHAPED)
229
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
230
self.theSizer.Add(self.txt24, 0, wx.ALIGN_LEFT | wx.SHAPED)
232
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
233
self.theSizer.Add(self.btn16, 0, wx.ALIGN_CENTER | wx.SHAPED)
234
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
235
self.theSizer.Add(self.btn24, 0, wx.ALIGN_CENTER | wx.SHAPED)
237
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
238
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
239
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
240
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
242
self.btnUpdate = wx.Button(self, self.ID_UPDATE, "&Update")
243
self.btnSave = wx.Button(self, self.ID_SAVE, "&Save")
245
self.btnClose = wx.Button(self, 101, "&Close")
247
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
248
self.theSizer.Add(self.btnClose, 0, wx.SHAPED | wx.ALIGN_CENTER)
249
self.theSizer.Add(self.btnUpdate, 0, wx.SHAPED | wx.ALIGN_CENTER)
250
self.theSizer.Add(self.btnSave, 0, wx.SHAPED | wx.ALIGN_CENTER)
251
self.btnClose.SetDefault()
253
self.SetAutoLayout(True)
254
self.SetSizerAndFit(self.theSizer)
256
self.Bind(wx.EVT_BUTTON, self.OnbtnUp, id=self.ID_UP)
257
self.Bind(wx.EVT_BUTTON, self.OnbtnAdd, id=self.ID_ADD)
258
self.Bind(wx.EVT_BUTTON, self.OnbtnRemove, id=self.ID_REMOVE)
259
self.Bind(wx.EVT_BUTTON, self.OnbtnDown, id=self.ID_DOWN)
260
self.Bind(wx.EVT_BUTTON, self.OnbtnUpdate, id=self.ID_UPDATE)
261
self.Bind(wx.EVT_BUTTON, self.OnbtnSave, id=self.ID_SAVE)
262
self.Bind(wx.EVT_BUTTON, self.OnbtnChange16, id=self.ID_16)
263
self.Bind(wx.EVT_BUTTON, self.OnbtnChange24, id=self.ID_24)
264
self.Bind(wx.EVT_BUTTON, self.OnbtnClose, id=101)
266
self.Bind(wx.EVT_COMBOBOX, self.OnList, id=self.ID_LIST)
267
self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.ID_PROGRAM)
269
self.parent.LoadDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
271
def OnCloseW(self, event):
272
self.parent.SaveDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
273
if event is not None:
276
def OnbtnAdd(self, event):
277
tselection = self.programmenu.GetStringSelection()
278
tsel = self.programmenu.GetSelection()
280
drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Add", "Mistake")
282
separator = (tselection == "<Insert Separator>")
284
tselection = "<Separator>"
285
sel = self.toolbaritems.GetSelection()
288
self.toolbaritems.InsertItems([tselection], sel+1)
289
self.toolbaritems.SetSelection(sel+1)
291
def OnbtnChange16(self, event):
292
d = wx.SingleChoiceDialog(self.parent, 'Change Icon For 16x16:', "Change Icon", ["Default", "Select File"], wx.CHOICEDLG_STYLE)
293
d.SetSize(wx.Size(250, 250))
294
answer = d.ShowModal()
296
if (answer == wx.ID_OK):
297
sname = self.programmenu.GetStringSelection()
299
newname = "<Default>"
301
dlg = drFileDialog.FileDialog(self.parent, "Open", "PNG (*.png)|*.png")
302
if (dlg.ShowModal() == wx.ID_OK):
303
newname = dlg.GetPath()
304
self.txt16.SetValue(newname)
306
if newname == "<Default>":
309
if sname in self.customNames:
310
ci = self.customNames.index(sname)
311
self.customFiles16.pop(ci)
312
self.customFiles16.insert(ci, newname)
314
self.customNames.append(sname)
315
self.customFiles16.append(newname)
316
self.customFiles24.append("")
318
def OnbtnChange24(self, event):
319
d = wx.SingleChoiceDialog(self.parent, 'Change Icon For 24x24:', "Change Icon", ["Default", "Select File"], wx.CHOICEDLG_STYLE)
320
d.SetSize(wx.Size(250, 250))
321
answer = d.ShowModal()
323
if (answer == wx.ID_OK):
324
sname = self.programmenu.GetStringSelection()
326
newname = "<Default>"
328
dlg = drFileDialog.FileDialog(self.parent, "Open", "PNG (*.png)|*.png")
329
if (dlg.ShowModal() == wx.ID_OK):
330
newname = dlg.GetPath()
331
self.txt24.SetValue(newname)
333
if newname == "<Default>":
336
if sname in self.customNames:
337
ci = self.customNames.index(sname)
338
self.customFiles24.pop(ci)
339
self.customFiles24.insert(ci, newname)
341
self.customNames.append(sname)
342
self.customFiles16.append("")
343
self.customFiles24.append(newname)
345
def OnbtnClose(self, event):
348
def OnbtnDown(self, event):
349
sel = self.toolbaritems.GetSelection()
350
if sel < self.toolbaritems.GetCount()-1 and sel > 0:
351
txt = self.toolbaritems.GetString(sel)
352
self.toolbaritems.Delete(sel)
353
self.toolbaritems.InsertItems([txt], sel+1)
354
self.toolbaritems.SetSelection(sel+1)
356
def OnbtnRemove(self, event):
357
sel = self.toolbaritems.GetSelection()
358
selection = self.toolbaritems.GetStringSelection()
360
drScrolledMessageDialog.ShowMessage(self, "You cannot remove the root item.", "Mistake")
363
drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Remove", "Mistake")
366
self.toolbaritems.Delete(sel)
367
self.toolbaritems.SetSelection(sel-1)
369
def OnbtnUp(self, event):
370
sel = self.toolbaritems.GetSelection()
372
txt = self.toolbaritems.GetString(sel)
373
self.toolbaritems.Delete(sel)
374
self.toolbaritems.InsertItems([txt], sel-1)
375
self.toolbaritems.SetSelection(sel-1)
377
def OnbtnUpdate(self, event):
379
c = self.toolbaritems.GetCount()
384
pop = self.toolbaritems.GetString(y)
385
if not pop == "<ROOT>":
386
ToolBarList.append(pop)
389
self.parent.ToolBarList = ToolBarList
391
if self.parent.hasToolBar:
392
self.parent.DestroyToolBar()
393
self.parent.SetToolBar(None)
394
self.parent.toolbar = wx.ToolBar(self.parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL)
395
self.parent.ToolBarIdList = self.parent.SetupToolBar()
397
if (self.parent.prefs.iconsize > 0):
398
self.parent.SetToolBar(self.parent.toolbar)
400
thereisafile = (len(self.parent.txtDocument.filename) > 0)
401
self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
403
if (self.parent.txtPrompt.pid is -1):
404
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, True)
405
self.parent.toolbar.EnableTool(self.parent.ID_END, False)
406
self.parent.toolbar.EnableTool(self.parent.ID_RUN, thereisafile)
407
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, thereisafile)
409
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
410
self.parent.toolbar.EnableTool(self.parent.ID_END, True)
412
self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
413
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
415
if self.parent.prefs.enablefeedback:
416
drScrolledMessageDialog.ShowMessage(self, ("Succesfully updated the current instance of DrPython.\nClick Save to make it permanent."), "Updated ToolBar")
418
def OnbtnSave(self, event):
419
toolbarfile = self.userpreferencesdirectory + "/toolbar.dat"
421
msg = "Succesfully wrote to:\n" + toolbarfile + "\nand updated the current instance of DrPython."
424
if len(self.customNames) > 0:
425
toolbarcustomfile = self.userpreferencesdirectory + "/toolbar.custom.icons.dat"
426
f = file(toolbarcustomfile, 'w')
428
l = len(self.customNames)
430
if (len(self.customFiles16[x]) > 0) or (len(self.customFiles24[x]) > 0):
431
f.write("<Name>"+self.customNames[x]+"</Name><16>"+self.customFiles16[x]+"</16><24>"+self.customFiles24[x]+"</24>\n")
434
msg = msg + "\n\nSuccesfully Saved Custom ToolBar Icons."
437
c = self.toolbaritems.GetCount()
439
toolbaritemsstring = ""
443
pop = self.toolbaritems.GetString(y)
444
if not pop == "<ROOT>":
445
toolbaritemsstring = toolbaritemsstring + pop + "\n"
446
ToolBarList.append(pop)
449
self.parent.ToolBarList = ToolBarList
451
if self.parent.hasToolBar:
452
if self.parent.toolbar is not None:
453
self.parent.SetToolBar(None)
455
self.parent.DestroyToolBar()
456
self.parent.toolbar = wx.ToolBar(self.parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL)
457
self.parent.ToolBarIdList = self.parent.SetupToolBar()
459
if (self.parent.prefs.iconsize > 0):
460
self.parent.SetToolBar(self.parent.toolbar)
462
thereisafile = (len(self.parent.txtDocument.filename) > 0)
463
self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
465
if (self.parent.txtPrompt.pid is -1):
466
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, True)
467
self.parent.toolbar.EnableTool(self.parent.ID_END, False)
468
self.parent.toolbar.EnableTool(self.parent.ID_RUN, thereisafile)
469
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, thereisafile)
471
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
472
self.parent.toolbar.EnableTool(self.parent.ID_END, True)
474
self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
475
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
477
if (not os.path.exists(self.userpreferencesdirectory)):
478
drScrolledMessageDialog.ShowMessage(self, ("Dude, you've got some problems...\nYour userpreferencesdirectory (" + self.userpreferencesdirectory + ") does not exist!\nLet's not bother speculating about how or why.\nRead the help file for this truly screwed up situation.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed this problem."), "Huge Error")
481
f = file(toolbarfile, 'w')
482
f.write(toolbaritemsstring)
485
drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n" + toolbarfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
487
if self.parent.prefs.enablefeedback:
488
drScrolledMessageDialog.ShowMessage(self, msg, "Saved ToolBar")
490
def OnList(self, event):
491
sel = self.cboList.GetSelection()
493
self.programmenu.Set(self.ListArray[sel])
495
def OnSelect(self, event):
496
#Take one away for "Insert Separator"
497
sel = self.programmenu.GetSelection() - 1
498
seltext = self.programmenu.GetStringSelection()
500
if seltext in self.customNames:
501
i = self.customNames.index(seltext)
502
if len(self.customFiles16[i]) > 0:
503
self.txt16.SetValue(self.customFiles16[i])
505
self.txt16.SetValue("<Default>")
506
if len(self.customFiles24[i]) > 0:
507
self.txt24.SetValue(self.customFiles24[i])
509
self.txt24.SetValue("<Default>")
511
self.txt16.SetValue("<Default>")
512
self.txt24.SetValue("<Default>")
b'\\ No newline at end of file'
75
def __init__(self, parent):
76
wx.Dialog.__init__(self, parent, -1, "Customize ToolBar", wx.DefaultPosition, wx.Size(-1, -1), wx.DEFAULT_DIALOG_STYLE | wx.THICK_FRAME)
81
self.ID_PROGRAM = 1001
97
self.theSizer = wx.FlexGridSizer(5, 4, 5, 10)
98
self.menubuttonSizer = wx.BoxSizer(wx.VERTICAL)
99
self.listSizer = wx.BoxSizer(wx.HORIZONTAL)
101
self.preferencesdirectory = parent.preferencesdirectory
105
map(ToolBarList.append, parent.ToolBarList)
109
self.customNames, self.customFiles16, self.customFiles24 = drToolBarFile.getCustomBitmaps(self.parent.datdirectory)
113
ToolBarList.insert(0, "<ROOT>")
115
programmenulist = drShortcutsFile.GetShortcutList()
117
i = programmenulist.index("Toggle Maximize")
118
programmenulist.pop(i)
122
programmenulist.sort()
124
programmenulist.insert(0, "<Insert Separator>")
127
self.ListArray.append(programmenulist)
132
map(stclist.append, drShortcutsFile.GetSTCShortcutList())
133
stclist.insert(0, "<Insert Separator>")
134
self.ListArray.append(stclist)
139
map(drscriptlist.append, parent.drscriptmenu.titles)
141
l = len(drscriptlist)
143
drscriptlist[x] = "<DrScript>:" + drscriptlist[x]
145
drscriptlist.insert(0, "<Insert Separator>")
146
self.ListArray.append(drscriptlist)
149
plist = os.listdir(parent.pluginsdirectory)
156
if i > -1 and (i + 3 == l):
157
self.PluginList.append("<Plugin>:" + p[:i])
158
plugins.append(p[:i])
161
for plugin in plugins:
162
pluginfile = os.path.join(self.parent.pluginsdirectory, plugin + ".py")
163
pluginlist = GetToolBarLabels(pluginfile, self)
164
plist = self.parent.GetPluginLabels(pluginfile)
166
if not (p in pluginlist):
169
pluginlist.insert(0, "<Insert Separator>")
170
self.ListArray.append(pluginlist)
172
poplist.append("<Plugin>:" + plugin)
175
i = self.PluginList.index(popl)
176
self.PluginList.pop(i)
178
list = ["Standard", "Text Control", "DrScript"]
179
list.extend(self.PluginList)
181
self.cboList = wx.ComboBox(self, self.ID_LIST, "Standard", wx.DefaultPosition, (200, -1), list, wx.CB_DROPDOWN|wx.CB_READONLY)
183
self.programmenu = wx.ListBox(self, self.ID_PROGRAM, wx.DefaultPosition, wx.Size(250, 250), programmenulist)
185
self.toolbaritems = wx.ListBox(self, self.ID_POPUP, wx.DefaultPosition, wx.Size(250, 250), ToolBarList)
187
self.btnUp = wx.Button(self, self.ID_UP, " Up ")
188
self.btnAdd = wx.Button(self, self.ID_ADD, " ---> ")
189
self.btnRemove = wx.Button(self, self.ID_REMOVE, " Remove ")
190
self.btnDown = wx.Button(self, self.ID_DOWN, " Down ")
192
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
193
self.menubuttonSizer.Add(self.btnAdd, 0, wx.SHAPED)
194
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
195
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
196
self.menubuttonSizer.Add(self.btnUp, 0, wx.SHAPED)
197
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
198
self.menubuttonSizer.Add(self.btnDown, 0, wx.SHAPED)
199
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
200
self.menubuttonSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
201
self.menubuttonSizer.Add(self.btnRemove, 0, wx.SHAPED)
203
self.listSizer.Add(wx.StaticText(self, -1, "List: "), 0, wx.ALIGN_CENTER | wx.SHAPED)
204
self.listSizer.Add(self.cboList, 0, wx.ALIGN_CENTER | wx.SHAPED)
206
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
207
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
208
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
209
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
211
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
212
self.theSizer.Add(self.listSizer, 0, wx.ALIGN_CENTER | wx.SHAPED)
213
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
214
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
216
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
217
self.theSizer.Add(wx.StaticText(self, -1, "Current List:"), 0, wx.ALIGN_CENTER | wx.SHAPED)
218
self.theSizer.Add(wx.StaticText(self, -1, " "), 0, wx.ALIGN_CENTER | wx.SHAPED)
219
self.theSizer.Add(wx.StaticText(self, -1, "ToolBar:"), 0, wx.ALIGN_CENTER | wx.SHAPED)
220
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
221
self.theSizer.Add(self.programmenu, 0, wx.SHAPED | wx.ALIGN_CENTER)
222
self.theSizer.Add(self.menubuttonSizer, 0, wx.SHAPED | wx.ALIGN_CENTER)
223
self.theSizer.Add(self.toolbaritems, 0, wx.SHAPED | wx.ALIGN_CENTER)
225
self.txt16 = wx.TextCtrl(self, -1, "<Default>", wx.DefaultPosition, wx.Size(200, -1), wx.TE_READONLY)
226
self.btn16 = wx.Button(self, self.ID_16, "Change")
228
self.txt24 = wx.TextCtrl(self, -1, "<Default>", wx.DefaultPosition, wx.Size(200, -1), wx.TE_READONLY)
229
self.btn24 = wx.Button(self, self.ID_24, "Change")
231
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
232
self.theSizer.Add(wx.StaticText(self, -1, "Icon 16x16:"), 0, wx.ALIGN_LEFT) #AB:with wx.SHAPED only shows 1st word
233
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
234
self.theSizer.Add(wx.StaticText(self, -1, "Icon 24x24:"), 0, wx.ALIGN_LEFT) #AB:with wx.SHAPED only shows 1st word
236
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
237
self.theSizer.Add(self.txt16, 0, wx.ALIGN_LEFT | wx.SHAPED)
238
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
239
self.theSizer.Add(self.txt24, 0, wx.ALIGN_LEFT | wx.SHAPED)
241
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
242
self.theSizer.Add(self.btn16, 0, wx.ALIGN_CENTER | wx.SHAPED)
243
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
244
self.theSizer.Add(self.btn24, 0, wx.ALIGN_CENTER | wx.SHAPED)
246
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
247
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
248
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
249
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
251
self.btnUpdate = wx.Button(self, self.ID_UPDATE, "&Update")
252
self.btnSave = wx.Button(self, self.ID_SAVE, "&Save")
254
self.btnClose = wx.Button(self, 101, "&Close")
256
self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
257
self.theSizer.Add(self.btnClose, 0, wx.SHAPED | wx.ALIGN_CENTER)
258
self.theSizer.Add(self.btnUpdate, 0, wx.SHAPED | wx.ALIGN_CENTER)
259
self.theSizer.Add(self.btnSave, 0, wx.SHAPED | wx.ALIGN_CENTER)
260
self.btnClose.SetDefault()
262
self.SetAutoLayout(True)
263
self.SetSizerAndFit(self.theSizer)
265
self.Bind(wx.EVT_BUTTON, self.OnbtnUp, id=self.ID_UP)
266
self.Bind(wx.EVT_BUTTON, self.OnbtnAdd, id=self.ID_ADD)
267
self.Bind(wx.EVT_BUTTON, self.OnbtnRemove, id=self.ID_REMOVE)
268
self.Bind(wx.EVT_BUTTON, self.OnbtnDown, id=self.ID_DOWN)
269
self.Bind(wx.EVT_BUTTON, self.OnbtnUpdate, id=self.ID_UPDATE)
270
self.Bind(wx.EVT_BUTTON, self.OnbtnSave, id=self.ID_SAVE)
271
self.Bind(wx.EVT_BUTTON, self.OnbtnChange16, id=self.ID_16)
272
self.Bind(wx.EVT_BUTTON, self.OnbtnChange24, id=self.ID_24)
273
self.Bind(wx.EVT_BUTTON, self.OnbtnClose, id=101)
275
self.Bind(wx.EVT_COMBOBOX, self.OnList, id=self.ID_LIST)
276
self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.ID_PROGRAM)
278
self.parent.LoadDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
280
def OnCloseW(self, event):
281
self.parent.SaveDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
282
if event is not None:
285
def OnbtnAdd(self, event):
286
tselection = self.programmenu.GetStringSelection()
287
tsel = self.programmenu.GetSelection()
289
drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Add", "Mistake")
291
separator = (tselection == "<Insert Separator>")
293
tselection = "<Separator>"
294
sel = self.toolbaritems.GetSelection()
297
self.toolbaritems.InsertItems([tselection], sel+1)
298
self.toolbaritems.SetSelection(sel+1)
300
def OnbtnChange16(self, event):
301
d = wx.SingleChoiceDialog(self.parent, 'Change Icon For 16x16:', "Change Icon", ["Default", "Select File"], wx.CHOICEDLG_STYLE)
302
d.SetSize(wx.Size(250, 250))
303
answer = d.ShowModal()
305
if answer == wx.ID_OK:
306
sname = self.programmenu.GetStringSelection()
308
newname = "<Default>"
310
dlg = drFileDialog.FileDialog(self.parent, "Open", "PNG (*.png)|*.png")
311
if dlg.ShowModal() == wx.ID_OK:
312
newname = dlg.GetPath()
313
self.txt16.SetValue(newname)
315
if newname == "<Default>":
318
if sname in self.customNames:
319
ci = self.customNames.index(sname)
320
self.customFiles16.pop(ci)
321
self.customFiles16.insert(ci, newname)
323
self.customNames.append(sname)
324
self.customFiles16.append(newname)
325
self.customFiles24.append("")
327
def OnbtnChange24(self, event):
328
d = wx.SingleChoiceDialog(self.parent, 'Change Icon For 24x24:', "Change Icon", ["Default", "Select File"], wx.CHOICEDLG_STYLE)
329
d.SetSize(wx.Size(250, 250))
330
answer = d.ShowModal()
332
if answer == wx.ID_OK:
333
sname = self.programmenu.GetStringSelection()
335
newname = "<Default>"
337
dlg = drFileDialog.FileDialog(self.parent, "Open", "PNG (*.png)|*.png")
338
if dlg.ShowModal() == wx.ID_OK:
339
newname = dlg.GetPath()
340
self.txt24.SetValue(newname)
342
if newname == "<Default>":
345
if sname in self.customNames:
346
ci = self.customNames.index(sname)
347
self.customFiles24.pop(ci)
348
self.customFiles24.insert(ci, newname)
350
self.customNames.append(sname)
351
self.customFiles16.append("")
352
self.customFiles24.append(newname)
354
def OnbtnClose(self, event):
357
def OnbtnDown(self, event):
358
sel = self.toolbaritems.GetSelection()
359
if sel < self.toolbaritems.GetCount()-1 and sel > 0:
360
txt = self.toolbaritems.GetString(sel)
361
self.toolbaritems.Delete(sel)
362
self.toolbaritems.InsertItems([txt], sel+1)
363
self.toolbaritems.SetSelection(sel+1)
365
def OnbtnRemove(self, event):
366
sel = self.toolbaritems.GetSelection()
368
drScrolledMessageDialog.ShowMessage(self, "You cannot remove the root item.", "Mistake")
371
drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Remove", "Mistake")
374
self.toolbaritems.Delete(sel)
375
self.toolbaritems.SetSelection(sel-1)
377
def OnbtnUp(self, event):
378
sel = self.toolbaritems.GetSelection()
380
txt = self.toolbaritems.GetString(sel)
381
self.toolbaritems.Delete(sel)
382
self.toolbaritems.InsertItems([txt], sel-1)
383
self.toolbaritems.SetSelection(sel-1)
385
def OnbtnUpdate(self, event):
387
c = self.toolbaritems.GetCount()
392
pop = self.toolbaritems.GetString(y)
393
if not pop == "<ROOT>":
394
ToolBarList.append(pop)
397
self.parent.ToolBarList = ToolBarList
399
if self.parent.hasToolBar:
400
self.parent.DestroyToolBar()
401
self.parent.SetToolBar(None)
402
self.parent.toolbar = wx.ToolBar(self.parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL)
403
self.parent.ToolBarIdList = self.parent.SetupToolBar()
405
if self.parent.prefs.iconsize > 0:
406
self.parent.SetToolBar(self.parent.toolbar)
408
thereisafile = (len(self.parent.txtDocument.filename) > 0)
409
self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
411
if self.parent.txtPrompt.pid == -1:
412
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, True)
413
self.parent.toolbar.EnableTool(self.parent.ID_END, False)
414
self.parent.toolbar.EnableTool(self.parent.ID_RUN, thereisafile)
415
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, thereisafile)
417
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
418
self.parent.toolbar.EnableTool(self.parent.ID_END, True)
420
self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
421
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
423
if self.parent.prefs.enablefeedback:
424
drScrolledMessageDialog.ShowMessage(self, ("Succesfully updated the current instance of DrPython.\nClick Save to make it permanent."), "Updated ToolBar")
426
def OnbtnSave(self, event):
427
toolbarfile = self.parent.datdirectory + "/toolbar.dat"
429
msg = "Succesfully wrote to:\n" + toolbarfile + "\nand updated the current instance of DrPython."
433
toolbarcustomfile = self.parent.datdirectory + "/toolbar.custom.icons.dat"
434
f = file(toolbarcustomfile, 'w')
436
l = len(self.customNames)
438
if (len(self.customFiles16[x]) > 0) or (len(self.customFiles24[x]) > 0):
439
f.write("<Name>"+self.customNames[x]+"</Name><16>"+self.customFiles16[x]+"</16><24>"+self.customFiles24[x]+"</24>\n")
442
msg = msg + "\n\nSuccesfully Saved Custom ToolBar Icons."
445
c = self.toolbaritems.GetCount()
447
toolbaritemsstring = ""
451
pop = self.toolbaritems.GetString(y)
452
if not pop == "<ROOT>":
453
toolbaritemsstring = toolbaritemsstring + pop + "\n"
454
ToolBarList.append(pop)
457
self.parent.ToolBarList = ToolBarList
459
if self.parent.hasToolBar:
460
if self.parent.toolbar is not None:
461
self.parent.SetToolBar(None)
463
self.parent.DestroyToolBar()
464
self.parent.toolbar = wx.ToolBar(self.parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL)
465
self.parent.ToolBarIdList = self.parent.SetupToolBar()
467
if self.parent.prefs.iconsize > 0:
468
self.parent.SetToolBar(self.parent.toolbar)
470
thereisafile = (len(self.parent.txtDocument.filename) > 0)
471
self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
473
if self.parent.txtPrompt.pid == -1:
474
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, True)
475
self.parent.toolbar.EnableTool(self.parent.ID_END, False)
476
self.parent.toolbar.EnableTool(self.parent.ID_RUN, thereisafile)
477
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, thereisafile)
479
self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
480
self.parent.toolbar.EnableTool(self.parent.ID_END, True)
482
self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
483
self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
486
f = file(toolbarfile, 'w')
487
f.write(toolbaritemsstring)
490
drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n" + toolbarfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
492
if self.parent.prefs.enablefeedback:
493
drScrolledMessageDialog.ShowMessage(self, msg, "Saved ToolBar")
495
def OnList(self, event):
496
sel = self.cboList.GetSelection()
498
self.programmenu.Set(self.ListArray[sel])
500
def OnSelect(self, event):
501
#Take one away for "Insert Separator"
502
seltext = self.programmenu.GetStringSelection()
504
if seltext in self.customNames:
505
i = self.customNames.index(seltext)
506
if self.customFiles16[i]:
507
self.txt16.SetValue(self.customFiles16[i])
509
self.txt16.SetValue("<Default>")
510
if self.customFiles24[i]:
511
self.txt24.SetValue(self.customFiles24[i])
513
self.txt24.SetValue("<Default>")
515
self.txt16.SetValue("<Default>")
516
self.txt24.SetValue("<Default>")
b'\\ No newline at end of file'