Esempio n. 1
0
    def setup_store_checks(self):
        first_run = self.config.get('first_run', True)

        # Add check boxes for each store so the user
        # can disable searching specific stores on a
        # per search basis.
        existing = {}
        for n in self.store_checks:
            existing[n] = self.store_checks[n].isChecked()

        self.store_checks = {}

        stores_check_widget = QWidget()
        store_list_layout = QGridLayout()
        stores_check_widget.setLayout(store_list_layout)

        icon = QIcon(I('donate.png'))
        for i, x in enumerate(sorted(self.gui.istores.keys(), key=lambda x: x.lower())):
            cbox = QCheckBox(x)
            cbox.setChecked(existing.get(x, first_run))
            store_list_layout.addWidget(cbox, i, 0, 1, 1)
            if self.gui.istores[x].base_plugin.affiliate:
                iw = QLabel(self)
                iw.setToolTip('<p>' + _('Buying from this store supports the calibre developer: %s</p>') % self.gui.istores[x].base_plugin.author + '</p>')
                iw.setPixmap(icon.pixmap(16, 16))
                store_list_layout.addWidget(iw, i, 1, 1, 1)
            self.store_checks[x] = cbox
        store_list_layout.setRowStretch(store_list_layout.rowCount(), 10)
        self.store_list.setWidget(stores_check_widget)

        self.config['first_run'] = False
Esempio n. 2
0
    def setup_store_checks(self):
        first_run = self.config.get('first_run', True)

        # Add check boxes for each store so the user
        # can disable searching specific stores on a
        # per search basis.
        existing = {}
        for n in self.store_checks:
            existing[n] = self.store_checks[n].isChecked()

        self.store_checks = {}

        stores_check_widget = QWidget()
        store_list_layout = QGridLayout()
        stores_check_widget.setLayout(store_list_layout)

        icon = QIcon(I('donate.png'))
        for i, x in enumerate(
                sorted(self.gui.istores.keys(), key=lambda x: x.lower())):
            cbox = QCheckBox(x)
            cbox.setChecked(existing.get(x, first_run))
            store_list_layout.addWidget(cbox, i, 0, 1, 1)
            if self.gui.istores[x].base_plugin.affiliate:
                iw = QLabel(self)
                iw.setToolTip('<p>' + _(
                    'Buying from this store supports the calibre developer: %s</p>'
                ) % self.gui.istores[x].base_plugin.author + '</p>')
                iw.setPixmap(icon.pixmap(16, 16))
                store_list_layout.addWidget(iw, i, 1, 1, 1)
            self.store_checks[x] = cbox
        store_list_layout.setRowStretch(store_list_layout.rowCount(), 10)
        self.store_list.setWidget(stores_check_widget)

        self.config['first_run'] = False
    def __init__(self, gui, existing_names, editing=None):
        QDialog.__init__(self, gui)

        self.gui = gui
        self.existing_names = existing_names

        if editing:
            self.setWindowTitle(_('Edit virtual library'))
        else:
            self.setWindowTitle(_('Create virtual library'))
        self.setWindowIcon(QIcon(I('lt.png')))

        gl = QGridLayout()
        self.setLayout(gl)
        self.la1 = la1 = QLabel(_('Virtual library &name:'))
        gl.addWidget(la1, 0, 0)
        self.vl_name = QComboBox()
        self.vl_name.setEditable(True)
        self.vl_name.lineEdit().setMaxLength(MAX_VIRTUAL_LIBRARY_NAME_LENGTH)
        la1.setBuddy(self.vl_name)
        gl.addWidget(self.vl_name, 0, 1)
        self.editing = editing

        self.saved_searches_label = QLabel('')
        self.saved_searches_label.setTextInteractionFlags(Qt.TextSelectableByMouse)
        gl.addWidget(self.saved_searches_label, 2, 0, 1, 2)

        self.la2 = la2 = QLabel(_('&Search expression:'))
        gl.addWidget(la2, 1, 0)
        self.vl_text = QLineEdit()
        self.vl_text.textChanged.connect(self.search_text_changed)
        la2.setBuddy(self.vl_text)
        gl.addWidget(self.vl_text, 1, 1)
        self.vl_text.setText(_build_full_search_string(self.gui))

        self.sl = sl = QLabel('<p>'+_('Create a virtual library based on: ')+
            ('<a href="author.{0}">{0}</a>, '
            '<a href="tag.{1}">{1}</a>, '
            '<a href="publisher.{2}">{2}</a>, '
            '<a href="series.{3}">{3}</a>, '
            '<a href="search.{4}">{4}</a>.').format(_('Authors'), _('Tags'),
                                            _('Publishers'), _('Series'), _('Saved Searches')))
        sl.setWordWrap(True)
        sl.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
        sl.linkActivated.connect(self.link_activated)
        gl.addWidget(sl, 3, 0, 1, 2)
        gl.setRowStretch(3,10)

        self.hl = hl = QLabel(_('''
            <h2>Virtual Libraries</h2>

            <p>Using <i>virtual libraries</i> you can restrict calibre to only show
            you books that match a search. When a virtual library is in effect, calibre
            behaves as though the library contains only the matched books. The Tag Browser
            display only the tags/authors/series/etc. that belong to the matched books and any searches
            you do will only search within the books in the virtual library. This
            is a good way to partition your large library into smaller and easier to work with subsets.</p>

            <p>For example you can use a Virtual Library to only show you books with the Tag <i>"Unread"</i>
            or only books by <i>"My Favorite Author"</i> or only books in a particular series.</p>

            <p>More information and examples are available in the
            <a href="http://manual.calibre-ebook.com/virtual_libraries.html">User Manual</a>.</p>
            '''))
        hl.setWordWrap(True)
        hl.setOpenExternalLinks(True)
        hl.setFrameStyle(hl.StyledPanel)
        gl.addWidget(hl, 0, 3, 4, 1)

        bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        bb.accepted.connect(self.accept)
        bb.rejected.connect(self.reject)
        gl.addWidget(bb, 4, 0, 1, 0)

        if editing:
            db = self.gui.current_db
            virt_libs = db.prefs.get('virtual_libraries', {})
            for dex,vl in enumerate(sorted(virt_libs.keys(), key=sort_key)):
                self.vl_name.addItem(vl, virt_libs.get(vl, ''))
                if vl == editing:
                    self.vl_name.setCurrentIndex(dex)
                    self.original_index = dex
            self.original_search = virt_libs.get(editing, '')
            self.vl_text.setText(self.original_search)
            self.new_name = editing
            self.vl_name.currentIndexChanged[int].connect(self.name_index_changed)
            self.vl_name.lineEdit().textEdited.connect(self.name_text_edited)

        self.resize(self.sizeHint()+QSize(150, 25))
