wxPython Merge #2 of 2.4 branch --> HEAD (branch tag: wxPy_2_4_merge_2)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21593 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-07-02 23:13:10 +00:00
parent e234d4c9b7
commit 1fded56b37
535 changed files with 48899 additions and 20067 deletions

View File

@@ -1,3 +1,39 @@
0.1.1-3
-------
Sizes of some controls were not normal on wxMSW. Fixed.
Some changes to test window code to make it resize better and to
have focus control with sawfish for all types of windows.
0.1.1-2
-------
Bugs with currentEncoding and frame testing fixed.
Some required parameters are set to default if missing.
Unsupported classes are tolerated, with warning message.
wxScrolledWindow added (to 'control' pulldown menu, not yet to the
tool palette).
Multi-line editing for labels and some values (wxTextCtrl,
wxHtmlWindow).
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
-----
@@ -11,6 +47,7 @@ Fixed double-refreshing after Ctrl+R.
Maybe something else that I've forgot. It's been a looong day... :)
0.0.9-6
-------

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

View File

@@ -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-3'
try:
True
@@ -34,6 +34,6 @@ class Globals:
testWin = None
testWinPos = wxDefaultPosition
currentXXX = None
xmlFlags = wxXRC_USE_LOCALE | wxXRC_NO_SUBCLASSING
currentEncoding = sys.getdefaultencoding() # wxLocale_GetSystemEncodingName()
g = Globals()

View File

