def addTab(self, id): """Add a new tab into the TabArea widget. The tab is appended after previously added tabs. @param id Identifier for the tab. The name and the icon of the tab will be determined using this identifier. @return The Area object for the contents of the tab. """ book = self.getWxWidget() #tab = scrolled.ScrolledPanel(book, -1) #tab.SetupScrolling() tab = wx.Panel(book, -1, style=wx.CLIP_CHILDREN) if host.isWindows(): tab.SetBackgroundStyle(wx.BG_STYLE_SYSTEM) # Put the new tab in the page map so that when an event # occurs, we will know the ID of the tab. self.panelMap.append((id, tab)) # Insert the page into the book. book.AddPage(tab, language.translate(id)) import sb.widget.area area = sb.widget.area.Area(id, tab, ui.ALIGN_VERTICAL) area.setExpanding(True) area.setWeight(1) # Store the Area object in a dictionary for quick access. self.tabAreas[id] = area self.updateIcons() return area
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 uniConv(str): """Decode character encoding to Unicode. @param str String in local encoding. @return Unicode string. """ if host.isWindows(): # Don't do Unicode on Windows. return str elif type(str) == unicode: return str else: return str.decode(host.getEncoding())
def uniDeconv(str): """Encode Unicode back to local character encoding. @param str Unicode string. @return String. """ if host.isWindows(): # Don't do Unicode on Windows. return str elif type(str) != unicode: return str else: return str.encode(host.getEncoding())
def readConfigFile(fileName): """Reads a configuration file from the specified path. The file must be a .conf file that contains either settings or components, or both.""" p = cfparser.FileParser(fileName) # We'll collect all the elements into this array. elements = [] try: # Loop through all the elements in the config file. while True: e = p.get() if e.isKey() and e.getName() == 'required-platform': # This configuration file is specific to a particular # platform. if (e.getValue() == 'windows' and not host.isWindows()) or \ (e.getValue() == 'mac' and not host.isMac()) or \ (e.getValue() == 'unix' and not host.isUnix()): # Look, we ran out early. raise cfparser.OutOfElements # Config files may contain blocks that group similar # settings together. if e.isBlock() and e.getType() == 'group': # Add everything inside the group into the elements. # A group can only contain settings. for sub in e.getContents(): # There can only be blocks in a group. if not sub.isBlock(): continue # Add the 'group' key element to the setting. sub.add(cfparser.KeyElement('group', e.getName())) elements.append(sub) else: elements.append(e) except cfparser.OutOfElements: # Parsing was completed. pass except Exception, exception: # Log an error message. import traceback traceback.print_exc() logger.add(logger.HIGH, 'error-read-config-file', fileName, str(exception))
def _checkSnowberryHome(): """Checks if the Snowberry home directory exists. If it doesn't, it is created and populated with the basic files and directories.""" global homeDir # When this is run for the first time, we'll need to figure out # where the home directory should be. if not homeDir: if isHomeless(): homeLocation = os.getcwd() else: if host.isMac(): # Home on the Mac. homeLocation = os.path.join(os.getenv('HOME'), 'Library/Application Support') else: # First see if a HOME environment variable has been defined. homeLocation = os.getenv('HOME') if not homeLocation: # The failsafe. homeLocation = os.getcwd() # The environment variable was not defined. Let's try # something else. if host.isWindows(): if os.getenv('HOMEPATH'): homeLocation = os.getenv('HOMEDRIVE') + \ os.getenv('HOMEPATH') elif os.getenv('USERPROFILE'): homeLocation = os.getenv('USERPROFILE') elif os.getenv('APPDATA'): homeLocation = os.getenv('APPDATA') homeDir = os.path.join(homeLocation, SNOWBERRY_HOME_DIR) homeDir = os.path.abspath(homeDir) # The home needs to be created if it doesn't exist yet. _createDir(homeDir) # Create the rest of the user directories if they don't exist yet. for p in [ADDONS, MANIFESTS, UNINSTALLED, CONF, LANG, PLUGINS, PROFILES, GRAPHICS, RUNTIME, SERVER_RUNTIME]: _createDir(getUserPath(p))
def isHomeless(): """Homeless setup means that Snowberry uses the main installation directory for user data. In Windows, the default is homeless mode.""" noHome = '-nohome' in sys.argv useHome = '-home' in sys.argv if useHome: return False if noHome: return True # The default is homeless in Windows versions earlier than Vista and # Win Server 2008. if host.isWindows() and not host.isWindowsVista(): return True return False
def createPage(self, identifier, align=ui.ALIGN_VERTICAL, border=3): """Create a subpage in the multiarea. This does not make the page visible, however. @param identifier Identifier of the new page. """ # Create a new panel for the page. panel = wx.Panel(self.panel, -1, style=wx.CLIP_CHILDREN) if host.isWindows(): panel.SetBackgroundStyle(wx.BG_STYLE_SYSTEM) panel.Hide() # Create a new Area for the page. area = Area('', panel, alignment=align, border=border) area.setExpanding(True) area.setWeight(1) self.pages[identifier] = area return area
def addTab(self, id): """Add a new tab into the TabArea widget. The tab is appended after previously added tabs. @param id Identifier for the tab. The name and the icon of the tab will be determined using this identifier. @return The Area object for the contents of the tab. """ book = self.getWxWidget() # tab = scrolled.ScrolledPanel(book, -1) # tab.SetupScrolling() tab = wx.Panel(book, -1, style=wx.CLIP_CHILDREN) if host.isWindows(): tab.SetBackgroundStyle(wx.BG_STYLE_SYSTEM) # Put the new tab in the page map so that when an event # occurs, we will know the ID of the tab. self.panelMap.append((id, tab)) # Insert the page into the book. book.AddPage(tab, language.translate(id)) import sb.widget.area area = sb.widget.area.Area(id, tab, ui.ALIGN_VERTICAL) area.setExpanding(True) area.setWeight(1) # Store the Area object in a dictionary for quick access. self.tabAreas[id] = area self.updateIcons() return area
import sb.widget.field import sb.widget.list import sb.widget.tab import sb.widget.text import sb.widget.tree import sb.profdb as pr import logger from widgets import uniConv # TODO: Make these .conf'able. SETTING_WEIGHT_LEFT = 1 SETTING_WEIGHT_RIGHT = 2 # Border widths in areas. # TODO: Move these to a .conf. if host.isWindows(): AREA_BORDER = 2 AREA_BORDER_BOXED = 2 elif host.isUnix(): AREA_BORDER = 2 AREA_BORDER_BOXED = 1 else: AREA_BORDER = 3 AREA_BORDER_BOXED = 2 # wxWidget ID counters. WIDGET_ID = 100 class Area (base.Widget): """Each Area instance governs the contents of a wxPanel widget.
def isCaseSensitive(): """Returns True if the file system is case sensitive.""" return not host.isWindows() and not host.isMac()
def __init__(self, parent, wxId, label, style=0): StaticText.__init__(self, parent, wxId, label, style=style) if host.isWindows(): # No background. self.SetBackgroundStyle(wx.BG_STYLE_SYSTEM) wx.EVT_ERASE_BACKGROUND(self, self.clearBack)