예제 #1
0
    def initGlobalStyle(cls, *args):
        """
        Initialize style that will be used across the application

        .. note::

            A limited set of pre-defined styles are available

            If desired it is possible to create a completely custom style, see
            the links below...

            Best left for major application creation in C++,
            not recommended for Python

            https://doc.qt.io/qt-5/qstyle.html#creating-a-custom-style
            https://doc.qt.io/qt-5/qstyleplugin.html
            https://doc.qt.io/qt-5/qstylefactory.html

        """
        print("\n\nAvailable styles: " +
              ", ".join(sorted(QStyleFactory.keys())))
        style = "Fusion"
        for arg in args:
            if arg.lower() in [k.lower() for k in QStyleFactory.keys()]:
                style = arg
        style = QStyleFactory.create(style)
        QApplication.instance().setStyle(style)
예제 #2
0
 def setAppStyle(app):
     if "Fusion" in [st for st in QStyleFactory.keys()]:
         app.setStyle(QStyleFactory.create("Fusion"))
     elif sys.platform == "win32":
         app.setStyle(QStyleFactory.create("WindowsVista"))
     elif sys.platform == "linux":
         app.setStyle(QStyleFactory.create("gtk"))
     elif sys.platform == "darwin":
         app.setStyle(QStyleFactory.create("macintosh"))
예제 #3
0
    def __init__(self, parent=None):
        super(WidgetGallery, self).__init__(parent)

        self.originalPalette = QApplication.palette()

        styleComboBox = QComboBox()
        styleComboBox.addItems(QStyleFactory.keys())

        styleLabel = QLabel("&Style:")
        styleLabel.setBuddy(styleComboBox)

        self.useStylePaletteCheckBox = QCheckBox(
            "&Use style's standard palette")
        self.useStylePaletteCheckBox.setChecked(True)

        disableWidgetsCheckBox = QCheckBox("&Disable widgets")

        self.createTopLeftGroupBox()
        self.createTopRightGroupBox()
        self.createBottomLeftTabWidget()
        self.createBottomRightGroupBox()
        self.createProgressBar()

        styleComboBox.activated[str].connect(self.changeStyle)
        self.useStylePaletteCheckBox.toggled.connect(self.changePalette)
        disableWidgetsCheckBox.toggled.connect(
            self.topLeftGroupBox.setDisabled)
        disableWidgetsCheckBox.toggled.connect(
            self.topRightGroupBox.setDisabled)
        disableWidgetsCheckBox.toggled.connect(
            self.bottomLeftTabWidget.setDisabled)
        disableWidgetsCheckBox.toggled.connect(
            self.bottomRightGroupBox.setDisabled)

        topLayout = QHBoxLayout()
        topLayout.addWidget(styleLabel)
        topLayout.addWidget(styleComboBox)
        topLayout.addStretch(1)
        topLayout.addWidget(self.useStylePaletteCheckBox)
        topLayout.addWidget(disableWidgetsCheckBox)

        mainLayout = QGridLayout()
        mainLayout.addLayout(topLayout, 0, 0, 1, 2)
        mainLayout.addWidget(self.topLeftGroupBox, 1, 0)
        mainLayout.addWidget(self.topRightGroupBox, 1, 1)
        mainLayout.addWidget(self.bottomLeftTabWidget, 2, 0)
        mainLayout.addWidget(self.bottomRightGroupBox, 2, 1)
        mainLayout.addWidget(self.progressBar, 3, 0, 1, 2)
        mainLayout.setRowStretch(1, 1)
        mainLayout.setRowStretch(2, 1)
        mainLayout.setColumnStretch(0, 1)
        mainLayout.setColumnStretch(1, 1)
        self.setLayout(mainLayout)

        self.setWindowTitle("Common Qt Widgets")
        self.changeStyle('Fusion')
예제 #4
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # print available styles
        print(QStyleFactory.keys())


        # Signals
        self.ui.my_button.clicked.connect(self.test)
예제 #5
0
 def _populate_themes_menu(self):
     self.theme_menu = self.menuOptions.addMenu("Theme")
     current_theme = locator.get_static("SettingsService").get_theme()
     for theme in QStyleFactory.keys():
         action = self.theme_menu.addAction(theme)
         action.setCheckable(True)
         if theme == current_theme:
             action.setChecked(True)
         action.setActionGroup(self.theme_action_group)
         action.changed.connect(
             lambda a=action, t=theme: self._on_theme_changed(a, t))
