def __init__(self, parent=None):
        super(XViewProfileManager, self).__init__(parent)

        # define custom properties
        self._profiles = []
        self._optionsMenuPolicy = Qt.DefaultContextMenu
        self._viewWidget = None

        # define the interface
        self._profileCombo = QComboBox(self)
        self._optionsButton = QToolButton(self)
        self._optionsButton.setAutoRaise(True)
        self._optionsButton.setToolTip('Advanced Options')
        self._optionsButton.setIcon(QIcon(resources.find('img/advanced.png')))

        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)

        layout.addWidget(self._profileCombo)
        layout.addWidget(self._optionsButton)

        self.setLayout(layout)

        # create connections
        self._profileCombo.currentIndexChanged.connect(
            self.handleProfileChange)
        self._optionsButton.clicked.connect(self.showOptionsMenu)
Example #2
0
 def __init__(self, parent=None):
     super(XTimeDeltaEdit, self).__init__(parent)
     
     # define custom properties
     self.setStyleSheet(COMBO_STYLE)
     
     self._numberSpinner = QSpinBox(self)
     self._numberSpinner.setRange(0, 100000)
     self._numberSpinner.setFrame(False)
     self._numberSpinner.setButtonSymbols(QSpinBox.NoButtons)
     self._numberSpinner.setSizePolicy(QSizePolicy.Expanding,
                                       QSizePolicy.Expanding)
     
     self._unitCombo = QComboBox(self)
     self._unitCombo.setEditable(True)
     self._unitCombo.setInsertPolicy(QComboBox.NoInsert)
     self._unitCombo.setFrame(False)
     self._unitCombo.addItems(['year(s)',
                               'month(s)',
                               'week(s)',
                               'day(s)',
                               'hour(s)',
                               'minute(s)',
                               'second(s)'])
     
     self._unitCombo.setCurrentIndex(3)
     self._unitCombo.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
     
     self._directionCombo = QComboBox(self)
     self._directionCombo.addItems(['ago', 'from now'])
     self._directionCombo.setEditable(True)
     self._directionCombo.setInsertPolicy(QComboBox.NoInsert)
     self._directionCombo.setFrame(False)
     self._directionCombo.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Expanding)
     
     # setup ui
     self.setFrameShape(QFrame.StyledPanel)
     self.setFrameShadow(QFrame.Sunken)
     self.setBackgroundRole(QPalette.Base)
     self.setAutoFillBackground(True)
     
     layout = QHBoxLayout()
     layout.setContentsMargins(2, 2, 2, 2)
     layout.setSpacing(0)
     layout.addWidget(self._numberSpinner)
     layout.addWidget(self._unitCombo)
     layout.addWidget(self._directionCombo)
     self.setLayout(layout)
 def __init__(self, parent=None):
     super(XViewProfileManager, self).__init__(parent)
     
     # define custom properties
     self._profiles           = []
     self._optionsMenuPolicy  = Qt.DefaultContextMenu
     self._viewWidget         = None
     
     # define the interface
     self._profileCombo  = QComboBox(self)
     self._optionsButton = QToolButton(self)
     self._optionsButton.setAutoRaise(True)
     self._optionsButton.setToolTip('Advanced Options')
     self._optionsButton.setIcon(QIcon(resources.find('img/advanced.png')))
     
     layout = QHBoxLayout()
     layout.setSpacing(0)
     layout.setContentsMargins(0, 0, 0, 0)
     
     layout.addWidget(self._profileCombo)
     layout.addWidget(self._optionsButton)
     
     self.setLayout(layout)
     
     # create connections
     self._profileCombo.currentIndexChanged.connect(self.handleProfileChange)
     self._optionsButton.clicked.connect(self.showOptionsMenu)
Example #4
0
    def createEditor(self, parent, option, index):
        combo = QComboBox(parent)

        keys = Q.Op.keys()
        keys = map(lambda x: projex.text.joinWords(x, ' ').lower(), keys)

        combo.addItems(sorted(keys))
        combo.setEditable(True)
        combo.setInsertPolicy(QComboBox.NoInsert)

        return combo
