Beispiel #1
0
    def __init__(self, argv):
        QApplication.__init__(self, argv)
        self.window = uic.loadUi(resource_filename('herborist',
                                                   'herborist.ui'))

        self.enable_motor_view(False)

        # slider / lcd connections
        self.window.rdt_slider.valueChanged.connect(
            self.window.rdt_lcd.display)
        self.window.torque_max_slider.valueChanged.connect(
            self.window.torque_max_lcd.display)
        self.window.lower_limit_dial.valueChanged.connect(
            self.window.lower_limit_lcd.display)
        self.window.upper_limit_dial.valueChanged.connect(
            self.window.upper_limit_lcd.display)
        self.window.present_position_dial.valueChanged.connect(
            self.window.present_position_lcd.display)
        self.window.goal_position_dial.valueChanged.connect(
            self.window.goal_position_lcd.display)

        # Connect the button to their cb
        self.window.scan_button.pressed.connect(self.start_scanning)
        self.window.abort_button.pressed.connect(self.abort_scanning)

        # We manually uncheck most baudrates in the selection list
        # as unchecking them in the ui editor make the checkbox goes away
        for i in range(1, len(self.window.baudrate_list)):
            self.window.baudrate_list.item(i).setCheckState(False)

        # We prevent the minimum id to be greater than the maximum id
        def min_id_changed(self, new_id):
            if new_id >= self.window.max_id.value():
                self.window.min_id.setValue(self.window.max_id.value())

        def max_id_changed(self, new_id):
            if new_id <= self.window.min_id.value():
                self.window.max_id.setValue(self.window.min_id.value())

        self.window.min_id.valueChanged.connect(
            lambda i: min_id_changed(self, i))
        self.window.max_id.valueChanged.connect(
            lambda i: max_id_changed(self, i))

        # We automatically refresh the port list
        self.refresh_port_thread = self.UpdatePortThread()
        self.refresh_port_thread.port_updated.connect(self.update_port)
        self.refresh_port_thread.start()

        # Motor View
        self.window.motor_tree.itemSelectionChanged.connect(
            self.update_motor_view)
        self.window.goal_position_dial.valueChanged.connect(
            self.update_motor_position)
        self.window.update_eeprom_button.pressed.connect(self.update_eeprom)
        self.window.torque_checkbox.stateChanged.connect(self.switch_torque)

        self.refresh_motor_thread = None
Beispiel #2
0
    def __init__(self,
                 name='VTK Viewer',
                 data={},
                 height=900,
                 width=1440,
                 datastructure=None):
        QApplication.__init__(self, sys.argv)

        if datastructure:

            i_k = datastructure.index_key()
            k_i = datastructure.index_key()
            data = {}

            data['vertices'] = {
                i: datastructure.vertex_coordinates(i_k[i])
                for i in range(datastructure.number_of_vertices())
            }

            data['edges'] = [{
                'u': k_i[u],
                'v': k_i[v]
            } for u, v in datastructure.edges()]

            data['fixed'] = [
                k_i[key] for key in datastructure.vertices()
                if datastructure.vertex[key].get('is_fixed')
            ]

            if datastructure.attributes['name'] == 'Mesh':
                data['faces'] = {
                    i: {
                        'vertices': datastructure.face[i]
                    }
                    for i in datastructure.faces()
                }

        self.camera_position = [10, -1, 10]
        self.camera_target = [0, 0, 0]
        self.show_axes = True
        self.vertex_size = 20.0
        self.vertex_scale = 0.001
        self.edge_width = 20.0
        self.edge_scale = 0.05

        self.name = name
        self.data = data
        self.height = height
        self.width = width
        self.keycallbacks = {}

        self.labels = {}
        self.listboxes = {}
        self.sliders = {}
        self.checkboxes = {}
