예제 #1
0
파일: about.py 프로젝트: timhowes/git-cola
def show_shortcuts():
    try:
        from qtpy import QtWebEngineWidgets
    except ImportError:
        # redhat disabled QtWebKit in their qt build but don't punish the
        # users
        qtutils.critical(
            N_('This PyQt4 does not include QtWebKit.\n'
               'The keyboard shortcuts feature is unavailable.'))
        return

    hotkeys_html = resources.doc(N_('hotkeys.html'))
    html = core.read(hotkeys_html)

    parent = qtutils.active_window()
    widget = QtWidgets.QDialog()
    widget.setWindowModality(Qt.WindowModal)
    widget.setWindowTitle(N_('Shortcuts'))

    web = QtWebEngineWidgets.QWebEngineView(parent)
    web.setHtml(html)

    layout = qtutils.hbox(defs.no_margin, defs.spacing, web)
    widget.setLayout(layout)
    widget.resize(800, min(parent.height(), 600))
    qtutils.add_action(widget, N_('Close'), widget.accept, hotkeys.QUESTION,
                       *hotkeys.ACCEPT)
    widget.show()
    widget.exec_()
예제 #2
0
def test_run_3():
    with qt_multiprocessing.AppEventLoop() as loop:
        app = QtWidgets.QApplication([])

        QtManager.register('Label', QtWidgets.QLabel)
        mngr = QtManager()
        mngr.start()

        # Create the proxy label
        lbl = mngr.Label("Hello")
        lbl.show()

        widg = QtWidgets.QDialog()
        lay = QtWidgets.QFormLayout()
        widg.setLayout(lay)

        # Form
        inp = QtWidgets.QLineEdit()
        btn = QtWidgets.QPushButton('Set Text')
        lay.addRow(inp, btn)

        def set_text():
            value = inp.text()
            lbl.setText(value)
            # loop.add_var_event('label', 'setText', value)

        btn.clicked.connect(set_text)

        widg.show()

        app.exec_()
예제 #3
0
def show_shortcuts():
    hotkeys_html = resources.doc(N_('hotkeys.html'))
    try:
        from qtpy import QtWebEngineWidgets
    except ImportError:
        # redhat disabled QtWebKit in their qt build but don't punish the users
        webbrowser.open_new_tab('file://' + hotkeys_html)
        return

    html = core.read(hotkeys_html)

    parent = qtutils.active_window()
    widget = QtWidgets.QDialog()
    widget.setWindowModality(Qt.WindowModal)
    widget.setWindowTitle(N_('Shortcuts'))

    web = QtWebEngineWidgets.QWebEngineView(parent)
    web.setHtml(html)

    layout = qtutils.hbox(defs.no_margin, defs.spacing, web)
    widget.setLayout(layout)
    widget.resize(800, min(parent.height(), 600))
    qtutils.add_action(widget, N_('Close'), widget.accept, hotkeys.QUESTION,
                       *hotkeys.ACCEPT)
    widget.show()
    widget.exec_()
예제 #4
0
    def show_remote(self):
        """

        """
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        tree = ParameterTree()
        # tree.setMinimumWidth(400)
        tree.setMinimumHeight(500)
        tree.setParameters(self.remote_params, showTop=False)

        vlayout.addWidget(tree)
        dialog.setLayout(vlayout)
        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)

        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle('Fill in information about the actions and their shortcuts')
        res = dialog.exec()

        if res == dialog.Accepted:
            # save preset parameters in a xml file
            ioxml.parameter_to_xml_file(
                self.remote_params, os.path.join(remote_path, self.remote_params.child('filename').value()))
