~ubuntu-branches/ubuntu/trusty/drpython/trusty

« back to all changes in this revision

Viewing changes to drToolBarDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-07-03 22:11:49 UTC
  • mfrom: (0.1.3 upstream) (8 intrepid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20080703221149-puu681p4w33g3s3m
* New upstream release.
* Bump epoch due to new version numbering system.
* debian/control:
  - Adjust dependencies for wxwidgets2.8.
* debian/patches/15_output_redirection.dpatch:
  - Set standard output and error to valid UNIX locations.
* Adjust patches for new upstream release:
  - debian/patches/03_pythonfix.dpatch
* Drop patches, implemented upstream:
  - debian/patches/10_ctrl_q_to_exit_as_default_shortcut.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#       Programmer:     Daniel Pozmanter
2
 
#       E-mail:         drpython@bluebottle.com
3
 
#       Note:           You must reply to the verification e-mail to get through.
4
 
#
5
 
#       Copyright 2003-2005 Daniel Pozmanter
6
 
#
7
 
#       Distributed under the terms of the GPL (GNU Public License)
 
1
#   Programmer: Daniel Pozmanter
 
2
#   E-mail:     drpython@bluebottle.com
 
3
#   Note:       You must reply to the verification e-mail to get through.
 
4
#
 
5
#   Copyright 2003-2007 Daniel Pozmanter
 
6
#
 
7
#   Distributed under the terms of the GPL (GNU Public License)
8
8
#
9
9
#    DrPython is free software; you can redistribute it and/or modify
10
10
#    it under the terms of the GNU General Public License as published by
19
19
#    You should have received a copy of the GNU General Public License
20
20
#    along with this program; if not, write to the Free Software
21
21
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 
        
 
22
 
23
23
#ToolBar Menu Dialog
24
24
 
25
25
import os.path, re
31
31
import drFileDialog
32
32
 
33
33
def GetToolBarLabels(filename, frame):
34
 
        try:
35
 
                f = file(filename, 'r')
36
 
                text = f.read()
37
 
                f.close()
38
 
        except:
39
 
                drScrolledMessageDialog.ShowMessage(frame, 'File error with: "' + filename + '".', "ERROR")
40
 
                return []
41
 
        
42
 
        rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddToolBarFunction\(.*\)', re.MULTILINE)
43
 
                
44
 
        allPopUps = rePopUpMenu.findall(text)
45
 
 
46
 
        PopUpArray = []
47
 
                        
48
 
        for s in allPopUps:
49
 
                #From the Left most '('
50
 
                start = s.find('(')
51
 
                #To the Right most ')'
52
 
                end = s.rfind(')')      
53
 
                
54
 
                if (start > -1) and (end > -1):
55
 
                        s = s[start+1:end]
56
 
                        i = s.find(',')
57
 
                        e = i + 1 + s[i+1:].find(',')
58
 
                        arglabel = s[i+1:e].strip().strip('"')
59
 
                        
60
 
                        PopUpArray.append("<Plugin>:"+arglabel)
61
 
                        
62
 
        return PopUpArray
 
34
    try:
 
35
        f = file(filename, 'r')
 
36
        text = f.read()
 
37
        f.close()
 
38
    except:
 
39
        drScrolledMessageDialog.ShowMessage(frame, 'File error with: "' + filename + '".', "ERROR")
 
40
        return []
 
41
 
 
42
        # modified 22/10/2006 Jean-Pierre MANDON
 
43
        # line: rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddToolBarFunction\(.*\)', re.MULTILINE)
 
44
        # replaced with
 
45
    rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddPluginToolBarFunction\(.*\)', re.MULTILINE)
 
46
 
 
47
    allPopUps = rePopUpMenu.findall(text)
 
48
 
 
49
    PopUpArray = []
 
50
 
 
51
    for s in allPopUps:
 
52
        #From the Left most '('
 
53
        start = s.find('(')
 
54
        #To the Right most ')'
 
55
        end = s.rfind(')')
 
56
 
 
57
        if (start > -1) and (end > -1):
 
58
            s = s[start+1:end]
 
59
            i = s.find(',')
 
60
            # modified 22/10/2006 Jean-Pierre MANDON
 
61
            """
 
62
            e = i + 1 + s[i+1:].find(',')
 
63
            arglabel = s[i+1:e].strip().strip('"')
 
64
            """
 
65
            # replaced with
 
66
            arglabel=s[1:i-1]
 
67
            arglabel=arglabel.strip().strip('"')
 
68
            # end of modification
 
69
            PopUpArray.append("<Plugin>:"+arglabel)
 
70
 
 
71
    return PopUpArray
63
72
 
64
73
class drToolBarDialog(wx.Dialog):
65
74
 
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)
68
 
                wx.Yield()