예제 #6
0
    def testSetStyle(self):
        '''All this test have to do is not break with some invalid Python wrapper.'''
        def setStyleHelper(widget, style):
            widget.setStyle(style)
            widget.setPalette(style.standardPalette())
            for child in widget.children():
                if isinstance(child, QWidget):
                    setStyleHelper(child, style)

        container = QWidget()
        # QFontComboBox is used because it has an QLineEdit created in C++ inside it,
        # and if the QWidget.setStyle(style) steals the ownership of the style
        # for the C++ originated widget everything will break.
        fontComboBox = QFontComboBox(container)
        label = QLabel(container)
        label.setText('Label')
        style = QStyleFactory.create(QStyleFactory.keys()[0])
        setStyleHelper(container, style)
예제 #7
0
    def testSetStyle(self):
        '''All this test have to do is not break with some invalid Python wrapper.'''

        def setStyleHelper(widget, style):
            widget.setStyle(style)
            widget.setPalette(style.standardPalette())
            for child in widget.children():
                if isinstance(child, QWidget):
                    setStyleHelper(child, style)

        container = QWidget()
        # QFontComboBox is used because it has an QLineEdit created in C++ inside it,
        # and if the QWidget.setStyle(style) steals the ownership of the style
        # for the C++ originated widget everything will break.
        fontComboBox = QFontComboBox(container)
        label = QLabel(container)
        label.setText('Label')
        style = QStyleFactory.create(QStyleFactory.keys()[0])
        setStyleHelper(container, style)
예제 #8
0
    def __init__(self):
        super().__init__('settings')
        self.app = QApplication.instance()

        idx = self.fontComboBox.findText(
            settings.value('appearance/font', 'MS Shell Dlg 2'))
        self.fontComboBox.setCurrentIndex(idx)

        self.styleComboBox.addItems(QStyleFactory.keys())
        idx = self.styleComboBox.findText(
            settings.value('appearance/style',
                           self.app.style().objectName()))
        self.styleComboBox.setCurrentIndex(idx)

        self.loopsSpinBox.setValue(int(settings.value('loopsNumber', 8)))

        self.buttonBox.accepted.connect(self.saveSettings)
        self.buttonBox.button(self.buttonBox.Reset).clicked.connect(
            self.resetSettings)
