1 |
# |
# |
|
# Copyright 2001 Free Software Foundation |
|
|
# |
|
2 |
# This file is part of GNU Enterprise. |
# This file is part of GNU Enterprise. |
3 |
# |
# |
4 |
# GNU Enterprise is free software; you can redistribute it |
# GNU Enterprise is free software; you can redistribute it |
16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
|
# Copyright 2001-2002 Free Software Foundation |
20 |
|
# |
21 |
# FILE: |
# FILE: |
22 |
# LayoutEditor.py |
# LayoutEditor.py |
23 |
# |
# |
29 |
from wxPython.wx import * |
from wxPython.wx import * |
30 |
from gnue.common import GDebug, GConfig |
from gnue.common import GDebug, GConfig |
31 |
|
|
32 |
|
from gnue.common.events import Event, EventAware |
33 |
|
|
34 |
iconlocation = GConfig.getInstalledBase('designer_images','common_images') + '/' |
iconlocation = GConfig.getInstalledBase('designer_images','common_images') + '/' |
35 |
|
|
36 |
|
|
37 |
|
ToolbarMapping = 'File|New|Form,tb_new.png;' \ |
38 |
|
+ 'File|Save,tb_save.png;' \ |
39 |
|
+ ';' \ |
40 |
|
+ 'Tools|Insert|Label,deslay_label.png;' \ |
41 |
|
+ 'Tools|Insert|Unbound Entry,deslay_entrytext.png;' \ |
42 |
|
+ 'Tools|Insert|Drop Down Entry,deslay_entrydrop.png;' \ |
43 |
|
+ 'Tools|Insert|Button,deslay_button.png;' \ |
44 |
|
+ 'Tools|Insert|Box,deslay_box.png' |
45 |
|
|
46 |
|
# + 'File|Open,tb_open.png;' \ |
47 |
|
|
48 |
|
|
49 |
class LayoutEditorTools(wxToolBar): |
class LayoutEditorTools(wxToolBar, EventAware): |
50 |
|
|
51 |
def __init__(self, editor, frame): |
def __init__(self, editor, frame): |
52 |
self.editor = editor |
self.editor = editor |
53 |
wxToolBar.__init__(self, frame, -1)#, style=wxTB_DOCKABLE) |
wxToolBar.__init__(self, frame, -1)#, style=wxTB_DOCKABLE) |
54 |
|
EventAware.__init__(self, editor._instance) |
55 |
|
self.registerEventListeners( {'BeginWizard' : self.onBeginWizard, |
56 |
|
'EndWizard' : self.onEndWizard, |
57 |
|
'MakeDirty' : self.onDirtyForm, |
58 |
|
'MakeClean' : self.onCleanForm, } ) |
59 |
|
|
60 |
|
|
61 |
self.mapping = {} |
self.mapping = {} |
62 |
self.SetToolBitmapSize(wxSize(32,32)) |
self.SetToolBitmapSize(wxSize(32,32)) |
|
|
|
|
for type in ( ('label','label'),('box','box'),('button','button'), |
|
|
('scrollbar','scrollbar'),('entrytext','text entry'), |
|
|
('entrynum','numeric entry'), |
|
|
('entrydate','date/time entry'), |
|
|
('entrydrop','dropdown-style entry'), |
|
|
('entrycheck','checkbox-style entry') ): |
|
|
|
|
|
handle, descr = type |
|
|
|
|
|
id = wxNewId() |
|
|
self.mapping[id] = type |
|
|
self.mapping[handle] = id |
|
|
|
|
|
self.AddTool(id, |
|
|
wxImage(os.path.join(iconlocation,'deslay_%s.png'%handle), |
|
|
wxBITMAP_TYPE_PNG).ConvertToBitmap(), |
|
|
isToggle=1, |
|
|
shortHelpString="Create a new %s" % descr, |
|
|
longHelpString="Create a new %s" % descr) |
|
63 |
|
|
64 |
self.SetToolClientData(id, type) |
for type in string.split(ToolbarMapping,';'): |
65 |
|
if not len(type): |
66 |
|
self.AddSeparator() |
67 |
|
else: |
68 |
|
handle, image = string.split(type,',',1) |
69 |
|
help = self.editor._instance._menubar.getEventHelp(handle) |
70 |
|
|
71 |
|
if not help: |
72 |
|
print "Warning: No event tied to %s" % handle |
73 |
|
help = "" |
74 |
|
|
75 |
|
id = wxNewId() |
76 |
|
self.mapping[id] = handle |
77 |
|
self.mapping[handle] = id |
78 |
|
|
79 |
|
self.AddTool(id, |
80 |
|
wxImage(os.path.join(iconlocation,image), |
81 |
|
wxBITMAP_TYPE_PNG).ConvertToBitmap(), |
82 |
|
isToggle=1, |
83 |
|
shortHelpString=help, |
84 |
|
longHelpString=help) |
85 |
|
|
86 |
EVT_TOOL(self, id, self.OnButtonSelected) |
self.SetToolClientData(id, handle) |
87 |
|
|
88 |
wxToolBar.Realize(self) |
EVT_TOOL(self, id, self.OnButtonSelected) |
89 |
|
|
90 |
|
wxToolBar.Realize(self) |
91 |
|
|
92 |
def resetTool(self, mode): |
def resetTool(self, mode): |
93 |
if self.mapping.has_key(mode): |
if self.mapping.has_key(mode): |
95 |
|
|
96 |
|
|
97 |
def OnButtonSelected(self, event): |
def OnButtonSelected(self, event): |
98 |
handle, descr = self.mapping[event.GetId()] |
self.ToggleTool(event.GetId(),0) |
99 |
|
handle = self.mapping[event.GetId()] |
100 |
if self.editor.mode == handle: |
self.editor._instance._menubar.simulateMenuEvent(handle) |
101 |
self.editor.mode = 'move' |
|
102 |
else: |
## if self.editor.mode == handle: |
103 |
self.resetTool(self.editor.mode) |
## self.editor.mode = 'move' |
104 |
self.editor.mode = handle |
## else: |
105 |
|
## self.resetTool(self.editor.mode) |
106 |
self.editor.frame.SetStatusText('Click on the gridded Layout ' |
## self.editor.mode = handle |
107 |
'Editor to create a new %s.' % descr) |
|
108 |
|
## self.editor.frame.SetStatusText('Click on the gridded Layout ' |
109 |
|
## 'Editor to create a new %s.' % descr) |
110 |
|
|
111 |
|
def onBeginWizard(self, event): |
112 |
|
try: |
113 |
|
self.ToggleTool(self.mapping[event.template['Location']],1) |
114 |
|
except KeyError: |
115 |
|
pass |
116 |
|
|
117 |
|
def onEndWizard(self, event): |
118 |
|
try: |
119 |
|
self.ToggleTool(self.mapping[event.template['Location']],0) |
120 |
|
except KeyError: |
121 |
|
pass |
122 |
|
|
123 |
|
def onDirtyForm(self, event): |
124 |
|
try: |
125 |
|
self.EnableTool(self.mapping['File|Save'],1) |
126 |
|
except KeyError: |
127 |
|
pass |
128 |
|
|
129 |
|
|
130 |
|
def onCleanForm(self, event): |
131 |
|
try: |
132 |
|
self.EnableTool(self.mapping['File|Save'],0) |
133 |
|
except KeyError: |
134 |
|
pass |