示例#1
0
    def __init__(self, tool):
        QWidget.__init__(self)

        self.tool = tool

        self.layout = QBoxLayout(QBoxLayout.TopToBottom)

        self.info_label = QLabel(
            """The system sometimes overrides the power and temperature limits.
The intel-undervolt daemon can be used to enforce them periodically.
Enabling the systemd service enables you to apply your settings on boot.""")
        self.info_label.setWordWrap(True)
        self.layout.addWidget(self.info_label)

        self.layout.addWidget(DaemonIntervalControls(self.tool))

        systemd_group = QGroupBox("systemd service")
        self.systemd_controls = SystemdControls(self.tool)
        systemd_group.setLayout(self.systemd_controls.layout)
        systemd_group.setEnabled(self.tool.has_systemd)
        self.layout.addWidget(systemd_group)

        self.setLayout(self.layout)
class BrokerConnectionDialog(QDialog):
    def __init__(self, parent=None):
        super(BrokerConnectionDialog, self).__init__(parent)
        
        self.settings = LazySettings('settings')
        self.broker = BrokerConnection()

        onlyInt = QIntValidator(1, 9999)

        hostLabel = QLabel("Host:")
        self.hostEdit = QLineEdit(self.settings.HOST)

        portLabel = QLabel("Port:")
        self.portEdit = QLineEdit(str(self.settings.PORT))
        self.portEdit.setValidator(onlyInt)

        clientIdLabel = QLabel("Client ID:")
        self.clientIdEdit = QLineEdit('1')
        self.clientIdEdit.setValidator(onlyInt)


        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)

        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)

        self.groupBox = QGroupBox()
        groupLayout = QVBoxLayout()
        groupLayout.addWidget(hostLabel)
        groupLayout.addWidget(self.hostEdit)
        groupLayout.addWidget(portLabel)
        groupLayout.addWidget(self.portEdit)
        groupLayout.addWidget(clientIdLabel)
        groupLayout.addWidget(self.clientIdEdit)
        groupLayout.addStretch(1)
        self.groupBox.setLayout(groupLayout)
        
        if self.broker.isConnected():
            buttonBox.button(QDialogButtonBox.Ok).setText('Disconnect')
            self.groupBox.setEnabled(False)
        else:
            buttonBox.button(QDialogButtonBox.Ok).setText('Connect')
        
        mainLayout = QVBoxLayout()
        mainLayout.addWidget(self.groupBox)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

        self.setWindowTitle("Settings")
        
    def accept(self):
        host = self.hostEdit.text()
        port = int(self.portEdit.text())
        client_id = int(self.clientIdEdit.text())
        self.broker.connect(host, port, client_id)
        self.broker.ib.connectedEvent += self.onConnectionEstablished
        self.hide()
        
    def onConnectionEstablished(self):
        if self.parent():
            self.parent().statusBar().showMessage('Connected to IB TWS/Gateway')
        else:
            print('Connected to IB TWS/Gateway')
        # Retrieve account open option positions from broker
        opt_positions = self.broker.positions()
        print(opt_positions)
            
    def reject(self):
        self.hide()
