def restoreSettings( self, settings ):
     """
     Restores the current structure of the view widget from the inputed \
     settings instance.
     
     :param      settings | <QSettings>
     """
     key     = self.objectName()
     value   = qt.unwrapVariant(settings.value('%s/profile' % key))
     
     if ( not value ):
         self.reset(force = True)
         return False
         
     profile = value
     
     # restore the view type settings
     for viewType in self.viewTypes():
         viewType.restoreGlobalSettings(settings)
     
     # restore the profile
     self.restoreProfile(XViewProfile.fromString(profile))
     
     if ( not self.views() ):
         self.reset(force = True)
     
     return True
 def saveProfile( self ):
     """
     Saves the profile for the current state and returns it.
     
     :return     <XViewProfile>
     """
     return XViewProfile.record(self)
 def importProfile( self, filename  = '' ):
     """
     Exports the current profile to a file.
     
     :param      filename | <str>
     """
     if ( not (filename and isinstance(filename, basestring)) ):
         filename = QFileDialog.getOpenFileName( self,
                                                 'Import Layout from...',
                                                 QDir.currentPath(),
                                                 'XView (*.xview)')
         
         if type(filename) == tuple:
             filename = str(filename[0])
     
     filename = str(filename)
     if not filename:
         return
     
     if not filename.endswith('.xview'):
         filename += '.xview'
     
     profile = XViewProfile.load(filename)
     if ( not profile ):
         return
         
     profile.restore(self)
 def saveProfile(self):
     """
     Saves the profile for the current state and returns it.
     
     :return     <XViewProfile>
     """
     return XViewProfile.record(self)
    def importProfile(self, filename=''):
        """
        Exports the current profile to a file.
        
        :param      filename | <str>
        """
        if (not (filename and isinstance(filename, basestring))):
            filename = QFileDialog.getOpenFileName(self,
                                                   'Import Layout from...',
                                                   QDir.currentPath(),
                                                   'XView (*.xview)')

            if type(filename) == tuple:
                filename = str(filename[0])

        filename = str(filename)
        if not filename:
            return

        if not filename.endswith('.xview'):
            filename += '.xview'

        profile = XViewProfile.load(filename)
        if (not profile):
            return

        profile.restore(self)
Exemple #6
0
    def createProfile(self, profile=None, clearLayout=True):
        """
        Prompts the user to create a new profile.
        """
        if (profile):
            prof = profile
        elif (not self.viewWidget() or clearLayout):
            prof = XViewProfile()
        else:
            prof = self.viewWidget().saveProfile()

        blocked = self.signalsBlocked()
        self.blockSignals(False)
        changed = self.editProfile(prof)
        self.blockSignals(blocked)

        if (not changed):
            return

        act = self.addProfile(prof)
        act.setChecked(True)

        # update the interface
        if (self.viewWidget() and (profile or clearLayout)):
            self.viewWidget().restoreProfile(prof)

        if (not self.signalsBlocked()):
            self.profileCreated.emit(prof)
    def restoreSettings(self, settings):
        """
        Restores the current structure of the view widget from the inputed \
        settings instance.
        
        :param      settings | <QSettings>
        """
        key = self.objectName()
        value = qt.unwrapVariant(settings.value('%s/profile' % key))

        if (not value):
            self.reset(force=True)
            return False

        profile = value

        # restore the view type settings
        for viewType in self.viewTypes():
            viewType.restoreGlobalSettings(settings)

        # restore the profile
        self.restoreProfile(XViewProfile.fromString(profile))

        if (not self.views()):
            self.reset(force=True)

        return True
    def accept(self):
        """
        Saves the data to the profile before closing.
        """
        if (not self.uiNameTXT.text()):
            QMessageBox.information(
                self, 'Invalid Name',
                'You need to supply a name for your layout.')
            return

        prof = self.profile()
        if (not prof):
            prof = XViewProfile()

        prof.setName(nativestring(self.uiNameTXT.text()))
        prof.setVersion(self.uiVersionSPN.value())
        prof.setDescription(nativestring(self.uiDescriptionTXT.toPlainText()))
        prof.setIcon(self.uiIconBTN.filepath())

        super(XViewProfileDialog, self).accept()
 def accept( self ):
     """
     Saves the data to the profile before closing.
     """
     if ( not self.uiNameTXT.text() ):
         QMessageBox.information(self,
                                'Invalid Name',
                                'You need to supply a name for your layout.')
         return
     
     prof = self.profile()
     if ( not prof ):
         prof = XViewProfile()
     
     prof.setName(nativestring(self.uiNameTXT.text()))
     prof.setVersion(self.uiVersionSPN.value())
     prof.setDescription(nativestring(self.uiDescriptionTXT.toPlainText()))
     prof.setIcon(self.uiIconBTN.filepath())
     
     super(XViewProfileDialog, self).accept()
