commit-gnue
[Top][All Lists]
Advanced

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

gnue/gnuef/designer/src GFDesigner.py


From: Jason Cater
Subject: gnue/gnuef/designer/src GFDesigner.py
Date: Sun, 10 Jun 2001 22:17:11 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/06/10 22:17:11

Modified files:
        gnuef/designer/src: GFDesigner.py 

Log message:
        Designer can now preview the form.  Check it out... it's pretty cool!

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/designer/src/GFDesigner.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: gnue/gnuef/designer/src/GFDesigner.py
diff -u gnue/gnuef/designer/src/GFDesigner.py:1.5 
gnue/gnuef/designer/src/GFDesigner.py:1.6
--- gnue/gnuef/designer/src/GFDesigner.py:1.5   Sun Jun 10 14:57:52 2001
+++ gnue/gnuef/designer/src/GFDesigner.py       Sun Jun 10 22:17:11 2001
@@ -27,9 +27,9 @@
 
 import sys, os, time
 from wxPython.wx import *
-from gnue.common import GDebug
+from gnue.common import GDebug, GConfig
 from gnue.common.GClientApp import GClientApp
-from gnue.forms import GFForm, GFInstance, GFParser
+from gnue.forms import GFForm, GFInstance, GFParser, GFObjects, GFTrigger, 
GFLibrary, UIwxpython
 from GFDDebug import DebugSession
 
 ID_NEW = 101
@@ -86,9 +86,12 @@
     GFDInstance(self, None)
  
   def OnOpen(self, event): 
-    dlg = wxFileDialog(NULL)
-    dlg.SetStyle(wxOPEN)
-    dlg.SetWildcard("*.gfd")
+
+    dlg = wxFileDialog(NULL, "Open GNUe Form...", defaultDir=os.getcwd(),
+                           wildcard = "GNUe Form Definitions (*.gfd)|*.gfd|" +\
+                                      "GNUe Form Libraries (*.gfl)|*.gfl|" +\
+                                      "All Files (*.*)|*.*",
+                           style=wxOPEN)
     if dlg.ShowModal() == wxID_OK:
       GFDInstance(self, dlg.GetPath()) 
     dlg.Destroy()
@@ -159,9 +162,18 @@
     self.nameMappings = {}
     app.addInstance(self) 
 
+    self._pages = []
+
+    self.widgets = UIwxpython.WIDGETS
+
     if location == None: 
       self._path = ""
       self._form = GFForm.GFForm()
+      options = GFObjects.GFOptions(self._form)
+      GFObjects.GFOption(options, "title","Untitled Form")
+      GFObjects.GFOption(options, "height","12")
+      GFObjects.GFOption(options, "width","40")
+      GFObjects.GFPage(self._form)
       self.SetTitle (TITLE + " - Untitled Form")
     else: 
       self._path = location
@@ -176,16 +188,16 @@
     self.Show(true)
 
     # Split Plane
-#    hsplitter = wxSplitterWindow (self, -1, style=wxSP_3D|wxNO_3D)
-#    hsplitter.SetMinimumPaneSize (1)
+    vsplitter = wxSplitterWindow (self, -1, style=wxSP_3D|wxNO_3D)
+    vsplitter.SetMinimumPaneSize (100)
+
+    hsplitter = wxSplitterWindow (vsplitter, -1, style=wxSP_3D|wxNO_3D)
+    hsplitter.SetMinimumPaneSize (100)
 
-#    vsplitter = wxSplitterWindow (hsplitter, -1, style=wxSP_3D|wxNO_3D)
-#    vsplitter.SetMinimumPaneSize (1)
 
     # Create tree
     tID = wxNewId()
