/[papo]/gnue/designer/src/MenuBar.py
ViewVC logotype

Diff of /gnue/designer/src/MenuBar.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by charlie, Tue Aug 27 18:15:52 2002 UTC revision 1.5 by styxman, Fri Nov 8 16:46:03 2002 UTC
# Line 1  Line 1 
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
# Line 18  Line 16 
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  # MenuBar.py  # MenuBar.py
23  #  #
# Line 28  Line 28 
28  import sys, os, string  import sys, os, string
29  from wxPython.wx import *  from wxPython.wx import *
30  from gnue.common import GDebug  from gnue.common import GDebug
31  import Incubator, MRUManager  import MRUManager
32  from ToolSupport import SupportedTools  from ToolSupport import SupportedTools
33    
 # File menu  
 ID_NEW = wxNewId()  
 ID_OPEN = wxNewId()  
 ID_OPEN_RECENT = wxNewId()  
 ID_SAVE = wxNewId()  
 ID_SAVE_AS = wxNewId()  
 ID_SAVE_ALL = wxNewId()  
 ID_CONNECT = wxNewId()  
 ID_CLOSE = wxNewId()  
 ID_RELOAD = wxNewId()  
 ID_EXIT = wxNewId()  
   
 # FileNew menu  
 ID_NEW_FORM = wxNewId()  
 ID_NEW_REPORT = wxNewId()  
 ID_NEW_WIZARD = wxNewId()  
   
 # Edit menu  
 ID_CUT = wxNewId()  
 ID_COPY = wxNewId()  
 ID_PASTE = wxNewId()  
 ID_PASTE_SPECIAL = wxNewId()  
 ID_DELETE = wxNewId()  
   
 # Debug menu  
 ID_RUN = wxNewId()  
   
 # Help menu  
 ID_ABOUT = wxNewId()  
   
34  #  #
35  #  #
36  #  #
# Line 68  class MainMenuBar(wxMenuBar): Line 38  class MainMenuBar(wxMenuBar):
38    def __init__(self, frame):    def __init__(self, frame):
39       wxMenuBar.__init__(self)       wxMenuBar.__init__(self)
40    
41         # Keep track of user-installed + sys-installed wizards/tools
42         self._menuMappings = {}
43         self._eventMappings = {}
44    
45         # So we can honor the module's requested order for the tool menu
46         self._toolMenuOrder = []
47    
48       self._frame = frame       self._frame = frame
49    
50      def addWizardLocation(self, location, template):
51        #print "Adding %s" % location
52        wr = self._frame.wizardRunner(template,
53                                      string.split(location,'|')[-1],
54                                      self._frame)
55    
56        self._menuMappings[location] = wr
57    
58      # Called after all the addWizardLocation's have been run
59      def buildMenu(self):
60         frame = self._frame
61         # File menu
62         ID_NEW = wxNewId()
63         ID_OPEN = wxNewId()
64         ID_OPEN_RECENT = wxNewId()
65         ID_SAVE = wxNewId()
66         ID_SAVE_AS = wxNewId()
67         ID_SAVE_ALL = wxNewId()
68         ID_CONNECT = wxNewId()
69         ID_CLOSE = wxNewId()
70         ID_RELOAD = wxNewId()
71         ID_EXIT = wxNewId()
72    
73         # FileNew menu
74         ID_NEW_FORM = wxNewId()
75         ID_NEW_REPORT = wxNewId()
76         ID_NEW_WIZARD = wxNewId()
77    
78         # Edit menu
79         ID_CUT = wxNewId()
80         ID_COPY = wxNewId()
81         ID_PASTE = wxNewId()
82         ID_PASTE_SPECIAL = wxNewId()
83         ID_DELETE = wxNewId()
84    
85         # Project menu
86         ID_NEW_PROJECT = wxNewId()
87         ID_OPEN_PROJECT = wxNewId()
88    
89         # Debug menu
90         ID_RUN = wxNewId()
91    
92         # Help menu
93         ID_ABOUT = wxNewId()
94    
95    
96    
97       self._file = wxMenu()       self._file = wxMenu()
98       self._fileNew = wxMenu()       self._fileNew = wxMenu()
99       self._fileRecent = wxMenu()       self._fileRecent = wxMenu()
100       self._fileConnect = wxMenu()       self._fileConnect = wxMenu()
101    
102       self._file.AppendMenu(ID_NEW, "&New", self._fileNew,"Create a new object")       self._file.AppendMenu(ID_NEW, _("&New"), self._fileNew, _("Create a new object"))
103       self._file.Append(ID_OPEN, "&Open...", "Open an existing object")       self._file.Append(ID_OPEN, _("&Open..."), _("Open an existing object"))
104       self._file.AppendMenu(ID_OPEN_RECENT, "Open &Recent", self._fileRecent,       self._file.AppendMenu(ID_OPEN_RECENT, _("Open &Recent"), self._fileRecent,
105                             "Open an existing object")                             _("Open an existing object"))
106       self._file.AppendSeparator()       self._file.AppendSeparator()
107       self._file.Append(ID_SAVE, "&Save", "Save the current object")       self._file.Append(ID_SAVE, _("&Save"), _("Save the current object"))
108       self._file.Append(ID_SAVE_AS, "Save &As...",       self._file.Append(ID_SAVE_AS, _("Save &As..."),
109                         "Save the current form under a new name")                         _("Save the current form under a new name"))
110       self._file.Append(ID_SAVE_ALL, "Save A&ll",       self._file.Append(ID_SAVE_ALL, _("Save A&ll"),
111                         "Save all open objects")                         _("Save all open objects"))
112       self._file.AppendSeparator()       self._file.AppendSeparator()
113       self._file.AppendMenu(ID_CONNECT, "Connect &to", self._fileConnect,       self._file.AppendMenu(ID_CONNECT, _("Connect &to"), self._fileConnect,
114                             "Connect to a database")                             _("Connect to a database"))
115       self._file.AppendSeparator()       self._file.AppendSeparator()
116       self._file.Append(ID_RELOAD, "Reload",       self._file.Append(ID_RELOAD, _("Reload"),
117          "Reload the current object as of its last save (abandoning any changes)")          _("Reload the current object as of its last save (abandoning any changes)"))
118       self._file.AppendSeparator()       self._file.AppendSeparator()
119       self._file.Append(ID_CLOSE, "&Close", "Close the current object")       self._file.Append(ID_CLOSE, _("&Close"), _("Close the current object"))
120       self._file.AppendSeparator()       self._file.AppendSeparator()
121       self._file.Append(ID_EXIT, "E&xit", "Exit GNUe Designer")       self._file.Append(ID_EXIT, _("E&xit"), _("Exit GNUe Designer"))
   