69
 
                                
70
 
                self.parent = parent
71
 
                
72
 
                self.ID_PROGRAM = 1001
73
 
                self.ID_POPUP = 1002
74
 
                
75
 
                self.ID_ADD = 1003
76
 
                self.ID_REMOVE = 1004
77
 
                self.ID_UPDATE = 1005
78
 
                self.ID_SAVE = 1006
79
 
                
80
 
                self.ID_LIST = 1300
81
 
                
82
 
                self.ID_UP = 1111
83
 
                self.ID_DOWN = 2222
84
 
                
85
 
                self.ID_16 = 3016
86
 
                self.ID_24 = 3024
87
 
                                
88
 
                self.theSizer = wx.FlexGridSizer(5, 4, 5, 10)
89
 
                self.menubuttonSizer = wx.BoxSizer(wx.VERTICAL)
90
 
                self.listSizer = wx.BoxSizer(wx.HORIZONTAL)
91
 
                
92
 
                self.userpreferencesdirectory = parent.userpreferencesdirectory
93
 
                
94
 
                ToolBarList = []
95
 
                
96
 
                map(ToolBarList.append, parent.ToolBarList)
97
 
                
98
 
                #Icons:
99
 
 
100
 
                self.customNames, self.customFiles16, self.customFiles24 = drToolBarFile.getCustomBitmaps(self.parent.userpreferencesdirectory)
101
 
                                
102
 
                #End Icons
103
 
                
104
 
                ToolBarList.insert(0, "<ROOT>")
105
 
                
106
 
                programmenulist = drShortcutsFile.GetShortcutList()
107
 
                try:
108
 
                        i = programmenulist.index("Toggle Maximize")
109
 
                        programmenulist.pop(i)
110
 
                except:
111
 
                        pass            
112
 
                
113
 
                programmenulist.sort()          
114
 
                
115
 
                programmenulist.insert(0, "<Insert Separator>")
116
 
                
117
 
                self.ListArray = []
118
 
                self.ListArray.append(programmenulist)
119
 
                
120
 
                #STC
121
 
                
122
 
                stclist = []
123
 
                map(stclist.append, drShortcutsFile.GetSTCShortcutList())
124
 
                stclist.insert(0, "<Insert Separator>")
125
 
                self.ListArray.append(stclist)
126
 
                
127
 
                #DrScript
128
 
                
129
 
                drscriptlist = []
130
 
                map(drscriptlist.append, parent.drscriptmenu.titles)
131
 
                x = 0
132
 
                l = len(drscriptlist)
133
 
                while x < l:
134
 
                        drscriptlist[x] = "<DrScript>:" + drscriptlist[x]
135
 
                        x = x + 1
136
 
                drscriptlist.insert(0, "<Insert Separator>")
137
 
                self.ListArray.append(drscriptlist)
138
 
                
139
 
                #Plugins
140
 
                plist = os.listdir(parent.userpreferencesdirectory + "/plugins")
141
 
                
142
 
                self.PluginList = []
143
 
                plugins = []
144
 
                for p in plist:
145
 
                        i = p.find(".py")                       
146
 
                        l = len(p)
147
 
                        if i > -1 and (i + 3 == l):                     
148
 
                                self.PluginList.append("<Plugin>:" + p[:i])
149
 
                                plugins.append(p[:i])
150
 
                
151
 
                poplist = []