Exemple #10
0
    def importProfile(self, filename=None):
        """
        Imports the profiles from the given filename.
        
        :param      filename | <str> || None
        """
        if not filename:
            filename = QFileDialog.getOpenFileName(self, 'Import Perspective',
                                                   '', 'XML Files (*.xml)')

            if type(filename) == tuple:
                filename = nativestring(filename[0])

        if not (filename and os.path.exists(filename)):
            return False

        prof = XViewProfile.load(filename)
        if prof:
            self.addProfile(prof)
 def importProfile(self, filename=None):
     """
     Imports the profiles from the given filename.
     
     :param      filename | <str> || None
     """
     if not filename:
         filename = QFileDialog.getOpenFileName( self,
                                                 'Import Perspective',
                                                 '',
                                                 'XML Files (*.xml)')
         
         if type(filename) == tuple:
             filename = nativestring(filename[0])
         
     if not (filename and os.path.exists(filename)):
         return False
     
     prof = XViewProfile.load(filename)
     if prof:
         self.addProfile(prof)
 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()
Exemple #13
0
    def restoreSettings(self, settings):
        """
        Restores settings from the application.
        
        :param      settings | <QSettings>
        """
        settings.beginGroup(self.objectName())

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

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

            prof_str = qt.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()
Exemple #14
0
    def showProfileMenu(self, point):
        """
        Prompts the user for profile menu options.  Editing needs to be enabled
        for this to work.
        """
        if (not self.isEditingEnabled()):
            return

        trigger = self.actionAt(point)
        if (isinstance(trigger, XViewProfileAction)):
            prof = trigger.profile()
        else:
            prof = None

        # define the menu
        menu = QMenu(self)

        new_act = menu.addAction('New Blank Layout...')
        new_act.setIcon(QIcon(resources.find('img/add.png')))

        if (prof):
            edit_act = menu.addAction('Edit Information...')
            menu.addSeparator()

            save_act = menu.addAction('Save from Current Layout')
            copy_act = menu.addAction('Copy Layout')
            copy_as_act = menu.addAction('Copy Layout as...')
            paste_act = menu.addAction('Paste Layout')

            menu.addSeparator()

            export_act = menu.addAction('Export Toolbar...')
            import_act = menu.addAction('Import Toolbar...')

            menu.addSeparator()

            rem_act = menu.addAction('Remove Layout')

            # set the icons
            save_act.setIcon(QIcon(resources.find('img/save.png')))
            edit_act.setIcon(QIcon(resources.find('img/edit.png')))
            copy_act.setIcon(QIcon(resources.find('img/copy.png')))
            paste_act.setIcon(QIcon(resources.find('img/paste.png')))
            rem_act.setIcon(QIcon(resources.find('img/remove.png')))

            create_current_act = -1
        else:
            create_current_act = menu.addAction('New from Current Layout...')

            menu.addSeparator()

            paste_act = menu.addAction('Paste Layout')

            menu.addSeparator()

            export_act = menu.addAction('Export Toolbar...')
            import_act = menu.addAction('Import Toolbar...')

            save_act = -1
            edit_act = -1
            copy_act = -1
            copy_as_act = -1
            rem_act = -1

            paste_act.setIcon(QIcon(resources.find('img/paste.png')))

        # run the menu
        act = menu.exec_(QCursor.pos())

        # create a new profile
        if (act == new_act):
            self.createProfile()

        # create a new clear profile
        elif (act == create_current_act):
            self.createProfile(clearLayout=False)

        # edit an existing profile
        elif (act == edit_act):
            self.editProfile(prof)

        # save or create a new profile
        elif (act == save_act):
            self.saveProfileLayout(prof)

        # copy profile
        elif (act == copy_act):
            QApplication.clipboard().setText(prof.toString())

        # copy profile as
        elif (act == copy_as_act):
            self.createProfile(profile=prof.duplicate())

        # export
        elif (act == export_act):
            self.exportProfiles()

        # export
        elif (act == import_act):
            self.importProfiles()

        # paste profile
        elif (act == paste_act):
            text = QApplication.clipboard().text()
            prof = XViewProfile.fromString(text)
            if (not prof.isEmpty()):
                self.createProfile(profile=prof)

        # remove the profile
        elif (act == rem_act):
            self.removeProfile(prof)
