Beispiel #1
0
    def itemContains(self, text, columns, mainWindow=mainWindow(), caseSensitive=False):
        lst = []
        text = text.lower() if not caseSensitive else text
        for c in columns:

            if c == Outline.POV.value and self.POV():
                c = mainWindow.mdlCharacter.getCharacterByID(self.POV())
                if c:
                    searchIn = c.name()
                else:
                    searchIn = ""
                    print("Character POV not found:", self.POV())

            elif c == Outline.status.value:
                searchIn = mainWindow.mdlStatus.item(toInt(self.status()), 0).text()

            elif c == Outline.label.value:
                searchIn = mainWindow.mdlLabels.item(toInt(self.label()), 0).text()

            else:
                searchIn = self.data(c)

            searchIn = searchIn.lower() if not caseSensitive else searchIn

            if text in searchIn:
                if not self.ID() in lst:
                    lst.append(self.ID())

        return lst
Beispiel #2
0
    def itemContains(self,
                     text,
                     columns,
                     mainWindow=F.mainWindow(),
                     caseSensitive=False):
        lst = []
        text = text.lower() if not caseSensitive else text
        for c in columns:

            if c == self.enum.POV and self.POV():
                c = mainWindow.mdlCharacter.getCharacterByID(self.POV())
                if c:
                    searchIn = c.name()
                else:
                    searchIn = ""
                    print("Character POV not found:", self.POV())

            elif c == self.enum.status:
                searchIn = mainWindow.mdlStatus.item(F.toInt(self.status()),
                                                     0).text()

            elif c == self.enum.label:
                searchIn = mainWindow.mdlLabels.item(F.toInt(self.label()),
                                                     0).text()

            else:
                searchIn = self.data(c)

            searchIn = searchIn.lower() if not caseSensitive else searchIn

            if text in searchIn:
                if not self.ID() in lst:
                    lst.append(self.ID())

        return lst
Beispiel #3
0
    def setData(self, column, data, role=Qt.DisplayRole):
        if role not in [Qt.DisplayRole, Qt.EditRole, Qt.CheckStateRole]:
            print(column, column == Outline.text.value, data, role)
            return

        if column == Outline.text.value and self.isFolder():
            # Folder have no text
            return

        if column == Outline.goal.value:
            self._data[Outline.setGoal] = toInt(data) if toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [Outline.wordCount.value, Outline.goal.value, Outline.setGoal.value]:
            updateWordCount = not Outline(column) in self._data or self._data[Outline(column)] != data

        # Stuff to do before
        if column == Outline.text.value:
            self.addRevision()

        # Setting data
        self._data[Outline(column)] = data

        # Stuff to do afterwards
        if column == Outline.text.value:
            wc = wordCount(data)
            self.setData(Outline.wordCount.value, wc)

        if column == Outline.compile.value:
            self.emitDataChanged(cols=[Outline.title.value, Outline.compile.value], recursive=True)

        if updateWordCount:
            self.updateWordCount()
def test_convert():

    # toInt
    assert F.toInt("9") == 9
    assert F.toInt("a") == 0
    assert F.toInt("") == 0

    # toFloat
    assert F.toFloat("9.4") == 9.4
    assert F.toFloat("") == 0.

    # toString
    assert F.toString(None) == ""
    assert F.toString("None") == ""
    assert F.toString("Joy") == "Joy"
Beispiel #5
0
def test_convert():

    # toInt
    assert F.toInt("9") == 9
    assert F.toInt("a") == 0
    assert F.toInt("") == 0

    # toFloat
    assert F.toFloat("9.4") == 9.4
    assert F.toFloat("") == 0.

    # toString
    assert F.toString(None) == ""
    assert F.toString("None") == ""
    assert F.toString("Joy") == "Joy"
    def setEditorData(self, editor, index):
        # editor.addItem("")
        editor.addItem(QIcon.fromTheme("dialog-no"), self.tr("None"))

        l = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]
        for importance in range(3):
            editor.addItem(l[importance])
            editor.setItemData(editor.count() - 1,
                               QBrush(QColor(S.highlightedTextDark)),
                               Qt.ForegroundRole)
            editor.setItemData(editor.count() - 1,
                               QBrush(QColor(S.highlightLight)),
                               Qt.BackgroundRole)
            item = editor.model().item(editor.count() - 1)
            item.setFlags(Qt.ItemIsEnabled)
            for i in range(self.mdlCharacter.rowCount()):
                imp = toInt(self.mdlCharacter.importance(i))
                if not 2 - imp == importance: continue

                # try:
                editor.addItem(self.mdlCharacter.icon(i),
                               self.mdlCharacter.name(i),
                               self.mdlCharacter.ID(i))
                editor.setItemData(editor.count() - 1,
                                   self.mdlCharacter.name(i), Qt.ToolTipRole)
                # except:
                # pass

        editor.setCurrentIndex(editor.findData(index.data()))
        editor.showPopup()
Beispiel #7
0
 def getPlotsByImportance(self):
     plots = [[], [], []]
     for i in range(self.rowCount()):
         importance = self.item(i, Plot.importance).text()
         ID = self.item(i, Plot.ID).text()
         plots[2 - toInt(importance)].append(ID)
     return plots
Beispiel #8
0
 def getPlotNameByID(self, ID):
     for i in range(self.rowCount()):
         _ID = self.item(i, Plot.ID).text()
         if _ID == ID or toInt(_ID) == ID:
             name = self.item(i, Plot.name).text()
             return name
     return None
Beispiel #9
0
 def getPlotImportanceByID(self, ID):
     for i in range(self.rowCount()):
         _ID = self.item(i, Plot.ID).text()
         if _ID == ID or toInt(_ID) == ID:
             importance = self.item(i, Plot.importance).text()
             return importance
     return "0"  # Default to "Minor"
Beispiel #10
0
 def getPersosByImportance(self):
     persos = [[], [], []]
     for i in range(self.rowCount()):
         importance = self.item(i, Perso.importance.value).text()
         ID = self.item(i, Perso.ID.value).text()
         persos[2-toInt(importance)].append(ID)
     return persos
Beispiel #11
0
 def updateValue(self):
     if self._index:
         val = toInt(self._model.data(self._index))
         if self.sld.value() != val:
             self._updating = True
             self.setValue(val)
             self._updating = False
    def updateItems(self):
        self.clear()
        self.addItem(QIcon.fromTheme("dialog-no"), self.tr("None"))

        l = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]

        for importance in range(3):
            self.addItem(l[importance])
            self.setItemData(self.count() - 1, QBrush(QColor(S.highlightedTextDark)), Qt.ForegroundRole)
            self.setItemData(self.count() - 1, QBrush(QColor(S.highlightLight)), Qt.BackgroundRole)
            item = self.model().item(self.count() - 1)
            item.setFlags(Qt.ItemIsEnabled)
            for i in range(self.mdlCharacters.rowCount()):
                imp = toInt(self.mdlCharacters.importance(i))

                if not 2 - imp == importance:
                    continue

                self.addItem(self.mdlCharacters.icon(i), self.mdlCharacters.name(i), self.mdlCharacters.ID(i))
                self.setItemData(self.count() - 1, self.mdlCharacters.name(i), Qt.ToolTipRole)

        self._various = False

        if self._index or self._indexes:
            self.updateSelectedItem()