Beispiel #3
0
    def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False, color_prefs=gprefs):
        self.file_event_hook = None
        if override_program_name:
            args = [override_program_name] + args[1:]
        if headless:
            if not args:
                args = sys.argv[:1]
            args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
        qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
        self.pi = plugins['progress_indicator'][0]
        QApplication.__init__(self, qargs)
        self.setup_styles(force_calibre_style)
        f = QFont(QApplication.font())
        if (f.family(), f.pointSize()) == ('Sans Serif', 9):  # Hard coded Qt settings, no user preference detected
            f.setPointSize(10)
            QApplication.setFont(f)
        f = QFontInfo(f)
        self.original_font = (f.family(), f.pointSize(), f.weight(), f.italic(), 100)
        if not self.using_calibre_style and self.style().objectName() == 'fusion':
            # Since Qt is using the fusion style anyway, specialize it
            self.load_calibre_style()
        fi = gprefs['font']
        if fi is not None:
            font = QFont(*(fi[:4]))
            s = gprefs.get('font_stretch', None)
            if s is not None:
                font.setStretch(s)
            QApplication.setFont(font)

        dl = QLocale(get_lang())
        if unicode(dl.bcp47Name()) != u'C':
            QLocale.setDefault(dl)
        global gui_thread, qt_app
        gui_thread = QThread.currentThread()
        self._translator = None
        self.load_translations()
        qt_app = self
        self._file_open_paths = []
        self._file_open_lock = RLock()

        if not isosx:
            # OS X uses a native color dialog that does not support custom
            # colors
            self.color_prefs = color_prefs
            self.read_custom_colors()
            self.lastWindowClosed.connect(self.save_custom_colors)

        if isxp:
            error_dialog(None, _('Windows XP not supported'), '<p>' + _(
                'calibre versions newer than 2.0 do not run on Windows XP. This is'
                ' because the graphics toolkit calibre uses (Qt 5) crashes a lot'
                ' on Windows XP. We suggest you stay with <a href="%s">calibre 1.48</a>'
                ' which works well on Windows XP.') % 'http://download.calibre-ebook.com/1.48.0/', show=True)
            raise SystemExit(1)
    def __init__(self, argv):
        QApplication.__init__(self, argv)
        self._dependency_container = DependencyContainer()
        self._garbage_collector = GarbageCollector(self)

        self._module_service = None
        self._message_board = None
        self._project_manager = None

        self._handling_exception = False

        sys.excepthook = self._handle_exception
Beispiel #5
0
    def __init__(self,
                 args,
                 force_calibre_style=False,
                 override_program_name=None,
                 headless=False):
        self.file_event_hook = None
        if override_program_name:
            args = [override_program_name] + args[1:]
        if headless:
            if not args:
                args = sys.argv[:1]
            args.extend([
                '-platformpluginpath', sys.extensions_location, '-platform',
                'headless'
            ])
        qargs = [
            i.encode('utf-8') if isinstance(i, unicode) else i for i in args
        ]
        self.pi = plugins['progress_indicator'][0]
        self.setup_styles(force_calibre_style)
        QApplication.__init__(self, qargs)
        f = QFont(QApplication.font())
        if (f.family(), f.pointSize()) == (
                'Sans Serif',
                9):  # Hard coded Qt settings, no user preference detected
            f.setPointSize(10)
            QApplication.setFont(f)
        f = QFontInfo(f)
        self.original_font = (f.family(), f.pointSize(), f.weight(),
                              f.italic(), 100)
        if not self.using_calibre_style and self.style().objectName(
        ) == 'fusion':
            # Since Qt is using the fusion style anyway, specialize it
            self.load_calibre_style()
        fi = gprefs['font']
        if fi is not None:
            font = QFont(*(fi[:4]))
            s = gprefs.get('font_stretch', None)
            if s is not None:
                font.setStretch(s)
            QApplication.setFont(font)

        dl = QLocale(get_lang())
        if unicode(dl.bcp47Name()) != u'C':
            QLocale.setDefault(dl)
        global gui_thread, qt_app
        gui_thread = QThread.currentThread()
        self._translator = None
        self.load_translations()
        qt_app = self
        self._file_open_paths = []
        self._file_open_lock = RLock()