예제 #5
0
    def pick_dialog(self):
        self.dialog = QtWidgets.QDialog()
        self.dialog.setMinimumWidth(500)
        vlayout = QtWidgets.QVBoxLayout()

        self.list_widget = QtWidgets.QListWidget()
        self.list_widget.addItems(self.list)

        vlayout.addWidget(self.list_widget, 10)
        self.dialog.setLayout(vlayout)

        buttonBox = QtWidgets.QDialogButtonBox()
        buttonBox.addButton('Apply', buttonBox.AcceptRole)
        buttonBox.accepted.connect(self.dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(self.dialog.reject)

        vlayout.addWidget(buttonBox)
        self.dialog.setWindowTitle('Select an entry in the list')

        res = self.dialog.show()

        pass
        if res == self.dialog.Accepted:
            # save managers parameters in a xml file
            return [
                self.list_widget.currentIndex(),
                self.list_widget.currentItem().text()
            ]
        else:
            return [-1, ""]
예제 #6
0
    def __init__(self, app, winePrefix, homeDir, osType, rootDir, parent):
        self.app = app
        self.winePrefix = winePrefix
        self.homeDir = homeDir
        self.osType = osType

        self.winCheckConfig = QtWidgets.QDialog(parent,
                                                QtCore.Qt.FramelessWindowHint)

        uifile = resource_filename(__name__,
                                   'ui' + os.sep + 'winCheckConfig.ui')

        Ui_dlgCheckConfig, base_class = uic.loadUiType(uifile)
        self.uiSettings = Ui_dlgCheckConfig()
        self.uiSettings.setupUi(self.winCheckConfig)

        if self.app == "Wine":
            self.winCheckConfig.setWindowTitle("Prefix Checker")
        else:
            self.winCheckConfig.setWindowTitle("Bottle Checker")

        self.uiSettings.lblWinVersion.setText(self.findWinVer())
        self.uiSettings.lblMemory.setText(self.findGraphicsMemory())

        if self.findVC2005():
            self.uiSettings.lblVCRun.setText("Installed")
        else:
            self.uiSettings.lblVCRun.setText("Not found")
예제 #7
0
    def run_std_analysis(self):
        if self.exportRan:
            # Loading dialog.
            dlg = QtWidgets.QDialog(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
            dlg.setWindowTitle("Working...")
            dlg.setWindowIcon(QtGui.QIcon('icon.png'))
            dlg.resize(200, 150)
            dlg.show()

            # start_time = time.perf_counter()
            standard_deviation(self.STD_DEV_ACROSS_N_FRAMES)
            # end_time = time.perf_counter()
            # print("Analysis performance (QMessageBox vs. QDialog): ", end_time - start_time)

            self.stdRan = True
            dlg.close()
            box = QtWidgets.QMessageBox()
            box.setWindowTitle("Success")
            box.setWindowIcon(QtGui.QIcon('icon.png'))
            box.setIcon(QtWidgets.QMessageBox.Information)
            box.setText("Standard deviation analysis complete!")
            msg = box.exec_()
        else:
            box = QtWidgets.QMessageBox()
            box.setWindowTitle("Error")
            box.setWindowIcon(QtGui.QIcon('icon.png'))
            box.setIcon(QtWidgets.QMessageBox.Critical)
            box.setText("Analysis could not be run! Ensure you have exported the parent folder to BMP images.")
            msg = box.exec_()
예제 #8
0
def text_dialog(context, text, title):
    """Show a wall of text in a dialog"""
    parent = qtutils.active_window()

    label = QtWidgets.QLabel(parent)
    label.setFont(qtutils.diff_font(context))
    label.setText(text)
    label.setMargin(defs.large_margin)
    text_flags = Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse
    label.setTextInteractionFlags(text_flags)

    widget = QtWidgets.QDialog(parent)
    widget.setWindowModality(Qt.WindowModal)
    widget.setWindowTitle(title)

    scroll = QtWidgets.QScrollArea()
    scroll.setWidget(label)

    layout = qtutils.hbox(defs.margin, defs.spacing, scroll)
    widget.setLayout(layout)

    qtutils.add_action(
        widget, N_('Close'), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return
    )
    widget.show()
    return widget
예제 #9
0
    def onAction(self):
        ui = Ui_SaveImage()
        dlg = QtWidgets.QDialog()
        ui.setupUi(dlg)
        ui.dpi_spin.setEnabled(False)

        view = self.content_ctrl.getViewerController().view
        figure = view.figure
        canvas = view.canvas

        filters, selectedFilter = self.getFilter(canvas)

        def selectFile():
            path = \
                QFileDialog.getSaveFileName(directory=ui.file_path.text(), filter=filters,
                                            initialFilter=selectedFilter)[0]
            if path:
                ui.file_path.setText(path)

        ui.file_select.clicked.connect(selectFile)

        startpath = os.path.expanduser(
            matplotlib.rcParams['savefig.directory'])
        start = os.path.join(startpath, canvas.get_default_filename())
        ui.file_path.setText(start)

        if not dlg.exec_():
            return

        path = ui.file_path.text()
        dpi = ui.dpi_spin.value() if ui.dpi_check.isChecked() else None

        figure.savefig(path,
                       dpi=dpi,
                       transparent=ui.transparent_check.isChecked())
예제 #10
0
def run_in_builtin_terminal(cmd, env,
                            text=None, success_msg=None, fail_msg=None):
    result = [False]

    def store_result(code):
        result[:] = [code]

    dialog = QtWidgets.QDialog()
    layout = QtWidgets.QVBoxLayout()
    if text is not None:
        layout.addWidget(QtWidgets.QLabel(text))
    terminal = Terminal(cmd, env, input_enabled=False,
                        success_msg=success_msg, fail_msg=fail_msg)
    terminal.finished.connect(store_result)
    layout.addWidget(terminal)
    buttons = QtWidgets.QHBoxLayout()
    buttons.addStretch(1)
    accept = QtWidgets.QPushButton("Close", enabled=False)
    accept.clicked.connect(dialog.accept)
    terminal.finished.connect(lambda _: accept.setEnabled(True))
    buttons.addWidget(accept)
    layout.addLayout(buttons)
    dialog.setLayout(layout)
    dialog.exec_()

    return result[0]
예제 #11
0
 def dialog_about(self):
     infobox = QtWidgets.QDialog()
     infobox.setObjectName("infobox")
     infobox.resize(721, 379)
     icon = QtGui.QIcon()
     icon.addPixmap(QtGui.QPixmap("ui_files/icons/poccad.png"),
                    QtGui.QIcon.Normal, QtGui.QIcon.Off)
     infobox.setWindowIcon(icon)
     self.logo = QtWidgets.QLabel(infobox)
     self.logo.setGeometry(QtCore.QRect(10, 10, 701, 311))
     self.logo.setText("")
     self.logo.setPixmap(QtGui.QPixmap("readme_files/poccad_github.png"))
     self.logo.setScaledContents(True)
     self.logo.setObjectName("logo")
     self.infotext = QtWidgets.QLabel(infobox)
     self.infotext.setGeometry(QtCore.QRect(190, 340, 291, 16))
     self.infotext.setAutoFillBackground(True)
     self.infotext.setScaledContents(False)
     self.infotext.setOpenExternalLinks(True)
     self.infotext.setTextInteractionFlags(
         QtCore.Qt.LinksAccessibleByMouse | QtCore.Qt.TextSelectableByMouse)
     self.infotext.setObjectName("infotext")
     QtCore.QMetaObject.connectSlotsByName(infobox)
     _translate = QtCore.QCoreApplication.translate
     infobox.setWindowTitle(_translate("infobox", "poccad_info"))
     self.infotext.setText(
         _translate("infobox",
                    "please visit https://github.com/Tanneguydv/poccad"))
     infobox.exec_()
예제 #12
0
    def show_okcancel_dialog(self, title, widget, modal=True):
        """
        Show a dialog with the passed widget and OK and cancel buttons.
        """
        diag = QtWidgets.QDialog(self)
        diag.setWindowTitle(title)
        diag.setWindowFlags(Qt.Tool)

        btns = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                                Qt.Horizontal, diag)
        btns.accepted.connect(diag.accept)
        btns.rejected.connect(diag.reject)

        box = QtWidgets.QVBoxLayout(diag)
        box.addWidget(widget)
        box.addWidget(btns)
        diag.setLayout(box)

        if modal:
            diag.exec_()
        else:
            diag.show()
        # Return the dialog for result checking, and to keep widget in scope
        # for caller
        return diag
예제 #13
0
def run_app():
    with qt_multiprocessing.MpApplication() as app:
        print("Main PID:", os.getpid())

        # Proxy
        lbl = MyPIDLabelProxy("Hello")

        widg = QtWidgets.QDialog()
        lay = QtWidgets.QFormLayout()
        widg.setLayout(lay)

        # Form
        inp = QtWidgets.QLineEdit()
        btn = QtWidgets.QPushButton('Set Text')
        lay.addRow(inp, btn)

        def set_text():
            text = inp.text()
            lbl.setText(inp.text())

            # Try to somewhat prove that the label is in a different process.
            # `print_pid` Not exposed (will call in other process. Result will be None)
            print('Set Label text', text + '. Label text in this process', lbl.print_pid())

            # `print_pid` will run in a separate process and print the pid.

        btn.clicked.connect(set_text)

        widg.show()
예제 #14
0
 def oneAction(self):
     self.inputView = QtWidgets.QDialog()
     self.oneUi = Ui_widget()
     self.oneUi.setupUi(self.inputView)
     self.inputView.show()
     self.oneUi.mySignal.connect(self.shoudongshuruSignal)
     self.inputView.exec()
예제 #15
0
def run_without_proxy():
    with qt_multiprocessing.MpApplication(initialize_process=create_process_widgets) as app:
        print("Main PID:", os.getpid())

        widg = QtWidgets.QDialog()
        lay = QtWidgets.QFormLayout()
        widg.setLayout(lay)

        # Form
        inp = QtWidgets.QLineEdit()
        btn = QtWidgets.QPushButton('Set Text')
        lay.addRow(inp, btn)

        def set_text():
            text = inp.text()
            app.add_var_event('label', 'setText', text)

            # The label does not exist in this process at all. Can only access by string names
            print('Set Label text', text + '.')

            # `print_pid` will run in a separate process and print the pid.
            app.add_var_event('label', 'print_pid')

        btn.clicked.connect(set_text)

        widg.show()
예제 #16
0
    def show_tree(self):
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        add_scan = QtWidgets.QPushButton('Add Scan')
        add_scan.clicked.connect(self.add_scan)
        self.tree.setParameters(self.settings, showTop=False)
        vlayout.addWidget(add_scan)
        vlayout.addWidget(self.tree)
        dialog.setLayout(vlayout)

        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)
        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle('Fill in information about this Scan batch')
        res = dialog.exec()

        if res == dialog.Accepted:
            # save managers parameters in a xml file
            # start = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
            # start = os.path.join("..",'daq_scan')
            ioxml.parameter_to_xml_file(
                self.settings, os.path.join(self.batch_path, self.settings.child('filename').value()))

        return res == dialog.Accepted