Exemple #15
0
    def showProfileMenu(self, point):
        """
        Prompts the user for profile menu options.  Editing needs to be enabled
        for this to work.
        """
        if not self.isEditingEnabled():
            return

        trigger = self.actionAt(point)
        if (isinstance(trigger, XViewProfileAction)):
            prof = trigger.profile()
        else:
            prof = None

        # define the menu
        menu = QMenu(self)
        acts = {}
        text = self.profileText()

        # user right clicked on a profile
        if prof:
            acts['edit'] = menu.addAction('Edit {0}...'.format(text))
            acts['save'] = menu.addAction('Save Layout')

            menu.addSeparator()

            acts['copy'] = menu.addAction('Copy {0}'.format(text))
            acts['export'] = menu.addAction('Export {0}...'.format(text))

            menu.addSeparator()

            acts['remove'] = menu.addAction('Delete {0}'.format(text))

        # show toolbar options
        else:
            acts['new'] = menu.addAction('New Layout'.format(text))

            menu.addSeparator()

            acts['save_as'] = menu.addAction('Save Layout as...')

            if QApplication.clipboard().text():
                acts['paste'] = menu.addAction('Paste {0}'.format(text))
            acts['import'] = menu.addAction('Import {0}...'.format(text))

        for key, act in acts.items():
            act.setIcon(QIcon(resources.find('img/{0}.png'.format(key))))

        # run the menu
        act = menu.exec_(QCursor.pos())

        # create a new profile
        if act is None:
            return

        elif act == acts.get('new'):
            self.clearActive()

        # create a new clear profile
        elif act == acts.get('save_as'):
            self.saveProfileAs()

        # edit an existing profile
        elif act == acts.get('edit'):
            self.editProfile(prof)

        # save or create a new profile
        elif act == acts.get('save'):
            self.saveProfileLayout(prof)

        # copy profile
        elif act == acts.get('copy'):
            QApplication.clipboard().setText(prof.toString())

        # export
        elif act == acts.get('export'):
            self.exportProfile(prof)

        # export
        elif act == acts.get('import'):
            self.importProfile()

        # paste profile
        elif act == acts.get('paste'):
            text = QApplication.clipboard().text()
            try:
                prof = XViewProfile.fromString(text)
            except:
                prof = None
                QMessageBox.information(self.window(),
                                        'Invalid {0}'.format(text),
                                        'The clipboard text does not contain '\
                                        'a properly formated {0}'.format(text))

            if prof and not prof.isEmpty():
                self.createProfile(profile=prof)

        # paste as profile
        elif act == acts.get('paste_as'):
            text = QApplication.clipboard().text()
            prof = XViewProfile.fromString(text)
            if not prof.isEmpty():
                if XViewProfileDialog.edit(self, prof):
                    self.createProfile(profile=prof)

        # remove the profile
        elif act == acts.get('remove'):
            self.removeProfile(prof)
 def showProfileMenu(self, point):
     """
     Prompts the user for profile menu options.  Editing needs to be enabled
     for this to work.
     """
     if not self.isEditingEnabled():
         return
     
     trigger = self.actionAt(point)
     if (isinstance(trigger, XViewProfileAction)):
         prof = trigger.profile()
     else:
         prof = None
     
     # define the menu
     menu = QMenu(self)
     acts = {}
     text = self.profileText()
     
     # user right clicked on a profile
     if prof:
         acts['edit'] = menu.addAction('Edit {0}...'.format(text))
         acts['save'] = menu.addAction('Save Layout')
         
         menu.addSeparator()
         
         acts['copy'] = menu.addAction('Copy {0}'.format(text))
         acts['export'] = menu.addAction('Export {0}...'.format(text))
         
         menu.addSeparator()
         
         acts['remove'] = menu.addAction('Delete {0}'.format(text))
     
     # show toolbar options
     else:
         acts['new'] = menu.addAction('New Layout'.format(text))
         
         menu.addSeparator()
         
         acts['save_as'] = menu.addAction('Save Layout as...')
         
         if QApplication.clipboard().text():
             acts['paste'] = menu.addAction('Paste {0}'.format(text))
         acts['import'] = menu.addAction('Import {0}...'.format(text))
     
     for key, act in acts.items():
         act.setIcon(QIcon(resources.find('img/{0}.png'.format(key))))
     
     # run the menu
     act = menu.exec_(QCursor.pos())
     
     # create a new profile
     if act is None:
         return
     
     elif act == acts.get('new'):
         self.clearActive()
     
     # create a new clear profile
     elif act == acts.get('save_as'):
         self.saveProfileAs()
     
     # edit an existing profile
     elif act == acts.get('edit'):
         self.editProfile(prof)
     
     # save or create a new profile
     elif act == acts.get('save'):
         self.saveProfileLayout(prof)
         
     # copy profile
     elif act == acts.get('copy'):
         QApplication.clipboard().setText(prof.toString())
     
     # export
     elif act == acts.get('export'):
         self.exportProfile(prof)
     
     # export
     elif act == acts.get('import'):
         self.importProfile()
     
     # paste profile
     elif act == acts.get('paste'):
         text = QApplication.clipboard().text()
         try:
             prof = XViewProfile.fromString(text)
         except:
             prof = None
             QMessageBox.information(self.window(),
                                     'Invalid {0}'.format(text),
                                     'The clipboard text does not contain '\
                                     'a properly formated {0}'.format(text))
             
         if prof and not prof.isEmpty():
             self.createProfile(profile=prof)
     
     # paste as profile
     elif act == acts.get('paste_as'):
         text = QApplication.clipboard().text()
         prof = XViewProfile.fromString(text)
         if not prof.isEmpty():
             if XViewProfileDialog.edit(self, prof):
                 self.createProfile(profile=prof)
     
     # remove the profile
     elif act == acts.get('remove'):
         self.removeProfile(prof)
