From 22b3452638818155d9a818bdb8b809d939ee024e Mon Sep 17 00:00:00 2001 From: Roman Rolinsky Date: Thu, 10 Apr 2003 09:31:39 +0000 Subject: [PATCH] - changed encoding selection, removed -i option - replace command git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20117 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/wxPython/tools/XRCed/CHANGES.txt | 13 +++ wxPython/wxPython/tools/XRCed/globals.py | 3 +- wxPython/wxPython/tools/XRCed/params.py | 6 +- wxPython/wxPython/tools/XRCed/tree.py | 77 ++++++++++++++-- wxPython/wxPython/tools/XRCed/xrced.py | 102 ++++++++++++++++++++-- wxPython/wxPython/tools/XRCed/xxx.py | 9 +- 6 files changed, 182 insertions(+), 28 deletions(-) diff --git a/wxPython/wxPython/tools/XRCed/CHANGES.txt b/wxPython/wxPython/tools/XRCed/CHANGES.txt index 3945253906..f4304e4396 100644 --- a/wxPython/wxPython/tools/XRCed/CHANGES.txt +++ b/wxPython/wxPython/tools/XRCed/CHANGES.txt @@ -1,3 +1,16 @@ +0.1.1-1 +------- + +Changed internationalization support. '-i' option removed, default +encoding is used (should be defined in sitecustomize.py, or 'ascii' by +default). When XRC file is opened with encoding specified, +translations are not used. + +0.1.1 +----- + +Replace command added (not quite finished yet). + 0.1.0 ----- diff --git a/wxPython/wxPython/tools/XRCed/globals.py b/wxPython/wxPython/tools/XRCed/globals.py index a9147ae687..e40180220d 100644 --- a/wxPython/wxPython/tools/XRCed/globals.py +++ b/wxPython/wxPython/tools/XRCed/globals.py @@ -15,7 +15,7 @@ modernFont = wxFont(sysFont.GetPointSize(), wxMODERN, wxNORMAL, wxNORMAL) smallerFont = wxFont(sysFont.GetPointSize()-2, wxDEFAULT, wxNORMAL, wxNORMAL) progname = 'XRCed' -version = '0.1.0' +version = '0.1.1-1' try: True @@ -34,6 +34,5 @@ class Globals: testWin = None testWinPos = wxDefaultPosition currentXXX = None - xmlFlags = wxXRC_USE_LOCALE | wxXRC_NO_SUBCLASSING g = Globals() diff --git a/wxPython/wxPython/tools/XRCed/params.py b/wxPython/wxPython/tools/XRCed/params.py index a0c71474cf..5869b9a74d 100644 --- a/wxPython/wxPython/tools/XRCed/params.py +++ b/wxPython/wxPython/tools/XRCed/params.py @@ -140,9 +140,9 @@ class ParamColour(PPanel): self.SetBackgroundColour(g.panel.GetBackgroundColour()) sizer = wxBoxSizer() self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(65,-1)) - sizer.Add(self.text, 0, wxRIGHT, 5) - self.button = wxPanel(self, self.ID_BUTTON, wxDefaultPosition, wxSize(20, 20)) - sizer.Add(self.button, 0, wxGROW) + sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5) + self.button = wxPanel(self, self.ID_BUTTON, wxDefaultPosition, wxSize(20, -1)) + sizer.Add(self.button, 0, wxGROW | wxALIGN_CENTER_VERTICAL) self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) diff --git a/wxPython/wxPython/tools/XRCed/tree.py b/wxPython/wxPython/tools/XRCed/tree.py index 4036f5d249..9de7f6b026 100644 --- a/wxPython/wxPython/tools/XRCed/tree.py +++ b/wxPython/wxPython/tools/XRCed/tree.py @@ -84,7 +84,7 @@ class ID_NEW: MENU = wxNewId() MENU_ITEM = wxNewId() SEPARATOR = wxNewId() - LAST = wxNewId() + LAST = wxNewId() class PullDownMenu: ID_EXPAND = wxNewId() @@ -94,6 +94,7 @@ class PullDownMenu: def __init__(self, parent): self.ID_DELETE = parent.ID_DELETE EVT_MENU_RANGE(parent, ID_NEW.PANEL, ID_NEW.LAST, parent.OnCreate) + EVT_MENU_RANGE(parent, 1000 + ID_NEW.PANEL, 1000 + ID_NEW.LAST, parent.OnReplace) EVT_MENU(parent, self.ID_COLLAPSE, parent.OnCollapse) EVT_MENU(parent, self.ID_EXPAND, parent.OnExpand) EVT_MENU(parent, self.ID_PASTE_SIBLING, parent.OnPaste) @@ -148,6 +149,29 @@ class PullDownMenu: ID_NEW.SPACER: 'spacer', ID_NEW.UNKNOWN: 'unknown', } + self.topLevel = [ + (ID_NEW.PANEL, 'Panel', 'Create panel'), + (ID_NEW.DIALOG, 'Dialog', 'Create dialog'), + (ID_NEW.FRAME, 'Frame', 'Create frame'), + None, + (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'), + (ID_NEW.MENU_BAR, 'MenuBar', 'Create menubar'), + (ID_NEW.MENU, 'Menu', 'Create menu') + ] + self.containers = [ + (ID_NEW.PANEL, 'Panel', 'Create panel'), + (ID_NEW.NOTEBOOK, 'Notebook', 'Create notebook control'), + (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'), + ] + self.sizers = [ + (ID_NEW.BOX_SIZER, 'BoxSizer', 'Create box sizer'), + (ID_NEW.STATIC_BOX_SIZER, 'StaticBoxSizer', + 'Create static box sizer'), + (ID_NEW.GRID_SIZER, 'GridSizer', 'Create grid sizer'), + (ID_NEW.FLEX_GRID_SIZER, 'FlexGridSizer', + 'Create flexgrid sizer'), + (ID_NEW.SPACER, 'Spacer', 'Create spacer'), + ] self.controls = [ ['control', 'Various controls', (ID_NEW.STATIC_TEXT, 'Label', 'Create label'), @@ -246,6 +270,19 @@ def SetMenu(m, list): m.AppendMenu(wxNewId(), l[0], subMenu, l[1]) else: # separator m.AppendSeparator() +# Same, but adds 1000 to all IDs +def SetMenu2(m, list): + for l in list: + if type(l) == types.TupleType: + # Shift ID + l = (1000 + l[0],) + l[1:] + apply(m.Append, l) + elif type(l) == types.ListType: + subMenu = wxMenu() + SetMenu2(subMenu, l[2:]) + m.AppendMenu(wxNewId(), l[0], subMenu, l[1]) + else: # separator + m.AppendSeparator() ################################################################################ @@ -413,6 +450,7 @@ class XML_Tree(wxTreeCtrl): elif n.nodeType != minidom.Node.ELEMENT_NODE: treeObj.element.removeChild(n) n.unlink() + # Insert new item at specific position def InsertNode(self, itemParent, parent, elem, nextItem): # Insert in XML tree and wxWin @@ -640,7 +678,11 @@ class XML_Tree(wxTreeCtrl): else: elem.setAttribute('name', xxx.name) memFile.close() # write to wxMemoryFS - res = wxXmlResource('', g.xmlFlags) + xmlFlags = wxXRC_NO_SUBCLASSING + # Use translations if encoding is not specified + if xxx.currentEncoding == 'ascii': + xmlFlags != wxXRC_USE_LOCALE + res = wxXmlResource('', xmlFlags) res.Load('memory:xxx.xrc') if xxx.__class__ == xxxFrame: # Frame can't have many children, @@ -764,13 +806,7 @@ class XML_Tree(wxTreeCtrl): else: needInsert = self.NeedInsert(item) if item == self.root or needInsert and self.GetItemParent(item) == self.root: - m.Append(ID_NEW.PANEL, 'Panel', 'Create panel') - m.Append(ID_NEW.DIALOG, 'Dialog', 'Create dialog') - m.Append(ID_NEW.FRAME, 'Frame', 'Create frame') - m.AppendSeparator() - m.Append(ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar') - m.Append(ID_NEW.MENU_BAR, 'MenuBar', 'Create menubar') - m.Append(ID_NEW.MENU, 'Menu', 'Create menu') + SetMenu(m, pullDownMenu.topLevel) else: xxx = self.GetPyData(item).treeObject() # Check parent for possible child nodes if inserting sibling @@ -803,6 +839,29 @@ class XML_Tree(wxTreeCtrl): else: menu.AppendMenu(wxNewId(), 'Create Sibling', m, 'Create sibling after selected object') + # Build replace menu + if item != self.root: + xxx = self.GetPyData(item).treeObject() + m = wxMenu() # create replace menu + if xxx.__class__ == xxxMenuBar: + m.Append(1000 + ID_NEW.MENU, 'Menu', 'Create menu') + elif xxx.__class__ in [xxxMenu, xxxMenuItem]: + SetMenu2(m, pullDownMenu.menuControls) + elif xxx.__class__ == xxxToolBar and \ + self.GetItemParent(item) == self.root: + SetMenu2(m, []) + elif xxx.__class__ in [xxxFrame, xxxDialog, xxxPanel]: + SetMenu2(m, [ + (ID_NEW.PANEL, 'Panel', 'Create panel'), + (ID_NEW.DIALOG, 'Dialog', 'Create dialog'), + (ID_NEW.FRAME, 'Frame', 'Create frame')]) + elif xxx.isSizer: + SetMenu2(m, pullDownMenu.sizers) + else: + SetMenu2(m, pullDownMenu.controls) + id = wxNewId() + menu.AppendMenu(id, 'Replace With', m) + if not m.GetMenuItemCount(): menu.Enable(id, False) menu.AppendSeparator() # Not using standart IDs because we don't want to show shortcuts menu.Append(wxID_CUT, 'Cut', 'Cut to the clipboard') diff --git a/wxPython/wxPython/tools/XRCed/xrced.py b/wxPython/wxPython/tools/XRCed/xrced.py index bc5a8513ad..ae328a759c 100644 --- a/wxPython/wxPython/tools/XRCed/xrced.py +++ b/wxPython/wxPython/tools/XRCed/xrced.py @@ -11,14 +11,12 @@ xrced -- Simple resource editor for XRC format used by wxWindows/wxPython Usage: - xrced [ -h ] [ -i ] [ -v ] [ XRC-file ] + xrced [ -h ] [ -v ] [ XRC-file ] Options: -h output short usage info and exit - -i use international character set instead of translations - -v output version info and exit """ @@ -272,6 +270,7 @@ class Frame(wxFrame): EVT_KEY_UP(self, tools.OnKeyUp) def OnNew(self, evt): + if not self.AskSave(): return self.Clear() def OnOpen(self, evt): @@ -527,7 +526,7 @@ class Frame(wxFrame): else: self.toolsSizer.Remove(g.tools) self.toolsSizer.Layout() - + def OnTest(self, evt): if not tree.selection: return # key pressed event tree.ShowTestWindow(tree.selection) @@ -637,6 +636,92 @@ Homepage: http://xrced.sourceforge.net\ else: tree.pendingHighLight = None tree.SetFocus() + self.modified = True + + # Replace one object with another + def OnReplace(self, evt): + selected = tree.selection + xxx = tree.GetPyData(selected).treeObject() + elem = xxx.element + parent = elem.parentNode + parentXXX = xxx.parent + # New class + className = pullDownMenu.createMap[evt.GetId() - 1000] + # Create temporary empty node (with default values) + dummy = MakeEmptyDOM(className) + xxxClass = xxxDict[className] + # Remove non-compatible children + if tree.ItemHasChildren(selected) and not xxxClass.hasChildren: + tree.DeleteChildren(selected) + nodes = elem.childNodes[:] + tags = [] + for node in nodes: + remove = False + tag = node.tagName + if tag == 'object': + if not xxxClass.hasChildren: + remove = True + elif tag not in xxxClass.allParams and \ + (not xxxClass.hasStyle or tag not in xxxClass.styles): + remove = True + else: + tags.append(tag) + if remove: + elem.removeChild(node) + node.unlink() + + # Copy parameters present in dummy but not in elem + for node in dummy.childNodes: + tag = node.tagName + if tag not in tags: + elem.appendChild(node.cloneNode(True)) + dummy.unlink() + # Change class name + elem.setAttribute('class', className) + # Re-create xxx element + xxx = MakeXXXFromDOM(parentXXX, elem) + # Update parent in child objects + if tree.ItemHasChildren(selected): + i, cookie = tree.GetFirstChild(selected, 0) + while i.IsOk(): + x = tree.GetPyData(i) + x.parent = xxx + if x.hasChild: x.child.parent = xxx + i, cookie = tree.GetNextChild(selected, cookie) + + # Update tree + if tree.GetPyData(selected).hasChild: # child container + container = tree.GetPyData(selected) + container.child = xxx + container.hasChildren = xxx.hasChildren + container.isSizer = xxx.isSizer + else: + tree.SetPyData(selected, xxx) + tree.SetItemText(selected, xxx.treeName()) + tree.SetItemImage(selected, xxx.treeImage()) + + # Set default name for top-level windows + if parent.__class__ == xxxMainNode: + cl = xxx.treeObject().__class__ + frame.maxIDs[cl] += 1 + xxx.treeObject().name = '%s%d' % (defaultIDs[cl], frame.maxIDs[cl]) + xxx.treeObject().element.setAttribute('name', xxx.treeObject().name) + + # Update panel + g.panel.SetData(xxx) + # Update tools + g.tools.UpdateUI() + + #undoMan.RegisterUndo(UndoPasteCreate(parentLeaf, parent, newItem, selected)) + # Update view? + if g.testWin and tree.IsHighlatable(newItem): + if conf.autoRefresh: + tree.needUpdate = True + tree.pendingHighLight = newItem + else: + tree.pendingHighLight = None + tree.SetFocus() + self.modified = True # Expand/collapse subtree def OnExpand(self, evt): @@ -739,8 +824,10 @@ Homepage: http://xrced.sourceforge.net\ import xxx if mo: dom.encoding = xxx.currentEncoding = mo.group('encd') + if dom.encoding not in ['ascii', sys.getdefaultencoding()]: + wxLogWarning('Encoding is different from system default') else: - xxx.currentEncoding = 'iso-8859-1' + xxx.currentEncoding = 'ascii' dom.encoding = '' f.close() # Change dir @@ -819,14 +906,13 @@ Homepage: http://xrced.sourceforge.net\ ################################################################################ def usage(): - print >> sys.stderr, 'usage: xrced [-dhlv] [file]' + print >> sys.stderr, 'usage: xrced [-dhiv] [file]' class App(wxApp): def OnInit(self): global debug # Process comand-line try: - opts = args = [] #give empty values in case of exception opts, args = getopt.getopt(sys.argv[1:], 'dhiv') except getopt.GetoptError: if wxPlatform != '__WXMAC__': # macs have some extra parameters @@ -839,8 +925,6 @@ class App(wxApp): sys.exit(0) elif o == '-d': debug = True - elif o == '-i': - g.xmlFlags &= ~wxXRC_USE_LOCALE elif o == '-v': print 'XRCed version', version sys.exit(0) diff --git a/wxPython/wxPython/tools/XRCed/xxx.py b/wxPython/wxPython/tools/XRCed/xxx.py index ac93753e72..fe0fbad82b 100644 --- a/wxPython/wxPython/tools/XRCed/xxx.py +++ b/wxPython/wxPython/tools/XRCed/xxx.py @@ -8,9 +8,7 @@ from xml.dom import minidom from globals import * from params import * -currentEncoding = wxLocale_GetSystemEncodingName() -if not currentEncoding: - currentEncoding = 'ascii' +currentEncoding = sys.getdefaultencoding() # wxLocale_GetSystemEncodingName() # Base class for interface parameter classes class xxxNode: @@ -325,12 +323,13 @@ class xxxEncoding: # Special class for root node class xxxMainNode(xxxContainer): allParams = ['encoding'] - required = ['encoding'] - default = {'encoding': ''} hasStyle = hasName = False def __init__(self, dom): xxxContainer.__init__(self, None, dom.documentElement) self.className = 'XML tree' + # Reset required parameters after processing XML, because encoding is + # a little special + self.required = ['encoding'] self.params['encoding'] = xxxEncoding(dom.encoding) ################################################################################