Example #5
0
    def createEditor(self, parent, option, index):
        schema = self.parent().schema()
        if (not schema):
            return None

        colNames = map(lambda x: x.displayName(), schema.columns())

        combo = QComboBox(parent)
        combo.setEditable(True)
        combo.setInsertPolicy(QComboBox.NoInsert)
        combo.addItems(colNames)

        return combo
 def createEditor( self, parent, option, index ):
     combo = QComboBox(parent)
     
     keys = Q.Op.keys()
     keys = map(lambda x: projex.text.joinWords(x, ' ').lower(), keys)
     
     combo.addItems(sorted(keys))
     combo.setEditable(True)
     combo.setInsertPolicy(QComboBox.NoInsert)
     
     return combo
Example #7
0
    def paintEvent(self, event):
        """
        Paints this combobox based on whether or not it is visible.
        
        :param      event | <QPaintEvent>
        """
        if not self.autoRaise() or (self._hovered and self.isEnabled()):
            super(XComboBox, self).paintEvent(event)

            text = QComboBox.currentText(self)
            if not text and self._hint and not self.lineEdit():
                text = self._hint
                palette = self.palette()
                with XPainter(self) as painter:
                    painter.setPen(
                        palette.color(palette.Disabled, palette.Text))
                    painter.drawText(5, 0, self.width(), self.height(),
                                     Qt.AlignLeft | Qt.AlignVCenter,
                                     self.currentText())

        else:
            palette = self.palette()

            with XPainter(self) as painter:
                text = QComboBox.currentText(self)
                if not text:
                    text = self.hint()
                    painter.setPen(
                        palette.color(palette.Disabled, palette.WindowText))

                painter.drawText(5, 0, self.width(), self.height(),
                                 Qt.AlignLeft | Qt.AlignVCenter, text)

                x = self.width() - 15
                y = 4
                pixmap = QPixmap(
                    resources.find('img/treeview/triangle_down.png'))
                painter.drawPixmap(x, y, pixmap)
 def createEditor( self, parent, option, index ):
     schema = self.parent().schema()
     if ( not schema ):
         return None
     
     colNames = map(lambda x: x.displayName(), schema.columns())
     
     combo = QComboBox(parent)
     combo.setEditable(True)
     combo.setInsertPolicy(QComboBox.NoInsert)
     combo.addItems(colNames)
     
     return combo
Example #9
0
    def createEditor(self, parent, option, index):
        tree = self.parent()
        querywidget = tree.parent()
        item = tree.itemFromIndex(index)
        if (isinstance(item, XQueryItem) and not item.childCount()):
            ttype = querywidget.tableType()
            options = querywidget.factory().columnOptions(ttype)

        elif (isinstance(item, XJoinItem)):
            options = ['and', 'or']

        combo = QComboBox(parent)
        combo.setEditable(True)
        combo.setInsertPolicy(QComboBox.NoInsert)
        combo.addItems(sorted(options))

        return combo
Example #10
0
 def paintEvent(self, event):
     """
     Paints this combobox based on whether or not it is visible.
     
     :param      event | <QPaintEvent>
     """
     if not self.autoRaise() or (self._hovered and self.isEnabled()):
         super(XComboBox, self).paintEvent(event)
         
         text = QComboBox.currentText(self)
         if not text and self._hint and not self.lineEdit():
             text = self._hint
             palette = self.palette()
             with XPainter(self) as painter:
                 painter.setPen(palette.color(palette.Disabled, palette.Text))
                 painter.drawText(5, 0, self.width(), self.height(),
                                  Qt.AlignLeft | Qt.AlignVCenter,
                                  self.currentText())
         
     else:
         palette = self.palette()
         
         with XPainter(self) as painter:
             text = QComboBox.currentText(self)
             if not text:
                 text = self.hint()
                 painter.setPen(palette.color(palette.Disabled,
                                              palette.WindowText))
             
             painter.drawText(5, 0, self.width(), self.height(),
                              Qt.AlignLeft | Qt.AlignVCenter, text)
             
             x = self.width() - 15
             y = 4
             pixmap = QPixmap(resources.find('img/treeview/triangle_down.png'))
             painter.drawPixmap(x, y, pixmap)