示例#3
0
文件: NodeInput.py 项目: wis/pyScript
class NodeInput(QWidget):
    def __init__(self, content_widget):
        super(NodeInput, self).__init__()

        self.content_widget = content_widget
        self.widget_type = ''  # gets specified automatically when creating ui below (see self.widget_combo_box_changed)

        # create UI

        # create all layouts
        self.grid_layout = QGridLayout(self)

        # move buttons
        self.up_button = QPushButton('   <   ')
        self.down_button = QPushButton('   >   ')

        # type and label
        self.type_combo_box = QComboBox(self)
        self.type_combo_box.addItem('exec')
        self.type_combo_box.addItem('data')
        self.type_combo_box.currentTextChanged.connect(
            self.type_combo_box_changed)
        self.label_text_edit = QPlainTextEdit(self)
        self.label_text_edit.setPlaceholderText('Label')
        self.label_text_edit.setFixedWidth(self.type_combo_box.width())
        # self.label_text_edit.setMinimumHeight(20)
        self.label_text_edit.setMaximumHeight(56)

        # widget
        self.widget_grid_layout = QGridLayout()
        self.widget_yes_no_group_box = QGroupBox(self)
        self.widget_yes_no_group_box.setLayout(QVBoxLayout())
        self.widget_yes_radio_button = QRadioButton('Yes', self)
        self.widget_yes_radio_button.setChecked(True)
        self.widget_yes_radio_button.toggled.connect(self.widget_yes_set)
        self.widget_no_radio_button = QRadioButton('No', self)
        self.widget_yes_no_group_box.layout().addWidget(
            self.widget_yes_radio_button)
        self.widget_yes_no_group_box.layout().addWidget(
            self.widget_no_radio_button)
        self.widget_grid_layout.addWidget(self.widget_yes_no_group_box, 0, 0,
                                          4, 1)

        self.widget_group_box = QGroupBox(self)
        self.widget_group_box.setLayout(QVBoxLayout())
        self.widget_type_combo_box = QComboBox(self)
        self.widget_type_combo_box.addItem('std line edit')
        self.widget_type_combo_box.addItem('std spin box')
        self.widget_type_combo_box.addItem('custom widget')
        self.widget_type_combo_box.currentTextChanged.connect(
            self.widget_type_combo_box_changed)
        self.custom_widget_line_edit = QLineEdit()
        self.custom_widget_line_edit.setPlaceholderText('input widget name')
        self.custom_widget_line_edit.editingFinished.connect(
            self.widget_name_line_edit_edited)
        self.custom_widget_line_edit.setEnabled(False)

        self.widget_under_label_radio_button = QRadioButton(
            'widget under label')
        self.widget_under_label_radio_button.setChecked(True)
        self.widget_besides_label_radio_button = QRadioButton(
            'widget besides label')

        self.widget_group_box.layout().addWidget(self.widget_type_combo_box)
        self.widget_group_box.layout().addWidget(self.custom_widget_line_edit)
        self.widget_group_box.layout().addWidget(
            self.widget_under_label_radio_button)
        self.widget_group_box.layout().addWidget(
            self.widget_besides_label_radio_button)

        self.widget_grid_layout.addWidget(self.widget_group_box, 0, 3, 4, 1)

        # del button
        self.del_button = QPushButton(self)
        self.del_button.setText(' Del ')
        self.del_button.clicked.connect(self.delete_clicked)

        # create layout
        self.grid_layout.addWidget(self.up_button, 0, 0, 1, 1)
        self.grid_layout.addWidget(self.down_button, 3, 0, 1, 1)
        self.grid_layout.addWidget(self.type_combo_box, 0, 1)
        self.grid_layout.addWidget(self.label_text_edit, 1, 1, 3, 1)
        self.grid_layout.addLayout(self.widget_grid_layout, 0, 2, 4, 1)
        self.grid_layout.addWidget(self.del_button, 0, 4, 4, 1)

    def get_type(self):
        return self.type_combo_box.currentText()

    def get_label(self):
        return self.label_text_edit.toPlainText()

    def has_widget(self):
        return self.widget_yes_radio_button.isChecked()

    def set_has_widget(self, has_widget):
        if has_widget:
            self.widget_yes_radio_button.setChecked(True)
            self.widget_no_radio_button.setChecked(False)
        else:
            self.widget_yes_radio_button.setChecked(False)
            self.widget_no_radio_button.setChecked(True)

    def get_widget_type(self):
        return self.widget_type_combo_box.currentText()

    def set_widget_type(self, new_widget_type):
        self.widget_type_combo_box.setCurrentText(new_widget_type)

    def get_widget_name(self):
        return self.content_widget.prepare_class_name(
            self.custom_widget_line_edit.text())

    def set_widget_name(self, name):
        self.custom_widget_line_edit.setText(name)

    def get_widget_pos(self):
        under = self.widget_under_label_radio_button
        # besides = self.widget_besides_label_radio_button
        return 'under' if under.isChecked() else 'besides'

    def set_widget_pos(self, pos):
        if pos == 'under':
            self.widget_under_label_radio_button.setChecked(True)
            self.widget_besides_label_radio_button.setChecked(False)
        elif pos == 'besides':
            self.widget_under_label_radio_button.setChecked(False)
            self.widget_besides_label_radio_button.setChecked(True)

    def widget_yes_set(self):
        if self.widget_yes_radio_button.isChecked():
            self.widget_group_box.setEnabled(True)
        else:
            self.widget_group_box.setEnabled(False)

    def widget_name_line_edit_edited(self):
        self.custom_widget_line_edit.setText(
            self.content_widget.prepare_class_name(
                self.custom_widget_line_edit.text()))

    def widget_type_combo_box_changed(self, new_text):
        self.widget_type = new_text
        if new_text == 'custom widget':
            self.custom_widget_line_edit.setEnabled(True)
        else:
            self.custom_widget_line_edit.setEnabled(False)

    def set_type(self, new_type):
        self.type_combo_box.setCurrentText(new_type)

    def type_combo_box_changed(self, new_type):
        if new_type == 'data':
            self.widget_grid_layout.setEnabled(True)
        elif new_type == 'exec':
            self.widget_grid_layout.setEnabled(False)

    def set_label(self, new_label):
        self.label_text_edit.setPlainText(new_label)

    def delete_clicked(self):
        ret = QMessageBox.warning(
            self, 'Input',
            'Do you really want to delete this input? All changes'
            'will be lost.', QMessageBox.Yes, QMessageBox.No)
        if ret == QMessageBox.Yes:
            self.content_widget.delete_input(self)
