def setText(self, formattedText): """Set new HTML content into the formatted text widget.""" w = self.getWxWidget() if self.useHtml: fontName = None fontSize = None if st.isDefined("style-html-font"): fontName = st.getSystemString("style-html-font") if st.isDefined("style-html-size"): fontSize = st.getSystemString("style-html-size") if fontName != None or fontSize != None: fontElem = "<font" if fontName != None: fontElem += ' face="%s"' % fontName if fontSize != None: fontElem += ' size="%s"' % fontSize fontElem += ">" else: fontElem = None #color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) #print color #formattedText = '<body bgcolor="#%02x%02x%02x">' \ # % (color.Red(), color.Green(), color.Blue()) \ # + formattedText + '</body>' if fontElem == None: w.SetPage(uniConv(formattedText)) else: w.SetPage(uniConv(fontElem + formattedText + '</font>'))
def __init__(self, parent, wxId, useHtmlFormatting=True, initialText=''): """Constructor. @param parent Parent wxWidget ID. @param wxId ID of the formatted text widget. @param useHtmlFormatting Use a HTML window widget. @param initialText Initial contents. """ self.useHtml = useHtmlFormatting if self.useHtml: base.Widget.__init__(self, MyHtmlWindow(parent, wxId)) else: if host.isMac(): # It appears wxWidgets fancy text is broken on the Mac. useFancy = True #False else: useFancy = True if useFancy: text = initialText.replace('<b>', '<font weight="bold">') text = text.replace('</b>', '</font>') text = text.replace('<i>', '<font style="italic">') text = text.replace('</i>', '</font>') text = text.replace('<tt>', '<font family="fixed">') text = text.replace('</tt>', '</font>') text = '<font family="swiss" size="%s">' \ % st.getSystemString('style-normal-size') + text + '</font>' # fancytext doesn't support non-ascii chars? text = text.replace('ä', 'a') text = text.replace('ö', 'o') text = text.replace('ü', 'u') text = text.replace('å', 'a') text = text.replace('Ä', 'A') text = text.replace('Ö', 'O') text = text.replace('Ü', 'U') text = text.replace('Å', 'A') else: text = initialText.replace('<b>', '') text = text.replace('</b>', '') text = text.replace('<i>', '') text = text.replace('</i>', '') text = text.replace('<tt>', '') text = text.replace('</tt>', '') # Break it up if too long lines detected. brokenText = breakLongLines(text, 70) if useFancy: base.Widget.__init__(self, fancy.StaticFancyText( parent, wxId, uniConv(brokenText))) else: base.Widget.__init__(self, StaticText(parent, wxId, uniConv(brokenText))) self.resizeToBestSize()
def __filter(self, itemText): """Filter the item text so it can be displayed on screen.""" # Set the maximum length. if len(itemText) > 30: return '...' + uniConv(itemText[-30:]) return uniConv(itemText)
def __init__(self, parent, wxId, label, isChecked): base.Widget.__init__(self, wx.CheckBox(parent, wxId, uniConv(language.translate(label)), style=wx.CHK_3STATE | wx.CHK_ALLOW_3RD_STATE_FOR_USER)) self.widgetId = label # Set the initial value of the checkbox. w = self.getWxWidget() if isChecked: w.Set3StateValue(wx.CHK_CHECKED) else: w.Set3StateValue(wx.CHK_UNCHECKED) # We want focus notifications. self.setFocusId(self.widgetId) self.indicator = None # When the checkbox is focused, send a notification. wx.EVT_CHECKBOX(parent, wxId, self.onClick) # Listen for value changes. self.addValueChangeListener() self.addProfileChangeListener()
def __init__(self, parent, wxId, label, isChecked): base.Widget.__init__( self, wx.CheckBox(parent, wxId, uniConv(language.translate(label)), style=wx.CHK_3STATE | wx.CHK_ALLOW_3RD_STATE_FOR_USER)) self.widgetId = label # Set the initial value of the checkbox. w = self.getWxWidget() if isChecked: w.Set3StateValue(wx.CHK_CHECKED) else: w.Set3StateValue(wx.CHK_UNCHECKED) # We want focus notifications. self.setFocusId(self.widgetId) self.indicator = None # When the checkbox is focused, send a notification. wx.EVT_CHECKBOX(parent, wxId, self.onClick) # Listen for value changes. self.addValueChangeListener() self.addProfileChangeListener()
def __init__(self, parent, wxId, id, suffix='', maxLineLength=0, align=0): """Constructor. @param parent @param wxId @param id Identifier of the text string. @param suffix Suffix for the translated version of the text. @param maxLineLength Maximum line length for the text (in characters). @param alignment Alignment (LEFT, MIDDLE, RIGHT). """ # Prepare the text string. self.maxLineLength = maxLineLength self.suffix = suffix self.widgetId = id # Alignment style flag. styleFlags = 0 if align == Text.LEFT: styleFlags |= wx.ALIGN_LEFT elif align == Text.MIDDLE: styleFlags |= wx.ALIGN_CENTRE elif align == Text.RIGHT: styleFlags |= wx.ALIGN_RIGHT base.Widget.__init__(self, MyStaticText(parent, wxId, uniConv(self.__prepareText()), style = styleFlags | wx.ST_NO_AUTORESIZE)) self.setNormalStyle() # When the text is clicked, send a notification. wx.EVT_LEFT_DOWN(self.getWxWidget(), self.onClick)
def __init__(self, parent, wxId, id, size, align=ui.ALIGN_VERTICAL, resizable=True): # Determine flags. flags = wx.CLOSE_BOX | wx.CAPTION if resizable: flags |= wx.RESIZE_BORDER wx.Dialog.__init__(self, parent, wxId, uniConv(language.translate(id)), style=flags) self.dialogId = id self.widgetMap = {} if size: self.recommendedSize = size else: self.recommendedSize = None # All the commands that will cause the dialog to be closed. self.dialogEndCommands = ['ok', 'cancel', 'yes', 'no'] # Create an area inside the dialog. self.area = sb.widget.area.Area('', self, alignment=align, border=0)
def addItemWithColumns(self, identifier, *columns): w = self.getWxWidget() if type(columns[0]) is int: # This is an image item. index = w.InsertImageItem(w.GetItemCount(), columns[0]) #info = wx.ListItem() #info.m_itemId = index #info.m_col = 0 #info.m_mask = wx.LIST_MASK_FORMAT #info.m_format = wx.LIST_FORMAT_CENTRE #w.SetItem(info) else: index = w.InsertStringItem(w.GetItemCount(), uniConv(columns[0])) for i in range(1, len(columns)): w.SetStringItem(index, i, uniConv(columns[i])) # Put the identifier into the data. w.SetItemData(index, index) self.items.append(identifier)
def __init__(self, parent, wxId, id, style): # Create a wxButton of the appropriate type. if style != Button.STYLE_MINI: widget = wx.Button(parent, wxId, uniConv(language.translate(id))) else: widget = wx.ToggleButton(parent, wxId, uniConv(language.translate(id))) # Default buttons are usually a bit different visually. if style == Button.STYLE_DEFAULT: widget.SetDefault() base.Widget.__init__(self, widget) self.widgetId = id if style == Button.STYLE_MINI: # The mini buttons use the small style. self.setSmallStyle() # The size of the mini buttons is configurable. bestSize = widget.GetBestSize() width = 30 height = bestSize[1] try: width = st.getSystemInteger('button-mini-width') if st.getSystemInteger('button-mini-height'): height = st.getSystemInteger('button-mini-height') except: pass widget.SetMinSize((width, height)) if style != Button.STYLE_MINI: # We will handle the click event ourselves. wx.EVT_BUTTON(parent, wxId, self.onClick) #self.updateDefaultSize() else: # Pop back up when toggled down. wx.EVT_TOGGLEBUTTON(parent, wxId, self.onToggle)
def onRightClick(self, ev): # Let wxWidgets handle the event, too. widget = self.getWxWidget() if not widget.IsEnabled(): return # Going up or down? if ev.ButtonDown(): # Mouse right down doesn't do anything. return # Request an update to the popup menu. if self.menuId: events.send(events.Notify(self.menuId + '-update-request')) # Display the popup menu. if self.menuItems: menu = wx.Menu() self.commandMap = {} idCounter = 10000 # Create the menu items. for item in self.menuItems: if type(item) == tuple: itemId = item[0] itemCommand = item[1] else: itemId = item itemCommand = item if itemId == '-': # This is just a separator. menu.AppendSeparator() continue # Generate a new ID for the item. wxId = idCounter idCounter += 1 self.commandMap[wxId] = itemCommand menu.Append( wxId, widgets.uniConv(language.translate('menu-' + itemId))) wx.EVT_MENU(widget, wxId, self.onPopupCommand) # Display the menu. The callback gets called during this. widget.PopupMenu(menu, ev.GetPosition()) menu.Destroy()
def onRightClick(self, ev): # Let wxWidgets handle the event, too. widget = self.getWxWidget() if not widget.IsEnabled(): return # Going up or down? if ev.ButtonDown(): # Mouse right down doesn't do anything. return # Request an update to the popup menu. if self.menuId: events.send(events.Notify(self.menuId + '-update-request')) # Display the popup menu. if self.menuItems: menu = wx.Menu() self.commandMap = {} idCounter = 10000 # Create the menu items. for item in self.menuItems: if type(item) == tuple: itemId = item[0] itemCommand = item[1] else: itemId = item itemCommand = item if itemId == '-': # This is just a separator. menu.AppendSeparator() continue # Generate a new ID for the item. wxId = idCounter idCounter += 1 self.commandMap[wxId] = itemCommand menu.Append(wxId, widgets.uniConv(language.translate('menu-' + itemId))) wx.EVT_MENU(widget, wxId, self.onPopupCommand) # Display the menu. The callback gets called during this. widget.PopupMenu(menu, ev.GetPosition()) menu.Destroy()
def addItem(self, identifier, isChecked=False): """Append a new item into the listbox. @param identifier Identifier of the item. """ w = self.getWxWidget() if language.isDefined(identifier): visibleText = language.translate(identifier) else: visibleText = identifier w.Append(uniConv(visibleText)) self.items.append(identifier) # In a checklistbox, the items can be checked. if self.style == List.STYLE_CHECKBOX: if isChecked: w.Check(w.GetCount() - 1)
def addItem(self, itemId, rawItemText, toIndex=None): """Add a new item into the formatted list box. No translation is done. Instead, the provided item text is displayed using HTML formatting. @param itemId Identifier of the item. This is sent in notification events. @param itemText Formatted text for the item. @param toIndex Optional index where the item should be placed. If None, the item is added to the end of the list. """ itemText = uniConv(rawItemText) # If this item identifier already exists, update its # description without making any further changes. for i in range(len(self.items)): if self.items[i][0] == itemId: self.items[i] = (itemId, itemText) # Let the widget know that a change has occured. # Although it may be that this does nothing... self.__updateItemCount() return newItem = (itemId, itemText) if toIndex == None: if self.addSorted: toIndex = 0 # Sort alphabetically based on identifier. for i in range(len(self.items)): if cmp(itemId, self.items[i][0]) < 0: break toIndex = i + 1 else: toIndex = len(self.items) self.items = self.items[:toIndex] + [newItem] + \ self.items[toIndex:] self.__updateItemCount()
def retranslate(self): self.getWxWidget().SetLabel(uniConv(language.translate(self.widgetId)))
def setText(self, text): "Set new untranslated content into the text widget." self.getWxWidget().SetLabel(uniConv(text))
def updateMenus(self): """Create the main frame menus based on menuItems array.""" global menuItems self.menuCommandMap = {} # Array of menus. Number to wxMenu. self.menus = {} # Three levels of priority. for level in range(len(menuItems)): if len(menuItems[level]) == 0: # No menu for this. self.menus[level] = None continue self.menus[level] = wx.Menu() self.menuBar.Append(self.menus[level], language.translate("menu-" + str(level))) # Sort the items based on groups, and append separators where necessary. menuItems[level].sort(lambda x, y: cmp(x[3], y[3])) separated = [] previousItem = None for item in menuItems[level]: if previousItem and previousItem[3] != item[3]: separated.append(('-', '', False, item[3])) separated.append(item) previousItem = item # Create the menu items. for itemId, itemCommand, itemSeparate, itemGroup in separated: if itemId == '-': # This is just a separator. self.menus[level].AppendSeparator() continue if itemSeparate and self.menus[level].GetMenuItemCount() > 0: self.menus[level].AppendSeparator() menuItemId = 'menu-' + itemId accel = '' if language.isDefined(menuItemId + '-accel'): accel = "\t" + language.translate(menuItemId + '-accel') # Generate a new ID for the item. wxId = wx.NewId() self.menuCommandMap[wxId] = itemCommand self.menus[level].Append(wxId, uniConv(language.translate(menuItemId) + accel)) wx.EVT_MENU(self, wxId, self.onPopupCommand) if host.isMac(): # Special menu items on Mac. if itemId == 'about': wx.App_SetMacAboutMenuItemId(wxId) if itemId == 'quit': wx.App_SetMacExitMenuItemId(wxId) if itemId == 'show-snowberry-settings': wx.App_SetMacPreferencesMenuItemId(wxId) if host.isMac(): # Special Help menu on Mac. wx.App_SetMacHelpMenuTitleName(language.translate('menu-' + str(MENU_HELP))) self.SetMenuBar(self.menuBar)
def updateMenus(self): """Create the main frame menus based on menuItems array.""" global menuItems self.menuCommandMap = {} # Array of menus. Number to wxMenu. self.menus = {} # Three levels of priority. for level in range(len(menuItems)): if len(menuItems[level]) == 0: # No menu for this. self.menus[level] = None continue self.menus[level] = wx.Menu() self.menuBar.Append(self.menus[level], language.translate("menu-" + str(level))) # Sort the items based on groups, and append separators where necessary. menuItems[level].sort(lambda x, y: cmp(x[3], y[3])) separated = [] previousItem = None for item in menuItems[level]: if previousItem and previousItem[3] != item[3]: separated.append(('-', '', False, item[3])) separated.append(item) previousItem = item # Create the menu items. for itemId, itemCommand, itemSeparate, itemGroup in separated: if itemId == '-': # This is just a separator. self.menus[level].AppendSeparator() continue if itemSeparate and self.menus[level].GetMenuItemCount() > 0: self.menus[level].AppendSeparator() menuItemId = 'menu-' + itemId accel = '' if language.isDefined(menuItemId + '-accel'): accel = "\t" + language.translate(menuItemId + '-accel') # Generate a new ID for the item. wxId = wx.NewId() self.menuCommandMap[wxId] = itemCommand self.menus[level].Append( wxId, uniConv(language.translate(menuItemId) + accel)) wx.EVT_MENU(self, wxId, self.onPopupCommand) if host.isMac(): # Special menu items on Mac. if itemId == 'about': wx.App_SetMacAboutMenuItemId(wxId) if itemId == 'quit': wx.App_SetMacExitMenuItemId(wxId) if itemId == 'show-snowberry-settings': wx.App_SetMacPreferencesMenuItemId(wxId) if host.isMac(): # Special Help menu on Mac. wx.App_SetMacHelpMenuTitleName( language.translate('menu-' + str(MENU_HELP))) self.SetMenuBar(self.menuBar)