Example #11
0
    def createEditor(self, parent, option, index):
        combo = QComboBox(parent)

        item = self.parent().itemFromIndex(index)
        columnType = item.columnType()

        operators = Q.ColumnOps.get(columnType, Q.ColumnOps[None])

        # create the keys based on the column type
        keys = []
        for operator in operators:
            op_name = Q.Op[operator]
            keys.append(projex.text.joinWords(op_name, ' ').lower())

        combo.addItems(sorted(keys))
        combo.setEditable(True)
        combo.setInsertPolicy(QComboBox.NoInsert)

        return combo
Example #12
0
 def createEditor( self, parent, option, index ):
     tree = self.parent()
     querywidget = tree.parent()
     item = tree.itemFromIndex(index)
     if ( isinstance(item, XQueryItem) and not item.childCount() ):
         ttype = querywidget.tableType()
         options = querywidget.factory().columnOptions(ttype)
     
     elif ( isinstance(item, XJoinItem) ):
         options = ['and', 'or']
     
     combo = QComboBox(parent)
     combo.setEditable(True)
     combo.setInsertPolicy(QComboBox.NoInsert)
     combo.addItems(sorted(options))
     
     return combo
Example #13
0
 def createEditor( self, parent, option, index ):
     combo = QComboBox(parent)
     
     item = self.parent().itemFromIndex(index)
     columnType = item.columnType()
     
     operators = Q.ColumnOps.get(columnType,
                                 Q.ColumnOps[None])
     
     # create the keys based on the column type
     keys = []
     for operator in operators:
         op_name = Q.Op[operator]
         keys.append(projex.text.joinWords(op_name, ' ').lower())
     
     combo.addItems(sorted(keys))
     combo.setEditable(True)
     combo.setInsertPolicy(QComboBox.NoInsert)
     
     return combo
    def createEditor(self, parent, schema, columnName, operatorType):
        """
        Returns an editor for the inputed table type, based on the column and
        operator types.
        
        :param      schema          | <orb.TableSchema>
                    columnName      | <str>
                    operatorType    | <orb.Query.Op>
        
        :return     <QWidget>
        """
        column = schema.column(columnName)
        if (not column):
            return None

        ctype = column.columnType()

        # based on the column and operator type, the editor may change
        if (ctype == ColumnType.String):
            if (operatorType in (Q.Op.IsIn, Q.Op.IsNotIn)):
                widget = XMultiTagEdit(parent)
            else:
                widget = QLineEdit(parent)

        elif (ctype == ColumnType.Bool):
            widget = QComboBox(parent)
            widget.addItems(['True', 'False'])
            widget.setEditable(True)
            widget.setInsertPolicy(QComboBox.NoInsert)

        elif (ctype == ColumnType.ForeignKey):
            widget = XOrbRecordBox(parent)
            widget.setRecords(self.collectRecords(column))

        else:
            widget = None

        return widget
