예제 #1
0
    def make_signal_labels(self, prefix):
        self._prefix = prefix
        # `in_data[, ]`
        for i, signal in enumerate(OWPythonScript.signal_names):
            # adding an empty b tag like this adjusts the
            # line height to match the rest of the labels
            signal_display_name = signal
            signal_lbl = QLabel('<b></b>' + prefix + signal_display_name, self)
            signal_lbl.setFont(self.font())
            signal_lbl.setContentsMargins(0, 0, 0, 0)
            self.layout().addWidget(signal_lbl)

            self.signal_labels[signal] = signal_lbl

            if i >= len(OWPythonScript.signal_names) - 1:
                break

            comma_lbl = QLabel(', ')
            comma_lbl.setFont(self.font())
            comma_lbl.setContentsMargins(0, 0, 0, 0)
            comma_lbl.setStyleSheet(
                '.QLabel { color: ' +
                self.highlighting_scheme[Punctuation].split(' ')[-1] + '; }')
            self.layout().addWidget(comma_lbl)
예제 #2
0
class PreprocessorModule(gui.OWComponent, QWidget):
    """The base widget for the pre-processing modules."""

    change_signal = pyqtSignal()  # Emitted when the settings are changed.
    title = NotImplemented
    attribute = NotImplemented
    methods = NotImplemented
    single_method = True
    toggle_enabled = True
    enabled = settings.Setting(True)
    disabled_value = None
    Layout = QGridLayout

    def __init__(self, master):
        QWidget.__init__(self)
        gui.OWComponent.__init__(self, master)
        self.master = master

        # Title bar.
        title_holder = QWidget()
        title_holder.setSizePolicy(QSizePolicy.MinimumExpanding,
                                   QSizePolicy.Fixed)
        title_holder.setStyleSheet("""
        .QWidget {
        background: qlineargradient( x1:0 y1:0, x2:0 y2:1,
        stop:0 #F8F8F8, stop:1 #C8C8C8);
        border-bottom: 1px solid #B3B3B3;
        }
        """)
        self.titleArea = QHBoxLayout()
        self.titleArea.setContentsMargins(10, 5, 10, 5)
        self.titleArea.setSpacing(0)
        title_holder.setLayout(self.titleArea)

        self.title_label = QLabel(self.title)
        self.title_label.mouseDoubleClickEvent = self.on_toggle
        self.title_label.setStyleSheet(
            'font-size: 12px; border: 2px solid red;')
        self.titleArea.addWidget(self.title_label)

        self.off_label = QLabel('[disabled]')
        self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;')
        self.titleArea.addWidget(self.off_label)
        self.off_label.hide()

        self.titleArea.addStretch()

        # Root.
        self.rootArea = QVBoxLayout()
        self.rootArea.setContentsMargins(0, 0, 0, 0)
        self.rootArea.setSpacing(0)
        self.setLayout(self.rootArea)
        self.rootArea.addWidget(title_holder)

        self.contents = QWidget()
        contentArea = QVBoxLayout()
        contentArea.setContentsMargins(15, 10, 15, 10)
        self.contents.setLayout(contentArea)
        self.rootArea.addWidget(self.contents)

        self.method_layout = self.Layout()
        self.setup_method_layout()
        self.contents.layout().addLayout(self.method_layout)

        if self.toggle_enabled:
            self.on_off_button = OnOffButton(enabled=self.enabled)
            self.on_off_button.stateChanged.connect(self.on_toggle)
            self.on_off_button.setContentsMargins(0, 0, 0, 0)
            self.titleArea.addWidget(self.on_off_button)
            self.display_widget()

    @staticmethod
    def get_tooltip(method):
        return ' '.join([l.strip() for l in method.__doc__.split('\n')]).strip('.') \
            if method.__doc__ else None

    @staticmethod
    def textify(text):
        return text.replace('&', '&&')

    @property
    def value(self):
        if self.enabled:
            return self.get_value()
        return self.disabled_value

    def setup_method_layout(self):
        raise NotImplementedError

    def on_toggle(self, event=None):
        # Activated when the widget is enabled/disabled.
        self.enabled = not self.enabled
        self.display_widget()
        self.update_value()

    def display_widget(self):
        if self.enabled:
            self.off_label.hide()
            self.contents.show()
            self.title_label.setStyleSheet('color: #000000;')
        else:
            self.off_label.show()
            self.contents.hide()
            self.title_label.setStyleSheet('color: #B0B0B0;')

    def get_value(self):
        raise NotImplemented

    def update_value(self):
        self.change_signal.emit()
