Example #1
0
    def __init__(self, parent, wxId, id):
        """A slider widget for constrained selection of values."""
        base.Widget.__init__(self, wx.Slider(parent, wxId, 50, 0, 100,
                                             style=(wx.SL_AUTOTICKS |
                                                    wx.SL_LABELS |
                                                    wx.SL_HORIZONTAL)))

        self.widgetId = id
        self.step = 1

        # Listen for changes.  Some platform-specific tweaks are needed:
        if host.isUnix():
            wx.EVT_COMMAND_SCROLL_THUMBTRACK(parent, wxId, self.onThumbTrack)
        else:
            wx.EVT_COMMAND_SCROLL_THUMBRELEASE(parent, wxId, self.onThumbTrack)

        # We want focus notifications.
        self.setFocusId(id)

        # Add a command for reseting the slider.
        self.resetCommand = self.widgetId + '-reset-to-default'
        self.setPopupMenu([('reset-slider', self.resetCommand)])
        
        # Listen to our reset command.
        events.addCommandListener(self.onCommand, [self.resetCommand])
        self.addValueChangeListener()
        self.addProfileChangeListener()

        self.oldValue = None
Example #2
0
    def __init__(self, parent, wxId, id):
        """A slider widget for constrained selection of values."""
        base.Widget.__init__(
            self,
            wx.Slider(parent,
                      wxId,
                      50,
                      0,
                      100,
                      style=(wx.SL_AUTOTICKS | wx.SL_LABELS
                             | wx.SL_HORIZONTAL)))

        self.widgetId = id
        self.step = 1

        # Listen for changes.  Some platform-specific tweaks are needed:
        if host.isUnix():
            wx.EVT_COMMAND_SCROLL_THUMBTRACK(parent, wxId, self.onThumbTrack)
        else:
            wx.EVT_COMMAND_SCROLL_THUMBRELEASE(parent, wxId, self.onThumbTrack)

        # We want focus notifications.
        self.setFocusId(id)

        # Add a command for reseting the slider.
        self.resetCommand = self.widgetId + '-reset-to-default'
        self.setPopupMenu([('reset-slider', self.resetCommand)])

        # Listen to our reset command.
        events.addCommandListener(self.onCommand, [self.resetCommand])
        self.addValueChangeListener()
        self.addProfileChangeListener()

        self.oldValue = None
Example #3
0
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))
Example #4
0
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.
    Together with the classes in widgets.py, the Area class
    encapsulates all management of the user interface.  Modules that
    use ui.py or widgets.py need not access wxWidgets directly at all.
