Exemplo n.º 1
0
class TextboxWidget(TritonWidget):
    def __init__(self, base, name):
        TritonWidget.__init__(self, base)
        self.name = name
        self.setBackgroundColor(self, Qt.white)

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

        self.label = QLabel()
        self.label.setText(name)
        self.label.setFont(QFont('Helvetica', 10))

        self.box = QLineEdit()
        self.box.setFixedWidth(250)
        self.box.setFont(QFont('Helvetica', 10))

        self.layout.addWidget(self.label)
        self.layout.addWidget(self.box)
Exemplo n.º 2
0
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(480, 150)
        self.buttonBox = QDialogButtonBox(Dialog)
        self.buttonBox.setObjectName(u"buttonBox")
        self.buttonBox.setGeometry(QRect(0, 100, 461, 32))
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Apply|QDialogButtonBox.Cancel)
        self.label = QLabel(Dialog)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(10, 20, 81, 16))
        self.label_2 = QLabel(Dialog)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(240, 20, 57, 14))
        self.key = QLineEdit(Dialog)
        self.key.setObjectName(u"key")
        self.key.setGeometry(QRect(10, 40, 211, 22))
        font = QFont()
        font.setFamilies([u"Monospace"])
        self.key.setFont(font)
        self.val = QLineEdit(Dialog)
        self.val.setObjectName(u"val")
        self.val.setGeometry(QRect(240, 40, 211, 22))
        font1 = QFont()
        self.val.setFont(font1)

        self.retranslateUi(Dialog)
        self.buttonBox.accepted.connect(Dialog.accept)
        self.buttonBox.rejected.connect(Dialog.reject)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Add key", None))
        self.label.setText(QCoreApplication.translate("Dialog", u"Key:", None))
        self.label_2.setText(QCoreApplication.translate("Dialog", u"Value:", None))