class XViewProfileManager(QWidget):
    currentProfileChanged = Signal(PyObject)
    optionsMenuRequested = Signal(QPoint)

    def __init__(self, parent=None):
        super(XViewProfileManager, self).__init__(parent)

        # define custom properties
        self._profiles = []
        self._optionsMenuPolicy = Qt.DefaultContextMenu
        self._viewWidget = None

        # define the interface
        self._profileCombo = QComboBox(self)
        self._optionsButton = QToolButton(self)
        self._optionsButton.setAutoRaise(True)
        self._optionsButton.setToolTip('Advanced Options')
        self._optionsButton.setIcon(QIcon(resources.find('img/advanced.png')))

        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)

        layout.addWidget(self._profileCombo)
        layout.addWidget(self._optionsButton)

        self.setLayout(layout)

        # create connections
        self._profileCombo.currentIndexChanged.connect(
            self.handleProfileChange)
        self._optionsButton.clicked.connect(self.showOptionsMenu)

    def addProfile(self, profile):
        """
        Adds the inputed profile to the system.
        
        :param      profile | <XViewProfile>
        """
        if (profile in self._profiles):
            return

        self._profiles.append(profile)
        self._profileCombo.blockSignals(True)
        self._profileCombo.addItem(profile.name())
        self._profileCombo.setCurrentIndex(self._profileCombo.count() - 1)
        self._profileCombo.blockSignals(False)

    def currentProfile(self):
        """
        Returns the currently selected profile from the system.
        
        :return     <XViewProfile>
        """
        index = self._profileCombo.currentIndex()

        if 0 <= index and index < len(self._profiles):
            return self._profiles[index]
        return None

    def handleProfileChange(self):
        """
        Emits that the current profile has changed.
        """
        # restore the profile settings
        prof = self.currentProfile()
        vwidget = self.viewWidget()
        if vwidget:
            prof.restore(vwidget)

        if not self.signalsBlocked():
            self.currentProfileChanged.emit(self.currentProfile())

    def optionsMenuPolicy(self):
        """
        Returns the option menu policy for this widget.
        
        :return     <Qt.MenuPolicy>
        """
        return self._optionsMenuPolicy

    def profiles(self):
        """
        Returns a list of all the profiles for this system.
        
        :return     [<XViewProfile>, ..]
        """
        return self._profiles

    def removeProfile(self, profile):
        """
        Adds the inputed profile to the system.
        
        :param      profile | <XViewProfile>
        """
        if not profile in self._profiles:
            return

        index = self._profiles.index(profile)
        self._profiles.remove(profile)
        self._profileCombo.blockSignals(True)
        self._profileCombo.takeItem(index)
        self._profileCombo.blockSignals(False)

    def restoreSettings(self, settings):
        """
        Restores settings from the application.
        
        :param      settings | <QSettings>
        """
        settings.beginGroup(self.objectName())

        curr_prof = None
        curr_name = unwrapVariant(settings.value('current'))

        profiles = []
        for prof_name in settings.childGroups():
            settings.beginGroup(prof_name)

            prof_str = unwrapVariant(settings.value('profile'))
            profile = XViewProfile.fromString(prof_str)
            profile.setName(prof_name)

            if prof_name == curr_name:
                curr_prof = profile

            profiles.append(profile)

            settings.endGroup()

        self.blockSignals(True)
        self._profileCombo.blockSignals(True)
        self.setProfiles(profiles)

        if curr_prof:
            self.setCurrentProfile(curr_prof)

        self._profileCombo.blockSignals(False)
        self.blockSignals(False)

        settings.endGroup()

    def saveSettings(self, settings):
        """
        Saves the settings for this widget to the application
        
        :param      settings | <QSettings>
        """
        settings.beginGroup(self.objectName())

        curr_prof = self.currentProfile()
        if curr_prof:
            settings.setValue('current', curr_prof.name())

        for profile in self.profiles():
            settings.beginGroup(profile.name())
            settings.setValue('profile', wrapVariant(profile.toString()))
            settings.endGroup()

        settings.endGroup()

    def setCurrentProfile(self, profile):
        """
        Sets the current profile to the inputed profile.
        
        :param      profile | <XViewProfile>
        """
        try:
            index = self._profiles.index(profile)
        except ValueError:
            index = -1

        self._profileCombo.setCurrentIndex(index)

    def setOptionsMenuPolicy(self, menuPolicy):
        """
        Sets the options menu policy for this item.
        
        :param      menuPolicy | <Qt.MenuPolicy>
        """
        self._optionsMenuPolicy = menuPolicy

    def setProfiles(self, profiles):
        """
        Sets a list of profiles to be the options for the manager.
        
        :param      profiles | [<XViewProfile>, ..]
        """
        self.blockSignals(True)
        self._profileCombo.blockSignals(True)

        self._profiles = profiles[:]
        self._profileCombo.clear()
        self._profileCombo.addItems(map(lambda x: x.name(), profiles))

        self._profileCombo.blockSignals(False)
        self.blockSignals(False)

    def setViewWidget(self, viewWidget):
        """
        Sets the view widget instance linked with this manager.
        
        :param      viewWidget | <XViewWidget>
        """
        self._viewWidget = viewWidget

    def showOptionsMenu(self):
        """
        Displays the options menu.  If the option menu policy is set to 
        CustomContextMenu, then the optionMenuRequested signal will be emitted,
        otherwise the default context menu will be displayed.
        """
        point = QPoint(0, self._optionsButton.height())
        global_point = self._optionsButton.mapToGlobal(point)

        # prompt the custom context menu
        if self.optionsMenuPolicy() == Qt.CustomContextMenu:
            if not self.signalsBlocked():
                self.optionsMenuRequested.emit(global_point)
            return

        # use the default context menu
        menu = XViewProfileManagerMenu(self)
        menu.exec_(global_point)

    def viewWidget(self):
        """
        Returns the view widget that is associated with this manager.
        
        :return     <XViewWidget>
        """
        return self._viewWidget
