Python PyQt5.QtWidgets.QApplication() Examples

The following are 30 code examples for showing how to use PyQt5.QtWidgets.QApplication(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module PyQt5.QtWidgets , or try the search function .

Example 1
Project: simnibs   Author: simnibs   File: main_gui.py    License: GNU General Public License v3.0 6 votes vote down vote up
def start_gui(args):
    app = QtWidgets.QApplication(args)
    #app.setAttribute(QtCore.Qt.AA_UseDesktopOpenGL)
    #app.setAttribute(QtCore.Qt.AA_UseSoftwareOpenGL)
    #app.setAttribute(QtCore.Qt.AA_UseOpenGLES)
    sys.excepthook = except_hook
    ex = TDCS_GUI()
    ex.show()
    if len(args) > 1:
        if args[1].endswith(".mat"):
            ex.openSimnibsFile(args[1])
        elif args[1].endswith(".msh"):
            ex.loadHeadModel(args[1])
        else:
            raise IOError('simnibs_gui can only load .mat and .msh files')
    sys.exit(app.exec_()) 
Example 2
Project: simnibs   Author: simnibs   File: head_model_OGL.py    License: GNU General Public License v3.0 6 votes vote down vote up
def loadMesh(self, mesh_fn):
        print("reading ", mesh_fn)
        self.skin_surf = 'Loading'
        self.gm_surf = 'Loading'
        self.mesh_fn = mesh_fn
        self.loadStage.emit(0)
        QtWidgets.QApplication.processEvents()
        mesh_struct = mesh_io.read_msh(mesh_fn)

        self.loadStage.emit(1)
        QtWidgets.QApplication.processEvents()
        self.skin_surf = surface.Surface(mesh_struct, [5,1005])

        self.loadStage.emit(2)
        QtWidgets.QApplication.processEvents()
        self.gm_surf = surface.Surface(mesh_struct, [2,1002])
        self.loadStage.emit(3)
        
        QtWidgets.QApplication.processEvents()

        self.skin_surf.mesh_name = mesh_fn 
Example 3
Project: simnibs   Author: simnibs   File: head_model_OGL.py    License: GNU General Public License v3.0 6 votes vote down vote up
def get_dAdtField(self, matsimnibs, fn_coil):
        #Try getting the values for plotting dA/dt
        if fn_coil.endswith('.nii') or fn_coil.endswith('.nii.gz'):
            M = numpy.array(matsimnibs)
            if self.skin_surf is not None:
                field_skin = coil._get_field(fn_coil, self.skin_surf.nodes, M, get_norm=True)*1e7
            if self.gm_surf is not None:
                field_gm = coil._get_field(fn_coil, self.gm_surf.nodes, M, get_norm=True)*1e7

            self.hasField = True
            if self.skin_surf is not None:
                self.skin_model_field = self.drawModel('Skin', field_skin)
            QtWidgets.QApplication.processEvents()
            if self.gm_surf is not None:
                self.gm_model_field = self.drawModel('GM', field_gm)
            QtWidgets.QApplication.processEvents()
            self.selectRenderSurface(self.currenSurface)
            self.update()

        else:
            return None 
Example 4
Project: pyweed   Author: iris-edu   File: pyweed_launcher.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def launch():
    """
    Basic startup process.
    """
    from PyQt5 import QtCore, QtWidgets
    from pyweed.gui.SplashScreenHandler import SplashScreenHandler
    import pyweed.gui.qrc  # NOQA

    # See https://stackoverflow.com/questions/31952711/
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)

    fix_locale()

    app = QtWidgets.QApplication(sys.argv)
    splashScreenHandler = SplashScreenHandler()
    app.processEvents()
    pyweed = get_pyweed()
    splashScreenHandler.finish(pyweed.mainWindow)
    sys.exit(app.exec_()) 
Example 5
Project: pipeline   Author: liorbenhorin   File: Qt.py    License: MIT License 6 votes vote down vote up
def convert(lines):
    """Convert compiled .ui file from PySide2 to Qt.py

    Arguments:
        lines (list): Each line of of .ui file

    Usage:
        >> with open("myui.py") as f:
        ..   lines = convert(f.readlines())

    """

    def parse(line):
        line = line.replace("from PySide2 import", "from Qt import")
        line = line.replace("QtWidgets.QApplication.translate",
                            "Qt.QtCompat.translate")
        return line

    parsed = list()
    for line in lines:
        line = parse(line)
        parsed.append(line)

    return parsed 