예제 #9
0
    def createUI(self):
        #
        #  Windows
        #

        self.progressWindow = None
        self.helpwindow = HelpWindow(self)
        self.presetWindow = PresetWindow(self)
        self.presetWindow.logmessage.connect(self.logmessage)
        self.apiWindow = ApiViewer(self)
        self.apiWindow.logmessage.connect(self.logmessage)
        self.dataWindow = DataViewer(self)
        self.timerWindow = TimerWindow(self)
        self.selectNodesWindow = SelectNodesWindow(self)

        self.timerWindow.timerstarted.connect(self.guiActions.timerStarted)
        self.timerWindow.timerstopped.connect(self.guiActions.timerStopped)
        self.timerWindow.timercountdown.connect(self.guiActions.timerCountdown)
        self.timerWindow.timerfired.connect(self.guiActions.timerFired)

        #
        #  Statusbar and toolbar
        #

        self.statusbar = self.statusBar()
        self.toolbar = Toolbar(parent=self, mainWindow=self)
        self.addToolBar(Qt.TopToolBarArea, self.toolbar)

        self.timerStatus = QLabel("Timer stopped ")
        self.statusbar.addPermanentWidget(self.timerStatus)

        self.databaseLabel = QPushButton("No database connection ")
        self.statusbar.addWidget(self.databaseLabel)

        self.selectionStatus = QLabel("0 node(s) selected ")
        self.statusbar.addPermanentWidget(self.selectionStatus)
        #self.statusBar.showMessage('No database connection')
        self.statusbar.setSizeGripEnabled(False)

        self.databaseLabel.setFlat(True)
        self.databaseLabel.clicked.connect(self.databaseLabelClicked)

        #
        #  Layout
        #

        #dummy widget to contain the layout manager
        self.mainWidget = QSplitter(self)
        self.mainWidget.setOrientation(Qt.Vertical)
        self.setCentralWidget(self.mainWidget)

        #top
        topWidget = QWidget(self)
        self.mainWidget.addWidget(topWidget)
        dataLayout = QHBoxLayout()
        topWidget.setLayout(dataLayout)
        dataSplitter = QSplitter(self)
        dataLayout.addWidget(dataSplitter)

        #top left
        dataWidget = QWidget()
        dataLayout = QVBoxLayout()
        dataLayout.setContentsMargins(0, 0, 0, 0)
        dataWidget.setLayout(dataLayout)
        dataSplitter.addWidget(dataWidget)
        dataSplitter.setStretchFactor(0, 1)

        #top right
        detailSplitter = QSplitter(self)
        detailSplitter.setOrientation(Qt.Vertical)

        #top right top
        detailWidget = QWidget(self)
        detailLayout = QVBoxLayout()
        detailLayout.setContentsMargins(11, 0, 0, 0)
        detailWidget.setLayout(detailLayout)
        detailSplitter.addWidget(detailWidget)

        dataSplitter.addWidget(detailSplitter)
        dataSplitter.setStretchFactor(1, 0)

        #bottom
        bottomSplitter = QSplitter(self)
        self.mainWidget.addWidget(bottomSplitter)
        self.mainWidget.setStretchFactor(0, 1)

        #requestLayout=QHBoxLayout()
        #bottomWidget.setLayout(requestLayout)

        #bottom left
        modulesWidget = QWidget(self)
        moduleslayout = QVBoxLayout()
        modulesWidget.setLayout(moduleslayout)
        bottomSplitter.addWidget(modulesWidget)

        #bottom middle
        fetchWidget = QWidget(self)
        fetchLayout = QVBoxLayout()
        fetchWidget.setLayout(fetchLayout)
        bottomSplitter.addWidget(fetchWidget)

        settingsGroup = QGroupBox("Settings")
        fetchLayout.addWidget(settingsGroup)

        fetchsettings = QFormLayout()
        fetchsettings.setRowWrapPolicy(QFormLayout.DontWrapRows)
        fetchsettings.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        fetchsettings.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
        fetchsettings.setLabelAlignment(Qt.AlignLeft)
        settingsGroup.setLayout(fetchsettings)
        #fetchLayout.addLayout(fetchsettings)

        fetchdata = QHBoxLayout()
        fetchdata.setContentsMargins(10, 0, 10, 0)
        fetchLayout.addLayout(fetchdata)

        #bottom right
        statusWidget = QWidget(self)
        statusLayout = QVBoxLayout()
        statusWidget.setLayout(statusLayout)
        bottomSplitter.addWidget(statusWidget)

        #
        # Settings widget
        #s

        self.settingsWidget = QWidget()
        self.settingsLayout = QFormLayout()
        self.settingsLayout.setContentsMargins(0, 0, 0, 0)
        self.settingsWidget.setLayout(self.settingsLayout)

        # Add headers
        self.headersCheckbox = QCheckBox("Create header nodes", self)
        self.headersCheckbox.setChecked(
            str(self.settings.value('saveheaders', 'false')) == 'true')
        self.headersCheckbox.setToolTip(
            wraptip(
                "Check if you want to create nodes containing headers of the response."
            ))
        self.settingsLayout.addRow(self.headersCheckbox)

        # Full offcut
        self.offcutCheckbox = QCheckBox("Keep all data in offcut", self)
        self.offcutCheckbox.setChecked(
            str(self.settings.value('fulloffcut', 'false')) == 'true')
        self.offcutCheckbox.setToolTip(
            wraptip(
                "Check if you don't want to filter out data from the offcut node. Useful for webscraping, keeps the full HTML content"
            ))
        self.settingsLayout.addRow(self.offcutCheckbox)

        # Timeout
        self.timeoutEdit = QSpinBox(self)
        self.timeoutEdit.setMinimum(1)
        self.timeoutEdit.setMaximum(300)
        self.timeoutEdit.setToolTip(
            wraptip("How many seconds will you wait for a response?"))
        self.timeoutEdit.setValue(self.settings.value('timeout', 15))
        self.settingsLayout.addRow('Request timeout', self.timeoutEdit)

        # Max data size
        self.maxsizeEdit = QSpinBox(self)
        self.maxsizeEdit.setMinimum(1)
        self.maxsizeEdit.setMaximum(300000)
        self.maxsizeEdit.setToolTip(
            wraptip("How many megabytes will you download at maximum?"))
        self.maxsizeEdit.setValue(self.settings.value('maxsize', 5))
        self.settingsLayout.addRow('Maximum size', self.maxsizeEdit)

        # Expand Box
        self.autoexpandCheckbox = QCheckBox("Expand new nodes", self)
        self.autoexpandCheckbox.setToolTip(
            wraptip(
                "Check to automatically expand new nodes when fetching data. Disable for big queries to speed up the process."
            ))
        self.settingsLayout.addRow(self.autoexpandCheckbox)
        self.autoexpandCheckbox.setChecked(
            str(self.settings.value('expand', 'true')) == 'true')

        # Log Settings
        self.logCheckbox = QCheckBox("Log all requests", self)
        self.logCheckbox.setToolTip(
            wraptip(
                "Check to see every request in the status log; uncheck to hide request messages."
            ))
        self.settingsLayout.addRow(self.logCheckbox)
        self.logCheckbox.setChecked(
            str(self.settings.value('logrequests', 'true')) == 'true')

        # Clear setttings
        self.clearCheckbox = QCheckBox("Clear settings when closing.", self)
        self.settings.beginGroup("GlobalSettings")
        self.clearCheckbox.setChecked(
            str(self.settings.value('clearsettings', 'false')) == 'true')
        self.settings.endGroup()

        self.clearCheckbox.setToolTip(
            wraptip(
                "Check to clear all settings and access tokens when closing Facepager. You should check this on public machines to clear credentials."
            ))
        self.settingsLayout.addRow(self.clearCheckbox)

        # Style
        self.styleEdit = QComboBox(self)
        self.styleEdit.setToolTip(wraptip("Choose the styling of Facepager."))

        styles = [x for x in QStyleFactory.keys() if x != "Windows"]
        styles = ['<default>'] + styles

        self.styleEdit.insertItems(0, styles)
        self.styleEdit.setCurrentText(self.settings.value(
            'style', '<default>'))

        self.styleEdit.currentIndexChanged.connect(self.setStyle)
        self.settingsLayout.addRow('Style', self.styleEdit)

        #
        #  Components
        #

        #main tree
        treetoolbar = QToolBar(self)
        treetoolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        treetoolbar.setIconSize(QSize(16, 16))

        treetoolbar.addActions(self.guiActions.treeActions.actions())
        dataLayout.addWidget(treetoolbar)

        self.tree = DataTree(self.mainWidget)
        self.tree.nodeSelected.connect(self.guiActions.treeNodeSelected)
        self.tree.logmessage.connect(self.logmessage)
        self.tree.showprogress.connect(self.showprogress)
        self.tree.hideprogress.connect(self.hideprogress)
        self.tree.stepprogress.connect(self.stepprogress)
        dataLayout.addWidget(self.tree)

        #right sidebar - toolbar
        detailtoolbar = QToolBar(self)
        detailtoolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        detailtoolbar.setIconSize(QSize(16, 16))
        detailtoolbar.addActions(self.guiActions.detailActions.actions())
        detailLayout.addWidget(detailtoolbar)

        #right sidebar - json viewer
        self.detailTree = DictionaryTree(self.mainWidget, self.apiWindow)
        detailLayout.addWidget(self.detailTree)

        #right sidebar - column setup
        detailGroup = QGroupBox("Custom Table Columns (one key per line)")
        detailSplitter.addWidget(detailGroup)
        groupLayout = QVBoxLayout()
        detailGroup.setLayout(groupLayout)

        self.fieldList = QTextEdit()
        self.fieldList.setLineWrapMode(QTextEdit.NoWrap)
        self.fieldList.setWordWrapMode(QTextOption.NoWrap)
        self.fieldList.acceptRichText = False
        self.fieldList.clear()
        self.fieldList.append('name')
        self.fieldList.append('message')
        self.fieldList.setPlainText(
            self.settings.value('columns', self.fieldList.toPlainText()))

        groupLayout.addWidget(self.fieldList)

        #column setup toolbar
        columntoolbar = QToolBar(self)
        columntoolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        columntoolbar.setIconSize(QSize(16, 16))
        columntoolbar.addActions(self.guiActions.columnActions.actions())
        groupLayout.addWidget(columntoolbar)

        #Requests/Apimodules
        self.RequestTabs = QTabWidget()
        moduleslayout.addWidget(self.RequestTabs)
        self.RequestTabs.addTab(YoutubeTab(self), "YouTube")
        self.RequestTabs.addTab(TwitterTab(self), "Twitter")
        self.RequestTabs.addTab(TwitterStreamingTab(self), "Twitter Streaming")
        self.RequestTabs.addTab(FacebookTab(self), "Facebook")
        self.RequestTabs.addTab(AmazonTab(self), "Amazon")
        self.RequestTabs.addTab(GenericTab(self), "Generic")

        module = self.settings.value('module', False)
        tab = self.getModule(module)
        if tab is not None:
            self.RequestTabs.setCurrentWidget(tab)

        #Fetch settings
        #-Level
        self.levelEdit = QSpinBox(self.mainWidget)
        self.levelEdit.setMinimum(1)
        self.levelEdit.setToolTip(
            wraptip(
                "Based on the selected nodes, only fetch data for nodes and subnodes of the specified level (base level is 1)"
            ))
        fetchsettings.addRow("Node level", self.levelEdit)

        #-Selected nodes
        self.allnodesCheckbox = QCheckBox(self)
        self.allnodesCheckbox.setCheckState(Qt.Unchecked)
        self.allnodesCheckbox.setToolTip(
            wraptip(
                "Check if you want to fetch data for all nodes. This helps with large datasets because manually selecting all nodes slows down Facepager."
            ))
        fetchsettings.addRow("Select all nodes", self.allnodesCheckbox)

        #-Empty nodes
        self.emptyCheckbox = QCheckBox(self)
        self.emptyCheckbox.setCheckState(Qt.Unchecked)
        self.emptyCheckbox.setToolTip(
            wraptip("Check if you want process only empty nodes."))
        fetchsettings.addRow("Only empty nodes", self.emptyCheckbox)

        #Object types
        self.typesEdit = QLineEdit('offcut')
        self.typesEdit.setToolTip(
            wraptip(
                "Skip nodes with these object types, comma separated list. Normally this should not be changed."
            ))
        fetchsettings.addRow("Exclude object types", self.typesEdit)

        #-Continue pagination
        self.resumeCheckbox = QCheckBox(self)
        self.resumeCheckbox.setCheckState(Qt.Unchecked)
        self.resumeCheckbox.setToolTip(
            wraptip(
                "Check if you want to continue collection after fetching was cancelled or nodes were skipped. The last fetched offcut or data node is used to determine the pagination value. Nodes are skipped if no pagination value can be found. Nodes without children having status fetched(200) are processed anyway."
            ))
        fetchsettings.addRow("Resume collection", self.resumeCheckbox)

        # Thread Box
        self.threadsEdit = QSpinBox(self)
        self.threadsEdit.setMinimum(1)
        self.threadsEdit.setMaximum(40)
        self.threadsEdit.setToolTip(
            wraptip(
                "The number of concurrent threads performing the requests. Higher values increase the speed, but may result in API-Errors/blocks"
            ))
        fetchsettings.addRow("Parallel Threads", self.threadsEdit)

        # Speed Box
        self.speedEdit = QSpinBox(self)
        self.speedEdit.setMinimum(1)
        self.speedEdit.setMaximum(60000)
        self.speedEdit.setValue(200)
        self.speedEdit.setToolTip(
            wraptip(
                "Limit the total amount of requests per minute (calm down to avoid API blocking)"
            ))
        fetchsettings.addRow("Requests per minute", self.speedEdit)

        #Error Box
        self.errorEdit = QSpinBox(self)
        self.errorEdit.setMinimum(1)
        self.errorEdit.setMaximum(100)
        self.errorEdit.setValue(10)
        self.errorEdit.setToolTip(
            wraptip(
                "Set the number of consecutive errors after which fetching will be cancelled. Please handle with care! Continuing with erroneous requests places stress on the servers."
            ))
        fetchsettings.addRow("Maximum errors", self.errorEdit)

        #More
        button = QPushButton(QIcon(":/icons/more.png"), "", self.mainWidget)
        button.setToolTip(
            wraptip(
                "Can't get enough? Here you will find even more settings!"))
        # button.setMinimumSize(QSize(120,40))
        # button.setIconSize(QSize(32,32))
        button.clicked.connect(self.guiActions.actionSettings.trigger)
        fetchsettings.addRow("More settings", button)

        #Fetch data

        #-button
        f = QFont()
        f.setPointSize(11)
        button = QPushButton(QIcon(":/icons/fetch.png"), "Fetch Data",
                             self.mainWidget)
        button.setToolTip(
            wraptip(
                "Fetch data from the API with the current settings. If you click the button with the control key pressed, a browser window is opened instead."
            ))
        button.setMinimumSize(QSize(120, 40))
        button.setIconSize(QSize(32, 32))
        button.clicked.connect(self.guiActions.actionQuery.trigger)
        button.setFont(f)
        fetchdata.addWidget(button, 1)

        #-timer button
        button = QToolButton(self.mainWidget)
        button.setIcon(QIcon(":/icons/timer.png"))
        button.setMinimumSize(QSize(40, 40))
        button.setIconSize(QSize(25, 25))
        button.clicked.connect(self.guiActions.actionTimer.trigger)
        fetchdata.addWidget(button, 1)

        #Status
        detailGroup = QGroupBox("Status Log")
        groupLayout = QVBoxLayout()
        detailGroup.setLayout(groupLayout)
        statusLayout.addWidget(detailGroup, 1)

        self.loglist = QTextEdit()
        self.loglist.setLineWrapMode(QTextEdit.NoWrap)
        self.loglist.setWordWrapMode(QTextOption.NoWrap)
        self.loglist.acceptRichText = False
        self.loglist.clear()
        groupLayout.addWidget(self.loglist)