152
 
                for plugin in plugins:                  
153
 
                        pluginfile = self.parent.userpreferencesdirectory + "/plugins/" + plugin + ".py"
154
 
                        pluginlist = GetToolBarLabels(pluginfile, self)
155
 
                        plist = self.parent.GetPluginLabels(pluginfile)
156
 
                        for p in plist:
157
 
                                if not (p in pluginlist):
158
 
                                        pluginlist.append(p)
159
 
                        if len(pluginlist) > 0:
160
 
                                pluginlist.insert(0, "<Insert Separator>")
161
 
                                self.ListArray.append(pluginlist)       
162
 
                        else:
163
 
                                poplist.append("<Plugin>:" + plugin)
164
 
                                
165
 
                for popl in poplist:
166
 
                        i = self.PluginList.index(popl)
167
 
                        self.PluginList.pop(i)
168
 
                
169
 
                list = ["Standard", "Text Control", "DrScript"]
170
 
                list.extend(self.PluginList)
171
 
                                
172
 
                self.cboList = wx.ComboBox(self, self.ID_LIST, "Standard", wx.DefaultPosition, (200, -1), list, wx.CB_DROPDOWN|wx.CB_READONLY)
173
 
                
174
 
                self.programmenu = wx.ListBox(self, self.ID_PROGRAM, wx.DefaultPosition, wx.Size(250, 250), programmenulist)
175
 
                
176
 
                self.toolbaritems = wx.ListBox(self, self.ID_POPUP, wx.DefaultPosition, wx.Size(250, 250), ToolBarList)
177
 
                
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 ")
182
 
                
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)
193
 
                
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)
196
 
 
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)
201
 
                
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)       
206
 
                
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)
215
 
                
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")
218
 
                
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")
221
 
                                
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)
226
 
                
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)
231
 
                
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)
236
 
                                                                
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)
241
 
                                
242
 
                self.btnUpdate = wx.Button(self, self.ID_UPDATE, "&Update")
243
 
                self.btnSave = wx.Button(self, self.ID_SAVE, "&Save")
244
 
                
245
 
                self.btnClose = wx.Button(self, 101, "&Close")          
246
 
                
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()
252
 
 
253
 
                self.SetAutoLayout(True)
254
 
                self.SetSizerAndFit(self.theSizer)
255
 
        
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)
265
 
                
266
 
                self.Bind(wx.EVT_COMBOBOX, self.OnList, id=self.ID_LIST)
267
 
                self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.ID_PROGRAM)            
268
 
 
269
 
                self.parent.LoadDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
270
 
 
271
 
        def OnCloseW(self, event):
272
 
                self.parent.SaveDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
273
 
                if event is not None:
274
 
                        event.Skip()                            
275
 
                                
276
 
        def OnbtnAdd(self, event):      
277
 
                tselection = self.programmenu.GetStringSelection()
278
 
                tsel = self.programmenu.GetSelection()
279
 
                if tsel == -1:
280
 
                        drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Add", "Mistake")
281
 
                        return  
282
 
                separator = (tselection == "<Insert Separator>")
283
 
                if separator:
284
 
                        tselection = "<Separator>"      
285
 
                sel = self.toolbaritems.GetSelection()
286
 
                if sel == -1:
287
 
                        sel = 0                 
288
 
                self.toolbaritems.InsertItems([tselection], sel+1)
289
 
                self.toolbaritems.SetSelection(sel+1)
290
 
        
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()
295
 
                d.Destroy()             
296
 
                if (answer == wx.ID_OK):
297
 
                        sname = self.programmenu.GetStringSelection()
298
 
                        i = d.GetSelection()
299
 
                        newname = "<Default>"
300
 
                        if i == 1:
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)
305
 
                        
306
 
                        if newname == "<Default>":
307
 
                                newname = ""
308
 
                        
309
 
                        if sname in self.customNames:
310
 
                                ci = self.customNames.index(sname)
311
 
                                self.customFiles16.pop(ci)
312
 
                                self.customFiles16.insert(ci, newname)
313
 
                        else:
314
 
                                self.customNames.append(sname)