-#    self.tree = wxTreeCtrl (hsplitter, tID, style=wxTR_HAS_BUTTONS |
-    self.tree = wxTreeCtrl (self, tID, style=wxTR_HAS_BUTTONS |
+    self.tree = wxTreeCtrl (hsplitter, tID, style=wxTR_HAS_BUTTONS |
                                                  wxTR_EDIT_LABELS |
                                         wxTR_HAS_VARIABLE_ROW_HEIGHT)
 
@@ -193,24 +205,94 @@
     EVT_TREE_END_LABEL_EDIT(self.tree, tID, self.OnTreeLabelEditEnd)
     EVT_TREE_ITEM_ACTIVATED(self.tree, tID, self.OnTreeItemActivated)
 
-#    self.editor = wxTextCtrl(vsplitter, -1, style=wxTE_MULTILINE)
-#    self.editor.Enable (0)
+    self.editor = wxTextCtrl(hsplitter, -1, style = wxTE_MULTILINE)
 
-#    self.editor2 = wxTextCtrl(vsplitter, -1, style=wxTE_MULTILINE)
-#    self.editor2.Enable (0)
+    self.previewPane = wxScrolledWindow(vsplitter, -1, style=wxHSCROLL | 
wxVSCROLL)
+    self.previewPane.SetBackgroundColour(wxWHITE)
 
-#    vsplitter.SplitVertically (self.tree, self.editor)
-#    vsplitter.SetSashPosition (180, true)
 
 
     self._form._treeItem = self.tree.AddRoot("Form")
+    self._form._treeItemFormProperties = \
+        self.tree.AppendItem(self._form._treeItem, "Properties")
+    self._form._treeItemImportedLibraries = \
+        self.tree.AppendItem(self._form._treeItem, "Imported Libraries")
+    self._form._treeItemDataSources = \
+        self.tree.AppendItem(self._form._treeItem, "Data Sources")
+    self._form._treeItemNamedTriggers = \
+        self.tree.AppendItem(self._form._treeItem, "Shared Triggers")
+    self._form._treeItemPageLayout = \
+        self.tree.AppendItem(self._form._treeItem, "Page Layout")
 
     self._form.walk(self.inventoryLoadedItems)
 
+    self._pageList = []
+
+    self._currentPage = self._pages[0]
+    hsplitter.SplitHorizontally (self.tree, self.editor)
+    vsplitter.SplitVertically(hsplitter, self.previewPane)
+    vsplitter.SetSashPosition (180, true)
+    self.vsplitter = vsplitter
+    self.pageNameLabel = wxStaticText(self.previewPane, -1, "Page: ", 
pos=wxPoint(10,20))
+    self.drawPage(self._currentPage)
+    hsplitter.SetSashPosition (360, true)
     self.tree.Expand(self._form._treeItem)
     self.Refresh()
 
+
+  def drawPage(self, page): 
+
+    self.panel = wxSashWindow(self.previewPane, -1, pos=wxPoint(10,60))
+    self.pageNameLabel.SetLabel("Page: %s" % page.name)
+
+    UIwxpython.initFont(self.panel)
+
+    maxWidth, maxHeight, maxDescent, maxLeading = [0,0,0,0]
+
+    # need to add string.punctionation if we dump python 1.5.2
+    checkchars = string.letters+string.digits+"-\|"
+    for letter in checkchars:   
+      width,height,descent,leading = self.panel.GetFullTextExtent(letter)
+      maxWidth = maxWidth > width and maxWidth or width
+      maxHeight = maxHeight > height and maxHeight or height
+      maxDescent = maxDescent > descent and maxDescent or descent
+      maxLeading = maxLeading > leading and maxLeading or leading
+
+    self.charWidth = maxWidth+maxLeading
+    self.charHeight = maxHeight+maxDescent
+    
+    self.borderPercentage = (int(GConfig.get('borderPercentage')) / 100.0)
+    self.textPercentage = (int(GConfig.get('textPercentage')) / 100.0)
+
+    width = int(self._form.getOption('width'))
+    height = int(self._form.getOption('height'))
+
+    self.widgetWidth = (self.charWidth * self.borderPercentage)
+    self.widgetHeight = (self.charHeight * self.borderPercentage) + 3
+    self.textWidth = self.charWidth * self.textPercentage
+    self.textHeight = self.charHeight * self.textPercentage
+
+    self.menu_sb_space=0 # the extra spaces needed by the menu, toolbar and 
statusbar    
+
+    self.panel.SetSize(wxSize(int(width)*int(self.widgetWidth), 
+                       int(height)*int(self.widgetHeight)))
+
+    page.walk(self.__drawItem)
+
+
+  def __drawItem(self, object): 
+    if self.widgets.has_key(object.getObjectType()): 
+      print self.widgets[object.getObjectType()]
+      object._widget = self.widgets[object.getObjectType()]\
+         (object,self.panel, self.textWidth, self.textHeight, \
+          self.widgetWidth, self.widgetHeight, self,initialize=0)
+      object._widget._object = object
+
+  def uiEventTrap(self, event): 
+    pass
+
   def inventoryLoadedItems (self, object): 
+
     if object != self._form: 
       
       if hasattr(object, 'name') and \
@@ -218,9 +300,31 @@
           object.name[:3] == "__<" and \
           object.name[-3:] == ">__")): 
         object.name = self.getNextGenericName(object.getObjectType()[2:])