@@ -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)
@@ -199,7 +199,7 @@ class ParamFont(PPanel):
self.ID_BUTTON_SELECT = wxNewId()
self.SetBackgroundColour(g.panel.GetBackgroundColour())
sizer = wxBoxSizer()
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1))
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(200,-1))
sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5)
self.button = wxButton(self, self.ID_BUTTON_SELECT, 'Select...', size=buttonSize)
sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
@@ -290,7 +290,7 @@ class ParamInt(PPanel):
PPanel.__init__(self, parent, name)
self.ID_SPIN_CTRL = wxNewId()
sizer = wxBoxSizer()
self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=wxSize(50,-1))
self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=(50,-1))
self.SetBackgroundColour(g.panel.GetBackgroundColour())
sizer.Add(self.spin)
self.SetAutoLayout(True)
@@ -312,12 +312,12 @@ class ParamUnit(PPanel):
self.ID_TEXT_CTRL = wxNewId()
self.ID_SPIN_BUTTON = wxNewId()
sizer = wxBoxSizer()
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(35,-1))
self.spin = wxSpinButton(self, self.ID_SPIN_BUTTON, style = wxSP_VERTICAL)
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(35,-1))
self.spin = wxSpinButton(self, self.ID_SPIN_BUTTON, style = wxSP_VERTICAL, size=(-1,1))
self.spin.SetRange(-10000, 10000)
self.SetBackgroundColour(g.panel.GetBackgroundColour())
sizer.Add(self.text, 0, wxEXPAND | wxRIGHT, 2)
sizer.Add(self.spin)
sizer.Add(self.spin, 0, wxEXPAND)
self.SetAutoLayout(True)
self.SetSizer(sizer)
sizer.Fit(self)
@@ -350,6 +350,50 @@ class ParamUnit(PPanel):
def OnSpinDown(self, evt):
self.Change(-1)
# Dialog for editing multi-line text
class TextDialog(wxDialog):
def __init__(self, parent, value):
pre = wxPreDialog()
g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_TEXT')
self.this = pre.this
self._setOORInfo(self)
self.text = self.FindWindowByName('TEXT')
self.text.SetValue(value)
self.SetAutoLayout(True)
self.SetSize((300,200))
def GetValue(self):
return self.text.GetValue()
class ParamMultilineText(PPanel):
def __init__(self, parent, name, textWidth=-1):
PPanel.__init__(self, parent, name)
self.ID_TEXT_CTRL = wxNewId()
self.ID_BUTTON_EDIT = wxNewId()
self.SetBackgroundColour(g.panel.GetBackgroundColour())
sizer = wxBoxSizer()
self.SetBackgroundColour(g.panel.GetBackgroundColour())
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1))
sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5)
self.button = wxButton(self, self.ID_BUTTON_EDIT, 'Edit...', size=buttonSize)
sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
self.SetAutoLayout(True)
self.SetSizer(sizer)
sizer.Fit(self)
EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit)
EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
def GetValue(self):
return self.text.GetValue()
def SetValue(self, value):
self.freeze = True # disable other handlers
self.text.SetValue(value)
self.freeze = False # disable other handlers
def OnButtonEdit(self, evt):
dlg = TextDialog(self, self.text.GetValue())
if dlg.ShowModal() == wxID_OK:
self.text.SetValue(dlg.GetValue())
self.SetModified()
dlg.Destroy()
class ParamText(PPanel):
def __init__(self, parent, name, textWidth=-1):
PPanel.__init__(self, parent, name)
@@ -388,14 +432,13 @@ class ParamEncoding(ParamText):
def __init__(self, parent, name):
ParamText.__init__(self, parent, name, 100)
class ContentDialog(wxDialogPtr):
class ContentDialog(wxDialog):
def __init__(self, parent, value):
# Load from resource
w = g.frame.res.LoadDialog(parent, 'DIALOG_CONTENT')
# Perform initialization with class pointer
wxDialogPtr.__init__(self, w.this)
self.thisown = 1
self.Center()
pre = wxPreDialog()
g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT')
self.this = pre.this
self._setOORInfo(self)
self.list = self.FindWindowByName('LIST')
# Set list items
for v in value:
@@ -440,12 +483,12 @@ class ContentDialog(wxDialogPtr):
evt.Enable(self.list.GetSelection() != -1 and \
self.list.GetSelection() < self.list.Number() - 1)
class ContentCheckListDialog(wxDialogPtr):
class ContentCheckListDialog(wxDialog):
def __init__(self, parent, value):
w = g.frame.res.LoadDialog(parent, 'DIALOG_CONTENT_CHECK_LIST')
wxDialogPtr.__init__(self, w.this)
self.thisown = 1
self.Center()
pre = wxPreDialog()
g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT_CHECK_LIST')
self.this = pre.this
self._setOORInfo(self)
self.list = self.FindWindowByName('CHECK_LIST')
# Set list items
i = 0
@@ -573,13 +616,12 @@ class ParamContentCheckList(ParamContent):
self.textModified = False
dlg.Destroy()
class IntListDialog(wxDialogPtr):
class IntListDialog(wxDialog):
def __init__(self, parent, value):
# Is this normal???
w = g.frame.res.LoadDialog(parent, 'DIALOG_INTLIST')
wxDialogPtr.__init__(self, w.this)
self.thisown = 1
self.Center()
pre = wxPreDialog()
g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_INTLIST')
self.this = pre.this
self._setOORInfo(self)
self.list = self.FindWindowByName('LIST')
# Set list items
value.sort()
@@ -598,6 +640,7 @@ class IntListDialog(wxDialogPtr):
EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI)
def OnButtonAppend(self, evt):
s = wxGetTextFromUser('Enter new number:', 'Add', '', self)
if not s: return
# Check that it's unique
try:
v = int(s)
@@ -742,11 +785,10 @@ class ParamFile(PPanel):
class ParamBitmap(PPanel):
def __init__(self, parent, name):
# Load from resource
w = g.frame.res.LoadPanel(parent, 'PANEL_BITMAP')
# Perform initialization with class pointer
wxPanelPtr.__init__(self, w.this)
self.thisown = 1
pre = wxPrePanel()
g.frame.res.LoadOnPanel(pre, parent, 'PANEL_BITMAP')
self.this = pre.this
self._setOORInfo(self)
self.modified = self.freeze = False
self.SetBackgroundColour(g.panel.GetBackgroundColour())
self.radio_std = self.FindWindowByName('RADIO_STD')
@@ -827,11 +869,13 @@ paramDict = {
'vgap': ParamUnit, 'hgap': ParamUnit,
'checkable': ParamBool, 'checked': ParamBool, 'radio': ParamBool,
'accel': ParamAccel,
'label': ParamText, 'title': ParamText, 'value': ParamText,
'label': ParamMultilineText, 'title': ParamText, 'value': ParamText,
'content': ParamContent, 'selection': ParamInt,
'min': ParamInt, 'max': ParamInt,
'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont,
'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool,
'tooltip': ParamText, 'bitmap': ParamBitmap, 'icon': ParamBitmap,
'label': ParamLabel, 'encoding': ParamEncoding
'encoding': ParamEncoding
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

After

Width:  |  Height:  |  Size: 185 B

View File

@@ -178,6 +178,7 @@ class Tools(wxPanel):
# Update interface
def UpdateUI(self):
if not self.IsShown(): return
# Update status bar
pullDownMenu = g.pullDownMenu
tree = g.tree

View File

@@ -6,6 +6,9 @@
from xxx import * # xxx imports globals and params
# Constant to define standart window name
STD_NAME = '_XRCED_T_W'
# Icons
import images
@@ -68,6 +71,7 @@ class ID_NEW:
LIST_CTRL = wxNewId()
CHECK_LIST = wxNewId()
NOTEBOOK = wxNewId()
SCROLLED_WINDOW = wxNewId()
HTML_WINDOW = wxNewId()
CALENDAR_CTRL = wxNewId()
GENERIC_DIR_CTRL = wxNewId()
@@ -84,7 +88,7 @@ class ID_NEW:
MENU = wxNewId()
MENU_ITEM = wxNewId()
SEPARATOR = wxNewId()
LAST = wxNewId()
LAST = wxNewId()
class PullDownMenu:
ID_EXPAND = wxNewId()
@@ -94,6 +98,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)
@@ -136,6 +141,7 @@ class PullDownMenu:
ID_NEW.LIST_CTRL: 'wxListCtrl',
ID_NEW.CHECK_LIST: 'wxCheckList',
ID_NEW.NOTEBOOK: 'wxNotebook',
ID_NEW.SCROLLED_WINDOW: 'wxScrolledWindow',
ID_NEW.HTML_WINDOW: 'wxHtmlWindow',
ID_NEW.CALENDAR_CTRL: 'wxCalendarCtrl',
ID_NEW.GENERIC_DIR_CTRL: 'wxGenericDirCtrl',
@@ -148,6 +154,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'),
@@ -162,6 +191,7 @@ class PullDownMenu:
(ID_NEW.TREE_CTRL, 'TreeCtrl', 'Create tree'),
(ID_NEW.LIST_CTRL, 'ListCtrl', 'Create list'),
(ID_NEW.CHECK_LIST, 'CheckList', 'Create check list'),
(ID_NEW.SCROLLED_WINDOW, 'ScrolledWindow', 'Create scrolled window'),
(ID_NEW.HTML_WINDOW, 'HtmlWindow', 'Create HTML window'),
(ID_NEW.CALENDAR_CTRL, 'CalendarCtrl', 'Create calendar control'),
(ID_NEW.GENERIC_DIR_CTRL, 'GenericDirCtrl', 'Create generic dir control'),
@@ -246,6 +276,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()
################################################################################
@@ -279,11 +322,10 @@ class HighLightBox:
################################################################################
class XML_Tree(wxTreeCtrl):
# Constant to define standart window name
stdName = '_XRCED_T_W'
def __init__(self, parent, id):
wxTreeCtrl.__init__(self, parent, id, style = wxTR_HAS_BUTTONS)
self.SetBackgroundColour(wxColour(224, 248, 224))
# Register events
EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
# One works on Linux, another on Windows
if wxPlatform == '__WXGTK__':
@@ -291,7 +333,10 @@ class XML_Tree(wxTreeCtrl):
else:
EVT_LEFT_DCLICK(self, self.OnDClick)
EVT_RIGHT_DOWN(self, self.OnRightDown)
EVT_TREE_ITEM_EXPANDED(self, self.GetId(), self.OnItemExpandedCollapsed)
EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemExpandedCollapsed)
self.selection = None
self.needUpdate = False
self.pendingHighLight = None
self.ctrl = self.shift = False
@@ -413,6 +458,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
@@ -471,6 +517,7 @@ class XML_Tree(wxTreeCtrl):
pos = obj.GetPosition()
if pos == (-1,-1): pos = (0,0)
return parentPos + pos
# Find window (or sizer) corresponding to a tree item.
def FindNodeObject(self, item):
testWin = g.testWin
@@ -493,6 +540,7 @@ class XML_Tree(wxTreeCtrl):
if isinstance(child, wxNotebookSizerPtr):
child = child.GetNotebook()
return child
def OnSelChanged(self, evt):
# Apply changes
# !!! problem with wxGTK - GetOldItem is Ok if nothing selected
@@ -523,6 +571,7 @@ class XML_Tree(wxTreeCtrl):
g.tools.UpdateUI()
# Hightlighting is done in OnIdle
self.pendingHighLight = self.selection
# Check if item is in testWin subtree
def IsHighlatable(self, item):
if item == g.testWin.item: return False
@@ -530,6 +579,7 @@ class XML_Tree(wxTreeCtrl):
item = self.GetItemParent(item)
if item == g.testWin.item: return True
return False
# Highlight selected item
def HighLight(self, item):
self.pendingHighLight = None
@@ -551,6 +601,7 @@ class XML_Tree(wxTreeCtrl):
else:
g.testWin.highLight = HighLightBox(pos, size)
g.testWin.highLight.item = item
def ShowTestWindow(self, item):
xxx = self.GetPyData(item)
if g.panel.IsModified():
@@ -566,10 +617,12 @@ class XML_Tree(wxTreeCtrl):
self.CreateTestWin(item)
# Maybe an error occured, so we need to test
if g.testWin: self.SetItemBold(g.testWin.item)
# Double-click on Linux
def OnItemActivated(self, evt):
if evt.GetItem() != self.root:
self.ShowTestWindow(evt.GetItem())
# Double-click on Windows
def OnDClick(self, evt):
item, flags = self.HitTest(evt.GetPosition())
@@ -577,13 +630,32 @@ class XML_Tree(wxTreeCtrl):
if item != self.root: self.ShowTestWindow(item)
else:
evt.Skip()
def OnItemExpandedCollapsed(self, evt):
# Update tool palette
g.tools.UpdateUI()
evt.Skip()
# (re)create test window
def CreateTestWin(self, item):
testWin = g.testWin
wxBeginBusyCursor()
wxYield()
# Create a window with this resource
xxx = self.GetPyData(item).treeObject()
# If frame
# if xxx.__class__ == xxxFrame:
# Frame can't have many children,
# but it's first child possibly can...
# child = self.GetFirstChild(item, 0)[0]
# if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
# # Clean-up before recursive call or error
# wxMemoryFSHandler_RemoveFile('xxx.xrc')
# wxEndBusyCursor()
# self.CreateTestWin(child)
# return
wxBeginBusyCursor()
wxYield()
# Close old window, remember where it was
highLight = None
if testWin:
@@ -623,7 +695,7 @@ class XML_Tree(wxTreeCtrl):
name = 'noname'
else:
name = xxx.name
elem.setAttribute('name', self.stdName)
elem.setAttribute('name', STD_NAME)
parent = elem.parentNode
next = elem.nextSibling
parent.replaceChild(self.dummyNode, elem)
@@ -640,60 +712,70 @@ 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 g.currentEncoding == 'ascii':
xmlFlags != wxXRC_USE_LOCALE
res = wxXmlResource('', xmlFlags)
res.Load('memory:xxx.xrc')
if xxx.__class__ == xxxFrame:
# Frame can't have many children,
# but it's first child possibly can...
child = self.GetFirstChild(item, 0)[0]
if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
# Clean-up before recursive call or error
wxMemoryFSHandler_RemoveFile('xxx.xrc')
wxEndBusyCursor()
self.CreateTestWin(child)
return
# child = self.GetFirstChild(item, 0)[0]
# if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
# # Clean-up before recursive call or error
# wxMemoryFSHandler_RemoveFile('xxx.xrc')
# wxEndBusyCursor()
# self.CreateTestWin(child)
# return
# This currently works under GTK, but not under MSW
testWin = g.testWin = wxPreFrame()
res.LoadOnFrame(testWin, g.frame, self.stdName)
res.LoadOnFrame(testWin, g.frame, STD_NAME)
# Create status bar
testWin.panel = testWin
testWin.CreateStatusBar()
testWin.SetClientSize(testWin.GetBestSize())
testWin.panel = testWin
testWin.SetPosition(pos)
testWin.Show(True)
elif xxx.__class__ == xxxPanel:
# Create new frame
if not testWin:
testWin = g.testWin = wxFrame(g.frame, -1, 'Panel: ' + name, pos=pos)
testWin.panel = res.LoadPanel(testWin, self.stdName)
testWin.SetClientSize(testWin.panel.GetSize())
testWin = g.testWin = wxFrame(g.frame, -1, 'Panel: ' + name,
pos=pos, name=STD_NAME)
testWin.panel = res.LoadPanel(testWin, STD_NAME)
testWin.SetClientSize(testWin.GetBestSize())
testWin.Show(True)
elif xxx.__class__ == xxxDialog:
testWin = g.testWin = res.LoadDialog(None, self.stdName)
testWin = g.testWin = res.LoadDialog(None, STD_NAME)
testWin.panel = testWin
testWin.Layout()
testWin.SetPosition(pos)
testWin.Show(True)
# Dialog's default code does not produce EVT_CLOSE
EVT_BUTTON(testWin, wxID_OK, self.OnCloseTestWin)
EVT_BUTTON(testWin, wxID_CANCEL, self.OnCloseTestWin)
elif xxx.__class__ == xxxMenuBar:
testWin = g.testWin = wxFrame(g.frame, -1, 'MenuBar: ' + name, pos=pos)
testWin = g.testWin = wxFrame(g.frame, -1, 'MenuBar: ' + name,
pos=pos, name=STD_NAME)
testWin.panel = None
# Set status bar to display help
testWin.CreateStatusBar()
testWin.menuBar = res.LoadMenuBar(self.stdName)
testWin.menuBar = res.LoadMenuBar(STD_NAME)
testWin.SetMenuBar(testWin.menuBar)
testWin.Show(True)
elif xxx.__class__ == xxxToolBar:
testWin = g.testWin = wxFrame(g.frame, -1, 'ToolBar: ' + name, pos=pos)
testWin = g.testWin = wxFrame(g.frame, -1, 'ToolBar: ' + name,
pos=pos, name=STD_NAME)
testWin.panel = None
# Set status bar to display help
testWin.CreateStatusBar()
testWin.toolBar = res.LoadToolBar(testWin, self.stdName)
testWin.toolBar = res.LoadToolBar(testWin, STD_NAME)
testWin.SetToolBar(testWin.toolBar)
testWin.Show(True)
wxMemoryFSHandler_RemoveFile('xxx.xrc')
testWin.item = item
EVT_CLOSE(testWin, self.OnCloseTestWin)
EVT_BUTTON(testWin, wxID_OK, self.OnCloseTestWin)
EVT_BUTTON(testWin, wxID_CANCEL, self.OnCloseTestWin)
testWin.highLight = None
if highLight and not self.pendingHighLight:
self.HighLight(highLight)
@@ -764,13 +846,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 +879,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')