Exemplo n.º 3
0
class WindowSearch(QWidget):
    def __init__(self,
                 heading,
                 parent=None,
                 counter=0,
                 pastResults={},
                 grid=False):
        QWidget.__init__(self)
        self.setParent(parent)
        self.heading = heading
        self.counter = counter
        self.pastResults = pastResults

        # Set layout and spacings
        layout = QGridLayout()

        # The heading of the widget
        label = QLabel(heading)
        label.setAlignment(Qt.AlignCenter)
        label.setFixedHeight(40)
        # TODO: Change with global themes
        label.setStyleSheet("color: white;")
        # Font for the label
        font = QFont()
        font.setPixelSize(25)
        font.setBold(True)
        label.setFont(font)
        layout.addWidget(label, 0, 0)

        # Add back button
        if self.counter:
            backButton = QToolButton()
            backButton.setText("🡸")
            font = QFont()
            font.setPointSize(30)
            backButton.setFont(font)
            backButton.setFixedSize(QSize(40, 40))
            backButton.setAutoRaise(True)
            backButton.setStyleSheet(
                "QToolButton { color: white; background-color: transparent;} QToolButton:pressed {background-color: rgba(255, 255, 255, 0.1);}"
            )
            layout.addWidget(backButton, 0, 0)
            backButton.clicked.connect(self.goBack)

        # Sub heading if this is an indepth search
        sublabel = QLabel()
        sublabel.setFixedHeight(20)
        if self.pastResults:
            sublabel.setAlignment(Qt.AlignCenter)
            # TODO: Change with global themes
            sublabel.setStyleSheet("color: white;")
            if "artist_id" in self.pastResults:
                sublabel.setText("Artist: " + self.pastResults["artist_name"])
            elif "language_id" in self.pastResults:
                sublabel.setText("Language: " +
                                 self.pastResults["language_name"])
            elif "playlist_id" in self.pastResults:
                sublabel.setText("Playlist: " +
                                 self.pastResults["playlist_name"])
            font = QFont()
            font.setPixelSize(15)
            font.setItalic(True)
            sublabel.setFont(font)
        layout.addWidget(sublabel, 1, 0)

        # Set searchbar
        self.searchBar = QLineEdit(self)
        # TODO: change with resizeEvent
        self.searchBar.setMinimumWidth(800)
        font = QFont()
        font.setPointSize(20)
        self.searchBar.setFont(font)
        layout.addWidget(self.searchBar, 2, 0)
        layout.setAlignment(self.searchBar, Qt.AlignCenter)

        # Set results page
        if (grid):
            self.results = self.ResultsGrid(self)
            layout.addWidget(self.results, 3, 0)
        else:
            self.results = self.ResultsList(self)
            layout.addWidget(self.results, 3, 0)

        self.searchBar.textEdited.connect(self.updateResults)
        self.updateResults()

        self.setLayout(layout)

    def updateResults(self):
        # Depending on heading, update page
        if self.heading == "播放清单/Playlists":
            self.results.addResults(DB.getPlaylists(self.searchBar.text()))
        elif self.heading == "最喜欢的歌曲/Favourite Songs":
            self.results.addResults(DB.getFavouriteSongs(
                self.searchBar.text()))
        elif self.heading == "最喜欢的歌手/Favourite Artists":
            self.results.addResults(
                DB.getFavouriteArtists(self.searchBar.text()))
        elif self.heading == "搜索语言/Language Search":
            self.results.addResults(DB.getLanguages(self.searchBar.text()))
        elif self.heading == "搜索歌手/Artist Search":
            if self.pastResults:
                self.results.addResults(
                    DB.getSongArtists(self.searchBar.text(),
                                      self.pastResults["language_id"]))
            else:
                self.results.addResults(
                    DB.getSongArtists(self.searchBar.text()))
        elif self.heading == "搜索全部/Search":
            if self.pastResults:
                if self.pastResults["type"] == "artists":
                    self.results.addResults(
                        DB.getSongTitles(self.searchBar.text(),
                                         artist=self.pastResults["artist_id"]))
                elif self.pastResults["type"] == "playlists":
                    self.results.addResults(
                        DB.getSongTitles(
                            self.searchBar.text(),
                            playlist=self.pastResults["playlist_id"]))
            else:
                self.results.addResults(DB.getSongTitles(
                    self.searchBar.text()))

    def goBack(self):
        # Move back in the QStackedWidget index
        if self.counter:
            self.window().content.setCurrentIndex(self.counter - 1)
            self.window().content.removeWidget(self)

    class ResultsList(QScrollArea):
        def __init__(self, parent=None):
            # List View of results
            # Only Title Search and Playlist Search use this
            QScrollArea.__init__(self)
            self.setParent(parent)

            # Make QScrollArea transparent
            self.setStyleSheet(
                "QScrollArea { background-color: transparent } .QFrame { background-color: transparent }"
            )
            self.setWidgetResizable(True)
            self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

            # Add touch screen control to QScrollArea
            QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)

            # Set layout settings of the QScrollArea
            self.layout = QVBoxLayout()
            self.layout.setContentsMargins(0, 0, 0, 0)
            self.layout.setSpacing(0)

            # A separate QWidget is needed to properly use QScrollArea
            frame = QFrame()
            frame.setLayout(self.layout)

            self.setWidget(frame)

        def clearResults(self):
            # Clear the results in the list
            while self.layout.count():
                item = self.layout.takeAt(0)
                if item.widget() is not None:
                    item.widget().deleteLater()

        def addResults(self, results):
            # Add the results to the list
            # results (list): list of python dict representing results details (playlist or song search)
            self.results = results
            self.clearResults()
            if results:
                for i in self.results:
                    item = self.ResultsListItem(i, self)
                    self.layout.addWidget(item)
                self.layout.addStretch(1)
            else:
                # If the results are empty, display no result
                label = QLabel("没有结果/No Result")
                label.setStyleSheet("color: white")
                label.setAlignment(Qt.AlignCenter)
                font = QFont()
                font.setPointSize(35)
                label.setFont(font)

                self.layout.addWidget(label)

        class ResultsListItem(QToolButton):
            def __init__(self, result, parent=None):
                # An item of ResultsList
                # result: (dict) represents details (playlist or song search)
                QToolButton.__init__(self)
                self.setParent(parent)
                self.result = result

                # Button formatting
                self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
                self.setFixedHeight(70)
                self.setAutoRaise(True)
                # TODO: change with global themes
                self.setStyleSheet(
                    "QToolButton:pressed { background-color: rgba(255, 255, 255, 0.1)} QToolButton { background-color: rgba(255, 255, 255, 0.05); border: 1px solid white}"
                )

                # Set layout
                self.layout = QHBoxLayout()
                self.layout.setContentsMargins(0, 0, 0, 0)
                self.layout.setSpacing(0)

                # Depending on result type, add action when the item is clicked
                if result["type"] == "songs":
                    self.formatTitle()
                    self.clicked.connect(self.clickedSong)
                elif result["type"] == "playlists":
                    self.formatPlaylist()
                    self.clicked.connect(self.clickedPlaylist)
                self.setLayout(self.layout)

            def formatTitle(self):
                # Format the title for the ResultsList

                # Add space to the beginning of the ResultsListItem
                labelQueue = self.formattedLabel(QLabel("", self))
                labelQueue.setFixedWidth(70)
                labelQueue.setAlignment(Qt.AlignCenter)
                self.layout.addWidget(labelQueue)

                # Artist name
                labelArtist = self.formattedLabel(
                    QLabel(self.result["artist_name"]))
                labelArtist.setFixedWidth(300)
                self.layout.addWidget(labelArtist)

                # Song title
                labelTitle = self.formattedLabel(
                    QLabel(self.result["song_title"]))
                self.layout.addWidget(labelTitle)

                # Add buttons for favourites and playlists

                # Favourite button
                self.favouriteButton = QToolButton()

                # Toggle Favourite Icon depending on DB
                if self.result["favourited"] == 0:
                    self.favouriteButton.isFavourited = False
                    self.favouriteButton.setIcon(QIcon("icons/star.svg"))
                else:
                    self.favouriteButton.isFavourited = True
                    self.favouriteButton.setIcon(
                        QIcon("icons/star-yellow.svg"))

                self.favouriteButton.setIconSize(QSize(30, 30))
                self.favouriteButton.setFixedSize(70, 70)
                self.favouriteButton.clicked.connect(self.clickedFavourite)
                self.layout.addWidget(self.favouriteButton)

                # Playlist button
                playlistButton = QToolButton()
                playlistButton.setIcon(QIcon("icons/music-player-2.svg"))
                playlistButton.setIconSize(QSize(30, 30))
                playlistButton.setFixedSize(70, 70)
                playlistButton.clicked.connect(self.addToPlaylist)
                self.layout.addWidget(playlistButton)

            def formatPlaylist(self):
                # Add space to beginning of LisItem
                labelQueue = self.formattedLabel(QLabel("", self))
                labelQueue.setFixedWidth(70)
                labelQueue.setAlignment(Qt.AlignCenter)
                self.layout.addWidget(labelQueue)

                # Playlist name
                labelPlaylist = self.formattedLabel(
                    QLabel(self.result["playlist_name"]))
                self.layout.addWidget(labelPlaylist)

                # Remove playlist button
                btnRemove = QToolButton()
                btnRemove.setText("X")
                btnRemove.setFixedSize(70, 70)
                btnRemove.setStyleSheet("color: white")
                btnRemove.clicked.connect(self.removePlaylist)
                self.layout.addWidget(btnRemove)

            def formattedLabel(self, label):
                # Format a label
                font = QFont()
                font.setPixelSize(25)
                # TODO: change with global themes
                label.setStyleSheet("color: white")
                label.setSizePolicy(QSizePolicy.Expanding,
                                    QSizePolicy.Expanding)
                label.setFont(font)
                return label

            def clickedSong(self):
                # Called when a song is clicked on

                # Add to queue
                self.window().songQueue.addSong(self.result)

                if len(self.window().songQueue.getQueue()) < 2:
                    if not self.window().mediaPlayer.currentSong:
                        # If this is the first song to queue, signal media player to start it
                        self.window().mediaPlayer.skipSong()
                    # Update scrolling text marquee
                    self.window().mediaPlayer.updateMarquee()

            def clickedPlaylist(self):
                # Called when a playlist is clicked on
                self.window().content.addWidget(
                    WindowSearch(
                        "搜索全部/Search", self,
                        self.window().content.currentWidget().counter + 1,
                        self.result))
                self.window().content.setCurrentIndex(
                    self.window().content.currentWidget().counter + 1)

            def clickedFavourite(self):
                # Toggle Icon and DB state of song being favourited
                # For songs only
                if self.favouriteButton.isFavourited:
                    self.favouriteButton.isFavourited = False
                    self.favouriteButton.setIcon(QIcon("icons/star.svg"))
                else:
                    self.favouriteButton.isFavourited = True
                    self.favouriteButton.setIcon(
                        QIcon("icons/star-yellow.svg"))
                DB.setFavouriteSong(self.result["song_id"])

            def addToPlaylist(self):
                # Opens a popup for adding songs to playlists
                popup = PlaylistPopup(self.result, self.window())
                popup.resize(1366, 768)
                popup.SIGNALS.CLOSE.connect(lambda: popup.close())
                popup.show()

            def removePlaylist(self):
                # Remove a playlist
                DB.removePlaylist(self.result["playlist_id"])
                self.window().content.currentWidget().results.results.remove(
                    self.result)
                self.window().content.currentWidget().results.addResults(
                    self.window().content.currentWidget().results.results)

    class ResultsGrid(QScrollArea):
        def __init__(self, parent=None):
            QScrollArea.__init__(self)
            self.setParent(parent)

            # Make QScrollArea transparent
            self.setStyleSheet(
                "QScrollArea { background-color: transparent } .QFrame { background-color: transparent }"
            )
            self.setWidgetResizable(True)
            self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

            # Add Touch Gestures to menu.
            QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)

            # Layout settings
            self.layout = QGridLayout()
            self.layout.setContentsMargins(0, 0, 0, 0)
            self.layout.setSpacing(0)

            # QScrollArea requires a separate QWidget to work properly
            frame = QFrame()
            frame.setLayout(self.layout)

            self.setWidget(frame)

        def clearResults(self):
            # Clear the results in the list
            while self.layout.count():
                item = self.layout.takeAt(0)
                if item.widget() is not None:
                    item.widget().deleteLater()

        def addResults(self, results):
            # Add the results to the list
            # results (list): list of python dict representing results details (playlist or song search)
            self.clearResults()
            for i in range(len(results)):
                item = self.ResultsGridItem(results[i], self)
                self.layout.addWidget(item, i // 6, i % 6)
            if results:
                self.layout.setRowStretch(self.layout.rowCount(), 1)
                self.layout.setColumnStretch(self.layout.columnCount(), 1)
            else:
                # If the results are empty, display no result
                label = QLabel("没有结果/No Result")
                label.setStyleSheet("color: white")
                label.setAlignment(Qt.AlignCenter)
                font = QFont()
                font.setPointSize(35)
                label.setFont(font)

                self.layout.addWidget(label)

        class ResultsGridItem(QToolButton):
            def __init__(self, result, parent=None):
                QToolButton.__init__(self)
                self.setParent(parent)
                self.result = result

                self.setContentsMargins(0, 0, 0, 0)
                # Button formatting
                self.setFixedSize(200, 240)
                self.setAutoRaise(True)
                # TODO: change with global themes
                self.setStyleSheet(
                    "QToolButton:pressed { background-color: rgba(255, 255, 255, 0.1)} QToolButton { background-color: rgba(255, 255, 255, 0.05); border: 1px solid white; color: white}"
                )

                # Set layout settings
                self.layout = QGridLayout()
                self.layout.setContentsMargins(0, 0, 0, 0)
                self.layout.setSpacing(0)

                if result["type"] == "artists":
                    # Artist image
                    self.formattedImage(self.window().artistPath +
                                        result["artist_path"])
                    self.formattedLabel(result["artist_name"])

                    # Favourite button
                    self.favouriteButton = QToolButton()
                    self.favouriteButton.setStyleSheet(
                        "QToolButton:pressed { background-color: rgb(31, 41, 75)} QToolButton { background-color: rgb(25, 33, 60);}"
                    )

                    # Toggle Favourite Icon depending on DB
                    if self.result["favourited"] == 0:
                        self.favouriteButton.isFavourited = False
                        self.favouriteButton.setIcon(QIcon("icons/star.svg"))
                    else:
                        self.favouriteButton.isFavourited = True
                        self.favouriteButton.setIcon(
                            QIcon("icons/star-yellow.svg"))
                    self.favouriteButton.setIconSize(QSize(30, 30))
                    self.favouriteButton.setFixedSize(70, 70)
                    self.favouriteButton.clicked.connect(self.clickedFavourite)
                    self.layout.addWidget(self.favouriteButton, 0, 0,
                                          Qt.AlignRight | Qt.AlignTop)

                    self.clicked.connect(self.clickedArtist)
                elif result["type"] == "languages":
                    # Language image
                    self.formattedImage(self.window().languagePath +
                                        result["language_path"])
                    self.formattedLabel(result["language_name"])
                    self.clicked.connect(self.clickedLanguage)

                self.setLayout(self.layout)

            def clickedFavourite(self):
                # Toggle Icon and DB state of song being favourited
                # For artists only
                if self.favouriteButton.isFavourited:
                    self.favouriteButton.isFavourited = False
                    self.favouriteButton.setIcon(QIcon("icons/star.svg"))
                else:
                    self.favouriteButton.isFavourited = True
                    self.favouriteButton.setIcon(
                        QIcon("icons/star-yellow.svg"))
                DB.setFavouriteArtist(self.result["artist_id"])

            def formattedImage(self, path):
                # Format an image given the path
                self.setIcon(QIcon(path))
                self.setIconSize(QSize(180, 180))

            def formattedLabel(self, text):
                # Format a label given text
                font = QFont()
                font.setPixelSize(18)
                self.setText(text)
                self.setFont(font)
                self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

            def clickedArtist(self):
                # Called when an Artist is clicked on
                self.window().content.addWidget(
                    WindowSearch(
                        "搜索全部/Search", self,
                        self.window().content.currentWidget().counter + 1,
                        self.result))
                self.window().content.setCurrentIndex(
                    self.window().content.currentWidget().counter + 1)

            def clickedLanguage(self):
                # Called when a Language is clicked on
                self.window().content.addWidget(
                    WindowSearch(
                        "搜索歌手/Artist Search",
                        self,
                        self.window().content.currentWidget().counter + 1,
                        self.result,
                        grid=True))
                self.window().content.setCurrentIndex(
                    self.window().content.currentWidget().counter + 1)
Exemplo n.º 4
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(1024, 768)
        self.actionOpen_ObjectBlueprints_xml = QAction(MainWindow)
        self.actionOpen_ObjectBlueprints_xml.setObjectName(
            u"actionOpen_ObjectBlueprints_xml")
        self.actionExit = QAction(MainWindow)
        self.actionExit.setObjectName(u"actionExit")
        self.actionWiki_template = QAction(MainWindow)
        self.actionWiki_template.setObjectName(u"actionWiki_template")
        self.actionWiki_template.setCheckable(True)
        self.actionWiki_template.setChecked(True)
        self.actionAttributes = QAction(MainWindow)
        self.actionAttributes.setObjectName(u"actionAttributes")
        self.actionAttributes.setCheckable(True)
        self.actionAll_attributes = QAction(MainWindow)
        self.actionAll_attributes.setObjectName(u"actionAll_attributes")
        self.actionAll_attributes.setCheckable(True)
        self.actionScan_wiki = QAction(MainWindow)
        self.actionScan_wiki.setObjectName(u"actionScan_wiki")
        self.actionUpload_templates = QAction(MainWindow)
        self.actionUpload_templates.setObjectName(u"actionUpload_templates")
        self.actionUpload_tiles = QAction(MainWindow)
        self.actionUpload_tiles.setObjectName(u"actionUpload_tiles")
        self.actionXML_source = QAction(MainWindow)
        self.actionXML_source.setObjectName(u"actionXML_source")
        self.actionXML_source.setCheckable(True)
        self.actionShow_help = QAction(MainWindow)
        self.actionShow_help.setObjectName(u"actionShow_help")
        self.actionUpload_extra_image_s_for_selected_objects = QAction(
            MainWindow)
        self.actionUpload_extra_image_s_for_selected_objects.setObjectName(
            u"actionUpload_extra_image_s_for_selected_objects")
        self.actionDiff_template_against_wiki = QAction(MainWindow)
        self.actionDiff_template_against_wiki.setObjectName(
            u"actionDiff_template_against_wiki")
        self.actionDark_mode = QAction(MainWindow)
        self.actionDark_mode.setObjectName(u"actionDark_mode")
        self.actionSuppress_image_comparison_popups = QAction(MainWindow)
        self.actionSuppress_image_comparison_popups.setObjectName(
            u"actionSuppress_image_comparison_popups")
        self.actionSuppress_image_comparison_popups.setCheckable(True)
        self.actionSuppress_image_comparison_popups.setChecked(False)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.gridLayout = QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName(u"gridLayout")
        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.plainTextEdit = QPlainTextEdit(self.centralwidget)
        self.plainTextEdit.setObjectName(u"plainTextEdit")
        font = QFont()
        font.setFamilies([u"Consolas"])
        font.setPointSize(10)
        self.plainTextEdit.setFont(font)
        self.plainTextEdit.setUndoRedoEnabled(False)
        self.plainTextEdit.setReadOnly(True)

        self.horizontalLayout.addWidget(self.plainTextEdit)

        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.tile_label = QLabel(self.centralwidget)
        self.tile_label.setObjectName(u"tile_label")
        self.tile_label.setMinimumSize(QSize(160, 240))
        font1 = QFont()
        font1.setFamilies([u"Segoe UI"])
        self.tile_label.setFont(font1)
        self.tile_label.setStyleSheet(u"background-color: rgb(15, 59, 58);")

        self.verticalLayout_4.addWidget(self.tile_label)

        self.save_tile_button = QPushButton(self.centralwidget)
        self.save_tile_button.setObjectName(u"save_tile_button")
        font2 = QFont()
        font2.setFamilies([u"Segoe UI"])
        font2.setPointSize(10)
        self.save_tile_button.setFont(font2)

        self.verticalLayout_4.addWidget(self.save_tile_button)

        self.swap_tile_button = QPushButton(self.centralwidget)
        self.swap_tile_button.setObjectName(u"swap_tile_button")
        self.swap_tile_button.setEnabled(True)
        self.swap_tile_button.setFont(font2)

        self.verticalLayout_4.addWidget(self.swap_tile_button)

        self.horizontalLayout.addLayout(self.verticalLayout_4)

        self.verticalLayout.addLayout(self.horizontalLayout)

        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.search_label = QLabel(self.centralwidget)
        self.search_label.setObjectName(u"search_label")
        self.search_label.setMinimumSize(QSize(0, 0))
        self.search_label.setFont(font2)

        self.horizontalLayout_2.addWidget(self.search_label)

        self.search_line_edit = QLineEdit(self.centralwidget)
        self.search_line_edit.setObjectName(u"search_line_edit")
        self.search_line_edit.setFont(font2)

        self.horizontalLayout_2.addWidget(self.search_line_edit)

        self.expand_all_button = QPushButton(self.centralwidget)
        self.expand_all_button.setObjectName(u"expand_all_button")
        self.expand_all_button.setMinimumSize(QSize(90, 0))
        self.expand_all_button.setFont(font2)

        self.horizontalLayout_2.addWidget(self.expand_all_button)

        self.collapse_all_button = QPushButton(self.centralwidget)
        self.collapse_all_button.setObjectName(u"collapse_all_button")
        self.collapse_all_button.setMinimumSize(QSize(90, 0))
        self.collapse_all_button.setFont(font2)

        self.horizontalLayout_2.addWidget(self.collapse_all_button)

        self.restore_all_button = QPushButton(self.centralwidget)
        self.restore_all_button.setObjectName(u"restore_all_button")
        self.restore_all_button.setMinimumSize(QSize(130, 0))
        self.restore_all_button.setFont(font2)

        self.horizontalLayout_2.addWidget(self.restore_all_button)

        self.verticalLayout_3.addLayout(self.horizontalLayout_2)

        self.tree_target_widget = QWidget(self.centralwidget)
        self.tree_target_widget.setObjectName(u"tree_target_widget")
        self.tree_target_widget.setFont(font1)

        self.verticalLayout_3.addWidget(self.tree_target_widget, 0,
                                        Qt.AlignBottom)

        self.verticalLayout.addLayout(self.verticalLayout_3)

        self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 1024, 21))
        self.menuFile = QMenu(self.menubar)
        self.menuFile.setObjectName(u"menuFile")
        self.menuView = QMenu(self.menubar)
        self.menuView.setObjectName(u"menuView")
        self.menuWiki = QMenu(self.menubar)
        self.menuWiki.setObjectName(u"menuWiki")
        self.menuHelp = QMenu(self.menubar)
        self.menuHelp.setObjectName(u"menuHelp")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuView.menuAction())
        self.menubar.addAction(self.menuWiki.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())
        self.menuFile.addAction(self.actionOpen_ObjectBlueprints_xml)
        self.menuFile.addAction(self.actionExit)
        self.menuView.addAction(self.actionWiki_template)
        self.menuView.addAction(self.actionAttributes)
        self.menuView.addAction(self.actionAll_attributes)
        self.menuView.addAction(self.actionXML_source)
        self.menuView.addSeparator()
        self.menuView.addAction(self.actionDark_mode)
        self.menuWiki.addAction(self.actionScan_wiki)
        self.menuWiki.addAction(self.actionDiff_template_against_wiki)
        self.menuWiki.addAction(self.actionUpload_templates)
        self.menuWiki.addAction(self.actionUpload_tiles)
        self.menuWiki.addAction(
            self.actionUpload_extra_image_s_for_selected_objects)
        self.menuWiki.addAction(self.actionSuppress_image_comparison_popups)
        self.menuHelp.addAction(self.actionShow_help)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)

    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(
            QCoreApplication.translate("MainWindow", u"Qud Blueprint Explorer",
                                       None))
        self.actionOpen_ObjectBlueprints_xml.setText(
            QCoreApplication.translate("MainWindow",
                                       u"Open ObjectBlueprints.xml...", None))
        self.actionExit.setText(
            QCoreApplication.translate("MainWindow", u"Exit", None))
        self.actionWiki_template.setText(
            QCoreApplication.translate("MainWindow", u"Wiki template", None))
        self.actionAttributes.setText(
            QCoreApplication.translate("MainWindow", u"Attributes", None))
        self.actionAll_attributes.setText(
            QCoreApplication.translate("MainWindow", u"All attributes", None))
        self.actionScan_wiki.setText(
            QCoreApplication.translate("MainWindow",
                                       u"Scan wiki for selected objects",
                                       None))
        self.actionUpload_templates.setText(
            QCoreApplication.translate(
                "MainWindow", u"Upload templates for selected objects", None))
        self.actionUpload_tiles.setText(
            QCoreApplication.translate("MainWindow",
                                       u"Upload tiles for selected objects",
                                       None))
        self.actionXML_source.setText(
            QCoreApplication.translate("MainWindow", u"XML source", None))
        self.actionShow_help.setText(
            QCoreApplication.translate("MainWindow", u"Show help", None))
        self.actionUpload_extra_image_s_for_selected_objects.setText(
            QCoreApplication.translate(
                "MainWindow", u"Upload extra image(s) for selected objects",
                None))
        self.actionDiff_template_against_wiki.setText(
            QCoreApplication.translate("MainWindow",
                                       u"Diff template against wiki", None))
        self.actionDark_mode.setText(
            QCoreApplication.translate("MainWindow", u"Toggle dark mode",
                                       None))
        self.actionSuppress_image_comparison_popups.setText(
            QCoreApplication.translate("MainWindow",
                                       u"Suppress image comparison pop-ups",
                                       None))
        self.tile_label.setText("")
        self.save_tile_button.setText(
            QCoreApplication.translate("MainWindow", u"Save tile...", None))
        self.swap_tile_button.setText(
            QCoreApplication.translate("MainWindow", u"Toggle .png/.gif",
                                       None))
        self.search_label.setText(
            QCoreApplication.translate("MainWindow", u"Search:", None))
        self.expand_all_button.setText(
            QCoreApplication.translate("MainWindow", u"Expand all", None))
        self.collapse_all_button.setText(
            QCoreApplication.translate("MainWindow", u"Collapse all", None))
        self.restore_all_button.setText(
            QCoreApplication.translate("MainWindow", u"Default expansion",
                                       None))
        self.menuFile.setTitle(
            QCoreApplication.translate("MainWindow", u"File", None))
        self.menuView.setTitle(
            QCoreApplication.translate("MainWindow", u"View type", None))
        self.menuWiki.setTitle(
            QCoreApplication.translate("MainWindow", u"Wiki", None))
        self.menuHelp.setTitle(
            QCoreApplication.translate("MainWindow", u"Help", None))
