]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/tools/XRCed/tree.py
[1231183] 'cleanup: mismatched indentation' and other cleanings.
[wxWidgets.git] / wxPython / wx / tools / XRCed / tree.py
index cb68fa49a64c5abf66c71d4616a432595b928786..0a4d4d0638509fc0d790d0dfbd8d371c950c60cf 100644 (file)
@@ -19,7 +19,15 @@ class MemoryFile:
         self.name = name
         self.buffer = ''
     def write(self, data):
-        self.buffer += data.encode(g.currentEncoding)
+        if g.currentEncoding:
+            encoding = g.currentEncoding
+        else:
+            encoding = wxGetDefaultPyEncoding()
+        try:
+            self.buffer += data.encode(encoding)
+        except UnicodeEncodeError:
+            self.buffer += data.encode(encoding, 'xmlcharrefreplace')
+            
     def close(self):
         wxMemoryFSHandler_AddFile(self.name, self.buffer)
 
@@ -99,12 +107,25 @@ class ID_NEW:
     MENU = wxNewId()
     MENU_ITEM = wxNewId()
     SEPARATOR = wxNewId()
+
+    OK_BUTTON = wxNewId()
+    YES_BUTTON = wxNewId()
+    SAVE_BUTTON = wxNewId()
+    APPLY_BUTTON = wxNewId()
+    NO_BUTTON = wxNewId()
+    CANCEL_BUTTON = wxNewId()
+    HELP_BUTTON = wxNewId()
+    CONTEXT_HELP_BUTTON = wxNewId()
+
     LAST = wxNewId()
 
+    
+
 class PullDownMenu:
     ID_EXPAND = wxNewId()
     ID_COLLAPSE = wxNewId()
     ID_PASTE_SIBLING = wxNewId()
+    ID_TOOL_PASTE = wxNewId()
     ID_SUBCLASS = wxNewId()
 
     def __init__(self, parent):
@@ -173,6 +194,15 @@ class PullDownMenu:
             ID_NEW.STD_DIALOG_BUTTON_SIZER: 'wxStdDialogButtonSizer',
             ID_NEW.SPACER: 'spacer',
             ID_NEW.UNKNOWN: 'unknown',
+
+            ID_NEW.OK_BUTTON: 'wxButton',
+            ID_NEW.YES_BUTTON: 'wxButton',
+            ID_NEW.SAVE_BUTTON: 'wxButton',
+            ID_NEW.APPLY_BUTTON: 'wxButton',
+            ID_NEW.NO_BUTTON: 'wxButton',
+            ID_NEW.CANCEL_BUTTON: 'wxButton',
+            ID_NEW.HELP_BUTTON: 'wxButton',
+            ID_NEW.CONTEXT_HELP_BUTTON: 'wxButton',
             }
         self.topLevel = [
             (ID_NEW.PANEL, 'Panel', 'Create panel'),
@@ -295,33 +325,45 @@ class PullDownMenu:
              (ID_NEW.LIST_BOX, 'ListBox', 'Create list box'),
              ],
             ]
+        self.stdButtons = [
+            (ID_NEW.OK_BUTTON, 'OK Button', 'Create standard button'),
+            (ID_NEW.YES_BUTTON, 'YES Button', 'Create standard button'),
+            (ID_NEW.SAVE_BUTTON, 'SAVE Button',  'Create standard button'),
+            (ID_NEW.APPLY_BUTTON, 'APPLY Button',  'Create standard button'),
+            (ID_NEW.NO_BUTTON, 'NO Button',  'Create standard button'),
+            (ID_NEW.CANCEL_BUTTON, 'CANCEL Button',  'Create standard button'),
+            (ID_NEW.HELP_BUTTON, 'HELP Button',  'Create standard button'),
+            (ID_NEW.CONTEXT_HELP_BUTTON, 'CONTEXT HELP Button', 'Create standard button'),
+            ]
+        self.stdButtonIDs = {
+            ID_NEW.OK_BUTTON: ('wxID_OK', '&Ok'),
+            ID_NEW.YES_BUTTON: ('wxID_YES', '&Yes'),
+            ID_NEW.SAVE_BUTTON: ('wxID_SAVE', '&Save'),
+            ID_NEW.APPLY_BUTTON: ('wxID_APPLY', '&Apply'),
+            ID_NEW.NO_BUTTON: ('wxID_NO', '&No'),
+            ID_NEW.CANCEL_BUTTON: ('wxID_CANCEL', '&Cancel'),
+            ID_NEW.HELP_BUTTON: ('wxID_HELP', '&Help'),
+            ID_NEW.CONTEXT_HELP_BUTTON: ('wxID_CONTEXT_HELP', '&Help'),
+            }
+            
+
 
 ################################################################################
 
 # Set menu to list items.
 # Each menu command is a tuple (id, label, help)
 # submenus are lists [id, label, help, submenu]