Beispiel #13
0
    def updatePlotPersoButton(self):
        menu = QMenu(self.mw)

        menus = []
        for i in [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]:
            m = QMenu(i, menu)
            menus.append(m)
            menu.addMenu(m)

        mpr = QSignalMapper(menu)
        for i in range(self.mw.mdlCharacter.rowCount()):
            a = QAction(self.mw.mdlCharacter.name(i), menu)
            a.setIcon(self.mw.mdlCharacter.icon(i))
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(self.mw.mdlCharacter.ID(i)))

            imp = toInt(self.mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        # Disabling empty menus
        for m in menus:
            if not m.actions():
                m.setEnabled(False)

        mpr.mapped.connect(self.addPlotPerso)
        self.mw.btnAddPlotPerso.setMenu(menu)
Beispiel #14
0
 def updateValue(self):
     if self._index:
         val = toInt(self._model.data(self._index))
         if self.sld.value() != val:
             self._updating = True
             self.setValue(val)
             self._updating = False
Beispiel #15
0
 def getPlotNameByID(self, ID):
     for i in range(self.rowCount()):
         _ID = self.item(i, Plot.ID).text()
         if _ID == ID or toInt(_ID) == ID:
             name = self.item(i, Plot.name).text()
             return name
     return None
Beispiel #16
0
 def getPlotsByImportance(self):
     plots = [[], [], []]
     for i in range(self.rowCount()):
         importance = self.item(i, Plot.importance).text()
         ID = self.item(i, Plot.ID).text()
         plots[2 - toInt(importance)].append(ID)
     return plots
Beispiel #17
0
    def updatePlotPersoButton(self):
        menu = QMenu(self.mw)

        menus = []
        for i in [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]:
            m = QMenu(i, menu)
            menus.append(m)
            menu.addMenu(m)

        mpr = QSignalMapper(menu)
        for i in range(self.mw.mdlCharacter.rowCount()):
            a = QAction(self.mw.mdlCharacter.name(i), menu)
            a.setIcon(self.mw.mdlCharacter.icon(i))
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(self.mw.mdlCharacter.ID(i)))

            imp = toInt(self.mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        # Disabling empty menus
        for m in menus:
            if not m.actions():
                m.setEnabled(False)

        mpr.mapped.connect(self.addPlotPerso)
        self.mw.btnAddPlotPerso.setMenu(menu)
    def updateItems(self):
        self.clear()
        self.addItem(QIcon.fromTheme("dialog-no"), self.tr("None"))

        l = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]

        for importance in range(3):
            self.addItem(l[importance])
            self.setItemData(self.count() - 1,
                             QBrush(QColor(S.highlightedTextDark)),
                             Qt.ForegroundRole)
            self.setItemData(self.count() - 1,
                             QBrush(QColor(S.highlightLight)),
                             Qt.BackgroundRole)
            item = self.model().item(self.count() - 1)
            item.setFlags(Qt.ItemIsEnabled)
            for i in range(self.mdlCharacters.rowCount()):
                imp = toInt(self.mdlCharacters.importance(i))

                if not 2 - imp == importance:
                    continue

                self.addItem(self.mdlCharacters.icon(i),
                             self.mdlCharacters.name(i),
                             self.mdlCharacters.ID(i))
                self.setItemData(self.count() - 1, self.mdlCharacters.name(i),
                                 Qt.ToolTipRole)

        self._various = False

        if self._index or self._indexes:
            self.updateSelectedItem()
Beispiel #19
0
    def setData(self, column, data, role=Qt.DisplayRole):

        E = self.enum

        if column == E.text and self.isFolder():
            # Folder have no text
            return

        if column == E.goal:
            self._data[E.setGoal] = F.toInt(data) if F.toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [E.wordCount, E.charCount, E.goal, E.setGoal]:
            updateWordCount = not column in self._data or self._data[
                column] != data

        # Stuff to do before
        if column == E.text:
            self.addRevision()

        # Calling base class implementation
        abstractItem.setData(self, column, data, role)

        # Stuff to do afterwards
        if column == E.text:
            wc = F.wordCount(data)
            cc = F.charCount(data, settings.countSpaces)
            self.setData(E.wordCount, wc)
            self.setData(E.charCount, cc)

        if column == E.compile:
            # Title changes when compile changes
            self.emitDataChanged(cols=[E.title, E.compile], recursive=True)

        if column == E.customIcon:
            # If custom icon changed, we tell views to update title (so that
            # icons will be updated as well)
            self.emitDataChanged(cols=[E.title])

        if updateWordCount:
            self.updateWordCount()
Beispiel #20
0
    def setData(self, column, data, role=Qt.DisplayRole):
        if role not in [Qt.DisplayRole, Qt.EditRole, Qt.CheckStateRole]:
            print(column, column == Outline.text.value, data, role)
            return

        if column == Outline.text.value and self.isFolder():
            # Folder have no text
            return

        if column == Outline.goal.value:
            self._data[Outline.setGoal] = toInt(
                data) if toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [
                Outline.wordCount.value, Outline.goal.value,
                Outline.setGoal.value
        ]:
            updateWordCount = not Outline(
                column) in self._data or self._data[Outline(column)] != data

        # Stuff to do before
        if column == Outline.text.value:
            self.addRevision()

        # Setting data
        self._data[Outline(column)] = data

        # Stuff to do afterwards
        if column == Outline.text.value:
            wc = wordCount(data)
            self.setData(Outline.wordCount.value, wc)

        if column == Outline.compile.value:
            self.emitDataChanged(
                cols=[Outline.title.value, Outline.compile.value],
                recursive=True)

        if updateWordCount:
            self.updateWordCount()