예제 #17
0
    def show_overshoot(self):
        """

        """
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        tree = ParameterTree()
        tree.setMinimumWidth(400)
        tree.setMinimumHeight(500)
        tree.setParameters(self.overshoot_params, showTop=False)

        vlayout.addWidget(tree)
        dialog.setLayout(vlayout)
        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)

        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle('Fill in information about this managers')
        res = dialog.exec()

        if res == dialog.Accepted:
            # save managers parameters in a xml file
            # start = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
            # start = os.path.join("..",'daq_scan')
            ioxml.parameter_to_xml_file(
                self.overshoot_params,
                os.path.join(overshoot_path,
                             self.overshoot_params.child('filename').value()))
예제 #18
0
def test_generalpreferencespage():
    app = QtWidgets.QApplication(sys.argv)
    d = QtWidgets.QDialog()
    layout = QtWidgets.QVBoxLayout()
    layout.addWidget(GeneralPreferencesPage())
    d.setLayout(layout)
    d.show()
    app.exec_()
예제 #19
0
def test_fileentrywidget():
    app = QtWidgets.QApplication(sys.argv)
    d = QtWidgets.QDialog()
    layout = QtWidgets.QVBoxLayout()
    layout.addWidget(FileEntryWidget())
    d.setLayout(layout)
    d.show()
    app.exec_()