-      object._treeItem = self.tree.AppendItem(object._parent._treeItem, 
-          "%s" % object.getDescription())
 
+      if isinstance(object, GFObjects.GFOptions) and \
+         object._parent == self._form: 
+        object._treeItem = self._form._treeItemFormProperties
+      else: 
+        parentTreeItem = object._parent._treeItem
+        if isinstance(object, GFTrigger.GFTrigger) and \
+           object.type == 'NAMED': 
+          parentTreeItem = self._form._treeItemNamedTriggers
+        elif isinstance(object, GFTrigger.GFTrigger):
+          parentTreeItem = object._parent._treeItemTrigger
+        elif isinstance(object, GFObjects.GFDataSource): 
+          parentTreeItem = self._form._treeItemDataSources
+        elif isinstance(object, GFObjects.GFPage) and \
+             object._parent == self._form: 
+          self._pages.append(object)
+          parentTreeItem = self._form._treeItemPageLayout
+        object._treeItem = self.tree.AppendItem(parentTreeItem, 
+            "%s" % object.getDescription())
+
+    if isinstance (object, GFTrigger.GFTriggerAware): 
+      object._treeItemTrigger = \
+        self.tree.AppendItem(object._treeItem, "Events")
+
+
   def getNextGenericName (self, type): 
     while 1: 
       if self._lastGenericNameSeq.has_key(string.lower(type)): 
@@ -251,9 +355,52 @@
       if fileHandle2 != None: 
         fileHandle.close()
 
+    options = []
+    imports = []
+    datasources = []
+    triggers = []
+    pages = []
+    other = []
+
+    for child in self._form._children: 
+      if isinstance(child, GFObjects.GFOptions): 
+        options.append(child)
+      elif isinstance(child, GFLibrary.GFImport): 
+        imports.append(child)
+      elif isinstance(child, GFObjects.GFDataSource) or \
+        (isinstance(child, GFLibrary.GFImportItem) and 
+         child._type == 'GFimport-datasource'): 
+        datasources.append(child)
+      elif isinstance(child, GFTrigger.GFTrigger) or \
+        (isinstance(child, GFLibrary.GFImportItem) and 
+         child._type == 'GFimport-trigger'): 
+        triggers.append(child)
+      elif isinstance(child, GFObjects.GFPage) or \
+        (isinstance(child, GFImportItem) and 
+         child._type == 'GFimport-page'): 
+        pages.append(child)
+      else: 
+        other.append(child)
+
+
+    # Reorder the children so items of same class are grouped 
+    self._form._children = []
+    for child in options: 
+      self._form._children.append(child)
+    for child in imports: 
+      self._form._children.append(child)
+    for child in datasources: 
+      self._form._children.append(child)
+    for child in triggers: 
+      self._form._children.append(child)
+    for child in pages: 
+      self._form._children.append(child)
+    for child in other: 
+      self._form._children.append(child)
+
     fileHandle = open(location,'w')
     fileHandle.write('<?xml version="1.0"?>\n\n')
-    fileHandle.write('<!--  %s [version %s]\n      Form saved on: %s  -->\n\n' 
\
+    fileHandle.write('<!--  %s (%s)\n      Form saved on: %s  -->\n\n' \
        % (TITLE, VERSION, \
           time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))))
     fileHandle.write(self._form.dumpXML(treeDump=1))
@@ -310,6 +457,7 @@
 
   def __init__(self, instance): 
     DesignerToolFrame.__init__(self, instance, "Data Sources")
+
 
 #
 #



reply via email to

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