Esempio n. 4
0
    def __init__(self, gui, existing_names, editing=None):
        QDialog.__init__(self, gui)

        self.gui = gui
        self.existing_names = existing_names

        if editing:
            self.setWindowTitle(_('Edit virtual library'))
        else:
            self.setWindowTitle(_('Create virtual library'))
        self.setWindowIcon(QIcon(I('lt.png')))

        gl = QGridLayout()
        self.setLayout(gl)
        self.la1 = la1 = QLabel(_('Virtual library &name:'))
        gl.addWidget(la1, 0, 0)
        self.vl_name = QComboBox()
        self.vl_name.setEditable(True)
        self.vl_name.lineEdit().setMaxLength(MAX_VIRTUAL_LIBRARY_NAME_LENGTH)
        la1.setBuddy(self.vl_name)
        gl.addWidget(self.vl_name, 0, 1)
        self.editing = editing

        self.saved_searches_label = QLabel('')
        self.saved_searches_label.setTextInteractionFlags(
            Qt.TextSelectableByMouse)
        gl.addWidget(self.saved_searches_label, 2, 0, 1, 2)

        self.la2 = la2 = QLabel(_('&Search expression:'))
        gl.addWidget(la2, 1, 0)
        self.vl_text = QLineEdit()
        self.vl_text.textChanged.connect(self.search_text_changed)
        la2.setBuddy(self.vl_text)
        gl.addWidget(self.vl_text, 1, 1)
        self.vl_text.setText(_build_full_search_string(self.gui))

        self.sl = sl = QLabel(
            '<p>' + _('Create a virtual library based on: ') +
            ('<a href="author.{0}">{0}</a>, '
             '<a href="tag.{1}">{1}</a>, '
             '<a href="publisher.{2}">{2}</a>, '
             '<a href="series.{3}">{3}</a>, '
             '<a href="search.{4}">{4}</a>.').format(_('Authors'), _(
                 'Tags'), _('Publishers'), _('Series'), _('Saved Searches')))
        sl.setWordWrap(True)
        sl.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
        sl.linkActivated.connect(self.link_activated)
        gl.addWidget(sl, 3, 0, 1, 2)
        gl.setRowStretch(3, 10)

        self.hl = hl = QLabel(
            _('''
            <h2>Virtual Libraries</h2>

            <p>Using <i>virtual libraries</i> you can restrict calibre to only show
            you books that match a search. When a virtual library is in effect, calibre
            behaves as though the library contains only the matched books. The Tag Browser
            display only the tags/authors/series/etc. that belong to the matched books and any searches
            you do will only search within the books in the virtual library. This
            is a good way to partition your large library into smaller and easier to work with subsets.</p>

            <p>For example you can use a Virtual Library to only show you books with the Tag <i>"Unread"</i>
            or only books by <i>"My Favorite Author"</i> or only books in a particular series.</p>

            <p>More information and examples are available in the
            <a href="http://manual.calibre-ebook.com/virtual_libraries.html">User Manual</a>.</p>
            '''))
        hl.setWordWrap(True)
        hl.setOpenExternalLinks(True)
        hl.setFrameStyle(hl.StyledPanel)
        gl.addWidget(hl, 0, 3, 4, 1)

        bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        bb.accepted.connect(self.accept)
        bb.rejected.connect(self.reject)
        gl.addWidget(bb, 4, 0, 1, 0)

        if editing:
            db = self.gui.current_db
            virt_libs = db.prefs.get('virtual_libraries', {})
            for dex, vl in enumerate(sorted(virt_libs.keys(), key=sort_key)):
                self.vl_name.addItem(vl, virt_libs.get(vl, ''))
                if vl == editing:
                    self.vl_name.setCurrentIndex(dex)
                    self.original_index = dex
            self.original_search = virt_libs.get(editing, '')
            self.vl_text.setText(self.original_search)
            self.new_name = editing
            self.vl_name.currentIndexChanged[int].connect(
                self.name_index_changed)
            self.vl_name.lineEdit().textEdited.connect(self.name_text_edited)

        self.resize(self.sizeHint() + QSize(150, 25))