Example #16
0
class XTimeDeltaEdit(QFrame):
    def __init__(self, parent=None):
        super(XTimeDeltaEdit, self).__init__(parent)
        
        # define custom properties
        self.setStyleSheet(COMBO_STYLE)
        
        self._numberSpinner = QSpinBox(self)
        self._numberSpinner.setRange(0, 100000)
        self._numberSpinner.setFrame(False)
        self._numberSpinner.setButtonSymbols(QSpinBox.NoButtons)
        self._numberSpinner.setSizePolicy(QSizePolicy.Expanding,
                                          QSizePolicy.Expanding)
        
        self._unitCombo = QComboBox(self)
        self._unitCombo.setEditable(True)
        self._unitCombo.setInsertPolicy(QComboBox.NoInsert)
        self._unitCombo.setFrame(False)
        self._unitCombo.addItems(['year(s)',
                                  'month(s)',
                                  'week(s)',
                                  'day(s)',
                                  'hour(s)',
                                  'minute(s)',
                                  'second(s)'])
        
        self._unitCombo.setCurrentIndex(3)
        self._unitCombo.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.Expanding)
        
        self._directionCombo = QComboBox(self)
        self._directionCombo.addItems(['ago', 'from now'])
        self._directionCombo.setEditable(True)
        self._directionCombo.setInsertPolicy(QComboBox.NoInsert)
        self._directionCombo.setFrame(False)
        self._directionCombo.setSizePolicy(QSizePolicy.Expanding,
                                           QSizePolicy.Expanding)
        
        # setup ui
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Sunken)
        self.setBackgroundRole(QPalette.Base)
        self.setAutoFillBackground(True)
        
        layout = QHBoxLayout()
        layout.setContentsMargins(2, 2, 2, 2)
        layout.setSpacing(0)
        layout.addWidget(self._numberSpinner)
        layout.addWidget(self._unitCombo)
        layout.addWidget(self._directionCombo)
        self.setLayout(layout)
        
    def delta(self):
        """
        Returns a delta based on this widget's information.
        
        :return     <datetime.timedelta>
        """
        number      = self._numberSpinner.value()
        unit        = self._unitCombo.currentText()
        direction   = self._directionCombo.currentText()
        
        # use past tense
        if direction == 'ago':
            number = -number
        
        if unit == 'year(s)':
            return datetime.timedelta(number * 365)
        elif unit == 'month(s)':
            return datetime.timedelta(number * 30)
        elif unit == 'week(s)':
            return datetime.timedelta(number * 7)
        elif unit == 'day(s)':
            return datetime.timedelta(number)
        elif unit == 'hour(s)':
            return datetime.timedelta(0, number * 3600)
        elif unit == 'minute(s)':
            return datetime.timedelta(0, number * 60)
        else:
            return datetime.timedelta(0, number)
    
    def setDelta(self, delta):
        """
        Sets the time delta for this widget to the inputed delta.
        
        :param      delta | <datetime.timedelta>
        """
        days = int(delta.days)
        secs = int(delta.total_seconds())
        
        direction = 'from now'
        if secs < 0:
            direction = 'ago'
        
        if days and days % 365 == 0:
            number = days / 365
            unit = 'year(s)'
        elif days and days % 30 == 0:
            number = days / 30
            unit = 'month(s)'
        elif days and days % 7 == 0:
            number = days / 7
            unit = 'week(s)'
        elif days:
            number = days
            unit = 'day(s)'
        elif secs % 3600 == 0:
            number = secs / 3600
            unit = 'hour(s)'
        elif secs % 60 == 0:
            number = secs / 60
            unit = 'minute(s)'
        else:
            number = secs
            unit = 'second(s)'
        
        self._numberSpinner.setValue(abs(int(number)))
        self._unitCombo.setCurrentIndex(self._unitCombo.findText(unit))
        index = self._directionCombo.findText(direction)
        self._directionCombo.setCurrentIndex(index)