Beispiel #6
0
    def __init__(self, master_password=None, urls=(), new_instance=False, shutdown=False, restart_state=None, no_session=False, run_local_server=True):
        if not isosx:  # OS X turns this on automatically
            for v in ('QT_AUTO_SCREEN_SCALE_FACTOR', 'QT_SCALE_FACTOR', 'QT_SCREEN_SCALE_FACTORS', 'QT_DEVICE_PIXEL_RATIO'):
                if os.environ.get(v):
                    break
            else:
                QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
        QApplication.__init__(self, [appname, '-name', appname])
        self.setAttribute(Qt.AA_UseHighDpiPixmaps)
        self.setOrganizationName('kovidgoyal')
        self.setApplicationName(appname)
        self.setApplicationVersion(str_version)
        self.no_session = no_session
        self.handle_unix_signals()
        if not QSslSocket.supportsSsl():
            raise SystemExit('Qt has been compiled without SSL support!')
        from .config import font_families, font_sizes
        ff = font_families().get('sans-serif') or 'default'
        if ff == 'default':
            ff = font_families().get('default') or 'default'
        f = self.font()
        if ff != 'default':
            f.setFamily(ff)
            fs = font_sizes().get('default-size')
            try:
                f.setPixelSize(int(fs))
            except Exception:
                pass
        self.setFont(f)
        self.password_loaded.connect(self.on_password_load, type=Qt.QueuedConnection)
        if master_password is not None:
            password_db.start_load(master_password, self.password_loaded.emit)
        elif restart_state and 'key' in restart_state:
            password_db.start_load(restart_state.pop('key'), self.password_loaded.emit, pw_is_key=True)

        self.lastWindowClosed.connect(self.shutdown)
        if run_local_server:
            self.run_local_server(urls, new_instance, shutdown)
        sys.excepthook = self.on_unhandled_error
        self.windows = []
        f = self.font()
        if (f.family(), f.pointSize()) == ('Sans Serif', 9):  # Hard coded Qt settings, no user preference detected
            f.setPointSize(10)
            if 'Ubuntu' in QFontDatabase().families():
                f.setFamily('Ubuntu')
            self.setFont(f)
        self.downloads = Downloads(self)
        self.disk_cache = create_favicon_cache()
        self.key_filter = KeyFilter(self)
        self.installEventFilter(self.key_filter)
Beispiel #7
0
    def __init__(self,
                 name='VTK Viewer',
                 data={},
                 height=900,
                 width=1440,
                 sidebar=120,
                 datastructure=None):
        QApplication.__init__(self, sys.argv)

        if datastructure:

            D = datastructure
            k_i = D.key_index()

            data = {}
            data['vertices'] = [
                D.vertex_coordinates(k_i[k]) for k in D.vertices()
            ]
            data['edges'] = [{
                'vertices': [k_i[u], k_i[v]]
            } for u, v in D.edges()]
            data['faces'] = []

            if D.attributes['name'] == 'Mesh':

                for fkey in D.faces():
                    face = [k_i[k] for k in D.face[fkey]]
                    data['faces'].append({'vertices': face})

        self.camera_position = [10, -1, 10]
        self.camera_target = [0, 0, 0]
        self.show_axes = True
        self.vertex_size = 20.0
        self.vertex_scale = 0.001
        self.edge_width = 20.0
        self.edge_scale = 0.05

        self.data = data
        self.height = height
        self.width = width
        self.sidebar_width = sidebar
        self.keycallbacks = {}

        self.checkboxes = {}
        self.labels = {}
        self.listboxes = {}
        self.sliders = {}
Beispiel #8
0
    def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False):
        self.file_event_hook = None
        if override_program_name:
            args = [override_program_name] + args[1:]
        if headless:
            if not args:
                args = sys.argv[:1]
            args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
        qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
        self.pi = plugins['progress_indicator'][0]
        self.setup_styles(force_calibre_style)
        QApplication.__init__(self, qargs)
        f = QFont(QApplication.font())
        if (f.family(), f.pointSize()) == ('Sans Serif', 9):  # Hard coded Qt settings, no user preference detected
            f.setPointSize(10)
            QApplication.setFont(f)
        f = QFontInfo(f)
        self.original_font = (f.family(), f.pointSize(), f.weight(), f.italic(), 100)
        if not self.using_calibre_style and self.style().objectName() == 'fusion':
            # Since Qt is using the fusion style anyway, specialize it
            self.load_calibre_style()
        fi = gprefs['font']
        if fi is not None:
            font = QFont(*(fi[:4]))
            s = gprefs.get('font_stretch', None)
            if s is not None:
                font.setStretch(s)
            QApplication.setFont(font)

        dl = QLocale(get_lang())
        if unicode(dl.bcp47Name()) != u'C':
            QLocale.setDefault(dl)
        global gui_thread, qt_app
        gui_thread = QThread.currentThread()
        self._translator = None
        self.load_translations()
        qt_app = self
        self._file_open_paths = []
        self._file_open_lock = RLock()