Beispiel #21
0
    def setData(self, column, data, role=Qt.DisplayRole):

        E = self.enum

        if column == E.text and self.isFolder():
            # Folder have no text
            return

        if column == E.goal:
            self._data[E.setGoal] = F.toInt(data) if F.toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [E.wordCount, E.goal, E.setGoal]:
            updateWordCount = not column in self._data or self._data[column] != data

        # Stuff to do before
        if column == E.text:
            self.addRevision()

        # Calling base class implementation
        abstractItem.setData(self, column, data, role)

        # Stuff to do afterwards
        if column == E.text:
            wc = F.wordCount(data)
            self.setData(E.wordCount, wc)

        if column == E.compile:
            # Title changes when compile changes
            self.emitDataChanged(cols=[E.title, E.compile],
                                 recursive=True)

        if column == E.customIcon:
            # If custom icon changed, we tell views to update title (so that
            # icons will be updated as well)
            self.emitDataChanged(cols=[E.title])

        if updateWordCount:
            self.updateWordCount()
Beispiel #22
0
    def searchData(self, column):
        mainWindow = F.mainWindow()

        searchData = None

        if column == self.enum.POV and self.POV():
            character = mainWindow.mdlCharacter.getCharacterByID(self.POV())
            if character:
                searchData = character.name()

        elif column == self.enum.status:
            searchData = mainWindow.mdlStatus.item(F.toInt(self.status()),
                                                   0).text()

        elif column == self.enum.label:
            searchData = mainWindow.mdlLabels.item(F.toInt(self.label()),
                                                   0).text()

        else:
            searchData = self.data(column)

        return searchData
Beispiel #23
0
    def updateWordCount(self):
        """Update word count for item and parents."""
        if not self.isFolder():
            setGoal = F.toInt(self.data(self.enum.setGoal))
            goal = F.toInt(self.data(self.enum.goal))

            if goal != setGoal:
                self._data[self.enum.goal] = setGoal
            if setGoal:
                wc = F.toInt(self.data(self.enum.wordCount))
                self.setData(self.enum.goalPercentage, wc / float(setGoal))

        else:
            wc = 0
            cc = 0
            for c in self.children():
                wc += F.toInt(c.data(self.enum.wordCount))
                cc += F.toInt(c.data(self.enum.charCount))
            self._data[self.enum.wordCount] = wc
            self._data[self.enum.charCount] = cc

            setGoal = F.toInt(self.data(self.enum.setGoal))
            goal = F.toInt(self.data(self.enum.goal))

            if setGoal:
                if goal != setGoal:
                    self._data[self.enum.goal] = setGoal
                    goal = setGoal
            else:
                goal = 0
                for c in self.children():
                    goal += F.toInt(c.data(self.enum.goal))
                self._data[self.enum.goal] = goal

            if goal:
                self.setData(self.enum.goalPercentage, wc / float(goal))
            else:
                self.setData(self.enum.goalPercentage, "")

        self.emitDataChanged([
            self.enum.goal, self.enum.setGoal, self.enum.wordCount,
            self.enum.charCount, self.enum.goalPercentage
        ])

        if self.parent():
            self.parent().updateWordCount()
Beispiel #24
0
    def updateWordCount(self, emit=True):
        """Update word count for item and parents.
        If emit is False, no signal is emitted (sometimes cause segfault)"""
        if not self.isFolder():
            setGoal = F.toInt(self.data(self.enum.setGoal))
            goal = F.toInt(self.data(self.enum.goal))

            if goal != setGoal:
                self._data[self.enum.goal] = setGoal
            if setGoal:
                wc = F.toInt(self.data(self.enum.wordCount))
                self.setData(self.enum.goalPercentage, wc / float(setGoal))

        else:
            wc = 0
            for c in self.children():
                wc += F.toInt(c.data(self.enum.wordCount))
            self._data[self.enum.wordCount] = wc

            setGoal = F.toInt(self.data(self.enum.setGoal))
            goal = F.toInt(self.data(self.enum.goal))

            if setGoal:
                if goal != setGoal:
                    self._data[self.enum.goal] = setGoal
                    goal = setGoal
            else:
                goal = 0
                for c in self.children():
                    goal += F.toInt(c.data(self.enum.goal))
                self._data[self.enum.goal] = goal

            if goal:
                self.setData(self.enum.goalPercentage, wc / float(goal))
            else:
                self.setData(self.enum.goalPercentage, "")

        if emit:
            self.emitDataChanged([
                self.enum.goal, self.enum.setGoal, self.enum.wordCount,
                self.enum.goalPercentage
            ])

        if self.parent():
            self.parent().updateWordCount(emit)
Beispiel #25
0
    def updateWordCount(self, emit=True):
        """Update word count for item and parents.
        If emit is False, no signal is emitted (sometimes cause segfault)"""
        if not self.isFolder():
            setGoal = toInt(self.data(Outline.setGoal.value))
            goal = toInt(self.data(Outline.goal.value))

            if goal != setGoal:
                self._data[Outline.goal] = setGoal
            if setGoal:
                wc = toInt(self.data(Outline.wordCount.value))
                self.setData(Outline.goalPercentage.value, wc / float(setGoal))

        else:
            wc = 0
            for c in self.children():
                wc += toInt(c.data(Outline.wordCount.value))
            self._data[Outline.wordCount] = wc

            setGoal = toInt(self.data(Outline.setGoal.value))
            goal = toInt(self.data(Outline.goal.value))

            if setGoal:
                if goal != setGoal:
                    self._data[Outline.goal] = setGoal
                    goal = setGoal
            else:
                goal = 0
                for c in self.children():
                    goal += toInt(c.data(Outline.goal.value))
                self._data[Outline.goal] = goal

            if goal:
                self.setData(Outline.goalPercentage.value, wc / float(goal))
            else:
                self.setData(Outline.goalPercentage.value, "")

        if emit:
            self.emitDataChanged([Outline.goal.value, Outline.setGoal.value,
                                  Outline.wordCount.value, Outline.goalPercentage.value])

        if self.parent():
            self.parent().updateWordCount(emit)
Beispiel #26
0
    def updatePlotPersoButton(self):
        menu = QMenu(self.mw)

        menus = []
        for i in [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]:
            m = QMenu(i, menu)
            menus.append(m)
            menu.addMenu(m)

        mpr = QSignalMapper(menu)
        for i in range(self.mw.mdlPersos.rowCount()):
            a = QAction(self.mw.mdlPersos.name(i), menu)
            a.setIcon(self.mw.mdlPersos.icon(i))
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(self.mw.mdlPersos.ID(i)))

            imp = toInt(self.mw.mdlPersos.importance(i))

            menus[2 - imp].addAction(a)

        mpr.mapped.connect(self.addPlotPerso)
        self.mw.btnAddPlotPerso.setMenu(menu)
    def setEditorData(self, editor, index):
        # editor.addItem("")
        editor.addItem(QIcon.fromTheme("dialog-no"), self.tr("None"))

        l = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]
        for importance in range(3):
            editor.addItem(l[importance])
            editor.setItemData(editor.count() - 1, QBrush(Qt.darkBlue), Qt.ForegroundRole)
            editor.setItemData(editor.count() - 1, QBrush(QColor(Qt.blue).lighter(190)), Qt.BackgroundRole)
            item = editor.model().item(editor.count() - 1)
            item.setFlags(Qt.ItemIsEnabled)
            for i in range(self.mdlCharacter.rowCount()):
                imp = toInt(self.mdlCharacter.importance(i))
                if not 2 - imp == importance: continue

                # try:
                editor.addItem(self.mdlCharacter.icon(i), self.mdlCharacter.name(i), self.mdlCharacter.ID(i))
                editor.setItemData(editor.count() - 1, self.mdlCharacter.name(i), Qt.ToolTipRole)
                # except:
                # pass

        editor.setCurrentIndex(editor.findData(index.data()))
        editor.showPopup()