Exemple #17
0
class XViewProfileToolBar(XToolBar):
    profileCreated = Signal(PyObject)
    profileChanged = Signal(PyObject)
    profileRemoved = Signal(PyObject)
    profilesChanged = Signal()
    currentProfileChanged = Signal(PyObject)
    loadProfileFinished = Signal(PyObject)
    newWindowProfileRequested = Signal(PyObject)

    def __init__(self, parent):
        super(XViewProfileToolBar, self).__init__(parent)

        # create custom properties
        self._editingEnabled = True
        self._viewWidget = None
        self._profileText = 'Profile'
        self._profileGroup = QActionGroup(self)
        self._currentProfile = None

        # set the default options
        self.setIconSize(QSize(48, 48))
        self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        self.setContextMenuPolicy(Qt.CustomContextMenu)

        # create connections
        self.actionTriggered.connect(self.handleActionTrigger)
        self.customContextMenuRequested.connect(self.showProfileMenu)

    def addProfile(self, profile):
        """
        Adds the inputed profile as an action to the toolbar.
        
        :param      profile | <projexui.widgets.xviewwidget.XViewProfile>
        """
        # use the existing version
        for exist in self.profiles():
            if exist.name() == profile.name():
                if exist.version() < profile.version():
                    exist.setProfile(profile)

                return

        # otherwise create a new profile
        act = XViewProfileAction(profile, self)
        self._profileGroup.addAction(act)
        self.addAction(act)
        return act

    def clearActive(self):
        # clear the GUI
        self.blockSignals(True)
        for act in self.actions():
            act.blockSignals(True)
            act.setChecked(False)
            act.blockSignals(False)
        self.blockSignals(False)

        self._currentProfile = None

        # reset the layout
        widget = self.viewWidget()
        if self.sender() != widget:
            widget.reset(force=True)
            widget.setLocked(False)

        self.currentProfileChanged.emit(None)

    def currentProfile(self):
        """
        Returns the current profile for this toolbar.
        
        :return     <projexui.widgets.xviewwidget.XViewProfile> || None
        """
        return self._currentProfile

    def createProfile(self, profile=None, clearLayout=True):
        """
        Prompts the user to create a new profile.
        """
        if profile:
            prof = profile
        elif not self.viewWidget() or clearLayout:
            prof = XViewProfile()
        else:
            prof = self.viewWidget().saveProfile()

        blocked = self.signalsBlocked()
        self.blockSignals(False)
        changed = self.editProfile(prof)
        self.blockSignals(blocked)

        if not changed:
            return

        act = self.addProfile(prof)
        act.setChecked(True)

        # update the interface
        if self.viewWidget() and (profile or clearLayout):
            self.viewWidget().restoreProfile(prof)

        if not self.signalsBlocked():
            self.profileCreated.emit(prof)
            self.profilesChanged.emit()

    @Slot(PyObject)
    def editProfile(self, profile):
        """
        Prompts the user to edit the given profile.
        
        :param      profile | <projexui.widgets.xviewwidget.XViewProfile>
        """
        mod = XViewProfileDialog.edit(self.window(), profile)
        if not mod:
            return False

        # update the action interface
        for act in self._profileGroup.actions():
            if act.profile() == profile:
                act.setProfile(profile)
                break

        # signal the change
        if not self.signalsBlocked():
            self.profileChanged.emit(profile)
            self.profilesChanged.emit()

        return True

    def exportProfile(self, profile, filename=None):
        """
        Exports this toolbar to the given filename.
        
        :param      profile  | <XViewProfile>
                    filename | <str> || None
        """
        if not filename:
            filename = QFileDialog.getSaveFileName(self, 'Export Profile', '',
                                                   'XML Files (*.xml)')
            if type(filename) == tuple:
                filename = nativestring(filename[0])

        if not filename:
            return False

        profile.save(filename)
        return True

    def handleActionTrigger(self, action):
        """
        Handles when an action has been triggered.  If the inputed action is a 
        XViewProfileAction, then the currentProfileChanged signal will emit.
        
        :param      action | <QAction>
        """
        # trigger a particular profile
        if isinstance(action, XViewProfileAction):
            # if the user CTRL+Clicks on the action, then attempt
            # to load it in a new window
            if QApplication.keyboardModifiers() == Qt.ControlModifier:
                self.newWindowProfileRequested.emit(action.profile())
                self.setCurrentProfile(self.currentProfile())
                return
            else:
                self.setCurrentProfile(action.profile())

    def importProfile(self, filename=None):
        """
        Imports the profiles from the given filename.
        
        :param      filename | <str> || None
        """
        if not filename:
            filename = QFileDialog.getOpenFileName(self, 'Import Perspective',
                                                   '', 'XML Files (*.xml)')

            if type(filename) == tuple:
                filename = nativestring(filename[0])

        if not (filename and os.path.exists(filename)):
            return False

        prof = XViewProfile.load(filename)
        if prof:
            self.addProfile(prof)

    def isEditingEnabled(self):
        """
        Sets whether or not the create is enabled for this toolbar.
        
        :return     <bool>
        """
        return self._editingEnabled

    def isEmpty(self):
        """
        Returns whether or not this toolbar is empty.
        
        :return     <bool>
        """
        return len(self._profileGroup.actions()) == 0

    def loadString(self, profilestr, merge=False, loadProfile=True):
        """
        Loads the information for this toolbar from the inputed string.
        
        :param      profilestr | <str>
        """
        try:
            xtoolbar = ElementTree.fromstring(nativestring(profilestr))
        except ExpatError, e:
            return

        if not merge:
            self.clear()

        self.blockSignals(True)
        for xprofile in xtoolbar:
            prof = XViewProfile.fromXml(xprofile)

            if merge:
                self.removeProfile(prof.name(), silent=True)

            self.addProfile(prof)

        self.setCurrentProfile(xtoolbar.get('current'))

        self.blockSignals(False)
        self.profilesChanged.emit()