315
 
                                self.customFiles16.append(newname)
316
 
                                self.customFiles24.append("")
317
 
                
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()
322
 
                d.Destroy()             
323
 
                if (answer == wx.ID_OK):
324
 
                        sname = self.programmenu.GetStringSelection()
325
 
                        i = d.GetSelection()
326
 
                        newname = "<Default>"
327
 
                        if i == 1:
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)
332
 
                        
333
 
                        if newname == "<Default>":
334
 
                                newname = ""
335
 
                        
336
 
                        if sname in self.customNames:
337
 
                                ci = self.customNames.index(sname)
338
 
                                self.customFiles24.pop(ci)
339
 
                                self.customFiles24.insert(ci, newname)
340
 
                        else:
341
 
                                self.customNames.append(sname)
342
 
                                self.customFiles16.append("")
343
 
                                self.customFiles24.append(newname)
344
 
        
345
 
        def OnbtnClose(self, event):
346
 
                self.Close(1)
347
 
                
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)
355
 
        
356
 
        def OnbtnRemove(self, event):
357
 
                sel = self.toolbaritems.GetSelection()
358
 
                selection = self.toolbaritems.GetStringSelection()
359
 
                if not sel:                     
360
 
                        drScrolledMessageDialog.ShowMessage(self, "You cannot remove the root item.", "Mistake")
361
 
                        return
362
 
                if sel == -1:
363
 
                        drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Remove", "Mistake")
364
 
                        return
365
 
 
366
 
                self.toolbaritems.Delete(sel)
367
 
                self.toolbaritems.SetSelection(sel-1)
368
 
        
369
 
        def OnbtnUp(self, event):
370
 
                sel = self.toolbaritems.GetSelection()          
371
 
                if sel > 1:
372
 
                        txt = self.toolbaritems.GetString(sel)
373
 
                        self.toolbaritems.Delete(sel)
374
 
                        self.toolbaritems.InsertItems([txt], sel-1)
375
 
                        self.toolbaritems.SetSelection(sel-1)
376
 
        
377
 
        def OnbtnUpdate(self, event):           
378
 
                y = 0
379
 
                c = self.toolbaritems.GetCount()
380
 
                                
381
 
                ToolBarList = []
382
 
                
383
 
                while y < c:
384
 
                        pop = self.toolbaritems.GetString(y)
385
 
                        if not pop == "<ROOT>":
386
 
                                ToolBarList.append(pop)
387
 
                        y = y + 1
388
 
                
389
 
                self.parent.ToolBarList = ToolBarList
390
 
                
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()                  
396
 
                                
397
 
                        if (self.parent.prefs.iconsize > 0):
398
 
                                self.parent.SetToolBar(self.parent.toolbar)
399
 
                        
400
 
                        thereisafile = (len(self.parent.txtDocument.filename) > 0)
401
 
                        self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
402
 
                        
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)                   
408
 
                        else:
409
 
                                self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
410
 
                                self.parent.toolbar.EnableTool(self.parent.ID_END, True)
411
 
                                if thereisafile:
412
 
                                        self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
413
 
                                        self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
414
 
                        
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")
417
 
                
418
 
        def OnbtnSave(self, event):
419
 
                toolbarfile = self.userpreferencesdirectory + "/toolbar.dat"
420
 
                
421
 
                msg = "Succesfully wrote to:\n"  + toolbarfile + "\nand updated the current instance of DrPython."              
422
 
                
423
 
                #Custom Bitmaps.
424
 
                if len(self.customNames) > 0:
425
 
                        toolbarcustomfile = self.userpreferencesdirectory + "/toolbar.custom.icons.dat"
426
 
                        f = file(toolbarcustomfile, 'w')
427
 
                        x = 0
428
 
                        l = len(self.customNames)
429
 
                        while x < l:
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")
432
 
                                x = x + 1
433
 
                        f.close()
434
 
                        msg = msg + "\n\nSuccesfully Saved Custom ToolBar Icons."               
435
 
                
436
 
                y = 0
437
 
                c = self.toolbaritems.GetCount()