Example 6
Project: asyncqt   Author: gmarull   File: __init__.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def __init__(self, app=None, set_running_loop=True):
        self.__app = app or QApplication.instance()
        assert self.__app is not None, 'No QApplication has been instantiated'
        self.__is_running = False
        self.__debug_enabled = False
        self.__default_executor = None
        self.__exception_handler = None
        self._read_notifiers = {}
        self._write_notifiers = {}
        self._timer = _SimpleTimer()

        self.__call_soon_signaller = signaller = _make_signaller(QtCore, object, tuple)
        self.__call_soon_signal = signaller.signal
        signaller.signal.connect(lambda callback, args: self.call_soon(callback, *args))

        assert self.__app is not None
        super().__init__()

        if set_running_loop:
            asyncio.events._set_running_loop(self) 
Example 7
Project: BaiduNetDiskAutoTransfer   Author: VinylChloride   File: mainPrgGui.py    License: GNU General Public License v3.0 6 votes vote down vote up
def main():
	app = QApplication(sys.argv)
	autoTransferGui = AutoTransferGUI()
	sys.exit(app.exec_()) 
Example 8
Project: kite   Author: pyrocko   File: talpa.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, filename=None):
        QtWidgets.QApplication.__init__(self, ['Talpa'])

        splash_img = QtGui.QPixmap(
            get_resource('talpa_splash.png'))\
            .scaled(QtCore.QSize(400, 250), QtCore.Qt.KeepAspectRatio)
        self.splash = QtWidgets.QSplashScreen(
            splash_img, QtCore.Qt.WindowStaysOnTopHint)
        self.updateSplashMessage('Talpa')
        self.splash.show()
        self.processEvents()

        self.talpa_win = TalpaMainWindow(filename=filename)

        self.talpa_win.actionExit.triggered.connect(self.exit)
        self.aboutToQuit.connect(self.talpa_win.sandbox.worker_thread.quit)
        self.aboutToQuit.connect(self.talpa_win.sandbox.deleteLater)
        self.aboutToQuit.connect(self.splash.deleteLater)
        self.aboutToQuit.connect(self.deleteLater)

        self.talpa_win.show()

        self.splash.finish(self.talpa_win)
        rc = self.exec_()
        sys.exit(rc) 
Example 9
Project: FRETBursts   Author: tritemio   File: gui.py    License: GNU General Public License v2.0 6 votes vote down vote up
def gui_fname(dir=None):
    """
    Select a file via a dialog and return the file name.
    """
    try:
        from PyQt5.QtWidgets import QApplication, QFileDialog
    except ImportError:
        try:
            from PyQt4.QtGui import QApplication, QFileDialog
        except ImportError:
            from PySide.QtGui import QApplication, QFileDialog

    if dir is None:
        dir = './'

    app = QApplication([dir])
    fname = QFileDialog.getOpenFileName(None, "Select a file...",
                                        dir, filter="All files (*)")

    if isinstance(fname, tuple):
        return fname[0]
    else:
        return str(fname) 
Example 10
Project: PyIntroduction   Author: tody411   File: web_browser.py    License: MIT License 6 votes vote down vote up
def mainPyQt4Simple():
    # 必要なモジュールのimport
    from PyQt4.QtCore import QUrl
    from PyQt4.QtGui import QApplication
    from PyQt4.QtWebKit import QWebView

    url = 'https://github.com/tody411/PyIntroduction'

    app = QApplication(sys.argv)

    # QWebViewによるWebページ表示
    browser = QWebView()
    browser.load(QUrl(url))
    browser.show()

    sys.exit(app.exec_())

## PyQt4でのWebブラウザー作成(Youtube用). 
Example 11
Project: PyIntroduction   Author: tody411   File: web_browser.py    License: MIT License 6 votes vote down vote up
def mainPyQt5():
    # 必要なモジュールのimport
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtCore import QUrl
    from PyQt5.QtWebEngineWidgets import QWebEngineView

    url = 'https://github.com/tody411/PyIntroduction'

    app = QApplication(sys.argv)

    # QWebEngineViewによるWebページ表示
    browser = QWebEngineView()
    browser.load(QUrl(url))
    browser.show()

    sys.exit(app.exec_()) 