예제 #20
0
def test_gdalpreferencespage():
    app = QtWidgets.QApplication(sys.argv)
    dialog = QtWidgets.QDialog()
    layout = QtWidgets.QVBoxLayout()
    layout.addWidget(GDALPreferencesPage())
    dialog.setLayout(layout)
    dialog.resize(500, 400)
    dialog.show()
    app.exec_()
예제 #21
0
def test_gdalinfowidget():
    app = QtWidgets.QApplication(sys.argv)
    dialog = QtWidgets.QDialog()
    layout = QtWidgets.QVBoxLayout()
    layout.addWidget(GDALInfoWidget())
    dialog.setLayout(layout)
    dialog.resize(500, 400)
    dialog.show()
    app.exec_()
예제 #22
0
    def __init__(self):
        self._dlg_view = QtWidgets.QDialog()
        self._dlg_view.setWindowTitle(self.item_config.title)
        self._dlg_ui = Ui_Dialog()
        self._dlg_ui.setupUi(self._dlg_view)

        self.setupContent(self._dlg_ui.content)
        self._dlg_ui.button_box.accepted.connect(self._onOk)
        self._dlg_ui.button_box.rejected.connect(self._onCancel)
예제 #23
0
 def pieAction(self):
     if not LYJMethod.isNetwork():
         QMessageBox.question(self, '消息', '没有网络,请先开启网络,才能使用百分比图表功能',
                              QMessageBox.Yes)
         return
     self.inputView = QtWidgets.QDialog()
     self.oneUi = pieWidget()
     self.oneUi.setupUi(self.inputView)
     self.inputView.show()
     self.inputView.exec()
