X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/32ce09e292c0d1a9a63c3edffc5778c4c094b003..08a15c0d899daad0ff8cc2ed4c06ff78b8ec3cc3:/wxPython/tools/XRCed/params.py diff --git a/wxPython/tools/XRCed/params.py b/wxPython/tools/XRCed/params.py index 4e0982abee..319034e02e 100644 --- a/wxPython/tools/XRCed/params.py +++ b/wxPython/tools/XRCed/params.py @@ -8,6 +8,7 @@ from wxPython.wx import * from wxPython.xrc import * import string import os.path +from types import * # Object which is currently processed currentXXX = None @@ -21,10 +22,12 @@ genericStyles = ['wxSIMPLE_BORDER', 'wxDOUBLE_BORDER', 'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS', 'wxNO_FULL_REPAINT_ON_RESIZE'] +buttonSize = (55,-1) + # Class that can properly disable children class PPanel(wxPanel): - def __init__(self, parent, id, name): - wxPanel.__init__(self, parent, id, name=name) + def __init__(self, parent, name): + wxPanel.__init__(self, parent, -1, name=name) self.modified = self.freeze = false def Enable(self, value): # Something strange is going on with enable so we make sure... @@ -33,18 +36,18 @@ class PPanel(wxPanel): wxPanel.Enable(self, value) def SetModified(self): self.modified = true - panel.SetModified(true) + panel.SetModified(true) class ParamBinaryOr(PPanel): - def __init__(self, parent, id, size, name): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name): + PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() self.ID_BUTTON_CHOICES = wxNewId() self.SetBackgroundColour(panel.GetBackgroundColour()) sizer = wxBoxSizer() self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) - sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) - self.button = wxButton(self, self.ID_BUTTON_CHOICES, 'Edit...') + sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5) + self.button = wxButton(self, self.ID_BUTTON_CHOICES, 'Edit...', size=buttonSize) sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL) self.SetAutoLayout(true) self.SetSizer(sizer) @@ -97,7 +100,10 @@ class ParamBinaryOr(PPanel): value.append(self.values[i]) # Add ignored flags value.extend(ignored) - self.SetValue(reduce(lambda a,b: a+'|'+b, value)) + if value: + self.SetValue(reduce(lambda a,b: a+'|'+b, value)) + else: + self.SetValue('') self.SetModified() dlg.Destroy() @@ -109,37 +115,37 @@ class ParamFlag(ParamBinaryOr): equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE', 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL'} - def __init__(self, parent, id, size, name): - ParamBinaryOr.__init__(self, parent, id, size, name) + def __init__(self, parent, name): + ParamBinaryOr.__init__(self, parent, name) class ParamStyle(ParamBinaryOr): equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE'} - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): + def __init__(self, parent, name): self.values = currentXXX.winStyles + genericStyles - ParamBinaryOr.__init__(self, parent, id, size, name) + ParamBinaryOr.__init__(self, parent, name) class ParamNonGenericStyle(ParamBinaryOr): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): + def __init__(self, parent, name): self.values = currentXXX.winStyles - ParamBinaryOr.__init__(self, parent, id, size, name) + ParamBinaryOr.__init__(self, parent, name) class ParamExStyle(ParamBinaryOr): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): + def __init__(self, parent, name): if currentXXX: self.values = currentXXX.exStyles # constant at the moment else: self.values = [] - ParamBinaryOr.__init__(self, parent, id, size, name) + ParamBinaryOr.__init__(self, parent, name) class ParamColour(PPanel): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name): + PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() self.ID_BUTTON = wxNewId() self.SetBackgroundColour(panel.GetBackgroundColour()) sizer = wxBoxSizer() - self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(60,-1)) - sizer.Add(self.text, 0, wxRIGHT, 10) + 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(40, -1)) sizer.Add(self.button, 0, wxGROW) self.SetAutoLayout(true) @@ -150,11 +156,10 @@ class ParamColour(PPanel): EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) EVT_LEFT_DOWN(self.button, self.OnLeftDown) def GetValue(self): - return self.value + return self.text.GetValue() def SetValue(self, value): self.freeze = true if not value: value = '#FFFFFF' - self.value = value self.text.SetValue(str(value)) # update text ctrl colour = wxColour(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16)) self.button.SetBackgroundColour(colour) @@ -163,7 +168,6 @@ class ParamColour(PPanel): def OnChange(self, evt): if self.freeze: return self.SetModified() - self.textModified = true evt.Skip() def OnPaintButton(self, evt): dc = wxPaintDC(self.button) @@ -173,11 +177,12 @@ class ParamColour(PPanel): size = self.button.GetSize() dc.DrawRectangle(0, 0, size.x, size.y) def OnLeftDown(self, evt): - dlg = wxColourDialog(self) + data = wxColourData() + data.SetColour(self.GetValue()) + dlg = wxColourDialog(self, data) if dlg.ShowModal() == wxID_OK: self.SetValue('#%02X%02X%02X' % dlg.GetColourData().GetColour().Get()) self.SetModified() - self.textModified = false dlg.Destroy() ################################################################################ @@ -197,15 +202,15 @@ fontStylesXml2wx = ReverseMap(fontStylesWx2Xml) fontWeightsXml2wx = ReverseMap(fontWeightsWx2Xml) class ParamFont(PPanel): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name): + PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() self.ID_BUTTON_SELECT = wxNewId() self.SetBackgroundColour(panel.GetBackgroundColour()) sizer = wxBoxSizer() self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) - sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) - self.button = wxButton(self, self.ID_BUTTON_SELECT, 'Select...') + 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) self.SetAutoLayout(true) self.SetSizer(sizer) @@ -218,34 +223,56 @@ class ParamFont(PPanel): self.SetModified() self.textModified = true evt.Skip() + def _defaultValue(self): + return ['12', 'default', 'normal', 'normal', '0', '', ''] def GetValue(self): if self.textModified: # text has newer value - return eval(self.text.GetValue()) + try: + return eval(self.text.GetValue()) + except SyntaxError: + wxLogError('Syntax error in parameter value: ' + self.GetName()) + return self._defaultValue() return self.value def SetValue(self, value): self.freeze = true # disable other handlers - if not value: value = [''] * 7 + if not value: value = self._defaultValue() self.value = value self.text.SetValue(str(value)) # update text ctrl self.freeze = false def OnButtonSelect(self, evt): if self.textModified: # text has newer value - self.value = eval(self.text.GetValue()) + try: + self.value = eval(self.text.GetValue()) + except SyntaxError: + wxLogError('Syntax error in parameter value: ' + self.GetName()) + self.value = self._defaultValue() # Make initial font - try: size = int(self.value[0]) - except ValueError: size = 12 - try: family = fontFamiliesXml2wx[self.value[1]] - except KeyError: family = wxDEFAULT - try: style = fontStylesXml2wx[self.value[2]] - except KeyError: style = wxNORMAL - try: weight = fontWeightsXml2wx[self.value[3]] - except KeyError: weight = wxNORMAL - try: underlined = int(self.value[4]) - except ValueError: underlined = 0 - face = self.value[5] - mapper = wxFontMapper() + # Default values + size = 12 + family = wxDEFAULT + style = weight = wxNORMAL + underlined = 0 + face = '' enc = wxFONTENCODING_DEFAULT - if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6]) + # Fall back to default if exceptions + error = false + try: + try: size = int(self.value[0]) + except ValueError: error = true + try: family = fontFamiliesXml2wx[self.value[1]] + except KeyError: error = true + try: style = fontStylesXml2wx[self.value[2]] + except KeyError: error = true + try: weight = fontWeightsXml2wx[self.value[3]] + except KeyError: error = true + try: underlined = int(self.value[4]) + except ValueError: error = true + face = self.value[5] + mapper = wxFontMapper() + if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6]) + except IndexError: + error = true + if error: wxLogError('Invalid font specification') if enc == wxFONTENCODING_DEFAULT: enc = wxFONTENCODING_SYSTEM font = wxFont(size, family, style, weight, underlined, face, enc) data = wxFontData() @@ -253,11 +280,14 @@ class ParamFont(PPanel): dlg = wxFontDialog(self, data) if dlg.ShowModal() == wxID_OK: font = dlg.GetFontData().GetChosenFont() - value = [str(font.GetPointSize()), fontFamiliesWx2Xml[font.GetFamily()], - fontStylesWx2Xml[font.GetStyle()], - fontWeightsWx2Xml[font.GetWeight()], - str(font.GetUnderlined()), font.GetFaceName(), - wxFontMapper_GetEncodingName(font.GetEncoding())] + value = [str(font.GetPointSize()), + fontFamiliesWx2Xml.get(font.GetFamily(), "default"), + fontStylesWx2Xml.get(font.GetStyle(), "normal"), + fontWeightsWx2Xml.get(font.GetWeight(), "normal"), + str(font.GetUnderlined()), + font.GetFaceName(), + wxFontMapper_GetEncodingName(font.GetEncoding()) + ] # Add ignored flags self.SetValue(value) self.SetModified() @@ -267,8 +297,8 @@ class ParamFont(PPanel): ################################################################################ class ParamInt(PPanel): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name): + PPanel.__init__(self, parent, name) self.ID_SPIN_CTRL = wxNewId() sizer = wxBoxSizer() self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=wxSize(50,-1)) @@ -291,8 +321,8 @@ class ParamInt(PPanel): evt.Skip() class ParamText(PPanel): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = '', textWidth=200): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name, textWidth=200): + PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() # We use sizer even here to have the same size of text control sizer = wxBoxSizer() @@ -315,35 +345,31 @@ class ParamText(PPanel): evt.Skip() class ParamAccel(ParamText): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - ParamText.__init__(self, parent, id, size, name, 50) + def __init__(self, parent, name): + ParamText.__init__(self, parent, name, 50) class ParamPosSize(ParamText): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - ParamText.__init__(self, parent, id, size, name, 80) + def __init__(self, parent, name): + ParamText.__init__(self, parent, name, 80) -class ContentDialog(wxDialog): +class ContentDialog(wxDialogPtr): def __init__(self, parent, value): - #wxPreDialog(self) - # Use another constructor - w = frame.res.LoadDialog(parent, 'ID_DIALOG_CONTENT') - self.this = w.this - w.thisown = 0 + # Is this normal??? + w = frame.res.LoadDialog(parent, 'DIALOG_CONTENT') + wxDialogPtr.__init__(self, w.this) self.thisown = 1 - #frame.res.LoadOnDialog(self, parent, 'ID_DIALOG_CONTENT') self.Center() - self.list = self.FindWindowByName('ID_LIST') + self.list = self.FindWindowByName('LIST') # Set list items for v in value: self.list.Append(v) self.SetAutoLayout(true) - # !!! self.SetSizer(sizer) self.GetSizer().Fit(self) # Callbacks - self.ID_BUTTON_APPEND = XMLID('ID_BUTTON_APPEND') - self.ID_BUTTON_REMOVE = XMLID('ID_BUTTON_REMOVE') - self.ID_BUTTON_UP = XMLID('ID_BUTTON_UP') - self.ID_BUTTON_DOWN = XMLID('ID_BUTTON_DOWN') + self.ID_BUTTON_APPEND = XMLID('BUTTON_APPEND') + self.ID_BUTTON_REMOVE = XMLID('BUTTON_REMOVE') + self.ID_BUTTON_UP = XMLID('BUTTON_UP') + self.ID_BUTTON_DOWN = XMLID('BUTTON_DOWN') EVT_BUTTON(self, self.ID_BUTTON_UP, self.OnButtonUp) EVT_BUTTON(self, self.ID_BUTTON_DOWN, self.OnButtonDown) EVT_BUTTON(self, self.ID_BUTTON_APPEND, self.OnButtonAppend) @@ -377,16 +403,76 @@ class ContentDialog(wxDialog): evt.Enable(self.list.GetSelection() != -1 and \ self.list.GetSelection() < self.list.Number() - 1) +class ContentCheckListDialog(wxDialogPtr): + def __init__(self, parent, value): + # Is this normal??? + w = frame.res.LoadDialog(parent, 'DIALOG_CONTENT_CHECK_LIST') + wxDialogPtr.__init__(self, w.this) + self.thisown = 1 + self.Center() + self.list = self.FindWindowByName('CHECK_LIST') + # Set list items + i = 0 + for v,ch in value: + self.list.Append(v) + self.list.Check(i, ch) + i += 1 + self.SetAutoLayout(true) + self.GetSizer().Fit(self) + # Callbacks + self.ID_BUTTON_APPEND = XMLID('BUTTON_APPEND') + self.ID_BUTTON_REMOVE = XMLID('BUTTON_REMOVE') + self.ID_BUTTON_UP = XMLID('BUTTON_UP') + self.ID_BUTTON_DOWN = XMLID('BUTTON_DOWN') + EVT_CHECKLISTBOX(self, self.list.GetId(), self.OnCheck) + EVT_BUTTON(self, self.ID_BUTTON_UP, self.OnButtonUp) + EVT_BUTTON(self, self.ID_BUTTON_DOWN, self.OnButtonDown) + EVT_BUTTON(self, self.ID_BUTTON_APPEND, self.OnButtonAppend) + EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) + EVT_UPDATE_UI(self, self.ID_BUTTON_UP, self.OnUpdateUI) + EVT_UPDATE_UI(self, self.ID_BUTTON_DOWN, self.OnUpdateUI) + EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) + def OnCheck(self, evt): + # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking + self.list.Deselect(evt.GetSelection()) + def OnButtonUp(self, evt): + i = self.list.GetSelection() + str, ch = self.list.GetString(i), self.list.IsChecked(i) + self.list.Delete(i) + self.list.InsertItems([str], i-1) + self.list.Check(i-1, ch) + self.list.SetSelection(i-1) + def OnButtonDown(self, evt): + i = self.list.GetSelection() + str, ch = self.list.GetString(i), self.list.IsChecked(i) + self.list.Delete(i) + self.list.InsertItems([str], i+1) + self.list.Check(i+1, ch) + self.list.SetSelection(i+1) + def OnButtonAppend(self, evt): + str = wxGetTextFromUser('Enter new item:', 'Append', '', self) + self.list.Append(str) + def OnButtonRemove(self, evt): + self.list.Delete(self.list.GetSelection()) + def OnUpdateUI(self, evt): + if evt.GetId() == self.ID_BUTTON_REMOVE: + evt.Enable(self.list.GetSelection() != -1) + elif evt.GetId() == self.ID_BUTTON_UP: + evt.Enable(self.list.GetSelection() > 0) + elif evt.GetId() == self.ID_BUTTON_DOWN: + evt.Enable(self.list.GetSelection() != -1 and \ + self.list.GetSelection() < self.list.Number() - 1) + class ParamContent(PPanel): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name): + PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() self.ID_BUTTON_EDIT = wxNewId() self.SetBackgroundColour(panel.GetBackgroundColour()) sizer = wxBoxSizer() self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) - sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) - self.button = wxButton(self, self.ID_BUTTON_EDIT, 'Edit...') + 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) @@ -395,22 +481,31 @@ class ParamContent(PPanel): EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit) EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) def OnChange(self, evt): - if self.freeze: return + if self.freeze: return self.SetModified() self.textModified = true evt.Skip() def GetValue(self): if self.textModified: # text has newer value - return eval(self.text.GetValue()) + try: + return eval(self.text.GetValue()) + except SyntaxError: + wxLogError('Syntax error in parameter value: ' + self.GetName()) + return [] return self.value def SetValue(self, value): self.freeze = true + if not value: value = [] self.value = value self.text.SetValue(str(value)) # update text ctrl self.freeze = false def OnButtonEdit(self, evt): if self.textModified: # text has newer value - self.value = eval(self.text.GetValue()) + try: + self.value = eval(self.text.GetValue()) + except SyntaxError: + wxLogError('Syntax error in parameter value: ' + self.GetName()) + self.value = [] dlg = ContentDialog(self, self.value) if dlg.ShowModal() == wxID_OK: value = [] @@ -422,11 +517,102 @@ class ParamContent(PPanel): self.textModified = false dlg.Destroy() +# CheckList content +class ParamContentCheckList(ParamContent): + def __init__(self, parent, name): + ParamContent.__init__(self, parent, name) + def OnButtonEdit(self, evt): + if self.textModified: # text has newer value + try: + self.value = eval(self.text.GetValue()) + except SyntaxError: + wxLogError('Syntax error in parameter value: ' + self.GetName()) + self.value = [] + dlg = ContentCheckListDialog(self, self.value) + if dlg.ShowModal() == wxID_OK: + value = [] + for i in range(dlg.list.Number()): + value.append((dlg.list.GetString(i), dlg.list.IsChecked(i))) + # Add ignored flags + self.SetValue(value) + self.SetModified() + self.textModified = false + dlg.Destroy() + +class IntListDialog(wxDialogPtr): + def __init__(self, parent, value): + # Is this normal??? + w = frame.res.LoadDialog(parent, 'DIALOG_INTLIST') + wxDialogPtr.__init__(self, w.this) + self.thisown = 1 + self.Center() + self.list = self.FindWindowByName('LIST') + # Set list items + value.sort() + for v in value: + if type(v) != IntType: + wxLogError('Invalid item type') + else: + self.list.Append(str(v)) + self.SetAutoLayout(true) + self.GetSizer().Fit(self) + # Callbacks + self.ID_BUTTON_ADD = XMLID('BUTTON_ADD') + self.ID_BUTTON_REMOVE = XMLID('BUTTON_REMOVE') + EVT_BUTTON(self, self.ID_BUTTON_ADD, self.OnButtonAppend) + EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) + EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) + def OnButtonAppend(self, evt): + s = wxGetTextFromUser('Enter new number:', 'Add', '', self) + # Check that it's unique + try: + v = int(s) + s = str(v) # to be sure + i = self.list.FindString(s) + if i == -1: # ignore non-unique + # Find place to insert + found = false + for i in range(self.list.Number()): + if int(self.list.GetString(i)) > v: + found = true + break + if found: self.list.InsertItems([s], i) + else: self.list.Append(s) + except ValueError: + wxLogError('List item is not an int!') + def OnButtonRemove(self, evt): + self.list.Delete(self.list.GetSelection()) + def OnUpdateUI(self, evt): + if evt.GetId() == self.ID_BUTTON_REMOVE: + evt.Enable(self.list.GetSelection() != -1) + +# For growable list +class ParamIntList(ParamContent): + def __init__(self, parent, name): + ParamContent.__init__(self, parent, name) + def OnButtonEdit(self, evt): + if self.textModified: # text has newer value + try: + self.value = eval(self.text.GetValue()) + except SyntaxError: + wxLogError('Syntax error in parameter value: ' + self.GetName()) + self.value = [] + dlg = IntListDialog(self, self.value) + if dlg.ShowModal() == wxID_OK: + value = [] + for i in range(dlg.list.Number()): + value.append(int(dlg.list.GetString(i))) + # Add ignored flags + self.SetValue(value) + self.SetModified() + self.textModified = false + dlg.Destroy() + # Boxless radiobox class RadioBox(PPanel): def __init__(self, parent, id, choices, - pos=wxDefaultPosition, size=wxDefaultSize, name='radiobox'): - PPanel.__init__(self, parent, id, name) + pos=wxDefaultPosition, name='radiobox'): + PPanel.__init__(self, parent, name) self.SetBackgroundColour(panel.GetBackgroundColour()) self.choices = choices topSizer = wxBoxSizer() @@ -454,8 +640,8 @@ class RadioBox(PPanel): class ParamBool(RadioBox): values = {'yes': '1', 'no': '0'} seulav = {'1': 'yes', '0': 'no'} - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name) + def __init__(self, parent, name): + RadioBox.__init__(self, parent, -1, choices = self.values.keys(), name=name) def GetValue(self): return self.values[self.GetStringSelection()] def SetValue(self, value): @@ -465,8 +651,8 @@ class ParamBool(RadioBox): class ParamOrient(RadioBox): values = {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'} seulav = {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'} - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name) + def __init__(self, parent, name): + RadioBox.__init__(self, parent, -1, choices = self.values.keys(), name=name) def GetValue(self): return self.values[self.GetStringSelection()] def SetValue(self, value): @@ -474,15 +660,15 @@ class ParamOrient(RadioBox): self.SetStringSelection(self.seulav[value]) class ParamFile(PPanel): - def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): - PPanel.__init__(self, parent, id, name) + def __init__(self, parent, name): + PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() self.ID_BUTTON_BROWSE = wxNewId() self.SetBackgroundColour(panel.GetBackgroundColour()) sizer = wxBoxSizer() self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) - sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) - self.button = wxButton(self, self.ID_BUTTON_BROWSE, 'Browse...') + sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5) + self.button = wxButton(self, self.ID_BUTTON_BROWSE, 'Browse...',size=buttonSize) sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL) self.SetAutoLayout(true) self.SetSizer(sizer) @@ -497,7 +683,7 @@ class ParamFile(PPanel): evt.Skip() def GetValue(self): if self.textModified: # text has newer value - return eval(self.text.GetValue()) + return self.text.GetValue() return self.value def SetValue(self, value): self.freeze = true @@ -508,11 +694,12 @@ class ParamFile(PPanel): if self.textModified: # text has newer value self.value = self.text.GetValue() dlg = wxFileDialog(self, - defaultDir = os.path.abspath(os.path.dirname(self.value)), + defaultDir = os.path.dirname(self.value), defaultFile = os.path.basename(self.value)) if dlg.ShowModal() == wxID_OK: # Make relative - common = os.path.commonprefix([frame.dataFile, dlg.GetPath()]) + common = os.path.commonprefix([os.path.abspath(frame.dataFile), + dlg.GetPath()]) self.SetValue(dlg.GetPath()[len(common):]) self.SetModified() self.textModified = false