Example 12
Project: Tools   Author: CharlesPikachu   File: runcat.py    License: MIT License 6 votes vote down vote up
def runcatCPU():
    app = QApplication(sys.argv)
    # 最后一个可视的窗口退出时程序不退出
    app.setQuitOnLastWindowClosed(False)
    icon = QSystemTrayIcon()
    icon.setIcon(QIcon('icons/0.png'))
    icon.setVisible(True)
    cpu_percent = psutil.cpu_percent(interval=1) / 100
    cpu_percent_update_fps = 20
    fps_count = 0
    while True:
        fps_count += 1
        if fps_count > cpu_percent_update_fps:
            cpu_percent = psutil.cpu_percent(interval=1) / 100
            fps_count = 0
        # 开口向上的抛物线, 左边递减
        time_interval = (cpu_percent * cpu_percent - 2 * cpu_percent + 2) / 20
        for i in range(5):
            icon.setIcon(QIcon('icons/%d.png' % i))
            icon.setToolTip('cpu: %.2f' % cpu_percent)
            time.sleep(time_interval)
    app.exec_() 
Example 13
Project: Tools   Author: CharlesPikachu   File: runcat.py    License: MIT License 6 votes vote down vote up
def runcatMemory():
    app = QApplication(sys.argv)
    # 最后一个可视的窗口退出时程序不退出
    app.setQuitOnLastWindowClosed(False)
    icon = QSystemTrayIcon()
    icon.setIcon(QIcon('icons/0.png'))
    icon.setVisible(True)
    memory_percent = psutil.virtual_memory().percent / 100
    memory_percent_update_fps = 20
    fps_count = 0
    while True:
        fps_count += 1
        if fps_count > memory_percent_update_fps:
            memory_percent = psutil.virtual_memory().percent / 100
            fps_count = 0
        # 开口向上的抛物线, 左边递减
        time_interval = (memory_percent * memory_percent - 2 * memory_percent + 2) / 20
        for i in range(5):
            icon.setIcon(QIcon('icons/%d.png' % i))
            icon.setToolTip('memory: %.2f' % memory_percent)
            time.sleep(time_interval)
    app.exec_() 
Example 14
Project: code2pdf   Author: tushar-rishav   File: code2pdf.py    License: MIT License 5 votes vote down vote up
def init_print(self, linenos=True, style="default"):
        app = QApplication([])  # noqa
        doc = QTextDocument()
        doc.setHtml(
            self.highlight_file(linenos=linenos, style=style)
        )
        printer = QPrinter()
        printer.setOutputFileName(self.pdf_file)
        printer.setOutputFormat(QPrinter.PdfFormat)
        page_size_dict = {"a2": QPrinter.A2, "a3": QPrinter.A3, "a4": QPrinter.A4, "letter": QPrinter.Letter}
        printer.setPageSize(page_size_dict.get(self.size.lower(), QPrinter.A4))
        printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)
        doc.print_(printer)
        logging.info("PDF created at %s" % (self.pdf_file)) 
Example 15
Project: multibootusb   Author: mbusb   File: mbusb_gui.py    License: GNU General Public License v2.0 5 votes vote down vote up
def main_gui():
    app = QtWidgets.QApplication(sys.argv)
    #    ui_about = Ui_About()
    #    ui = Ui_MainWindow()

    if platform.system() == 'Linux' and os.getuid() != 0:
        show_admin_info()
        sys.exit(2)

    else:
        window = AppGui()
        window.show()
        window.setWindowTitle("MultiBootUSB - " + mbusb_version())
        window.setWindowIcon(QtGui.QIcon(resource_path(os.path.join("data", "tools", "multibootusb.png"))))
    sys.exit(app.exec_()) 
Example 16
Project: kw_condition   Author: coreanq   File: main.py    License: MIT License 5 votes vote down vote up
def quit(self):
        print(util.whoami())
        self.commTerminate()
        QApplication.quit()

    # 에러코드의 메시지를 출력한다. 
Example 17
Project: ANGRYsearch   Author: DoTheEvo   File: angrysearch.py    License: GNU General Public License v2.0 5 votes vote down vote up
def right_clk_copy(self):
        qmodel_index = self.center.table.currentIndex()
        path = self.model.itemFromIndex(qmodel_index.row(), 0)._fullpath
        clipboard = Qw.QApplication.clipboard()
        clipboard.setText(path)

    # WHEN A ROW IS SELECTED IN TABLE VIEW, BY MOUSE OR KEYBOARD
    # MIMETYPE IS GET IN A THREAD TO KEEP THE INTERFACE RESPONSIVE 