class XViewProfileManager(QWidget):
    currentProfileChanged = Signal(PyObject)
    optionsMenuRequested  = Signal(QPoint)
    
    def __init__(self, parent=None):
        super(XViewProfileManager, self).__init__(parent)
        
        # define custom properties
        self._profiles           = []
        self._optionsMenuPolicy  = Qt.DefaultContextMenu
        self._viewWidget         = None
        
        # define the interface
        self._profileCombo  = QComboBox(self)
        self._optionsButton = QToolButton(self)
        self._optionsButton.setAutoRaise(True)
        self._optionsButton.setToolTip('Advanced Options')
        self._optionsButton.setIcon(QIcon(resources.find('img/advanced.png')))
        
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        
        layout.addWidget(self._profileCombo)
        layout.addWidget(self._optionsButton)
        
        self.setLayout(layout)
        
        # create connections
        self._profileCombo.currentIndexChanged.connect(self.handleProfileChange)
        self._optionsButton.clicked.connect(self.showOptionsMenu)
    
    def addProfile(self, profile):
        """
        Adds the inputed profile to the system.
        
        :param      profile | <XViewProfile>
        """
        if ( profile in self._profiles ):
            return
        
        self._profiles.append(profile)
        self._profileCombo.blockSignals(True)
        self._profileCombo.addItem(profile.name())
        self._profileCombo.setCurrentIndex(self._profileCombo.count()-1)
        self._profileCombo.blockSignals(False)
    
    def currentProfile(self):
        """
        Returns the currently selected profile from the system.
        
        :return     <XViewProfile>
        """
        index = self._profileCombo.currentIndex()
        
        if 0 <= index and index < len(self._profiles):
            return self._profiles[index]
        return None
    
    def handleProfileChange(self):
        """
        Emits that the current profile has changed.
        """
        # restore the profile settings
        prof    = self.currentProfile()
        vwidget = self.viewWidget()
        if vwidget:
            prof.restore(vwidget)
        
        if not self.signalsBlocked():
            self.currentProfileChanged.emit(self.currentProfile())
    
    def optionsMenuPolicy(self):
        """
        Returns the option menu policy for this widget.
        
        :return     <Qt.MenuPolicy>
        """
        return self._optionsMenuPolicy
    
    def profiles(self):
        """
        Returns a list of all the profiles for this system.
        
        :return     [<XViewProfile>, ..]
        """
        return self._profiles
    
    def removeProfile(self, profile):
        """
        Adds the inputed profile to the system.
        
        :param      profile | <XViewProfile>
        """
        if not profile in self._profiles:
            return
        
        index = self._profiles.index(profile)
        self._profiles.remove(profile)
        self._profileCombo.blockSignals(True)
        self._profileCombo.takeItem(index)
        self._profileCombo.blockSignals(False)
    
    def restoreSettings(self, settings):
        """
        Restores settings from the application.
        
        :param      settings | <QSettings>
        """
        settings.beginGroup(self.objectName())
        
        curr_prof = None
        curr_name = unwrapVariant(settings.value('current'))
        
        profiles = []
        for prof_name in settings.childGroups():
            settings.beginGroup(prof_name)
            
            prof_str = unwrapVariant(settings.value('profile'))
            profile  = XViewProfile.fromString(prof_str)
            profile.setName(prof_name)
            
            if prof_name == curr_name:
                curr_prof = profile
            
            profiles.append(profile)
            
            settings.endGroup()
        
        self.blockSignals(True)
        self._profileCombo.blockSignals(True)
        self.setProfiles(profiles)
        
        if curr_prof:
            self.setCurrentProfile(curr_prof)
        
        self._profileCombo.blockSignals(False)
        self.blockSignals(False)
        
        settings.endGroup()
    
    def saveSettings(self, settings):
        """
        Saves the settings for this widget to the application
        
        :param      settings | <QSettings>
        """
        settings.beginGroup(self.objectName())
        
        curr_prof = self.currentProfile()
        if curr_prof:
            settings.setValue('current', curr_prof.name())
        
        for profile in self.profiles():
            settings.beginGroup(profile.name())
            settings.setValue('profile', wrapVariant(profile.toString()))
            settings.endGroup()
        
        settings.endGroup()
    
    def setCurrentProfile(self, profile):
        """
        Sets the current profile to the inputed profile.
        
        :param      profile | <XViewProfile>
        """
        try:
            index = self._profiles.index(profile)
        except ValueError:
            index = -1
        
        self._profileCombo.setCurrentIndex(index)
    
    def setOptionsMenuPolicy(self, menuPolicy):
        """
        Sets the options menu policy for this item.
        
        :param      menuPolicy | <Qt.MenuPolicy>
        """
        self._optionsMenuPolicy = menuPolicy
    
    def setProfiles(self, profiles):
        """
        Sets a list of profiles to be the options for the manager.
        
        :param      profiles | [<XViewProfile>, ..]
        """
        self.blockSignals(True)
        self._profileCombo.blockSignals(True)
        
        self._profiles = profiles[:]
        self._profileCombo.clear()
        self._profileCombo.addItems(map(lambda x: x.name(), profiles))
        
        self._profileCombo.blockSignals(False)
        self.blockSignals(False)
    
    def setViewWidget(self, viewWidget):
        """
        Sets the view widget instance linked with this manager.
        
        :param      viewWidget | <XViewWidget>
        """
        self._viewWidget = viewWidget
    
    def showOptionsMenu(self):
        """
        Displays the options menu.  If the option menu policy is set to 
        CustomContextMenu, then the optionMenuRequested signal will be emitted,
        otherwise the default context menu will be displayed.
        """
        point        = QPoint(0, self._optionsButton.height())
        global_point = self._optionsButton.mapToGlobal(point)
        
        # prompt the custom context menu
        if self.optionsMenuPolicy() == Qt.CustomContextMenu:
            if not self.signalsBlocked():
                self.optionsMenuRequested.emit(global_point)
            return
        
        # use the default context menu
        menu = XViewProfileManagerMenu(self)
        menu.exec_(global_point)
    
    def viewWidget(self):
        """
        Returns the view widget that is associated with this manager.
        
        :return     <XViewWidget>
        """
        return self._viewWidget