예제 #10
0
def _load_theme_from_settings(app: QApplication):
    theme = locator.get_static("SettingsService").get_theme()
    if theme and theme in QStyleFactory.keys():
        app.setStyle(theme)
예제 #11
0
 def testSetStyleOwnership(self):
     style = QStyleFactory.create(QStyleFactory.keys()[0])
     self.assertEqual(sys.getrefcount(style), 2)
     QApplication.instance().setStyle(style)
     self.assertEqual(sys.getrefcount(style), 3)
예제 #12
0
        button = self.window.findChild(QObject, 'button')
        # Conectando o signal a um slot.
        button.clicked.connect(self.on_button_clicked)

    def on_button_clicked(self):
        if self.text_field.property('text'):
            self.label.setProperty('text', self.text_field.property('text'))
        else:
            self.label.setProperty('text', 'Digite algo no campo de texto :)')


if __name__ == "__main__":
    import sys

    styles = QStyleFactory.keys()
    print('Estilos disponíveis:', styles)

    # Aplicando estilo.
    # Testado no Windows e funcionou.
    # sys.argv += ['--style', 'Default']
    # sys.argv += ['--style', 'Fusion']
    # sys.argv += ['--style', 'Imagine']
    # sys.argv += ['--style', 'Material']
    # sys.argv += ['--style', 'Universal']
    # sys.argv += ['--style', 'Windows']
    # sys.argv += ['--style', 'org.kde.desktop']

    # ou
    # environ['QT_QUICK_CONTROLS_STYLE'] = 'Default'
    # environ['QT_QUICK_CONTROLS_STYLE'] = 'Fusion'