示例#4
0
class Focus_UI(QGroupBox):
    """
    A QGroupbox widget with all properties of a Visca camera
    """
    def __init__(self, visca, v):
        super(Focus_UI, self).__init__()
        self.v = v
        self.visca = visca
        self.setTitle('Focus')
        focus_layout = QGridLayout()
        visca.focus_auto = QPushButton()
        visca.focus_auto.setCheckable(1)
        visca.focus_auto.setText('Auto')
        visca.focus_auto.toggled.connect(self.on_focus_auto_stateChanged)
        visca.focus_stop = QPushButton()
        visca.focus_stop.setText('Stop')
        visca.focus_stop.clicked.connect(self.on_focus_stop_pressed)
        visca.focus_near = QPushButton()
        visca.focus_near.setText('Near')
        visca.focus_near.clicked.connect(self.on_focus_near_pressed)
        visca.focus_far = QPushButton()
        visca.focus_far.setText('Far')
        visca.focus_far.clicked.connect(self.on_focus_far_pressed)
        visca.focus_far_speed = QSpinBox()
        visca.focus_far_speed.valueChanged.connect(
            self.on_focus_far_speed_valueChanged)
        visca.focus_far_speed_label = QLabel()
        visca.focus_far_speed_label.setText('Far Speed')
        visca.focus_near_speed = QSpinBox()
        visca.focus_near_speed.valueChanged.connect(
            self.on_focus_near_speed_valueChanged)
        visca.focus_near_speed_label = QLabel()
        visca.focus_near_speed_label.setText('Near Speed')
        visca.focus = QSlider()
        visca.focus.setOrientation(Qt.Horizontal)
        visca.focus.setMinimum(0)
        visca.focus.setMaximum(16384)
        visca.focus_direct_value = QSpinBox()
        visca.focus_direct_value.setKeyboardTracking(0)
        visca.focus_label = QLabel()
        visca.focus_label.setText('Focus Value')
        visca.focus.valueChanged.connect(visca.focus_direct_value.setValue)
        visca.focus_direct_value.setMinimum(0)
        visca.focus_direct_value.setMaximum(65536)
        visca.focus_direct_value.valueChanged.connect(
            self.on_focus_direct_valueChanged)
        visca.focus_nearlimit_label = QLabel()
        visca.focus_nearlimit_label.setText('Focus nearlimit')
        visca.focus_nearlimit_value = QSpinBox()
        visca.focus_nearlimit_value.setKeyboardTracking(0)
        visca.focus_nearlimit_value.setMinimum(0)
        visca.focus_nearlimit_value.setMaximum(65536)
        visca.focus_nearlimit_value.valueChanged.connect(
            self.on_focus_nearlimit_valueChanged)
        # create a groupbox for all manual settings
        self.focus_manual = QGridLayout()
        self.focus_manual.addWidget(visca.focus_near_speed, 2, 1, 1, 1)
        self.focus_manual.addWidget(visca.focus_far_speed, 2, 3, 1, 1)
        self.focus_manual.addWidget(visca.focus_label, 2, 4, 1, 1)
        self.focus_manual.addWidget(visca.focus_near_speed_label, 1, 1, 1, 1)
        self.focus_manual.addWidget(visca.focus_far_speed_label, 1, 3, 1, 1)
        #self.focus_manual.addWidget(self.focus, 4, 2, 3, 1)
        self.focus_manual.addWidget(visca.focus_near, 3, 1, 1, 1)
        self.focus_manual.addWidget(visca.focus_stop, 3, 2, 1, 1)
        self.focus_manual.addWidget(visca.focus_far, 3, 3, 1, 1)
        self.focus_manual.addWidget(visca.focus_direct_value, 3, 4, 1, 1)
        self.focus_manual.addWidget(visca.focus_nearlimit_label, 4, 1, 1, 1)
        self.focus_manual.addWidget(visca.focus_nearlimit_value, 4, 2, 1, 1)
        self.focus_manual_box = QGroupBox()
        self.focus_manual_box.setLayout(self.focus_manual)
        focus_layout.addWidget(visca.focus_auto, 1, 1, 1, 1)
        focus_layout.addWidget(self.focus_manual_box, 2, 1, 1, 1)
        self.setLayout(focus_layout)

    def on_focus_auto_stateChanged(self, state):
        if state:
            self.v.focus_auto = 1
            self.focus_manual_box.setEnabled(0)
        else:
            self.v.focus_auto = 0
            self.focus_manual_box.setEnabled(1)
        sleep(0.1)
        focus = self.v._query('focus')
        focus_auto___ = self.v._query('focus_auto')
        print('------autofocus is :', focus_auto___)
        self.visca.focus_direct_value.setValue(focus)
        sleep(0.1)
        nearlimit = self.v._query('focus_nearlimit')
        self.visca.focus_nearlimit_value.setValue(nearlimit)

    def on_focus_near_pressed(self):
        self.v.focus_near()

    def on_focus_far_pressed(self):
        self.v.focus_far()

    def focus_refresh(self):
        focus = self.v._query('focus')
        self.visca.focus_direct_value.setValue(focus)

    def on_focus_stop_pressed(self):
        self.v.focus_stop()
        self.focus_refresh()

    def on_focus_near_speed_valueChanged(self, speed):
        self.visca.focus_near_speed = speed

    def on_focus_far_speed_valueChanged(self, speed):
        self.visca.focus_far_speed = speed

    def on_focus_direct_valueChanged(self, value):
        self.v.focus = value

    def on_focus_nearlimit_valueChanged(self, nearlimit):
        self.v.focus_nearlimit = nearlimit