Exemple #18
0
class XViewProfileToolBar(XToolBar):
    profileCreated = qt.Signal(qt.PyObject)
    profileChanged = qt.Signal(qt.PyObject)
    profileRemoved = qt.Signal(qt.PyObject)
    currentProfileChanged = qt.Signal(qt.PyObject)

    def __init__(self, parent):
        super(XViewProfileToolBar, self).__init__(parent)

        # create custom properties
        self._editingEnabled = True
        self._viewWidget = None
        self._profileGroup = QActionGroup(self)

        # set the default options
        self.setIconSize(QSize(48, 48))
        self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        self.setContextMenuPolicy(Qt.CustomContextMenu)

        # create connections
        self.actionTriggered.connect(self.handleActionTrigger)
        self.customContextMenuRequested.connect(self.showProfileMenu)

    def addProfile(self, profile):
        """
        Adds the inputed profile as an action to the toolbar.
        
        :param      profile | <projexui.widgets.xviewwidget.XViewProfile>
        """
        act = XViewProfileAction(profile, self)
        self._profileGroup.addAction(act)
        self.addAction(act)
        return act

    def currentProfile(self):
        """
        Returns the current profile for this toolbar.
        
        :return     <projexui.widgets.xviewwidget.XViewProfile> || None
        """
        act = self._profileGroup.checkedAction()
        if (act):
            return act.profile()
        return None

    def createProfile(self, profile=None, clearLayout=True):
        """
        Prompts the user to create a new profile.
        """
        if (profile):
            prof = profile
        elif (not self.viewWidget() or clearLayout):
            prof = XViewProfile()
        else:
            prof = self.viewWidget().saveProfile()

        blocked = self.signalsBlocked()
        self.blockSignals(False)
        changed = self.editProfile(prof)
        self.blockSignals(blocked)

        if (not changed):
            return

        act = self.addProfile(prof)
        act.setChecked(True)

        # update the interface
        if (self.viewWidget() and (profile or clearLayout)):
            self.viewWidget().restoreProfile(prof)

        if (not self.signalsBlocked()):
            self.profileCreated.emit(prof)

    @qt.Slot(qt.PyObject)
    def editProfile(self, profile):
        """
        Prompts the user to edit the given profile.
        
        :param      profile | <projexui.widgets.xviewwidget.XViewProfile>
        """
        mod = XViewProfileDialog.edit(self, profile)
        if (not mod):
            return False

        # update the action interface
        for act in self._profileGroup.actions():
            if (act.profile() == profile):
                act.setProfile(profile)
                break

        # signal the change
        if (not self.signalsBlocked()):
            self.profileChanged.emit(profile)

        return True

    def exportProfiles(self, filename=None):
        """
        Exports this toolbar to the given filename.
        
        :param      filename | <str> || None
        """
        if (not filename):
            filename = QFileDialog.getSaveFileName(self, 'Export Toolbar', '',
                                                   'Toolbar Files (*.xtool)')

        if (not filename):
            return False

        profile_xml = self.toXml()

        projex.text.xmlindent(profile_xml)
        profile_string = ElementTree.tostring(profile_xml)

        f = open(str(filename), 'w')
        f.write(profile_string)
        f.close()

        return True

    def handleActionTrigger(self, action):
        """
        Handles when an action has been triggered.  If the inputed action is a 
        XViewProfileAction, then the currentProfileChanged signal will emit.
        
        :param      action | <QAction>
        """
        # trigger a particular profile
        if (isinstance(action, XViewProfileAction)):
            if (not self.signalsBlocked()):
                self.currentProfileChanged.emit(action.profile())

            if (self._viewWidget):
                self._viewWidget.restoreProfile(action.profile())

    def importProfiles(self, filename=None):
        """
        Imports the profiles from the given filename.
        
        :param      filename | <str> || None
        """
        if (not filename):
            filename = QFileDialog.getOpenFileName(self, 'Import Toolbar', '',
                                                   'Toolbar Files (*.xtool)')

            if type(filename) == tuple:
                filename = str(filename[0])

        if (not (filename and os.path.exists(filename))):
            return False

        f = open(str(filename), 'r')
        profile_string = f.read()
        f.close()

        self.loadString(profile_string)

        # load the default toolbar
        action = self._profileGroup.checkedAction()
        if (action):
            self.handleActionTrigger(action)

    def isEditingEnabled(self):
        """
        Sets whether or not the create is enabled for this toolbar.
        
        :return     <bool>
        """
        return self._editingEnabled

    def isEmpty(self):
        """
        Returns whether or not this toolbar is empty.
        
        :return     <bool>
        """
        return len(self._profileGroup.actions()) == 0

    def loadString(self, profilestr):
        """
        Loads the information for this toolbar from the inputed string.
        
        :param      profilestr | <str>
        """
        try:
            xtoolbar = ElementTree.fromstring(str(profilestr))
        except ExpatError, e:
            return

        self.clear()
        curr = xtoolbar.get('current')

        for xprofile in xtoolbar:
            prof = XViewProfile.fromXml(xprofile)
            act = self.addProfile(prof)
            if (prof.name() == curr):
                act.setChecked(True)
 def showProfileMenu( self, point ):
     """
     Prompts the user for profile menu options.  Editing needs to be enabled
     for this to work.
     """
     if ( not self.isEditingEnabled() ):
         return
     
     trigger = self.actionAt(point)
     if (isinstance(trigger, XViewProfileAction)):
         prof = trigger.profile()
     else:
         prof = None
     
     # define the menu
     menu = QMenu(self)
     
     new_act  = menu.addAction('New Blank Layout...')
     new_act.setIcon( QIcon(resources.find('img/add.png')))
     
     if ( prof ):
         edit_act = menu.addAction('Edit Information...')
         menu.addSeparator()
         
         save_act    = menu.addAction('Save from Current Layout')
         copy_act    = menu.addAction('Copy Layout')
         copy_as_act = menu.addAction('Copy Layout as...')
         paste_act   = menu.addAction('Paste Layout')
         
         menu.addSeparator()
         
         export_act  = menu.addAction('Export Toolbar...')
         import_act  = menu.addAction('Import Toolbar...')
         
         menu.addSeparator()
         
         rem_act  = menu.addAction('Remove Layout')
         
         # set the icons
         save_act.setIcon(QIcon(resources.find('img/save.png')))
         edit_act.setIcon(QIcon(resources.find('img/edit.png')))
         copy_act.setIcon(QIcon(resources.find('img/copy.png')))
         paste_act.setIcon(QIcon(resources.find('img/paste.png')))
         rem_act.setIcon( QIcon(resources.find('img/remove.png')))
         
         create_current_act = -1
     else:
         create_current_act    = menu.addAction('New from Current Layout...')
         
         menu.addSeparator()
         
         paste_act   = menu.addAction('Paste Layout')
         
         menu.addSeparator()
         
         export_act  = menu.addAction('Export Toolbar...')
         import_act  = menu.addAction('Import Toolbar...')
         
         save_act    = -1
         edit_act    = -1
         copy_act    = -1
         copy_as_act = -1
         rem_act     = -1
         
         paste_act.setIcon(QIcon(resources.find('img/paste.png')))
         
     # run the menu
     act = menu.exec_(QCursor.pos())
     
     # create a new profile
     if ( act == new_act ):
         self.createProfile()
     
     # create a new clear profile
     elif ( act == create_current_act ):
         self.createProfile(clearLayout = False)
     
     # edit an existing profile
     elif ( act == edit_act ):
         self.editProfile(prof)
     
     # save or create a new profile
     elif ( act == save_act ):
         self.saveProfileLayout(prof)
         
     # copy profile
     elif ( act == copy_act ):
         QApplication.clipboard().setText(prof.toString())
     
     # copy profile as
     elif ( act == copy_as_act ):
         self.createProfile(profile = prof.duplicate())
     
     # export
     elif ( act == export_act ):
         self.exportProfiles()
     
     # export
     elif ( act == import_act ):
         self.importProfiles()
     
     # paste profile
     elif ( act == paste_act ):
         text = QApplication.clipboard().text()
         prof = XViewProfile.fromString(text)
         if ( not prof.isEmpty() ):
             self.createProfile(profile = prof)
     
     # remove the profile
     elif ( act == rem_act ):
         self.removeProfile(prof)