Beispiel #28
0
 def getIndexFromID(self, ID):
     for i in range(self.rowCount()):
         _ID = self.item(i, Plot.ID).text()
         if _ID == ID or toInt(_ID) == ID:
             return self.index(i, 0)
     return QModelIndex()
Beispiel #29
0
    def makePopupMenu(self):
        index = self.currentIndex()
        sel = self.getSelection()
        clipboard = qApp.clipboard()

        menu = QMenu(self)

        # Add / remove items
        self.actAddFolder = QAction(
            QIcon.fromTheme("folder-new"),
            qApp.translate("outlineBasics", "New Folder"), menu)
        self.actAddFolder.triggered.connect(self.addFolder)
        menu.addAction(self.actAddFolder)

        self.actAddText = QAction(QIcon.fromTheme("document-new"),
                                  qApp.translate("outlineBasics", "New Text"),
                                  menu)
        self.actAddText.triggered.connect(self.addText)
        menu.addAction(self.actAddText)

        self.actDelete = QAction(QIcon.fromTheme("edit-delete"),
                                 qApp.translate("outlineBasics", "Delete"),
                                 menu)
        self.actDelete.triggered.connect(self.delete)
        menu.addAction(self.actDelete)

        menu.addSeparator()

        # Copy, cut, paste
        self.actCopy = QAction(QIcon.fromTheme("edit-copy"),
                               qApp.translate("outlineBasics", "Copy"), menu)
        self.actCopy.triggered.connect(self.copy)
        menu.addAction(self.actCopy)

        self.actCut = QAction(QIcon.fromTheme("edit-cut"),
                              qApp.translate("outlineBasics", "Cut"), menu)
        self.actCut.triggered.connect(self.cut)
        menu.addAction(self.actCut)

        self.actPaste = QAction(QIcon.fromTheme("edit-paste"),
                                qApp.translate("outlineBasics", "Paste"), menu)
        self.actPaste.triggered.connect(self.paste)
        menu.addAction(self.actPaste)

        menu.addSeparator()

        # POV
        self.menuPOV = QMenu(qApp.translate("outlineBasics", "Set POV"), menu)
        mw = mainWindow()
        a = QAction(QIcon.fromTheme("dialog-no"),
                    qApp.translate("outlineBasics", "None"), self.menuPOV)
        a.triggered.connect(lambda: self.setPOV(""))
        self.menuPOV.addAction(a)
        self.menuPOV.addSeparator()

        menus = []
        for i in [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]:
            m = QMenu(i, self.menuPOV)
            menus.append(m)
            self.menuPOV.addMenu(m)

        mpr = QSignalMapper(self.menuPOV)
        for i in range(mw.mdlCharacter.rowCount()):
            a = QAction(mw.mdlCharacter.icon(i), mw.mdlCharacter.name(i),
                        self.menuPOV)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(mw.mdlCharacter.ID(i)))

            imp = toInt(mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        mpr.mapped.connect(self.setPOV)
        menu.addMenu(self.menuPOV)

        # Status
        self.menuStatus = QMenu(qApp.translate("outlineBasics", "Set Status"),
                                menu)
        # a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuStatus)
        # a.triggered.connect(lambda: self.setStatus(""))
        # self.menuStatus.addAction(a)
        # self.menuStatus.addSeparator()

        mpr = QSignalMapper(self.menuStatus)
        for i in range(mw.mdlStatus.rowCount()):
            a = QAction(mw.mdlStatus.item(i, 0).text(), self.menuStatus)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuStatus.addAction(a)
        mpr.mapped.connect(self.setStatus)
        menu.addMenu(self.menuStatus)

        # Labels
        self.menuLabel = QMenu(qApp.translate("outlineBasics", "Set Label"),
                               menu)
        mpr = QSignalMapper(self.menuLabel)
        for i in range(mw.mdlLabels.rowCount()):
            a = QAction(
                mw.mdlLabels.item(i, 0).icon(),
                mw.mdlLabels.item(i, 0).text(), self.menuLabel)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuLabel.addAction(a)
        mpr.mapped.connect(self.setLabel)
        menu.addMenu(self.menuLabel)

        if len(sel) > 0 and index.isValid() and not index.internalPointer().isFolder() \
                or not clipboard.mimeData().hasFormat("application/xml"):
            self.actPaste.setEnabled(False)

        if len(sel) > 0 and index.isValid(
        ) and not index.internalPointer().isFolder():
            self.actAddFolder.setEnabled(False)
            self.actAddText.setEnabled(False)

        if len(sel) == 0:
            self.actCopy.setEnabled(False)
            self.actCut.setEnabled(False)
            self.actDelete.setEnabled(False)
            self.menuPOV.setEnabled(False)
            self.menuStatus.setEnabled(False)
            self.menuLabel.setEnabled(False)

        return menu
Beispiel #30
0
    def makePopupMenu(self):
        index = self.currentIndex()
        sel = self.getSelection()
        clipboard = qApp.clipboard()

        menu = QMenu(self)

        # Add / remove items
        self.actOpen = QAction(QIcon.fromTheme("go-right"),
                               qApp.translate("outlineBasics", "Open Item"),
                               menu)
        self.actOpen.triggered.connect(self.openItem)
        menu.addAction(self.actOpen)

        menu.addSeparator()

        # Add / remove items
        self.actAddFolder = QAction(
            QIcon.fromTheme("folder-new"),
            qApp.translate("outlineBasics", "New Folder"), menu)
        self.actAddFolder.triggered.connect(self.addFolder)
        menu.addAction(self.actAddFolder)

        self.actAddText = QAction(QIcon.fromTheme("document-new"),
                                  qApp.translate("outlineBasics", "New Text"),
                                  menu)
        self.actAddText.triggered.connect(self.addText)
        menu.addAction(self.actAddText)

        self.actDelete = QAction(QIcon.fromTheme("edit-delete"),
                                 qApp.translate("outlineBasics", "Delete"),
                                 menu)
        self.actDelete.triggered.connect(self.delete)
        menu.addAction(self.actDelete)

        menu.addSeparator()

        # Copy, cut, paste
        self.actCopy = QAction(QIcon.fromTheme("edit-copy"),
                               qApp.translate("outlineBasics", "Copy"), menu)
        self.actCopy.triggered.connect(self.copy)
        menu.addAction(self.actCopy)

        self.actCut = QAction(QIcon.fromTheme("edit-cut"),
                              qApp.translate("outlineBasics", "Cut"), menu)
        self.actCut.triggered.connect(self.cut)
        menu.addAction(self.actCut)

        self.actPaste = QAction(QIcon.fromTheme("edit-paste"),
                                qApp.translate("outlineBasics", "Paste"), menu)
        self.actPaste.triggered.connect(self.paste)
        menu.addAction(self.actPaste)

        menu.addSeparator()

        # POV
        self.menuPOV = QMenu(qApp.translate("outlineBasics", "Set POV"), menu)
        mw = mainWindow()
        a = QAction(QIcon.fromTheme("dialog-no"),
                    qApp.translate("outlineBasics", "None"), self.menuPOV)
        a.triggered.connect(lambda: self.setPOV(""))
        self.menuPOV.addAction(a)
        self.menuPOV.addSeparator()

        menus = []
        for i in [
                qApp.translate("outlineBasics", "Main"),
                qApp.translate("outlineBasics", "Secondary"),
                qApp.translate("outlineBasics", "Minor")
        ]:
            m = QMenu(i, self.menuPOV)
            menus.append(m)
            self.menuPOV.addMenu(m)

        mpr = QSignalMapper(self.menuPOV)
        for i in range(mw.mdlCharacter.rowCount()):
            a = QAction(mw.mdlCharacter.icon(i), mw.mdlCharacter.name(i),
                        self.menuPOV)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(mw.mdlCharacter.ID(i)))

            imp = toInt(mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        mpr.mapped.connect(self.setPOV)
        menu.addMenu(self.menuPOV)

        # Status
        self.menuStatus = QMenu(qApp.translate("outlineBasics", "Set Status"),
                                menu)
        # a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuStatus)
        # a.triggered.connect(lambda: self.setStatus(""))
        # self.menuStatus.addAction(a)
        # self.menuStatus.addSeparator()

        mpr = QSignalMapper(self.menuStatus)
        for i in range(mw.mdlStatus.rowCount()):
            a = QAction(mw.mdlStatus.item(i, 0).text(), self.menuStatus)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuStatus.addAction(a)
        mpr.mapped.connect(self.setStatus)
        menu.addMenu(self.menuStatus)

        # Labels
        self.menuLabel = QMenu(qApp.translate("outlineBasics", "Set Label"),
                               menu)
        mpr = QSignalMapper(self.menuLabel)
        for i in range(mw.mdlLabels.rowCount()):
            a = QAction(
                mw.mdlLabels.item(i, 0).icon(),
                mw.mdlLabels.item(i, 0).text(), self.menuLabel)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuLabel.addAction(a)
        mpr.mapped.connect(self.setLabel)
        menu.addMenu(self.menuLabel)

        menu.addSeparator()

        # Custom icons
        self.menuCustomIcons = QMenu(
            qApp.translate("outlineBasics", "Set Custom Icon"), menu)
        a = QAction(qApp.translate("outlineBasics", "Restore to default"),
                    self.menuCustomIcons)
        a.triggered.connect(lambda: self.setCustomIcon(""))
        self.menuCustomIcons.addAction(a)
        self.menuCustomIcons.addSeparator()

        txt = QLineEdit()
        txt.textChanged.connect(self.filterLstIcons)
        txt.setPlaceholderText("Filter icons")
        txt.setStyleSheet("background: transparent; border: none;")
        act = QWidgetAction(self.menuCustomIcons)
        act.setDefaultWidget(txt)
        self.menuCustomIcons.addAction(act)

        self.lstIcons = QListWidget()
        for i in customIcons():
            item = QListWidgetItem()
            item.setIcon(QIcon.fromTheme(i))
            item.setData(Qt.UserRole, i)
            item.setToolTip(i)
            self.lstIcons.addItem(item)
        self.lstIcons.itemClicked.connect(self.setCustomIconFromItem)
        self.lstIcons.setViewMode(self.lstIcons.IconMode)
        self.lstIcons.setUniformItemSizes(True)
        self.lstIcons.setResizeMode(self.lstIcons.Adjust)
        self.lstIcons.setMovement(self.lstIcons.Static)
        self.lstIcons.setStyleSheet(
            "background: transparent; background: none;")
        self.filterLstIcons("")
        act = QWidgetAction(self.menuCustomIcons)
        act.setDefaultWidget(self.lstIcons)
        self.menuCustomIcons.addAction(act)

        menu.addMenu(self.menuCustomIcons)

        # Disabling stuff
        if len(sel) > 0 and index.isValid() and not index.internalPointer().isFolder() \
                or not clipboard.mimeData().hasFormat("application/xml"):
            self.actPaste.setEnabled(False)

        if len(sel) > 0 and index.isValid(
        ) and not index.internalPointer().isFolder():
            self.actAddFolder.setEnabled(False)
            self.actAddText.setEnabled(False)

        if len(sel) == 0:
            self.actOpen.setEnabled(False)
            self.actCopy.setEnabled(False)
            self.actCut.setEnabled(False)
            self.actDelete.setEnabled(False)
            self.menuPOV.setEnabled(False)
            self.menuStatus.setEnabled(False)
            self.menuLabel.setEnabled(False)
            self.menuCustomIcons.setEnabled(False)

        return menu
Beispiel #31
0
    def makePopupMenu(self):
        index = self.currentIndex()
        sel = self.getSelection()
        clipboard = qApp.clipboard()

        menu = QMenu(self)

        # Get index under cursor
        pos = self.viewport().mapFromGlobal(QCursor.pos())
        mouseIndex = self.indexAt(pos)

        # Get index's title
        if mouseIndex.isValid():
            title = mouseIndex.internalPointer().title()

        elif self.rootIndex().parent().isValid():
            # mouseIndex is the background of an item, so we check the parent
            mouseIndex = self.rootIndex().parent()
            title = mouseIndex.internalPointer().title()

        else:
            title = qApp.translate("outlineBasics", "Root")

        if len(title) > 25:
            title = title[:25] + "…"

        # Open Item action
        self.actOpen = QAction(QIcon.fromTheme("go-right"),
                               qApp.translate("outlineBasics", "Open {}".format(title)),
                               menu)
        self.actOpen.triggered.connect(self.openItem)
        menu.addAction(self.actOpen)

        # Open item(s) in new tab
        if mouseIndex in sel and len(sel) > 1:
            actionTitle = qApp.translate("outlineBasics", "Open {} items in new tabs").format(len(sel))
            self._indexesToOpen = sel
        else:
            actionTitle = qApp.translate("outlineBasics", "Open {} in a new tab").format(title)
            self._indexesToOpen = [mouseIndex]

        self.actNewTab = QAction(QIcon.fromTheme("go-right"), actionTitle, menu)
        self.actNewTab.triggered.connect(self.openItemsInNewTabs)
        menu.addAction(self.actNewTab)

        menu.addSeparator()

        # Add text / folder
        self.actAddFolder = QAction(QIcon.fromTheme("folder-new"),
                                    qApp.translate("outlineBasics", "New &Folder"),
                                    menu)
        self.actAddFolder.triggered.connect(self.addFolder)
        menu.addAction(self.actAddFolder)

        self.actAddText = QAction(QIcon.fromTheme("document-new"),
                                  qApp.translate("outlineBasics", "New &Text"),
                                  menu)
        self.actAddText.triggered.connect(self.addText)
        menu.addAction(self.actAddText)

        menu.addSeparator()

        # Copy, cut, paste, duplicate
        self.actCut = QAction(QIcon.fromTheme("edit-cut"),
                              qApp.translate("outlineBasics", "C&ut"), menu)
        self.actCut.triggered.connect(self.cut)
        menu.addAction(self.actCut)

        self.actCopy = QAction(QIcon.fromTheme("edit-copy"),
                               qApp.translate("outlineBasics", "&Copy"), menu)
        self.actCopy.triggered.connect(self.copy)
        menu.addAction(self.actCopy)

        self.actPaste = QAction(QIcon.fromTheme("edit-paste"),
                                qApp.translate("outlineBasics", "&Paste"), menu)
        self.actPaste.triggered.connect(self.paste)
        menu.addAction(self.actPaste)

        # Rename / duplicate / remove items
        self.actDelete = QAction(QIcon.fromTheme("edit-delete"),
                                 qApp.translate("outlineBasics", "&Delete"),
                                 menu)
        self.actDelete.triggered.connect(self.delete)
        menu.addAction(self.actDelete)

        self.actRename = QAction(QIcon.fromTheme("edit-rename"),
                                 qApp.translate("outlineBasics", "&Rename"),
                                 menu)
        self.actRename.triggered.connect(self.rename)
        menu.addAction(self.actRename)

        menu.addSeparator()

        # POV
        self.menuPOV = QMenu(qApp.translate("outlineBasics", "Set POV"), menu)
        mw = mainWindow()
        a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuPOV)
        a.triggered.connect(lambda: self.setPOV(""))
        self.menuPOV.addAction(a)
        self.menuPOV.addSeparator()

        menus = []
        for i in [qApp.translate("outlineBasics", "Main"),
                  qApp.translate("outlineBasics", "Secondary"),
                  qApp.translate("outlineBasics", "Minor")]:
            m = QMenu(i, self.menuPOV)
            menus.append(m)
            self.menuPOV.addMenu(m)

        mpr = QSignalMapper(self.menuPOV)
        for i in range(mw.mdlCharacter.rowCount()):
            a = QAction(mw.mdlCharacter.icon(i), mw.mdlCharacter.name(i), self.menuPOV)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(mw.mdlCharacter.ID(i)))

            imp = toInt(mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        mpr.mapped.connect(self.setPOV)
        menu.addMenu(self.menuPOV)

        # Status
        self.menuStatus = QMenu(qApp.translate("outlineBasics", "Set Status"), menu)
        # a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuStatus)
        # a.triggered.connect(lambda: self.setStatus(""))
        # self.menuStatus.addAction(a)
        # self.menuStatus.addSeparator()

        mpr = QSignalMapper(self.menuStatus)
        for i in range(mw.mdlStatus.rowCount()):
            a = QAction(mw.mdlStatus.item(i, 0).text(), self.menuStatus)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuStatus.addAction(a)
        mpr.mapped.connect(self.setStatus)
        menu.addMenu(self.menuStatus)

        # Labels
        self.menuLabel = QMenu(qApp.translate("outlineBasics", "Set Label"), menu)
        mpr = QSignalMapper(self.menuLabel)
        for i in range(mw.mdlLabels.rowCount()):
            a = QAction(mw.mdlLabels.item(i, 0).icon(),
                        mw.mdlLabels.item(i, 0).text(),
                        self.menuLabel)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuLabel.addAction(a)
        mpr.mapped.connect(self.setLabel)
        menu.addMenu(self.menuLabel)

        menu.addSeparator()

        # Custom icons
        if self.menuCustomIcons:
            menu.addMenu(self.menuCustomIcons)
        else:
            self.menuCustomIcons = QMenu(qApp.translate("outlineBasics", "Set Custom Icon"), menu)
            a = QAction(qApp.translate("outlineBasics", "Restore to default"), self.menuCustomIcons)
            a.triggered.connect(lambda: self.setCustomIcon(""))
            self.menuCustomIcons.addAction(a)
            self.menuCustomIcons.addSeparator()

            txt = QLineEdit()
            txt.textChanged.connect(self.filterLstIcons)
            txt.setPlaceholderText("Filter icons")
            txt.setStyleSheet("QLineEdit { background: transparent; border: none; }")
            act = QWidgetAction(self.menuCustomIcons)
            act.setDefaultWidget(txt)
            self.menuCustomIcons.addAction(act)

            self.lstIcons = QListWidget()
            for i in customIcons():
                item = QListWidgetItem()
                item.setIcon(QIcon.fromTheme(i))
                item.setData(Qt.UserRole, i)
                item.setToolTip(i)
                self.lstIcons.addItem(item)
            self.lstIcons.itemClicked.connect(self.setCustomIconFromItem)
            self.lstIcons.setViewMode(self.lstIcons.IconMode)
            self.lstIcons.setUniformItemSizes(True)
            self.lstIcons.setResizeMode(self.lstIcons.Adjust)
            self.lstIcons.setMovement(self.lstIcons.Static)
            self.lstIcons.setStyleSheet("background: transparent; background: none;")
            self.filterLstIcons("")
            act = QWidgetAction(self.menuCustomIcons)
            act.setDefaultWidget(self.lstIcons)
            self.menuCustomIcons.addAction(act)

            menu.addMenu(self.menuCustomIcons)

        # Disabling stuff
        if not clipboard.mimeData().hasFormat("application/xml"):
            self.actPaste.setEnabled(False)

        if len(sel) == 0:
            self.actCopy.setEnabled(False)
            self.actCut.setEnabled(False)
            self.actRename.setEnabled(False)
            self.actDelete.setEnabled(False)
            self.menuPOV.setEnabled(False)
            self.menuStatus.setEnabled(False)
            self.menuLabel.setEnabled(False)
            self.menuCustomIcons.setEnabled(False)

        if len(sel) > 1:
            self.actRename.setEnabled(False)

        return menu
Beispiel #32
0
    def makePopupMenu(self):
        index = self.currentIndex()
        sel = self.getSelection()
        clipboard = qApp.clipboard()

        menu = QMenu(self)

        # Get index under cursor
        pos = self.viewport().mapFromGlobal(QCursor.pos())
        mouseIndex = self.indexAt(pos)

        # Get index's title
        if mouseIndex.isValid():
            title = mouseIndex.internalPointer().title()

        elif self.rootIndex().parent().isValid():
            # mouseIndex is the background of an item, so we check the parent
            mouseIndex = self.rootIndex().parent()
            title = mouseIndex.internalPointer().title()

        else:
            title = qApp.translate("outlineBasics", "Root")

        if len(title) > 25:
            title = title[:25] + "…"

        # Open Item action
        self.actOpen = QAction(
            QIcon.fromTheme("go-right"),
            qApp.translate("outlineBasics", "Open {}".format(title)), menu)
        self.actOpen.triggered.connect(self.openItem)
        menu.addAction(self.actOpen)

        # Open item(s) in new tab
        if mouseIndex in sel and len(sel) > 1:
            actionTitle = qApp.translate("outlineBasics",
                                         "Open {} items in new tabs").format(
                                             len(sel))
            self._indexesToOpen = sel
        else:
            actionTitle = qApp.translate("outlineBasics",
                                         "Open {} in a new tab").format(title)
            self._indexesToOpen = [mouseIndex]

        self.actNewTab = QAction(QIcon.fromTheme("go-right"), actionTitle,
                                 menu)
        self.actNewTab.triggered.connect(self.openItemsInNewTabs)
        menu.addAction(self.actNewTab)

        menu.addSeparator()

        # Add text / folder
        self.actAddFolder = QAction(
            QIcon.fromTheme("folder-new"),
            qApp.translate("outlineBasics", "New &Folder"), menu)
        self.actAddFolder.triggered.connect(self.addFolder)
        menu.addAction(self.actAddFolder)

        self.actAddText = QAction(QIcon.fromTheme("document-new"),
                                  qApp.translate("outlineBasics", "New &Text"),
                                  menu)
        self.actAddText.triggered.connect(self.addText)
        menu.addAction(self.actAddText)

        menu.addSeparator()

        # Copy, cut, paste, duplicate
        self.actCut = QAction(QIcon.fromTheme("edit-cut"),
                              qApp.translate("outlineBasics", "C&ut"), menu)
        self.actCut.triggered.connect(self.cut)
        menu.addAction(self.actCut)

        self.actCopy = QAction(QIcon.fromTheme("edit-copy"),
                               qApp.translate("outlineBasics", "&Copy"), menu)
        self.actCopy.triggered.connect(self.copy)
        menu.addAction(self.actCopy)

        self.actPaste = QAction(QIcon.fromTheme("edit-paste"),
                                qApp.translate("outlineBasics", "&Paste"),
                                menu)
        self.actPaste.triggered.connect(self.paste)
        menu.addAction(self.actPaste)

        # Rename / duplicate / remove items
        self.actDelete = QAction(QIcon.fromTheme("edit-delete"),
                                 qApp.translate("outlineBasics", "&Delete"),
                                 menu)
        self.actDelete.triggered.connect(self.delete)
        menu.addAction(self.actDelete)

        self.actRename = QAction(QIcon.fromTheme("edit-rename"),
                                 qApp.translate("outlineBasics", "&Rename"),
                                 menu)
        self.actRename.triggered.connect(self.rename)
        menu.addAction(self.actRename)

        menu.addSeparator()

        # POV
        self.menuPOV = QMenu(qApp.translate("outlineBasics", "Set POV"), menu)
        mw = mainWindow()
        a = QAction(QIcon.fromTheme("dialog-no"),
                    qApp.translate("outlineBasics", "None"), self.menuPOV)
        a.triggered.connect(lambda: self.setPOV(""))
        self.menuPOV.addAction(a)
        self.menuPOV.addSeparator()

        menus = []
        for i in [
                qApp.translate("outlineBasics", "Main"),
                qApp.translate("outlineBasics", "Secondary"),
                qApp.translate("outlineBasics", "Minor")
        ]:
            m = QMenu(i, self.menuPOV)
            menus.append(m)
            self.menuPOV.addMenu(m)

        mpr = QSignalMapper(self.menuPOV)
        for i in range(mw.mdlCharacter.rowCount()):
            a = QAction(mw.mdlCharacter.icon(i), mw.mdlCharacter.name(i),
                        self.menuPOV)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(mw.mdlCharacter.ID(i)))

            imp = toInt(mw.mdlCharacter.importance(i))

            menus[2 - imp].addAction(a)

        mpr.mapped.connect(self.setPOV)
        menu.addMenu(self.menuPOV)

        # Status
        self.menuStatus = QMenu(qApp.translate("outlineBasics", "Set Status"),
                                menu)
        # a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuStatus)
        # a.triggered.connect(lambda: self.setStatus(""))
        # self.menuStatus.addAction(a)
        # self.menuStatus.addSeparator()

        mpr = QSignalMapper(self.menuStatus)
        for i in range(mw.mdlStatus.rowCount()):
            a = QAction(mw.mdlStatus.item(i, 0).text(), self.menuStatus)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuStatus.addAction(a)
        mpr.mapped.connect(self.setStatus)
        menu.addMenu(self.menuStatus)

        # Labels
        self.menuLabel = QMenu(qApp.translate("outlineBasics", "Set Label"),
                               menu)
        mpr = QSignalMapper(self.menuLabel)
        for i in range(mw.mdlLabels.rowCount()):
            a = QAction(
                mw.mdlLabels.item(i, 0).icon(),
                mw.mdlLabels.item(i, 0).text(), self.menuLabel)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuLabel.addAction(a)
        mpr.mapped.connect(self.setLabel)
        menu.addMenu(self.menuLabel)

        menu.addSeparator()

        # Custom icons
        if self.menuCustomIcons:
            menu.addMenu(self.menuCustomIcons)
        else:
            self.menuCustomIcons = QMenu(
                qApp.translate("outlineBasics", "Set Custom Icon"), menu)
            a = QAction(qApp.translate("outlineBasics", "Restore to default"),
                        self.menuCustomIcons)
            a.triggered.connect(lambda: self.setCustomIcon(""))
            self.menuCustomIcons.addAction(a)
            self.menuCustomIcons.addSeparator()

            txt = QLineEdit()
            txt.textChanged.connect(self.filterLstIcons)
            txt.setPlaceholderText("Filter icons")
            txt.setStyleSheet("background: transparent; border: none;")
            act = QWidgetAction(self.menuCustomIcons)
            act.setDefaultWidget(txt)
            self.menuCustomIcons.addAction(act)

            self.lstIcons = QListWidget()
            for i in customIcons():
                item = QListWidgetItem()
                item.setIcon(QIcon.fromTheme(i))
                item.setData(Qt.UserRole, i)
                item.setToolTip(i)
                self.lstIcons.addItem(item)
            self.lstIcons.itemClicked.connect(self.setCustomIconFromItem)
            self.lstIcons.setViewMode(self.lstIcons.IconMode)
            self.lstIcons.setUniformItemSizes(True)
            self.lstIcons.setResizeMode(self.lstIcons.Adjust)
            self.lstIcons.setMovement(self.lstIcons.Static)
            self.lstIcons.setStyleSheet(
                "background: transparent; background: none;")
            self.filterLstIcons("")
            act = QWidgetAction(self.menuCustomIcons)
            act.setDefaultWidget(self.lstIcons)
            self.menuCustomIcons.addAction(act)

            menu.addMenu(self.menuCustomIcons)

        # Disabling stuff
        if not clipboard.mimeData().hasFormat("application/xml"):
            self.actPaste.setEnabled(False)

        if len(sel) == 0:
            self.actCopy.setEnabled(False)
            self.actCut.setEnabled(False)
            self.actRename.setEnabled(False)
            self.actDelete.setEnabled(False)
            self.menuPOV.setEnabled(False)
            self.menuStatus.setEnabled(False)
            self.menuLabel.setEnabled(False)
            self.menuCustomIcons.setEnabled(False)

        if len(sel) > 1:
            self.actRename.setEnabled(False)

        return menu
