def __init__(self, name, klass, parent, property_window): custom_class = parent is None EditBase.__init__(self, name, klass, parent, wx.NewId(), property_window, custom_class=custom_class, show=False) self.base = 'wx.ToolBar' def nil(*args): return () self.tools = [] # list of Tool objects self._tb = None # the real toolbar self.style = 0 self.access_functions['style'] = (self.get_style, self.set_style) self.style_pos = [wx.TB_FLAT, wx.TB_DOCKABLE, wx.TB_3DBUTTONS] if misc.check_wx_version(2, 3, 3): self.style_pos += [wx.TB_TEXT, wx.TB_NOICONS, wx.TB_NODIVIDER, wx.TB_NOALIGN] if misc.check_wx_version(2, 5, 0): self.style_pos += [wx.TB_HORZ_LAYOUT, wx.TB_HORZ_TEXT] style_labels = ['#section#' + _('Style'), 'wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_3DBUTTONS'] if misc.check_wx_version(2, 3, 3): style_labels += ['wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER', 'wxTB_NOALIGN'] if misc.check_wx_version(2, 5, 0): style_labels += ['wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT'] self.properties['style'] = CheckListProperty(self, 'style', None, style_labels) self.bitmapsize = '16, 15' self.access_functions['bitmapsize'] = (self.get_bitmapsize, self.set_bitmapsize) self.properties['bitmapsize'] = TextProperty(self, 'bitmapsize', None, can_disable=True, label=_("bitmapsize")) self.margins = '0, 0' self.access_functions['margins'] = (self.get_margins, self.set_margins) self.properties['margins'] = TextProperty(self, 'margins', None, can_disable=True, label=_("margins")) self.access_functions['tools'] = (self.get_tools, self.set_tools) prop = self.properties['tools'] = ToolsProperty(self, 'tools', None) self.packing = 1 self.access_functions['packing'] = (self.get_packing, self.set_packing) self.properties['packing'] = SpinProperty(self, 'packing', None, r=(0, 100), can_disable=True, label=_("packing")) self.separation = 5 self.access_functions['separation'] = (self.get_separation, self.set_separation) self.properties['separation'] = SpinProperty( self, 'separation', None, r=(0, 100), can_disable=True, label=_("separation")) # 2003-05-07 preview support PreviewMixin.__init__(self)
def set_size(self, value): #if not self.widget: return if self.properties['size'].is_active(): v = self.properties['size'].get_value().strip() use_dialog_units = v and v[-1] == 'd' else: use_dialog_units = config.preferences.use_dialog_units #False try: "" + value except TypeError: pass else: # value is a string-like object if value and value.strip()[-1] == 'd': use_dialog_units = True value = value[:-1] try: size = [int(t.strip()) for t in value.split(',', 1)] except: self.properties['size'].set_value(self.size) else: if use_dialog_units and value[-1] != 'd': value += 'd' self.size = value if self.widget: if use_dialog_units: size = wx.DLG_SZE(self.widget, size) if misc.check_wx_version(2, 5): self.widget.SetMinSize(size) self.widget.SetSize(size) try: #self.sizer.set_item(self.pos, size=self.widget.GetSize()) self.sizer.set_item(self.pos, size=size) except AttributeError: pass
def save_preferences(): # let the exception be raised if 'WXGLADE_CONFIG_PATH' in os.environ: path = os.path.expandvars('$WXGLADE_CONFIG_PATH') else: path = _get_appdatapath() if path != common.wxglade_path: path = os.path.join(path, '.wxglade') if not os.path.isdir(path): os.mkdir(path) # always save the file history if _use_file_history: fh = common.palette.file_history if misc.check_wx_version(2, 5): count = fh.GetCount() else: count = fh.GetNoHistoryFiles() encoding = 'utf-8' filenames = [ common._encode_to_xml(fh.GetHistoryFile(i), encoding) for i in range(min(preferences.number_history, count)) ] outfile = open(os.path.join(path, 'file_history.txt'), 'w') print >> outfile, "# -*- coding: %s -*-" % encoding for filename in filenames: print >> outfile, filename outfile.close() if preferences.changed: outfile = open(os.path.join(path, _rc_name), 'w') # let the exception be raised to signal abnormal behaviour preferences.write(outfile) outfile.close()
def OnInit(self): import sys sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ # needed for wx >= 2.3.4 to disable wxPyAssertionError exceptions if misc.check_wx_version(2, 3, 4): self.SetAssertMode(0) wx.InitAllImageHandlers() config.init_preferences() # ALB 2004-10-27 if wx.Platform == '__WXGTK__' and config.preferences.use_kde_dialogs: import kdefiledialog if kdefiledialog.test_kde(): misc.FileSelector = kdefiledialog.kde_file_selector misc.DirSelector = kdefiledialog.kde_dir_selector wx.ArtProvider.PushProvider(wxGladeArtProvider()) frame = wxGladeFrame() ## if wx.Platform == '__WXMSW__': ## def on_activate(event): ## if event.GetActive() and not frame.IsIconized(): ## frame.show_and_raise() ## event.Skip() ## wx.EVT_ACTIVATE_APP(self, on_activate) self.SetTopWindow(frame) self.SetExitOnFrameDelete(True) wx.EVT_IDLE(self, self.on_idle) return True
def insert(self, child, parent, pos, image=None): """\ inserts child to the list of parent's children, before index """ if parent.children is None: self.add(child, parent, image) return import common name = child.widget.__class__.__name__ image_index = WidgetTree.images.get(name, -1) if parent is None: parent = parent.item = self.GetRootItem() index = 0 if misc.check_wx_version(2, 5): item, cookie = self.GetFirstChild(parent.item) else: item, cookie = self.GetFirstChild(parent.item, 1) while item.IsOk(): item_pos = self.GetPyData(item).widget.pos if pos < item_pos: break index += 1 item, cookie = self.GetNextChild(parent.item, cookie) Tree.insert(self, child, parent, index) child.item = self.InsertItemBefore(parent.item, index, self._build_label(child), image_index) self.SetPyData(child.item, child) if self.auto_expand: self.Expand(parent.item) self.select_item(child) child.widget.show_properties() self.app.check_codegen(child.widget)
def save_preferences(): # let the exception be raised if 'WXGLADE_CONFIG_PATH' in os.environ: path = os.path.expandvars('$WXGLADE_CONFIG_PATH') else: path = _get_appdatapath() if path != common.wxglade_path: path = os.path.join(path, '.wxglade') if not os.path.isdir(path): os.mkdir(path) # always save the file history if _use_file_history: fh = common.palette.file_history if misc.check_wx_version(2, 5): count = fh.GetCount() else: count = fh.GetNoHistoryFiles() encoding = 'utf-8' filenames = [common._encode_to_xml(fh.GetHistoryFile(i), encoding) for i in range(min(preferences.number_history, count))] outfile = open(os.path.join(path, 'file_history.txt'), 'w') print >> outfile, "# -*- coding: %s -*-" % encoding for filename in filenames: print >> outfile, filename outfile.close() if preferences.changed: outfile = open(os.path.join(path, _rc_name), 'w') # let the exception be raised to signal abnormal behaviour preferences.write(outfile) outfile.close()
def createBrowseButton( self): """Create the browse-button control""" ID = wx.NewId() button =wx.Button(self, ID, misc.wxstr(self.buttonText)) button.SetToolTipString(misc.wxstr(self.toolTip)) w = button.GetTextExtent(self.buttonText)[0] + 10 if not misc.check_wx_version(2, 5, 2): button.SetSize((w, -1)) else: button.SetMinSize((w, -1)) wx.EVT_BUTTON(button, ID, self.OnBrowse) return button
def createBrowseButton(self): """Create the browse-button control""" ID = wx.NewId() button = wx.Button(self, ID, misc.wxstr(self.buttonText)) button.SetToolTipString(misc.wxstr(self.toolTip)) w = button.GetTextExtent(self.buttonText)[0] + 10 if not misc.check_wx_version(2, 5, 2): button.SetSize((w, -1)) else: button.SetMinSize((w, -1)) wx.EVT_BUTTON(button, ID, self.OnBrowse) return button
def set_tools(self, tools): self.tools = tools if not self._tb: return # nothing left to do while self._tb.DeleteToolByPos(0): pass # clear the toolbar # now add all the tools for tool in self.tools: if misc.streq(tool.id, '---'): # the tool is a separator self._tb.AddSeparator() else: if tool.bitmap1: bmp1 = None if not (tool.bitmap1.startswith('var:') or tool.bitmap1.startswith('code:')): bmp1 = wx.Bitmap( misc.get_relative_path(misc.wxstr(tool.bitmap1)), wx.BITMAP_TYPE_ANY) if not bmp1 or not bmp1.Ok(): bmp1 = wx.EmptyBitmap(1, 1) else: bmp1 = wx.NullBitmap if tool.bitmap2: bmp2 = None if not (tool.bitmap2.startswith('var:') or tool.bitmap2.startswith('code:')): bmp2 = wx.Bitmap( misc.get_relative_path(misc.wxstr(tool.bitmap2)), wx.BITMAP_TYPE_ANY) if not bmp2 or not bmp2.Ok(): bmp2 = wx.EmptyBitmap(1, 1) else: bmp2 = wx.NullBitmap # signature of AddTool for 2.3.2.1: # wxToolBarToolBase *AddTool( # int id, const wxBitmap& bitmap, # const wxBitmap& pushedBitmap, bool toggle = FALSE, # wxObject *clientData = NULL, # const wxString& shortHelpString = wxEmptyString, # const wxString& longHelpString = wxEmptyString) if not misc.check_wx_version(2, 3, 3): # use the old signature, some of the entries are ignored self._tb.AddTool(wx.NewId(), bmp1, bmp2, tool.type == 1, shortHelpString=\ misc.wxstr(tool.short_help), longHelpString=misc.wxstr(tool.long_help)) else: kinds = [wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO] try: kind = kinds[int(tool.type)] except (ValueError, IndexError): kind = wx.ITEM_NORMAL self._tb.AddLabelTool(wx.NewId(), misc.wxstr(tool.label), bmp1, bmp2, kind, misc.wxstr(tool.short_help), misc.wxstr(tool.long_help)) # this is required to refresh the toolbar properly self._refresh_widget()
def __init__(self, name, klass, parent, id, sizer, pos, property_window, show=True): WindowBase.__init__(self, name, klass, parent, id, property_window, show=show) # if True, the user is able to control the layout of the widget # inside the sizer (proportion, borders, alignment...) self._has_layout = not sizer.is_virtual() # selection markers self.sel_marker = None # dictionary of properties relative to the sizer which # controls this window self.sizer_properties = {} # attributes to keep the values of the sizer_properties self.option = 0 self.flag = 0 self.border = 0 self.sizer = sizer self.pos = pos self.access_functions['option'] = (self.get_option, self.set_option) self.access_functions['flag'] = (self.get_flag, self.set_flag) self.access_functions['border'] = (self.get_border, self.set_border) self.access_functions['pos'] = (self.get_pos, self.set_pos) self.flags_pos = (wx.ALL, wx.LEFT, wx.RIGHT, wx.TOP, wx.BOTTOM, wx.EXPAND, wx.ALIGN_RIGHT, wx.ALIGN_BOTTOM, wx.ALIGN_CENTER_HORIZONTAL, wx.ALIGN_CENTER_VERTICAL, wx.SHAPED, wx.ADJUST_MINSIZE) flag_labels = (u'#section#' + _('Border'), 'wxALL', 'wxLEFT', 'wxRIGHT', 'wxTOP', 'wxBOTTOM', u'#section#' + _('Alignment'), 'wxEXPAND', 'wxALIGN_RIGHT', 'wxALIGN_BOTTOM', 'wxALIGN_CENTER_HORIZONTAL', 'wxALIGN_CENTER_VERTICAL', 'wxSHAPED', 'wxADJUST_MINSIZE') # ALB 2004-08-16 - see the "wxPython migration guide" for details... if misc.check_wx_version(2, 5, 2): self.flag = wx.ADJUST_MINSIZE #wxFIXED_MINSIZE self.flags_pos += (wx.FIXED_MINSIZE, ) flag_labels += ('wxFIXED_MINSIZE', ) sizer.add_item(self, pos) szprop = self.sizer_properties #szprop['option'] = SpinProperty(self, _("option"), None, 0, (0, 1000)) from layout_option_property import LayoutOptionProperty, \ LayoutPosProperty szprop['option'] = LayoutOptionProperty(self, sizer) szprop['flag'] = CheckListProperty(self, 'flag', None, flag_labels) szprop['border'] = SpinProperty(self, 'border', None, 0, (0, 1000), label=_('border')) ## pos_p = szprop['pos'] = SpinProperty(self, 'pos', None, 0, (0, 1000)) ## def write(*args, **kwds): pass ## pos_p.write = write # no need to save the position szprop['pos'] = LayoutPosProperty(self, sizer)
def remove(self, *args, **kwds): if not kwds.get('do_nothing', False): if self.parent.widget: self.parent.widget.SetStatusBar(None) try: self.parent.properties['statusbar'].set_value(0) except KeyError: pass if self.widget: self.widget.Hide() EditBase.remove(self) else: if misc.check_wx_version(2, 6): if EditStatusBar._hidden_frame is None: EditStatusBar._hidden_frame = wx.Frame(None, -1, "") if self.widget is not None: self.widget.Reparent(EditStatusBar._hidden_frame) self.widget = None
def choose_specific_font(self, event): dialog = wx.FontDialog(self, wx.FontData()) if dialog.ShowModal() == wx.ID_OK: font = dialog.GetFontData().GetChosenFont() family = font.GetFamily() if misc.check_wx_version(2, 3, 3): for f in (wx.VARIABLE, wx.FIXED): if family & f: family = family ^ f self.value = "['%s', '%s', '%s', '%s', '%s', '%s']" % \ (font.GetPointSize(), self.font_families_from[family], self.font_styles_from[font.GetStyle()], self.font_weights_from[font.GetWeight()], font.GetUnderlined() and 1 or 0, font.GetFaceName()) self.EndModal(wx.ID_OK)
def save_app_as(self, event): """\ saves a wxGlade project onto an xml file chosen by the user """ fn = misc.FileSelector(_("Save project as..."), wildcard="wxGlade files (*.wxg)|*.wxg|" "wxGlade Template files (*.wgt) |*.wgt|" "XML files (*.xml)|*.xml|All files|*", flags=wx.SAVE | wx.OVERWRITE_PROMPT, default_path=self.cur_dir) if fn: common.app_tree.app.filename = fn #remove the template flag so we can save the file. common.app_tree.app.is_template = False self.save_app(event) self.cur_dir = os.path.dirname(fn) if misc.check_wx_version(2, 3, 3): self.file_history.AddFileToHistory(fn)
def save_app_as(self, event): """\ saves a wxGlade project onto an xml file chosen by the user """ fn = misc.FileSelector(_("Save project as..."), wildcard="wxGlade files (*.wxg)|*.wxg|" "wxGlade Template files (*.wgt) |*.wgt|" "XML files (*.xml)|*.xml|All files|*", flags=wx.SAVE|wx.OVERWRITE_PROMPT, default_path=self.cur_dir) if fn: common.app_tree.app.filename = fn #remove the template flag so we can save the file. common.app_tree.app.is_template = False self.save_app(event) self.cur_dir = os.path.dirname(fn) if misc.check_wx_version(2, 3, 3): self.file_history.AddFileToHistory(fn)
def remove(self, *args, **kwds): if self.parent is not None: self.parent.properties['menubar'].set_value(0) if kwds.get('gtk_do_nothing', False) and wx.Platform == '__WXGTK__': # workaround to prevent some segfaults on GTK: unfortunately, # I'm not sure that this works in all cases, and moreover it # could probably leak some memory (but I'm not sure) self.widget = None else: if self.parent.widget: if wx.Platform == '__WXGTK__' and \ not misc.check_wx_version(2, 5): self.widget.Reparent(EditMenuBar.__hidden_frame) self.widget.Hide() self.parent.widget.SetMenuBar(None) else: if self.widget: self.widget.Destroy() self.widget = None EditBase.remove(self)
def create_properties(self): """\ Creates the notebook with the properties of self """ self.notebook = wx.Notebook(self.property_window, -1) if not misc.check_wx_version(2, 5, 2): nb_sizer = wx.NotebookSizer(self.notebook) self.notebook.sizer = nb_sizer else: self.notebook.sizer = None self.notebook.SetAutoLayout(True) self.notebook.Hide() self._common_panel = panel = wx.ScrolledWindow( self.notebook, -1, style=wx.TAB_TRAVERSAL|wx.FULL_REPAINT_ON_RESIZE) self.name_prop.display(panel) self.klass_prop.display(panel) if getattr(self, '_custom_base_classes', False): self.properties['custom_base'].display(panel)
def create_properties(self): """\ Creates the notebook with the properties of self """ self.notebook = wx.Notebook(self.property_window, -1) if not misc.check_wx_version(2, 5, 2): nb_sizer = wx.NotebookSizer(self.notebook) self.notebook.sizer = nb_sizer else: self.notebook.sizer = None self.notebook.SetAutoLayout(True) self.notebook.Hide() self._common_panel = panel = wx.ScrolledWindow( self.notebook, -1, style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE) self.name_prop.display(panel) self.klass_prop.display(panel) if getattr(self, '_custom_base_classes', False): self.properties['custom_base'].display(panel)
h = self.get(section, 'h') return (x, y, w, h) else: return None # end of class Preferences preferences = None if sys.platform == 'win32': _rc_name = 'wxglade.ini' else: _rc_name = 'wxgladerc' _use_file_history = False if common.use_gui: import misc if misc.check_wx_version(2, 3, 3): _use_file_history = True def init_preferences(): global preferences if preferences is None: preferences = Preferences() h = _get_appdatapath('') search_path = [os.path.join(common.wxglade_path, _rc_name)] if h: search_path.append(os.path.join(h, '.wxglade', _rc_name)) if 'WXGLADE_CONFIG_PATH' in os.environ: search_path.append( os.path.expandvars('$WXGLADE_CONFIG_PATH/%s' % _rc_name)) preferences.read(search_path) if not preferences.has_section('wxglade'):
return (x, y, w, h) else: return None # end of class Preferences preferences = None if sys.platform == 'win32': _rc_name = 'wxglade.ini' else: _rc_name = 'wxgladerc' _use_file_history = False if common.use_gui: import misc if misc.check_wx_version(2, 3, 3): _use_file_history = True def init_preferences(): global preferences if preferences is None: preferences = Preferences() h = _get_appdatapath('') search_path = [os.path.join(common.wxglade_path, _rc_name)] if h: search_path.append(os.path.join(h, '.wxglade', _rc_name)) if 'WXGLADE_CONFIG_PATH' in os.environ: search_path.append( os.path.expandvars('$WXGLADE_CONFIG_PATH/%s' % _rc_name)) preferences.read(search_path) if not preferences.has_section('wxglade'):
def __init__(self, parent=None): style = wx.SYSTEM_MENU|wx.CAPTION|wx.MINIMIZE_BOX|wx.RESIZE_BORDER if misc.check_wx_version(2, 5): style |= wx.CLOSE_BOX wx.Frame.__init__(self, parent, -1, "wxGlade v%s" % common.version, style=style) self.CreateStatusBar(1) if parent is None: parent = self common.palette = self # to provide a reference accessible # by the various widget classes icon = wx.EmptyIcon() bmp = wx.Bitmap(os.path.join(common.wxglade_path, "icons/icon.xpm"), wx.BITMAP_TYPE_XPM) icon.CopyFromBitmap(bmp) self.SetIcon(icon) self.SetBackgroundColour(wx.SystemSettings_GetColour( wx.SYS_COLOUR_BTNFACE)) menu_bar = wx.MenuBar() file_menu = wx.Menu(style=wx.MENU_TEAROFF) view_menu = wx.Menu(style=wx.MENU_TEAROFF) help_menu = wx.Menu(style=wx.MENU_TEAROFF) wx.ToolTip_SetDelay(1000) # load the available code generators common.load_code_writers() # load the available widgets and sizers core_btns, custom_btns = common.load_widgets() sizer_btns = common.load_sizers() append_item = misc.append_item self.TREE_ID = TREE_ID = wx.NewId() append_item(view_menu, TREE_ID, _("Show &Tree\tF2")) self.PROPS_ID = PROPS_ID = wx.NewId() self.RAISE_ID = RAISE_ID = wx.NewId() append_item(view_menu, PROPS_ID, _("Show &Properties\tF3")) append_item(view_menu, RAISE_ID, _("&Raise All\tF4")) NEW_ID = wx.NewId() append_item(file_menu, NEW_ID, _("&New\tCtrl+N"), wx.ART_NEW) NEW_FROM_TEMPLATE_ID = wx.NewId() append_item(file_menu, NEW_FROM_TEMPLATE_ID, _("New from &Template...\tShift+Ctrl+N")) OPEN_ID = wx.NewId() append_item(file_menu, OPEN_ID, _("&Open...\tCtrl+O"), wx.ART_FILE_OPEN) SAVE_ID = wx.NewId() append_item(file_menu, SAVE_ID, _("&Save\tCtrl+S"), wx.ART_FILE_SAVE) SAVE_AS_ID = wx.NewId() append_item(file_menu, SAVE_AS_ID, _("Save As...\tShift+Ctrl+S"), wx.ART_FILE_SAVE_AS) SAVE_TEMPLATE_ID = wx.NewId() append_item(file_menu, SAVE_TEMPLATE_ID, _("Save As Template...")) file_menu.AppendSeparator() RELOAD_ID = wx.ID_REFRESH #wx.NewId() append_item(file_menu, RELOAD_ID, _("&Refresh\tf5")) #, wx.ART_REDO) GENERATE_CODE_ID = wx.NewId() append_item(file_menu, GENERATE_CODE_ID, _("&Generate Code\tCtrl+G"), wx.ART_EXECUTABLE_FILE) file_menu.AppendSeparator() IMPORT_ID = wx.NewId() append_item(file_menu, IMPORT_ID, _("&Import from XRC...\tCtrl+I")) EXIT_ID = wx.NewId() file_menu.AppendSeparator() append_item(file_menu, EXIT_ID, _('E&xit\tCtrl+Q'), wx.ART_QUIT) PREFS_ID = wx.ID_PREFERENCES #NewId() view_menu.AppendSeparator() MANAGE_TEMPLATES_ID = wx.NewId() append_item(view_menu, MANAGE_TEMPLATES_ID, _('Templates Manager...')) view_menu.AppendSeparator() append_item(view_menu, PREFS_ID, _('Preferences...')) #wx.ART_HELP_SETTINGS) menu_bar.Append(file_menu, _("&File")) menu_bar.Append(view_menu, _("&View")) TUT_ID = wx.NewId() append_item(help_menu, TUT_ID, _('Contents\tF1'), wx.ART_HELP) ABOUT_ID = wx.ID_ABOUT #wx.NewId() append_item(help_menu, ABOUT_ID, _('About...'))#, wx.ART_QUESTION) menu_bar.Append(help_menu, _('&Help')) parent.SetMenuBar(menu_bar) # Mac tweaks... if wx.Platform == "__WXMAC__": wx.App_SetMacAboutMenuItemId(ABOUT_ID) wx.App_SetMacPreferencesMenuItemId(PREFS_ID) wx.App_SetMacExitMenuItemId(EXIT_ID) wx.App_SetMacHelpMenuTitleName(_('&Help')) # file history support if misc.check_wx_version(2, 3, 3): self.file_history = wx.FileHistory( config.preferences.number_history) self.file_history.UseMenu(file_menu) files = config.load_history() files.reverse() for path in files: self.file_history.AddFileToHistory(path.strip()) def open_from_history(event): if not self.ask_save(): return infile = self.file_history.GetHistoryFile( event.GetId() - wx.ID_FILE1) # ALB 2004-10-15 try to restore possible autosave content... if common.check_autosaved(infile) and \ wx.MessageBox(_("There seems to be auto saved data for " "this file: do you want to restore it?"), _("Auto save detected"), style=wx.ICON_QUESTION|wx.YES_NO) == wx.YES: common.restore_from_autosaved(infile) else: common.remove_autosaved(infile) self._open_app(infile) wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, open_from_history) wx.EVT_MENU(self, TREE_ID, self.show_tree) wx.EVT_MENU(self, PROPS_ID, self.show_props_window) wx.EVT_MENU(self, RAISE_ID, self.raise_all) wx.EVT_MENU(self, NEW_ID, self.new_app) wx.EVT_MENU(self, NEW_FROM_TEMPLATE_ID, self.new_app_from_template) wx.EVT_MENU(self, OPEN_ID, self.open_app) wx.EVT_MENU(self, SAVE_ID, self.save_app) wx.EVT_MENU(self, SAVE_AS_ID, self.save_app_as) wx.EVT_MENU(self, SAVE_TEMPLATE_ID, self.save_app_as_template) def generate_code(event): common.app_tree.app.generate_code() wx.EVT_MENU(self, GENERATE_CODE_ID, generate_code) wx.EVT_MENU(self, EXIT_ID, lambda e: self.Close()) wx.EVT_MENU(self, TUT_ID, self.show_tutorial) wx.EVT_MENU(self, ABOUT_ID, self.show_about_box) wx.EVT_MENU(self, PREFS_ID, self.edit_preferences) wx.EVT_MENU(self, MANAGE_TEMPLATES_ID, self.manage_templates) wx.EVT_MENU(self, IMPORT_ID, self.import_xrc) wx.EVT_MENU(self, RELOAD_ID, self.reload_app) PREVIEW_ID = wx.NewId() def preview(event): if common.app_tree.cur_widget is not None: p = misc.get_toplevel_widget(common.app_tree.cur_widget) if p is not None: p.preview(None) wx.EVT_MENU(self, PREVIEW_ID, preview) self.accel_table = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('N'), NEW_ID), (wx.ACCEL_CTRL, ord('O'), OPEN_ID), (wx.ACCEL_CTRL, ord('S'), SAVE_ID), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('S'), SAVE_AS_ID), (wx.ACCEL_CTRL, ord('G'), GENERATE_CODE_ID), (wx.ACCEL_CTRL, ord('I'), IMPORT_ID), (0, wx.WXK_F1, TUT_ID), (wx.ACCEL_CTRL, ord('Q'), EXIT_ID), (0, wx.WXK_F5, RELOAD_ID), (0, wx.WXK_F2, TREE_ID), (0, wx.WXK_F3, PROPS_ID), (0, wx.WXK_F4, RAISE_ID), (wx.ACCEL_CTRL, ord('P'), PREVIEW_ID), ]) # Tutorial window ## self.tut_frame = None # layout # if there are custom components, add the toggle box... if custom_btns: main_sizer = wx.BoxSizer(wx.VERTICAL) show_core_custom = ToggleButtonBox( self, -1, [_("Core components"), _("Custom components")], 0) if misc.check_wx_version(2, 5): core_sizer = wx.FlexGridSizer( 0, config.preferences.buttons_per_row) custom_sizer = wx.FlexGridSizer( 0, config.preferences.buttons_per_row) else: core_sizer = wx.GridSizer( 0, config.preferences.buttons_per_row) custom_sizer = wx.GridSizer( 0, config.preferences.buttons_per_row) self.SetAutoLayout(True) # core components for b in core_btns: core_sizer.Add(b) for sb in sizer_btns: core_sizer.Add(sb) # custom components for b in custom_btns: custom_sizer.Add(b) if misc.check_wx_version(2, 5): custom_sizer.Show(b, False) custom_sizer.Layout() main_sizer.Add(show_core_custom, 0, wx.EXPAND) main_sizer.Add(core_sizer, 0, wx.EXPAND) main_sizer.Add(custom_sizer, 0, wx.EXPAND) self.SetSizer(main_sizer) if not misc.check_wx_version(2, 5): main_sizer.Show(custom_sizer, False) #main_sizer.Show(1, False) main_sizer.Fit(self) # events to display core/custom components if misc.check_wx_version(2, 5): def on_show_core_custom(event): show_core = True show_custom = False if event.GetValue() == 1: show_core = False show_custom = True for b in custom_btns: custom_sizer.Show(b, show_custom) for b in core_btns: core_sizer.Show(b, show_core) for b in sizer_btns: core_sizer.Show(b, show_core) core_sizer.Layout() custom_sizer.Layout() main_sizer.Layout() else: def on_show_core_custom(event): to_show = core_sizer to_hide = custom_sizer if event.GetValue() == 1: to_show, to_hide = to_hide, to_show main_sizer.Show(to_show, True) main_sizer.Show(to_hide, False) main_sizer.Layout() EVT_TOGGLE_BOX(self, show_core_custom.GetId(), on_show_core_custom) # ... otherwise (the common case), just add the palette of core buttons else: sizer = wx.GridSizer(0, config.preferences.buttons_per_row) self.SetAutoLayout(True) # core components for b in core_btns: sizer.Add(b) for sb in sizer_btns: sizer.Add(sb) self.SetSizer(sizer) sizer.Fit(self) # Properties window frame_style = wx.DEFAULT_FRAME_STYLE frame_tool_win = config.preferences.frame_tool_win if frame_tool_win: frame_style |= wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT frame_style &= ~wx.MINIMIZE_BOX if wx.Platform != '__WXGTK__': frame_style |= wx.FRAME_TOOL_WINDOW self.frame2 = wx.Frame(self, -1, _('Properties - <app>'), style=frame_style) self.frame2.SetBackgroundColour(wx.SystemSettings_GetColour( wx.SYS_COLOUR_BTNFACE)) self.frame2.SetIcon(icon) sizer_tmp = wx.BoxSizer(wx.VERTICAL) property_panel = wxGladePropertyPanel(self.frame2, -1) #---- 2003-06-22 Fix for what seems to be a GTK2 bug (notebooks) misc.hidden_property_panel = wx.Panel(self.frame2, -1) sz = wx.BoxSizer(wx.VERTICAL) sz.Add(property_panel, 1, wx.EXPAND) sz.Add(misc.hidden_property_panel, 1, wx.EXPAND) self.frame2.SetSizer(sz) sz.Show(misc.hidden_property_panel, False) self.property_frame = self.frame2 #-------------------------------------------------------- property_panel.SetAutoLayout(True) self.hidden_frame = wx.Frame(self, -1, "") self.hidden_frame.Hide() sizer_tmp.Add(property_panel, 1, wx.EXPAND) self.frame2.SetAutoLayout(True) self.frame2.SetSizer(sizer_tmp) sizer_tmp = wx.BoxSizer(wx.VERTICAL) def hide_frame2(event): #menu_bar.Check(PROPS_ID, False) self.frame2.Hide() wx.EVT_CLOSE(self.frame2, hide_frame2) wx.EVT_CLOSE(self, self.cleanup) common.property_panel = property_panel # Tree of widgets self.tree_frame = wx.Frame(self, -1, _('wxGlade: Tree'), style=frame_style) self.tree_frame.SetIcon(icon) import application app = application.Application(common.property_panel) common.app_tree = WidgetTree(self.tree_frame, app) self.tree_frame.SetSize((300, 300)) app.notebook.Show() sizer_tmp.Add(app.notebook, 1, wx.EXPAND) property_panel.SetSizer(sizer_tmp) sizer_tmp.Fit(property_panel) def on_tree_frame_close(event): #menu_bar.Check(TREE_ID, False) self.tree_frame.Hide() wx.EVT_CLOSE(self.tree_frame, on_tree_frame_close) # check to see if there are some remembered values prefs = config.preferences if prefs.remember_geometry: #print 'initializing geometry' try: x, y, w, h = prefs.get_geometry('main') misc.set_geometry(self, (x, y)) except Exception, e: pass misc.set_geometry(self.frame2, prefs.get_geometry('properties')) misc.set_geometry(self.tree_frame, prefs.get_geometry('tree'))
def display( self, parent ): """\ Actually builds the grid to set the value of the property interactively """ children = [] self.panel = wx.Panel( parent, -1 ) # why if the grid is not on this # panel it is not displayed??? label = getattr( self, 'label', _mangle( self.dispName ) ) sizer = wx.StaticBoxSizer( wx.StaticBox( self.panel, -1, label ), wx.VERTICAL ) self.btn_id = wx.NewId() self.btn = wx.Button( self.panel, self.btn_id, _( " Apply " ), style = wx.BU_EXACTFIT ) children.append( self.btn ) if self.can_add: self.add_btn = wx.Button( self.panel, self.btn_id + 1, _( " Add " ), style = wx.BU_EXACTFIT ) children.append( self.add_btn ) if self.can_insert: self.insert_btn = wx.Button( self.panel, self.btn_id + 3, _( " Insert " ), style = wx.BU_EXACTFIT ) children.append( self.insert_btn ) if self.can_remove: self.remove_btn = wx.Button( self.panel, self.btn_id + 2, _( " Remove " ), style = wx.BU_EXACTFIT ) children.append( self.remove_btn ) self.grid = wx.grid.Grid( self.panel, -1 ) self.grid.CreateGrid( self.rows, len( self.cols ) ) children.append( self.grid ) if misc.check_wx_version( 2, 3, 3 ): self.grid.SetMargins( 0, 0 ) else: # wx 2.3.2 seems to have some problems with grid scrollbars... self.grid.SetMargins( 0, self.grid.GetDefaultRowSize() ) for i in range( len( self.cols ) ): self.grid.SetColLabelValue( i, misc.wxstr( self.cols[i][0] ) ) GridProperty.col_format[self.cols[i][1]]( self.grid, i ) self.cols = len( self.cols ) self.grid.SetRowLabelSize( 0 ) self.grid.SetColLabelSize( 20 ) self.btn_sizer = wx.BoxSizer( wx.HORIZONTAL ) _w = self.btn.GetTextExtent( self.btn.GetLabel() )[0] if misc.check_wx_version( 2, 5, 2 ): extra_flag = wx.FIXED_MINSIZE else: extra_flag = 0 #self.btn.SetSize((_w, -1)) self.btn_sizer.Add( self.btn, 0, extra_flag ) if self.can_add: _w = self.add_btn.GetTextExtent( self.add_btn.GetLabel() )[0] #self.add_btn.SetSize((_w, -1)) self.btn_sizer.Add( self.add_btn, 0, wx.LEFT | wx.RIGHT | extra_flag, 4 ) wx.EVT_BUTTON( self.add_btn, self.btn_id + 1, self.add_row ) if self.can_insert: _w = self.insert_btn.GetTextExtent( self.insert_btn.GetLabel() )[0] #self.insert_btn.SetSize((_w, -1)) self.btn_sizer.Add( self.insert_btn, 0, wx.LEFT | wx.RIGHT | extra_flag, 4 ) wx.EVT_BUTTON( self.insert_btn, self.btn_id + 3, self.insert_row ) if self.can_remove: _w = self.remove_btn.GetTextExtent( self.remove_btn.GetLabel() )[0] #self.remove_btn.SetSize((_w, -1)) self.btn_sizer.Add( self.remove_btn, 0, extra_flag ) wx.EVT_BUTTON( self.remove_btn, self.btn_id + 2, self.remove_row ) sizer.Add( self.btn_sizer, 0, wx.BOTTOM | wx.EXPAND, 2 ) sizer.Add( self.grid, 1, wx.EXPAND ) self.panel.SetAutoLayout( 1 ) self.panel.SetSizer( sizer ) self.panel.SetSize( sizer.GetMinSize() ) self.prepare_activator( target = children ) wx.grid.EVT_GRID_SELECT_CELL( self.grid, self.on_select_cell ) self.bind_event( self.on_change_val ) self.set_value( self.val )
def __init__(self, name, parent, id, title, property_window, style=wx.DEFAULT_FRAME_STYLE, show=True, klass='wxFrame'): TopLevelBase.__init__(self, name, klass, parent, id, property_window, show=show, title=title) self.base = 'wxFrame' self.style = style self.statusbar = None self.icon = '' self.access_functions['statusbar'] = (self.get_statusbar, self.set_statusbar) self.menubar = None self.access_functions['menubar'] = (self.get_menubar, self.set_menubar) self.toolbar = None self.access_functions['toolbar'] = (self.get_toolbar, self.set_toolbar) self.access_functions['style'] = (self.get_style, self.set_style) self.access_functions['icon'] = (self.get_icon, self.set_icon) prop = self.properties style_labels = ['#section#' + _('Style'), 'wxDEFAULT_FRAME_STYLE', 'wxICONIZE', 'wxCAPTION', 'wxMINIMIZE', 'wxMINIMIZE_BOX', 'wxMAXIMIZE', 'wxMAXIMIZE_BOX', 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxSIMPLE_BORDER', 'wxRESIZE_BORDER', 'wxFRAME_TOOL_WINDOW', 'wxFRAME_NO_TASKBAR', 'wxFRAME_FLOAT_ON_PARENT', 'wxNO_BORDER', 'wxNO_FULL_REPAINT_ON_RESIZE', 'wxFULL_REPAINT_ON_RESIZE', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN'] self.style_pos = [wx.DEFAULT_FRAME_STYLE, wx.ICONIZE, wx.CAPTION, wx.MINIMIZE, wx.MINIMIZE_BOX, wx.MAXIMIZE, wx.MAXIMIZE_BOX, wx.STAY_ON_TOP, wx.SYSTEM_MENU, wx.SIMPLE_BORDER, wx.RESIZE_BORDER, wx.FRAME_TOOL_WINDOW, wx.FRAME_NO_TASKBAR, wx.FRAME_FLOAT_ON_PARENT, wx.NO_BORDER, wx.NO_FULL_REPAINT_ON_RESIZE, wx.FULL_REPAINT_ON_RESIZE, wx.TAB_TRAVERSAL, wx.CLIP_CHILDREN] if misc.check_wx_version(2, 5): style_labels.insert(5, 'wxCLOSE_BOX') self.style_pos.insert(4, wx.CLOSE_BOX) prop['style'] = CheckListProperty(self, 'style', None, style_labels) # menubar property prop['menubar'] = CheckBoxProperty(self, 'menubar', None, _('Has MenuBar')) # statusbar property prop['statusbar'] = CheckBoxProperty(self, 'statusbar', None, _('Has StatusBar')) # toolbar property prop['toolbar'] = CheckBoxProperty(self, 'toolbar', None, _('Has ToolBar')) # icon property prop['icon'] = FileDialogProperty(self, 'icon', None, style=wx.OPEN|wx.FILE_MUST_EXIST, can_disable=True, label=_("icon")) # centered property self.centered = False self.access_functions['centered'] = (self.get_centered, self.set_centered) prop['centered'] = CheckBoxProperty(self, 'centered', None, label=_("centered")) # size hints property self.sizehints = False self.access_functions['sizehints'] = (self.get_sizehints, self.set_sizehints) prop['sizehints'] = CheckBoxProperty(self, 'sizehints', None, label=_('Set Size Hints'))
def __init__(self, parent=None): wx.Dialog.__init__(self, parent, -1, _('About wxGlade')) class HtmlWin(wx.html.HtmlWindow): def OnLinkClicked(self, linkinfo): href = linkinfo.GetHref() if href == 'show_license': from wx.lib.dialogs import ScrolledMessageDialog try: license = open( os.path.join(common.wxglade_path, 'license.txt')) dlg = ScrolledMessageDialog(self, license.read(), _("wxGlade - License")) license.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox( _("Can't find the license!\n" "You can get a copy at \n" "http://www.opensource.org/licenses/" "mit-license.php"), _("Error"), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) elif href == 'show_credits': from wx.lib.dialogs import ScrolledMessageDialog try: credits = open( os.path.join(common.wxglade_path, 'credits.txt')) dlg = ScrolledMessageDialog(self, credits.read(), _("wxGlade - Credits")) credits.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox(_("Can't find the credits file!\n"), _("Oops!"), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) else: import webbrowser webbrowser.open(linkinfo.GetHref(), new=True) html = HtmlWin(self, -1, size=(400, -1)) if misc.check_wx_version(2, 5, 3): try: html.SetStandardFonts() except AttributeError: pass py_version = sys.version.split()[0] bgcolor = misc.color_to_string(self.GetBackgroundColour()) icon_path = os.path.join(common.wxglade_path, 'icons/wxglade_small.png') html.SetPage( self.text % (bgcolor, icon_path, common.version, py_version, wx.__version__)) ir = html.GetInternalRepresentation() ir.SetIndent(0, wx.html.HTML_INDENT_ALL) html.SetSize((ir.GetWidth(), ir.GetHeight())) szr = wx.BoxSizer(wx.VERTICAL) szr.Add(html, 0, wx.TOP | wx.ALIGN_CENTER, 10) szr.Add(wx.StaticLine(self, -1), 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 20) szr2 = wx.BoxSizer(wx.HORIZONTAL) btn = wx.Button(self, wx.ID_OK, _("OK")) btn.SetDefault() szr2.Add(btn) if wx.Platform == '__WXGTK__': extra_border = 5 # border around a default button else: extra_border = 0 szr.Add(szr2, 0, wx.ALL | wx.ALIGN_RIGHT, 20 + extra_border) self.SetAutoLayout(True) self.SetSizer(szr) szr.Fit(self) self.Layout() if parent: self.CenterOnParent() else: self.CenterOnScreen()
def __init__(self, parent=None): style = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.RESIZE_BORDER if misc.check_wx_version(2, 5): style |= wx.CLOSE_BOX wx.Frame.__init__(self, parent, -1, "wxGlade v%s" % common.version, style=style) self.CreateStatusBar(1) if parent is None: parent = self common.palette = self # to provide a reference accessible # by the various widget classes icon = wx.EmptyIcon() bmp = wx.Bitmap(os.path.join(common.wxglade_path, "icons/icon.xpm"), wx.BITMAP_TYPE_XPM) icon.CopyFromBitmap(bmp) self.SetIcon(icon) self.SetBackgroundColour( wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) menu_bar = wx.MenuBar() file_menu = wx.Menu(style=wx.MENU_TEAROFF) view_menu = wx.Menu(style=wx.MENU_TEAROFF) help_menu = wx.Menu(style=wx.MENU_TEAROFF) wx.ToolTip_SetDelay(1000) # load the available code generators common.load_code_writers() # load the available widgets and sizers core_btns, custom_btns = common.load_widgets() sizer_btns = common.load_sizers() append_item = misc.append_item self.TREE_ID = TREE_ID = wx.NewId() append_item(view_menu, TREE_ID, _("Show &Tree\tF2")) self.PROPS_ID = PROPS_ID = wx.NewId() self.RAISE_ID = RAISE_ID = wx.NewId() append_item(view_menu, PROPS_ID, _("Show &Properties\tF3")) append_item(view_menu, RAISE_ID, _("&Raise All\tF4")) NEW_ID = wx.NewId() append_item(file_menu, NEW_ID, _("&New\tCtrl+N"), wx.ART_NEW) NEW_FROM_TEMPLATE_ID = wx.NewId() append_item(file_menu, NEW_FROM_TEMPLATE_ID, _("New from &Template...\tShift+Ctrl+N")) OPEN_ID = wx.NewId() append_item(file_menu, OPEN_ID, _("&Open...\tCtrl+O"), wx.ART_FILE_OPEN) SAVE_ID = wx.NewId() append_item(file_menu, SAVE_ID, _("&Save\tCtrl+S"), wx.ART_FILE_SAVE) SAVE_AS_ID = wx.NewId() append_item(file_menu, SAVE_AS_ID, _("Save As...\tShift+Ctrl+S"), wx.ART_FILE_SAVE_AS) SAVE_TEMPLATE_ID = wx.NewId() append_item(file_menu, SAVE_TEMPLATE_ID, _("Save As Template...")) file_menu.AppendSeparator() RELOAD_ID = wx.ID_REFRESH #wx.NewId() append_item(file_menu, RELOAD_ID, _("&Refresh\tf5")) #, wx.ART_REDO) GENERATE_CODE_ID = wx.NewId() append_item(file_menu, GENERATE_CODE_ID, _("&Generate Code\tCtrl+G"), wx.ART_EXECUTABLE_FILE) file_menu.AppendSeparator() IMPORT_ID = wx.NewId() append_item(file_menu, IMPORT_ID, _("&Import from XRC...\tCtrl+I")) EXIT_ID = wx.NewId() file_menu.AppendSeparator() append_item(file_menu, EXIT_ID, _('E&xit\tCtrl+Q'), wx.ART_QUIT) PREFS_ID = wx.ID_PREFERENCES #NewId() view_menu.AppendSeparator() MANAGE_TEMPLATES_ID = wx.NewId() append_item(view_menu, MANAGE_TEMPLATES_ID, _('Templates Manager...')) view_menu.AppendSeparator() append_item(view_menu, PREFS_ID, _('Preferences...')) #wx.ART_HELP_SETTINGS) menu_bar.Append(file_menu, _("&File")) menu_bar.Append(view_menu, _("&View")) TUT_ID = wx.NewId() append_item(help_menu, TUT_ID, _('Contents\tF1'), wx.ART_HELP) ABOUT_ID = wx.ID_ABOUT #wx.NewId() append_item(help_menu, ABOUT_ID, _('About...')) #, wx.ART_QUESTION) menu_bar.Append(help_menu, _('&Help')) parent.SetMenuBar(menu_bar) # Mac tweaks... if wx.Platform == "__WXMAC__": wx.App_SetMacAboutMenuItemId(ABOUT_ID) wx.App_SetMacPreferencesMenuItemId(PREFS_ID) wx.App_SetMacExitMenuItemId(EXIT_ID) wx.App_SetMacHelpMenuTitleName(_('&Help')) # file history support if misc.check_wx_version(2, 3, 3): self.file_history = wx.FileHistory( config.preferences.number_history) self.file_history.UseMenu(file_menu) files = config.load_history() files.reverse() for path in files: self.file_history.AddFileToHistory(path.strip()) def open_from_history(event): if not self.ask_save(): return infile = self.file_history.GetHistoryFile(event.GetId() - wx.ID_FILE1) # ALB 2004-10-15 try to restore possible autosave content... if common.check_autosaved(infile) and \ wx.MessageBox(_("There seems to be auto saved data for " "this file: do you want to restore it?"), _("Auto save detected"), style=wx.ICON_QUESTION|wx.YES_NO) == wx.YES: common.restore_from_autosaved(infile) else: common.remove_autosaved(infile) self._open_app(infile) wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, open_from_history) wx.EVT_MENU(self, TREE_ID, self.show_tree) wx.EVT_MENU(self, PROPS_ID, self.show_props_window) wx.EVT_MENU(self, RAISE_ID, self.raise_all) wx.EVT_MENU(self, NEW_ID, self.new_app) wx.EVT_MENU(self, NEW_FROM_TEMPLATE_ID, self.new_app_from_template) wx.EVT_MENU(self, OPEN_ID, self.open_app) wx.EVT_MENU(self, SAVE_ID, self.save_app) wx.EVT_MENU(self, SAVE_AS_ID, self.save_app_as) wx.EVT_MENU(self, SAVE_TEMPLATE_ID, self.save_app_as_template) def generate_code(event): common.app_tree.app.generate_code() wx.EVT_MENU(self, GENERATE_CODE_ID, generate_code) wx.EVT_MENU(self, EXIT_ID, lambda e: self.Close()) wx.EVT_MENU(self, TUT_ID, self.show_tutorial) wx.EVT_MENU(self, ABOUT_ID, self.show_about_box) wx.EVT_MENU(self, PREFS_ID, self.edit_preferences) wx.EVT_MENU(self, MANAGE_TEMPLATES_ID, self.manage_templates) wx.EVT_MENU(self, IMPORT_ID, self.import_xrc) wx.EVT_MENU(self, RELOAD_ID, self.reload_app) PREVIEW_ID = wx.NewId() def preview(event): if common.app_tree.cur_widget is not None: p = misc.get_toplevel_widget(common.app_tree.cur_widget) if p is not None: p.preview(None) wx.EVT_MENU(self, PREVIEW_ID, preview) self.accel_table = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('N'), NEW_ID), (wx.ACCEL_CTRL, ord('O'), OPEN_ID), (wx.ACCEL_CTRL, ord('S'), SAVE_ID), (wx.ACCEL_CTRL | wx.ACCEL_SHIFT, ord('S'), SAVE_AS_ID), (wx.ACCEL_CTRL, ord('G'), GENERATE_CODE_ID), (wx.ACCEL_CTRL, ord('I'), IMPORT_ID), (0, wx.WXK_F1, TUT_ID), (wx.ACCEL_CTRL, ord('Q'), EXIT_ID), (0, wx.WXK_F5, RELOAD_ID), (0, wx.WXK_F2, TREE_ID), (0, wx.WXK_F3, PROPS_ID), (0, wx.WXK_F4, RAISE_ID), (wx.ACCEL_CTRL, ord('P'), PREVIEW_ID), ]) # Tutorial window ## self.tut_frame = None # layout # if there are custom components, add the toggle box... if custom_btns: main_sizer = wx.BoxSizer(wx.VERTICAL) show_core_custom = ToggleButtonBox( self, -1, [_("Core components"), _("Custom components")], 0) if misc.check_wx_version(2, 5): core_sizer = wx.FlexGridSizer( 0, config.preferences.buttons_per_row) custom_sizer = wx.FlexGridSizer( 0, config.preferences.buttons_per_row) else: core_sizer = wx.GridSizer(0, config.preferences.buttons_per_row) custom_sizer = wx.GridSizer(0, config.preferences.buttons_per_row) self.SetAutoLayout(True) # core components for b in core_btns: core_sizer.Add(b) for sb in sizer_btns: core_sizer.Add(sb) # custom components for b in custom_btns: custom_sizer.Add(b) if misc.check_wx_version(2, 5): custom_sizer.Show(b, False) custom_sizer.Layout() main_sizer.Add(show_core_custom, 0, wx.EXPAND) main_sizer.Add(core_sizer, 0, wx.EXPAND) main_sizer.Add(custom_sizer, 0, wx.EXPAND) self.SetSizer(main_sizer) if not misc.check_wx_version(2, 5): main_sizer.Show(custom_sizer, False) #main_sizer.Show(1, False) main_sizer.Fit(self) # events to display core/custom components if misc.check_wx_version(2, 5): def on_show_core_custom(event): show_core = True show_custom = False if event.GetValue() == 1: show_core = False show_custom = True for b in custom_btns: custom_sizer.Show(b, show_custom) for b in core_btns: core_sizer.Show(b, show_core) for b in sizer_btns: core_sizer.Show(b, show_core) core_sizer.Layout() custom_sizer.Layout() main_sizer.Layout() else: def on_show_core_custom(event): to_show = core_sizer to_hide = custom_sizer if event.GetValue() == 1: to_show, to_hide = to_hide, to_show main_sizer.Show(to_show, True) main_sizer.Show(to_hide, False) main_sizer.Layout() EVT_TOGGLE_BOX(self, show_core_custom.GetId(), on_show_core_custom) # ... otherwise (the common case), just add the palette of core buttons else: sizer = wx.GridSizer(0, config.preferences.buttons_per_row) self.SetAutoLayout(True) # core components for b in core_btns: sizer.Add(b) for sb in sizer_btns: sizer.Add(sb) self.SetSizer(sizer) sizer.Fit(self) # Properties window frame_style = wx.DEFAULT_FRAME_STYLE frame_tool_win = config.preferences.frame_tool_win if frame_tool_win: frame_style |= wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT frame_style &= ~wx.MINIMIZE_BOX if wx.Platform != '__WXGTK__': frame_style |= wx.FRAME_TOOL_WINDOW self.frame2 = wx.Frame(self, -1, _('Properties - <app>'), style=frame_style) self.frame2.SetBackgroundColour( wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) self.frame2.SetIcon(icon) sizer_tmp = wx.BoxSizer(wx.VERTICAL) property_panel = wxGladePropertyPanel(self.frame2, -1) #---- 2003-06-22 Fix for what seems to be a GTK2 bug (notebooks) misc.hidden_property_panel = wx.Panel(self.frame2, -1) sz = wx.BoxSizer(wx.VERTICAL) sz.Add(property_panel, 1, wx.EXPAND) sz.Add(misc.hidden_property_panel, 1, wx.EXPAND) self.frame2.SetSizer(sz) sz.Show(misc.hidden_property_panel, False) self.property_frame = self.frame2 #-------------------------------------------------------- property_panel.SetAutoLayout(True) self.hidden_frame = wx.Frame(self, -1, "") self.hidden_frame.Hide() sizer_tmp.Add(property_panel, 1, wx.EXPAND) self.frame2.SetAutoLayout(True) self.frame2.SetSizer(sizer_tmp) sizer_tmp = wx.BoxSizer(wx.VERTICAL) def hide_frame2(event): #menu_bar.Check(PROPS_ID, False) self.frame2.Hide() wx.EVT_CLOSE(self.frame2, hide_frame2) wx.EVT_CLOSE(self, self.cleanup) common.property_panel = property_panel # Tree of widgets self.tree_frame = wx.Frame(self, -1, _('wxGlade: Tree'), style=frame_style) self.tree_frame.SetIcon(icon) import application app = application.Application(common.property_panel) common.app_tree = WidgetTree(self.tree_frame, app) self.tree_frame.SetSize((300, 300)) app.notebook.Show() sizer_tmp.Add(app.notebook, 1, wx.EXPAND) property_panel.SetSizer(sizer_tmp) sizer_tmp.Fit(property_panel) def on_tree_frame_close(event): #menu_bar.Check(TREE_ID, False) self.tree_frame.Hide() wx.EVT_CLOSE(self.tree_frame, on_tree_frame_close) # check to see if there are some remembered values prefs = config.preferences if prefs.remember_geometry: #print 'initializing geometry' try: x, y, w, h = prefs.get_geometry('main') misc.set_geometry(self, (x, y)) except Exception, e: pass misc.set_geometry(self.frame2, prefs.get_geometry('properties')) misc.set_geometry(self.tree_frame, prefs.get_geometry('tree'))
def do_layout(self): self.label.Enable(False) self.id.Enable(False) self.name.Enable(False) self.help_str.Enable(False) self.event_handler.Enable(False) self.check_radio.Enable(False) sizer = wx.BoxSizer(wx.VERTICAL) sizer2 = wx.StaticBoxSizer(self._staticbox, wx.VERTICAL) self.label.SetSize((150, -1)) self.id.SetSize((150, -1)) self.name.SetSize((150, -1)) self.help_str.SetSize((150, -1)) self.event_handler.SetSize((150, -1)) szr = wx.FlexGridSizer(0, 2) if misc.check_wx_version(2, 5, 2): flag = wx.FIXED_MINSIZE else: flag = 0 label_flag = wx.ALIGN_CENTER_VERTICAL szr.Add(wx.StaticText(self, -1, _("Id ")), flag=label_flag) szr.Add(self.id, flag=flag) szr.Add(wx.StaticText(self, -1, _("Label ")), flag=label_flag) szr.Add(self.label, flag=flag) szr.Add(wx.StaticText(self, -1, _("Name ")), flag=label_flag) szr.Add(self.name, flag=flag) szr.Add(wx.StaticText(self, -1, _("Help String ")), flag=label_flag) szr.Add(self.help_str, flag=flag) szr.Add(wx.StaticText(self, -1, _("Event Handler ")), flag=label_flag) szr.Add(self.event_handler, flag=flag) sizer2.Add(szr, 1, wx.ALL|wx.EXPAND, 5) sizer2.Add(self.check_radio, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 4) szr = wx.GridSizer(0, 2, 3, 3) szr.Add(self.add, 0, wx.EXPAND); szr.Add(self.remove, 0, wx.EXPAND) sizer2.Add(szr, 0, wx.EXPAND) sizer2.Add(self.add_sep, 0, wx.TOP|wx.EXPAND, 3) sizer3 = wx.BoxSizer(wx.VERTICAL) sizer3.Add(self.menu_items, 1, wx.ALL|wx.EXPAND, 5) sizer4 = wx.BoxSizer(wx.HORIZONTAL) sizer4.Add(self.move_up, 0, wx.LEFT|wx.RIGHT, 3) sizer4.Add(self.move_down, 0, wx.LEFT|wx.RIGHT, 5) sizer4.Add(self.move_left, 0, wx.LEFT|wx.RIGHT, 5) sizer4.Add(self.move_right, 0, wx.LEFT|wx.RIGHT, 5) sizer3.Add(sizer4, 0, wx.ALIGN_CENTER|wx.ALL, 5) szr = wx.BoxSizer(wx.HORIZONTAL) szr.Add(sizer3, 1, wx.ALL|wx.EXPAND, 5) szr.Add(sizer2, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5) sizer.Add(szr, 1, wx.EXPAND) sizer2 = wx.BoxSizer(wx.HORIZONTAL) sizer2.Add(self.ok, 0, wx.ALL, 5) sizer2.Add(self.apply, 0, wx.ALL, 5) sizer2.Add(self.cancel, 0, wx.ALL, 5) sizer.Add(sizer2, 0, wx.ALL|wx.ALIGN_CENTER, 3) self.SetAutoLayout(1) self.SetSizer(sizer) sizer.Fit(self) self.SetSize((-1, 350)) self.CenterOnScreen()
class Sizeritem: if common.use_gui: flags = { 'wxALL': wx.ALL, 'wxEXPAND': wx.EXPAND, 'wxALIGN_RIGHT': wx.ALIGN_RIGHT, 'wxALIGN_BOTTOM': wx.ALIGN_BOTTOM, 'wxALIGN_CENTER_HORIZONTAL': wx.ALIGN_CENTER_HORIZONTAL, 'wxALIGN_CENTER_VERTICAL': wx.ALIGN_CENTER_VERTICAL, 'wxLEFT': wx.LEFT, 'wxRIGHT': wx.RIGHT, 'wxTOP': wx.TOP, 'wxBOTTOM': wx.BOTTOM, 'wxSHAPED': wx.SHAPED, 'wxADJUST_MINSIZE': wx.ADJUST_MINSIZE, } import misc if misc.check_wx_version(2, 5, 2): flags['wxFIXED_MINSIZE'] = wx.FIXED_MINSIZE else: flags['wxFIXED_MINSIZE'] = 0 def __init__(self): self.option = self.border = 0 self.flag = 0 def __getitem__(self, name): if name != 'flag': return (None, lambda v: setattr(self, name, v)) def get_flag(v): val = reduce(lambda a, b: a | b, [Sizeritem.flags[t] for t in v.split("|")]) setattr(self, name, val) return (None, get_flag) ## lambda v: setattr(self, name, ## reduce(lambda a,b: a|b, ## [Sizeritem.flags[t] for t in ## v.split("|")]))) def flag_str(self): # returns the flag attribute as a string of tokens separated # by a '|' (used during the code generation) if hasattr(self, 'flag_s'): return self.flag_s else: try: tmp = {} for k in self.flags: if self.flags[k] & self.flag: tmp[k] = 1 # patch to make wxALL work remove_wxall = 4 for k in ('wxLEFT', 'wxRIGHT', 'wxTOP', 'wxBOTTOM'): if k in tmp: remove_wxall -= 1 if remove_wxall: try: del tmp['wxALL'] except KeyError: pass else: for k in ('wxLEFT', 'wxRIGHT', 'wxTOP', 'wxBOTTOM'): try: del tmp[k] except KeyError: pass tmp['wxALL'] = 1 tmp = '|'.join(tmp.keys()) except: print 'EXCEPTION: self.flags = %s, self.flag = %s' % \ (self.flags, repr(self.flag)) raise if tmp: return tmp else: return '0'
def create_widget(self): self.widget = wx.Notebook(self.parent.widget, self.id, style=self.style) if not misc.check_wx_version(2, 5, 2): self.nb_sizer = wx.NotebookSizer(self.widget)
def finish_widget_creation(self): ManagedBase.finish_widget_creation(self) # replace 'self' with 'self.nb_sizer' in 'self.sizer' if not misc.check_wx_version(2, 5, 2): self.sizer._fix_notebook(self.pos, self.nb_sizer)
def do_layout(self): self.label.Enable(False) self.id.Enable(False) self.help_str.Enable(False) self.long_help_str.Enable(False) self.event_handler.Enable(False) self.bitmap1.Enable(False) self.bitmap2.Enable(False) self.check_radio.Enable(False) sizer = wx.BoxSizer(wx.VERTICAL) sizer2 = wx.StaticBoxSizer(self._staticbox, wx.VERTICAL) self.label.SetSize((150, -1)) self.id.SetSize((150, -1)) self.help_str.SetSize((150, -1)) self.long_help_str.SetSize((150, -1)) self.event_handler.SetSize((150, -1)) szr = wx.FlexGridSizer(0, 2) if misc.check_wx_version(2, 5, 2): flag = wx.FIXED_MINSIZE else: flag = 0 label_flag = wx.ALIGN_CENTER_VERTICAL szr.Add(wx.StaticText(self, -1, _("Id ")), flag=label_flag) szr.Add(self.id, flag=flag) szr.Add(wx.StaticText(self, -1, _("Label ")), flag=label_flag) szr.Add(self.label, flag=flag) szr.Add(wx.StaticText(self, -1, _("Short Help ")), flag=label_flag) szr.Add(self.help_str, flag=flag) szr.Add(wx.StaticText(self, -1, _("Long Help ")), flag=label_flag) szr.Add(self.long_help_str, flag=flag) szr.Add(wx.StaticText(self, -1, _("Event Handler ")), flag=label_flag) szr.Add(self.event_handler, flag=flag) sizer2.Add(szr, 1, wx.ALL|wx.EXPAND, 5) label_w = self.bitmap1.browseButton.GetTextExtent('...')[0] sizer2.Add(self.bitmap1, 0, wx.EXPAND) sizer2.Add(self.bitmap2, 0, wx.EXPAND) sizer2.Add(self.check_radio, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 4) szr = wx.GridSizer(0, 2, 3, 3) szr.Add(self.add, 0, wx.EXPAND); szr.Add(self.remove, 0, wx.EXPAND) sizer2.Add(szr, 0, wx.EXPAND) sizer2.Add(self.add_sep, 0, wx.TOP|wx.EXPAND, 3) sizer3 = wx.BoxSizer(wx.VERTICAL) sizer3.Add(self.tool_items, 1, wx.ALL|wx.EXPAND, 5) sizer4 = wx.BoxSizer(wx.HORIZONTAL) sizer4.Add(self.move_up, 0, wx.LEFT|wx.RIGHT, 3) sizer4.Add(self.move_down, 0, wx.LEFT|wx.RIGHT, 5) sizer3.Add(sizer4, 0, wx.ALIGN_CENTER|wx.ALL, 5) szr = wx.BoxSizer(wx.HORIZONTAL) szr.Add(sizer3, 1, wx.ALL|wx.EXPAND, 5) szr.Add(sizer2, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5) sizer.Add(szr, 1, wx.EXPAND) sizer2 = wx.BoxSizer(wx.HORIZONTAL) sizer2.Add(self.ok, 0, wx.ALL, 5) sizer2.Add(self.apply, 0, wx.ALL, 5) sizer2.Add(self.cancel, 0, wx.ALL, 5) sizer.Add(sizer2, 0, wx.ALL|wx.ALIGN_CENTER, 3) self.SetAutoLayout(1) self.SetSizer(sizer) sizer.Fit(self) #self.SetSize((-1, 350)) self.CenterOnScreen()
def __init__(self, name, parent, id, title, property_window, style=wx.DEFAULT_DIALOG_STYLE, show=True, klass='wxDialog'): TopLevelBase.__init__(self, name, klass, parent, id, property_window, show=show, title=title) self.base = 'wxDialog' self.style = style prop = self.properties # style property self.access_functions['style'] = (self.get_style, self.set_style) style_labels = ('#section#' + _('Style'), 'wxDEFAULT_DIALOG_STYLE', 'wxDIALOG_MODAL', 'wxCAPTION', 'wxRESIZE_BORDER', 'wxSYSTEM_MENU') if misc.check_wx_version(2, 5): style_labels += ('wxCLOSE_BOX', 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX') style_labels += ('wxTHICK_FRAME', 'wxSTAY_ON_TOP', 'wxNO_3D', 'wxDIALOG_NO_PARENT', 'wxNO_FULL_REPAINT_ON_RESIZE', 'wxFULL_REPAINT_ON_RESIZE', 'wxCLIP_CHILDREN') #note that the tooltips are only for wxPython>=2.5 self.tooltips = (_("Equivalent to a combination of wxCAPTION, wxCLOSE_BOX and wxSYSTEM_MENU (the last one is not used under Unix)"), _("NO DESCRIPTION"), _("Puts a caption on the dialog box."), _("Display a resizeable frame around the window."), _("Display a system menu."), _("Displays a close box on the frame."), _("Displays a maximize box on the dialog."), _("Displays a minimize box on the dialog."), _("Display a thick frame around the window."), _("The dialog stays on top of all other windows."), _("Under Windows, specifies that the child controls should not have 3D borders unless specified in the control."), _("By default, a dialog created with a NULL parent window will be given the application's top level window as parent. Use this style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs."), _("NO DESCRIPTION"), _("NO DESCRIPTION"), _("NO DESCRIPTION")) self.style_pos = (wx.DEFAULT_DIALOG_STYLE, wx.DIALOG_MODAL, wx.CAPTION, wx.RESIZE_BORDER, wx.SYSTEM_MENU) if misc.check_wx_version(2, 5): self.style_pos += (wx.CLOSE_BOX, wx.MAXIMIZE_BOX, wx.MINIMIZE_BOX) self.style_pos += (wx.THICK_FRAME, wx.STAY_ON_TOP, wx.NO_3D, wx.DIALOG_NO_PARENT, wx.NO_FULL_REPAINT_ON_RESIZE, wx.FULL_REPAINT_ON_RESIZE, wx.CLIP_CHILDREN) prop['style'] = CheckListProperty(self, 'style', None, style_labels, tooltips=self.tooltips) # icon property self.icon = "" self.access_functions['icon'] = (self.get_icon, self.set_icon) prop['icon'] = FileDialogProperty(self, 'icon', None, style=wx.OPEN|wx.FILE_MUST_EXIST, can_disable=True, label=_("icon")) # centered property self.centered = False self.access_functions['centered'] = (self.get_centered, self.set_centered) prop['centered'] = CheckBoxProperty(self, 'centered', None, label=_("centered")) # size hints property self.sizehints = False self.access_functions['sizehints'] = (self.get_sizehints, self.set_sizehints) prop['sizehints'] = CheckBoxProperty(self, 'sizehints', None, label=_('Set Size Hints'))
def __init__(self, property_window): self.property_window = property_window self.notebook = wx.Notebook(self.property_window, -1) if not misc.check_wx_version(2, 5, 2): nb_sizer = wx.NotebookSizer(self.notebook) self.notebook.sizer = nb_sizer else: self.notebook.sizer = None self.notebook.SetAutoLayout(True) self.notebook.Hide() panel = wx.ScrolledWindow( self.notebook, -1, style=wx.TAB_TRAVERSAL|wx.FULL_REPAINT_ON_RESIZE) self.name = "app" # name of the wxApp instance to generate self.__saved = True # if True, there are no changes to save self.__filename = None # name of the output xml file self.klass = "MyApp" self.codegen_opt = 0 # if != 0, generates a separate file # for each class def set_codegen_opt(value): try: opt = int(value) except ValueError: pass else: self.codegen_opt = opt self.output_path = "" self.language = 'python' # output language def get_output_path(): return os.path.expanduser(self.output_path) def set_output_path(value): self.output_path = value self.is_template = False self.use_gettext = False def set_use_gettext(value): self.use_gettext = bool(int(value)) self.for_version = wx.VERSION_STRING[:3] def set_for_version(value): self.for_version = self.for_version_prop.get_str_value() self.access_functions = { 'name': (lambda : self.name, self.set_name), 'class': (lambda : self.klass, self.set_klass), 'code_generation': (lambda : self.codegen_opt, set_codegen_opt), 'output_path': (get_output_path, set_output_path), 'language': (self.get_language, self.set_language), 'encoding': (self.get_encoding, self.set_encoding), 'use_gettext': (lambda : self.use_gettext, set_use_gettext), 'for_version': (lambda : self.for_version, set_for_version), } self.name_prop = TextProperty(self, "name", panel, True) self.klass_prop = TextProperty(self, "class", panel, True) self.encoding = self._get_default_encoding() self.encoding_prop = TextProperty(self, 'encoding', panel) self.use_gettext_prop = CheckBoxProperty(self, "use_gettext", panel, _("Enable gettext support")) TOP_WIN_ID = wx.NewId() self.top_win_prop = wx.Choice(panel, TOP_WIN_ID, choices=[], size=(1, -1)) self.top_window = '' # name of the top window of the generated app self.codegen_prop = RadioProperty(self, "code_generation", panel, [_("Single file"), _("Separate file for" \ " each class")], label=_("Code Generation")) ext = getattr(common.code_writers.get('python'), 'default_extensions', []) wildcard = [] for e in ext: wildcard.append('%s files (*.%s)|*.%s' % ('Python', e, e)) wildcard.append('All files|*') dialog = FileDirDialog(self, panel, '|'.join(wildcard), _("Select output file"), _("Select output directory"), wx.SAVE|wx.OVERWRITE_PROMPT) _writers = common.code_writers.keys() columns = 3 self.codewriters_prop = RadioProperty(self, "language", panel, _writers, columns=columns) self.codewriters_prop.set_str_value('python') self.for_version_prop = RadioProperty(self, "for_version", panel, ['2.4', '2.6', '2.8'], columns=3, label=_("wxWidgets compatibility")) self.for_version_prop.set_str_value(self.for_version) # ALB 2004-01-18 self.access_functions['use_new_namespace'] = ( self.get_use_old_namespace, self.set_use_old_namespace) self.use_old_namespace_prop = CheckBoxProperty( self, 'use_new_namespace', panel, _('Use old "from wxPython.wx"\n' 'import (python output only)')) # `overwrite' property - added 2003-07-15 self.overwrite = False def get_overwrite(): return self.overwrite def set_overwrite(val): self.overwrite = bool(int(val)) self.access_functions['overwrite'] = (get_overwrite, set_overwrite) self.overwrite_prop = CheckBoxProperty(self, 'overwrite', panel, _('Overwrite existing sources')) self.outpath_prop = DialogProperty(self, "output_path", panel, dialog, label=_('Output path')) BTN_ID = wx.NewId() btn = wx.Button(panel, BTN_ID, _("Generate code")) # layout of self.notebook sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.name_prop.panel, 0, wx.EXPAND) sizer.Add(self.klass_prop.panel, 0, wx.EXPAND) sizer.Add(self.encoding_prop.panel, 0, wx.EXPAND) sizer.Add(self.use_gettext_prop.panel, 0, wx.EXPAND) szr = wx.BoxSizer(wx.HORIZONTAL) from widget_properties import _label_initial_width as _w label = wx.StaticText(panel, -1, _("Top window"), size=(_w, -1)) label.SetToolTip(wx.ToolTip(_("Top window"))) szr.Add(label, 2, wx.ALL|wx.ALIGN_CENTER, 3) szr.Add(self.top_win_prop, 5, wx.ALL|wx.ALIGN_CENTER, 3) sizer.Add(szr, 0, wx.EXPAND) sizer.Add(self.codegen_prop.panel, 0, wx.ALL|wx.EXPAND, 4) sizer.Add(self.codewriters_prop.panel, 0, wx.ALL|wx.EXPAND, 4) sizer.Add(self.for_version_prop.panel, 0, wx.ALL|wx.EXPAND, 4) sizer.Add(self.use_old_namespace_prop.panel, 0, wx.EXPAND) sizer.Add(self.overwrite_prop.panel, 0, wx.EXPAND) sizer.Add(self.outpath_prop.panel, 0, wx.EXPAND) sizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5) panel.SetAutoLayout(True) panel.SetSizer(sizer) sizer.Layout() sizer.Fit(panel) h = panel.GetSize()[1] self.notebook.AddPage(panel, _("Application")) import math panel.SetScrollbars(1, 5, 1, int(math.ceil(h/5.0))) wx.EVT_BUTTON(btn, BTN_ID, self.generate_code) wx.EVT_CHOICE(self.top_win_prop, TOP_WIN_ID, self.set_top_window) # this is here to keep the interface similar to the various widgets # (to simplify Tree) self.widget = None # this is always None
def __init__(self, name, klass, parent, property_window): custom_class = parent is None EditBase.__init__(self, name, klass, parent, wx.NewId(), property_window, custom_class=custom_class, show=False) self.base = 'wx.ToolBar' def nil(*args): return () self.tools = [] # list of Tool objects self._tb = None # the real toolbar self.style = 0 self.access_functions['style'] = (self.get_style, self.set_style) self.style_pos = [wx.TB_FLAT, wx.TB_DOCKABLE, wx.TB_3DBUTTONS] if misc.check_wx_version(2, 3, 3): self.style_pos += [ wx.TB_TEXT, wx.TB_NOICONS, wx.TB_NODIVIDER, wx.TB_NOALIGN ] if misc.check_wx_version(2, 5, 0): self.style_pos += [wx.TB_HORZ_LAYOUT, wx.TB_HORZ_TEXT] style_labels = [ '#section#' + _('Style'), 'wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_3DBUTTONS' ] if misc.check_wx_version(2, 3, 3): style_labels += [ 'wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER', 'wxTB_NOALIGN' ] if misc.check_wx_version(2, 5, 0): style_labels += ['wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT'] self.properties['style'] = CheckListProperty(self, 'style', None, style_labels) self.bitmapsize = '16, 15' self.access_functions['bitmapsize'] = (self.get_bitmapsize, self.set_bitmapsize) self.properties['bitmapsize'] = TextProperty(self, 'bitmapsize', None, can_disable=True, label=_("bitmapsize")) self.margins = '0, 0' self.access_functions['margins'] = (self.get_margins, self.set_margins) self.properties['margins'] = TextProperty(self, 'margins', None, can_disable=True, label=_("margins")) self.access_functions['tools'] = (self.get_tools, self.set_tools) prop = self.properties['tools'] = ToolsProperty(self, 'tools', None) self.packing = 1 self.access_functions['packing'] = (self.get_packing, self.set_packing) self.properties['packing'] = SpinProperty(self, 'packing', None, r=(0, 100), can_disable=True, label=_("packing")) self.separation = 5 self.access_functions['separation'] = (self.get_separation, self.set_separation) self.properties['separation'] = SpinProperty(self, 'separation', None, r=(0, 100), can_disable=True, label=_("separation")) # 2003-05-07 preview support PreviewMixin.__init__(self)
def display(self, parent): """\ Actually builds the grid to set the value of the property interactively """ self.panel = wx.Panel(parent, -1) # why if the grid is not on this # panel it is not displayed??? label = getattr(self, 'label', _mangle(self.dispName)) sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, -1, label), wx.VERTICAL) self.btn_id = wx.NewId() self.btn = wx.Button(self.panel, self.btn_id, _(" Apply "), style=wx.BU_EXACTFIT) if self.can_add: self.add_btn = wx.Button(self.panel, self.btn_id+1, _(" Add "), style=wx.BU_EXACTFIT) if self.can_insert: self.insert_btn = wx.Button(self.panel, self.btn_id+3, _(" Insert "), style=wx.BU_EXACTFIT) if self.can_remove: self.remove_btn = wx.Button(self.panel, self.btn_id+2, _(" Remove "), style=wx.BU_EXACTFIT) self.grid = wx.grid.Grid(self.panel, -1) self.grid.CreateGrid(self.rows, len(self.cols)) if misc.check_wx_version(2, 3, 3): self.grid.SetMargins(0, 0) else: # wx 2.3.2 seems to have some problems with grid scrollbars... self.grid.SetMargins(0, self.grid.GetDefaultRowSize()) for i in range(len(self.cols)): self.grid.SetColLabelValue(i, misc.wxstr(self.cols[i][0])) GridProperty.col_format[self.cols[i][1]](self.grid, i) self.cols = len(self.cols) self.grid.SetRowLabelSize(0) self.grid.SetColLabelSize(20) self.btn_sizer = wx.BoxSizer(wx.HORIZONTAL) _w = self.btn.GetTextExtent(self.btn.GetLabel())[0] if misc.check_wx_version(2, 5, 2): extra_flag = wx.FIXED_MINSIZE else: extra_flag = 0 #self.btn.SetSize((_w, -1)) self.btn_sizer.Add(self.btn, 0, extra_flag) if self.can_add: _w = self.add_btn.GetTextExtent(self.add_btn.GetLabel())[0] #self.add_btn.SetSize((_w, -1)) self.btn_sizer.Add(self.add_btn, 0, wx.LEFT|wx.RIGHT|extra_flag, 4) wx.EVT_BUTTON(self.add_btn, self.btn_id+1, self.add_row) if self.can_insert: _w = self.insert_btn.GetTextExtent(self.insert_btn.GetLabel())[0] #self.insert_btn.SetSize((_w, -1)) self.btn_sizer.Add( self.insert_btn, 0, wx.LEFT|wx.RIGHT|extra_flag, 4) wx.EVT_BUTTON(self.insert_btn, self.btn_id+3, self.insert_row) if self.can_remove: _w = self.remove_btn.GetTextExtent(self.remove_btn.GetLabel())[0] #self.remove_btn.SetSize((_w, -1)) self.btn_sizer.Add(self.remove_btn, 0, extra_flag) wx.EVT_BUTTON(self.remove_btn, self.btn_id+2, self.remove_row) sizer.Add(self.btn_sizer, 0, wx.BOTTOM|wx.EXPAND, 2) sizer.Add(self.grid, 1, wx.EXPAND) self.panel.SetAutoLayout(1) self.panel.SetSizer(sizer) self.panel.SetSize(sizer.GetMinSize()) wx.grid.EVT_GRID_SELECT_CELL(self.grid, self.on_select_cell) self.bind_event(self.on_change_val) self.set_value(self.val)
def do_layout(self): self.label.Enable(False) self.id.Enable(False) self.help_str.Enable(False) self.long_help_str.Enable(False) self.event_handler.Enable(False) self.bitmap1.Enable(False) self.bitmap2.Enable(False) self.check_radio.Enable(False) sizer = wx.BoxSizer(wx.VERTICAL) sizer2 = wx.StaticBoxSizer(self._staticbox, wx.VERTICAL) self.label.SetSize((150, -1)) self.id.SetSize((150, -1)) self.help_str.SetSize((150, -1)) self.long_help_str.SetSize((150, -1)) self.event_handler.SetSize((150, -1)) szr = wx.FlexGridSizer(0, 2) if misc.check_wx_version(2, 5, 2): flag = wx.FIXED_MINSIZE else: flag = 0 label_flag = wx.ALIGN_CENTER_VERTICAL szr.Add(wx.StaticText(self, -1, _("Id ")), flag=label_flag) szr.Add(self.id, flag=flag) szr.Add(wx.StaticText(self, -1, _("Label ")), flag=label_flag) szr.Add(self.label, flag=flag) szr.Add(wx.StaticText(self, -1, _("Short Help ")), flag=label_flag) szr.Add(self.help_str, flag=flag) szr.Add(wx.StaticText(self, -1, _("Long Help ")), flag=label_flag) szr.Add(self.long_help_str, flag=flag) szr.Add(wx.StaticText(self, -1, _("Event Handler ")), flag=label_flag) szr.Add(self.event_handler, flag=flag) sizer2.Add(szr, 1, wx.ALL | wx.EXPAND, 5) label_w = self.bitmap1.browseButton.GetTextExtent('...')[0] sizer2.Add(self.bitmap1, 0, wx.EXPAND) sizer2.Add(self.bitmap2, 0, wx.EXPAND) sizer2.Add(self.check_radio, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM, 4) szr = wx.GridSizer(0, 2, 3, 3) szr.Add(self.add, 0, wx.EXPAND) szr.Add(self.remove, 0, wx.EXPAND) sizer2.Add(szr, 0, wx.EXPAND) sizer2.Add(self.add_sep, 0, wx.TOP | wx.EXPAND, 3) sizer3 = wx.BoxSizer(wx.VERTICAL) sizer3.Add(self.tool_items, 1, wx.ALL | wx.EXPAND, 5) sizer4 = wx.BoxSizer(wx.HORIZONTAL) sizer4.Add(self.move_up, 0, wx.LEFT | wx.RIGHT, 3) sizer4.Add(self.move_down, 0, wx.LEFT | wx.RIGHT, 5) sizer3.Add(sizer4, 0, wx.ALIGN_CENTER | wx.ALL, 5) szr = wx.BoxSizer(wx.HORIZONTAL) szr.Add(sizer3, 1, wx.ALL | wx.EXPAND, 5) szr.Add(sizer2, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 5) sizer.Add(szr, 1, wx.EXPAND) sizer2 = wx.BoxSizer(wx.HORIZONTAL) sizer2.Add(self.ok, 0, wx.ALL, 5) sizer2.Add(self.apply, 0, wx.ALL, 5) sizer2.Add(self.cancel, 0, wx.ALL, 5) sizer.Add(sizer2, 0, wx.ALL | wx.ALIGN_CENTER, 3) self.SetAutoLayout(1) self.SetSizer(sizer) sizer.Fit(self) #self.SetSize((-1, 350)) self.CenterOnScreen()
def __init__(self, parent=None): wx.Dialog.__init__(self, parent, -1, _('About wxGlade')) class HtmlWin(wx.html.HtmlWindow): def OnLinkClicked(self, linkinfo): href = linkinfo.GetHref() if href == 'show_license': from wx.lib.dialogs import ScrolledMessageDialog try: license = open(os.path.join(common.wxglade_path, 'license.txt')) dlg = ScrolledMessageDialog(self, license.read(), _("wxGlade - License")) license.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox(_("Can't find the license!\n" "You can get a copy at \n" "http://www.opensource.org/licenses/" "mit-license.php"), _("Error"), wx.OK|wx.CENTRE|wx.ICON_EXCLAMATION) elif href == 'show_credits': from wx.lib.dialogs import ScrolledMessageDialog try: credits = open(os.path.join(common.wxglade_path, 'credits.txt')) dlg = ScrolledMessageDialog(self, credits.read(), _("wxGlade - Credits")) credits.close() dlg.ShowModal() dlg.Destroy() except IOError: wx.MessageBox(_("Can't find the credits file!\n"), _("Oops!"), wx.OK|wx.CENTRE|wx.ICON_EXCLAMATION) else: import webbrowser webbrowser.open(linkinfo.GetHref(), new=True) html = HtmlWin(self, -1, size=(400, -1)) if misc.check_wx_version(2, 5, 3): try: html.SetStandardFonts() except AttributeError: pass py_version = sys.version.split()[0] bgcolor = misc.color_to_string(self.GetBackgroundColour()) icon_path = os.path.join(common.wxglade_path, 'icons/wxglade_small.png') html.SetPage(self.text % (bgcolor, icon_path, common.version, py_version, wx.__version__)) ir = html.GetInternalRepresentation() ir.SetIndent(0, wx.html.HTML_INDENT_ALL) html.SetSize((ir.GetWidth(), ir.GetHeight())) szr = wx.BoxSizer(wx.VERTICAL) szr.Add(html, 0, wx.TOP|wx.ALIGN_CENTER, 10) szr.Add(wx.StaticLine(self, -1), 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 20) szr2 = wx.BoxSizer(wx.HORIZONTAL) btn = wx.Button(self, wx.ID_OK, _("OK")) btn.SetDefault() szr2.Add(btn) if wx.Platform == '__WXGTK__': extra_border = 5 # border around a default button else: extra_border = 0 szr.Add(szr2, 0, wx.ALL|wx.ALIGN_RIGHT, 20 + extra_border) self.SetAutoLayout(True) self.SetSizer(szr) szr.Fit(self) self.Layout() if parent: self.CenterOnParent() else: self.CenterOnScreen()
def _get_first_child(self, item): if misc.check_wx_version(2, 5): return self.GetFirstChild(item) else: return self.GetFirstChild(item, 1)
class FontDialogProperty(DialogProperty): font_families_to = { 'default': wx.DEFAULT, 'decorative': wx.DECORATIVE, 'roman': wx.ROMAN, 'swiss': wx.SWISS, 'script':wx.SCRIPT, 'modern': wx.MODERN } font_families_from = _reverse_dict(font_families_to) font_styles_to = { 'normal': wx.NORMAL, 'slant': wx.SLANT, 'italic': wx.ITALIC } font_styles_from = _reverse_dict(font_styles_to) font_weights_to = {'normal': wx.NORMAL, 'light': wx.LIGHT, 'bold': wx.BOLD } font_weights_from = _reverse_dict(font_weights_to) if misc.check_wx_version(2, 3, 3): font_families_to['teletype'] = wx.TELETYPE font_families_from[wx.TELETYPE] = 'teletype' dialog = [None] def __init__(self, owner, name, parent=None, can_disable=True, label=None): if not self.dialog[0]: import font_dialog self.dialog[0] = font_dialog.wxGladeFontDialog(parent, -1, "") DialogProperty.__init__(self, owner, name, parent, self.dialog[0], can_disable, label=label) def display_dialog(self, event): try: props = eval(self.get_value()) except: import traceback; traceback.print_exc() else: if len(props) == 6: self.dialog.set_value(props) DialogProperty.display_dialog(self, event) def write(self, outfile=None, tabs=0): if self.is_active(): try: props = [_encode(s) for s in eval(self.get_value().strip())] except: import traceback traceback.print_exc() return if len(props) < 6: print _('error in the value of the property "%s"') % self.name return fwrite = outfile.write fwrite(' ' * tabs + '<%s>\n' % self.name) tstr = ' ' * (tabs+1) fwrite('%s<size>%s</size>\n' % (tstr, escape(props[0]))) fwrite('%s<family>%s</family>\n' % (tstr, escape(props[1]))) fwrite('%s<style>%s</style>\n' % (tstr, escape(props[2]))) fwrite('%s<weight>%s</weight>\n' % (tstr, escape(props[3]))) fwrite('%s<underlined>%s</underlined>\n' % (tstr, escape(props[4]))) fwrite('%s<face>%s</face>\n' % (tstr, escape(props[5]))) fwrite(' ' * tabs + '</%s>\n' % self.name) def toggle_active(self, active): DialogProperty.toggle_active(self, active) if not active: # restore the original value if toggled off font = self.owner._original['font'] if font is not None and self.owner.widget is not None: self.owner.widget.SetFont(font) self.owner.widget.Refresh() else: # restore the saved value getval, setval = self.owner[self.name] setval(getval())
def __init__(self, name, parent, id, title, property_window, style=wx.DEFAULT_DIALOG_STYLE, show=True, klass='wxDialog'): TopLevelBase.__init__(self, name, klass, parent, id, property_window, show=show, title=title) self.base = 'wxDialog' self.style = style prop = self.properties # style property self.access_functions['style'] = (self.get_style, self.set_style) style_labels = ('#section#' + _('Style'), 'wxDEFAULT_DIALOG_STYLE', 'wxDIALOG_MODAL', 'wxCAPTION', 'wxRESIZE_BORDER', 'wxSYSTEM_MENU') if misc.check_wx_version(2, 5): style_labels += ('wxCLOSE_BOX', 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX') style_labels += ('wxTHICK_FRAME', 'wxSTAY_ON_TOP', 'wxNO_3D', 'wxDIALOG_NO_PARENT', 'wxNO_FULL_REPAINT_ON_RESIZE', 'wxFULL_REPAINT_ON_RESIZE', 'wxCLIP_CHILDREN') #note that the tooltips are only for wxPython>=2.5 self.tooltips = ( _("Equivalent to a combination of wxCAPTION, wxCLOSE_BOX and wxSYSTEM_MENU (the last one is not used under Unix)" ), _("NO DESCRIPTION"), _("Puts a caption on the dialog box."), _("Display a resizeable frame around the window."), _("Display a system menu."), _("Displays a close box on the frame."), _("Displays a maximize box on the dialog."), _("Displays a minimize box on the dialog."), _("Display a thick frame around the window."), _("The dialog stays on top of all other windows."), _("Under Windows, specifies that the child controls should not have 3D borders unless specified in the control." ), _("By default, a dialog created with a NULL parent window will be given the application's top level window as parent. Use this style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs." ), _("NO DESCRIPTION"), _("NO DESCRIPTION"), _("NO DESCRIPTION")) self.style_pos = (wx.DEFAULT_DIALOG_STYLE, wx.DIALOG_MODAL, wx.CAPTION, wx.RESIZE_BORDER, wx.SYSTEM_MENU) if misc.check_wx_version(2, 5): self.style_pos += (wx.CLOSE_BOX, wx.MAXIMIZE_BOX, wx.MINIMIZE_BOX) self.style_pos += (wx.THICK_FRAME, wx.STAY_ON_TOP, wx.NO_3D, wx.DIALOG_NO_PARENT, wx.NO_FULL_REPAINT_ON_RESIZE, wx.FULL_REPAINT_ON_RESIZE, wx.CLIP_CHILDREN) prop['style'] = CheckListProperty(self, 'style', None, style_labels, tooltips=self.tooltips) # icon property self.icon = "" self.access_functions['icon'] = (self.get_icon, self.set_icon) prop['icon'] = FileDialogProperty(self, 'icon', None, style=wx.OPEN | wx.FILE_MUST_EXIST, can_disable=True, label=_("icon")) # centered property self.centered = False self.access_functions['centered'] = (self.get_centered, self.set_centered) prop['centered'] = CheckBoxProperty(self, 'centered', None, label=_("centered")) # size hints property self.sizehints = False self.access_functions['sizehints'] = (self.get_sizehints, self.set_sizehints) prop['sizehints'] = CheckBoxProperty(self, 'sizehints', None, label=_('Set Size Hints'))
class wxGladeFontDialog(wx.Dialog): font_families_to = { 'default': wx.DEFAULT, 'decorative': wx.DECORATIVE, 'roman': wx.ROMAN, 'swiss': wx.SWISS, 'script': wx.SCRIPT, 'modern': wx.MODERN } font_families_from = _reverse_dict(font_families_to) font_styles_to = { 'normal': wx.NORMAL, 'slant': wx.SLANT, 'italic': wx.ITALIC } font_styles_from = _reverse_dict(font_styles_to) font_weights_to = {'normal': wx.NORMAL, 'light': wx.LIGHT, 'bold': wx.BOLD} font_weights_from = _reverse_dict(font_weights_to) import misc if misc.check_wx_version(2, 3, 3): font_families_to['teletype'] = wx.TELETYPE font_families_from[wx.TELETYPE] = 'teletype' def __init__(self, *args, **kwds): # begin wxGlade: wxGladeFontDialog.__init__ kwds["style"] = wx.DEFAULT_DIALOG_STYLE wx.Dialog.__init__(self, *args, **kwds) self.label_2_copy = wx.StaticText(self, -1, _("Family:")) self.label_3_copy = wx.StaticText(self, -1, _("Style:")) self.label_4_copy = wx.StaticText(self, -1, _("Weight:")) self.family = wx.Choice(self, -1, choices=[ "Default", "Decorative", "Roman", "Script", "Swiss", "Modern" ]) self.style = wx.Choice(self, -1, choices=["Normal", "Slant", "Italic"]) self.weight = wx.Choice(self, -1, choices=["Normal", "Light", "Bold"]) self.label_1 = wx.StaticText(self, -1, _("Size in points:")) self.point_size = wx.SpinCtrl(self, -1, "", min=0, max=100) self.underline = wx.CheckBox(self, -1, _("Underlined")) self.font_btn = wx.Button(self, -1, _("Specific font...")) self.static_line_1 = wx.StaticLine(self, -1) self.ok_btn = wx.Button(self, wx.ID_OK, _("OK")) self.cancel_btn = wx.Button(self, wx.ID_CANCEL, _("Cancel")) self.__set_properties() self.__do_layout() # end wxGlade self.value = None wx.EVT_BUTTON(self, self.font_btn.GetId(), self.choose_specific_font) wx.EVT_BUTTON(self, self.ok_btn.GetId(), self.on_ok) def choose_specific_font(self, event): dialog = wx.FontDialog(self, wx.FontData()) if dialog.ShowModal() == wx.ID_OK: font = dialog.GetFontData().GetChosenFont() family = font.GetFamily() if misc.check_wx_version(2, 3, 3): for f in (wx.VARIABLE, wx.FIXED): if family & f: family = family ^ f self.value = "['%s', '%s', '%s', '%s', '%s', '%s']" % \ (font.GetPointSize(), self.font_families_from[family], self.font_styles_from[font.GetStyle()], self.font_weights_from[font.GetWeight()], font.GetUnderlined() and 1 or 0, font.GetFaceName()) self.EndModal(wx.ID_OK) def on_ok(self, event): self.value = "['%s', '%s', '%s', '%s', '%s', '']" % \ (self.point_size.GetValue(), self.family.GetStringSelection().lower(), self.style.GetStringSelection().lower(), self.weight.GetStringSelection().lower(), self.underline.GetValue() and 1 or 0) self.EndModal(wx.ID_OK) def get_value(self): return self.value def set_value(self, props): self.family.SetStringSelection(props[1].capitalize()) self.style.SetStringSelection(props[2].capitalize()) self.weight.SetStringSelection(props[3].capitalize()) try: try: underline = int(props[4]) except ValueError: if props[4].lower() == "true": underline = 1 else: underline = 0 self.underline.SetValue(underline) self.point_size.SetValue(int(props[0])) except ValueError: import traceback traceback.print_exc() def __set_properties(self): # begin wxGlade: wxGladeFontDialog.__set_properties self.SetTitle(_("Select font attributes")) self.family.SetSelection(0) self.style.SetSelection(0) self.weight.SetSelection(0) self.ok_btn.SetDefault() # end wxGlade def __do_layout(self): # begin wxGlade: wxGladeFontDialog.__do_layout sizer_1 = wx.BoxSizer(wx.VERTICAL) sizer_2 = wx.BoxSizer(wx.VERTICAL) sizer_4 = wx.BoxSizer(wx.HORIZONTAL) sizer_5 = wx.BoxSizer(wx.VERTICAL) grid_sizer_1_copy = wx.FlexGridSizer(2, 3, 2, 10) grid_sizer_2_copy = wx.FlexGridSizer(2, 3, 2, 5) grid_sizer_2_copy.Add(self.label_2_copy, 0, wx.ALIGN_BOTTOM, 3) grid_sizer_2_copy.Add(self.label_3_copy, 0, wx.ALIGN_BOTTOM, 3) grid_sizer_2_copy.Add(self.label_4_copy, 0, wx.ALIGN_BOTTOM, 3) grid_sizer_2_copy.Add(self.family, 0, wx.EXPAND, 0) grid_sizer_2_copy.Add(self.style, 0, wx.EXPAND, 0) grid_sizer_2_copy.Add(self.weight, 0, wx.EXPAND, 0) grid_sizer_2_copy.AddGrowableCol(0) grid_sizer_2_copy.AddGrowableCol(1) grid_sizer_2_copy.AddGrowableCol(2) sizer_5.Add(grid_sizer_2_copy, 0, wx.EXPAND, 0) grid_sizer_1_copy.Add(self.label_1, 0, wx.ALIGN_BOTTOM, 0) grid_sizer_1_copy.Add((20, 5), 0, wx.ALIGN_BOTTOM, 0) grid_sizer_1_copy.Add((20, 5), 0, wx.ALIGN_BOTTOM, 0) grid_sizer_1_copy.Add(self.point_size, 0, 0, 0) grid_sizer_1_copy.Add(self.underline, 0, wx.EXPAND, 0) grid_sizer_1_copy.Add(self.font_btn, 0, 0, 0) grid_sizer_1_copy.AddGrowableCol(1) sizer_5.Add(grid_sizer_1_copy, 0, wx.TOP | wx.EXPAND, 3) sizer_5.Add(self.static_line_1, 0, wx.TOP | wx.EXPAND, 8) sizer_2.Add(sizer_5, 0, wx.EXPAND, 0) sizer_4.Add(self.ok_btn, 0, wx.RIGHT, 12) sizer_4.Add(self.cancel_btn, 0, 0, 0) sizer_2.Add(sizer_4, 0, wx.TOP | wx.ALIGN_RIGHT, 9) sizer_1.Add(sizer_2, 1, wx.ALL | wx.EXPAND, 10) self.SetAutoLayout(1) self.SetSizer(sizer_1) sizer_1.Fit(self) sizer_1.SetSizeHints(self) self.Layout() # end wxGlade self.CenterOnScreen()
def __init__(self, name, parent, id, title, property_window, style=wx.DEFAULT_FRAME_STYLE, show=True, klass='wxFrame'): TopLevelBase.__init__(self, name, klass, parent, id, property_window, show=show, title=title) self.base = 'wxFrame' self.style = style self.statusbar = None self.icon = '' self.access_functions['statusbar'] = (self.get_statusbar, self.set_statusbar) self.menubar = None self.access_functions['menubar'] = (self.get_menubar, self.set_menubar) self.toolbar = None self.access_functions['toolbar'] = (self.get_toolbar, self.set_toolbar) self.access_functions['style'] = (self.get_style, self.set_style) self.access_functions['icon'] = (self.get_icon, self.set_icon) prop = self.properties style_labels = [ '#section#' + _('Style'), 'wxDEFAULT_FRAME_STYLE', 'wxICONIZE', 'wxCAPTION', 'wxMINIMIZE', 'wxMINIMIZE_BOX', 'wxMAXIMIZE', 'wxMAXIMIZE_BOX', 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxSIMPLE_BORDER', 'wxRESIZE_BORDER', 'wxFRAME_TOOL_WINDOW', 'wxFRAME_NO_TASKBAR', 'wxFRAME_FLOAT_ON_PARENT', 'wxNO_BORDER', 'wxNO_FULL_REPAINT_ON_RESIZE', 'wxFULL_REPAINT_ON_RESIZE', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN' ] self.style_pos = [ wx.DEFAULT_FRAME_STYLE, wx.ICONIZE, wx.CAPTION, wx.MINIMIZE, wx.MINIMIZE_BOX, wx.MAXIMIZE, wx.MAXIMIZE_BOX, wx.STAY_ON_TOP, wx.SYSTEM_MENU, wx.SIMPLE_BORDER, wx.RESIZE_BORDER, wx.FRAME_TOOL_WINDOW, wx.FRAME_NO_TASKBAR, wx.FRAME_FLOAT_ON_PARENT, wx.NO_BORDER, wx.NO_FULL_REPAINT_ON_RESIZE, wx.FULL_REPAINT_ON_RESIZE, wx.TAB_TRAVERSAL, wx.CLIP_CHILDREN ] if misc.check_wx_version(2, 5): style_labels.insert(5, 'wxCLOSE_BOX') self.style_pos.insert(4, wx.CLOSE_BOX) prop['style'] = CheckListProperty(self, 'style', None, style_labels) # menubar property prop['menubar'] = CheckBoxProperty(self, 'menubar', None, _('Has MenuBar')) # statusbar property prop['statusbar'] = CheckBoxProperty(self, 'statusbar', None, _('Has StatusBar')) # toolbar property prop['toolbar'] = CheckBoxProperty(self, 'toolbar', None, _('Has ToolBar')) # icon property prop['icon'] = FileDialogProperty(self, 'icon', None, style=wx.OPEN | wx.FILE_MUST_EXIST, can_disable=True, label=_("icon")) # centered property self.centered = False self.access_functions['centered'] = (self.get_centered, self.set_centered) prop['centered'] = CheckBoxProperty(self, 'centered', None, label=_("centered")) # size hints property self.sizehints = False self.access_functions['sizehints'] = (self.get_sizehints, self.set_sizehints) prop['sizehints'] = CheckBoxProperty(self, 'sizehints', None, label=_('Set Size Hints'))