View File

@@ -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(selected):
if conf.autoRefresh:
tree.needUpdate = True
tree.pendingHighLight = selected
else:
tree.pendingHighLight = None
tree.SetFocus()
self.modified = True
# Expand/collapse subtree
def OnExpand(self, evt):
@@ -736,11 +821,12 @@ Homepage: http://xrced.sourceforge.net\
f.seek(0)
dom = minidom.parse(f)
# Set encoding global variable and document encoding property
import xxx
if mo:
dom.encoding = xxx.currentEncoding = mo.group('encd')
dom.encoding = g.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'
g.currentEncoding = 'ascii'
dom.encoding = ''
f.close()
# Change dir
@@ -819,14 +905,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 +924,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)

View File

@@ -1,7 +1,55 @@
<?xml version="1.0" ?>
<resource>
<object class="wxDialog" name="DIALOG_TEXT">
<title>Text Dialog</title>
<centered>1</centered>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxTextCtrl" name="TEXT">
<style>wxTE_MULTILINE</style>
</object>
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
</object>
</object>
<option>1</option>
<flag>wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxStaticLine"/>
<flag>wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxButton" name="wxID_OK">
<label>OK</label>
<default>1</default>
</object>
<flag>wxRIGHT</flag>
<border>10</border>
</object>
<object class="sizeritem">
<object class="wxButton" name="wxID_CANCEL">
<label>Cancel</label>
</object>
</object>
</object>
<flag>wxALL|wxALIGN_CENTRE_HORIZONTAL</flag>
<border>10</border>
</object>
</object>
<style>wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</style>
</object>
<object class="wxDialog" name="DIALOG_CONTENT">
<title>Content</title>
<centered>1</centered>
<size>250,300</size>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
@@ -86,6 +134,7 @@
</object>
<object class="wxDialog" name="DIALOG_CONTENT_CHECK_LIST">
<title>Content</title>
<centered>1</centered>
<size>250,300</size>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
@@ -170,6 +219,7 @@
</object>
<object class="wxDialog" name="DIALOG_INTLIST">
<title>Numbers</title>
<centered>1</centered>
<size>100,300</size>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>