122    
      EVT_MENU (frame, ID_NEW_WIZARD, frame._app.OnWizard)  
      EVT_MENU (frame, ID_OPEN, frame._app.OnOpen)  
      EVT_MENU (frame, ID_SAVE, frame.OnSave)  
      EVT_MENU (frame, ID_SAVE_AS, frame.OnSaveAs)  
      EVT_MENU (frame, ID_SAVE_ALL, frame._app.OnSaveAll)  
      EVT_MENU (frame, ID_CLOSE, frame.OnClose)  
      EVT_MENU (frame, ID_EXIT, frame._app.OnExit)  
123    
124         self.__addMenuEvent('File|New|Wizard', ID_NEW_WIZARD, frame._app.OnWizard)
125         self.__addMenuEvent('File|Open', ID_OPEN, frame._app.OnOpen)
126         self.__addMenuEvent('File|Save', ID_SAVE, frame.OnSave)
127         self.__addMenuEvent('File|Save As', ID_SAVE_AS, frame.OnSaveAs)
128         self.__addMenuEvent('File|Save All', ID_SAVE_ALL, frame._app.OnSaveAll)
129         self.__addMenuEvent('File|Close', ID_CLOSE, frame.OnClose)
130         self.__addMenuEvent('File|Exit', ID_EXIT, frame._app.OnExit)
131    
132       # Set up out MRU list       # Set up our MRU list
133       frame._app.mru.addMenu(self._fileRecent, frame)       frame._app.mru.addMenu(self._fileRecent, frame)
134    
135    
136       frame._fileNewMap = {}       frame._fileNewMap = {}
137       for tool in SupportedTools:       for tool in SupportedTools:
138         id = wxNewId()         id = wxNewId()
139         frame._fileNewMap[id] = tool         frame._fileNewMap[id] = tool.properties.module
140         self._fileNew.Append(id, '&%s' % tool.properties.nickname,         self._fileNew.Append(id, '&%s' % tool.properties.nickname,
141           'Create a new %s' % string.lower(tool.properties.nickname))           _('Create a new %s') % string.lower(tool.properties.nickname))
142         EVT_MENU (frame, id, frame.OnNew)         self.__addMenuEvent('File|New|%s' % tool.properties.nickname, id, frame.OnNew)
143    
144    
   
 ##     self._fileNew.Append(ID_NEW_FORM,'&Form', "Create a new form")  
 ##     self._fileNew.Append(ID_NEW_REPORT,'&Report', "Create a new report")  