438
 
                                
439
 
                toolbaritemsstring = ""
440
 
                ToolBarList = []
441
 
                
442
 
                while y < c:
443
 
                        pop = self.toolbaritems.GetString(y)
444
 
                        if not pop == "<ROOT>":
445
 
                                toolbaritemsstring = toolbaritemsstring + pop + "\n"
446
 
                                ToolBarList.append(pop)
447
 
                        y = y + 1
448
 
 
449
 
                self.parent.ToolBarList = ToolBarList
450
 
 
451
 
                if self.parent.hasToolBar:
452
 
                        if self.parent.toolbar is not None:
453
 
                                self.parent.SetToolBar(None)
454
 
                        
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()                  
458
 
                                
459
 
                        if (self.parent.prefs.iconsize > 0):
460
 
                                self.parent.SetToolBar(self.parent.toolbar)
461
 
                        
462
 
                        thereisafile = (len(self.parent.txtDocument.filename) > 0)
463
 
                        self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
464
 
                        
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)                   
470
 
                        else:
471
 
                                self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
472
 
                                self.parent.toolbar.EnableTool(self.parent.ID_END, True)
473
 
                                if thereisafile:
474
 
                                        self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
475
 
                                        self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
476
 
        
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")
479
 
                        return
480
 
                try:                    
481
 
                        f = file(toolbarfile, 'w')
482
 
                        f.write(toolbaritemsstring)
483
 
                        f.close()
484
 
                except IOError:                 
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")
486
 
                        return
487
 
                if self.parent.prefs.enablefeedback:
488
 
                        drScrolledMessageDialog.ShowMessage(self, msg, "Saved ToolBar")
489
 
                        
490
 
        def OnList(self, event):
491
 
                sel = self.cboList.GetSelection()
492
 
 
493
 
                self.programmenu.Set(self.ListArray[sel])
494
 
                        
495
 
        def OnSelect(self, event):
496
 
                #Take one away for "Insert Separator"
497
 
                sel = self.programmenu.GetSelection() - 1
498
 
                seltext = self.programmenu.GetStringSelection()
499
 
                
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])
504
 
                        else:
505
 
                                self.txt16.SetValue("<Default>")
506
 
                        if len(self.customFiles24[i]) > 0:
507
 
                                self.txt24.SetValue(self.customFiles24[i])
508
 
                        else:
509
 
                                self.txt24.SetValue("<Default>")
510
 
                else:
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)
 
77
        wx.Yield()
 
78
 
 
79
        self.parent = parent
 
80
 
 
81
        self.ID_PROGRAM = 1001
 
82
        self.ID_POPUP = 1002
 
83
 
 
84
        self.ID_ADD = 1003
 
85
        self.ID_REMOVE = 1004
 
86
        self.ID_UPDATE = 1005
 
87
        self.ID_SAVE = 1006
 
88
 
 
89
        self.ID_LIST = 1300
 
90
 
 
91
        self.ID_UP = 1111
 
92
        self.ID_DOWN = 2222
 
93
 
 
94
        self.ID_16 = 3016
 
95
        self.ID_24 = 3024
 
96
 
 
97
        self.theSizer = wx.FlexGridSizer(5, 4, 5, 10)
 
98
        self.menubuttonSizer = wx.BoxSizer(wx.VERTICAL)
 
99
        self.listSizer = wx.BoxSizer(wx.HORIZONTAL)
 
100
 
 
101
        self.preferencesdirectory = parent.preferencesdirectory
 
102
 
 
103
        ToolBarList = []
 
104
 
 
105
        map(ToolBarList.append, parent.ToolBarList)
 
106
 
 
107
        #Icons:
 
108
 
 
109
        self.customNames, self.customFiles16, self.customFiles24 = drToolBarFile.getCustomBitmaps(self.parent.datdirectory)
 
110
 
 
111
        #End Icons
 
112
 
 
113
        ToolBarList.insert(0, "<ROOT>")
 
114
 
 
115
        programmenulist = drShortcutsFile.GetShortcutList()
 
116
        try:
 
