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 clearLog(): try: os.remove(logFileName) except: pass global logFile logFile = file(logFileName, 'w') logFile.write(st.getSystemString('snowberry-title') + ' ' + st.getSystemString('snowberry-version') + "\n") logFile.write("Launching on " + time.strftime('%a, %d %b %Y %H:%M:%S') + "\n")
def setStyle(self, textStyle): """Set a new style for the text label. @param style One of the constants: - Widget.NORMAL: default style - Widget.BOLD: bold typeface - Widget.ITALIC: italic typeface - Widget.HEADING: large bold typeface - Widget.TITLE: largest bold typeface """ weight = wx.NORMAL style = wx.NORMAL styleName = 'style-' + \ ['normal', 'bold', 'italic', 'heading', 'title', 'small'][textStyle] + '-' try: size = st.getSystemInteger(styleName + 'size') except: size = 11 try: font = st.getSystemString(styleName + 'font') except: font = '' try: w = st.getSystemString(styleName + 'weight') if w == 'bold': weight = wx.BOLD except: pass try: s = st.getSystemString(styleName + 'slant') if s == 'italic': style = wx.ITALIC except: pass newFont = wx.Font(size, wx.DEFAULT, style, weight, faceName=font) w = self.getWxWidget() w.SetFont(newFont) #w.SetSize(w.GetBestSize()) #bestSize = w.GetBestSize() #w.SetMinSize((0,bestSize[1])) self.updateDefaultSize()
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 getValue(self, id, fallbackToDefaults=True): """Returns the Value for the given setting. Falls back to the defaults profile. @param id Setting identifier. @param fallbackToDefaults If True, the value is retrieved from the Defaults profile if it isn't defined in this one. """ defaults = profdb.defaults # If this is a system setting, let's consult the system # configuration. if st.isDefined(id): return Value(id, st.getSystemString(id)) # First look in the Values in this profile. for v in self.values: if v.getId() == id: return v if id == 'game-mode': # We can look for the game mode in the system profile. sysProfFileName = os.path.join(paths.getSystemPath(paths.PROFILES), self.getFileName()) if os.path.exists(sysProfFileName): try: p = cfparser.FileParser(sysProfFileName) while True: element = p.get() if element.isKey() and element.getName() == 'game-mode': return Value(element.getName(), element.getValue()) except cfparser.OutOfElements: # The file ended normally. pass # Fall back to the Defaults profile. if fallbackToDefaults and self is not defaults: return defaults.getValue(id) elif self is defaults: # See if the setting itself has a default for this. try: setting = st.getSetting(id) if setting.getDefault(): return Value(id, str(setting.getDefault())) except: pass # No Value for this setting could be found. return None else: # A normal profile with no value for this setting. return None
def handleCommand(event): """Handle the About command and display the About Snowberry dialog. @param event An events.Command event. """ if event.hasId('about'): # Create the About dialog and show it. dialog, area = sb.util.dialog.createButtonDialog( 'about-dialog', ['show-credits', '', 'ok'], 'ok', resizable=False) content = area.createArea(alignment=ui.ALIGN_VERTICAL, border=0) content.setWeight(0) # Big logo. content.setBorder(16, ui.BORDER_BOTTOM) content.createImage('about') content.setBorder(6, ui.BORDER_BOTTOM) versionText = content.createText('', align=wt.Text.MIDDLE) versionText.setBoldStyle() versionText.setText( language.translate('about-version') + ' ' + st.getSystemString('snowberry-version')) content.createText('about-subtitle', align=wt.Text.MIDDLE) content.createText('about-license', align=wt.Text.MIDDLE) content.createText('about-website', align=wt.Text.MIDDLE).setSmallStyle() #content.setBorder(6) #content.setWeight(1) #box = content.createArea(boxedWithTitle='about-credits') #info = box.createFormattedText() #info.setMinSize(300, 280) #info.setText(language.translate('about-info')) dialog.focusWidget('ok') dialog.run() elif event.hasId('show-credits'): dialog, area = sb.util.dialog.createButtonDialog( 'about-credits', ['close'], 'close') info = area.createFormattedText() info.setMinSize(290, 230) info.setText(language.translate('credits')) dialog.addEndCommand('close') dialog.run()
def startGame(profile): """Start the game using the specified profile. @param profile A profiles.Profile object. """ setLaunchMessage(language.translate('launch-message')) options = generateOptions(profile) if options == None: return # Locate the paths and binaries. Most of these are configured in # the .conf files. engineBin = st.getSystemString('doomsday-binary') userPath = paths.getUserPath(paths.RUNTIME) options += ' -userdir ' + paths.quote(userPath) # Put the response file in the user's runtime directory. responseFile = os.path.join(userPath, 'Options.rsp') file(responseFile, 'w').write(options + "\n") # Execute the command line. if host.isWindows(): spawnFunc = os.spawnv else: spawnFunc = os.spawnvp if host.isWindows(): spawnFunc(os.P_NOWAIT, engineBin, [engineBin, '@' + paths.quote(responseFile)]) else: spawnFunc(os.P_NOWAIT, engineBin, [engineBin, '@' + responseFile]) # Shut down if the configuration settings say so. value = profile.getValue('quit-on-launch') if not value or value.getValue() == 'yes': # Quit Snowberry. events.sendAfter(events.Command('quit'))
def generateOptions(profile): """Generate a text string of all the command line options used when launching a game. @param profile A profiles.Profile object. The values of settings are retrieved from here. @return All the options in a single string. Returns None if there is an unresolved addon conflict. """ clearLog() # Determine which addons are in use. The final list of addons # includes all the addons that must be loaded at launch (defaults; # required parts of boxes). usedAddonIds = profile.getFinalAddons() usedAddons = map(lambda id: ao.get(id), usedAddonIds) # Form the command line. cmdLine = [] # Determine the settings that apply to the components and # addons. effectiveSettings = st.getCompatibleSettings(profile) # Are there any system-specific options defined? if st.isDefined('common-options'): cmdLine.append(ex.evaluate(st.getSystemString('common-options'), None)) # All profiles use the same runtime directory. if st.isDefined('doomsday-base'): basePath = os.path.abspath(st.getSystemString('doomsday-base')) cmdLine.append('-basedir ' + paths.quote(basePath)) # Determine the components used by the profile. for compId in profile.getComponents(): # Append the component's options to the command line as-is. cmdLine.append( st.getComponent(compId).getOption() ) # Resolve conflicting addons by letting the user choose between # them. if not resolveAddonConflicts(usedAddons, profile): # Launch aborted! return None # Get the command line options for loading all the addons. for addon in usedAddons: params = addon.getCommandLine(profile).strip() if params: cmdLine.append(params) # Update IDs of used addons. usedAddonsId = map(lambda a: a.getId(), usedAddons) # Get the command line options from each setting. for setting in effectiveSettings: # If the setting's required addons are not being loaded, skip # this setting. skipThis = False for req in setting.getRequiredAddons(): if req not in usedAddonIds: skipThis = True break if skipThis: continue # All settings can't be used at all times. In # case of a conflict, some of the settings are ignored. if setting.isEnabled(profile): params = setting.getCommandLine(profile).strip() if params: cmdLine.append(params) # Send a launch options notification. This is done so that # plugins are able to observe/modify the list of launch options. events.send(events.LaunchNotify(cmdLine)) return string.join(cmdLine, ' ')
def updateTitle(self): windowTitle = st.getSystemString('snowberry-title') + ' ' + \ st.getSystemString('snowberry-version') self.mainFrame.SetTitle(windowTitle)