예제 #24
0
    def __init__(self, homeDir, osType, rootDir, parent):

        self.homeDir = homeDir
        self.osType = osType
        self.prefix = ""
        self.gameDir = ""

        self.winSetupWizard = QtWidgets.QDialog(parent,
                                                QtCore.Qt.FramelessWindowHint)

        if self.osType.usingWindows:
            uifile = resource_filename(
                __name__, 'ui' + os.sep + 'winSetupWizardNative.ui')
        else:
            uifile = resource_filename(__name__,
                                       'ui' + os.sep + 'winSetupWizard.ui')

        Ui_winSetupWizard, base_class = uic.loadUiType(uifile)
        self.uiWizard = Ui_winSetupWizard()
        self.uiWizard.setupUi(self.winSetupWizard)
        self.winSetupWizard.setWindowTitle("Setup Wizard")

        self.model = QtGui.QStandardItemModel(0, 3, self.winSetupWizard)
        self.model.setHeaderData(0, QtCore.Qt.Horizontal, "Prefix")
        self.model.setHeaderData(1, QtCore.Qt.Horizontal, "Game Directory")
        self.model.setHeaderData(2, QtCore.Qt.Horizontal, "Game Directory")
        self.uiWizard.tblGame.setModel(self.model)

        if self.osType.usingWindows:
            self.uiWizard.tblGame.setColumnWidth(0, 0)
            self.uiWizard.tblGame.setColumnWidth(1, 0)
            self.uiWizard.tblGame.setColumnWidth(2, 650)
        else:
            self.uiWizard.tblGame.setColumnWidth(0, 260)
            self.uiWizard.tblGame.setColumnWidth(1, 390)
            self.uiWizard.tblGame.setColumnWidth(2, 0)
            self.uiWizard.cboApplication.addItem("Wine")
            self.uiWizard.cboApplication.addItem("Crossover Games")
            self.uiWizard.cboApplication.addItem("Crossover Office")

        self.uiWizard.cboGame.addItem("Lord of the Rings Online")
        self.uiWizard.cboGame.addItem("Lord of the Rings Online (Test)")
        self.uiWizard.cboGame.addItem("Dungeons & Dragons Online")
        self.uiWizard.cboGame.addItem("Dungeons & Dragons Online (Test)")

        self.ClearGameTable()

        self.uiWizard.btnFind.clicked.connect(self.btnFindClicked)

        if not self.osType.usingWindows:
            self.uiWizard.cboApplication.currentIndexChanged.connect(
                self.ClearGameTable)

        self.uiWizard.cboGame.currentIndexChanged.connect(self.ClearGameTable)
        self.uiWizard.tblGame.clicked.connect(self.GameSelected)
