commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r9219 - trunk/gnue-navigator/src


From: reinhard
Subject: [gnue] r9219 - trunk/gnue-navigator/src
Date: Sat, 6 Jan 2007 10:33:08 -0600 (CST)

Author: reinhard
Date: 2007-01-06 10:33:07 -0600 (Sat, 06 Jan 2007)
New Revision: 9219

Added:
   trunk/gnue-navigator/src/UIwx26.py
Log:
Quickly hacked wx26 UIdriver for gnue-navigator.


Added: trunk/gnue-navigator/src/UIwx26.py
===================================================================
--- trunk/gnue-navigator/src/UIwx26.py  2007-01-05 21:17:07 UTC (rev 9218)
+++ trunk/gnue-navigator/src/UIwx26.py  2007-01-06 16:33:07 UTC (rev 9219)
@@ -0,0 +1,280 @@
+# GNU Enterprise Navigator - wx26 User Interface
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id: GFBlock.py 9214 2007-01-05 19:23:02Z reinhard $
+
+"""
+User interface driver for wxWidgets 2.6.
+"""
+
+import os
+import sys
+if not hasattr(sys, 'frozen'):
+    import wxversion
+    wxversion.ensureMinimal('2.6')
+
+from gnue.common.datasources import Exceptions
+from gnue.common.apps import GConfig
+
+from gnue.forms.GFInstance import GFInstance
+from gnue.forms.uidrivers import wx26 as ui
+
+from gnue.navigator import VERSION
+
+# Must import wx *after* importing wx26 uidriver from forms.
+import wx.html
+
+images_dir = GConfig.getInstalledBase('forms_images','common_images') + '/'
+
+class Instance:
+  def __init__(self, processes):
+    self.processes = processes
+    self._formInstances = {}
+    self._lastSerialNumber = 0
+
+    self.titlePage = """
+    <html>
+      <body>
+        <center>
+         <B>GNUe Navigator</B>
+         <p><img src="%s"></p>
+         <p>A part of the <a href="http://www.gnuenteprise.org/";>GNU 
Enterprise Project</a></p>
+        </center>
+      </body>
+    </html>
+    """ % (images_dir+"/ship2.png")
+
+  def run(self, connections):
+    #
+    # Assign the proper login handler based upon the user interface choice
+    #
+    self.connections = connections
+    self.connections.setLoginHandler(ui.UILoginHandler())
+
+    app = wx.GetApp() or wx.App()
+    self.frame = wx.Frame(None, -1, "GNUe Navigator", size=wx.Size(600,400))
+    self.frame.Bind(wx.EVT_CLOSE, self.__on_close)
+
+    self.menu = MenuBar(self)
+    self.frame.SetMenuBar(self.menu)
+
+    wx.EVT_MENU(self.frame, ID_EXIT,  self.__on_close)
+    wx.EVT_MENU(self.frame, ID_ABOUT, self.__on_about)
+
+    self.splitter= wx.SplitterWindow(self.frame,-1)
+
+    self.panel1 = wx.Window(self.splitter, -1)
+    self.panel2 = wx.Window(self.splitter, -1)
+
+    # Panel 1 contents
+    self.panel1.SetBackgroundColour(wx.WHITE)
+    self.tree = wx.TreeCtrl(self.panel1, -1)
+    self.processes.setClientHandlers({'form':self.runForm})
+
+    self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.__on_select, self.tree)
+    self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.__on_activate, self.tree)
+
+    self._mapping = {}
+    self.processes.walk(self.__buildTreeControl)
+
+    self.tree.Expand(self.processes.__node)
+
+    # Panel 2 contents
+    self.panel2.SetBackgroundColour(wx.WHITE)
+    self.helpText = wx.html.HtmlWindow(self.panel2, -1)
+    self.helpText.SetPage(self.titlePage)
+
+    wx.EVT_SIZE(self.panel1,self.__on_resize)
+    wx.EVT_SIZE(self.panel2,self.__on_resize)
+
+    self.frame.Show(True)
+
+    self.splitter.SetMinimumPaneSize(20)
+    self.splitter.SplitVertically(self.panel1, self.panel2)
+    self.splitter.SetSashPosition(200)
+
+    app.MainLoop()
+
+  def __on_resize(self,evt):
+    self.tree.SetSize(self.panel1.GetSize())
+    self.helpText.SetSize(self.panel2.GetSize())
+
+
+  def __buildTreeControl(self, object):
+
+    if object._type == 'GNProcesses':
+      node = self.tree.AddRoot(object.title)
+    elif object._type in ('GNStep','GNProcess'):
+      node = self.tree.AppendItem(object.getParent().__node, object.title)
+    else:
+      return
+
+    object.__node = node
+    self.tree.SetPyData(node, object)
+    self._mapping[object] = node
+
+
+  def __on_close(self, event):
+    self.frame.Destroy()
+
+  def __on_about(self, event):
+    text = _("GNUE Navigator")+"\n"+      \
+    _("  Version : ")+"%s\n"+         \
+    _("  Driver  : UIwxpython")+"\n"+ \
+    _("-= Process Info =-")+"\n"+        \
+    _("  Name   : ")+"%s\n"+          \
+    _("  Version: ")+"%s\n"+          \
+    _("  Author : ")+"%s\n"+          \
+    _("  Description:")+"%s\n"
+    dlg = wx.MessageDialog(self.frame,
+                          text % (VERSION,"","","",""),
+                          _("About"), wx.OK | wx.ICON_INFORMATION)
+    dlg.ShowModal()
+
+    dlg.Destroy()
+
+  def buildMenu(self, process):
+    self.tree.Expand(process.__node)
+    return 1
+
+
+  def __on_select(self, event):
+    object = self.tree.GetPyData(event.GetItem())
+    self.helpText.SetPage("")
+    for item in object._children:
+      if item._type == 'GNDescription':
+        self.helpText.SetPage(item.getChildrenAsContent())
+        break
+
+
+  def __on_activate(self, event):
+    object = self.tree.GetPyData(event.GetItem())
+
+    if object._type != 'GNStep':
+      self.buildMenu(object)
+    else:
+      object.run()
+
+
+  def handleError(self, mesg):
+    dlg = wx.MessageDialog(self.frame, "Error: %s!" % mesg, "Error", wx.OK)
+    dlg.ShowModal()
+    dlg.Destroy()
+
+  def runForm(self, step, parameters = {}):
+    # parameters are now part of the step in _params
+    
+    # This is the code executing in the new thread. Simulation of
+    # a long process (well, 10s here) as a simple loop - you will
+    # need to structure your processing so that you periodically
+    # peek at the abort variable
+
+    if os.path.basename(step.location) == step.location:
+      try:
+        formdir = gConfigNav('FormDir')
+      except KeyError:
+        formdir = ""
+      formfile = os.path.join (formdir, step.location)
+    else:
+      formfile = step.location
+
+    self._runForm(formfile, step._params)
+
+
+  def _runForm(self, formfile, parameters):
+
+    try:
+      #
+      # Create the instance
+      #
+      
+      #
+      # TODO: The next if looks funny because the code above results in
+      #
+      #  disable splash:  1 <type 'int'>
+      #  embed forms:  0 <type 'str'>
+      #
+      # And I don't have time to dig ATM
+      #
+      # FIXME: Embedding forms does not work.
+      # if gConfigNav('embedForms') == "%s" % True: 
+      if False:
+        instance = GFInstance(self,connections=self.connections,
+                              ui=ui,disableSplash=1, parameters=parameters,
+                              parentContainer=self.panel2)
+      else:
+        instance = GFInstance(id(self),
+           connections=self.connections,
+           ui=ui, disableSplash=1)
+
+      self._formInstances[id(self)] = instance
+
+      #
+      # Build the form tree
+      #
+      instance.addFormFromFile(formfile)
+
+      # Temp stuff to test embedding
+      self.panel2.SetTitle = self.setTitle
+      self.panel2.SetMenuBar = self.setMenuBar
+      self.panel2.SetToolBar = self.setToolBar
+
+      #
+      # Start the instance
+      #
+      #instance.addDialogs()
+
+      #instance.buildForm(form)
+      instance.activate()
+
+    except IOError, mesg:
+      self.handleError(_("Unable to open file\n\n     %s")%mesg)
+
+    except Exceptions.ConnectionError, mesg:
+      self.handleError(\
+         _("Error while communicating with datasource.\n\n       %s") %mesg)
+
+  def setTitle(self, title):
+    self.frame.SetTitle ("GNUe Navigator: %s (form)" % title )
+
+  def setMenuBar(self, *arg, **parm):
+    self.frame.SetMenuBar (*arg, **parm)
+
+  def setToolBar(self, *arg, **parm):
+    self.frame.SetToolBar (*arg, **parm)
+
+ID_EXIT = wx.NewId()
+ID_ABOUT = wx.NewId()
+
+class MenuBar(wx.MenuBar):
+  def __init__(self, frame):
+    wx.MenuBar.__init__(self)
+
+    self._frame = frame
+
+    self._menu = wx.Menu()
+    self._help = wx.Menu()
+
+    self._menu.Append(ID_EXIT, "E&xit", "Exit GNUe Designer")
+    self._help.Append(ID_ABOUT,'&About','About')
+
+    self.Append(self._menu,'&Menu')
+    self.Append(self._help,'&Help')





reply via email to

[Prev in Thread] Current Thread [Next in Thread]