117
            i = programmenulist.index("Toggle Maximize")
 
118
            programmenulist.pop(i)
 
119
        except:
 
120
            pass
 
121
 
 
122
        programmenulist.sort()
 
123
 
 
124
        programmenulist.insert(0, "<Insert Separator>")
 
125
 
 
126
        self.ListArray = []
 
127
        self.ListArray.append(programmenulist)
 
128
 
 
129
        #STC
 
130
 
 
131
        stclist = []
 
132
        map(stclist.append, drShortcutsFile.GetSTCShortcutList())
 
133
        stclist.insert(0, "<Insert Separator>")
 
134
        self.ListArray.append(stclist)
 
135
 
 
136
        #DrScript
 
137
 
 
138
        drscriptlist = []
 
139
        map(drscriptlist.append, parent.drscriptmenu.titles)
 
140
        x = 0
 
141
        l = len(drscriptlist)
 
142
        while x < l:
 
143
            drscriptlist[x] = "<DrScript>:" + drscriptlist[x]
 
144
            x = x + 1
 
145
        drscriptlist.insert(0, "<Insert Separator>")
 
146
        self.ListArray.append(drscriptlist)
 
147
 
 
148
        #Plugins
 
149
        plist = os.listdir(parent.pluginsdirectory)
 
150
 
 
151
        self.PluginList = []
 
152
        plugins = []
 
153
        for p in plist:
 
154
            i = p.find(".py")
 
155
            l = len(p)
 
156
            if i > -1 and (i + 3 == l):
 
157
                self.PluginList.append("<Plugin>:" + p[:i])
 
158
                plugins.append(p[:i])
 
159
 
 
160
        poplist = []
 
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)
 
165
            for p in plist:
 
166
                if not (p in pluginlist):
 
167
                    pluginlist.append(p)
 
168
            if pluginlist:
 
169
                pluginlist.insert(0, "<Insert Separator>")
 
170
                self.ListArray.append(pluginlist)
 
171
            else:
 
172
                poplist.append("<Plugin>:" + plugin)
 
173
 
 
174
        for popl in poplist:
 
175
            i = self.PluginList.index(popl)
 
176
            self.PluginList.pop(i)
 
177
 
 
178
        list = ["Standard", "Text Control", "DrScript"]
 
179
        list.extend(self.PluginList)
 
180
 
 
181
        self.cboList = wx.ComboBox(self, self.ID_LIST, "Standard", wx.DefaultPosition, (200, -1), list, wx.CB_DROPDOWN|wx.CB_READONLY)
 
182
 
 
183
        self.programmenu = wx.ListBox(self, self.ID_PROGRAM, wx.DefaultPosition, wx.Size(250, 250), programmenulist)
 
184
 
 
185
        self.toolbaritems = wx.ListBox(self, self.ID_POPUP, wx.DefaultPosition, wx.Size(250, 250), ToolBarList)
 
186
 
 
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 ")
 
191
 
 
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)
 
202
 
 
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)
 
205
 
 
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)
 
210
 
 
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)
 
215
 
 
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)
 
224
 
 
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")
 
227
 
 
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")
 
230
 
 
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
 
235
 
 
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)
 
240
 
 
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)
 
245
 
 
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)
 
250
 
 
251
        self.btnUpdate = wx.Button(self, self.ID_UPDATE, "&Update")
 
252
        self.btnSave = wx.Button(self, self.ID_SAVE, "&Save")
 
253
 
 
254
        self.btnClose = wx.Button(self, 101, "&Close")
 
255
 
 
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()
 
261
 
 
262
        self.SetAutoLayout(True)
 
263
        self.SetSizerAndFit(self.theSizer)
 
264
 
 
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)
 
274
 
 
275
        self.Bind(wx.EVT_COMBOBOX, self.OnList, id=self.ID_LIST)
 
276
        self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.ID_PROGRAM)
 
277
 
 
278
        self.parent.LoadDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
 
279
 
 
280
    def OnCloseW(self, event):
 
281
        self.parent.SaveDialogSizeAndPosition(self, 'toolbardialog.sizeandposition.dat')
 