Exemplo n.º 5
0
class PlaylistPopup(QWidget):
    def __init__(self, result, parent=None):
        # Popup when "Add song to playlist" is clicked on
        # How this works is a QWidget that encompasses the entire window area, representing an unclickable translucent background.
        # Another QWidget is then contained inside that QWidget representing the popup.
        # result: (dict) Python dict containing information of the song clicked
        QWidget.__init__(self)
        self.setParent(parent)
        self.result = result

        # Signals are used to indicate to close the window
        self.SIGNALS = self.TranslucentWidgetSignals()

        # Make the window frameless and expanding.
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # Makes the window background colour translucent
        self.setAttribute(Qt.WA_StyledBackground)
        self.setStyleSheet(
            "PlaylistPopup { background-color: rgba(255, 255, 255, 0.5)}")

        # Sets the grid settings of the "background" and the "popup"
        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        playlistAdd = QWidget(self)
        playlistAdd.setFixedSize(800, 300)
        playlistAdd.setStyleSheet(
            ".QWidget { background-color: rgba(255, 255, 255, 1)}")
        innerLayout = QGridLayout()
        innerLayout.setContentsMargins(20, 20, 20, 20)
        innerLayout.setSpacing(30)

        # Heading font
        font = QFont()
        font.setPointSize(24)

        # Default label font
        font2 = QFont()
        font2.setPointSize(16)

        # Heading
        label = QLabel("添加到播放列表/Add to Playlist", self)
        label.setAlignment(Qt.AlignCenter)
        label.setFont(font)
        innerLayout.addWidget(label, 0, 0)

        # Playlist selection
        self.comboBox = QComboBox(self)
        self.comboBox.setFont(font)
        playlists = DB.getPlaylists("")
        for playlist in playlists:
            self.comboBox.addItem(playlist["playlist_name"])
        self.comboBox.setCurrentIndex(-1)
        innerLayout.addWidget(self.comboBox, 1, 0)

        # Textbox to create a new playlist
        self.textBox = QLineEdit(self)
        self.textBox.setFont(font2)
        self.textBox.setAlignment(Qt.AlignCenter)
        self.textBox.setPlaceholderText(
            "输入以创建新的播放列表/Type to create a new playlist")
        self.textBox.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        # TODO: resize textbox with window
        self.textBox.setFixedWidth(760)
        innerLayout.addWidget(self.textBox, 2, 0, Qt.AlignCenter)

        # Add actions for then the QComboBox or QLineEdit is changed.
        # This is done so there is only one action between "Add to existing Playlist" or "Add to new Playlist"
        self.comboBox.currentIndexChanged.connect(self.comboBoxChanged)
        self.textBox.textEdited.connect(self.textBoxChanged)

        # Confirm button
        confirmButton = QToolButton(self)
        confirmButton.setText("确认/Confirm")
        confirmButton.setFont(font)
        confirmButton.clicked.connect(self.processPlaylistRequest)
        innerLayout.addWidget(confirmButton, 3, 0, Qt.AlignCenter)

        # Exit button
        btn = QToolButton(self)
        btn.setFixedSize(44, 44)
        btn.setText("X")
        btn.setFont(font)
        btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        btn.clicked.connect(lambda: self.SIGNALS.CLOSE.emit())
        innerLayout.addWidget(btn, 0, 0, Qt.AlignRight)

        playlistAdd.setLayout(innerLayout)
        layout.addWidget(playlistAdd, 0, 0, Qt.AlignCenter)
        self.setLayout(layout)

    def comboBoxChanged(self):
        # Called when the ComboBox is changed
        # Clears the text in the "Create Playlist" TextBox
        if self.textBox.text() != "":
            self.textBox.setText("")

    def textBoxChanged(self):
        # Called when the TextBox is changed
        # Clears the selection in the "Add to Playlist" ComboBox
        if self.comboBox.currentIndex != -1:
            self.comboBox.setCurrentIndex(-1)

    def processPlaylistRequest(self):
        # Called when the Confirm button is clicked
        def addToPlaylist(self, playlistID):
            # Adds the song to the playlist
            # Get song ID
            song = self.result["song_id"]
            DB.addPlaylistSong(playlistID, song)

        if self.textBox.text() != "":
            # New playlist
            playlistName = self.textBox.text()
            counter = 1
            while DB.checkPlaylist(playlistName):
                playlistName = "{} ({})".format(self.textBox.text(), counter)
                counter += 1
            playlistID = DB.newPlaylist(playlistName)[0]["playlist_id"]
            addToPlaylist(self, playlistID)
            self.SIGNALS.CLOSE.emit()
        elif self.comboBox.currentIndex != -1:
            playlistID = DB.checkPlaylist(
                self.comboBox.currentText())[0]["playlist_id"]
            # Add to existing playlist
            addToPlaylist(self, playlistID)
            self.SIGNALS.CLOSE.emit()

    # Taken from https://stackoverflow.com/questions/44264852/pyside-pyqt-overlay-widget
    class TranslucentWidgetSignals(QtCore.QObject):
        CLOSE = QtCore.Signal()