145       self._fileNew.AppendSeparator()       self._fileNew.AppendSeparator()
146       self._fileNew.Append(ID_NEW_WIZARD,'from &Wizard...', \       self._fileNew.Append(ID_NEW_WIZARD,_('from &Wizard...'), \
147                            "Create a new object from a wizard")                            _("Create a new object from a wizard"))
148    
149       # Build a connection list       # Build a connection list
150       frame.connectionMap = {}       frame.connectionMap = {}
151       for conn in frame.connections.getAllConnectionParameters().keys():       for conn in frame.connections.getAllConnectionParameters().keys():
152         id = wxNewId()         id = wxNewId()
153         self._fileConnect.Append(id, conn, "Login to %s connection" % conn)         self._fileConnect.Append(id, conn, _("Login to %s connection") % conn)
154         frame.connectionMap[id] = conn         frame.connectionMap[id] = conn
155         EVT_MENU(frame, id, frame.OnConnectTo)         self.__addMenuEvent('File|Connect To|%s' % conn, id, frame.OnConnectTo)
156    
157    
158       self._file.Enable(ID_RELOAD,0)       self._file.Enable(ID_RELOAD,0)
159    
160       self._help = wxMenu()       self._help = wxMenu()
161       self._help.Append(ID_ABOUT, "&About...", "More information about GNUe Designer")       self._help.Append(ID_ABOUT, _("&About..."), _("More information about GNUe Designer"))
162       EVT_MENU (frame, ID_ABOUT, frame._app.OnAbout)       self.__addMenuEvent('Help|About', ID_ABOUT, frame._app.OnAbout)
163    
164       self._edit = wxMenu()       self._edit = wxMenu()
165       self._edit.Append(ID_CUT, "C&ut", "Cut the current object and move to the clipboard")       self._edit.Append(ID_CUT, _("C&ut"), _("Cut the current object and move to the clipboard"))
166       self._edit.Append(ID_COPY, "&Copy", "Copy the current object to the clipboard")       self._edit.Append(ID_COPY, _("&Copy"), _("Copy the current object to the clipboard"))
167       self._edit.Append(ID_PASTE, "&Paste", "Paste the current object on the clipboard")       self._edit.Append(ID_PASTE, _("&Paste"), _("Paste the current object on the clipboard"))
168       self._edit.Append(ID_PASTE_SPECIAL, "Paste &Special...", "Paste the current object on the clipboard with special attributes")       self._edit.Append(ID_PASTE_SPECIAL, _("Paste &Special..."), _("Paste the current object on the clipboard with special attributes"))
169       self._edit.AppendSeparator()       self._edit.AppendSeparator()
170       self._edit.Append(ID_DELETE, "&Delete", "Delete the current object")       self._edit.Append(ID_DELETE, _("&Delete"), _("Delete the current object"))
171    
172       # TODO: Implement clipboard       # TODO: Implement clipboard
173       self._edit.Enable(ID_CUT,0)       self._edit.Enable(ID_CUT,0)
# Line 155  class MainMenuBar(wxMenuBar): Line 176  class MainMenuBar(wxMenuBar):
176       self._edit.Enable(ID_PASTE_SPECIAL,0)       self._edit.Enable(ID_PASTE_SPECIAL,0)
177       self._edit.Enable(ID_DELETE,0)       self._edit.Enable(ID_DELETE,0)
178    
179       self._window = wxMenu()  
180         # TODO: Implement projects
181         self._project = wxMenu()
182    
183    
184         self._tools = wxMenu()
185         for location in self._toolMenuOrder:
186    
187           # Grab our ToolRunner (or WizardRunner if tool was replaced???)
188           # and delete the reference.
189           tool = self._menuMappings[location]
190           del self._menuMappings[location]
191    
192           menu = wxMenuItem(self._tools, tool.wxId, tool.title,
193                             tool.tooltip, tool.checkable)
194           tool.menu = menu
195           self._tools.AppendItem(menu)
196           self.__addMenuEvent('%s|%s' % (location, tool.title),
197                               tool.wxId, tool.run)
198           tool.finalize()
199    
200         self._tools.AppendSeparator()
201    
202    
203       self._debug = wxMenu()       self._debug = wxMenu()
204       self._debug.Append(ID_RUN, '&Run', "Run the current form")       self._debug.Append(ID_RUN, _('&Run'), _("Run the current form"))
205       EVT_MENU (frame, ID_RUN, frame.OnDebugRun)       self.__addMenuEvent('Debug|Run', ID_RUN, frame.OnDebugRun)
206    
207         menumap = { '': (self, {}),
208                     'File': (self._file,{}),
209                     'File|New': (self._fileNew,{}),
210                     'Edit': (self._edit,{}),
211                     'Project': (self._project,{}),
212                     'Debug': (self._debug,{}),
213                     'Tools': (self._tools,{}),
214                     'Help': (self._help, {})}
215    
216         basemenuorder = ['File','Edit','Debug','Project', 'Tools']
217    
218         for location in self._menuMappings.keys():
219           last = None
220           nav = string.split(location,'|')
221           partial = ""
222           lastpartial = ""
223           for loc in nav[:-1]:
224             lastpartial = partial
225             partial += (partial and '|' or "") + loc
226             if not menumap.has_key(partial):
227               menumap[partial] = (wxMenu(), {})
228               menumap[lastpartial][1][loc] = (1, menumap[partial][0])
229    
230           menumap[partial][1][nav[-1]] = (0, location)
231    
232    
233         # Add all the base menus first...
234         for name in basemenuorder:
235           self.Append(menumap[name][0], '&' + name)
236    
237    
238         # Next, add all the customizations
239         locsort = menumap.keys()
240         locsort.sort()
241         for location in locsort:
242           menu, submenus = menumap[location]
243           mm = submenus.keys()
244           mm.sort()
245           for menuitem in mm:
246             isMenu, data  = submenus[menuitem]
247             if isMenu:
248               # data is a wxMenu instance
249               menu.AppendMenu(wxNewId(), '&' + menuitem, data)
250             else:
251               # Data is a location pointer
252               wizard = self._menuMappings[data]
253               menu.Append(wizard.wxId, wizard.title, wizard.tooltip)
254               self.__addMenuEvent('%s|%s' % (location, wizard.title),
255                                   wizard.wxId, wizard.run)
256    
257    
258         # Add the Help menu
259         self.Append(menumap['Help'][0], '&Help')
260    
261    
262      def __createMenuStructure(location, data):
263        for loc, isMenu, data in menumap[name][1]:
264         if isMenu:
265           menu.AppendMenu(wxNewId(), "&%s" % loc, data)
266         else:
267           pass
268    
269    
270      def __addMenuEvent(self, location, wxId, method):
271        self._eventMappings[location] = (method, wxId)
272        EVT_MENU(self._frame, wxId, method)
273    
274    
275      def getEventHelp (self, location):
276        try:
277          wxId = self._eventMappings[location][1]
278          return self.GetHelpString(wxId)
279        except KeyError:
280          return None
281    
282    
283      def simulateMenuEvent(self, location):
284        method, id = self._eventMappings[location]
285        method(wxEvent(id))
286    
      self.Append(self._file, '&File')  
      self.Append(self._edit, '&Edit')  
      self.Append(self._debug, '&Debug')  
      self.Append(self._window, '&Window')  
      self.Append(self._help, '&Help')  