Example #5
0
    def __init__(self, title):
        """Initialize the main window.

        @param title  Title for the main window.
        """
        from sb.widget.area import Area

        # Commands for the popup menu.
        self.menuCommandMap = {}

        # FIXME: Layout is botched. Way too wide.
        if host.isMac():
            initialSize = (769, 559)
        elif host.isUnix():
            initialSize = (900, 610)
        else:
            initialSize = (733, 527)

        # The configuration may define a window size.
        if st.isDefined('main-width'):
            initialSize = (st.getSystemInteger('main-width'), initialSize[1])
        if st.isDefined('main-height'):
            initialSize = (initialSize[0], st.getSystemInteger('main-height'))

        # The configuration can also specify the window position.
        if st.isDefined('main-x') and st.isDefined('main-y'):
            initialPos = (st.getSystemInteger('main-x'), st.getSystemInteger('main-y'))
        else:
            initialPos = None

        wx.Frame.__init__(self, None, -1, title, size=initialSize)
        #self.SetExtraStyle(wx.FRAME_EX_METAL)
        #self.Create(None, -1, title, size=initialSize)

        if initialPos is not None:
            self.MoveXY(*initialPos)
        else:
            self.Center()

        # Set the icon for the frame.
        icon = wx.Icon('graphics/snowberry.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        #self.Iconize(True)
        #self.Hide()

        SPLITTER_ID = 9501
        PROF_SPLITTER_ID = 9502
        self.splitter = None
        self.profSplitter = None

        # The parentWin is where the profSplitter and the help panel
        # are inside.
        parentWin = self

        if USE_HELP_AREA:
            # The help area is in a splitter.
            self.splitter = wx.SplitterWindow(self, SPLITTER_ID,
                                              style=wx.SP_3DSASH)
            self.splitter.SetMinimumPaneSize(10)
            parentWin = self.splitter

        if not USE_MINIMAL_PROFILE:
            self.profSplitter = wx.SplitterWindow(parentWin, PROF_SPLITTER_ID,
                                                  style=wx.SP_3DSASH)# |
                                                  #wx.SP_NO_XP_THEME)
            self.profSplitter.SetMinimumPaneSize(100)

            # Profile panel.
            profilePanel = wx.Panel(self.profSplitter, -1, style=wx.NO_BORDER
                                    | wx.CLIP_CHILDREN)
            area = Area(PROFILES, profilePanel, ALIGN_VERTICAL, 10)
            _newArea(area)

            # Create panels inside the profile splitter.
            self.mainPanel = MainPanel(self.profSplitter)
        else:
            profilePanel = None

            self.mainPanel = MainPanel(parentWin)

            getArea(TABS).setWeight(0)
            profArea = getArea(TABS).createArea(alignment=ALIGN_HORIZONTAL, border=12)
            profArea.setId(PROFILES)
            _newArea(profArea)
            getArea(TABS).setWeight(1)
            getArea(TABS).setBorderDirs(BORDER_NOT_TOP)

        # Create a TabArea into the TABS area.
        self.mainPanel.tabs = getArea(TABS).createTabArea(
            'tab', style=sb.widget.tab.TabArea.STYLE_BASIC)

        if st.isDefined('main-split-position'):
            self.splitPos = INITIAL_SASH_POS
        else:
            self.splitPos = None
        self.profSplitPos = INITIAL_PROFILE_SASH_POS

        # Create the help area.
        if self.splitter:
            self.helpPanel = wx.Panel(self.splitter, -1, style = wx.NO_BORDER
                                      | wx.CLIP_CHILDREN)
            self.helpPanel.SetBackgroundColour(wx.WHITE)
            _newArea( Area(HELP, self.helpPanel, ALIGN_VERTICAL,
                           border=4) )
            # Init the splitter.
            leftSide = self.profSplitter
            if not leftSide:
                leftSide = self.mainPanel
            self.splitter.SplitVertically(leftSide, self.helpPanel,
                                          -INITIAL_SASH_POS)
        else:
            self.helpPanel = None

        if self.profSplitter:
            self.profSplitter.SplitVertically(profilePanel, self.mainPanel,
                                              self.profSplitPos)

        # Listen for changes in the sash position.
        wx.EVT_SPLITTER_SASH_POS_CHANGED(self, SPLITTER_ID,
                                         self.onSplitChange)
        wx.EVT_SPLITTER_SASH_POS_CHANGED(self, PROF_SPLITTER_ID,
                                         self.onProfSplitChange)

        # The main panel should be globally accessible.
        global mainPanel
        mainPanel = self.mainPanel

        # Intercept the window close event.
        wx.EVT_CLOSE(self, self.onWindowClose)

        # Maintain the splitter position.
        wx.EVT_SIZE(self, self.onWindowSize)

        # Listen to some commands.
        events.addCommandListener(self.handleCommand, ['quit'])

        # Create a menu bar.
        self.menuBar = wx.MenuBar()
Example #6
0
    def __init__(self, title):
        """Initialize the main window.

        @param title  Title for the main window.
        """
        from sb.widget.area import Area

        # Commands for the popup menu.
        self.menuCommandMap = {}

        # FIXME: Layout is botched. Way too wide.
        if host.isMac():
            initialSize = (769, 559)
        elif host.isUnix():
            initialSize = (900, 610)
        else:
            initialSize = (733, 527)

        # The configuration may define a window size.
        if st.isDefined('main-width'):
            initialSize = (st.getSystemInteger('main-width'), initialSize[1])
        if st.isDefined('main-height'):
            initialSize = (initialSize[0], st.getSystemInteger('main-height'))

        # The configuration can also specify the window position.
        if st.isDefined('main-x') and st.isDefined('main-y'):
            initialPos = (st.getSystemInteger('main-x'),
                          st.getSystemInteger('main-y'))
        else:
            initialPos = None

        wx.Frame.__init__(self, None, -1, title, size=initialSize)
        #self.SetExtraStyle(wx.FRAME_EX_METAL)
        #self.Create(None, -1, title, size=initialSize)

        if initialPos is not None:
            self.MoveXY(*initialPos)
        else:
            self.Center()

        # Set the icon for the frame.
        icon = wx.Icon('graphics/snowberry.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        #self.Iconize(True)
        #self.Hide()

        SPLITTER_ID = 9501
        PROF_SPLITTER_ID = 9502
        self.splitter = None
        self.profSplitter = None

        # The parentWin is where the profSplitter and the help panel
        # are inside.
        parentWin = self

        if USE_HELP_AREA:
            # The help area is in a splitter.
            self.splitter = wx.SplitterWindow(self,
                                              SPLITTER_ID,
                                              style=wx.SP_3DSASH)
            self.splitter.SetMinimumPaneSize(10)
            parentWin = self.splitter

        if not USE_MINIMAL_PROFILE:
            self.profSplitter = wx.SplitterWindow(parentWin,
                                                  PROF_SPLITTER_ID,
                                                  style=wx.SP_3DSASH)  # |
            #wx.SP_NO_XP_THEME)
            self.profSplitter.SetMinimumPaneSize(100)

            # Profile panel.
            profilePanel = wx.Panel(self.profSplitter,
                                    -1,
                                    style=wx.NO_BORDER
                                    | wx.CLIP_CHILDREN)
            area = Area(PROFILES, profilePanel, ALIGN_VERTICAL, 10)
            _newArea(area)

            # Create panels inside the profile splitter.
            self.mainPanel = MainPanel(self.profSplitter)
        else:
            profilePanel = None

            self.mainPanel = MainPanel(parentWin)

            getArea(TABS).setWeight(0)
            profArea = getArea(TABS).createArea(alignment=ALIGN_HORIZONTAL,
                                                border=12)
            profArea.setId(PROFILES)
            _newArea(profArea)
            getArea(TABS).setWeight(1)
            getArea(TABS).setBorderDirs(BORDER_NOT_TOP)

        # Create a TabArea into the TABS area.
        self.mainPanel.tabs = getArea(TABS).createTabArea(
            'tab', style=sb.widget.tab.TabArea.STYLE_BASIC)

        if st.isDefined('main-split-position'):
            self.splitPos = INITIAL_SASH_POS
        else:
            self.splitPos = None
        self.profSplitPos = INITIAL_PROFILE_SASH_POS

        # Create the help area.
        if self.splitter:
            self.helpPanel = wx.Panel(self.splitter,
                                      -1,
                                      style=wx.NO_BORDER
                                      | wx.CLIP_CHILDREN)
            self.helpPanel.SetBackgroundColour(wx.WHITE)
            _newArea(Area(HELP, self.helpPanel, ALIGN_VERTICAL, border=4))
            # Init the splitter.
            leftSide = self.profSplitter
            if not leftSide:
                leftSide = self.mainPanel
            self.splitter.SplitVertically(leftSide, self.helpPanel,
                                          -INITIAL_SASH_POS)
        else:
            self.helpPanel = None

        if self.profSplitter:
            self.profSplitter.SplitVertically(profilePanel, self.mainPanel,
                                              self.profSplitPos)

        # Listen for changes in the sash position.
        wx.EVT_SPLITTER_SASH_POS_CHANGED(self, SPLITTER_ID, self.onSplitChange)
        wx.EVT_SPLITTER_SASH_POS_CHANGED(self, PROF_SPLITTER_ID,
                                         self.onProfSplitChange)

        # The main panel should be globally accessible.
        global mainPanel
        mainPanel = self.mainPanel

        # Intercept the window close event.
        wx.EVT_CLOSE(self, self.onWindowClose)

        # Maintain the splitter position.
        wx.EVT_SIZE(self, self.onWindowSize)

        # Listen to some commands.
        events.addCommandListener(self.handleCommand, ['quit'])

        # Create a menu bar.
        self.menuBar = wx.MenuBar()