예제 #25
0
    def show_preset(self):
        """

        """
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        tree = ParameterTree()
        tree.setMinimumWidth(400)
        tree.setMinimumHeight(500)
        tree.setParameters(self.preset_params, showTop=False)

        vlayout.addWidget(tree)
        dialog.setLayout(vlayout)
        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)

        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle('Fill in information about this manager')
        res = dialog.exec()

        if self.pid_type:
            path = pid_path
        else:
            path = self.preset_path

        if res == dialog.Accepted:
            # save managers parameters in a xml file
            # start = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
            # start = os.path.join("..",'daq_scan')
            ioxml.parameter_to_xml_file(
                self.preset_params,
                os.path.join(path,
                             self.preset_params.child('filename').value()))

            if not self.pid_type:
                # check if overshoot configuration and layout configuration with same name exists => delete them if yes
                file = os.path.splitext(
                    self.preset_params.child('filename').value())[0]
                file = os.path.join(overshoot_path, file + '.xml')
                if os.path.isfile(file):
                    os.remove(file)

                file = os.path.splitext(
                    self.preset_params.child('filename').value())[0]
                file = os.path.join(layout_path, file + '.dock')
                if os.path.isfile(file):
                    os.remove(file)

        return res == dialog.Accepted
예제 #26
0
파일: qt.py 프로젝트: ykonter/scikit-rf
 def popup(self):
     dialog = QtWidgets.QDialog()
     dialog.setWindowTitle(self.title)
     vlay = QtWidgets.QVBoxLayout(dialog)
     vlay.setContentsMargins(2, 2, 2, 2)
     textEdit = HTMLDisplay()
     qsize = textEdit.sizeHint()  # type: QtCore.QSize
     qsize.setWidth(qsize.width() * 2)
     qsize.setHeight(qsize.height() * 2)
     textEdit.setReadOnly(True)
     textEdit.setHtml(self.help_text)
     vlay.addWidget(textEdit)
     dialog.exec_()
예제 #27
0
    def __init__(self):
        self._view = QtWidgets.QDialog()
        self._ui = Ui_DBSettings()
        self._ui.setupUi(self._view)

        def selectFile():
            path = QFileDialog.getExistingDirectory(
                directory=self._ui.file_path.text())
            if path:
                self._ui.file_path.setText(path)

        self._ui.file_select.clicked.connect(selectFile)
        self._ui.buttonBox.accepted.connect(self.onOk)