287    
288    
289    def addTool(self, toolFrame, title):    def addTool(self, toolFrame, title):
290        location = 'Tools|%s' % title
291        self._menuMappings[location] = ToolRunner(toolFrame, title)
292        self._toolMenuOrder.append(location)
293        return self._menuMappings[location]
294    
295    
296      #
297      # Convenience methods to make the main menu bar appear to be a menu container
298      #
299    
300      def AppendMenu(self, wxId, text, menu):
301        self.Append(menu, text)
302    
303    
     toolFrame._wxMenuID = wxNewId()  
     toolFrame._menu = wxMenuItem(self._window, toolFrame._wxMenuID,  
           '&%s' % title, "Show or hide the %s" % title, 1)  
     self._window.AppendItem(toolFrame._menu)  
     EVT_MENU(self._frame, toolFrame._wxMenuID, toolFrame.OnMenuSelected)  
304    
305    class ToolRunner:
306      def __init__(self, toolFrame, title):
307         self.toolFrame = toolFrame
308    
309    def lastToolAdded(self):       self.wxId = wxNewId()
310     self._window.AppendSeparator()       self.title = title
311         self.checkable = 1
312         self.tooltip = _("Show or hide the %s") % title
313    
314      def run(self, event):
315        self.toolFrame.OnMenuSelected(event)
316    
317      def finalize(self):
318        self.toolFrame.finalize()

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26