View File

@@ -8,10 +8,6 @@ from xml.dom import minidom
from globals import *
from params import *
currentEncoding = wxLocale_GetSystemEncodingName()
if not currentEncoding:
currentEncoding = 'ascii'
# Base class for interface parameter classes
class xxxNode:
def __init__(self, node):
@@ -32,6 +28,15 @@ class xxxParam(xxxNode):
else:
text = node.childNodes[0] # first child must be text node
assert text.nodeType == minidom.Node.TEXT_NODE
# Append other text nodes if present and delete them
extraText = ''
for n in node.childNodes[1:]:
if n.nodeType == minidom.Node.TEXT_NODE:
extraText += n.data
node.removeChild(n)
n.unlink()
else: break
if extraText: text.data = text.data + extraText
# Use convertion from unicode to current encoding
self.textNode = text
# Value returns string
@@ -42,9 +47,9 @@ class xxxParam(xxxNode):
self.textNode.data = value
else:
def value(self):
return self.textNode.data.encode(currentEncoding)
return self.textNode.data.encode(g.currentEncoding)
def update(self, value):
self.textNode.data = unicode(value, currentEncoding)
self.textNode.data = unicode(value, g.currentEncoding)
# Integer parameter
class xxxParamInt(xxxParam):
@@ -238,7 +243,13 @@ class xxxObject:
# If default is specified, set it
if self.default.has_key(param):
elem = g.tree.dom.createElement(param)
self.params[param] = xxxParam(elem)
if param == 'content':
if self.className == 'wxCheckList':
self.params[param] = xxxParamContentCheckList(elem)
else:
self.params[param] = xxxParamContent(elem)
else:
self.params[param] = xxxParam(elem)
# Find place to put new element: first present element after param
found = False
paramStyles = self.allParams + self.styles
@@ -325,12 +336,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)
################################################################################
@@ -347,6 +359,7 @@ class xxxDialog(xxxContainer):
allParams = ['title', 'centered', 'pos', 'size', 'style']
paramDict = {'centered': ParamBool}
required = ['title']
default = {'title': ''}
winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
@@ -360,6 +373,7 @@ class xxxFrame(xxxContainer):
allParams = ['title', 'centered', 'pos', 'size', 'style']
paramDict = {'centered': ParamBool}
required = ['title']
default = {'title': ''}
winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
'wxSTAY_ON_TOP',
'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
@@ -418,10 +432,12 @@ class xxxTextCtrl(xxxObject):
allParams = ['value', 'pos', 'size', 'style']
winStyles = ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
paramDict = {'value': ParamMultilineText}
class xxxChoice(xxxObject):
allParams = ['content', 'selection', 'pos', 'size', 'style']
required = ['content']
default = {'content': '[]'}
winStyles = ['wxCB_SORT']
class xxxSlider(xxxObject):
@@ -462,7 +478,7 @@ class xxxTreeCtrl(xxxObject):
class xxxHtmlWindow(xxxObject):
allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
paramDict = {'borders': ParamInt}
paramDict = {'borders': ParamInt, 'htmlcode':ParamMultilineText}
winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
class xxxCalendarCtrl(xxxObject):
@@ -479,6 +495,10 @@ class xxxGenericDirCtrl(xxxObject):
winStyles = ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
class xxxScrolledWindow(xxxContainer):
allParams = ['pos', 'size', 'style']
winStyles = ['wxHSCROLL', 'wxVSCROLL']
################################################################################
# Buttons
@@ -522,6 +542,7 @@ class xxxRadioBox(xxxObject):
allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
paramDict = {'dimension': ParamInt}
required = ['label', 'content']
default = {'content': '[]'}
winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
class xxxCheckBox(xxxObject):
@@ -532,17 +553,20 @@ class xxxCheckBox(xxxObject):
class xxxComboBox(xxxObject):
allParams = ['content', 'selection', 'value', 'pos', 'size', 'style']
required = ['content']
default = {'content': '[]'}
winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
class xxxListBox(xxxObject):
allParams = ['content', 'selection', 'pos', 'size', 'style']
required = ['content']
default = {'content': '[]'}
winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
class xxxCheckList(xxxObject):
allParams = ['content', 'pos', 'size', 'style']
required = ['content']
default = {'content': '[]'}
winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
@@ -733,6 +757,7 @@ xxxDict = {
'wxCalendarCtrl': xxxCalendarCtrl,
'wxGenericDirCtrl': xxxGenericDirCtrl,
'wxSpinCtrl': xxxSpinCtrl,
'wxScrolledWindow': xxxScrolledWindow,
'wxBoxSizer': xxxBoxSizer,
'wxStaticBoxSizer': xxxStaticBoxSizer,
@@ -772,9 +797,9 @@ def MakeXXXFromDOM(parent, element):
try:
klass = xxxDict[element.getAttribute('class')]
except KeyError:
# Verify that it's not recursive exception
print 'ERROR: unknown class:', element.getAttribute('class')
raise
# If we encounter a weird class, use unknown template
print 'WARNING: unsupported class:', element.getAttribute('class')
klass = xxxUnknown
return klass(parent, element)
# Make empty DOM element