-# and separators are any other type
-def SetMenu(m, list):
-    for l in list:
-        if type(l) == types.TupleType:
-            apply(m.Append, l)
-        elif type(l) == types.ListType:
-            subMenu = wxMenu()
-            SetMenu(subMenu, l[2:])
-            m.AppendMenu(wxNewId(), l[0], subMenu, l[1])
-        else:                           # separator
-            m.AppendSeparator()
-# Same, but adds 1000 to all IDs
-def SetMenu2(m, list):
+# and separators are any other type. Shift is for making
+# alternative sets of IDs. (+1000).
+def SetMenu(m, list, shift=False):
     for l in list:
         if type(l) == types.TupleType:
             # Shift ID
-            l = (1000 + l[0],) + l[1:]
+            if shift:  l = (1000 + l[0],) + l[1:]
             apply(m.Append, l)
         elif type(l) == types.ListType:
             subMenu = wxMenu()
-            SetMenu2(subMenu, l[2:])
+            SetMenu(subMenu, l[2:])
             m.AppendMenu(wxNewId(), l[0], subMenu, l[1])
         else:                           # separator
             m.AppendSeparator()
@@ -354,6 +396,8 @@ class HighLightBox:
     def Remove(self):
         map(wxWindow.Destroy, self.lines)
         g.testWin.highLight = None
+    def Refresh(self):
+        map(wxWindow.Refresh, self.lines)
 
 ################################################################################
 
@@ -531,12 +575,12 @@ class XML_Tree(wxTreeCtrl):
         self.selection = None
         return node
     # Find position relative to the top-level window
-    def FindNodePos(self, item):
+    def FindNodePos(self, item, obj=None):
         # Root at (0,0)
         if item == g.testWin.item: return wxPoint(0, 0)
         itemParent = self.GetItemParent(item)
         # Select NB page
-        obj = self.FindNodeObject(item)
+        if not obj: obj = self.FindNodeObject(item)
         if self.GetPyData(itemParent).treeObject().__class__ == xxxNotebook:
             notebook = self.FindNodeObject(itemParent)
             # Find position
@@ -573,6 +617,15 @@ class XML_Tree(wxTreeCtrl):
         # Top-level sizer? return window's sizer
         if xxx.isSizer and isinstance(parentWin, wxWindow):
             return parentWin.GetSizer()
+        elif isinstance(xxx.parent, xxxToolBar):
+            # How to get tool from toolbar?
+            return parentWin.GetChildren()[0]
+        elif isinstance(xxx.parent, xxxStdDialogButtonSizer):
+            # This sizer returns non-existing children
+            for ch in parentWin.GetChildren():
+                if ch.GetWindow() and ch.GetWindow().GetName() == xxx.name:
+                    return ch.GetWindow()
+            return None
         # Otherwise get parent's object and it's child
         child = parentWin.GetChildren()[self.ItemIndex(item)]
         # Return window or sizer for sizer items
@@ -616,7 +669,7 @@ class XML_Tree(wxTreeCtrl):
         g.panel.SetData(xxx)
         # Update tools
         g.tools.UpdateUI()
-        # Hightlighting is done in OnIdle
+        # Highlighting is done in OnIdle
         self.pendingHighLight = self.selection
 
     # Check if item is in testWin subtree
@@ -639,14 +692,17 @@ class XML_Tree(wxTreeCtrl):
             if g.testWin.highLight: g.testWin.highLight.Remove()
             return
         # Get window/sizer object