示例#5
0
class ScaleDialogPQ(QDialog):
    '''
    Dialog for obtaining scaling information from the user.
    Validates that the resulting width and height values
    are not smaller than the specified minimums.
    '''
    def __init__(self,
                 scale,
                 width,
                 height,
                 minwidth,
                 minheight,
                 autoscale,
                 parent=None):
        '''
        Creates a scaling dialog, with scale as the current
        scaling value which gives a pixmap of size width and
        height.  The minimum acceptable width and heights are
        given by minwidth and minheight.  Values are assumed to
        be in units of pixels.  The value of autoscale sets the
        default value of "Scale image to fir window frame".
        '''
        super(ScaleDialogPQ, self).__init__(parent)

        self.__scale = float(scale)
        self.__pixwidth = float(width)
        self.__inchwidth = float(width) / float(self.physicalDpiX())
        self.__pixheight = float(height)
        self.__inchheight = float(height) / float(self.physicalDpiY())
        self.__minpixwidth = int(minwidth)
        self.__minpixheight = int(minheight)
        self.__autoscale = bool(autoscale)

        self.FLTSTR_FORMAT = "%#.3f"

        self.setWindowTitle(self.tr("Image Size Scaling"))

        # auto-scaling option at the top
        autoscalelabel = QLabel(self.tr("Scale image to fit window frame?"),
                                self)
        autoscalelabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.__autoyesbtn = QRadioButton(self.tr("&Yes"), self)
        self.__autonobtn = QRadioButton(self.tr("&No"), self)
        autoscalebtngrp = QButtonGroup(self)
        autoscalebtngrp.addButton(self.__autoyesbtn)
        autoscalebtngrp.addButton(self.__autonobtn)

        # put the manual scaling settings into their own box
        self.__grpbox = QGroupBox(self.tr("Fixed scaling"), self)

        # create the widgets going inside this group box
        messagelabel = QLabel(
            self.tr("Scaling factor (both horiz. and vert.) for the image"),
            self.__grpbox)
        messagelabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

        scalelabel = QLabel(self.tr("&Scale: "), self.__grpbox)
        self.__scaleedit = QLineEdit(self.FLTSTR_FORMAT % self.__scale,
                                     self.__grpbox)
        scalelabel.setBuddy(self.__scaleedit)

        widthbegin = QLabel(self.tr("Width: "), self.__grpbox)
        self.__pixwidthlabel = QLabel(str(int(self.__pixwidth + 0.5)),
                                      self.__grpbox)
        widthmiddle = QLabel(self.tr("pixels, or"), self.__grpbox)
        self.__inchwidthlabel = QLabel(self.FLTSTR_FORMAT % self.__inchwidth,
                                       self.__grpbox)
        widthend = QLabel(self.tr("inches on the screen"), self.__grpbox)
        minwidthlabel = QLabel(self.tr("(must not be less than %d pixels)" % \
                               self.__minpixwidth), self.__grpbox)

        heightbegin = QLabel(self.tr("Height:"), self.__grpbox)
        self.__pixheightlabel = QLabel(str(int(self.__pixheight + 0.5)),
                                       self.__grpbox)
        heightmiddle = QLabel(self.tr("pixels, or"), self.__grpbox)
        self.__inchheightlabel = QLabel(self.FLTSTR_FORMAT % self.__inchheight,
                                        self.__grpbox)
        heightend = QLabel(self.tr("inches on the screen"), self.__grpbox)
        minheightlabel = QLabel(self.tr("(must not be less than %d pixels)" % \
                                self.__minpixheight), self.__grpbox)

        # layout the widgets in this group box
        layout = QGridLayout()

        layout.addWidget(messagelabel, 0, 0, 1, 5)

        layout.addWidget(scalelabel, 1, 0, 1, 1)
        layout.addWidget(self.__scaleedit, 1, 1, 1, 4)

        layout.addWidget(widthbegin, 2, 0, 1, 1)
        layout.addWidget(self.__pixwidthlabel, 2, 1, 1, 1)
        layout.addWidget(widthmiddle, 2, 2, 1, 1)
        layout.addWidget(self.__inchwidthlabel, 2, 3, 1, 1)
        layout.addWidget(widthend, 2, 4, 1, 1)

        layout.addWidget(minwidthlabel, 3, 1, 1, 4)

        layout.addWidget(heightbegin, 4, 0, 1, 1)
        layout.addWidget(self.__pixheightlabel, 4, 1, 1, 1)
        layout.addWidget(heightmiddle, 4, 2, 1, 1)
        layout.addWidget(self.__inchheightlabel, 4, 3, 1, 1)
        layout.addWidget(heightend, 4, 4, 1, 1)

        layout.addWidget(minheightlabel, 5, 1, 1, 4)

        # assign this layout to the group box
        self.__grpbox.setLayout(layout)

        # layout the widgets in the dialog (outside the group box)
        layout = QGridLayout()
        layout.addWidget(autoscalelabel, 0, 0, 1, 1)
        layout.addWidget(self.__autoyesbtn, 0, 1, 1, 1)
        layout.addWidget(self.__autonobtn, 0, 2, 1, 1)
        layout.addWidget(self.__grpbox, 1, 0, 1, 3)

        buttonbox = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel
            | QDialogButtonBox.Reset, Qt.Horizontal, self)

        layout.addWidget(buttonbox, 2, 0, 1, 3)

        self.setLayout(layout)

        # The OK button is not the default here in Qt4.2
        okbutton = buttonbox.button(QDialogButtonBox.Ok)
        okbutton.setDefault(True)

        resetbutton = buttonbox.button(QDialogButtonBox.Reset)

        self.__autoyesclicked = self.__autoyesbtn.clicked
        self.__autoyesclicked.connect(self.setAutoScale)

        self.__autonoclicked = self.__autonobtn.clicked
        self.__autonoclicked.connect(self.unsetAutoScale)

        self.__scaletextchanged = self.__scaleedit.textChanged
        self.__scaletextchanged.connect(self.updateValues)

        self.__buttonboxaccepted = buttonbox.accepted
        self.__buttonboxaccepted.connect(self.checkValues)

        self.__buttonboxrejected = buttonbox.rejected
        self.__buttonboxrejected.connect(self.reject)

        self.__resetbuttonclicked = resetbutton.clicked
        self.__resetbuttonclicked.connect(self.resetValues)

        # initialize the state from autoscale
        if self.__autoscale:
            self.__autoyesbtn.setChecked(True)
            self.setAutoScale(True)
        else:
            self.__autonobtn.setChecked(True)
            self.unsetAutoScale(True)

    def setAutoScale(self, checked):
        if checked:
            self.__grpbox.setEnabled(False)

    def unsetAutoScale(self, checked):
        if checked:
            self.__grpbox.setEnabled(True)
            self.__scaleedit.setFocus()
            self.__scaleedit.selectAll()

    def updateValues(self, newstring):
        try:
            newscale = float(newstring)
            if (newscale < 0.0001) or (newscale > 10000.0):
                raise OverflowError()
            newval = self.__pixwidth * newscale / self.__scale
            self.__pixwidthlabel.setText(str(int(newval + 0.5)))
            newval = self.__inchwidth * newscale / self.__scale
            self.__inchwidthlabel.setText(self.FLTSTR_FORMAT % newval)
            newval = self.__pixheight * newscale / self.__scale
            self.__pixheightlabel.setText(str(int(newval + 0.5)))
            newval = self.__inchheight * newscale / self.__scale
            self.__inchheightlabel.setText(self.FLTSTR_FORMAT % newval)
        except Exception:
            pass

    def checkValues(self):
        okay = self.getValues()[2]
        if okay:
            self.accept()
        else:
            QMessageBox.warning(self, self.tr("Invalid value"),
                                self.tr("Scale value is not valid"))

    def getValues(self):
        if self.__autoyesbtn.isChecked():
            return (0.0, True, True)
        try:
            newscale = float(self.__scaleedit.text())
            if (newscale < 0.0001) or (newscale > 10000.0):
                raise OverflowError()
            newwidth = self.__pixwidth * newscale / self.__scale
            newwidth = int(newwidth + 0.5)
            newheight = self.__pixheight * newscale / self.__scale
            newheight = int(newheight + 0.5)
            if (newwidth < self.__minpixwidth) or (newheight <
                                                   self.__minpixheight):
                raise OverflowError()
        except Exception:
            return (0.0, False, False)
        return (newscale, False, True)

    def resetValues(self):
        self.__scaleedit.setText(self.FLTSTR_FORMAT % self.__scale)
        self.__pixwidthlabel.setText(str(int(self.__pixwidth + 0.5)))
        self.__inchwidthlabel.setText(self.FLTSTR_FORMAT % self.__inchwidth)
        self.__pixheightlabel.setText(str(int(self.__pixheight + 0.5)))
        self.__inchheightlabel.setText(self.FLTSTR_FORMAT % self.__inchheight)
        if self.__autoscale:
            self.__autoyesbtn.setChecked(True)
            self.setAutoScale(True)
        else:
            self.__autonobtn.setChecked(True)
            self.unsetAutoScale(True)
