def __init__(self, width=800, height=600, parent=None): # Start app self._app = QApplication.instance() if self._app is None: self._app = QApplication([]) super(ShapeViewerQt, self).__init__(parent) # Window settings self.setWindowTitle('pyOCCT') _icon = os.path.dirname(__file__) + '/_resources/icon.png' _qicon = QIcon(_icon) self.setWindowIcon(_qicon) # Create the OCCT view frame = QFrame(self) layout = QVBoxLayout(frame) layout.setContentsMargins(0, 0, 0, 0) self._the_view = QOpenCascadeWidget(self) layout.addWidget(self._the_view) self.setCentralWidget(frame) self.show() self.resize(width, height) self.view.my_view.MustBeResized()
def run_gui(args): app = QApplication( []) # Early so that QT is initialized before other imports app.setWindowIcon(resourceIcon("application/window_icon_cutout")) if FeatureToggling.is_enabled("prefect"): ert_conf_path = os.path.abspath(args.config)[:-3] + "ert" with open(ert_conf_path, "w") as f: f.write("""QUEUE_SYSTEM LOCAL QUEUE_OPTION LOCAL MAX_RUNNING 50 RUNPATH out/real_%d/iter_%d NUM_REALIZATIONS 100 MIN_REALIZATIONS 1 """) res_config = ResConfig(ert_conf_path) else: res_config = ResConfig(args.config) os.chdir(res_config.config_path) ert = EnKFMain(res_config, strict=True, verbose=args.verbose) # window reference must be kept until app.exec returns window = _start_window(ert, args) return app.exec_()
def main(): # pragma: no cover """basic testing""" # kills the program when you hit Cntl+C from the command line # doesn't save the current state as presumably there's been an error import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import sys # Someone is launching this directly # Create the QApplication app = QApplication(sys.argv) #The Main window data = { 'font_size': 8, 'model_name': 'main', 'nodes_pound': 100, 'elements_pound': 200, } #main_window = HighlightWindow(data, menu_type='highlight') main_window = HighlightWindow(data, menu_type='mark') main_window.show() # Enter the main loop app.exec_()
def get_application(name=''): """ Initialise and return the global application object :param name: Optional application name :return: Global appliction object """ global _QAPP def exception_handler(exctype, value, tb): traceback.print_exception(exctype, value, tb) sys.exit(1) if _QAPP is None: setup_library_paths() _QAPP = QApplication([name]) if PYQT4: # Do not destroy C++ Qtcore objects on exit # Matches PyQt5 behaviour to avoid random segfaults # https://www.riverbankcomputing.com/static/Docs/PyQt5/pyqt4_differences.html#object-destruction-on-exit sip.setdestroyonexit(False) sys.excepthook = exception_handler return _QAPP
def main_gui(): from qtpy.QtWidgets import QInputDialog, QApplication, QMessageBox import sys _app = QApplication(sys.argv) hostname = prompt_hostname_gui() if not hostname: return try: displays = list_displays(hostname) except subprocess.CalledProcessError as e: QMessageBox.critical(None, 'Error listing displays', e.output) exit(-1) if not displays: try: display = create_display(hostname) except subprocess.CalledProcessError as e: QMessageBox.critical(None, 'Error creating display', e.output) exit(-1) elif len(displays) == 1: display = displays[0] else: display, accepted = QInputDialog.getItem(None, 'Select display', 'Display:', map(str, displays), editable=False) if not accepted: return display = int(display) try: print('Connecting to {}:{}'.format(hostname, display)) connect_viewer(hostname, display) except subprocess.CalledProcessError as e: QMessageBox.critical(None, 'Error connecting to display', e.output) exit(-1)
def _main(args, exec=True): # import pydm # app = QApplication([]) # app = pydm.PyDMApplication() app = QApplication.instance() or QApplication([]) signal.signal(signal.SIGINT, signal.SIG_DFL) from xicam.gui.windows import splash from xicam.core import msg if getattr(args, 'verbose', False): QErrorMessage.qtHandler() # start splash in subprocess splash_proc = QProcess() # splash_proc.started.connect(lambda: print('started splash')) # splash_proc.finished.connect(lambda: print('finished splashing')) log_file = msg.file_handler.baseFilename initial_length = os.path.getsize(log_file) splash_proc.start(sys.executable, [splash.__file__, log_file, str(initial_length)]) from xicam.gui.windows.mainwindow import XicamMainWindow mainwindow = XicamMainWindow() while splash_proc.state() != QProcess.NotRunning: app.processEvents() # splash_proc.waitForFinished() mainwindow.show() mainwindow.activateWindow() # splash = splash.XicamSplashScreen(args=args) if exec: return app.exec_() else: return mainwindow
def main(): # pragma: no cover # kills the program when you hit Cntl+C from the command line # doesn't save the current state as presumably there's been an error import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import sys # Someone is launching this directly # Create the QApplication app = QApplication(sys.argv) #The Main window transform = { 'xyz': [0., 0., 0.], 'is_absolute': False, 'rot origin(X)': 0., } symmetry = {} data = { 'name': 'WingGeom', 'color': (0, 0, 255), 'font_size': 8, 'num_U': 16, 'num_W': 33, 'Density': 1.0, 'Thin Shell': False, 'Mass/Area': 1.0, #'Priority' : 0, 'Negative Volume': False, 'transform': transform, 'symmetry': symmetry, } main_window = WingWindow(data) main_window.show() # Enter the main loop app.exec_()
def main(): # pragma: no cover # kills the program when you hit Cntl+C from the command line # doesn't save the current state as presumably there's been an error import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import sys # Someone is launching this directly # Create the QApplication app = QApplication(sys.argv) #The Main window data = { 'font_size': 8, 'use_gradient_background': True, 'background_color': (0., 0., 0.), # black 'background_color2': (1., 0., 1.), # purple 'coord_scale': 0.05, 'coord_text_scale': 1.0, 'show_corner_coord': False, 'magnify': 5, 'text_size': 12, 'text_color': (0., 1., 0.), # green 'highlight_color': (1., 1., 0.), # yellow 'highlight_opacity': 0.8, 'annotation_color': (1., 0., 0.), # red 'annotation_size': 11, 'picker_size': 10., 'min_clip': 0., 'max_clip': 10, 'dim_max': 502., } for name in NASTRAN_BOOL_KEYS: data[name] = True main_window = PreferencesWindow(data) main_window.show() # Enter the main loop app.exec_()
def test(): # pragma: no cover """Display dialog for manual testing.""" class FakeProcess: def __init__(self, pid): self.pid = pid def processId(self): return self.pid servers = [ ServerProcess(FakeProcess(42), '/my/home/dir', state=ServerState.RUNNING, output='Nicely humming along...\n'), ServerProcess(FakeProcess(404), '/some/other/dir', state=ServerState.FINISHED, output='Terminated for some reason...\n') ] app = QApplication(sys.argv) dialog = ServerInfoDialog(servers) dialog.show() sys.exit(app.exec_())
def main(): # pragma: no cover import sys # kills the program when you hit Cntl+C from the command line import signal signal.signal(signal.SIGINT, signal.SIG_DFL) from qtpy.QtWidgets import QApplication app = QApplication(sys.argv) form = [ [u'Geometry', None, [ [u'NodeID', 0, []], [u'ElementID', 1, []], [u'PropertyID', 2, []], [u'MaterialID', 3, []], [u'E', 4, []], [u'Element Checks', None, [ [u'ElementDim', 5, []], [u'Min Edge Length', 6, []], [u'Min Interior Angle', 7, []], [u'Max Interior Angle', 8, []]], ],], ], ] name = 'Model' data = form choices = ['cat?', 'dog?'] res_widget = ResultsWindow(app, name, data, choices) #name = 'name' #res_widget.update_results(form, name) res_widget.show() sys.exit(app.exec_())
def test_widget(widget_class, size=None, title=None, options=True, timeout=1000): """Test widget""" widget_name = widget_class.__name__ app = QApplication([]) window = widget = widget_class() if options: if isinstance(widget, QMainWindow): widget = window.centralWidget() widget.setParent(None) else: window = QMainWindow() central_widget = TestCentralWidget(widget_name, parent=window) central_widget.add_widget(widget) window.setCentralWidget(central_widget) widget_of_interest = central_widget.widget_of_interest else: widget_of_interest = window widget_of_interest.setObjectName(widget_name) if title is None: from qwt import __version__ title = 'Test "%s" - PythonQwt %s' % (widget_name, __version__) window.setWindowTitle(title) if size is not None: width, height = size window.resize(width, height) window.show() if os.environ.get("TEST_UNATTENDED") is not None: QTimer.singleShot(timeout, lambda: take_screenshot(widget_of_interest)) app.exec_() return app
def main(): # kills the program when you hit Cntl+C from the command line # doesn't save the current state as presumably there's been an error import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import sys # Someone is launching this directly # Create the QApplication app = QApplication(sys.argv) #The Main window data = { 'font_size' : 8, #'cids' : [0, 1, 2, 3], 'cids' : [0], 'plane_color' : (1., 0., 1.), # purple 'name' : 'main', } main_window = CuttingPlaneWindow(data, show_tol=True) main_window.show() # Enter the main loop app.exec_()
def test_threads(): from qtpy.QtWidgets import QApplication app = QApplication([]) from xicam.core import threads from qtpy.QtCore import QTimer, QObject, Signal q = QTimer() def callback(a): assert a == 10 t = threads.QThreadFuture(sum, [1, 2, 3, 4], callback_slot=callback) class Callback(QObject): sig = Signal(int) callback = Callback() t2 = threads.QThreadFuture(sum, [1, 2, 3, 4], callback_slot=callback.sig) q.singleShot(1000, t.start) q.singleShot(1000, t2.start) q.singleShot(2000, app.quit) app.exec_()
def main(): # pragma: no cover # kills the program when you hit Cntl+C from the command line # doesn't save the current state as presumably there's been an error import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import sys # Someone is launching this directly # Create the QApplication app = QApplication(sys.argv) #The Main window #g = GeometryHandle() #g.add('main', color=(0, 0, 0), line_thickness=0.0) #g.get_grid('name') #g.set_color('name') #g.set_grid('name') #g.set_grid('name') parent = app red = (255, 0, 0) blue = (0, 0, 255) green = (0, 255, 0) purple = (255, 0, 255) d = { 'caero1': AltGeometry(parent, 'caero', color=green, line_width=3, opacity=0.2), 'caero2': AltGeometry(parent, 'caero', color=purple, line_width=4, opacity=0.3), 'caero': AltGeometry(parent, 'caero', color=blue, line_width=2, opacity=0.1), 'main': AltGeometry(parent, 'main', color=red, line_width=1, opacity=0.0), } main_window = EditBoundaryConditions(d, win_parent=None) main_window.show() # Enter the main loop app.exec_()
def gui_qt(*, startup_logo=False): """Start a Qt event loop in which to run the application. Parameters ---------- startup_logo : bool Show a splash screen with the napari logo during startup. Notes ----- This context manager is not needed if running napari within an interactive IPython session. In this case, use the ``%gui qt`` magic command, or start IPython with the Qt GUI event loop enabled by default by using ``ipython --gui=qt``. """ app = QApplication.instance() or QApplication(sys.argv) if startup_logo: logopath = join(dirname(__file__), '..', 'resources', 'logo.png') splash_widget = QSplashScreen(QPixmap(logopath).scaled(400, 400)) splash_widget.show() yield if startup_logo: splash_widget.close() app.exec_()
def _main(args, exec=True): global mainwindow, splash_proc, show_check_timer # import pydm # app = QApplication([]) # app = pydm.PyDMApplication() app = QApplication.instance() or QApplication([]) signal.signal(signal.SIGINT, signal.SIG_DFL) from xicam.gui.windows import splash from xicam.core import msg if getattr(args, 'verbose', False): QErrorMessage.qtHandler() # start splash in subprocess splash_proc = QProcess() # splash_proc.started.connect(lambda: print('started splash')) # splash_proc.finished.connect(lambda: print('finished splashing')) log_file = msg.file_handler.baseFilename initial_length = os.path.getsize(log_file) splash_proc.start(sys.executable, [splash.__file__, log_file, str(initial_length)]) show_check_timer = QTimer() show_check_timer.timeout.connect(check_show_mainwindow) show_check_timer.start(100) from xicam.gui.windows.mainwindow import XicamMainWindow mainwindow = XicamMainWindow() if exec: return app.exec_() else: return mainwindow
def create_window(window): def _create(): browser = BrowserView(window) _main_window_created.set() if window.minimized: # showMinimized does not work on start without showNormal first # looks like a bug in QT browser.showNormal() browser.showMinimized() elif not window.hidden: browser.show() if window.uid == 'master': global _app _app = QApplication.instance() or QApplication([]) _create() _app.exec_() else: _main_window_created.wait() i = list(BrowserView.instances.values())[0] # arbitrary instance i.create_window_trigger.emit(_create)
def update_progress(self, progress): self.progressBar.setValue(progress) def lightTheme(self): qtmodern.styles.light(QApplication.instance()) def darkTheme(self): qtmodern.styles.dark(QApplication.instance()) @Slot() def on_pushButton_clicked(self): self.close() @Slot() def closeEvent(self, event): reply = QMessageBox.question(self, 'Exit', 'Do you want to exit?') if reply == QMessageBox.Yes: event.accept() else: event.ignore() if __name__ == '__main__': app = QApplication(sys.argv) qtmodern.styles.dark(app) mw = qtmodern.windows.ModernWindow(MainWindow()) mw.show() sys.exit(app.exec_())
def test(): """ """ app = QApplication([]) win = TourTestWindow() win.show() app.exec_()
def event_loop(): """Start a Qt event loop in which to run the application.""" app = QApplication.instance() or QApplication(sys.argv) yield app.exec_()
def setUpClass(cls): cls.app = QApplication([])
import sys from pathlib import Path from qtpy.QtGui import QIcon from qtpy.QtWidgets import QApplication import modpack_builder from modpack_builder.builder import ModpackBuilder from modpack_builder.gui.application import ModpackBuilderWindow app = QApplication(list()) builder = ModpackBuilder() window = ModpackBuilderWindow(builder) icon_path = (Path(modpack_builder.__file__).parent.parent / "icon/icon.ico").resolve() window.setWindowIcon(QIcon(str(icon_path))) window.show() sys.exit(app.exec_())
def create_images(base_svg_path=SVG_PATH, rc_path=RC_PATH, palette=DarkPalette): """Create resources `rc` png image files from base svg files and palette. Search all SVG files in `base_svg_path` excluding IMAGE_BLACKLIST, change its colors using `palette` creating temporary SVG files, for each state generating PNG images for each size `heights`. Args: base_svg_path (str, optional): [description]. Defaults to SVG_PATH. rc_path (str, optional): [description]. Defaults to RC_PATH. palette (DarkPalette, optional): Palette . Defaults to DarkPalette. """ # Needed to use QPixmap _ = QApplication([]) temp_dir = tempfile.mkdtemp() svg_fnames = [f for f in os.listdir(base_svg_path) if f.endswith('.svg')] base_height = 32 # See: https://doc.qt.io/qt-5/scalability.html heights = { 32: '.png', 64: '@2x.png', } _logger.info("Creating images ...") _logger.info("SVG folder: %s" % base_svg_path) _logger.info("TMP folder: %s" % temp_dir) _logger.info("PNG folder: %s" % rc_path) num_svg = len(svg_fnames) num_png = 0 num_ignored = 0 # Get rc links from scss to check matches rc_list = get_rc_links_from_scss() num_rc_list = len(rc_list) for height, ext in heights.items(): width = height _logger.debug(" Size HxW (px): %s X %s" % (height, width)) for svg_fname in svg_fnames: svg_name = svg_fname.split('.')[0] # Skip blacklist if svg_name not in IMAGE_BLACKLIST: svg_path = os.path.join(base_svg_path, svg_fname) color_files = _get_file_color_map(svg_fname, palette=palette) _logger.debug(" Working on: %s" % os.path.basename(svg_fname)) # Replace colors and create all file for different states for color_svg_name, color in color_files.items(): temp_svg_path = os.path.join(temp_dir, color_svg_name) _create_colored_svg(svg_path, temp_svg_path, color) png_fname = color_svg_name.replace('.svg', ext) png_path = os.path.join(rc_path, png_fname) convert_svg_to_png(temp_svg_path, png_path, height, width) num_png += 1 _logger.debug(" Creating: %s" % os.path.basename(png_fname)) # Check if the rc_name is in the rc_list from scss # only for the base size if height == base_height: rc_base = os.path.basename(rc_path) png_base = os.path.basename(png_fname) rc_name = '/' + os.path.join(rc_base, png_base) try: rc_list.remove(rc_name) except ValueError: pass else: num_ignored += 1 _logger.debug(" Ignored blacklist: %s" % os.path.basename(svg_fname)) _logger.info("# SVG files: %s" % num_svg) _logger.info("# SVG ignored: %s" % num_ignored) _logger.info("# PNG files: %s" % num_png) _logger.info("# RC links: %s" % num_rc_list) _logger.info("# RC links not in RC: %s" % len(rc_list)) _logger.info("RC links not in RC: %s" % rc_list)
def main(): # pragma: no cover """test example for AnimationWindow""" # kills the program when you hit Cntl+C from the command line # doesn't save the current state as presumably there's been an error import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import sys # Someone is launching this directly # Create the QApplication app = QApplication(sys.argv) #The Main window #from pyNastran.gui.menus.legend.animation import AnimationWindow data2 = { 'font_size' : 8, 'icase_fringe' : 1, 'icase_disp' : 2, 'icase_vector' : 3, 'title' : 'cat', 'time' : 2, 'frames/sec' : 30, 'resolution' : 1, 'iframe' : 0, 'is_scale' : False, 'dirname' : os.getcwd(), 'scale' : 2.0, 'default_scale' : 10, 'arrow_scale' : 3.0, 'default_arrow_scale' : 30, #'phase' : 0., 'phase' : None, 'default_phase' : 120., #'default_phase' : None, #'start_time' : 0., #'end_time' : 0., 'default_time' : 0., 'icase_start' : 10, 'icase_delta' : 3, 'stress_min' : 0., 'stress_max' : 1000., } data2['phase'] = 0. # uncomment for phase form = [ [u'Geometry', None, [ (u'NodeID', 0, []), (u'ElementID', 1, []), (u'PropertyID', 2, []), (u'MaterialID', 3, []), (u'E', 4, []), (u'Element Checks', None, [ (u'ElementDim', 5, []), (u'Min Edge Length', 6, []), (u'Min Interior Angle', 7, []), (u'Max Interior Angle', 8, [])], ),], ], ] #[0, 1, 2, 3, 4, 5, 6, 7, 8] main_window = AnimationWindow(data2, fringe_cases=form) main_window.show() # Enter the main loop app.exec_()
def main(): """Launch.""" app = None app = QApplication(argv) ex = Csgogsi() exit(app.exec_())
import os import unittest import unittest.mock import qtpy.QtWebEngineWidgets # noqa: F401 from qtpy.QtWidgets import QApplication if QApplication.instance() is None: _ = QApplication(["vidify"]) CI = "CI" in os.environ and os.environ["CI"] == "true" SKIP_MSG = "Skipping this test as it won't work on the current system." class SpotifyWebTest(unittest.TestCase): @unittest.skipIf(CI, SKIP_MSG) def test_simple(self): """ The web credentials have to be already in the config file, including the auth token and the expiration date. """ from vidify.api.spotify.web import get_token, SpotifyWebAPI from vidify.config import Config config = Config() with unittest.mock.patch('sys.argv', ['']): config.parse() token = get_token(config.refresh_token, config.client_id, config.client_secret) api = SpotifyWebAPI(token) api.connect_api() api._refresh_metadata()
def main(): app = QApplication(sys.argv) ex = StackedCanvasView() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) form = MyTree() form.show() app.exec_()
from qtpy.QtWidgets import QApplication, QLabel # Initialize application app = QApplication([]) # Create label widget label = QLabel('Hello, world!') label.show() # Start 'event loop' app.exec_()
def main(): import sys Program = QApplication(sys.argv) MyProg = Prog() MyProg.show() Program.exec_()