Exemplo n.º 6
0
class AddSteamWidget(TritonWidget):

    def __init__(self, base, *args, **kwargs):
        TritonWidget.__init__(self, base, *args, **kwargs)
        self.sharedSecret = None
        self.identitySecret = None
        self.steamId = None
        self.type = Globals.SteamAuth

        self.setWindowTitle('Add Steam')
        self.setBackgroundColor(self, Qt.white)

        self.boxLayout = QVBoxLayout(self)
        self.boxLayout.setContentsMargins(20, 20, 20, 20)

        self.nameWidget = TextboxWidget(base, 'Name:')
        self.steamIdWidget = TextboxWidget(base, 'Steam ID:')
        self.sharedWidget = TextboxWidget(base, 'Shared Secret:')
        self.identityWidget = TextboxWidget(base, 'Identity Secret:')

        self.verifyLabel = QLabel()
        self.verifyLabel.setText('Click the Verify button to check the first code.')
        self.verifyLabel.setFont(QFont('Helvetica', 10))

        self.verifyBox = QLineEdit()
        self.verifyBox.setFixedWidth(150)
        self.verifyBox.setFont(QFont('Helvetica', 10))
        self.verifyBox.setEnabled(False)

        palette = QPalette()
        palette.setColor(QPalette.Text, Qt.black)
        self.verifyBox.setPalette(palette)
        self.verifyBox.setAlignment(Qt.AlignCenter)

        self.verifyButton = QPushButton('Verify')
        self.verifyButton.clicked.connect(self.checkVerify)
        self.verifyButton.setFixedWidth(150)

        self.addButton = QPushButton('OK')
        self.addButton.clicked.connect(self.add)

        self.boxLayout.addWidget(self.nameWidget)
        self.boxLayout.addWidget(self.steamIdWidget)
        self.boxLayout.addWidget(self.sharedWidget)
        self.boxLayout.addWidget(self.identityWidget)
        self.boxLayout.addSpacing(10)
        self.boxLayout.addWidget(self.verifyLabel)
        self.boxLayout.addWidget(self.verifyBox, 0, Qt.AlignCenter)
        self.boxLayout.addWidget(self.verifyButton, 0, Qt.AlignCenter)
        self.boxLayout.addSpacing(10)
        self.boxLayout.addWidget(self.addButton, 0, Qt.AlignRight)

        self.setFixedSize(self.sizeHint())
        self.center()
        self.show()

    def getName(self):
        return self.nameWidget.box.text()

    def getAccount(self):
        return {'name': self.getName(), 'type': self.type, 'sharedSecret': self.sharedSecret, 'identitySecret': self.identitySecret, 'steamId': self.steamId, 'icon': 'icons/SteamIcon.png'}

    def invalidateSecret(self, text=''):
        self.sharedSecret = None
        self.identitySecret = None
        self.steamId = None
        self.verifyBox.setText(text)

    def checkVerify(self):
        self.sharedSecret = self.sharedWidget.box.text()
        self.identitySecret = self.identityWidget.box.text()
        self.steamId = self.steamIdWidget.box.text()

        if not self.sharedSecret or not self.identitySecret or not self.steamId:
            self.invalidateSecret('Invalid')
            return

        try:
            self.verifyBox.setText(self.base.getAuthCode(self.getAccount()))
        except:
            self.invalidateSecret('Invalid')

    def add(self):
        if not self.sharedSecret or not self.getName():
            return

        self.base.addAccount(self.getAccount())
        self.close()
