def on_text(self, event): import re validation_re = re.compile(r'^[a-zA-Z_]+[\w:.0-9-]*$') name = event.GetString() OK = bool(validation_re.match(name)) if not OK: self.klass.SetBackgroundColour(wx.RED) compat.SetToolTip(self.klass, "Class name not valid") else: #if name in [c.widget.klass for c in common.root.children or []]: if self.toplevel and name in self.toplevel_names: self.klass.SetBackgroundColour(wx.RED) compat.SetToolTip( self.klass, "Class name already in use for toplevel window") OK = False elif name in self.class_names: # if the class name is in use already, indicate in yellow self.klass.SetBackgroundColour(wx.Colour(255, 255, 0, 255)) compat.SetToolTip(self.klass, "Class name not unique") if self.toplevel and name in self.toplevel_names: OK = False else: self.klass.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) compat.SetToolTip(self.klass, "") self.klass.Refresh() self.btnOK.Enable(OK) event.Skip()
def _select_item(self, index, force=False): item_count = self.items.GetItemCount() if index == -1 and item_count: index = 0 if index >= item_count and item_count: index = item_count-1 if index==self.selected_index and not force: return self.selected_index = index if index == -1: self._enable_fields(False, clear=True) self._enable_buttons() return self._ignore_events = True self.items.Select(index) if self._get_item_text(index, "label") != '---': # skip if the selected item is a separator for i,colname in enumerate(self.columns): s = getattr(self, colname) coltype = self.coltypes.get(colname,None) value = self._get_item_text(index, i) if coltype is None: # at this point, the value should be validated already s.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) ) s.SetValue(value) elif coltype is int: s.SetSelection( int(value) ) self.label.SetValue(self.label.GetValue().lstrip()) self._enable_fields(True) else: self._enable_fields(False, clear=True) self._enable_buttons() state = wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED self.items.SetItemState(index, state, state) # fix bug 698071
def _select_item(self, index, force=False): if index >= self.menu_items.GetItemCount() or index<0 or (index==self.selected_index and not force): return self._ignore_events = True self.menu_items.Select(index) self.selected_index = index if self.menu_items.GetItem(index, 2).GetText() != '---': # skip if the selected item is a separator for (s, i) in ((self.label, 0), (self.event_handler, 1), (self.name, 2), (self.help_str, 4), (self.id, 5)): # at this point, the value should be validated already s.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) ) s.SetValue(self.menu_items.GetItem(index, i).GetText()) self.label.SetValue(self.label.GetValue().lstrip()) try: self.check_radio.SetSelection( int(self.menu_items.GetItem(index, 3).GetText()) ) except: self.check_radio.SetSelection(0) self._enable_fields(True) # set focus to text field again focus = self.FindFocus() if not isinstance(focus, wx.TextCtrl) and isinstance(self._last_focus, wx.TextCtrl): self._last_focus.SetFocus() else: for c in (self.label, self.event_handler, self.name, self.help_str, self.id): c.SetValue("") self._enable_fields(False) self._enable_buttons() if force: self.label.SetFocus() self.label.SelectAll()
def create_property_panel(self, frame_style, icon, main_geometry): # create property editor frame self.property_frame = wxGladePropertyPanel(self, frame_style) self.property_frame.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) self.property_frame.SetIcon(icon) # set geometry property_geometry = None if config.preferences.remember_geometry: property_geometry = config.preferences.get_geometry('properties') if isinstance(property_geometry, tuple): property_geometry = wx.Rect(*property_geometry) if not property_geometry: property_geometry = wx.Rect() property_geometry.Position = main_geometry.BottomLeft width = max(self.Size[0], 345) property_geometry.Size = (width, 550) # sometimes especially on GTK GetSize seems to ignore window decorations (bug still exists on wx3) if wx.Platform != '__WXMSW__': property_geometry.Y += 40 # set size on Mac manually if wx.Platform == '__WXMAC__': property_geometry.Size = (width, 584) self._set_geometry(self.property_frame, property_geometry) self.property_frame.Show()
def _select_item(self, index, force=False): if index >= self.items.GetItemCount() or index<0 or (index==self.selected_index and not force): return self._ignore_events = True self.items.Select(index) self.selected_index = index if self.items.GetItem(index, 2).GetText() != '---': # skip if the selected item is a separator for i,colname in enumerate(self.columns): s = getattr(self, colname) coltype = self.coltypes.get(colname,None) value = self.items.GetItem(index, i).GetText() if coltype is None: # at this point, the value should be validated already s.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) ) s.SetValue(value) elif coltype is int: s.SetSelection( int(value) ) self.label.SetValue(self.label.GetValue().lstrip()) self._enable_fields(True) # set focus to text field again focus = self.FindFocus() if not isinstance(focus, wx.TextCtrl) and isinstance(self._last_focus, wx.TextCtrl): self._last_focus.SetFocus() else: for c in (self.label, self.handler, self.long_help, self.short_help, self.id, self.bitmap1, self.bitmap2): c.SetValue("") self._enable_fields(False) self._enable_buttons() if force: self.label.SetFocus() self.label.SelectAll()
def update_label(self): if not self.owner.widget or not self.owner.is_visible(): label = _('Show Design Window') self.background_color = wx.Colour(150,150,240) # make button more visible else: label = _('Hide Design Window') self.background_color = compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE) self.set_label(label)
def on_event_handler_edited(self, event): value = self.handler.GetValue() if not value or self.handler_re.match(value): self.handler.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) ) valid = True else: self.handler.SetBackgroundColour(wx.RED) valid = False self.handler.Refresh() self._on_edited(event, "handler", value, valid)
def on_event_handler_edited(self, event): value = self.event_handler.GetValue() if not value or self.handler_re.match(value): self.event_handler.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) ) valid = True else: self.event_handler.SetBackgroundColour(wx.RED) valid = False self.event_handler.Refresh() if valid and not self._ignore_events: self.menu_items.SetStringItem(self.selected_index, 1, value) event.Skip()
def display_sys_color(self, event=None): colour = self.sys_color.GetValue().strip() if colour.startswith("wxSYS_COLOUR_"): colour = getattr(wx, colour[2:], None) else: colour = None if colour: self.sys_color.SetBackgroundColour(wx.WHITE) colour = compat.wx_SystemSettings_GetColour(colour) else: self.sys_color.SetBackgroundColour(wx.RED) colour = wx.NullColour self.sys_color_panel.SetBackgroundColour(colour) self.sys_color_panel.Refresh()
def create_widget(self): if self.parent: parent = self.parent.widget else: parent = common.palette # we set always a default style because this is the best one for editing the dialog # (for example, a dialog without a caption would be hard to move, etc.) default_style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER # change 2002-10-09: now we create a wxFrame instead of a wxDialog, # because the latter gives troubles I wasn't able to solve when using wxPython 2.3.3.1 :-/ self.widget = wx.Frame(parent, self.id, "", style=default_style) self.widget.SetBackgroundColour(compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) self._set_widget_icon()
def on_name_edited(self, event): value = self.name.GetValue() if not value or self.name_re.match(value): self.name.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) ) valid = True else: self.name.SetBackgroundColour(wx.RED) valid = False if value and valid and not self._ignore_events: # check for double names for i in range(self.items.GetItemCount()): if i==self.selected_index: continue if value == self._get_item_text(i, "name"): valid = False self.name.SetBackgroundColour( wx.Colour(255, 255, 0, 255) ) # YELLOW break self.name.Refresh() self._on_edited(event, "name", value, valid)
def __init__(self, parent=None): self._logger = logging.getLogger(self.__class__.__name__) style = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX style |= wx.RESIZE_BORDER | wx.CLOSE_BOX version = config.version if version == '"faked test version"': version = "%s on Python %d.%d" % (version, sys.version_info.major, sys.version_info.minor) wx.Frame.__init__(self, parent, -1, "wxGlade v%s" % version, style=style, name='MainFrame') if parent is None: parent = self common.palette = self # to provide a reference accessible by the various widget classes icon = compat.wx_EmptyIcon() bmp = wx.Bitmap(os.path.join(config.icons_path, "icon.xpm"), wx.BITMAP_TYPE_XPM) icon.CopyFromBitmap(bmp) self.SetIcon(icon) self.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) self.create_menu(parent) # load the available code generators all_widgets = common.init_codegen() if config.use_gui: # build the palette for all_widgets sizer = wx.FlexGridSizer(0, 2, 0, 0) sizer.AddGrowableCol(0) self.SetAutoLayout(True) maxlen = max([len(all_widgets[sect]) for sect in all_widgets ]) # the maximum number of buttons in a section for section in all_widgets: if section: label = wx.StaticText(self, -1, "%s:" % section.replace('&', '&&')) sizer.Add(label, 1, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 2) bsizer = wx.GridSizer(cols=maxlen, hgap=2, vgap=2) for button in all_widgets[section]: bsizer.Add(button, flag=wx.ALL, border=1) sizer.Add(bsizer) self.SetSizer(sizer) sizer.Fit(self) self.Bind(wx.EVT_CLOSE, self.cleanup) # the style for the property and tree frames 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 # set window geometry main_geometry = None extend_Y = False if config.preferences.remember_geometry: main_geometry = config.preferences.get_geometry('main') if isinstance(main_geometry, tuple): main_geometry = wx.Rect(*main_geometry) if not main_geometry: main_geometry = wx.Rect() main_geometry.TopLeft = wx.Display().GetClientArea().GetTopLeft() main_geometry.Size = (-1, -1) extend_Y = True self._set_geometry(self, main_geometry) if extend_Y: # expand in Y by 40 pixels size = self.GetSize() self.SetSize((size[0], size[1] + 20)) self.Show() main_geometry.Size = self.GetSize() # create the property and the tree frame self.create_property_panel(frame_style, icon, main_geometry) common.property_panel = self.property_frame self.create_tree_frame( frame_style, icon, main_geometry) # also creates Application object # last visited directory, used on GTK for wxFileDialog self.cur_dir = config.preferences.open_save_path # set a drop target for us... self._droptarget = clipboard.FileDropTarget(self) self.SetDropTarget(self._droptarget) #self.tree_frame.SetDropTarget(self._droptarget) #self.property_frame.SetDropTarget(self._droptarget) # ALB 2004-10-15, autosave support... self.autosave_timer = None if config.preferences.autosave: self.autosave_timer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.on_autosave_timer, self.autosave_timer) self.autosave_timer.Start( int(config.preferences.autosave_delay) * 1000) self.create_statusbar() # create statusbar for display of messages self.Raise() misc.set_focused_widget(common.app_tree.app) # disable autosave checks during unittests if config.testing: return if common.check_autosaved(None): res = wx.MessageBox(_( 'There seems to be auto saved data from last wxGlade session: do you want to restore it?' ), _('Auto save detected'), style=wx.ICON_QUESTION | wx.YES_NO) if res == wx.YES: filename = common.get_name_for_autosave() if self._open_app(filename, add_to_history=False): self.cur_dir = os.path.dirname(filename) common.app_tree.app.saved = False common.app_tree.app.filename = None self.user_message(_('Auto save loaded')) common.remove_autosaved() self.Bind(wx.EVT_CHAR_HOOK, self.on_key_event)