예제 #3
0
class SignInForm(QDialog):
    def __init__(self, flags, *args, **kwargs):
        super().__init__(flags, *args, **kwargs)
        self.cm: CredentialManager = CredentialManager(CREDENTIAL_MANAGER_SERVICE)

        self.setWindowTitle('Sign in')
        self.setFixedSize(400, 250)

        self.server_cb_label = QLabel('Server *')
        self.server_cb = QComboBox(self)
        self.server_cb.addItems(RESOLWE_URLS)
        self.server_cb.setEditable(True)

        self.username_label = QLabel('Username *')
        self.username_line_edit = QLineEdit(self)
        self.username_line_edit.setPlaceholderText('Enter correct username')
        self.username_line_edit.returnPressed.connect(self.sign_in)
        self.username_line_edit.textChanged.connect(self.handle_sign_in_btn)

        self.password_label = QLabel('Password *')
        self.password_line_edit = QLineEdit(self)
        self.password_line_edit.setPlaceholderText('Enter correct password')
        self.password_line_edit.returnPressed.connect(self.sign_in)
        self.password_line_edit.textChanged.connect(self.handle_sign_in_btn)
        self.password_line_edit.setEchoMode(QLineEdit.Password)

        self.sign_in_btn = QPushButton('Sign in', self)
        self.sign_in_btn.setDisabled(True)
        self.sign_in_btn.clicked.connect(self.sign_in)

        self.error_msg = QLabel('Unable to log in with provided credentials.')
        self.error_msg.setStyleSheet('color:red')
        self.error_msg.hide()

        layout = QVBoxLayout(self)
        layout.addWidget(self.server_cb_label)
        layout.addWidget(self.server_cb)
        layout.addWidget(self.username_label)
        layout.addWidget(self.username_line_edit)
        layout.addWidget(self.password_label)
        layout.addWidget(self.password_line_edit)
        layout.addWidget(self.error_msg)
        layout.addStretch()
        layout.addWidget(self.sign_in_btn)

        self.resolwe_instance = None

    def handle_sign_in_btn(self):
        self.sign_in_btn.setEnabled(
            True if self.username_line_edit.text() and self.password_line_edit.text() else False
        )

    def sign_in(self):
        self.server_cb_label.setStyleSheet(None)
        self.username_label.setStyleSheet(None)
        self.password_label.setStyleSheet(None)
        self.error_msg.hide()

        server = self.server_cb.currentText()
        username = self.cm.username if self.cm.username else self.username_line_edit.text()
        password = self.cm.password if self.cm.password else self.password_line_edit.text()

        if not server:
            self.server_cb_label.setStyleSheet('color:red')
            return

        if not username:
            self.username_label.setStyleSheet('color:red')
            return

        if not password:
            self.password_label.setStyleSheet('color:red')
            return

        try:
            self.resolwe_instance = connect(username, password, url=server)
        except ResolweAuthException:
            self.error_msg.show()
            return

        self.cm.username = username
        self.cm.password = password
        self.accept()