Exemplo n.º 7
0
class AddOTPWidget(TritonWidget):
    def __init__(self, base, *args, **kwargs):
        TritonWidget.__init__(self, base, *args, **kwargs)
        self.key = None
        self.type = Globals.OTPAuth

        self.setWindowTitle('Add Authenticator')
        self.setBackgroundColor(self, Qt.white)

        self.boxLayout = QVBoxLayout(self)
        self.boxLayout.setContentsMargins(20, 20, 20, 20)

        self.nameWidget = TextboxWidget(base, 'Name:')

        self.secretLabel = QLabel()
        self.secretLabel.setText(
            'Enter the Secret Code. If you have a QR code,\nyou can paste the URL of the image instead.'
        )
        self.secretLabel.setFont(QFont('Helvetica', 10))

        self.secretBox = QLineEdit()
        self.secretBox.setFixedWidth(300)
        self.secretBox.setFont(QFont('Helvetica', 10))
        self.secretBox.textChanged.connect(
            lambda text: self.invalidateSecret())

        self.verifyLabel = QLabel()
        self.verifyLabel.setText(
            'Click the Verify button to check the first code.')
        self.verifyLabel.setFont(QFont('Helvetica', 10))

        self.verifyBox = QLineEdit()
        self.verifyBox.setFixedWidth(150)
        self.verifyBox.setFont(QFont('Helvetica', 10))
        self.verifyBox.setEnabled(False)

        palette = QPalette()
        palette.setColor(QPalette.Text, Qt.black)
        self.verifyBox.setPalette(palette)
        self.verifyBox.setAlignment(Qt.AlignCenter)

        self.verifyButton = QPushButton('Verify')
        self.verifyButton.clicked.connect(self.checkVerify)
        self.verifyButton.setFixedWidth(150)

        self.addButton = QPushButton('OK')
        self.addButton.clicked.connect(self.add)

        self.boxLayout.addWidget(self.nameWidget)
        self.boxLayout.addSpacing(10)
        self.boxLayout.addWidget(self.secretLabel)
        self.boxLayout.addWidget(self.secretBox)
        self.boxLayout.addSpacing(10)
        self.boxLayout.addWidget(self.verifyLabel)
        self.boxLayout.addWidget(self.verifyBox, 0, Qt.AlignCenter)
        self.boxLayout.addWidget(self.verifyButton, 0, Qt.AlignCenter)
        self.boxLayout.addSpacing(10)
        self.boxLayout.addWidget(self.addButton, 0, Qt.AlignRight)

        self.setFixedSize(self.sizeHint())
        self.center()
        self.show()

    def getName(self):
        return self.nameWidget.box.text()

    def getAccount(self):
        return {
            'name': self.getName(),
            'type': self.type,
            'key': self.key,
            'icon': 'icons/WinAuthIcon.png'
        }

    def invalidateSecret(self, value=''):
        self.key = None
        self.verifyBox.setText(value)

    def checkVerify(self):
        self.key = self.secretBox.text()

        if not self.key:
            self.invalidateSecret('Invalid')
            return

        self.key = self.base.readQRLink(self.key) or self.key
        self.key = self.key.upper().replace(' ', '')

        try:
            self.verifyBox.setText(self.base.getAuthCode(self.getAccount()))
        except:
            self.invalidateSecret('Invalid')

    def add(self):
        if not self.key or not self.getName():
            return

        self.base.addAccount(self.getAccount())
        self.close()