Beispiel #9
0
    def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False, color_prefs=gprefs):
        self.file_event_hook = None
        if override_program_name:
            args = [override_program_name] + args[1:]
        if headless:
            if not args:
                args = sys.argv[:1]
            args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
        self.headless = headless
        qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
        self.pi = plugins['progress_indicator'][0]
        QApplication.__init__(self, qargs)
        if islinux or isbsd:
            self.setAttribute(Qt.AA_DontUseNativeMenuBar, 'CALIBRE_NO_NATIVE_MENUBAR' in os.environ)
        self.setup_styles(force_calibre_style)
        f = QFont(QApplication.font())
        if (f.family(), f.pointSize()) == ('Sans Serif', 9):  # Hard coded Qt settings, no user preference detected
            f.setPointSize(10)
            QApplication.setFont(f)
        f = QFontInfo(f)
        self.original_font = (f.family(), f.pointSize(), f.weight(), f.italic(), 100)
        if not self.using_calibre_style and self.style().objectName() == 'fusion':
            # Since Qt is using the fusion style anyway, specialize it
            self.load_calibre_style()
        fi = gprefs['font']
        if fi is not None:
            font = QFont(*(fi[:4]))
            s = gprefs.get('font_stretch', None)
            if s is not None:
                font.setStretch(s)
            QApplication.setFont(font)

        dl = QLocale(get_lang())
        if unicode(dl.bcp47Name()) != u'C':
            QLocale.setDefault(dl)
        global gui_thread, qt_app
        gui_thread = QThread.currentThread()
        self._translator = None
        self.load_translations()
        qt_app = self
        self._file_open_paths = []
        self._file_open_lock = RLock()

        if not isosx:
            # OS X uses a native color dialog that does not support custom
            # colors
            self.color_prefs = color_prefs
            self.read_custom_colors()
            self.lastWindowClosed.connect(self.save_custom_colors)

        if isxp:
            error_dialog(None, _('Windows XP not supported'), '<p>' + _(
                'calibre versions newer than 2.0 do not run on Windows XP. This is'
                ' because the graphics toolkit calibre uses (Qt 5) crashes a lot'
                ' on Windows XP. We suggest you stay with <a href="%s">calibre 1.48</a>'
                ' which works well on Windows XP.') % 'http://download.calibre-ebook.com/1.48.0/', show=True)
            raise SystemExit(1)

        if iswindows:
            # On windows the highlighted colors for inactive widgets are the
            # same as non highlighted colors. This is a regression from Qt 4.
            # https://bugreports.qt-project.org/browse/QTBUG-41060
            p = self.palette()
            for role in (p.Highlight, p.HighlightedText, p.Base, p.AlternateBase):
                p.setColor(p.Inactive, role, p.color(p.Active, role))
            self.setPalette(p)

            # Prevent text copied to the clipboard from being lost on quit due to
            # Qt 5 bug: https://bugreports.qt-project.org/browse/QTBUG-41125
            self.aboutToQuit.connect(self.flush_clipboard)
Beispiel #10
0
    def __init__(self,
                 master_password=None,
                 urls=(),
                 new_instance=False,
                 shutdown=False,
                 restart_state=None,
                 no_session=False,
                 run_local_server=True):
        if not isosx:  # OS X turns this on automatically
            for v in ('QT_AUTO_SCREEN_SCALE_FACTOR', 'QT_SCALE_FACTOR',
                      'QT_SCREEN_SCALE_FACTORS', 'QT_DEVICE_PIXEL_RATIO'):
                if os.environ.get(v):
                    break
            else:
                QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
        QApplication.__init__(self, [appname, '-name', appname])
        self.setAttribute(Qt.AA_UseHighDpiPixmaps)
        self.setOrganizationName('kovidgoyal')
        self.setApplicationName(appname)
        self.setApplicationVersion(str_version)
        self.no_session = no_session
        self.handle_unix_signals()
        if not QSslSocket.supportsSsl():
            raise SystemExit('Qt has been compiled without SSL support!')
        from .config import font_families, font_sizes
        ff = font_families().get('sans-serif') or 'default'
        if ff == 'default':
            ff = font_families().get('default') or 'default'
        f = self.font()
        if ff != 'default':
            f.setFamily(ff)
            fs = font_sizes().get('default-size')
            try:
                f.setPixelSize(int(fs))
            except Exception:
                pass
        self.setFont(f)
        self.password_loaded.connect(self.on_password_load,
                                     type=Qt.QueuedConnection)
        if master_password is not None:
            password_db.start_load(master_password, self.password_loaded.emit)
        elif restart_state and 'key' in restart_state:
            password_db.start_load(restart_state.pop('key'),
                                   self.password_loaded.emit,
                                   pw_is_key=True)

        self.lastWindowClosed.connect(self.shutdown)
        if run_local_server:
            self.run_local_server(urls, new_instance, shutdown)
        sys.excepthook = self.on_unhandled_error
        self.windows = []
        f = self.font()
        if (f.family(), f.pointSize()) == (
                'Sans Serif',
                9):  # Hard coded Qt settings, no user preference detected
            f.setPointSize(10)
            if 'Ubuntu' in QFontDatabase().families():
                f.setFamily('Ubuntu')
            self.setFont(f)
        self.downloads = Downloads(self)
        self.disk_cache = create_favicon_cache()
        self.key_filter = KeyFilter(self)
        self.installEventFilter(self.key_filter)