예제 #4
0
class PreprocessorModule(gui.OWComponent, QWidget):
    """The base widget for the pre-processing modules."""

    change_signal = pyqtSignal()  # Emitted when the settings are changed.
    title = NotImplemented
    attribute = NotImplemented
    methods = NotImplemented
    single_method = True
    toggle_enabled = True
    enabled = settings.Setting(True)
    disabled_value = None
    Layout = QGridLayout

    def __init__(self, master):
        QWidget.__init__(self)
        gui.OWComponent.__init__(self, master)
        self.master = master

        # Title bar.
        title_holder = QWidget()
        title_holder.setSizePolicy(QSizePolicy.MinimumExpanding,
                                   QSizePolicy.Fixed)
        title_holder.setStyleSheet("""
        .QWidget {
        background: qlineargradient( x1:0 y1:0, x2:0 y2:1,
        stop:0 #F8F8F8, stop:1 #C8C8C8);
        border-bottom: 1px solid #B3B3B3;
        }
        """)
        self.titleArea = QHBoxLayout()
        self.titleArea.setContentsMargins(10, 5, 10, 5)
        self.titleArea.setSpacing(0)
        title_holder.setLayout(self.titleArea)

        self.title_label = QLabel(self.title)
        self.title_label.mouseDoubleClickEvent = self.on_toggle
        self.title_label.setStyleSheet('font-size: 12px; border: 2px solid red;')
        self.titleArea.addWidget(self.title_label)

        self.off_label = QLabel('[disabled]')
        self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;')
        self.titleArea.addWidget(self.off_label)
        self.off_label.hide()

        self.titleArea.addStretch()

        # Root.
        self.rootArea = QVBoxLayout()
        self.rootArea.setContentsMargins(0, 0, 0, 0)
        self.rootArea.setSpacing(0)
        self.setLayout(self.rootArea)
        self.rootArea.addWidget(title_holder)

        self.contents = QWidget()
        contentArea = QVBoxLayout()
        contentArea.setContentsMargins(15, 10, 15, 10)
        self.contents.setLayout(contentArea)
        self.rootArea.addWidget(self.contents)

        self.method_layout = self.Layout()
        self.setup_method_layout()
        self.contents.layout().addLayout(self.method_layout)

        if self.toggle_enabled:
            self.on_off_button = OnOffButton(enabled=self.enabled)
            self.on_off_button.stateChanged.connect(self.on_toggle)
            self.on_off_button.setContentsMargins(0, 0, 0, 0)
            self.titleArea.addWidget(self.on_off_button)
            self.display_widget()

    @staticmethod
    def get_tooltip(method):
        return ' '.join([l.strip() for l in method.__doc__.split('\n')]).strip('.') \
            if method.__doc__ else None

    @staticmethod
    def textify(text):
        return text.replace('&', '&&')

    @property
    def value(self):
        if self.enabled:
            return self.get_value()
        return self.disabled_value

    def setup_method_layout(self):
        raise NotImplementedError

    def on_toggle(self, event=None):
        # Activated when the widget is enabled/disabled.
        self.enabled = not self.enabled
        self.display_widget()
        self.update_value()

    def display_widget(self):
        if self.enabled:
            self.off_label.hide()
            self.contents.show()
            self.title_label.setStyleSheet('color: #000000;')
        else:
            self.off_label.show()
            self.contents.hide()
            self.title_label.setStyleSheet('color: #B0B0B0;')

    def get_value(self):
        raise NotImplemented

    def update_value(self):
        self.change_signal.emit()