예제 #13
0
    def __init__(self, parent=None):
        super(CmdLib, self).__init__(parent)

        # open ui file directly
        ui_file = QFile('mainwindow.ui')
        ui_file.open(QFile.ReadOnly)
        loader = QUiLoader()
        self.window = loader.load(ui_file)
        ui_file.close()

        # app name and version
        self.appname = "CmdLib"
        self.version = "0.1"

        # set fixed window size
        #self.window.setFixedSize(self.window.size())

        # set title and center window
        self.window.setWindowTitle(self.appname)
        self.center_window()

        # print available styles
        print(QStyleFactory.keys())

        ##### SIGNALS

        # run command
        self.window.button_run_term.clicked.connect(self.run_cmd_term)

        # load cmd
        #self.window.cmd_list.clicked.connect(self.load_cmd)
        self.window.cmd_list.itemSelectionChanged.connect(self.load_cmd)
        #self.window.cmd_list.currentRowChanged.connect(self.load_cmd)

        # add cmd to list
        self.window.button_to_list.clicked.connect(self.save_cmd)

        # delete cmd
        self.window.button_delete_cmd.clicked.connect(self.delete_cmd)

        # multi cmd mode
        self.window.multicmd_mode.clicked.connect(self.multicmd_mode)

        # is script mode
        self.window.check_script.clicked.connect(self.is_script)

        # search
        self.window.search_box.currentTextChanged.connect(self.search_cmds)

        # workdir
        self.window.set_workdir.clicked.connect(self.set_workdir)
        self.window.open_workdir.clicked.connect(self.open_workdir)
        self.window.workdir_line.editingFinished.connect(self.check_workdir)

        # show help from helpbox
        self.window.show_helpbox.clicked.connect(self.show_help)

        # new cmd
        self.window.new_button.clicked.connect(self.new_cmd)
        # copy cmd
        self.window.copy_button.clicked.connect(self.copy2clipboard)
        # add file name
        self.window.addfile_button.clicked.connect(self.on_insert_file_name)
        # open file
        self.window.openfile_button.clicked.connect(self.on_open_file_button)

        # if cmd selection is changed
        self.window.cmd_field.selectionChanged.connect(
            self.set_open_file_button)

        # check name
        self.window.name_field.textChanged.connect(self.check_name)
        # check command
        self.window.cmd_field.textChanged.connect(self.check_command)

        # DROP signal!!
        self.window.cmd_list.model().rowsMoved.connect(self.reorder_cmds)

        # menu/actions
        self.window.actionBackupLib.triggered.connect(self.backup)
        self.window.actionExportLib.triggered.connect(self.exportlib)
        self.window.actionImportLib.triggered.connect(self.importlib)

        self.window.actionInsert_File_Name.triggered.connect(
            self.on_insert_file_name)
        self.window.actionInsert_File_Path.triggered.connect(
            self.on_insert_file_path)
        self.window.actionExport2Script.triggered.connect(self.export2script)

        self.window.actionGet_File_Name.triggered.connect(
            self.on_copy_file_name)
        self.window.actionGet_File_Path.triggered.connect(
            self.on_copy_file_path)
        self.window.actionOpen_Scripts_Folder.triggered.connect(
            self.open_scriptsdir)
        self.window.actionOpen_File.triggered.connect(self.open_file)
        self.window.actionOpen_Script.triggered.connect(self.open_script)

        self.window.actionAbout.triggered.connect(self.on_about)

        # extra shortcuts
        # delete cmd from cmdlist
        QShortcut(QKeySequence(Qt.Key_Delete), self.window.cmd_list,
                  self.delete_cmd)

        # save cmd
        QShortcut(QKeySequence("Ctrl+S"), self.window, self.on_save_cmd)

        # new cmd
        QShortcut(QKeySequence("Ctrl+N"), self.window, self.new_cmd)

        # new cmd
        QShortcut(QKeySequence("Ctrl+H"), self.window, self.show_help)

        # run in term
        QShortcut(QKeySequence("Ctrl+Return"), self.window, self.run_cmd_term)

        # focus on search
        QShortcut(QKeySequence("Ctrl+F"), self.window, self.focus_search)

        # focus on lib
        QShortcut(QKeySequence("Ctrl+L"), self.window, self.focus_lib)
        QShortcut(QKeySequence(Qt.Key_Tab), self.window, self.focus_lib)

        # trigger when quitting
        app.aboutToQuit.connect(self.on_quit)

        # update cmd list
        self.update_cmd_list()

        # select first cmd
        self.window.cmd_list.setCurrentRow(0)

        # load init command
        self.load_cmd()

        # set search box to All
        self.window.search_box.setCurrentIndex(0)

        #set focus on search box
        self.focus_search()

        # if provided, set first argument to workdir
        self.set_workdir_with_arg()

        # make start backup
        self.df.to_csv("./backups/cmds.csv", index=False)

        # show main window
        self.window.show()