示例#6
0
class ExerciseWindow(QWidget):
    closed = Signal()

    def __init__(self, nursery, exercise):
        super().__init__()
        self.log = logging.getLogger("Test qt lean")

        self.server = ServerInterface(nursery)

        self.exercise = exercise
        self.statements = self.exercise.course.statements

        self._initUI()

        # Link signals
        self.server.proof_state_change.connect(self.proof_state_update)

        # Start waiter task
        self.server.nursery.start_soon(self.server_task)

        # Update initial proof state
        #self.proof_state_update(self.server.proof_state)

    async def server_task(self):
        await self.server.start()
        await self.server.exercise_set(self.exercise)
        async with qtrio.enter_emissions_channel(
                signals=[self.closed, self.send.clicked, self.undo.clicked
                         ]) as emissions:
            async for emission in emissions.channel:
                if emission.is_from(self.closed):
                    break
                elif emission.is_from(self.send.clicked):
                    await self.go_send()
                elif emission.is_from(self.undo.clicked):
                    await self.go_undo()

        self.server.stop()

    async def go_send(self):
        self.log.info("Send file to lean")
        self.freeze(True)

        txt = self.edit.toPlainText()
        try:
            await self.server.code_set("add", txt)
        except exceptions.FailedRequestError as ex:
            msg = QMessageBox(self)
            msg.setIcon(QMessageBox.Critical)
            msg.setWindowTitle("Failed lean request")
            msg.setText("I am broken :'(")

            detailed = ""
            for err in ex.errors:
                detailed += f"* at {err.pos_line} : {err.text}\n"

            msg.setDetailedText(detailed)
            msg.setStandardButtons(QMessageBox.Ok)
            msg.exec_()

        self.freeze(False)

    async def go_undo(self):
        self.log.info("Undo")
        self.freeze(True)
        await self.server.history_undo()
        self.edit.setPlainText(self.server.lean_file.inner_contents)
        self.freeze(False)

    def closeEvent(self, ev):
        super().closeEvent(ev)
        self.closed.emit()

    def _initUI(self):
        # Create widgets
        self.objects = PropobjList()
        self.properties = PropobjList()

        self.goal = Goal("TODO")

        self.edit = QPlainTextEdit()
        self.send = QPushButton("Send to lean")
        self.undo = QPushButton("Undo")

        self.deflist = QListWidget()

        # --> Build deflist
        for st in self.statements:
            self.deflist.addItem(st.pretty_name)

        # --> Link signal
        self.deflist.itemClicked.connect(self.add_statement_name)

        # Create layouts
        goal_layout = QHBoxLayout()
        main_layout = QVBoxLayout()
        workspace_layout = QHBoxLayout()
        propobj_layout = QVBoxLayout()
        tools_layout = QVBoxLayout()
        btns_layout = QHBoxLayout()

        # Create QGroupBox to have titles
        propobj_gb = QGroupBox('Properties and objects')
        self.tools_gb = QGroupBox('Lean code')

        # Put widgets in layouts and group boxes
        goal_layout.addStretch()
        goal_layout.addWidget(self.goal)
        goal_layout.addStretch()

        # Add space below goal
        goal_layout.setContentsMargins(0, 10, 0, 30)  #LTRB

        # Build propobj layout
        propobj_layout.addWidget(self.objects)
        propobj_layout.addWidget(self.properties)
        propobj_gb.setLayout(propobj_layout)

        # Build tools layout
        btns_layout.addWidget(self.send)
        btns_layout.addWidget(self.undo)

        tools_layout.addWidget(self.deflist)
        tools_layout.addWidget(self.edit)
        tools_layout.addLayout(btns_layout)

        self.tools_gb.setLayout(tools_layout)

        # Build workspace layout
        workspace_layout.addWidget(propobj_gb)
        workspace_layout.addWidget(self.tools_gb)

        # Don't forget me
        main_layout.addLayout(goal_layout)
        main_layout.addLayout(workspace_layout)
        self.setWindowTitle("d∃∀duction")
        self.setLayout(main_layout)
        self.show()

    def freeze(self, state: bool):
        self.tools_gb.setEnabled(not state)

    @Slot(QListWidgetItem)
    def add_statement_name(self, item):
        st = self.statements[self.deflist.row(item)]
        self.edit.insertPlainText(st.lean_name)

    @Slot(ProofState)
    def proof_state_update(self, po: ProofState):
        # Update goal
        # log.debug("Updating goal")
        goal = po.goals[0]
        target = goal.target.math_type.format_as_utf8()

        self.goal.setText(target)

        # Update properties and objects
        self.properties.clear()
        self.objects.clear()
        for type_, instances in goal.math_types:
            utf8 = type_.format_as_utf8(is_math_type=True)

            for obj in instances:
                txt = f"{obj.format_as_utf8()} : {utf8}"
                if obj.is_prop(): self.properties.addItem(txt)
                else: self.objects.addItem(txt)