예제 #5
0
파일: MainUI.py 프로젝트: kylefortin/TacOS
class MainUI(QWidget):
    def __init__(self):
        super().__init__()
        self.left = Config.geometry[0]
        self.top = Config.geometry[1]
        self.width = Config.geometry[2]
        self.height = Config.geometry[3]
        self.setLayout(QHBoxLayout(self))

        # Init logger
        self.logger = Logger('mainUI', 'UI : Main')

        # Read in user prefs
        self.prefs = {}
        self.loadPrefs()

        # Load configured objects
        self.lights = Lights()
        self.lights.load()
        self.obas = OBAs()
        self.obas.load()
        self.tracs = Tracs()
        self.tracs.load()

        # Init I2C control
        if 'i2cAddress' in self.prefs.keys():
            _address = self.prefs['i2cAddress']
        else:
            _address = Config.defaultI2CAddress
        if 'i2cBus' in self.prefs.keys():
            _bus = self.prefs['i2cBus']
        else:
            _bus = Config.defaultI2CBus
        if 'i2cDebug' in self.prefs.keys():
            _debug = self.prefs['i2cDebug']
        else:
            _debug = False
        self._i2cBus = I2CBus(int(_bus), str(_address), bool(_debug))
        del _bus, _address, _debug

        # Create menu frame
        self._sidebarMenu = QFrame(self)
        self._sidebarMenu.layout = QVBoxLayout(self._sidebarMenu)
        self._sidebarMenu.setMaximumWidth(Config.menuWidth + 50)
        self._sidebarMenu.setMaximumHeight(Config.geometry[3])
        self._sidebarMenu.setStyleSheet(
            "QFrame{border-right: 1px solid black}")

        # Create menu
        _container = QWidget()
        _container.layout = QVBoxLayout()
        _container.setLayout(_container.layout)
        _scroll = QScrollArea()
        _scroll.setWidget(_container)
        _scroll.setWidgetResizable(True)
        self._sidebarMenu.layout.addWidget(_scroll)
        for _key in [
                'enableOBA', 'enableLighting', 'enableTracControl',
                'enableCamViewer', 'enableGyro'
        ]:
            if _key in self.prefs.keys():
                if self.prefs[_key]:
                    _title = {
                        'enableOBA': 'control_oba',
                        'enableLighting': 'control_light',
                        'enableTracControl': 'control_trac',
                        'enableCamViewer': 'control_cam',
                        'enableGyro': 'control_gyro'
                    }[_key]
                    _icon = {
                        'enableOBA':
                        Config.faIcon("wind"),
                        'enableLighting':
                        Config.faIcon("lightbulb"),
                        'enableTracControl':
                        Config.icon("tracControl", "rearDiff")['path'],
                        'enableCamViewer':
                        Config.faIcon("camera"),
                        'enableGyro':
                        Config.faIcon("truck-pickup")
                    }[_key]
                    _button = MenuButton(panel=_title, parent=self)
                    _button.setIcon(QIcon(_icon))
                    _container.layout.addWidget(_button)
        _settingsButton = MenuButton(panel="config_prefs", parent=self)
        _settingsButton.setIcon(QIcon(Config.faIcon("user-cog")))
        _container.layout.addWidget(_settingsButton)
        del _container, _scroll, _key, _settingsButton, _title, _icon, _button

        # Create version info label
        self._version = QLabel('v%s' % Config.version, self)
        self._version.setAlignment(Qt.AlignCenter)
        self._version.setFixedWidth(Config.menuWidth)
        self._version.setStyleSheet("QLabel{border: none}")
        self._sidebarMenu.layout.addWidget(self._version)

        # Create OSK button
        self._oskButton = QPushButton('', self)
        self._oskButton.setIcon(QIcon(Config.faIcon('keyboard')))
        self._oskButton.setFixedWidth(Config.menuWidth)
        self._oskButton.clicked.connect(self.showOSK)
        self._sidebarMenu.layout.addWidget(self._oskButton)

        # Add menu frame to main UI
        self.layout().addWidget(self._sidebarMenu)

        # Create main UI panel
        self._mainPanel = QWidget(self)
        self._mainPanel.setLayout(QVBoxLayout(self._mainPanel))
        self.layout().addWidget(self._mainPanel)

        # Init default UI
        for _key in [
                'enableOBA', 'enableLighting', 'enableTracControl',
                'enableCamViewer', 'enableGyro'
        ]:
            _cUI = None
            _uiName = None
            if _key in self.prefs.keys():
                if self.prefs[_key]:
                    if _key == 'enableOBA':
                        _cUI = OBAControlUI(self.obas.obas, self)
                        _uiName = 'control_oba'
                    elif _key == 'enableLighting':
                        _cUI = LightControlUI(self.lights.lights, self)
                        _uiName = 'control_light'
                    elif _key == 'enableTracControl':
                        _cUI = TracControlUI(self.tracs.tracs, self)
                        _uiName = 'control_trac'
                    elif _key == 'enableCamViewer':
                        _cUI = CamViewer(0)
                        _uiName = 'control_cam'
                    elif _key == 'enableGryo':
                        _cUI = Gyrometer()
                        _uiName = 'control_gyro'
            if _cUI is not None:
                break
        if _cUI is None:
            _cUI = UserPrefUI(self.prefs, parent=self)
            _uiName = 'config_prefs'
        self._currentUI = {'name': _uiName, 'obj': _cUI}
        _cUI.setParent(self)
        self._mainPanel.layout().addWidget(_cUI)
        _cUI.show()

        # Create button panel
        self._btnPanel = QWidget(self)
        self._btnPanel.setLayout(QHBoxLayout(self._btnPanel))
        self._mainPanel.layout().addWidget(self._btnPanel)

        # Create Config button
        self._configButton = QPushButton('Configure', self)
        self._configButton.setFixedHeight(50)
        self._configButton.setIcon(QIcon(Config.faIcon('cog')))
        self._configButton.clicked.connect(self.__configButtonAction)
        self._btnPanel.layout().addWidget(self._configButton)

        # Create Night Mode button
        self._nightModeButton = QPushButton('', self)
        self._nightModeButton.setFixedHeight(50)
        self._nightModeButton.setIcon(
            QIcon({
                True: Config.faIcon('sun'),
                False: Config.faIcon('moon')
            }[self.prefs['nightMode']]))
        self._nightModeButton.setText({
            True: 'Day Mode',
            False: 'Night Mode'
        }[self.prefs['nightMode']])
        self._nightModeButton.clicked.connect(self.toggleNightMode)
        self._btnPanel.layout().addWidget(self._nightModeButton)
        self.setNightMode(self.prefs['nightMode'])

    def closeEvent(self, event):
        self.savePrefs()
        self._i2cBus.deEnergizeAll()
        super(MainUI, self).closeEvent(event)

    def availablePins(self, value=None):
        if not self.prefs['allowDuplicatePins']:
            _pins = Config.outputPinList
            for _light in self.lights.lights:
                if _light.outputPin in _pins:
                    _pins.remove(_light.outputPin)
            for _oba in self.obas.obas:
                if _oba.outputPin in _pins:
                    _pins.remove(_oba.outputPin)
            for _trac in self.tracs.tracs:
                if _trac.outputPin in _pins:
                    _pins.remove(_trac.outputPin)
        else:
            _pins = Config.outputPinList
        _pins.sort()
        return _pins

    def setOutputPin(self, pin, state):
        fx = {
            True: self.i2cBus.energizeRelay,
            False: self.i2cBus.deEnergizeRelay
        }[state]
        fx(pin)

    def disableConfigButtons(self):
        for _ctrl in [self.configButton]:
            _ctrl.setEnabled(False)
        del _ctrl

    def enableConfigButtons(self):
        for _ctrl in [self.configButton]:
            _ctrl.setEnabled(True)
        del _ctrl

    def loadUI(self, ui, idx=None):
        if 'cam' in self.currentUI['name']:
            self.currentUI['obj'].stop()
        if 'gyro' in self.currentUI['name']:
            self.currentUI['obj'].stopSerial()
            self.currentUI['obj'].stopRotation()
        self.currentUI['obj'].hide()
        self.mainPanel.layout().removeWidget(self.currentUI['obj'])
        self.mainPanel.layout().removeWidget(self.btnPanel)
        _mode = ui.split('_')[0]
        _type = ui.split('_')[1]
        _ui = None
        if _mode == 'control':
            if _type == 'gyro':
                self.configButton.setText("Calibrate")
            else:
                self.configButton.setText("Configure")
            if _type == 'light':
                _ui = LightControlUI(self.lights.lights, self)
            elif _type == 'oba':
                _ui = OBAControlUI(self.obas.obas, self)
            elif _type == 'trac':
                _ui = TracControlUI(self.tracs.tracs, self)
            elif _type == 'cam':
                _ui = CamViewer(0)
                _ui.start()
            elif _type == 'gyro':
                _ui = Gyrometer(parent=self)
                _ui.startSerial()
                _ui.startRotation()
        elif _mode == 'config':
            if _type == 'light':
                _ui = LightConfigUI(self.lights.lights, self)
            elif _type == 'oba':
                _ui = OBAConfigUI(self.obas.obas, self)
            elif _type == 'trac':
                _ui = TracConfigUI(self.tracs.tracs, self)
            elif _type == 'prefs':
                _ui = UserPrefUI(self.prefs, self)
        elif _mode == 'edit':
            if _type == 'light':
                _ui = EditLightUI(self.lights.lights[idx], self)
            elif _type == 'oba':
                _ui = EditOBAUI(self.obas.obas[idx], self)
            elif _type == 'trac':
                _ui = EditTracUI(self.tracs.tracs[idx], self)
        elif _mode == 'create':
            if _type == 'light':
                _ui = AddLightUI(self)
            elif _type == 'oba':
                _ui = AddOBAUI(self)
            elif _type == 'trac':
                _ui = AddTracUI(self)
        if _ui is not None:
            _ui.setParent(self)
            self.mainPanel.layout().addWidget(_ui)
            _ui.show()
            self.currentUI = {'name': ui, 'obj': _ui}
        self.mainPanel.layout().addWidget(self.btnPanel)

    def toggleNightMode(self):
        _mode = self.prefs['nightMode']
        _value = {False: Config.dayBright, True: Config.nightBright}[not _mode]
        self.nightModeButton.setIcon({
            False: QIcon(Config.faIcon('sun')),
            True: QIcon(Config.faIcon('moon'))
        }[not _mode])
        self.nightModeButton.setText({
            False: 'Day Mode',
            True: 'Night Mode'
        }[not _mode])
        os.system("echo %s > /sys/class/backlight/rpi_backlight/brightness" %
                  _value)
        self.prefs['nightMode'] = not _mode
        self.savePrefs()
        self.logger.log('Night mode %s: backlight set to %s' %
                        (not _mode, _value))
        del _mode, _value

    def setNightMode(self, mode):
        _value = {False: Config.dayBright, True: Config.nightBright}[mode]
        self.nightModeButton.setIcon({
            False: QIcon(Config.faIcon('sun')),
            True: QIcon(Config.faIcon('moon'))
        }[mode])
        self.nightModeButton.setText({
            False: 'Day Mode',
            True: 'Night Mode'
        }[mode])
        os.system("echo %s > /sys/class/backlight/rpi_backlight/brightness" %
                  _value)
        del _value

    def loadPrefs(self):
        _pPrefs = open(Config.prefs, 'rb')
        _prefs = pickle.load(_pPrefs)
        for key in _prefs:
            self.prefs[key] = _prefs[key]
        _pPrefs.close()
        del _pPrefs, _prefs

    def savePrefs(self):
        _pPrefs = open(Config.prefs, 'wb')
        pickle.dump(self.prefs, _pPrefs)
        _pPrefs.close()

    def showOSK(self):
        if self.window().dock.isHidden():
            self.window().dock.show()
        else:
            self.window().dock.hide()

    def __configButtonAction(self):
        if self.currentUI['name'] not in ['control_camera', 'control_gyro']:
            self.disableConfigButtons()
            self.mainPanel.layout().removeWidget(self.currentUI['obj'])
            self.loadUI(self.currentUI['name'].replace('control', 'config'))
        elif self.currentUI['name'] == 'control_gyro':
            self.currentUI['obj'].calibrate()

    @property
    def mainPanel(self):
        return self._mainPanel

    @property
    def btnPanel(self):
        return self._btnPanel

    @property
    def nightModeButton(self):
        return self._nightModeButton

    @property
    def configButton(self):
        return self._configButton

    @property
    def currentUI(self):
        return self._currentUI

    @currentUI.setter
    def currentUI(self, value):
        self._currentUI = value

    @property
    def i2cBus(self):
        return self._i2cBus