Example 18
Project: ANGRYsearch   Author: DoTheEvo   File: angrysearch.py    License: GNU General Public License v2.0 5 votes vote down vote up
def paint(self, painter, option, index):
            painter.save()

            options = Qw.QStyleOptionViewItem(option)

            self.initStyleOption(options, index)
            self.doc.setHtml(options.text)
            options.text = ''

            style = (Qw.QApplication.style() if options.widget is None
                else options.widget.style())
            style.drawControl(Qw.QStyle.CE_ItemViewItem, options, painter)

            ctx = Qg.QAbstractTextDocumentLayout.PaintContext()

            if option.state & Qw.QStyle.State_Selected:
                ctx.palette.setColor(Qg.QPalette.Text,
                                     option.palette.color(
                                         Qg.QPalette.Active,
                                         Qg.QPalette.HighlightedText))
            else:
                ctx.palette.setColor(Qg.QPalette.Text,
                                     option.palette.color(
                                         Qg.QPalette.Active, Qg.QPalette.Text))

            textRect = style.subElementRect(Qw.QStyle.SE_ItemViewItemText,
                                            options, None)

            if index.column() != 0:
                textRect.adjust(5, 0, 0, 0)

            thefuckyourshitup_constant = 4
            margin = (option.rect.height() - options.fontMetrics.height()) // 2
            margin = margin - thefuckyourshitup_constant
            textRect.setTop(textRect.top() + margin)

            painter.translate(textRect.topLeft())
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
            self.doc.documentLayout().draw(painter, ctx)

            painter.restore() 
Example 19
Project: ANGRYsearch   Author: DoTheEvo   File: angrysearch.py    License: GNU General Public License v2.0 5 votes vote down vote up
def main():
    global con
    with open_database() as con:
        con.create_function("regexp", 2, regexp)
        app = Qw.QApplication(sys.argv)
        ui = AngryMainWindow()
        sys.exit(app.exec_()) 
Example 20
Project: simnibs   Author: simnibs   File: main_gui.py    License: GNU General Public License v3.0 5 votes vote down vote up
def drawModel(self):
        QtWidgets.QApplication.processEvents()
        self.headModelWidget.glHeadModel.drawSkinAndGm()
        self.headModelWidget.glHeadModel.setEEG(self.session.eeg_cap)
        #self.headModelWidget.glHeadModel.selectRenderSurface('Scalp')

    #Defines the tabs 
Example 21
Project: simnibs   Author: simnibs   File: head_model_OGL.py    License: GNU General Public License v3.0 5 votes vote down vote up
def drawSkinAndGm(self):
        self.loadStage.emit(3)
        self.skin_model = self.drawModel('Skin')
        #QtWidgets.QApplication.processEvents()
        self.gm_model = self.drawModel('GM')
        self.loadStage.emit(4)
        #QtWidgets.QApplication.processEvents()
        self.selectRenderSurface('Skin') 
Example 22
Project: simnibs   Author: simnibs   File: postinstall_simnibs.py    License: GNU General Public License v3.0 5 votes vote down vote up
def start_gui(simnibsdir,
                  copy_matlab,
                  setup_links,
                  copy_gmsh_options,
                  add_to_path,
                  extra_coils,
                  add_shortcut_icons,
                  associate_files):
        app = QtWidgets.QApplication(sys.argv)
        ex = PostInstallGUI(
            simnibsdir,
            copy_gmsh_options,
            add_to_path,
            extra_coils,
            add_shortcut_icons,
            associate_files
        )
        ex.show()
        app.exec_()
        if ex.result():
            install(ex.install_dir,
                    False, False,
                    ex.copy_gmsh_options,
                    ex.add_to_path,
                    ex.extra_coils,
                    ex.add_shortcut_icons,
                    ex.associate_files,
                    copy_matlab,
                    setup_links)
        else:
            raise Exception('Post-installation cancelled by user') 
Example 23
Project: simnibs   Author: simnibs   File: postinstall_simnibs.py    License: GNU General Public License v3.0 5 votes vote down vote up
def start_uninstall_gui(install_dir):
        app = QtWidgets.QApplication(sys.argv)
        ex = UnintallerGUI()
        ex.show()
        app.exec_()
        if ex.result():
            uninstall(install_dir)
        else:
            raise Exception('uninstall cancelled by user') 