示例#7
0
class Exposure_UI(QGroupBox):
    """
    A QGroupbox widget with all properties of a Visca camera
    """
    def __init__(self, ui, cam):
        super(Exposure_UI, self).__init__()
        self.cam = cam
        self.ui = ui
        self.setTitle('Exposure')
        expo_layout = QGridLayout()
        ui.AE = QComboBox()
        ui.AE.addItems(['auto', 'manual', 'iris', 'shutter', 'bright'])
        ui.AE.currentTextChanged.connect(self.on_AE_currentTextChanged)
        ui.slowshutter = QCheckBox()
        ui.slowshutter.setText('auto slowshutter')
        ui.slowshutter.clicked.connect(self.on_slowshutter_currentIndexChanged)
        ui.backlight = QCheckBox()
        ui.backlight.setText('Backlight')
        ui.backlight.clicked.connect(self.on_backlight_toggled)
        ui.shutter_label = QLabel()
        ui.shutter_label.setText('Shutter')
        ui.shutter = QComboBox()
        ui.shutter.addItems(
            [str(truc) for truc in answers['shutter'].values()])
        ui.shutter.currentTextChanged.connect(
            self.on_shutter_currentTextChanged)
        ui.iris_label = QLabel()
        ui.iris_label.setText('Iris')
        ui.iris = QComboBox()
        ui.iris.addItems([str(truc) for truc in answers['iris'].values()])
        ui.iris.currentTextChanged.connect(self.on_iris_currentTextChanged)
        ui.gain_label = QLabel()
        ui.gain_label.setText('Gain')
        ui.gain = QComboBox()
        ui.gain.addItems([str(truc) for truc in answers['gain'].values()])
        ui.gain.currentTextChanged.connect(self.on_gain_currentTextChanged)
        ui.gamma_label = QLabel()
        ui.gamma_label.setText('Gamma')
        ui.gamma = QSpinBox()
        ui.gamma.setMinimum(0)
        ui.gamma.setMaximum(4)
        ui.gamma.valueChanged.connect(self.on_gamma_valueChanged)
        ui.aperture_label = QLabel()
        ui.aperture_label.setText('Aperture')
        ui.aperture = QSpinBox()
        ui.aperture.setMinimum(0)
        ui.aperture.setMaximum(15)
        ui.aperture.valueChanged.connect(self.on_aperture_valueChanged)
        # create a groupbox for all manual settings
        self.expo_manual = QGridLayout()
        self.expo_manual.addWidget(ui.shutter_label, 1, 1, 1, 1)
        self.expo_manual.addWidget(ui.shutter, 2, 1, 1, 1)
        self.expo_manual.addWidget(ui.iris_label, 1, 2, 1, 1)
        self.expo_manual.addWidget(ui.iris, 2, 2, 1, 1)
        self.expo_manual.addWidget(ui.gain_label, 1, 3, 1, 1)
        self.expo_manual.addWidget(ui.gain, 2, 3, 1, 1)
        self.expo_manual.addWidget(ui.gamma_label, 1, 4, 1, 1)
        self.expo_manual.addWidget(ui.gamma, 2, 4, 1, 1)
        self.expo_manual.addWidget(ui.aperture_label, 1, 5, 1, 1)
        self.expo_manual.addWidget(ui.aperture, 2, 5, 1, 1)
        self.expo_manual_box = QGroupBox()
        self.expo_manual_box.setLayout(self.expo_manual)
        expo_layout.addWidget(ui.AE, 1, 1, 1, 1)
        expo_layout.addWidget(ui.slowshutter, 1, 2, 1, 1)
        expo_layout.addWidget(ui.backlight, 1, 3, 1, 1)
        expo_layout.addWidget(self.expo_manual_box, 2, 1, 1, 4)
        self.setLayout(expo_layout)

        AE = cam._query('AE')
        ui.AE.setCurrentText(AE)
        if AE != 'auto':
            # if expo is manual, refresh values
            self.expo_refresh()
        if ui.AE.currentText() == 'auto':
            self.expo_manual_box.setEnabled(False)
        else:
            self.expo_manual_box.setEnabled(True)

    def on_slowshutter_currentIndexChanged(self, state):
        if type(state) == unicode:
            state = state.encode('utf-8')
        if state:
            self.cam.slowshutter = 'auto'
        else:
            self.cam.slowshutter = 'manual'

    def on_backlight_toggled(self, state):
        self.cam.backlight = state

    def expo_refresh(self):
        gamma = self.cam._query('gamma')
        if gamma:
            self.ui.gamma.setValue(gamma)
        aperture = self.cam._query('aperture')
        if aperture:
            self.ui.aperture.setValue(aperture)
        iris = self.cam._query('iris')
        if iris:
            self.ui.iris.setCurrentText(str(iris))
        shutter = self.cam._query('shutter')
        if shutter:
            self.ui.shutter.setCurrentText(str(shutter))
        gain = self.cam._query('gain')
        if gain:
            self.ui.gain.setCurrentText(str(gain))

    def on_AE_currentTextChanged(self, mode):
        if type(mode) == unicode:
            mode = mode.encode('utf-8')
            self.cam.AE = mode
            if mode == 'auto':
                self.expo_manual_box.setEnabled(False)
                self.ui.backlight.setEnabled(True)
                self.ui.slowshutter.setEnabled(True)
            if mode == 'manual':
                self.ui.backlight.setEnabled(False)
                self.ui.slowshutter.setEnabled(False)
                self.expo_manual_box.setEnabled(True)
                self.ui.shutter.setEnabled(True)
                self.ui.shutter_label.setEnabled(True)
                self.ui.iris.setEnabled(True)
                self.ui.iris_label.setEnabled(True)
                self.ui.gain.setEnabled(True)
                self.ui.gain_label.setEnabled(True)
                self.expo_refresh()
            if mode == 'shutter':
                self.ui.backlight.setEnabled(False)
                self.ui.slowshutter.setEnabled(False)
                self.expo_manual_box.setEnabled(True)
                self.ui.shutter.setEnabled(True)
                self.ui.shutter_label.setEnabled(True)
                self.ui.iris.setEnabled(False)
                self.ui.iris_label.setEnabled(False)
                self.ui.gain.setEnabled(False)
                self.ui.gain_label.setEnabled(False)
                self.expo_refresh()
            if mode == 'iris':
                self.ui.backlight.setEnabled(False)
                self.ui.slowshutter.setEnabled(False)
                self.expo_manual_box.setEnabled(True)
                self.ui.iris.setEnabled(True)
                self.ui.iris_label.setEnabled(True)
                self.ui.shutter.setEnabled(False)
                self.ui.shutter_label.setEnabled(False)
                self.ui.gain.setEnabled(False)
                self.ui.gain_label.setEnabled(False)
                self.expo_refresh()

    def on_shutter_currentTextChanged(self, text):
        index = get_key_by_value(answers['shutter'], text)
        self.cam.shutter = index

    def on_iris_currentTextChanged(self, text):
        index = get_key_by_value(answers['iris'], text)
        self.cam.iris = index

    def on_gain_currentTextChanged(self, text):
        index = get_key_by_value(answers['gain'], text)
        self.cam.gain = index

    def on_aperture_valueChanged(self, index):
        self.cam.aperture = int(index)
        self.cam._query('aperture')

    def on_gamma_valueChanged(self, index):
        self.cam.gamma = index
        self.cam._query('gamma')
