X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9abdd2cb902ca40a25ab84e70155dcf58e92c4e2..1d88e73a3f25f16ad845b114153edd603d4970be:/wxPython/wx/tools/XRCed/params.py diff --git a/wxPython/wx/tools/XRCed/params.py b/wxPython/wx/tools/XRCed/params.py index 7a1b4b75a9..442c9c2257 100644 --- a/wxPython/wx/tools/XRCed/params.py +++ b/wxPython/wx/tools/XRCed/params.py @@ -10,11 +10,21 @@ from globals import * from types import * from wxPython.xrc import * -genericStyles = ['wxSIMPLE_BORDER', 'wxDOUBLE_BORDER', - 'wxSUNKEN_BORDER', 'wxRAISED_BORDER', - 'wxSTATIC_BORDER', 'wxNO_BORDER', - 'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS', - 'wxNO_FULL_REPAINT_ON_RESIZE'] +genericStyles = [ + 'wxSIMPLE_BORDER', 'wxSUNKEN_BORDER', 'wxDOUBLE_BORDER', + 'wxRAISED_BORDER', 'wxSTATIC_BORDER', 'wxNO_BORDER', + 'wxCLIP_CHILDREN', 'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS', + 'wxNO_FULL_REPAINT_ON_RESIZE', 'wxFULL_REPAINT_ON_RESIZE' + ] + +genericExStyles = [ + 'wxWS_EX_VALIDATE_RECURSIVELY', + 'wxWS_EX_BLOCK_EVENTS', + 'wxWS_EX_TRANSIENT', + 'wxFRAME_EX_CONTEXTHELP', + 'wxWS_EX_PROCESS_IDLE', + 'wxWS_EX_PROCESS_UI_UPDATES' + ] buttonSize = (35,-1) # in dialog units, transformed to pixels in panel ctor @@ -22,14 +32,12 @@ buttonSize = (35,-1) # in dialog units, transformed to pixels in panel ctor class PPanel(wxPanel): def __init__(self, parent, name): wxPanel.__init__(self, parent, -1, name=name) - self.SetBackgroundColour(parent.GetBackgroundColour()) - self.SetForegroundColour(parent.GetForegroundColour()) self.modified = self.freeze = False def Enable(self, value): # Something strange is going on with enable so we make sure... for w in self.GetChildren(): w.Enable(value) - wxPanel.Enable(self, value) + #wxPanel.Enable(self, value) def SetModified(self): self.modified = True g.panel.SetModified(True) @@ -62,7 +70,10 @@ class ParamBinaryOr(PPanel): self.freeze = False def OnButtonChoices(self, evt): dlg = g.frame.res.LoadDialog(self, 'DIALOG_CHOICES') - listBox = XRCCTRL(dlg, 'CHECK_LIST') + if self.GetName() == 'flag': dlg.SetTitle('Sizer item flags') + elif self.GetName() == 'style': dlg.SetTitle('Window styles') + elif self.GetName() == 'exstyle': dlg.SetTitle('Extended window styles') + listBox = XRCCTRL(dlg, 'CHECKLIST') listBox.InsertItems(self.values, 0) value = map(string.strip, self.text.GetValue().split('|')) if value == ['']: value = [] @@ -93,32 +104,86 @@ class ParamBinaryOr(PPanel): class ParamFlag(ParamBinaryOr): values = ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL', - 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxALIGN_CENTRE', 'wxALIGN_RIGHT', - 'wxFIXED_MINSIZE', - 'wxALIGN_BOTTOM', 'wxALIGN_CENTRE_VERTICAL', - 'wxALIGN_CENTRE_HORIZONTAL', + 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxSTRETCH_NOT', + 'wxALIGN_CENTRE', 'wxALIGN_LEFT', 'wxALIGN_RIGHT', + 'wxALIGN_TOP', 'wxALIGN_BOTTOM', + 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTRE_HORIZONTAL', + 'wxADJUST_MINSIZE', 'wxFIXED_MINSIZE' ] equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE', 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL', - 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL'} + 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL', + 'wxUP': 'wxTOP', 'wxDOWN': 'wxBOTTOM', 'wxNORTH': 'wxTOP', + 'wxSOUTH': 'wxBOTTOM', 'wxWEST': 'wxLEFT', 'wxEAST': 'wxRIGHT'} def __init__(self, parent, name): ParamBinaryOr.__init__(self, parent, name) -class ParamStyle(ParamBinaryOr): - equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE'} +class ParamNonGenericStyle(ParamBinaryOr): def __init__(self, parent, name): - self.values = g.currentXXX.winStyles + genericStyles + self.values = g.currentXXX.winStyles ParamBinaryOr.__init__(self, parent, name) -class ParamNonGenericStyle(ParamBinaryOr): +class ParamStyle(ParamBinaryOr): + equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE'} def __init__(self, parent, name): - self.values = g.currentXXX.winStyles ParamBinaryOr.__init__(self, parent, name) + self.valuesSpecific = g.currentXXX.winStyles + if self.valuesSpecific: # override if using specific styles + # Remove duplicates + self.valuesGeneric = [s for s in genericStyles + if s not in self.valuesSpecific] + EVT_BUTTON(self, self.ID_BUTTON_CHOICES, self.OnButtonChoicesBoth) + else: + self.values = genericStyles + def OnButtonChoicesBoth(self, evt): + dlg = g.frame.res.LoadDialog(self, 'DIALOG_STYLES') + listBoxSpecific = XRCCTRL(dlg, 'CHECKLIST_SPECIFIC') + listBoxSpecific.InsertItems(self.valuesSpecific, 0) + listBoxGeneric = XRCCTRL(dlg, 'CHECKLIST_GENERIC') + listBoxGeneric.InsertItems(self.valuesGeneric, 0) + value = map(string.strip, self.text.GetValue().split('|')) + if value == ['']: value = [] + # Set specific styles + value2 = [] # collect generic and ignored here + for i in value: + try: + listBoxSpecific.Check(self.valuesSpecific.index(i)) + except ValueError: + # Try to find equal + if self.equal.has_key(i): + listBoxSpecific.Check(self.valuesSpecific.index(self.equal[i])) + else: + value2.append(i) + ignored = [] + # Set generic styles, collect non-standart values + for i in value2: + try: + listBoxGeneric.Check(self.valuesGeneric.index(i)) + except ValueError: + # Try to find equal + if self.equal.has_key(i): + listBoxGeneric.Check(self.valuesGeneric.index(self.equal[i])) + else: + print 'WARNING: unknown flag: %s: ignored.' % i + ignored.append(i) + if dlg.ShowModal() == wxID_OK: + value = [self.valuesSpecific[i] + for i in range(listBoxSpecific.GetCount()) + if listBoxSpecific.IsChecked(i)] + \ + [self.valuesGeneric[i] + for i in range(listBoxGeneric.GetCount()) + if listBoxGeneric.IsChecked(i)] + ignored + if value: + self.SetValue(reduce(lambda a,b: a+'|'+b, value)) + else: + self.SetValue('') + self.SetModified() + dlg.Destroy() class ParamExStyle(ParamBinaryOr): def __init__(self, parent, name): if g.currentXXX: - self.values = g.currentXXX.exStyles # constant at the moment + self.values = g.currentXXX.exStyles + genericExStyles else: self.values = [] ParamBinaryOr.__init__(self, parent, name) @@ -129,10 +194,10 @@ class ParamColour(PPanel): self.ID_TEXT_CTRL = wxNewId() self.ID_BUTTON = wxNewId() sizer = wxBoxSizer() - self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(65,-1)) - 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.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(80,-1)) + sizer.Add(self.text, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, 2) + self.button = wxPanel(self, self.ID_BUTTON, wxDefaultPosition, wxSize(20, 20)) + sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5) self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) @@ -146,8 +211,11 @@ class ParamColour(PPanel): self.freeze = True if not value: value = '#FFFFFF' 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) + try: + colour = wxColour(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16)) + self.button.SetBackgroundColour(colour) + except: # ignore errors + pass self.button.Refresh() self.freeze = False def OnPaintButton(self, evt): @@ -168,7 +236,7 @@ class ParamColour(PPanel): ################################################################################ -# Mapping from wx constants ro XML strings +# Mapping from wx constants to XML strings fontFamiliesWx2Xml = {wxDEFAULT: 'default', wxDECORATIVE: 'decorative', wxROMAN: 'roman', wxSCRIPT: 'script', wxSWISS: 'swiss', wxMODERN: 'modern'} @@ -202,7 +270,7 @@ class ParamFont(PPanel): PPanel.OnChange(self, evt) self.textModified = True def _defaultValue(self): - return ['12', 'default', 'normal', 'normal', '0', '', ''] + return [`g._sysFont.GetPointSize()`, 'default', 'normal', 'normal', '0', '', ''] def GetValue(self): if self.textModified: # text has newer value try: @@ -226,7 +294,7 @@ class ParamFont(PPanel): self.value = self._defaultValue() # Make initial font # Default values - size = 12 + size = g._sysFont.GetPointSize() family = wxDEFAULT style = weight = wxNORMAL underlined = 0 @@ -236,20 +304,21 @@ class ParamFont(PPanel): error = False try: try: size = int(self.value[0]) - except ValueError: error = True + except ValueError: error = True; wxLogError('Invalid size specification') try: family = fontFamiliesXml2wx[self.value[1]] - except KeyError: error = True + except KeyError: error = True; wxLogError('Invalid family specification') try: style = fontStylesXml2wx[self.value[2]] - except KeyError: error = True + except KeyError: error = True; wxLogError('Invalid style specification') try: weight = fontWeightsXml2wx[self.value[3]] - except KeyError: error = True - try: underlined = int(self.value[4]) - except ValueError: error = True + except KeyError: error = True; wxLogError('Invalid weight specification') + try: underlined = bool(self.value[4]) + except ValueError: error = True; wxLogError('Invalid underlined flag specification') face = self.value[5] - mapper = wxFontMapper() - if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6]) except IndexError: error = True + mapper = wxFontMapper() + if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6]) + if error: wxLogError('Invalid font specification') if enc == wxFONTENCODING_DEFAULT: enc = wxFONTENCODING_SYSTEM font = wxFont(size, family, style, weight, underlined, face, enc) @@ -258,15 +327,19 @@ class ParamFont(PPanel): dlg = wxFontDialog(self, data) if dlg.ShowModal() == wxID_OK: font = dlg.GetFontData().GetChosenFont() + print font.GetEncoding() + if font.GetEncoding() == wxFONTENCODING_SYSTEM: + encName = '' + else: + encName = wxFontMapper_GetEncodingName(font.GetEncoding()).encode() value = [str(font.GetPointSize()), fontFamiliesWx2Xml.get(font.GetFamily(), "default"), fontStylesWx2Xml.get(font.GetStyle(), "normal"), fontWeightsWx2Xml.get(font.GetWeight(), "normal"), - str(font.GetUnderlined()), + str(int(font.GetUnderlined())), font.GetFaceName().encode(), - wxFontMapper_GetEncodingName(font.GetEncoding()).encode() + encName ] - # Add ignored flags self.SetValue(value) self.SetModified() self.textModified = False @@ -279,7 +352,29 @@ class ParamInt(PPanel): PPanel.__init__(self, parent, name) self.ID_SPIN_CTRL = wxNewId() sizer = wxBoxSizer() - self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=(50,-1)) + self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=(60,-1)) + self.spin.SetRange(-2147483648, 2147483647) # min/max integers + sizer.Add(self.spin) + self.SetAutoLayout(True) + self.SetSizer(sizer) + sizer.Fit(self) + EVT_SPINCTRL(self, self.ID_SPIN_CTRL, self.OnChange) + def GetValue(self): + return str(self.spin.GetValue()) + def SetValue(self, value): + self.freeze = True + if not value: value = 0 + self.spin.SetValue(int(value)) + self.freeze = False + +# Non-negative number +class ParamIntNN(PPanel): + 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=(60,-1)) + self.spin.SetRange(0, 10000) # min/max integers sizer.Add(self.spin) self.SetAutoLayout(True) self.SetSizer(sizer) @@ -299,12 +394,14 @@ class ParamUnit(PPanel): PPanel.__init__(self, parent, name) self.ID_TEXT_CTRL = wxNewId() self.ID_SPIN_BUTTON = wxNewId() - sizer = wxBoxSizer() - self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(35,-1)) + sizer = wxBoxSizer(wxHORIZONTAL) self.spin = wxSpinButton(self, self.ID_SPIN_BUTTON, style = wxSP_VERTICAL, size=(-1,1)) + textW = 60 - self.spin.GetSize()[0] + self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=(textW,-1)) self.spin.SetRange(-10000, 10000) - sizer.Add(self.text, 0, wxEXPAND | wxRIGHT, 2) + sizer.Add(self.text, 0, wxEXPAND) sizer.Add(self.spin, 0, wxEXPAND) + #sizer.SetMinSize((50,-1)) self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) @@ -376,7 +473,7 @@ class ParamText(PPanel): self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(textWidth,-1)) if textWidth == -1: option = 1 else: option = 0 - sizer.Add(self.text, option, wxALIGN_CENTER_VERTICAL) + sizer.Add(self.text, option, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, 2) self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) @@ -407,10 +504,10 @@ class ParamEncoding(ParamText): class ContentDialog(wxDialog): def __init__(self, parent, value): # Load from resource - pre = wxPreDialog() + pre = wxPreDialog() g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT') self.this = pre.this - self._setOORInfo(self) + self._setOORInfo(self) self.list = XRCCTRL(self, 'LIST') # Set list items for v in value: @@ -457,11 +554,11 @@ class ContentDialog(wxDialog): class ContentCheckListDialog(wxDialog): def __init__(self, parent, value): - pre = wxPreDialog() - g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT_CHECK_LIST') + pre = wxPreDialog() + g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT_CHECKLIST') self.this = pre.this - self._setOORInfo(self) - self.list = XRCCTRL(self, 'CHECK_LIST') + self._setOORInfo(self) + self.list = XRCCTRL(self, 'CHECKLIST') # Set list items i = 0 for v,ch in value: @@ -559,7 +656,6 @@ class ParamContent(PPanel): value = [] for i in range(dlg.list.GetCount()): value.append(dlg.list.GetString(i)) - # Add ignored flags self.SetValue(value) self.SetModified() self.textModified = False @@ -580,8 +676,7 @@ class ParamContentCheckList(ParamContent): if dlg.ShowModal() == wxID_OK: value = [] for i in range(dlg.list.GetCount()): - value.append((dlg.list.GetString(i), dlg.list.IsChecked(i))) - # Add ignored flags + value.append((dlg.list.GetString(i), int(dlg.list.IsChecked(i)))) self.SetValue(value) self.SetModified() self.textModified = False @@ -589,10 +684,10 @@ class ParamContentCheckList(ParamContent): class IntListDialog(wxDialog): def __init__(self, parent, value): - pre = wxPreDialog() + pre = wxPreDialog() g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_INTLIST') self.this = pre.this - self._setOORInfo(self) + self._setOORInfo(self) self.list = XRCCTRL(self, 'LIST') # Set list items value.sort() @@ -604,17 +699,16 @@ class IntListDialog(wxDialog): self.SetAutoLayout(True) self.GetSizer().Fit(self) # Callbacks - self.ID_BUTTON_ADD = XRCID('BUTTON_ADD') + self.spinCtrl = XRCCTRL(self, 'SPIN') + EVT_BUTTON(self, XRCID('BUTTON_ADD'), self.OnButtonAdd) self.ID_BUTTON_REMOVE = XRCID('BUTTON_REMOVE') - EVT_BUTTON(self, self.ID_BUTTON_ADD, self.OnButtonAppend) EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) + EVT_BUTTON(self, XRCID('BUTTON_CLEAR'), self.OnButtonClear) 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 + def OnButtonAdd(self, evt): # Check that it's unique try: - v = int(s) + v = self.spinCtrl.GetValue() s = str(v) # to be sure i = self.list.FindString(s) if i == -1: # ignore non-unique @@ -630,6 +724,8 @@ class IntListDialog(wxDialog): wxLogError('List item is not an int!') def OnButtonRemove(self, evt): self.list.Delete(self.list.GetSelection()) + def OnButtonClear(self, evt): + self.list.Clear() def OnUpdateUI(self, evt): if evt.GetId() == self.ID_BUTTON_REMOVE: evt.Enable(self.list.GetSelection() != -1) @@ -650,7 +746,6 @@ class ParamIntList(ParamContent): value = [] for i in range(dlg.list.GetCount()): value.append(int(dlg.list.GetString(i))) - # Add ignored flags self.SetValue(value) self.SetModified() self.textModified = False @@ -706,6 +801,17 @@ class ParamOrient(RadioBox): if not value: value = 'wxHORIZONTAL' self.SetStringSelection(self.seulav[value]) +class ParamOrientation(RadioBox): + values = {'horizontal': 'horizontal', 'vertical': 'vertical'} + seulav = {'horizontal': 'horizontal', 'vertical': 'vertical'} + 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): + if not value: value = 'vertical' + self.SetStringSelection(self.seulav[value]) + class ParamFile(PPanel): def __init__(self, parent, name): PPanel.__init__(self, parent, name) @@ -754,19 +860,13 @@ class ParamFile(PPanel): class ParamBitmap(PPanel): def __init__(self, parent, name): - pre = wxPrePanel() + pre = wxPrePanel() g.frame.res.LoadOnPanel(pre, parent, 'PANEL_BITMAP') self.this = pre.this - self._setOORInfo(self) - self.SetBackgroundColour(parent.GetBackgroundColour()) - self.SetForegroundColour(parent.GetForegroundColour()) + self._setOORInfo(self) self.modified = self.freeze = False self.radio_std = XRCCTRL(self, 'RADIO_STD') - self.radio_std.SetBackgroundColour(parent.GetBackgroundColour()) - self.radio_std.SetForegroundColour(parent.GetForegroundColour()) self.radio_file = XRCCTRL(self, 'RADIO_FILE') - self.radio_file.SetBackgroundColour(parent.GetBackgroundColour()) - self.radio_file.SetForegroundColour(parent.GetForegroundColour()) self.combo = XRCCTRL(self, 'COMBO_STD') self.text = XRCCTRL(self, 'TEXT_FILE') self.button = XRCCTRL(self, 'BUTTON_BROWSE') @@ -841,15 +941,16 @@ paramDict = { 'flag': ParamFlag, 'style': ParamStyle, 'exstyle': ParamExStyle, 'pos': ParamPosSize, 'size': ParamPosSize, - 'border': ParamUnit, 'cols': ParamInt, 'rows': ParamInt, + 'cellpos': ParamPosSize, 'cellspan': ParamPosSize, + 'border': ParamUnit, 'cols': ParamIntNN, 'rows': ParamIntNN, 'vgap': ParamUnit, 'hgap': ParamUnit, 'checkable': ParamBool, 'checked': ParamBool, 'radio': ParamBool, 'accel': ParamAccel, 'label': ParamMultilineText, 'title': ParamText, 'value': ParamText, - 'content': ParamContent, 'selection': ParamInt, + 'content': ParamContent, 'selection': ParamIntNN, 'min': ParamInt, 'max': ParamInt, 'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont, 'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool, 'tooltip': ParamText, 'bitmap': ParamBitmap, 'icon': ParamBitmap, - 'encoding': ParamEncoding + 'encoding': ParamEncoding, 'borders': ParamUnit }