-        obj, pos = self.FindNodeObject(item), self.FindNodePos(item)
+        obj = self.FindNodeObject(item)
+        if not obj: return
+        pos = self.FindNodePos(item, obj)
         size = obj.GetSize()
         # Highlight
-        # Nagative positions are not working wuite well
+        # Negative positions are not working quite well
         if g.testWin.highLight:
             g.testWin.highLight.Replace(pos, size)
         else:
             g.testWin.highLight = HighLightBox(pos, size)
+        g.testWin.highLight.Refresh()
         g.testWin.highLight.item = item
 
     def ShowTestWindow(self, item):
@@ -663,7 +719,7 @@ class XML_Tree(wxTreeCtrl):
         if g.testWin:     # Reset old
             self.SetItemBold(g.testWin.item, False)
         self.CreateTestWin(item)
-        # Maybe an error occured, so we need to test
+        # Maybe an error occurred, so we need to test
         if g.testWin: self.SetItemBold(g.testWin.item)
 
     # Double-click on Linux
@@ -768,7 +824,7 @@ class XML_Tree(wxTreeCtrl):
         memFile.close()                 # write to wxMemoryFS
         xmlFlags = wxXRC_NO_SUBCLASSING
         # Use translations if encoding is not specified
-        if g.currentEncoding == 'ascii':
+        if not g.currentEncoding:
             xmlFlags != wxXRC_USE_LOCALE
         res = wxXmlResource('', xmlFlags)
         res.Load('memory:xxx.xrc')
@@ -874,7 +930,7 @@ class XML_Tree(wxTreeCtrl):
     def CloseTestWindow(self):
         if not g.testWin: return
         self.SetItemBold(g.testWin.item, False)
-        g.frame.tb.ToggleTool(g.frame.ID_LOCATE_TOOL, False)
+        g.frame.tb.ToggleTool(g.frame.ID_TOOL_LOCATE, False)
         g.testWinPos = g.testWin.GetPosition()
         g.testWin.Destroy()
         g.testWin = None
@@ -953,6 +1009,8 @@ class XML_Tree(wxTreeCtrl):
                     SetMenu(m, pullDownMenu.toolBarControls)
                 elif xxx.__class__ in [xxxMenu, xxxMenuItem]:
                     SetMenu(m, pullDownMenu.menuControls)
+                elif xxx.__class__ == xxxStdDialogButtonSizer:
+                    SetMenu(m, pullDownMenu.stdButtons)
                 else:
                     SetMenu(m, pullDownMenu.controls)
                     if xxx.__class__ == xxxNotebook:
@@ -981,19 +1039,19 @@ class XML_Tree(wxTreeCtrl):
                 if xxx.__class__ == xxxMenuBar:
                     m.Append(1000 + ID_NEW.MENU, 'Menu', 'Create menu')
                 elif xxx.__class__ in [xxxMenu, xxxMenuItem]:
-                    SetMenu2(m, pullDownMenu.menuControls)
+                    SetMenu(m, pullDownMenu.menuControls, shift=True)
                 elif xxx.__class__ == xxxToolBar and \
                          self.GetItemParent(item) == self.root:
-                    SetMenu2(m, [])
+                    SetMenu(m, [], shift=True)
                 elif xxx.__class__ in [xxxFrame, xxxDialog, xxxPanel]:
-                    SetMenu2(m, [
+                    SetMenu(m, [
                         (ID_NEW.PANEL, 'Panel', 'Create panel'),
                         (ID_NEW.DIALOG, 'Dialog', 'Create dialog'),
-                        (ID_NEW.FRAME, 'Frame', 'Create frame')])
+                        (ID_NEW.FRAME, 'Frame', 'Create frame')], shift=True)
                 elif xxx.isSizer:
-                    SetMenu2(m, pullDownMenu.sizers)
+                    SetMenu(m, pullDownMenu.sizers, shift=True)
                 else:
-                    SetMenu2(m, pullDownMenu.controls)
+                    SetMenu(m, pullDownMenu.controls, shift=True)
                 id = wxNewId()
                 menu.AppendMenu(id, 'Replace With', m)
                 if not m.GetMenuItemCount(): menu.Enable(id, False)