282
        if event is not None:
 
283
            event.Skip()
 
284
 
 
285
    def OnbtnAdd(self, event):
 
286
        tselection = self.programmenu.GetStringSelection()
 
287
        tsel = self.programmenu.GetSelection()
 
288
        if tsel == -1:
 
289
            drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Add", "Mistake")
 
290
            return
 
291
        separator = (tselection == "<Insert Separator>")
 
292
        if separator:
 
293
            tselection = "<Separator>"
 
294
        sel = self.toolbaritems.GetSelection()
 
295
        if sel == -1:
 
296
            sel = 0
 
297
        self.toolbaritems.InsertItems([tselection], sel+1)
 
298
        self.toolbaritems.SetSelection(sel+1)
 
299
 
 
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()
 
304
        d.Destroy()
 
305
        if answer == wx.ID_OK:
 
306
            sname = self.programmenu.GetStringSelection()
 
307
            i = d.GetSelection()
 
308
            newname = "<Default>"
 
309
            if i == 1:
 
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)
 
314
 
 
315
            if newname == "<Default>":
 
316
                newname = ""
 
317
 
 
318
            if sname in self.customNames:
 
319
                ci = self.customNames.index(sname)
 
320
                self.customFiles16.pop(ci)
 
321
                self.customFiles16.insert(ci, newname)
 
322
            else:
 
323
                self.customNames.append(sname)
 
324
                self.customFiles16.append(newname)
 
325
                self.customFiles24.append("")
 
326
 
 
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()
 
331
        d.Destroy()
 
332
        if answer == wx.ID_OK:
 
333
            sname = self.programmenu.GetStringSelection()
 
334
            i = d.GetSelection()
 
335
            newname = "<Default>"
 
336
            if i == 1:
 
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)
 
341
 
 
342
            if newname == "<Default>":
 
343
                newname = ""
 
344
 
 
345
            if sname in self.customNames:
 
346
                ci = self.customNames.index(sname)
 
347
                self.customFiles24.pop(ci)
 
348
                self.customFiles24.insert(ci, newname)
 
349
            else:
 
350
                self.customNames.append(sname)
 
351
                self.customFiles16.append("")
 
352
                self.customFiles24.append(newname)
 
353
 
 
354
    def OnbtnClose(self, event):
 
355
        self.Close(1)
 
356
 
 
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)
 
364
 
 
365
    def OnbtnRemove(self, event):
 
366
        sel = self.toolbaritems.GetSelection()
 
367
        if not sel:
 
368
            drScrolledMessageDialog.ShowMessage(self, "You cannot remove the root item.", "Mistake")
 
369
            return
 
370
        if sel == -1:
 
371
            drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Remove", "Mistake")
 
372
            return
 
373
 
 
374
        self.toolbaritems.Delete(sel)
 
375
        self.toolbaritems.SetSelection(sel-1)
 
376
 
 
377
    def OnbtnUp(self, event):
 
378
        sel = self.toolbaritems.GetSelection()
 
379
        if sel > 1:
 
380
            txt = self.toolbaritems.GetString(sel)
 
381
            self.toolbaritems.Delete(sel)
 
382
            self.toolbaritems.InsertItems([txt], sel-1)
 
383
            self.toolbaritems.SetSelection(sel-1)
 
384
 
 
385
    def OnbtnUpdate(self, event):
 
386
        y = 0
 
387
        c = self.toolbaritems.GetCount()
 
388
 
 
389
        ToolBarList = []
 
390
 
 
391
        while y < c:
 
392
            pop = self.toolbaritems.GetString(y)
 
393
            if not pop == "<ROOT>":
 
394
                ToolBarList.append(pop)
 
395
            y = y + 1
 
396
 
 
397
        self.parent.ToolBarList = ToolBarList
 
398
 
 
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()
 
404
 
 
405
            if self.parent.prefs.iconsize > 0:
 
406
                self.parent.SetToolBar(self.parent.toolbar)
 
407
 
 
408
            thereisafile = (len(self.parent.txtDocument.filename) > 0)
 