예제 #28
0
def prompt_n(msg, inputs):
    """Presents the user with N input widgets and returns the results"""
    dialog = QtWidgets.QDialog(active_window())
    dialog.setWindowModality(Qt.WindowModal)
    dialog.setWindowTitle(msg)

    long_value = msg
    for k, v in inputs:
        if len(k + v) > len(long_value):
            long_value = k + v

    metrics = QtGui.QFontMetrics(dialog.font())
    min_width = metrics.width(long_value) + 100
    if min_width > 720:
        min_width = 720
    dialog.setMinimumWidth(min_width)

    ok_b = ok_button(msg, enabled=False)
    close_b = close_button()

    form_widgets = []

    def get_values():
        return [pair[1].text().strip() for pair in form_widgets]

    for name, value in inputs:
        lineedit = QtWidgets.QLineEdit()
        # Enable the OK button only when all fields have been populated
        # pylint: disable=no-member
        lineedit.textChanged.connect(
            lambda x: ok_b.setEnabled(all(get_values())))
        if value:
            lineedit.setText(value)
        form_widgets.append((name, lineedit))

    # layouts
    form_layout = form(defs.no_margin, defs.button_spacing, *form_widgets)
    button_layout = hbox(defs.no_margin, defs.button_spacing, STRETCH, close_b,
                         ok_b)
    main_layout = vbox(defs.margin, defs.button_spacing, form_layout,
                       button_layout)
    dialog.setLayout(main_layout)

    # connections
    connect_button(ok_b, dialog.accept)
    connect_button(close_b, dialog.reject)

    accepted = dialog.exec_() == QtWidgets.QDialog.Accepted
    text = get_values()
    ok = accepted and all(text)
    return (ok, text)
예제 #29
0
def dialog(title='', message='', widget=None):
    dlg = QtWidgets.QDialog()
    dlg.setWindowTitle(title)
    dlg.setLayout(QtWidgets.QVBoxLayout())
    label = QtWidgets.QLabel(message)
    label.setAlignment(QtCore.Qt.AlignCenter)
    dlg.layout().addWidget(label)
    dlg.layout().addWidget(widget)
    button_box = QtWidgets.QDialogButtonBox(
        QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
    dlg.layout().addWidget(button_box)
    button_box.accepted.connect(dlg.accept)
    button_box.rejected.connect(dlg.reject)
    ret = dlg.exec()
    return ret
예제 #30
0
    def export_image(self):
        # file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
        #     self,
        #     "Save file",
        #     os.path.expanduser("~/dicom-export.png"),
        #     "PNG images (*.png)"
        # )
        # if file_name:
        #     self.pix_label._image.save(file_name)

        # box = QtWidgets.QMessageBox()
        # box.setWindowTitle("Exporting")
        # box.setWindowIcon(QtGui.QIcon('icon.png'))
        # box.setIcon(QtWidgets.QMessageBox.Warning)
        # box.setText("Processing...please wait")
        # msg = box.exec_()

        dialog = QtWidgets.QFileDialog(self)
        dialog.setFileMode(QtWidgets.QFileDialog.DirectoryOnly)
        dialog.setViewMode(QtWidgets.QFileDialog.List)
        dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True)
        if dialog.exec_():
            directory = str(dialog.selectedFiles()[0])

            # Loading dialog.
            dlg = QtWidgets.QDialog(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
            dlg.setWindowTitle("Working...")
            dlg.setWindowIcon(QtGui.QIcon('icon.png'))
            dlg.resize(200, 150)
            dlg.show()

            # start_time = time.perf_counter()
            dicom_to_bmp(directory, self.DESIRED_SERIES)
            grid_images_to_folders(self.HEIGHT_IN_PIXELS, self.WIDTH_IN_PIXELS, self.IMAGE_ROWS, self.IMAGE_COLS)
            # end_time = time.perf_counter()
            # print("Exporting performance (QMessageBox vs. QDialog): ", end_time - start_time)

            dlg.close()
            box = QtWidgets.QMessageBox()
            box.setWindowTitle("Success")
            box.setWindowIcon(QtGui.QIcon('icon.png'))
            box.setIcon(QtWidgets.QMessageBox.Information)
            box.setText("Export complete!")
            msg = box.exec_()

            # No exceptions to this point == successful export.
            self.exportRan = True