示例#8
0
class SaveTab(QWidget):
    def __init__(self, parent):
        """Initialize the save tab
        """

        super(SaveTab, self).__init__(parent)

        self.prefs = parent.prefs
        self.order_options = {'SortedOrder': 'Sorted (based on IDD file)',
                              'OriginalOrderTop': 'Original order (With new objects on top)',
                              'OriginalOrderBottom': 'Original order (With new objects on bottom)'}
        self.format_options = {'UseSpecialFormat': 'Use special formatting for some objects',
                               'None': 'Do not use special formatting'}

        # Sort Order Code
        order_label = QLabel("Save Order for Objects:")
        self.order_edit = QComboBox(self)
        self.order_edit.addItems(list(self.order_options.values()))
        self.order_edit.setMaximumWidth(350)
        order_setting = self.order_options[self.prefs['sort_order']]
        self.order_edit.setCurrentIndex(self.order_edit.findText(order_setting))
        self.order_edit.currentIndexChanged.connect(self.update_order)

        format_label = QLabel("Special Formatting:")
        self.format_edit = QComboBox(self)
        self.format_edit.addItems(list(self.format_options.values()))
        self.format_edit.setMaximumWidth(350)
        format_setting = self.format_options[self.prefs['special_formatting']]
        self.format_edit.setCurrentIndex(self.format_edit.findText(format_setting))
        self.order_edit.currentIndexChanged.connect(self.update_format)

        self.save_group_box = QGroupBox("Default Save Options")
        save_box = QVBoxLayout()
        save_box.addWidget(order_label)
        save_box.addWidget(self.order_edit)
        save_box.addSpacing(10)
        save_box.addWidget(format_label)
        save_box.addWidget(self.format_edit)
        save_box.addStretch(1)
        self.save_group_box.setLayout(save_box)
        self.save_group_box.setEnabled(False)

        # Save additional options code
        self.save_units_check = QCheckBox('Units to display by default (SI vs IP)', self)
        checked_header = Qt.Checked if self.prefs['save_units'] == 1 else Qt.Unchecked
        self.save_units_check.setCheckState(checked_header)
        self.save_units_check.stateChanged.connect(self.update)
        self.save_hidden_classes_check = QCheckBox('Whether empty classes are hidden', self)
        checked_cells = Qt.Checked if self.prefs['save_hidden_classes'] == 1 else Qt.Unchecked
        self.save_hidden_classes_check.setCheckState(checked_cells)
        self.save_hidden_classes_check.stateChanged.connect(self.update)
        self.save_groups_check = QCheckBox('Whether to hide group headers', self)
        checked_groups = Qt.Checked if self.prefs['save_hide_groups'] == 1 else Qt.Unchecked
        self.save_groups_check.setCheckState(checked_groups)
        self.save_groups_check.stateChanged.connect(self.update)

        # Save additional options group box code
        self.save_additional_group_box = QGroupBox("Save Additional Options in IDF File")
        save_additional_box = QVBoxLayout()
        save_additional_box.addWidget(self.save_units_check)
        save_additional_box.addWidget(self.save_hidden_classes_check)
        save_additional_box.addWidget(self.save_groups_check)
        save_additional_box.addStretch(1)
        self.save_additional_group_box.setLayout(save_additional_box)

        # Main layout code
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.save_additional_group_box)
        main_layout.addSpacing(10)
        main_layout.addWidget(self.save_group_box)
        main_layout.addStretch(1)
        self.setLayout(main_layout)

    def update_order(self):
        text = self.order_edit.currentText()
        for key, val in list(self.order_options.items()):
            if val == text:
                to_save = key
        self.prefs['sort_order'] = to_save

    def update_format(self):
        text = self.format_edit.currentText()
        for key, val in self.format_options.items():
            if val == text:
                to_save = key
        self.prefs['format'] = to_save

    def update(self):
        self.prefs['save_units'] = 1 if self.save_units_check.checkState() else 0
        self.prefs['save_hidden_classes'] = 1 if self.save_hidden_classes_check.checkState() else 0
        self.prefs['save_hide_groups'] = 1 if self.save_groups_check.checkState() else 0