Esempio n. 5
0
class FtcGuiApplication(TouchApplication):
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # create the empty main window
        self.w = TouchWindow("Run JetsonEV")

        self.relative_path = os.path.dirname(os.path.realpath(__file__))
        self.script = os.path.join(self.relative_path, 'Run_car.py')
        self.grid = QGridLayout()
        self.grid.setSpacing(0)
        self.process = QProcess()
        self.process.readyReadStandardOutput.connect(self.stdoutReady)
        self.process.readyReadStandardError.connect(self.stderrReady)

        self.play_btn = ShadowButton(os.path.join(self.relative_path, 'start'))
        self.play_btn.setText("Start")
        self.play_btn.clicked.connect(self.start_script)
        self.grid.addWidget(self.play_btn, 0, 0, 1, 1)
        self.grid.setColumnStretch(0, 1.25)

        self.imu_box = QCheckBox('IMU')
        self.imu_box.setChecked(True)
        self.camera_box = QCheckBox('Cam')
        self.camera_box.setChecked(False)
        self.lidar_box = QCheckBox('Lidar')
        self.lidar_box.setChecked(False)
        self.grid.addWidget(self.imu_box, 0, 1, 1, 1)
        self.grid.setColumnStretch(1, 1)
        self.grid.addWidget(self.camera_box, 0, 2, 1, 1)
        self.grid.setColumnStretch(2, 1)
        self.grid.addWidget(self.lidar_box, 0, 3, 1, 1)
        self.grid.setColumnStretch(3, 1.5)
        self.grid.setAlignment(Qt.AlignCenter)

        self.stop_btn = ShadowButton(os.path.join(self.relative_path, 'stop'))
        self.stop_btn.setText("Stop")
        self.stop_btn.clicked.connect(self.stop_script)
        self.grid.addWidget(self.stop_btn, 0, 4, 1, 1)
        self.grid.setRowStretch(1, 4)

        self.console_output = QPlainTextEdit()
        self.console_output.setReadOnly(True)
        console_style = "QPlainTextEdit {" \
                        "background-color: black;" \
                        "color: white;" \
                        "}"
        self.console_output.setFocusPolicy(Qt.NoFocus)
        self.console_output.setFrameStyle(3)
        self.console_output.setStyleSheet(console_style)

        self.grid.addWidget(self.console_output, 1, 0, 1, 5)

        self.w.centralWidget.setLayout(self.grid)
        self.w.centralWidget.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.w.centralWidget, event)
        self.w.centralWidget.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.w.centralWidget, event)
        self.w.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.w, event)
        self.w.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.w, event)
        self.play_btn.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.play_btn, event)
        self.play_btn.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.play_btn, event)
        self.stop_btn.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.stop_btn, event)
        self.stop_btn.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.stop_btn, event)

        self.imu_box.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.imu_box, event)
        self.imu_box.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.imu_box, event)
        self.camera_box.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.camera_box, event)
        self.camera_box.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.camera_box, event)
        self.lidar_box.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.lidar_box, event)
        self.lidar_box.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.lidar_box, event)

        self.xbox_controller = XBoxInput()
        self.xbox_controller.cycle_right.connect(self.cycle_right)
        self.xbox_controller.cycle_left.connect(self.cycle_left)

        self.speed_widget = SpeedWidget()
        self.grid.addWidget(self.speed_widget, 1, 0, 1, 5)
        self.speed_widget.hide()

        self.imu_widget = IMUWidget()
        self.grid.addWidget(self.imu_widget, 1, 0, 1, 5)
        self.imu_widget.hide()

        self.camera_widget = VideoWidget()
        self.grid.addWidget(self.camera_widget, 1, 0, 1, 5)
        self.camera_widget.hide()

        self.lidar_widget = LidarWidget()
        self.grid.addWidget(self.lidar_widget, 1, 0, 1, 5)
        self.lidar_widget.hide()

        self.widgets_to_show = []
        self.show_widget_index = 0
        self.w.show()
        self.aboutToQuit.connect(self.xbox_controller.xbox_controller.close)
        self.exec_()

    def cycle_right(self, axis):
        last_index = self.show_widget_index
        self.show_widget_index += 1
        if self.show_widget_index >= len(self.widgets_to_show):
            self.show_widget_index = 0
        self.widgets_to_show[last_index].hide()
        self.widgets_to_show[self.show_widget_index].show()

    def cycle_left(self, axis):
        last_index = self.show_widget_index
        self.show_widget_index -= 1
        if self.show_widget_index < 0:
            self.show_widget_index = len(self.widgets_to_show) - 1
        self.widgets_to_show[last_index].hide()
        self.widgets_to_show[self.show_widget_index].show()

    def start_script(self):
        self.widgets_to_show = [self.console_output, self.speed_widget]
        flags = ['-u', self.script]
        self.speed_widget.start(port=4021)

        if self.imu_box.isChecked():
            print('starting imu socket')
            self.imu_widget.start(port=9009)
            self.widgets_to_show.append(self.imu_widget)
            flags.extend(['--enable-imu'])
        if self.lidar_box.isChecked():
            print('starting lidar socket')
            self.lidar_widget.start(port=9010)
            self.widgets_to_show.append(self.lidar_widget)
            flags.extend(['--enable-lidar'])
        if self.camera_box.isChecked():
            print('starting camera socket')
            self.camera_widget.start(port=9011)
            self.widgets_to_show.append(self.camera_widget)
            flags.extend(['--enable-camera'])
        self.process.start('python3', flags)

    def stop_script(self):
        self.imu_widget.shutdown()
        self.camera_widget.shutdown()
        self.lidar_widget.shutdown()
        self.speed_widget.shutdown()
        self.process.terminate()

    def fwd_output(self, text):
        self.console_output.appendPlainText(text)
        cursor = self.console_output.textCursor()
        cursor.movePosition(cursor.End)

    def stdoutReady(self):
        text = str(self.process.readAllStandardOutput(), encoding='utf8')
        self.fwd_output(text)

    def stderrReady(self):
        text = str(self.process.readAllStandardError(), encoding='utf8')
        self.fwd_output(text)

    def filter_out_arrow_release_keys(self, widget, event):
        if event.key() == Qt.Key_Up:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepSub)
        elif event.key() == Qt.Key_Down:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepAdd)
        else:
            type(widget).keyReleaseEvent(widget, event)

    def filter_out_arrow_press_keys(self, widget, event):
        if event.key() == Qt.Key_Up:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepSub)
        elif event.key() == Qt.Key_Down:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepAdd)
        else:
            type(widget).keyPressEvent(widget, event)