예제 #14
0
 def resetSettings(self):
     self.fontComboBox.setCurrentText('MS Shell Dlg 2')
     self.styleComboBox.setCurrentText(QStyleFactory.keys()[0])
     self.loopsSpinBox.setValue(8)
예제 #15
0
파일: prefs.py 프로젝트: mattdoiron/idfplus
    def __init__(self, parent):
        """Initialize the appearance tab
        """

        super(AppearanceTab, self).__init__(parent)

        self.prefs = parent.prefs

        # Default column width code
        col_width_label = QLabel("Default Column Width:")
        self.col_width_edit = QLineEdit(str(self.prefs['default_column_width']))
        self.col_width_edit.setMinimumWidth(40)
        self.col_width_edit.setMaximumWidth(100)
        validator = QIntValidator(10, 200, self)
        self.col_width_edit.setValidator(validator)

        # Visual style code
        style_label = QLabel("Visual Style of Application:")
        self.style_edit = QComboBox(self)
        self.style_edit.addItems(list(QStyleFactory.keys()))
        self.style_edit.setMaximumWidth(200)
        self.style_edit.setCurrentIndex(self.style_edit.findText(self.prefs['style']))

        # Units display code
        units_header_label = QLabel("Units Display:")
        self.header_units_check = QCheckBox('Show Units in Table Headers', self)
        checked_header = Qt.Checked if self.prefs['show_units_in_headers'] == 1 else Qt.Unchecked
        self.header_units_check.setCheckState(checked_header)
        self.cells_units_check = QCheckBox('Show Units in Table Cells', self)
        checked_cells = Qt.Checked if self.prefs['show_units_in_cells'] == 1 else Qt.Unchecked
        self.cells_units_check.setCheckState(checked_cells)

        # Handling of file options code
        default_handling_text = QLabel("Select how options saved directly within an IDF "
                                             "file are treated. See \"Save Options\" tab "
                                             "for the options in question.")
        default_handling_text.setWordWrap(True)
        default_handling_text.setMaximumWidth(450)
        self.button_force = QRadioButton("Force Session Options:", self)
        force_text = QLabel("Options from the current session will be used for all "
                                  "files, ignoring any options saved in the IDF file.")
        force_text.setWordWrap(True)
        force_text.setMaximumWidth(450)
        force_text.setMinimumHeight(30)
        force_text.setIndent(25)
        self.button_obey = QRadioButton("Obey IDF Options if Present:", self)
        obey_text = QLabel("Obey options saved in the IDF file. If none are "
                                 "present, use the current session's options.")
        obey_text.setWordWrap(True)
        obey_text.setMaximumWidth(450)
        obey_text.setMinimumHeight(30)
        obey_text.setIndent(25)

        # Handling of file options group box
        self.behaviour_group_box = QGroupBox("Handling of File-based Options")
        self.behaviour_group_box.setMinimumHeight(220)
        self.behaviour_group_box.setMinimumWidth(450)
        behaviour_box = QVBoxLayout()
        behaviour_box.addWidget(default_handling_text)
        behaviour_box.addWidget(self.button_force)
        behaviour_box.addWidget(force_text)
        behaviour_box.addSpacing(5)
        behaviour_box.addWidget(self.button_obey)
        behaviour_box.addWidget(obey_text)
        behaviour_box.addStretch(1)
        self.behaviour_group_box.setLayout(behaviour_box)

        self.behaviour_button_group = QButtonGroup(self)
        self.behaviour_button_group.addButton(self.button_force)
        self.behaviour_button_group.addButton(self.button_obey)
        self.behaviour_button_group.setId(self.button_force, 0)
        self.behaviour_button_group.setId(self.button_obey, 1)
        self.behaviour_button_group.button(self.prefs['obey_idf_options']).setChecked(True)

        # Main layout code
        mainLayout = QVBoxLayout()
        mainLayout.addWidget(col_width_label)
        mainLayout.addWidget(self.col_width_edit)
        mainLayout.addSpacing(10)
        mainLayout.addWidget(style_label)
        mainLayout.addWidget(self.style_edit)
        mainLayout.addSpacing(10)
        mainLayout.addWidget(self.behaviour_group_box)
        mainLayout.addSpacing(10)
        mainLayout.addWidget(units_header_label)
        mainLayout.addWidget(self.header_units_check)
        mainLayout.addWidget(self.cells_units_check)
        mainLayout.addStretch(1)
        self.setLayout(mainLayout)

        # Update settings
        self.behaviour_button_group.buttonClicked.connect(self.update)
        self.col_width_edit.textChanged.connect(self.update)
        self.style_edit.currentIndexChanged.connect(self.update)
        self.header_units_check.stateChanged.connect(self.update)
        self.cells_units_check.stateChanged.connect(self.update)