Example 24
Project: idasec   Author: RobinDavid   File: idasec.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def main_standalone():
    app = QtWidgets.QApplication(sys.argv)
    ida_app = IDASecStandalone()
    form = AnalysisWidget(ida_app)
    form.show()
    app.exec_() 
Example 25
Project: dcc   Author: amimo   File: main.py    License: Apache License 2.0 5 votes vote down vote up
def androgui_main(input_file, input_plugin):
    # Load pyqt5 after argument processing, so we can collect the arguments
    # on a system without PyQT5.
    try:
        from PyQt5 import QtWidgets, QtGui
    except ImportError:
        print("No PyQT5 found! Exiting...", file=sys.stderr)
        sys.exit(1)
    try:
        import pyperclip
    except ImportError:
        print("No pyperclip found! Exiting...", file=sys.stderr)
        sys.exit(1)

    from androguard.gui.mainwindow import MainWindow

    # We need that to save huge sessions when leaving and avoid
    # RuntimeError: maximum recursion depth exceeded while pickling an object
    # or
    # RuntimeError: maximum recursion depth exceeded in cmp
    # http://stackoverflow.com/questions/2134706/hitting-maximum-recursion-depth-using-pythons-pickle-cpickle
    sys.setrecursionlimit(50000)

    app = QtWidgets.QApplication(sys.argv)

    window = MainWindow(input_file=input_file,
                        input_plugin=input_plugin)
    window.resize(1024, 768)
    window.show()

    sys.exit(app.exec_()) 
Example 26
Project: easygui_qt   Author: aroberge   File: launcher.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    _ = qt_widgets.QApplication([])
    dialog = Dialog()
    dialog.exec_() 
Example 27
Project: easygui_qt   Author: aroberge   File: test_app.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_string(prompt="What is your name? ", title="Title",
               default_response="PyQt", app=None):
    """GUI equivalent of input()."""

    if app is None:
        app = qt_widgets.QApplication([])
    app.dialog = qt_widgets.QInputDialog()
    text, ok = app.dialog.getText(None, title, prompt,
                                  qt_widgets.QLineEdit.Normal,
                                  default_response)
    app.quit()
    if ok:
        return text 
Example 28
Project: raspiblitz   Author: rootzoll   File: main.py    License: MIT License 5 votes vote down vote up
def main():
    # make sure CTRL+C works
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    description = """BlitzTUI - the Touch-User-Interface for the RaspiBlitz project

Keep on stacking SATs..! :-D"""

    parser = argparse.ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
    parser.add_argument("-V", "--version",
                        help="print version", action="version",
                        version=__version__)

    parser.add_argument('-d', '--debug', help="enable debug logging", action="store_true")

    # parse args
    args = parser.parse_args()

    if args.debug:
        setup_logging(log_level="DEBUG")
    else:
        setup_logging()

    log.info("Starting BlitzTUI v{}".format(__version__))

    # initialize app
    app = QApplication(sys.argv)

    w = AppWindow()
    w.show()

    # run app
    sys.exit(app.exec_()) 
Example 29
Project: BreezeStyleSheets   Author: Alexhuszagh   File: native.py    License: MIT License 5 votes vote down vote up
def main():
    """
    Application entry point
    """
    logging.basicConfig(level=logging.DEBUG)
    # create the application and the main window
    app = QtWidgets.QApplication(sys.argv)
    #app.setStyle(QtWidgets.QStyleFactory.create("fusion"))
    window = QtWidgets.QMainWindow()

    # setup ui
    ui = example.Ui_MainWindow()
    ui.setupUi(window)
    ui.bt_delay_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    ui.bt_instant_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    ui.bt_menu_button_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    window.setWindowTitle("Native example")

    # tabify dock widgets to show bug #6
    window.tabifyDockWidget(ui.dockWidget1, ui.dockWidget2)

    # auto quit after 2s when testing on travis-ci
    if "--travis" in sys.argv:
        QtCore.QTimer.singleShot(2000, app.exit)

    # run
    window.show()
    app.exec_() 
Example 30
Project: qutebrowser   Author: qutebrowser   File: test_miscwidgets.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mock_clipboard(self, mocker):
        """Fixture to mock QApplication.clipboard.

        Return:
            The mocked QClipboard object.
        """
        mocker.patch.object(QApplication, 'clipboard')
        clipboard = mock.MagicMock()
        clipboard.supportsSelection.return_value = True
        QApplication.clipboard.return_value = clipboard
        return clipboard