Esempio n. 6
0
class FtcGuiApplication(TouchApplication):
    def __init__(self, args):
        TouchApplication.__init__(self, args)
        self.script_directory = '/home/isys/git/JetsonEV-scripts'

        # create the empty main window
        self.w = TouchWindow("Run Python Script")

        self.relative_path = os.path.dirname(os.path.realpath(__file__))
        self.grid = QGridLayout()
        environment = QProcessEnvironment()
        environment.insert('PYTHONPATH', self.script_directory)
        self.process = QProcess()
        self.process.setProcessEnvironment(environment)
        self.process.readyReadStandardOutput.connect(self.stdoutReady)
        self.process.readyReadStandardError.connect(self.stderrReady)

        self.play_btn = ShadowButton(os.path.join(self.relative_path, 'start'))
        self.play_btn.setText("Start")
        self.play_btn.clicked.connect(self.start_script)
        self.grid.addWidget(self.play_btn, 0, 0, 1, 1)

        self.script_selector = QComboBox()
        self.scan_scripts()
        self.grid.addWidget(self.script_selector, 0, 1, 1, 3)
        self.grid.setColumnStretch(1, 1.5)

        self.grid.setAlignment(Qt.AlignCenter)

        self.stop_btn = ShadowButton(os.path.join(self.relative_path, 'stop'))
        self.stop_btn.setText("Stop")
        self.stop_btn.clicked.connect(self.stop_script)
        self.grid.addWidget(self.stop_btn, 0, 4, 1, 1)
        self.grid.setRowStretch(1, 4)

        self.console_output = QPlainTextEdit()
        self.console_output.setReadOnly(True)
        console_style = "QPlainTextEdit {" \
                        "background-color: black;" \
                        "color: white;" \
                        "}"
        self.console_output.setFocusPolicy(Qt.NoFocus)
        self.console_output.setFrameStyle(3)
        self.console_output.setStyleSheet(console_style)

        self.grid.addWidget(self.console_output, 1, 0, 1, 5)

        self.w.centralWidget.setLayout(self.grid)
        self.w.centralWidget.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.w.centralWidget, event)
        self.w.centralWidget.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.w.centralWidget, event)
        self.w.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.w, event)
        self.w.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.w, event)

        self.play_btn.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.play_btn, event)
        self.play_btn.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.play_btn, event)
        self.stop_btn.keyReleaseEvent = lambda event: self.filter_out_arrow_release_keys(
            self.stop_btn, event)
        self.stop_btn.keyPressEvent = lambda event: self.filter_out_arrow_press_keys(
            self.stop_btn, event)

        self.w.show()
        self.exec_()

    def scan_scripts(self):
        self.script_selector.clear()

        for script in os.listdir(self.script_directory):
            if os.path.isfile(os.path.join(self.script_directory, script)):
                if script[-3:] == '.py':
                    self.script_selector.addItem(script[:-3])

    def start_script(self):
        flags = [
            '-u',
            os.path.join(self.script_directory,
                         self.script_selector.currentText() + '.py')
        ]
        self.process.start('python3', flags)

    def stop_script(self):
        self.process.terminate()

    def fwd_output(self, text):
        self.console_output.appendPlainText(text)
        cursor = self.console_output.textCursor()
        cursor.movePosition(cursor.End)

    def stdoutReady(self):
        text = str(self.process.readAllStandardOutput(), encoding='utf8')
        self.fwd_output(text)

    def stderrReady(self):
        text = str(self.process.readAllStandardError(), encoding='utf8')
        self.fwd_output(text)

    def filter_out_arrow_release_keys(self, widget, event):
        if event.key() == Qt.Key_Up:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepSub)
        elif event.key() == Qt.Key_Down:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepAdd)
        else:
            type(widget).keyReleaseEvent(widget, event)

    def filter_out_arrow_press_keys(self, widget, event):
        if event.key() == Qt.Key_Up:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepSub)
        elif event.key() == Qt.Key_Down:
            self.console_output.verticalScrollBar().triggerAction(
                QAbstractSlider.SliderSingleStepAdd)
        else:
            type(widget).keyPressEvent(widget, event)