Beispiel #11
0
    def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False, color_prefs=gprefs):
        self.file_event_hook = None
        if override_program_name:
            args = [override_program_name] + args[1:]
        if headless:
            if not args:
                args = sys.argv[:1]
            args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
        self.headless = headless
        qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
        self.pi = plugins['progress_indicator'][0]
        if not isosx and not headless:
            # On OS X high dpi scaling is turned on automatically by the OS, so we dont need to set it explicitly
            setup_hidpi()
        QApplication.setOrganizationName('calibre-ebook.com')
        QApplication.setOrganizationDomain(QApplication.organizationName())
        QApplication.setApplicationVersion(__version__)
        QApplication.setApplicationName(APP_UID)
        QApplication.__init__(self, qargs)
        self.setAttribute(Qt.AA_UseHighDpiPixmaps)
        self.setAttribute(Qt.AA_SynthesizeTouchForUnhandledMouseEvents, False)
        try:
            base_dir()
        except EnvironmentError as err:
            if not headless:
                show_temp_dir_error(err)
            raise SystemExit('Failed to create temporary directory')
        if DEBUG and not headless:
            prints('devicePixelRatio:', self.devicePixelRatio())
            s = self.primaryScreen()
            if s:
                prints('logicalDpi:', s.logicalDotsPerInchX(), 'x', s.logicalDotsPerInchY())
                prints('physicalDpi:', s.physicalDotsPerInchX(), 'x', s.physicalDotsPerInchY())
        if not iswindows:
            self.setup_unix_signals()
        if islinux or isbsd:
            self.setAttribute(Qt.AA_DontUseNativeMenuBar, 'CALIBRE_NO_NATIVE_MENUBAR' in os.environ)
        self.setup_styles(force_calibre_style)
        self.setup_ui_font()
        if not self.using_calibre_style and self.style().objectName() == 'fusion':
            # Since Qt is using the fusion style anyway, specialize it
            self.load_calibre_style()
        fi = gprefs['font']
        if fi is not None:
            font = QFont(*(fi[:4]))
            s = gprefs.get('font_stretch', None)
            if s is not None:
                font.setStretch(s)
            QApplication.setFont(font)
        self.line_height = max(12, QFontMetrics(self.font()).lineSpacing())

        dl = QLocale(get_lang())
        if unicode(dl.bcp47Name()) != u'C':
            QLocale.setDefault(dl)
        global gui_thread, qt_app
        gui_thread = QThread.currentThread()
        self._translator = None
        self.load_translations()
        qt_app = self
        self._file_open_paths = []
        self._file_open_lock = RLock()

        if not isosx:
            # OS X uses a native color dialog that does not support custom
            # colors
            self.color_prefs = color_prefs
            self.read_custom_colors()
            self.lastWindowClosed.connect(self.save_custom_colors)

        if isxp:
            error_dialog(None, _('Windows XP not supported'), '<p>' + _(
                'calibre versions newer than 2.0 do not run on Windows XP. This is'
                ' because the graphics toolkit calibre uses (Qt 5) crashes a lot'
                ' on Windows XP. We suggest you stay with <a href="%s">calibre 1.48</a>'
                ' which works well on Windows XP.') % 'http://download.calibre-ebook.com/1.48.0/', show=True)
            raise SystemExit(1)

        if iswindows:
            # On windows the highlighted colors for inactive widgets are the
            # same as non highlighted colors. This is a regression from Qt 4.
            # https://bugreports.qt-project.org/browse/QTBUG-41060
            p = self.palette()
            for role in (p.Highlight, p.HighlightedText, p.Base, p.AlternateBase):
                p.setColor(p.Inactive, role, p.color(p.Active, role))
            self.setPalette(p)

            # Prevent text copied to the clipboard from being lost on quit due to
            # Qt 5 bug: https://bugreports.qt-project.org/browse/QTBUG-41125
            self.aboutToQuit.connect(self.flush_clipboard)