409
            self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
 
410
 
 
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)
 
416
            else:
 
417
                self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
 
418
                self.parent.toolbar.EnableTool(self.parent.ID_END, True)
 
419
                if thereisafile:
 
420
                    self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
 
421
                    self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
 
422
 
 
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")
 
425
 
 
426
    def OnbtnSave(self, event):
 
427
        toolbarfile = self.parent.datdirectory + "/toolbar.dat"
 
428
 
 
429
        msg = "Succesfully wrote to:\n"  + toolbarfile + "\nand updated the current instance of DrPython."
 
430
 
 
431
        #Custom Bitmaps.
 
432
        if self.customNames:
 
433
            toolbarcustomfile = self.parent.datdirectory + "/toolbar.custom.icons.dat"
 
434
            f = file(toolbarcustomfile, 'w')
 
435
            x = 0
 
436
            l = len(self.customNames)
 
437
            while x < l:
 
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")
 
440
                x = x + 1
 
441
            f.close()
 
442
            msg = msg + "\n\nSuccesfully Saved Custom ToolBar Icons."
 
443
 
 
444
        y = 0
 
445
        c = self.toolbaritems.GetCount()
 
446
 
 
447
        toolbaritemsstring = ""
 
448
        ToolBarList = []
 
449
 
 
450
        while y < c:
 
451
            pop = self.toolbaritems.GetString(y)
 
452
            if not pop == "<ROOT>":
 
453
                toolbaritemsstring = toolbaritemsstring + pop + "\n"
 
454
                ToolBarList.append(pop)
 
455
            y = y + 1
 
456
 
 
457
        self.parent.ToolBarList = ToolBarList
 
458
 
 
459
        if self.parent.hasToolBar:
 
460
            if self.parent.toolbar is not None:
 
461
                self.parent.SetToolBar(None)
 
462
 
 
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()
 
466
 
 
467
            if self.parent.prefs.iconsize > 0:
 
468
                self.parent.SetToolBar(self.parent.toolbar)
 
469
 
 
470
            thereisafile = (len(self.parent.txtDocument.filename) > 0)
 
471
            self.parent.toolbar.EnableTool(self.parent.ID_RELOAD, thereisafile)
 
472
 
 
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)
 
478
            else:
 
479
                self.parent.toolbar.EnableTool(self.parent.ID_PYTHON, False)
 
480
                self.parent.toolbar.EnableTool(self.parent.ID_END, True)
 
481
                if thereisafile:
 
482
                    self.parent.toolbar.EnableTool(self.parent.ID_RUN, False)
 
483
                    self.parent.toolbar.EnableTool(self.parent.ID_SET_ARGS, False)
 
484
 
 
485
        try:
 
486
            f = file(toolbarfile, 'w')
 
487
            f.write(toolbaritemsstring)
 
488
            f.close()
 
489
        except IOError:
 
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")
 
491
            return
 
492
        if self.parent.prefs.enablefeedback:
 
493
            drScrolledMessageDialog.ShowMessage(self, msg, "Saved ToolBar")
 
494
 
 
495
    def OnList(self, event):
 
496
        sel = self.cboList.GetSelection()
 
497
 
 
498
        self.programmenu.Set(self.ListArray[sel])
 
499
 
 
500
    def OnSelect(self, event):
 
501
        #Take one away for "Insert Separator"
 
502
        seltext = self.programmenu.GetStringSelection()
 
503
 
 
504
        if seltext in self.customNames:
 
505
            i = self.customNames.index(seltext)
 
506
            if self.customFiles16[i]:
 
507
                self.txt16.SetValue(self.customFiles16[i])
 
508
            else:
 
509
                self.txt16.SetValue("<Default>")
 
510
            if self.customFiles24[i]:
 
511
                self.txt24.SetValue(self.customFiles24[i])
 
512
            else:
 
513
                self.txt24.SetValue("<Default>")
 
514
        else:
 
515
            self.txt16.SetValue("<Default>")
 
516
            self.txt24.SetValue("<Default>")
 
 
b'\\ No newline at end of file'