Beispiel #33
0
 def getIndexFromID(self, ID):
     for i in range(self.rowCount()):
         _ID = self.item(i, Plot.ID).text()
         if _ID == ID or toInt(_ID) == ID:
             return self.index(i, 0)
     return QModelIndex()
Beispiel #34
0
    def makePopupMenu(self):
        index = self.currentIndex()
        sel = self.getSelection()
        clipboard = qApp.clipboard()

        menu = QMenu(self)

        # Add / remove items
        self.actAddFolder = QAction(QIcon.fromTheme("folder-new"), qApp.translate("outlineBasics", "New Folder"), menu)
        self.actAddFolder.triggered.connect(self.addFolder)
        menu.addAction(self.actAddFolder)

        self.actAddText = QAction(QIcon.fromTheme("document-new"), qApp.translate("outlineBasics", "New Text"), menu)
        self.actAddText.triggered.connect(self.addText)
        menu.addAction(self.actAddText)

        self.actDelete = QAction(QIcon.fromTheme("edit-delete"), qApp.translate("outlineBasics", "Delete"), menu)
        self.actDelete.triggered.connect(self.delete)
        menu.addAction(self.actDelete)

        menu.addSeparator()

        # Copy, cut, paste
        self.actCopy = QAction(QIcon.fromTheme("edit-copy"), qApp.translate("outlineBasics", "Copy"), menu)
        self.actCopy.triggered.connect(self.copy)
        menu.addAction(self.actCopy)

        self.actCut = QAction(QIcon.fromTheme("edit-cut"), qApp.translate("outlineBasics", "Cut"), menu)
        self.actCut.triggered.connect(self.cut)
        menu.addAction(self.actCut)

        self.actPaste = QAction(QIcon.fromTheme("edit-paste"), qApp.translate("outlineBasics", "Paste"), menu)
        self.actPaste.triggered.connect(self.paste)
        menu.addAction(self.actPaste)

        menu.addSeparator()

        # POV
        self.menuPOV = QMenu(qApp.translate("outlineBasics", "Set POV"), menu)
        mw = mainWindow()
        a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuPOV)
        a.triggered.connect(lambda: self.setPOV(""))
        self.menuPOV.addAction(a)
        self.menuPOV.addSeparator()

        menus = []
        for i in [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]:
            m = QMenu(i, self.menuPOV)
            menus.append(m)
            self.menuPOV.addMenu(m)

        mpr = QSignalMapper(self.menuPOV)
        for i in range(mw.mdlPersos.rowCount()):
            a = QAction(mw.mdlPersos.icon(i), mw.mdlPersos.name(i), self.menuPOV)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, int(mw.mdlPersos.ID(i)))

            imp = toInt(mw.mdlPersos.importance(i))

            menus[2 - imp].addAction(a)

        mpr.mapped.connect(self.setPOV)
        menu.addMenu(self.menuPOV)

        # Status
        self.menuStatus = QMenu(qApp.translate("outlineBasics", "Set Status"), menu)
        # a = QAction(QIcon.fromTheme("dialog-no"), qApp.translate("outlineBasics", "None"), self.menuStatus)
        # a.triggered.connect(lambda: self.setStatus(""))
        # self.menuStatus.addAction(a)
        # self.menuStatus.addSeparator()

        mpr = QSignalMapper(self.menuStatus)
        for i in range(mw.mdlStatus.rowCount()):
            a = QAction(mw.mdlStatus.item(i, 0).text(), self.menuStatus)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuStatus.addAction(a)
        mpr.mapped.connect(self.setStatus)
        menu.addMenu(self.menuStatus)

        # Labels
        self.menuLabel = QMenu(qApp.translate("outlineBasics", "Set Label"), menu)
        mpr = QSignalMapper(self.menuLabel)
        for i in range(mw.mdlLabels.rowCount()):
            a = QAction(mw.mdlLabels.item(i, 0).icon(),
                        mw.mdlLabels.item(i, 0).text(),
                        self.menuLabel)
            a.triggered.connect(mpr.map)
            mpr.setMapping(a, i)
            self.menuLabel.addAction(a)
        mpr.mapped.connect(self.setLabel)
        menu.addMenu(self.menuLabel)

        if len(sel) > 0 and index.isValid() and not index.internalPointer().isFolder() \
                or not clipboard.mimeData().hasFormat("application/xml"):
            self.actPaste.setEnabled(False)

        if len(sel) > 0 and index.isValid() and not index.internalPointer().isFolder():
            self.actAddFolder.setEnabled(False)
            self.actAddText.setEnabled(False)

        if len(sel) == 0:
            self.actCopy.setEnabled(False)
            self.actCut.setEnabled(False)
            self.actDelete.setEnabled(False)
            self.menuPOV.setEnabled(False)
            self.menuStatus.setEnabled(False)
            self.menuLabel.setEnabled(False)

        return menu