Esempio n. 1
0
    def __init__(self, dockwidget):
        super(Widget, self).__init__(dockwidget)
        self._document = None
        self._fileSelector = QComboBox(editable=True, insertPolicy=QComboBox.NoInsert)
        gadgets.drag.ComboDrag(self._fileSelector).role = Qt.UserRole
        self._fileSelector.lineEdit().setReadOnly(True)
        self._fileSelector.lineEdit().setFocusPolicy(Qt.NoFocus)
        self._stopButton = QToolButton()
        self._playButton = QToolButton()
        self._timeSlider = QSlider(Qt.Horizontal, tracking=False,
            singleStep=500, pageStep=5000, invertedControls=True)
        self._display = Display()
        self._tempoFactor = QSlider(Qt.Vertical, minimum=-50, maximum=50,
            singleStep=1, pageStep=5)

        grid = QGridLayout(spacing=0)
        self.setLayout(grid)

        grid.addWidget(self._fileSelector, 0, 0, 1, 3)
        grid.addWidget(self._stopButton, 1, 0)
        grid.addWidget(self._playButton, 1, 1)
        grid.addWidget(self._timeSlider, 1, 2)
        grid.addWidget(self._display, 2, 0, 1, 3)
        grid.addWidget(self._tempoFactor, 0, 3, 3, 1)

        # size policy of combo
        p = self._fileSelector.sizePolicy()
        p.setHorizontalPolicy(QSizePolicy.Ignored)
        self._fileSelector.setSizePolicy(p)

        # size policy of combo popup
        p = self._fileSelector.view().sizePolicy()
        p.setHorizontalPolicy(QSizePolicy.MinimumExpanding)
        self._fileSelector.view().setSizePolicy(p)

        self._player = player.Player()
        self._outputCloseTimer = QTimer(interval=60000, singleShot=True,
            timeout=self.closeOutput)
        self._timeSliderTicker = QTimer(interval=200, timeout=self.updateTimeSlider)
        self._fileSelector.activated[int].connect(self.slotFileSelected)
        self._tempoFactor.valueChanged.connect(self.slotTempoChanged)
        self._timeSlider.valueChanged.connect(self.slotTimeSliderChanged)
        self._timeSlider.sliderMoved.connect(self.slotTimeSliderMoved)
        self._player.beat.connect(self.updateDisplayBeat)
        self._player.time.connect(self.updateDisplayTime)
        self._player.stateChanged.connect(self.slotPlayerStateChanged)
        self.slotPlayerStateChanged(False)
        dockwidget.mainwindow().currentDocumentChanged.connect(self.loadResults)
        app.documentLoaded.connect(self.slotDocumentLoaded)
        app.jobFinished.connect(self.slotUpdatedFiles)
        app.aboutToQuit.connect(self.stop)
        midihub.aboutToRestart.connect(self.slotAboutToRestart)
        midihub.settingsChanged.connect(self.clearMidiSettings, -100)
        midihub.settingsChanged.connect(self.readMidiSettings)
        app.documentClosed.connect(self.slotDocumentClosed)
        app.translateUI(self)
        self.readMidiSettings()
        d = dockwidget.mainwindow().currentDocument()
        if d:
            self.loadResults(d)
Esempio n. 2
0
    def drawSpan(self, painter, rect):
        opt = QStyleOptionSlider()
        QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QPen(self.gradientLeftColor, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation, groove.center().x(),
                              groove.top(), groove.center().x(),
                              groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(),
                              groove.center().y(), groove.right(),
                              groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QLinearGradient(intersected.topLeft(), intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)
Esempio n. 3
0
    def createUI(self):
        """Set up the user interface, signals & slots
        """
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        # In this widget, the video will be drawn
        if sys.platform == "darwin": # for MacOS
            from PyQt5.QtWidgets import QMacCocoaViewContainer	
            self.videoframe = QMacCocoaViewContainer(0)
        else:
            self.videoframe = QFrame()
        self.palette = self.videoframe.palette()
        self.palette.setColor (QPalette.Window,
                               QColor(0,0,0))
        self.videoframe.setPalette(self.palette)
        self.videoframe.setAutoFillBackground(True)

        self.positionslider = QSlider(Qt.Horizontal, self)
        self.positionslider.setToolTip("Position")
        self.positionslider.setMaximum(1000)
        self.positionslider.sliderMoved.connect(self.setPosition)

        self.hbuttonbox = QHBoxLayout()
        self.playbutton = QPushButton("Play")
        self.hbuttonbox.addWidget(self.playbutton)
        self.playbutton.clicked.connect(self.PlayPause)

        self.stopbutton = QPushButton("Stop")
        self.hbuttonbox.addWidget(self.stopbutton)
        self.stopbutton.clicked.connect(self.Stop)

        self.hbuttonbox.addStretch(1)
        self.volumeslider = QSlider(Qt.Horizontal, self)
        self.volumeslider.setMaximum(100)
        self.volumeslider.setValue(self.mediaplayer.audio_get_volume())
        self.volumeslider.setToolTip("Volume")
        self.hbuttonbox.addWidget(self.volumeslider)
        self.volumeslider.valueChanged.connect(self.setVolume)

        self.vboxlayout = QVBoxLayout()
        self.vboxlayout.addWidget(self.videoframe)
        self.vboxlayout.addWidget(self.positionslider)
        self.vboxlayout.addLayout(self.hbuttonbox)

        self.widget.setLayout(self.vboxlayout)

        open = QAction("&Open", self)
        open.triggered.connect(self.OpenFile)
        exit = QAction("&Exit", self)
        exit.triggered.connect(sys.exit)
        menubar = self.menuBar()
        filemenu = menubar.addMenu("&File")
        filemenu.addAction(open)
        filemenu.addSeparator()
        filemenu.addAction(exit)

        self.timer = QTimer(self)
        self.timer.setInterval(200)
        self.timer.timeout.connect(self.updateUI)
Esempio n. 4
0
    def createBottomRightGroupBox(self):
        self.bottomRightGroupBox = QGroupBox("Group 3")
        self.bottomRightGroupBox.setCheckable(True)
        self.bottomRightGroupBox.setChecked(True)

        lineEdit = QLineEdit('s3cRe7')
        lineEdit.setEchoMode(QLineEdit.Password)

        spinBox = QSpinBox(self.bottomRightGroupBox)
        spinBox.setValue(50)

        dateTimeEdit = QDateTimeEdit(self.bottomRightGroupBox)
        dateTimeEdit.setDateTime(QDateTime.currentDateTime())

        slider = QSlider(Qt.Horizontal, self.bottomRightGroupBox)
        slider.setValue(40)

        scrollBar = QScrollBar(Qt.Horizontal, self.bottomRightGroupBox)
        scrollBar.setValue(60)

        dial = QDial(self.bottomRightGroupBox)
        dial.setValue(30)
        dial.setNotchesVisible(True)

        layout = QGridLayout()
        layout.addWidget(lineEdit, 0, 0, 1, 2)
        layout.addWidget(spinBox, 1, 0, 1, 2)
        layout.addWidget(dateTimeEdit, 2, 0, 1, 2)
        layout.addWidget(slider, 3, 0)
        layout.addWidget(scrollBar, 4, 0)
        layout.addWidget(dial, 3, 1, 2, 1)
        layout.setRowStretch(5, 1)
        self.bottomRightGroupBox.setLayout(layout)
Esempio n. 5
0
class PlayerControls(QWidget):

    def __init__(self, parent=None):
        super().__init__(parent)
        layout = QHBoxLayout(self)

        self.seek_slider = QSlider(orientation=Qt.Horizontal, parent=self)
        self.volume_slider = QSlider(orientation=Qt.Horizontal, maximum=1000,
                                     parent=self)
        self.playback_time = QLabel(parent=self)
        self.duration = QLabel(parent=self)

        layout.addWidget(self.seek_slider)
        layout.addWidget(self.volume_slider)
        layout.addWidget(self.playback_time)
        layout.addWidget(self.duration)

        self.setLayout(layout)

    @pyqtSlot(float)
    def update_seek_slider_position(self, val):
        if not self.seek_slider.isSliderDown():
            self.seek_slider.setSliderPosition(val * 1000)

    @pyqtSlot(float)
    def update_seek_slider_maximum(self, val):
        self.seek_slider.setMaximum(val * 1000)

    @pyqtSlot(float)
    def update_duration(self, val):
        self.duration.setText('{:.2f}'.format(val))

    @pyqtSlot(float)
    def update_playback_time(self, val):
        self.playback_time.setText('{:.2f}'.format(val))
    def mousePressEvent(self, QMouseEvent):
        print("fug :-D")

        if QMouseEvent.button() == Qt.LeftButton:
            time = self.minimum() + ((self.maximum()-self.minimum()) * QMouseEvent.x()) / self.width()
            self.parent().seek(time)
            self.setValue(time)

        QSlider.mousePressEvent(self, QMouseEvent)
Esempio n. 7
0
 def __init__(self, window, config, callback):
     QSlider.__init__(self, Qt.Horizontal)
     self.config = config
     self.window = window
     self.callback = callback
     self.dyn = False
     self.lock = threading.RLock()
     self.update()
     self.valueChanged.connect(self.moved)
Esempio n. 8
0
    def createGUI(self):
        self.widget = QWidget(self)
        self.gvMain = MainView(self, 0, self.blocks)
        self.views = {key: XYZview(self, self.blocks, key)
                for key in ('xy', 'yz', 'zx')}
        self.cbSelectBox = QComboBox(self)
        self.pbAddBox = QPushButton("Add Box", self)
        self.pbDeleteBox = QPushButton("Delete selected box", self)
        self.slScale = QSlider(self)
        self.slScale.setOrientation(Qt.Horizontal)
        self.slScale.setRange(2, 15)
        self.slScale.setValue(5)
        self.slResolution = QSlider(self)
        self.slResolution.setOrientation(Qt.Horizontal)
        self.slResolution.setRange(1, 6) # resolution is 2**this_value
        self.slResolution.setValue(4) # 2**4 is 16 -- initial resolution
        self.turn_buttons = {'x': QPushButton("Turn around X axis", self),
                             'y': QPushButton("Turn around Y axis", self),
                             'z': QPushButton("Turn around Z axis", self)}
        self.swap_buttons = {'xy': QPushButton("Swap X and Y", self),
                             'yz': QPushButton("Swap Y and Z", self),
                             'zx': QPushButton("Swap Z and X", self)}
        self.grLayout = QGridLayout()
        self.grLayout.addWidget(QLabel("Main view"), 0, 0)
        self.grLayout.addWidget(self.gvMain, 1, 0)
        self.grLayout.addWidget(QLabel("Y view"), 0, 1)
        self.grLayout.addWidget(self.views['zx'], 1, 1)

        self.vbRightLayout = QVBoxLayout()
        self.vbRightLayout.addWidget(QLabel("Select box"))
        self.vbRightLayout.addWidget(self.cbSelectBox)
        self.vbRightLayout.addWidget(self.pbAddBox)
        self.vbRightLayout.addWidget(self.pbDeleteBox)
        self.vbRightLayout.addWidget(QLabel("Scale"))
        self.vbRightLayout.addWidget(self.slScale)
        self.vbRightLayout.addWidget(QLabel("Resolution"))
        self.vbRightLayout.addWidget(self.slResolution)
        self.vbRightLayout.addItem(
            QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding))
        for button in self.swap_buttons.values():
            self.vbRightLayout.addWidget(button)
        for button in self.turn_buttons.values():
            self.vbRightLayout.addWidget(button)

        self.hbMainLayout = QHBoxLayout()
        self.hbMainLayout.addLayout(self.grLayout, 10)
        self.hbMainLayout.addLayout(self.vbRightLayout, 1)

        self.grLayout.addWidget(QLabel("X view"), 2, 0)
        self.grLayout.addWidget(self.views['yz'], 3, 0)
        self.grLayout.addWidget(QLabel("Z view"), 2, 1)
        self.grLayout.addWidget(self.views['xy'], 3, 1)
        self.widget.setLayout(self.hbMainLayout)
        self.setCentralWidget(self.widget)
        self.setWindowTitle("Nodebox editor")
        self.resize(1000, 600)
Esempio n. 9
0
class ColorConvertor(QDialog):
    def __init__(self,parent=None):
        super().__init__(parent=parent)
        self.colorR = 255
        self.colorG = 255
        self.colorB = 255
        self.opacity = 255
        self.color = QColor(self.colorR,self.colorG,self.colorB)
        #RGB
        rgbLayout=QFormLayout()
        labelR = QLabel("R")
        self.sliderR = QSlider(Qt.Horizontal)
        labelG = QLabel("G")
        self.sliderG = QSlider(Qt.Horizontal)
        labelB = QLabel("B")
        self.sliderB = QSlider(Qt.Horizontal)
        labelOpacity = QLabel("opacity")
        self.sliderOpacity = QSlider(Qt.Horizontal)
        for (l,s) in ((labelR,self.sliderR),(labelG,self.sliderG),(labelB,self.sliderB),(labelOpacity,self.sliderOpacity)):
            rgbLayout.addRow(l,s)
            s.setMinimum(0)
            s.setMaximum(255)
            s.setValue(255)
            s.setSingleStep(10)
            s.valueChanged.connect(self.changeColor)


        self.label = QLabel()
        self.label.setTextInteractionFlags(Qt.TextSelectableByMouse)#可复制
        self.label.setText('''RGB:{colorR} {colorG} {colorB}  HTML:#{colorR:02X}{colorG:02X}{colorB:02X}
opacity:{opacity}'''.format(colorR=self.colorR,colorG=self.colorG,colorB=self.colorB,opacity=self.opacity))

        mainLayout=QVBoxLayout()
        mainLayout.addLayout(rgbLayout)
        mainLayout.addWidget(self.label)

        self.setLayout(mainLayout)

    def paintEvent(self,event):
        painter = QPainter()
        painter.begin(self)
        painter.fillRect(event.rect(),QBrush(self.color))
        painter.end()


    def changeColor(self,value):
        self.colorR = self.sliderR.value()
        self.colorG = self.sliderG.value()
        self.colorB = self.sliderB.value()
        self.opacity = self.sliderOpacity.value()
        self.color = QColor(self.colorR,self.colorG,self.colorB,self.opacity)

        self.label.setText('''RGB:{colorR} {colorG} {colorB}  HTML:#{colorR:02X}{colorG:02X}{colorB:02X}
opacity:{opacity}'''.format(colorR=self.colorR,colorG=self.colorG,colorB=self.colorB,opacity=self.opacity))
        self.update()
Esempio n. 10
0
    def create_slider(self, label, idx, precision_sld, lower_bound, upper_bound, slider_fun):
        # create slider
        sld = QSlider(QtCore.Qt.Horizontal, self)
        sld.id = idx
        sld.precision = precision_sld

        # display label
        layout_disp = QHBoxLayout()
        sld.label = QLabel(label)
        sld.label.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft)
        layout_disp.addWidget(sld.label)

        # display of current value
        sld.value = QLabel('Value: 0')
        sld.value.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight)
        layout_disp.addWidget(sld.value)

        # slider layout
        layout_sld = QVBoxLayout()
        layout_sld.addLayout(layout_disp)
        layout_sld.addWidget(sld)

        # settings
        sld.setFocusPolicy(QtCore.Qt.NoFocus)
        sld.valueChanged.connect(slider_fun)
        sld.setRange(int(np.round(lower_bound/precision_sld, 0)),
                     int(np.round(upper_bound/precision_sld, 0)))
        return layout_sld, sld
Esempio n. 11
0
 def __init__(self, army):
     super().__init__()
     self.addLabels()
     self.cavSld = QSlider(Qt.Horizontal, self)
     self.cavSld.move(150, 40)
     self.infSld = QSlider(Qt.Horizontal, self)
     self.infSld.move(0, 40)
     self.addNumbers()
     accept = QPushButton("Accept", self)
     accept.move(100, 150)
     accept.clicked.connect(self.accept)
Esempio n. 12
0
    def __init__(self, *args):
        super().__init__(BrickletMotorizedLinearPoti, *args)

        self.mp = self.device

        self.cbe_position = CallbackEmulator(self.mp.get_position,
                                             None,
                                             self.cb_position,
                                             self.increase_error_count)

        self.current_position = CurveValueWrapper()

        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, 100)
        self.slider.setMinimumWidth(200)
        self.slider.setEnabled(False)

        plots = [('Potentiometer Position', Qt.red, self.current_position, str)]
        self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider],
                                      update_interval=0.025, y_resolution=1.0)

        self.motor_slider = QSlider(Qt.Horizontal)
        self.motor_slider.setRange(0, 100)
        self.motor_slider.valueChanged.connect(self.motor_slider_value_changed)
        self.motor_hold_position = QCheckBox("Hold Position")
        self.motor_drive_mode = QComboBox()
        self.motor_drive_mode.addItem('Fast')
        self.motor_drive_mode.addItem('Smooth')

        def get_motor_slider_value():
            return self.motor_slider.value()

        self.motor_hold_position.stateChanged.connect(lambda x: self.motor_slider_value_changed(get_motor_slider_value()))
        self.motor_drive_mode.currentIndexChanged.connect(lambda x: self.motor_slider_value_changed(get_motor_slider_value()))

        self.motor_position_label = MotorPositionLabel('Motor Target Position:')

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.motor_position_label)
        hlayout.addWidget(self.motor_slider)
        hlayout.addWidget(self.motor_drive_mode)
        hlayout.addWidget(self.motor_hold_position)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
    def createEditor(self, parent, option, index):
        editor = QSlider(parent=parent, orientation=Qt.Horizontal)
        editor.setRange(0, 5)
        editor.setAutoFillBackground(True)

        editor.setTickPosition(QSlider.TicksBelow)
        editor.setTickInterval(1)

        return editor
Esempio n. 14
0
class AudioPanSettings(SettingsSection):

    NAME = "Pan"
    ELEMENT = AudioPan

    def __init__(self, size, Id, parent=None):
        super().__init__(size, parent)

        self.id = Id

        self.panBox = QGroupBox(self)
        self.panBox.setGeometry(0, 0, self.width(), 80)
        self.panBox.setLayout(QHBoxLayout(self.panBox))

        self.panSlider = QSlider(self.panBox)
        self.panSlider.setRange(-10, 10)
        self.panSlider.setPageStep(1)
        self.panSlider.setOrientation(Qt.Horizontal)
        self.panSlider.valueChanged.connect(self.pan_changed)
        self.panBox.layout().addWidget(self.panSlider)

        self.panLabel = QLabel(self.panBox)
        self.panLabel.setAlignment(Qt.AlignCenter)
        self.panBox.layout().addWidget(self.panLabel)

        self.panBox.layout().setStretch(0, 5)
        self.panBox.layout().setStretch(1, 1)

        self.retransaleUi()

    def retransaleUi(self):
        self.panBox.setTitle("Audio Pan")
        self.panLabel.setText("Center")

    def enable_check(self, enable):
        self.panBox.setCheckable(enable)
        self.panBox.setChecked(False)

    def get_configuration(self):
        conf = {}

        if not (self.panBox.isCheckable() and not self.panBox.isChecked()):
            conf["panorama"] = self.panSlider.value() / 10

        return {self.id: conf}

    def set_configuration(self, conf):
        if conf is not None and self.id in conf:
            self.panSlider.setValue(conf[self.id]["panorama"] * 10)

    def pan_changed(self, value):
        if value < 0:
            self.panLabel.setText("Left")
        elif value > 0:
            self.panLabel.setText("Right")
        else:
            self.panLabel.setText("Center")
Esempio n. 15
0
class ControlWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        
        self.directionSlider = QSlider(Qt.Horizontal, self)
        self.directionSlider.setMinimum(0)
        self.directionSlider.setMaximum(360)

        self.direction = QLCDNumber(self)
        self.directionSlider.valueChanged.connect(self.direction.display)
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)
        self.layout.addWidget(self.directionSlider)
        self.layout.addWidget(self.direction)
Esempio n. 16
0
    def initUI(self):     
 
        sld = QSlider(Qt.Horizontal, self)
        sld.setFocusPolicy(Qt.NoFocus)
        sld.setGeometry(30, 40, 100, 30)
        sld.valueChanged[int].connect(self.changeValue)
         
        self.label = QLabel(self)
        self.label.setPixmap(QPixmap('mute.png'))
        self.label.setGeometry(160, 40, 80, 30)
         
        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle('QSlider')
        self.show()
Esempio n. 17
0
class AudioPanSettings(GstElementSettingsPage):

    NAME = 'Pan'
    ELEMENT = AudioPan

    def __init__(self, element_id, **kwargs):
        super().__init__(element_id)
        self.setLayout(QVBoxLayout())
        self.layout().setAlignment(Qt.AlignTop)

        self.panBox = QGroupBox(self)
        self.panBox.setGeometry(0, 0, self.width(), 80)
        self.panBox.setLayout(QHBoxLayout(self.panBox))
        self.layout().addWidget(self.panBox)

        self.panSlider = QSlider(self.panBox)
        self.panSlider.setRange(-10, 10)
        self.panSlider.setPageStep(1)
        self.panSlider.setOrientation(Qt.Horizontal)
        self.panSlider.valueChanged.connect(self.pan_changed)
        self.panBox.layout().addWidget(self.panSlider)

        self.panLabel = QLabel(self.panBox)
        self.panLabel.setAlignment(Qt.AlignCenter)
        self.panBox.layout().addWidget(self.panLabel)

        self.panBox.layout().setStretch(0, 5)
        self.panBox.layout().setStretch(1, 1)

        self.retransaleUi()

    def retransaleUi(self):
        self.panBox.setTitle('Audio Pan')
        self.panLabel.setText('Center')

    def enable_check(self, enable):
        self.panBox.setCheckable(enable)
        self.panBox.setChecked(False)

    def get_settings(self):
        conf = {}

        if not (self.panBox.isCheckable() and not self.panBox.isChecked()):
            conf['pan'] = self.panSlider.value() / 10

        return {self.id: conf}

    def load_settings(self, settings):
        if settings is not None and self.id in settings:
            self.panSlider.setValue(settings[self.id]['pan'] * 10)

    def pan_changed(self, value):
        position = 'Left' if value < 0 else 'Right' if value > 0 else 'Center'
        self.panLabel.setText('{0} - {1}'.format(value, position))
Esempio n. 18
0
class Window(QWidget):
    """
    The main window of the application. Houses a media player and related
    controls.
    """
    def __init__(self):
        super().__init__()

        layout = QVBoxLayout()
        self.slider = QSlider(Qt.Horizontal)
        btnOpen = QPushButton("Open")
        btnPlay = QPushButton("Play")
        self.player = QMediaPlayer()
        tl = Timeline(None, None)
        tlscroll = QScrollArea()
        tlscroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        tlscroll.setWidget(tl)

        btnOpen.clicked.connect(self.open)
        btnPlay.clicked.connect(self.play)

        self.player.durationChanged.connect(self.durationChanged)
        self.player.positionChanged.connect(self.positionChanged)

        layout.addWidget(self.slider)
        layout.addWidget(btnOpen)
        layout.addWidget(btnPlay)
        layout.addWidget(tlscroll)
        self.setLayout(layout)

    def open(self):
        fileName = QFileDialog.getOpenFileName(self, "Open File")[0]
        fileInfo = QFileInfo(fileName)
        if fileInfo.exists():
            url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
            self.changeMedia(QMediaContent(url))

    def play(self):
        self.player.play()

    def changeMedia(self, mediaContent):
        self.player.setMedia(mediaContent)

    def durationChanged(self, duration):
        self.slider.setRange(0, duration)

    def positionChanged(self, position):
        self.slider.setValue(position)
    def __init__(self):
        QWidget.__init__(self)

        # Handle to the image stack tiffcapture object.
        self._tiffCaptureHandle = None
        self.currentFrameIndex = None

        # Image frame viewer.
        self.viewer = ImageViewerQt()

        # Slider and arrow buttons for frame traversal.
        self.frameSlider = QSlider(Qt.Horizontal)
        self.prevFrameButton = QPushButton("<")
        self.nextFrameButton = QPushButton(">")
        self.currentFrameLabel = QLabel()

        self.prevFrameButton.clicked.connect(self.prevFrame)
        self.nextFrameButton.clicked.connect(self.nextFrame)
        self.frameSlider.valueChanged.connect(self.showFrame)

        # Layout.
        grid = QGridLayout(self)
        grid.addWidget(self.currentFrameLabel, 0, 0, 1, 3)
        grid.addWidget(self.viewer, 1, 0, 1, 3)
        grid.addWidget(self.prevFrameButton, 2, 0)
        grid.addWidget(self.frameSlider, 2, 1)
        grid.addWidget(self.nextFrameButton, 2, 2)
        grid.setContentsMargins(2, 2, 2, 2)
        grid.setSpacing(0)
Esempio n. 20
0
    def __init__(self, parent):
        super(PercentSlider, self).__init__(parent)

        self._slider = QSlider(Qt.Vertical, self)
        self._slider.setMinimum(-100)
        self._slider.setMaximum(100)
        self._slider.setValue(0)
        self._slider.setTickInterval(100)
        self._slider.setTickPosition(QSlider.TicksBothSides)
        self._slider.valueChanged.connect(lambda: self._spinbox.setValue(self._slider.value()))

        self._spinbox = QSpinBox(self)
        self._spinbox.setMinimum(-100)
        self._spinbox.setMaximum(100)
        self._spinbox.setValue(0)
        self._spinbox.valueChanged.connect(lambda: self._slider.setValue(self._spinbox.value()))

        self._zero_button = make_icon_button("hand-stop-o", "Zero setpoint", self, on_clicked=self.zero)

        layout = QVBoxLayout(self)
        sub_layout = QHBoxLayout(self)
        sub_layout.addStretch()
        sub_layout.addWidget(self._slider)
        sub_layout.addStretch()
        layout.addLayout(sub_layout)
        layout.addWidget(self._spinbox)
        layout.addWidget(self._zero_button)
        self.setLayout(layout)

        self.setMinimumHeight(400)
Esempio n. 21
0
    def __init__(self, element_id, **kwargs):
        super().__init__(element_id)
        self.setLayout(QVBoxLayout())
        self.layout().setAlignment(Qt.AlignTop)

        self.panBox = QGroupBox(self)
        self.panBox.setGeometry(0, 0, self.width(), 80)
        self.panBox.setLayout(QHBoxLayout(self.panBox))
        self.layout().addWidget(self.panBox)

        self.panSlider = QSlider(self.panBox)
        self.panSlider.setRange(-10, 10)
        self.panSlider.setPageStep(1)
        self.panSlider.setOrientation(Qt.Horizontal)
        self.panSlider.valueChanged.connect(self.pan_changed)
        self.panBox.layout().addWidget(self.panSlider)

        self.panLabel = QLabel(self.panBox)
        self.panLabel.setAlignment(Qt.AlignCenter)
        self.panBox.layout().addWidget(self.panLabel)

        self.panBox.layout().setStretch(0, 5)
        self.panBox.layout().setStretch(1, 1)

        self.retransaleUi()
Esempio n. 22
0
 def initPositionSlider(self):
     """Initialize position slider."""
     self.positionSlider = QSlider(Qt.Horizontal, self)
     self.positionSlider.setValue(0)
     self.positionSlider.valueChanged[int].connect(self.position)
     self.positionSliderClicked = False
     self.grid.addWidget(self.positionSlider, 0, 0, 1, 3, Qt.AlignBottom)
Esempio n. 23
0
	def __init__(self, parent, update_callback):
		QWidget.__init__(self, parent)
		self.layout = QGridLayout()
		self.setLayout(self.layout)
		self.update_callback = update_callback


		self.light_value = QSlider(self)
		self.hue_value = QDial(self)
		self.saturation_value = QDial(self)
		self.monitor = Monitor(self)

		self.layout.addWidget(QLabel('Hue'), 0, 0, Qt.AlignHCenter)
		self.layout.addWidget(self.hue_value, 1, 0, Qt.AlignHCenter)
		self.layout.addWidget(QLabel('Saturation'), 2, 0, Qt.AlignHCenter)
		self.layout.addWidget(self.saturation_value, 3, 0, Qt.AlignHCenter)
		self.layout.addWidget(self.monitor, 4, 0, Qt.AlignHCenter)
		self.layout.addWidget(QLabel('Intensity'), 5, 0, Qt.AlignHCenter)
		self.layout.addWidget(self.light_value, 6, 0, Qt.AlignHCenter)

		self.update()

		self.hue_value.valueChanged.connect(self.update)
		self.saturation_value.valueChanged.connect(self.update)
		self.light_value.valueChanged.connect(self.update)
Esempio n. 24
0
    def initializeWindow(self):
        layout = QVBoxLayout()

        self.m_deviceBox = QComboBox(activated=self.deviceChanged)
        for deviceInfo in QAudioDeviceInfo.availableDevices(QAudio.AudioOutput):
            self.m_deviceBox.addItem(deviceInfo.deviceName(), deviceInfo)

        layout.addWidget(self.m_deviceBox)

        self.m_modeButton = QPushButton(clicked=self.toggleMode)
        self.m_modeButton.setText(self.PUSH_MODE_LABEL)

        layout.addWidget(self.m_modeButton)

        self.m_suspendResumeButton = QPushButton(
                clicked=self.toggleSuspendResume)
        self.m_suspendResumeButton.setText(self.SUSPEND_LABEL)

        layout.addWidget(self.m_suspendResumeButton)

        volumeBox = QHBoxLayout()
        volumeLabel = QLabel("Volume:")
        self.m_volumeSlider = QSlider(Qt.Horizontal, minimum=0, maximum=100,
                singleStep=10, valueChanged=self.volumeChanged)
        volumeBox.addWidget(volumeLabel)
        volumeBox.addWidget(self.m_volumeSlider)

        layout.addLayout(volumeBox)

        window = QWidget()
        window.setLayout(layout)

        self.setCentralWidget(window)
Esempio n. 25
0
    def __init__(self, size, Id, parent=None):
        super().__init__(size, parent)

        self.id = Id

        self.groupBox = QGroupBox(self)
        self.groupBox.setGeometry(0, 0, self.width(), 80)

        self.layout = QHBoxLayout(self.groupBox)

        self.pitchSlider = QSlider(self.groupBox)
        self.pitchSlider.setMinimum(-12)
        self.pitchSlider.setMaximum(12)
        self.pitchSlider.setPageStep(1)
        self.pitchSlider.setValue(0)
        self.pitchSlider.setOrientation(QtCore.Qt.Horizontal)
        self.pitchSlider.setTickPosition(QSlider.TicksAbove)
        self.pitchSlider.setTickInterval(1)
        self.layout.addWidget(self.pitchSlider)

        self.pitchLabel = QLabel(self.groupBox)
        self.pitchLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.layout.addWidget(self.pitchLabel)

        self.layout.setStretch(0, 3)
        self.layout.setStretch(1, 1)

        self.pitchSlider.valueChanged.connect(self.pitch_changed)

        self.retranslateUi()
Esempio n. 26
0
    def __init__(self, orientation, title, parent=None):
        super(SlidersGroup, self).__init__(title, parent)

        self.slider = QSlider(orientation)
        self.slider.setFocusPolicy(Qt.StrongFocus)
        self.slider.setTickPosition(QSlider.TicksBothSides)
        self.slider.setTickInterval(10)
        self.slider.setSingleStep(1)

        self.scrollBar = QScrollBar(orientation)
        self.scrollBar.setFocusPolicy(Qt.StrongFocus)

        self.dial = QDial()
        self.dial.setFocusPolicy(Qt.StrongFocus)

        self.slider.valueChanged.connect(self.scrollBar.setValue)
        self.scrollBar.valueChanged.connect(self.dial.setValue)
        self.dial.valueChanged.connect(self.slider.setValue)
        self.dial.valueChanged.connect(self.valueChanged)

        if orientation == Qt.Horizontal:
            direction = QBoxLayout.TopToBottom
        else:
            direction = QBoxLayout.LeftToRight

        slidersLayout = QBoxLayout(direction)
        slidersLayout.addWidget(self.slider)
        slidersLayout.addWidget(self.scrollBar)
        slidersLayout.addWidget(self.dial)
        self.setLayout(slidersLayout)    
Esempio n. 27
0
    def initUI(self):
        self.player = QMediaPlayer()
        self.playlist = QMediaPlaylist()
        vbox = QVBoxLayout()
        hbox = QHBoxLayout()
        self.setGeometry(300, 300, 290, 150)
        self.slider = QSlider(Qt.Horizontal)
        self.playBtn = QPushButton('►')
        self.nextBtn = QPushButton('>')
        self.prevBtn = QPushButton('<')

        self.nextBtn.clicked.connect(self.nextSong)
        self.prevBtn.clicked.connect(self.prevSong)

        self.playBtn.clicked.connect(self.playSong)
        self.setWindowTitle('VK music')
        self.list = QListWidget(self)
        self.list.currentItemChanged.connect(self.selectSong)

        for track in self.vk.method('audio.get').get('items'):
            self.list.addItem(SongWidgetItem(track))
            self.playlist.addMedia(QMediaContent(QUrl(track['url'])))

        hbox.addWidget(self.prevBtn)
        hbox.addWidget(self.playBtn)
        hbox.addWidget(self.nextBtn)
        hbox.addWidget(self.slider)

        self.player.setPlaylist(self.playlist)
        self.player.positionChanged.connect(self.setPosition)
        vbox.addWidget(self.list)
        vbox.addLayout(hbox)
        self.setLayout(vbox)
        self.show()
    def __init__(self, parent=None, display_status=False):
        super(VideoPlayer, self).__init__(parent)

        self.display_status = display_status

        self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)

        self.videoItem = QGraphicsVideoItem()

        scene = QGraphicsScene(self)
        graphicsView = QGraphicsView(scene)

        scene.addItem(self.videoItem)

        self.playButton = QPushButton()
        self.playButton.setEnabled(False)
        self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
        self.playButton.clicked.connect(self.play)

        self.positionSlider = QSlider(Qt.Horizontal)
        self.positionSlider.setRange(0, 0)
        self.positionSlider.sliderMoved.connect(self.setPosition)
        
        if self.display_status:
            self.status_mapping = {
                QMediaPlayer.UnknownMediaStatus: "UnknownMediaStatus",
                QMediaPlayer.NoMedia: "NoMedia",
                QMediaPlayer.LoadingMedia: "LoadingMedia",
                QMediaPlayer.LoadedMedia: "LoadedMedia",
                QMediaPlayer.StalledMedia: "StalledMedia", 
                QMediaPlayer.BufferingMedia: "BufferingMedia",
                QMediaPlayer.BufferedMedia: "BufferedMedia",
                QMediaPlayer.EndOfMedia: "EndOfMedia",
                QMediaPlayer.InvalidMedia: "InvalidMedia"
            }
            self.statusText = QPlainTextEdit()
            self.statusText.setReadOnly(True)
            self.statusText.setFixedHeight(25)
            self.statusText.setFixedWidth(150)
            self.mediaPlayer.mediaStatusChanged.connect(self.mediaStatusChanged)

        controlLayout = QHBoxLayout()
        controlLayout.setContentsMargins(0, 0, 0, 0)
        controlLayout.addWidget(self.playButton)
        controlLayout.addWidget(self.positionSlider)
        if self.display_status:
            controlLayout.addWidget(self.statusText)

        layout = QVBoxLayout()
        layout.addWidget(graphicsView)
        layout.addLayout(controlLayout)
        self.setFixedWidth(WIDTH + WIGGLE)

        self.setLayout(layout)

        self.mediaPlayer.setVideoOutput(self.videoItem)
        self.mediaPlayer.stateChanged.connect(self.mediaStateChanged)
        self.mediaPlayer.positionChanged.connect(self.positionChanged)
        self.mediaPlayer.durationChanged.connect(self.durationChanged)
Esempio n. 29
0
    def __init__(self, data_manager, pca):
        super(FitterDialog, self).__init__()
        self.setupUi(self)
        self.setAttribute(Qt.WA_DeleteOnClose)

        assert isinstance(data_manager, DataManager)
        self.data_manager = data_manager
        self.pca = pca
        self.active_shape_model = ActiveShapeModel(self.data_manager, self.pca)
        self.initial_pose_model = InitialPoseModel(self.data_manager)

        self.scene = InteractiveGraphicsScene()
        self.graphicsView.setScene(self.scene)
        self.scene.clicked.connect(self._set_position)

        self.image = self.data_manager.radiographs[0].image
        self.radiograph_image = Filter.crop_image(self.data_manager.radiographs[0].image)

        self.openButton.clicked.connect(self._open_radiograph)
        self.exportButton.clicked.connect(self._export_result)
        self.exportButton.setEnabled(False)

        self.zoomSlider.setRange(-10, 10)
        self.zoomSlider.setValue(self.current_scale)
        self.zoomSlider.valueChanged.connect(self.change_scale)

        self.levelSlider.setRange(1, MultiResolutionFramework.levels_count)
        self.levelSlider.setValue(self.current_sampling_level + 1)
        self.levelSlider.valueChanged.connect(self.user_change_level)

        self.stepButton.clicked.connect(self._perform_one_step_asm)
        self.animateButton.clicked.connect(self._animator_entry)

        self._scales = np.empty(self.pca.eigen_values.shape)
        for i, deviation in enumerate(self.pca.get_allowed_deviation()):
            slider = QSlider(Qt.Horizontal, self.paramsScrollAreaContents)
            slider.setRange(-self.slider_resolution, self.slider_resolution)
            # slider.valueChanged.connect(self.slider_moved)
            self.paramsScrollAreaContents.layout().addWidget(slider)
            self._scales[i] = deviation / self.slider_resolution

        self.show_sampled_positions = self.sampledPositionsCheckBox.isChecked()
        self.sampledPositionsCheckBox.stateChanged.connect(self.change_show_positions)
        self.startingPoseSpinBox.setMaximum(len(self.data_manager.selector)-1)

        self._redraw(self.active_shape_model.current_tooth)
Esempio n. 30
0
 def initUI(self):
     
     self.setFixedSize(400, 260)
     
     self.setWindowTitle('Fomoire!')
     fomoire = QPixmap(os.path.join('./Pictures/', "fomoire.png"))
     logo = QLabel(self)
     logo.setPixmap(fomoire)
     logo.setFixedSize(fomoire.size())
     logo.move(400 / 2 - fomoire.width() / 2, 15)
     
     towerDefence = QLabel('A Tower Defence Game', self)
     towerDefence.move(130, 66)
     
     selectMap = QLabel('Select map:', self)
     selectMap.move(50, 105)
     
     mapList = QComboBox(self)
     mapList.addItem('No map selected')
     
     for mapFile in os.listdir('./Maps/'):
         mapList.addItem(mapFile)
     
     mapList.move(135, 102)
     mapList.activated[str].connect(self.selectMap)
     
     setSpeed = QLabel('Set game speed:', self)
     setSpeed.move(50, 140)
     
     slow = QLabel('Slow', self)
     slow.move(170, 140)
     
     slider = QSlider(Qt.Horizontal, self)
     slider.setFocusPolicy(Qt.NoFocus)
     slider.setSliderPosition(100 - self.gameSpeed)
     slider.setGeometry(210, 140, 100, 20)
     slider.valueChanged[int].connect(self.changeGameSpeed)
     
     fast = QLabel('Fast', self)
     fast.move(325, 140)
     
     start = QPushButton('Start game!', self)
     start.move(145, 175)
     start.clicked[bool].connect(self.startGame)
     
     quitButton = QPushButton('Quit', self)
     quitButton.move(168, 210)
     quitButton.clicked[bool].connect(qApp.quit)
     
     barbarian = QLabel(self)
     brbr = QPixmap(os.path.join('./Pictures/', "barbarian.png"))
     barbarian.setPixmap(brbr)
     barbarian.move(70, 185)
     
     berserker = QLabel(self)
     berber = QPixmap(os.path.join('./Pictures/', "berserker_left.png"))
     berserker.setPixmap(berber)
     berserker.move(290, 185)
     
     self.show()
Esempio n. 31
0
    def __init__(self):
        self.inital_completed = False
        self.threadpool = QThreadPool()
        self.lock = Lock()
        self.video_stream = None
        root = Tk()
        root.withdraw()
        self.root_dir = askdirectory(
            initialdir="/",
            title="Select root directory containing all cage folders")
        if self.root_dir is ():
            raise AssertionError
        else:
            self.database_local_dir = 'database/homecage_database.sqlite'
            self.F = None
            super().__init__()

            self.widget_main = QWidget()
            self.play_speed = 0
            self.image_label = QLabel()
            self.image_label.resize(1280, 720)

            self.radio_group = [
                QRadioButton('Unlabeled'),
                QRadioButton('Labeled')
            ]

            self.components_left = [
                QLabel("Cage"),
                QComboBox(),
                QLabel("Animal"),
                QComboBox(),
                QLabel("Date"),
                QLabel("From"),
                QCalendarWidget(),
                QLabel("Till"),
                QCalendarWidget(),
                QLabel("Video List || Double click :)"),
                QListWidget()
            ]
            self.components_right_low = [
                QPushButton('Play(space)'),
                QPushButton('Speed(q): %d' % self.play_speed),
                QPushButton('Next Frame (d)'),
                QPushButton('Previous Frame (a)'),
                QPushButton('Start Labeling (s)'),
                QPushButton('Clean all labels')
            ]
            for i in range(len(self.components_right_low)):
                self.components_right_low[i].setDisabled(True)
            self.Playing_Flag = False
            self.layout_main = QGridLayout()
            self.layout_left = QVBoxLayout()
            self.layout_radio = QHBoxLayout()
            self.layout_right_high = QVBoxLayout()
            self.layout_right_low = QHBoxLayout()
            self.widget_main.setLayout(self.layout_main)
            for component in self.components_left:
                self.layout_left.addWidget(component)
            for component in self.components_right_low:
                self.layout_right_low.addWidget(component)
            for radio in self.radio_group:
                self.layout_radio.addWidget(radio)

            self.slider = QSlider(Qt.Horizontal)
            self.slider.setTickPosition(QSlider.TicksBothSides)
            self.slider.setTickInterval(10)
            self.slider.setSingleStep(1)
            self.slider.setValue(0)
            self.radio_group[0].setChecked(True)

            self.layout_right_high.addWidget(self.image_label)
            self.layout_right_high.addWidget(self.slider)
            self.components_left[6].setMaximumDate(datetime.datetime.now())
            self.components_left[8].setMaximumDate(datetime.datetime.now())
            self.min_date = datetime.datetime.now()
            self.max_date = datetime.datetime.now()

            self.layout_left.addLayout(self.layout_radio)
            self.layout_main.addLayout(self.layout_left, 0, 0, 4, 1)
            self.layout_main.addLayout(self.layout_right_high, 0, 2, 4, 4)
            self.layout_main.addLayout(self.layout_right_low, 4, 2, 5, 5)
            self.setCentralWidget(self.widget_main)
            self.overlay = Overlay(self.centralWidget())
            self.overlay.show()
            self.show()
            self.thread_get_cages()

            self.components_left[1].currentIndexChanged.connect(
                self.on_select_cage)
            self.components_left[3].currentIndexChanged.connect(
                self.on_select_animal)
            self.components_left[6].selectionChanged.connect(
                self.on_select_date_min)
            self.components_left[8].selectionChanged.connect(
                self.on_select_date_max)
            self.components_left[10].itemDoubleClicked.connect(
                self.on_select_video)
            self.components_left[10].setSelectionMode(
                QListWidget.SingleSelection)

            self.slider.sliderMoved.connect(self.on_slider)
            self.slider.sliderReleased.connect(self.on_slider_release)

            self.components_right_low[0].clicked.connect(self.on_play)
            self.components_right_low[1].clicked.connect(self.on_speed)
            self.components_right_low[2].clicked.connect(self.on_next_frame)
            self.components_right_low[3].clicked.connect(
                self.on_previous_frame)
            self.components_right_low[4].clicked.connect(self.on_labeling)
            self.components_right_low[5].clicked.connect(self.on_clean_all)

            for i in range(len(self.radio_group)):
                self.radio_group[i].clicked.connect(
                    lambda: self.on_radio(self.radio_group[i]))

            self.init_image = cv2.imread(os.path.join("pic", "init.jpg"))
            self.init_image = cv2.cvtColor(self.init_image, cv2.COLOR_BGR2RGB)
            self.init_image = cv2.resize(self.init_image, (1280, 720))
            self.th = imageThread()
            self.th.changePixmap.connect(self.update_image)
            self.th.start()
            self.th.frames_queue.put(self.init_image)
            self.animal = ""
            self.index = 0
            self.inital_completed = True
            self.start_frame = 0
            self.end_frame = 0
            self.event_dict = {
                0: "Knock Down",
                1: "Attemp",
                2: "Success",
                3: "Successful Lick",
                4: "Discard this event"
            }
            self.current_video_list_all = []
            self.current_video_list_unlabeled = []
            self.current_video_list_labeled = []
            self.video_path = None
            self.slider_queue = Queue()
            self.thread_update_slider()
            self.thread_update_database()
Esempio n. 32
0
class LoadDataDialog(QDialog):
    """Dialog box that contains a data preview for a 3d HDF5 dataset.

    Preview window allows selection of a ROI using a mouse or manual input.
    An estimated data size is calculated based upon ROI size and downsampling factor.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.data_limits = None
        self.roi_changed = False

        self.setWindowTitle("Select Data to Load")
        main_layout = QVBoxLayout()
        main_layout.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.setLayout(main_layout)
        container = QWidget(self)
        hbox = QHBoxLayout(container)
        container.setMaximumWidth(950)
        container.setMaximumHeight(530)
        container.setLayout(hbox)
        container.setObjectName("loaderContainer")
        container.setStyleSheet(
            "QWidget#loaderContainer {"
            "  background-color: #fefefe; "
            "  border-radius: 10px;"
            "}"
        )
        lvbox = QVBoxLayout()
        rvbox = QVBoxLayout()
        lvbox.setAlignment(Qt.AlignTop)
        rvbox.setAlignment(Qt.AlignTop)
        hbox.addLayout(lvbox, 1)
        hbox.addLayout(rvbox, 1)

        main_layout.addWidget(container)

        lvbox.addWidget(QLabel("Preview Dataset"))

        slider_vbox = self.setup_slider()
        lvbox.addLayout(slider_vbox)

        self.canvas = MplCanvas()
        self.canvas.roi_updated.connect(self.on_roi_box_update)
        lvbox.addWidget(self.canvas)

        # INPUT
        rvbox.addWidget(QLabel("Input Dataset:"))
        self.winput = FileWidget(extensions=LOAD_DATA_EXT, save=False)
        rvbox.addWidget(self.winput)
        rvbox.addWidget(QLabel("Internal HDF5 data path:"))
        self.int_h5_pth = QLabel("None selected")
        rvbox.addWidget(self.int_h5_pth)
        roi_fields = self.setup_roi_fields()
        rvbox.addWidget(QWidget(), 1)
        rvbox.addWidget(roi_fields)

        # Save | Cancel
        buttons = QDialogButtonBox.Ok | QDialogButtonBox.Cancel
        self.buttonBox = QDialogButtonBox(buttons)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        rvbox.addWidget(self.buttonBox)
        self.winput.path_updated.connect(self.load_data)
        self.slider.sliderReleased.connect(self.update_image)
        self.slider.valueChanged.connect(self.update_slider_z_label)

    def setup_roi_fields(self):
        """Setup the dialog fields associated with ROI selection.

        Returns:
            PyQt5.QWidgets.QGroupBox: The GroupBox containing the fields.
        """
        apply_roi_button = QPushButton("Apply ROI")
        reset_button = QPushButton("Reset ROI")
        roi_fields = QGroupBox("Select Region of Interest:")
        roi_layout = QGridLayout()
        roi_layout.addWidget(
            QLabel("Drag a box in the image window or type manually"), 0, 0, 1, 3
        )
        roi_layout.addWidget(QLabel("Axis"), 1, 0)
        roi_layout.addWidget(QLabel("Start Value:"), 1, 1)
        roi_layout.addWidget(QLabel("End Value:"), 1, 2)
        roi_layout.addWidget(apply_roi_button, 1, 3)
        roi_layout.addWidget(reset_button, 2, 3)
        roi_layout.addWidget(QLabel("x:"), 2, 0)
        self.xstart_linedt = QLineEdit("0")
        self.xstart_linedt.textChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.xstart_linedt, 2, 1)
        self.xend_linedt = QLineEdit("0")
        self.xend_linedt.textChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.xend_linedt, 2, 2)
        roi_layout.addWidget(QLabel("y:"), 3, 0)
        self.ystart_linedt = QLineEdit("0")
        self.ystart_linedt.textChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.ystart_linedt, 3, 1)
        self.yend_linedt = QLineEdit("0")
        self.yend_linedt.textChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.yend_linedt, 3, 2)
        roi_layout.addWidget(QLabel("z:"), 4, 0)
        self.zstart_linedt = QLineEdit("0")
        self.zstart_linedt.textChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.zstart_linedt, 4, 1)
        self.zend_linedt = QLineEdit("0")
        self.zend_linedt.textChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.zend_linedt, 4, 2)
        roi_layout.addWidget(QLabel("Downsample Factor:"), 5, 0)
        self.downsample_spinner = QSpinBox()
        self.downsample_spinner.setRange(1, 10)
        self.downsample_spinner.setSpecialValueText("None")
        self.downsample_spinner.setMaximumWidth(60)
        self.downsample_spinner.valueChanged.connect(self.on_roi_param_changed)
        roi_layout.addWidget(self.downsample_spinner, 5, 1)
        roi_layout.addWidget(QLabel("Estimated datasize (MB):"), 5, 3)
        self.data_size_label = QLabel("0")
        roi_layout.addWidget(self.data_size_label, 5, 4)
        roi_fields.setLayout(roi_layout)
        apply_roi_button.clicked.connect(self.on_roi_apply_clicked)
        reset_button.clicked.connect(self.on_roi_reset_clicked)
        return roi_fields

    def setup_slider(self):
        """Creates a horizontal slider in a VBoX with labels showing max and min values.

        Returns:
            PyQt5.QWidgets.QVBoxLayout: A QVBoXLayout containing the slider and labels.
        """
        self.slider = QSlider(1)
        slider_vbox = QVBoxLayout()
        slider_hbox = QHBoxLayout()
        slider_hbox.setContentsMargins(0, 0, 0, 0)
        slider_vbox.setContentsMargins(0, 0, 0, 0)
        slider_vbox.setSpacing(0)
        self.slider_min_label = QLabel(alignment=Qt.AlignLeft)
        self.slider_z_label = QLabel(alignment=Qt.AlignCenter)
        self.slider_max_label = QLabel(alignment=Qt.AlignRight)
        slider_vbox.addWidget(self.slider)
        slider_vbox.addLayout(slider_hbox)
        slider_hbox.addWidget(self.slider_min_label, Qt.AlignLeft)
        slider_hbox.addWidget(self.slider_z_label, Qt.AlignCenter)
        slider_hbox.addWidget(self.slider_max_label, Qt.AlignRight)
        slider_vbox.addStretch()
        return slider_vbox

    @pyqtSlot()
    def update_slider_z_label(self):
        """Changes Z value label when slider moved."""
        idx = self.sender().value()
        self.slider_z_label.setNum(idx)

    @pyqtSlot()
    def on_roi_reset_clicked(self):
        """Resets data preview and ROI fields when reset button clicked."""
        self.data_limits = None
        self.reset_roi_fields()
        self.update_image(load=True)

    @pyqtSlot()
    def on_roi_apply_clicked(self):
        """Updates data preview window to fit new ROI when 'Apply' button clicked."""
        self.data_limits = self.get_roi_limits()
        self.roi_changed = self.check_if_roi_changed(self.data_limits)
        self.update_image()

    @pyqtSlot()
    def on_roi_param_changed(self):
        """Gets ROI limits and updates estimated data size whenever value is changed."""
        limits = self.get_roi_limits()
        x_start, x_end, y_start, y_end, z_start, z_end = self.clip_roi_box_vals(limits)
        x_size = x_end - x_start
        y_size = y_end - y_start
        z_size = z_end - z_start
        self.update_est_data_size(z_size, y_size, x_size)

    def get_roi_limits(self):
        """Reads the values of the ROI parameter fields.

        Returns:
            tuple: The six parameters x_start, x_end, y_start, y_end, z_start, z_end defining a 3d ROI
        """
        x_start = self.get_linedt_value(self.xstart_linedt)
        x_end = self.get_linedt_value(self.xend_linedt)
        y_start = self.get_linedt_value(self.ystart_linedt)
        y_end = self.get_linedt_value(self.yend_linedt)
        z_start = self.get_linedt_value(self.zstart_linedt)
        z_end = self.get_linedt_value(self.zend_linedt)
        return x_start, x_end, y_start, y_end, z_start, z_end

    def get_linedt_value(self, linedt):
        """Helper function that converts text in a LineEdit to int if it exists

        Args:
            linedt (PyQt5.QWidgets.LineEdit): A linedit widget to read.

        Returns:
            int: Value of text in LineEdt or 0
        """
        if linedt.text():
            return int(linedt.text())
        return 0

    def load_data(self, path):
        """Launches dialog box to select dataset from within HDF5 file and loads in data if selected.

        Args:
            path (str): Path to the HDF5 file.
        """
        if path is not None and len(path) > 0:
            dataset = None
            if path.endswith(".h5") or path.endswith(".hdf5"):
                available_hdf5 = self.available_hdf5_datasets(path)
                selected, accepted = ComboDialog.getOption(
                    available_hdf5, parent=self, title="HDF5: Select internal path"
                )
                if accepted == QDialog.Rejected:
                    return
                dataset = selected
                self.int_h5_pth.setText(selected)

            self.data = self.volread(path)
            self.dataset = dataset
            if isinstance(self.data, h5.Group):
                self.data_shape = self.data[self.dataset].shape
            else:
                self.data_shape = self.data.shape
            logger.info(self.data_shape)
            self.reset_roi_fields()
            self.update_image(load=True)

    def reset_roi_fields(self):
        """Resets all the ROI dimension parameters to equal the data shape."""
        self.xstart_linedt.setText("0")
        self.xend_linedt.setText(str(self.data_shape[2]))
        self.ystart_linedt.setText("0")
        self.yend_linedt.setText(str(self.data_shape[1]))
        self.zstart_linedt.setText("0")
        self.zend_linedt.setText(str(self.data_shape[0]))
        self.roi_changed = False

    def check_if_roi_changed(self, roi_limits):
        """Checks if any of the ROI dimension parameters are different from the data shape.

        Args:
            roi_limits (tuple): The six parameters x_start, x_end, y_start, y_end, z_start, z_end defining a 3d ROI

        Returns:
            bool: True if the ROI dimension parameters are different from the data shape.
        """
        x_start, x_end, y_start, y_end, z_start, z_end = roi_limits
        if not x_start == y_start == z_start == 0:
            return True
        if (
            (x_end != self.data_shape[2])
            or (y_end != self.data_shape[1])
            or (z_end != self.data_shape[0])
        ):
            return True
        return False

    def on_roi_box_update(self, size_tuple):
        """Updates ROI dimension parameters with data from ROI box drawn by dragging mouse on preview window.

        Args:
            size_tuple (tuple): Tuple of values received from ROI box, x_start, x_end, y_start, y_end
        """
        # Append the z values
        z_start = int(self.zstart_linedt.text())
        z_end = int(self.zend_linedt.text())
        size_tuple += (z_start, z_end)
        # Clip the values
        x_start, x_end, y_start, y_end, z_start, z_end = self.clip_roi_box_vals(
            size_tuple
        )
        self.xstart_linedt.setText(str(x_start))
        self.xend_linedt.setText(str(x_end))
        self.ystart_linedt.setText(str(y_start))
        self.yend_linedt.setText(str(y_end))
        self.zstart_linedt.setText(str(z_start))
        self.zend_linedt.setText(str(z_end))

    def clip_roi_box_vals(self, vals):
        """Clip ROI values to ensure that they lie within the data shape.

        Args:
            vals (tuple): Tuple of six ROI parameters x_start, x_end, y_start, y_end, z_start, z_end

        Returns:
            tuple: Tuple of six clipped ROI parameters x_start, x_end, y_start, y_end, z_start, z_end
        """
        x_start, x_end, y_start, y_end, z_start, z_end = map(round, vals)
        x_start, x_end = clip([x_start, x_end], 0, self.data_shape[2])
        y_start, y_end = clip([y_start, y_end], 0, self.data_shape[1])
        z_start, z_end = clip([z_start, z_end], 0, self.data_shape[0])
        return x_start, x_end, y_start, y_end, z_start, z_end

    def volread(self, path):
        """Helper to return a file handle to an HDF5 file.

        Args:
            path (str): Path to the HDF5 file.

        Raises:
            Exception: If the file is not and HDF5 file.

        Returns:
            h5py.File: File handle to an HDF5 file.
        """
        _, file_extension = os.path.splitext(path)
        data = None
        logger.info("Loading file handle")
        if file_extension in [".hdf5", ".h5"]:
            data = h5.File(path, "r")
        elif file_extension in [".tif", ".tiff"]:
            data = io.imread(path)
        elif file_extension in [".rec", ".mrc"]:
            mrc = mrcfile.mmap(path, mode="r+")
            data = mrc.data
        else:
            raise Exception("File format not supported")
        return data

    def scan_datasets_group(self, group, shape=None, dtype=None, path=""):
        """Recursive function that finds the datasets in an HDF5 file.

        Args:
            group (h5py.File or h5py.Group): A File Handle (Root Group) or Group.
            shape (tuple, optional): Specify datasets of a certain shape. Defaults to None.
            dtype (str, optional): Specify datasets of certain type. Defaults to None.
            path (str, optional): Internal HDF5 path. Defaults to ''.

        Returns:
            list: The datasets contained with the HDF5 file.
        """
        datasets = []
        for name, ds in group.items():
            curr_path = "{}/{}".format(path, name)
            if hasattr(ds, "shape"):
                if (
                    len(ds.shape) == 3
                    and (shape is None or ds.shape == shape)
                    and (dtype is None or ds.dtype == dtype)
                ):
                    datasets.append(curr_path)
            else:
                extra = self.scan_datasets_group(ds, shape=shape, path=curr_path)
                if len(extra) > 0:
                    datasets += extra
        return datasets

    def available_hdf5_datasets(self, path, shape=None, dtype=None):
        """Wrapper round the scan_datasets_gruop function."""
        datasets = []
        with h5.File(path, "r") as f:
            datasets = self.scan_datasets_group(f, shape=shape, dtype=dtype)
        return datasets

    @pyqtSlot()
    def update_image(self, load=False):
        """Updates the image in the preview window.

        Args:
            load (bool, optional): Set to True if loading a new dataset. Defaults to False.
        """
        # Only update index if called by slider
        if isinstance(self.sender(), QSlider):
            idx = self.sender().value()
        else:
            idx = None
        # Set limits
        if self.data_limits:
            x_start, x_end, y_start, y_end, z_start, z_end = self.data_limits
            x_size = x_end - x_start
            y_size = y_end - y_start
            z_size = z_end - z_start
        else:
            z_size, y_size, x_size = self.data_shape
            x_start, x_end, y_start, y_end, z_start, z_end = (
                0,
                x_size,
                0,
                y_size,
                0,
                z_size,
            )
        # Show central slice if loading data or changing roi
        if idx is None or load:
            idx = z_size // 2
            self.slider.blockSignals(True)
            self.slider.setMinimum(z_start)
            self.slider_min_label.setNum(z_start)
            self.slider.setMaximum(z_end - 1)
            self.slider_max_label.setNum(z_end)
            self.slider.setValue(idx)
            self.slider_z_label.setNum(idx)
            self.slider.blockSignals(False)
            self.canvas.ax.set_ylim([y_size + 1, -1])
            self.canvas.ax.set_xlim([-1, x_size + 1])
        if isinstance(self.data, h5.Group):
            img = self.data[self.dataset][idx]
        else:
            img = self.data[idx]
        self.canvas.ax.imshow(img[y_start:y_end, x_start:x_end], "gray")
        self.canvas.ax.grid(False)
        self.canvas.redraw()

    def update_est_data_size(self, z_size, y_size, x_size):
        """Updates the estimated datasize label according to the dimensions and the downsampling factor.

        Args:
            z_size (int): Length of z dimension.
            y_size (int): Length of y dimension.
            x_size (int): Length of x dimension.
        """
        data_size_tup = tuple(map(int, (z_size, y_size, x_size)))
        est_data_size = (product(data_size_tup) * 4) / 10 ** 6
        est_data_size /= self.downsample_spinner.value()
        self.data_size_label.setText(f"{est_data_size:.2f}")
Esempio n. 33
0
    def add_options_panel(self):
        # Prepare the sliders
        options_layout = QVBoxLayout()

        options_layout.addStretch()  # Centralize the sliders
        sliders_layout = QVBoxLayout()
        max_label_width = -1

        # Get min and max for all dof
        ranges = []
        for i in range(self.model.nbSegment()):
            seg = self.model.segment(i)
            for r in seg.QRanges():
                ranges.append([r.min(), r.max()])

        for i in range(self.model.nbQ()):
            slider_layout = QHBoxLayout()
            sliders_layout.addLayout(slider_layout)

            # Add a name
            name_label = QLabel()
            name = f"{self.model.nameDof()[i].to_string()}"
            name_label.setText(name)
            name_label.setPalette(self.palette_active)
            label_width = name_label.fontMetrics().boundingRect(
                name_label.text()).width()
            if label_width > max_label_width:
                max_label_width = label_width
            slider_layout.addWidget(name_label)

            # Add the slider
            slider = QSlider(Qt.Horizontal)
            slider.setMinimumSize(100, 0)
            slider.setMinimum(ranges[i][0] * self.double_factor)
            slider.setMaximum(ranges[i][1] * self.double_factor)
            slider.setPageStep(self.double_factor)
            slider.setValue(0)
            slider.valueChanged.connect(self.__move_avatar_from_sliders)
            slider.sliderReleased.connect(
                partial(self.__update_muscle_analyses_graphs, False, False,
                        False, False))
            slider_layout.addWidget(slider)

            # Add the value
            value_label = QLabel()
            value_label.setText(f"{0:.2f}")
            value_label.setPalette(self.palette_active)
            slider_layout.addWidget(value_label)

            # Add to the main sliders
            self.sliders.append((name_label, slider, value_label))
        # Adjust the size of the names
        for name_label, _, _ in self.sliders:
            name_label.setFixedWidth(max_label_width + 1)

        # Put the sliders in a scrollable area
        sliders_widget = QWidget()
        sliders_widget.setLayout(sliders_layout)
        sliders_scroll = QScrollArea()
        sliders_scroll.setFrameShape(0)
        sliders_scroll.setWidgetResizable(True)
        sliders_scroll.setWidget(sliders_widget)
        options_layout.addWidget(sliders_scroll)

        # Add reset button
        button_layout = QHBoxLayout()
        options_layout.addLayout(button_layout)
        reset_push_button = QPushButton("Reset")
        reset_push_button.setPalette(self.palette_active)
        reset_push_button.released.connect(self.reset_q)
        button_layout.addWidget(reset_push_button)

        # Add the radio button for analyses
        option_analyses_group = QGroupBox()
        option_analyses_layout = QVBoxLayout()
        # Add text
        analyse_text = QLabel()
        analyse_text.setPalette(self.palette_active)
        analyse_text.setText("Analyses")
        option_analyses_layout.addWidget(analyse_text)
        # Add the no analyses
        radio_none = QRadioButton()
        radio_none.setPalette(self.palette_active)
        radio_none.setChecked(True)
        radio_none.toggled.connect(
            lambda: self.__select_analyses_panel(radio_none, 0))
        radio_none.setText("None")
        option_analyses_layout.addWidget(radio_none)
        # Add the muscles analyses
        radio_muscle = QRadioButton()
        radio_muscle.setPalette(self.palette_active)
        radio_muscle.toggled.connect(
            lambda: self.__select_analyses_panel(radio_muscle, 1))
        radio_muscle.setText("Muscles")
        option_analyses_layout.addWidget(radio_muscle)
        # Add the layout to the interface
        option_analyses_group.setLayout(option_analyses_layout)
        options_layout.addWidget(option_analyses_group)

        # Finalize the options panel
        options_layout.addStretch()  # Centralize the sliders

        # Animation panel
        animation_layout = QVBoxLayout()
        animation_layout.addWidget(self.vtk_window.avatar_widget)

        # Add the animation slider
        animation_slider_layout = QHBoxLayout()
        animation_layout.addLayout(animation_slider_layout)
        load_push_button = QPushButton("Load movement")
        load_push_button.setPalette(self.palette_active)
        load_push_button.released.connect(self.__load_movement_from_button)
        animation_slider_layout.addWidget(load_push_button)

        # Controllers
        self.play_stop_push_button = QPushButton()
        self.play_stop_push_button.setIcon(self.start_icon)
        self.play_stop_push_button.setPalette(self.palette_active)
        self.play_stop_push_button.setEnabled(False)
        self.play_stop_push_button.released.connect(
            self.__start_stop_animation)
        animation_slider_layout.addWidget(self.play_stop_push_button)

        slider = QSlider(Qt.Horizontal)
        slider.setMinimum(0)
        slider.setMaximum(100)
        slider.setValue(0)
        slider.setEnabled(False)
        slider.valueChanged.connect(self.__animate_from_slider)
        animation_slider_layout.addWidget(slider)

        self.record_push_button = QPushButton()
        self.record_push_button.setIcon(self.record_icon)
        self.record_push_button.setPalette(self.palette_active)
        self.record_push_button.setEnabled(True)
        self.record_push_button.released.connect(self.__record)
        animation_slider_layout.addWidget(self.record_push_button)

        self.stop_record_push_button = QPushButton()
        self.stop_record_push_button.setIcon(self.stop_icon)
        self.stop_record_push_button.setPalette(self.palette_active)
        self.stop_record_push_button.setEnabled(False)
        self.stop_record_push_button.released.connect(self.__stop_record, True)
        animation_slider_layout.addWidget(self.stop_record_push_button)

        # Add the frame count
        frame_label = QLabel()
        frame_label.setText(f"{0}")
        frame_label.setPalette(self.palette_inactive)
        animation_slider_layout.addWidget(frame_label)

        self.movement_slider = (slider, frame_label)

        # Global placement of the window
        self.vtk_window.main_layout.addLayout(options_layout, 0, 0)
        self.vtk_window.main_layout.addLayout(animation_layout, 0, 1)
        self.vtk_window.main_layout.setColumnStretch(0, 1)
        self.vtk_window.main_layout.setColumnStretch(1, 2)

        # Change the size of the window to account for the new sliders
        self.vtk_window.resize(self.vtk_window.size().width() * 2,
                               self.vtk_window.size().height())

        # Prepare all the analyses panel
        self.muscle_analyses = MuscleAnalyses(self.analyses_muscle_widget,
                                              self)
        if biorbd.currentLinearAlgebraBackend() == 1:
            radio_muscle.setEnabled(False)
        else:
            if self.model.nbMuscles() == 0:
                radio_muscle.setEnabled(False)
        self.__select_analyses_panel(radio_muscle, 1)
Esempio n. 34
0
class Player(QMainWindow):
    """
    A simple Media Player using VLC and Qt
    """
    def __init__(self, master=None):
        super().__init__()
        self.setWindowTitle("CCTV by @XII")

        # creating a basic vlc instance
        self.instance = vlc.Instance()
        # creating an empty vlc media player
        self.mediaplayer = self.instance.media_player_new()

        self.path = ''

        self.initUI()
        self.isPaused = False
        self.setStyleSheet(open("style.qss", "r").read())

    def initUI(self):
        """
        Set up the user interface, signals & slots
        For better understaning, I made some shortcuts for variables,
        which is the instance of the QtWidgets classes.
        List of shortcuts(made):
        *btn - QPushButton;
        *lbl - QLabel;
        *slr - QSlider;
        *lyt - Q_lyt;
        *ctrl - ctrl;
        """
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        #video widget
        self.videoframe = QFrame()
        self.palette = self.videoframe.palette()
        self.palette.setColor(QtGui.QPalette.Window, QtGui.QColor(0, 0, 0))
        self.videoframe.setPalette(self.palette)
        self.videoframe.setAutoFillBackground(True)

        #time value
        self.timevalue = QDateTimeEdit()
        self.timevalue.setDisplayFormat('hh:mm:ss')
        self.timevalue.setReadOnly(True)
        self.timevalue.setFixedSize(80, 30)

        #position slider
        self.position_slr = QSlider(QtCore.Qt.Horizontal, self)
        self.position_slr.setToolTip("Position")
        self.position_slr.setMaximum(1000)
        self.position_slr.sliderMoved.connect(self.set_position)

        #play button
        self.play_btn = QPushButton()
        self.play_btn.setProperty("onplay", True)
        self.play_btn.setObjectName("play")
        self.play_btn.clicked.connect(self.play_pause)

        #stop button
        self.stop_btn = QPushButton()
        self.stop_btn.setObjectName('stop')
        self.stop_btn.clicked.connect(self.stop)

        #analyse button
        self.analyse_btn = QPushButton('Analyse')
        self.analyse_btn.setObjectName('analyse')
        self.analyse_btn.setFixedSize(70, 28)
        self.analyse_btn.clicked.connect(self.start_analyse)
        self.analyse_window = Analyse(self)
        self.analyse_window.off()
        self.analyse_btn.setEnabled(False)
        self.on_analyse = False

        self.details_btn = QPushButton('Details')
        self.details_btn.setVisible(False)
        self.details_btn.setObjectName('details')
        self.details_btn.setFixedSize(70, 28)
        self.details_btn.clicked.connect(self.show_details)

        self.details_wd = pictureViewer()
        self.details_wd.close()

        self.threadpool = QtCore.QThreadPool()
        self.threadpool.setMaxThreadCount(1)
        worker = loadModules(self)
        self.threadpool.start(worker)

        self.path_input = pathLineEdit(self)
        self.path_input.setObjectName('path')

        self.folder_btn = QPushButton()
        self.folder_btn.setObjectName('folder')
        self.folder_btn.clicked.connect(
            lambda x: self.select_folder(foldername=''))

        self.fileslist_lbl = QLabel('Playlist:')
        self.fileslist_lbl.setObjectName('lbl')
        self.fileslist_lbl.setIndent(12)

        self.fileslist = QListWidget()
        self.fileslist.itemClicked.connect(self.select_file)

        self.warnings_lbl = QLabel('Warnings time:')
        self.warnings_lbl.setObjectName('lbl')
        self.warnings_lbl.setIndent(12)

        self.warningslist = QListWidget()

        #volume slider
        self.volume_slr = QSlider(QtCore.Qt.Horizontal, self)
        self.volume_slr.setMaximum(100)
        self.volume_slr.setValue(self.mediaplayer.audio_get_volume())
        self.volume_slr.setToolTip("Volume")
        self.volume_slr.valueChanged.connect(self.set_volume)

        #setting up layouts
        folder_lyt = QHBoxLayout()
        folder_lyt.addWidget(self.path_input)
        folder_lyt.addWidget(self.folder_btn)

        leftside_lyt = QVBoxLayout()
        leftside_lyt.setContentsMargins(0, 10, 0, 0)
        leftside_lyt.addSpacing(6)
        leftside_lyt.addWidget(self.fileslist_lbl)
        leftside_lyt.addWidget(self.fileslist)

        analyse_btns = QHBoxLayout()
        analyse_btns.addWidget(self.details_btn)
        analyse_btns.addWidget(self.analyse_btn)
        leftside_lyt.addLayout(analyse_btns)

        leftside_lyt.addWidget(self.warnings_lbl)
        leftside_lyt.addWidget(self.warningslist)
        leftside_lyt.addLayout(folder_lyt)
        leftside_lyt.addSpacing(6)

        self.leftside_bg = QWidget()
        self.leftside_bg.setObjectName("leftside_bg")
        self.leftside_bg.setLayout(leftside_lyt)

        ctrl_lyt = QHBoxLayout()
        ctrl_lyt.addSpacing(20)
        ctrl_lyt.addWidget(self.play_btn)
        ctrl_lyt.setSpacing(0)
        ctrl_lyt.addWidget(self.stop_btn)
        ctrl_lyt.addStretch(1)
        ctrl_lyt.addWidget(self.volume_slr)

        ctrl_panel_lyt = QVBoxLayout()
        ctrl_panel_lyt.setContentsMargins(60, 12, 60, 12)
        ctrl_panel_lyt.addWidget(self.timevalue, 0, QtCore.Qt.AlignLeft)
        ctrl_panel_lyt.addWidget(self.position_slr)
        ctrl_panel_lyt.addLayout(ctrl_lyt)

        rightside_lyt = QVBoxLayout()
        rightside_lyt.addWidget(self.videoframe)
        rightside_lyt.addLayout(ctrl_panel_lyt)

        main_lyt = QHBoxLayout()
        main_lyt.setSpacing(0)
        main_lyt.setContentsMargins(0, 0, 0, 0)
        main_lyt.addWidget(self.leftside_bg)
        main_lyt.addLayout(rightside_lyt, 60)

        self.widget.setLayout(main_lyt)

        self.timer = QtCore.QTimer(self)
        self.timer.setInterval(200)
        self.timer.timeout.connect(self.updateUI)

        #creates connection to db
        self.db = db_api.create_connection(
            os.path.join(os.getcwd(), 'db', 'data.db'))

    def play_pause(self):
        """
        Toggle play/pause status
        """
        if self.mediaplayer.is_playing():
            self.mediaplayer.pause()
            self.play_btn.setProperty("onplay", True)
            self.play_btn.setStyle(self.play_btn.style())
            self.isPaused = True

        else:
            if self.mediaplayer.play() == -1:
                return
            self.mediaplayer.play()
            self.play_btn.setProperty("onplay", False)
            self.play_btn.setStyle(self.play_btn.style())

            self.timer.start()
            self.isPaused = False

    def start_analyse(self):

        self.analyse_btn.setEnabled(False)

        try:
            file = self.fileslist.currentItem().text()
        except AttributeError:
            self.analyse_btn.setEnabled(True)
            QMessageBox.information(self, "Warning!",
                                    "You should to select a file.")
            return

        if not self.on_analyse:
            self.setEnabled(False)
            self.analyse_window.on()

            try:
                worker = AnalyseWorker(file, self)
                self.threadpool.start(worker)
            except Exception as e:
                print(e)
        else:
            return

    def show_details(self):

        try:
            file = self.fileslist.currentItem().text()
        except AttributeError:
            self.analyse_btn.setEnabled(True)
            QMessageBox.information(self, "Warning!",
                                    "You should to select a file.")
            return

        item = self.fileslist.currentItem().text()
        if os.path.isdir(os.path.join('warnings', os.path.splitext(item)[0])):
            self.details_wd.show()
            self.details_wd.start(self.fileslist.currentItem().text())
        else:
            return

    def stop_analyse(self):
        self.analyse_window.off()
        self.setEnabled(True)
        self.on_analyse = False

    def stop(self):
        """
        stop player
        """
        if self.mediaplayer.is_playing():
            self.timevalue.setTime(QtCore.QTime.fromMSecsSinceStartOfDay(0))

        self.mediaplayer.stop()

    def select_file(self, item):
        self.open_file(filename=self.path + '/' + item.text())

    def check_warnings_time(self, filename):
        with self.db:
            file_id = db_api.select_file(self.db, filename)
            if file_id:

                #if file in db, then add warning times in list bellow
                timelist = db_api.select_time(self.db, file_id)

                self.warningslist.clear()
                for time in timelist:
                    self.warningslist.addItem(time[0] + "-" + time[1])

                self.details_btn.setVisible(True)

            else:
                self.details_btn.setVisible(False)
                self.warningslist.clear()
                self.warningslist.addItem("There is nothing to show.")

    def open_file(self, filename=''):
        """
        Open a media file in a MediaPlayer
        """
        if filename == '':
            filename = QFileDialog.getOpenFileName(self, "Open File", './')[0]
        if not filename:
            return

        self.check_warnings_time(os.path.split(filename)[1])

        # create the media
        self.media = self.instance.media_new(filename)

        # put the media in the media player
        self.mediaplayer.set_media(self.media)

        # parse the metadata of the file
        self.media.parse_async()

        fullpath = re.escape(filename)

        # get video duration
        time = os.popen("ffmpeg -i {0}".format(fullpath) +
                        " 2>&1 | grep Duration | awk '{print $2}' | tr -d ,"
                        ).read().split(':')
        self.duration = int(3600000 * int(time[0]) + 60000 * int(time[1]) +
                            1000 * float(time[2]))

        # set the title of the track as window title
        self.setWindowTitle("CCTV: " + self.media.get_meta(0))

        # the media player has to be 'connected' to the QFrame
        # (otherwise a video would be displayed in it's own window)
        # this is platform specific!
        # you have to give the id of the QFrame (or similar object) to
        # vlc, different platforms have diffqerent functions for this
        if sys.platform == "linux":  # for Linux using the X Server
            self.mediaplayer.set_xwindow(self.videoframe.winId())
        elif sys.platform == "win32":  # for Windows
            self.mediaplayer.set_hwnd(self.videoframe.winId())
        elif sys.platform == "darwin":  # for MacOS
            self.mediaplayer.set_agl(self.videoframe.windId())
        self.play_pause()

    def set_volume(self, Volume):
        """
        Set the volume
        """
        self.mediaplayer.audio_set_volume(Volume)

    def set_position(self, position):
        """
        Set the position
        """
        # setting the position to where the slider was dragged
        self.mediaplayer.set_position(position / 1000.0)
        # the vlc MediaPlayer needs a float value between 0 and 1, Qt
        # uses integer variables, so you need a factor; the higher the
        # factor, the more precise are the results
        # (1000 should be enough)
        self.timevalue.setTime(
            QtCore.QTime.fromMSecsSinceStartOfDay(
                self.mediaplayer.get_position() * self.duration))

    def set_time(self, time):
        """
        Set time to display
        """
        self.mediaplayer.set_time(time)

    def select_folder(self, foldername=''):
        if foldername == '':
            foldername = str(
                QFileDialog.getExistingDirectory(self, "Select Directory"))
            self.path_input.setText(foldername)
            self.path = foldername
        if not foldername:
            return

        files = os.listdir(foldername)
        self.path = foldername
        self.fileslist.clear()
        for file in files:
            self.fileslist.addItem(file)

    def updateUI(self):
        """
        updates the user interface
        """
        # setting the slider to the desired position
        self.position_slr.setValue(self.mediaplayer.get_position() * 1000)
        self.timevalue.setTime(
            QtCore.QTime.fromMSecsSinceStartOfDay(
                self.mediaplayer.get_position() * self.duration))
        self.volume_slr.setValue(self.mediaplayer.audio_get_volume())

        if not self.mediaplayer.is_playing():
            # no need to call this function if nothing is played
            self.timer.stop()
            if not self.isPaused:
                # after the video finished, the play button stills shows
                # "Pause", not the desired behavior of a media player
                # this will fix it
                self.stop()
Esempio n. 35
0
class MainScreen(QMainWindow):
    """The Main GUI layout and callbacks.
    """
    def __init__(self) -> None:

        logging.info("Initialize MainScreen")
        super().__init__(parent=None)

        self._traffic: Optional[Traffic] = None
        self._tview: Optional[Traffic] = None
        self.decoder: Optional[ModeS_Decoder] = None
        self.updateTraffic: Optional[UpdateTraffic] = None
        self.airspace_ready: bool = False
        self.last_interact: datetime = datetime.now()

        airspace_init = AirspaceInitCache(self)
        airspace_init.start()

        self.setWindowTitle("traffic")
        self.setGeometry(10, 10, 920, 720)

        self.set_icons()
        self.set_layout()
        self.set_design()
        self.set_callbacks()

    def __del__(self) -> None:
        if self.updateTraffic is not None:
            self.updateTraffic.terminate()
        if self.decoder is not None:
            self.decoder.stop()

    @property
    def traffic(self) -> Optional[Traffic]:
        self.last_interact = datetime.now()
        if self.decoder is not None:
            self._traffic = self.decoder.traffic
            if self._traffic is None:
                return None
            self.set_time_range()
            # self.set_float_columns()
        #            max_alt = 100 * self.altitude_slider.value()
        #            max_time = self.dates[self.time_slider.value()]
        #            self.on_filter(max_alt, max_time)
        return self._traffic

    def set_callbacks(self) -> None:
        self.airport_button.clicked.connect(self.on_plot_airport)
        self.altitude_slider.sliderMoved.connect(self.on_altitude_moved)
        self.altitude_slider.sliderReleased.connect(self.on_select)
        self.area_input.textEdited.connect(self.on_area_input)
        self.area_select.itemSelectionChanged.connect(self.on_area_select)
        self.extent_button.clicked.connect(self.on_extent_button)
        self.identifier_input.textEdited.connect(self.on_id_input)
        self.identifier_select.itemSelectionChanged.connect(self.on_id_change)
        self.open_dropdown.activated.connect(self.on_open)
        self.plot_button.clicked.connect(self.on_plot_button)
        self.projection_dropdown.activated.connect(self.make_map)
        self.reset_button.clicked.connect(self.on_clear_button)
        self.time_slider.sliderMoved.connect(self.on_time_moved)
        self.time_slider.sliderReleased.connect(self.on_select)
        self.y_selector.itemSelectionChanged.connect(self.on_id_change)
        self.sec_y_selector.itemSelectionChanged.connect(self.on_id_change)

    def set_design(self) -> None:
        self.open_dropdown.setMaximumWidth(400)
        self.projection_dropdown.setMaximumWidth(400)
        self.altitude_description.setMinimumWidth(100)
        self.altitude_description.setMaximumWidth(100)
        self.altitude_slider_info.setMinimumWidth(50)
        self.altitude_slider_info.setMaximumWidth(50)
        self.altitude_slider.setMaximumWidth(240)
        self.area_input_description.setMinimumWidth(100)
        self.area_input_description.setMaximumWidth(100)
        self.area_input.setMaximumWidth(290)
        self.area_select.setMaximumHeight(100)
        self.area_select.setMaximumWidth(400)
        self.identifier_description.setMinimumWidth(100)
        self.identifier_description.setMaximumWidth(100)
        self.identifier_input.setMaximumWidth(290)
        self.identifier_select.setMaximumWidth(400)
        self.time_description.setMinimumWidth(100)
        self.time_description.setMaximumWidth(100)
        self.time_slider_info.setMinimumWidth(50)
        self.time_slider_info.setMaximumWidth(50)
        self.time_slider.setMaximumWidth(240)
        self.y_selector.setMaximumHeight(100)
        self.sec_y_selector.setMaximumHeight(100)

    def set_layout(self) -> None:

        self.plot_tabs = QTabWidget()
        map_tab = QWidget()
        map_layout = QVBoxLayout()
        map_tab.setLayout(map_layout)

        self.map_plot = MapCanvas(parent=self, width=5, height=4)
        self.map_plot.move(0, 0)
        self.time_plot = TimeCanvas(parent=self, width=5, height=4)
        self.time_plot.move(0, 0)

        map_toolbar = NavigationToolbar2QT(self.map_plot, map_tab)
        map_toolbar.setVisible(False)
        map_layout.addWidget(map_toolbar)
        map_layout.addWidget(self.map_plot)
        map_toolbar.pan()

        time_tab = QWidget()
        time_layout = QVBoxLayout()
        time_tab.setLayout(time_layout)

        self.y_selector = QListWidget()
        self.sec_y_selector = QListWidget()
        self.y_selector.setSelectionMode(3)  # extended selection
        self.sec_y_selector.setSelectionMode(3)  # extended selection
        selector = QHBoxLayout()
        selector.addWidget(self.y_selector)
        selector.addWidget(self.sec_y_selector)

        time_layout.addLayout(selector)
        time_layout.addWidget(self.time_plot)

        self.plot_tabs.addTab(map_tab, "Map")
        self.plot_tabs.addTab(time_tab, "Plots")

        plot_column = QVBoxLayout()
        plot_column.addWidget(self.plot_tabs)

        self.interact_column = QVBoxLayout()

        self.open_options = ["Open file", "dump1090"]
        if "decoders" in config:
            self.open_options += list(config["decoders"])
        self.open_dropdown = QComboBox()
        for option in self.open_options:
            self.open_dropdown.addItem(option)
        self.interact_column.addWidget(self.open_dropdown)

        self.projections = ["EuroPP", "Lambert93", "Mercator"]
        self.projection_dropdown = QComboBox()
        more_projs = config.get("projections", "extra", fallback="")
        if more_projs != "":
            proj_list = more_projs.split(";")
            self.projections += list(x.strip() for x in proj_list)
        for proj in self.projections:
            self.projection_dropdown.addItem(proj)
        self.interact_column.addWidget(self.projection_dropdown)

        button_grid = QGridLayout()

        self.extent_button = QPushButton("Extent")
        button_grid.addWidget(self.extent_button, 0, 0)
        self.plot_button = QPushButton("Plot")
        button_grid.addWidget(self.plot_button, 0, 1)
        self.airport_button = QPushButton("Airport")
        button_grid.addWidget(self.airport_button, 1, 0)
        self.reset_button = QPushButton("Reset")
        button_grid.addWidget(self.reset_button, 1, 1)

        self.interact_column.addLayout(button_grid)

        self.area_input_description = QLabel("Area")
        self.area_input = QLineEdit()
        area_input_layout = QHBoxLayout()
        area_input_layout.addWidget(self.area_input_description)
        area_input_layout.addWidget(self.area_input)
        self.interact_column.addLayout(area_input_layout)

        self.area_select = QListWidget()
        self.interact_column.addWidget(self.area_select)

        self.time_slider = QSlider(QtCore.Qt.Horizontal)
        self.time_description = QLabel("Date max.")
        self.time_slider_info = QLabel()
        time_layout = QHBoxLayout()
        time_layout.addWidget(self.time_description)
        time_layout.addWidget(self.time_slider)
        time_layout.addWidget(self.time_slider_info)
        self.time_slider.setMinimum(0)
        self.time_slider.setMaximum(99)
        self.time_slider.setValue(99)
        self.time_slider.setEnabled(False)
        self.interact_column.addLayout(time_layout)

        self.altitude_slider = QSlider(QtCore.Qt.Horizontal)
        self.altitude_description = QLabel("Altitude max.")
        self.altitude_slider_info = QLabel("60000")
        self.altitude_slider.setSingleStep(5)
        self.altitude_slider.setPageStep(100)
        self.altitude_slider.setMinimum(0)
        self.altitude_slider.setMaximum(600)
        self.altitude_slider.setValue(600)
        altitude_layout = QHBoxLayout()
        altitude_layout.addWidget(self.altitude_description)
        altitude_layout.addWidget(self.altitude_slider)
        altitude_layout.addWidget(self.altitude_slider_info)
        self.interact_column.addLayout(altitude_layout)

        self.identifier_description = QLabel("Callsign/ID")
        self.identifier_input = QLineEdit()

        identifier_layout = QHBoxLayout()
        identifier_layout.addWidget(self.identifier_description)
        identifier_layout.addWidget(self.identifier_input)
        self.interact_column.addLayout(identifier_layout)

        self.identifier_select = QListWidget()
        self.identifier_select.setSelectionMode(3)  # extended selection
        self.interact_column.addWidget(self.identifier_select)

        mainLayout = QGridLayout()
        mainLayout.addLayout(plot_column, 0, 0)
        mainLayout.addLayout(self.interact_column, 0, 1)

        mainWidget = QWidget()
        mainWidget.setLayout(mainLayout)
        self.setCentralWidget(mainWidget)

    # -- Callbacks --

    @dont_crash
    def on_time_moved(self, value: int, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        self.time_slider_info.setText(self.date_options[value])

    @dont_crash
    def on_altitude_moved(self, value: int, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        self.altitude_slider_info.setText(f"{100*value}")

    @dont_crash
    def on_select(self, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        if self.traffic is not None:
            max_alt = 100 * self.altitude_slider.value()
            max_time = self.dates[self.time_slider.value()]
            self.on_filter(max_alt, max_time)

    @dont_crash
    def on_filter(self, max_alt: int, max_time: datetime) -> None:

        assert self._traffic is not None

        west, east, south, north = self.map_plot.ax.get_extent(
            crs=PlateCarree())

        self._tview = self._traffic.before(max_time).sort_values("timestamp")

        if self._tview is None:
            return

        filtered = Traffic.from_flights(
            Flight(f.data.ffill().bfill()) for f in self._tview)
        if "altitude" in filtered.data.columns:
            filtered = filtered.query(
                f"altitude != altitude or altitude <= {max_alt}")
        if "latitude" in self._tview.data.columns:
            filtered = filtered.query("latitude != latitude or "
                                      f"({west} <= longitude <= {east} and "
                                      f"{south} <= latitude <= {north})")

        self.identifier_select.clear()
        text = self.identifier_input.text()
        # cast is necessary because of the @lru_cache on callsigns which hides
        # the type annotation
        for callsign in sorted(cast(Set[str], filtered.callsigns)):
            if re.match(text, callsign, flags=re.IGNORECASE):
                self.identifier_select.addItem(callsign)

        callsigns = cast(Set[str], filtered.callsigns)
        self.map_plot.default_plot(self._tview[callsigns])
        self.set_float_columns()

    @dont_crash
    def on_extent_button(self, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        if self.area_select.count() == 0:
            if len(self.area_input.text()) == 0:
                self.map_plot.ax.set_global()
            else:
                self.map_plot.ax.set_extent(location(self.area_input.text()))
        else:
            if self.airspace_ready:
                self.map_plot.ax.set_extent(
                    aixm_airspaces[self.area_select.item(0).text()])

        self.map_plot.draw()

        if self.traffic is not None:
            max_alt = 100 * self.altitude_slider.value()
            max_time = self.dates[self.time_slider.value()]
            self.on_filter(max_alt, max_time)

    @dont_crash
    def on_id_change(self, *args, **kwargs) -> None:
        assert self._tview is not None
        self.last_interact = datetime.now()

        list_callsigns = list(
            item.text() for item in self.identifier_select.selectedItems())
        selected_y = list(item.text()
                          for item in self.y_selector.selectedItems())
        selected_sec_y = list(item.text()
                              for item in self.sec_y_selector.selectedItems())
        self.map_plot.plot_callsigns(self._tview, list_callsigns)
        self.time_plot.create_plot()
        self.time_plot.plot_callsigns(
            self._tview,
            list_callsigns,
            y=selected_y + selected_sec_y,
            secondary_y=selected_sec_y,
        )

    @dont_crash
    def on_id_input(self, text, *args, **kwargs) -> None:
        assert self._tview is not None
        self.last_interact = datetime.now()
        # segfault prone when interactive (decoder)
        # selected = list(
        #     item.text() for item in self.identifier_select.selectedItems()
        # )
        self.identifier_select.clear()
        for callsign in sorted(cast(Set[str], self._tview.callsigns)):
            if re.match(text, callsign, flags=re.IGNORECASE):
                self.identifier_select.addItem(callsign)
                # if callsign in selected:
                #     curItem = self.identifier_select.item(
                #         self.identifier_select.count() - 1
                #     )
                #     self.identifier_select.setItemSelected(curItem, True)

    @dont_crash
    def on_plot_button(self, *args, **kwargs) -> None:
        assert self._tview is not None
        self.last_interact = datetime.now()
        if self.area_select.count() == 0:
            if len(self.area_input.text()) == 0:
                self.map_plot.default_plot(self._tview)
            else:
                location(self.area_input.text()).plot(
                    self.map_plot.ax,
                    color="#524c50",
                    linestyle="dotted",
                    linewidth=0.5,
                )
        else:
            if self.airspace_ready:
                selected = self.area_select.selectedItems()
                if len(selected) == 0:
                    return
                airspace = aixm_airspaces[selected[0].text()]
                if airspace is not None:
                    airspace.plot(self.map_plot.ax)

        self.map_plot.draw()

    @dont_crash
    def on_area_input(self, text: str, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        self.area_select.clear()
        if len(text) > 0 and self.airspace_ready:
            for airspace_info in aixm_airspaces.parse(text):
                self.area_select.addItem(airspace_info.name)

    @dont_crash
    def on_area_select(self, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        selected = self.area_select.selectedItems()
        if len(selected) == 0:
            return
        if self.airspace_ready:
            airspace = aixm_airspaces[selected[0].text()]
            if airspace is not None:
                self.map_plot.ax.set_extent(airspace)
                self.map_plot.draw()

    @dont_crash
    def on_plot_airport(self, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        if len(self.area_input.text()) == 0:
            from cartotools.osm import request, tags

            west, east, south, north = self.map_plot.ax.get_extent(
                crs=PlateCarree())
            if abs(east - west) > 1 or abs(north - south) > 1:
                # that would be a too big request
                return
            request((west, south, east, north),
                    **tags.airport).plot(self.map_plot.ax)
        else:
            from traffic.data import airports

            airport = airports[self.area_input.text()]
            if airport is not None:
                airport.plot(self.map_plot.ax)
        self.map_plot.draw()

    @dont_crash
    def on_clear_button(self, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        if self.traffic is not None:
            assert self._traffic is not None
            self._tview = self._traffic.sort_values("timestamp")
            self.altitude_slider.setValue(600)
            self.make_map(self.projection_dropdown.currentIndex())
            self.time_plot.create_plot()
            self.set_float_columns()

    @dont_crash
    def make_map(self, index_projection: int, *args, **kwargs) -> None:
        self.last_interact = datetime.now()
        self.map_plot.create_map(self.projections[index_projection])
        if self._tview is not None:
            self.map_plot.default_plot(self._tview)

    @dont_crash
    def on_open(self, index: int, *args, **kwargs) -> None:
        if self.decoder is not None and self.updateTraffic is not None:
            self.updateTraffic.terminate()
            self.decoder.stop()
        if index == 0:
            self.openFile()
        elif index == 1:
            self.openDump1090()
        else:
            address = config.get("decoders", self.open_options[index])
            host_port, reference = address.split("/")
            host, port = host_port.split(":")
            self.decoder = ModeS_Decoder.from_address(host, int(port),
                                                      reference)
            refresh_time = config.getint("decoders",
                                         "refresh_time",
                                         fallback=30)
            self.updateTraffic = UpdateTraffic(self, refresh_time)
            self.updateTraffic.start()

    # -- Basic setters --

    def set_icons(self) -> None:

        logging.info("Setting options")
        icon_path = Path(traffic.__file__).absolute().parent.parent / "icons"
        if sys.platform == "linux":
            icon_full = QtGui.QIcon(
                (icon_path / "travel-beige.svg").as_posix())
        elif sys.platform == "darwin":
            icon_full = QtGui.QIcon((icon_path / "travel-grey.svg").as_posix())
        else:
            icon_full = QtGui.QIcon(
                (icon_path / "travel-orange.svg").as_posix())

        self.setWindowIcon(icon_full)

    def set_time_range(self) -> None:
        assert self._traffic is not None
        self.time_slider.setEnabled(True)
        start_time = cast(pd.Timestamp, self._traffic.start_time)
        end_time = cast(pd.Timestamp, self._traffic.end_time)
        self.dates = [
            start_time + i * (end_time - start_time) / 99 for i in range(100)
        ]

        tz_now = datetime.now().astimezone().tzinfo
        if cast(pd.Timestamp, self._traffic.start_time).tzinfo is not None:
            self.date_options = [
                t.tz_convert("utc").strftime("%H:%M") for t in self.dates
            ]
        else:
            self.date_options = [
                t.tz_localize(tz_now).tz_convert("utc").strftime("%H:%M")
                for t in self.dates
            ]
        self.time_slider_info.setText(self.date_options[-1])

    def set_float_columns(self) -> None:
        assert self._traffic is not None
        self.y_selector.clear()
        self.sec_y_selector.clear()
        for column, dtype in self._traffic.data.dtypes.items():
            if column not in ("latitude", "longitude"):
                if dtype in ["float64", "int64"]:
                    self.y_selector.addItem(column)
                    self.sec_y_selector.addItem(column)

    def openDump1090(self) -> None:
        reference, ok = QInputDialog.getText(self, "dump1090 reference",
                                             "Reference airport:")

        if ok:
            self.open_dropdown.setItemText(1, f"dump1090 ({reference})")
            self.decoder = ModeS_Decoder.from_dump1090(reference)
            refresh_time = config.getint("decoders",
                                         "refresh_time",
                                         fallback=30)
            self.updateTraffic = UpdateTraffic(self, refresh_time)
            self.updateTraffic.start()

    @dont_crash
    def openFile(self, *args, **kwargs) -> None:
        options = {
            "caption":
            "Open file",
            "filter": ("Pandas DataFrame (*.pkl);;"
                       "CSV files (*.csv);;"
                       "Sqlite3 files (*.db)"),
            #             "filter": "Data files (*.csv *.pkl)",
            "directory":
            os.path.expanduser("~"),
        }

        self.filename = QFileDialog.getOpenFileName(self, **options)[0]
        if self.filename == "":
            return
        self.filename = Path(self.filename)
        self._traffic = Traffic.from_file(self.filename)

        assert self._traffic is not None
        self._tview = self._traffic.sort_values("timestamp")
        assert self._tview is not None
        self.open_dropdown.setItemText(0, self.filename.name)
        self.map_plot.default_plot(self._tview)

        self.identifier_select.clear()
        for callsign in sorted(cast(Set[str], self._tview.callsigns)):
            self.identifier_select.addItem(callsign)

        self.set_time_range()
        self.set_float_columns()
Esempio n. 36
0
    def __init__(self, window, plugin, keystore, device_id):
        title = _("{} Settings").format(plugin.device)
        super(SettingsDialog, self).__init__(window, title)

        config = app_state.config
        hs_rows, hs_cols = (64, 128)

        def invoke_client(method, *args, **kw_args):
            unpair_after = kw_args.pop('unpair_after', False)

            def task():
                client = app_state.device_manager.client_by_id(device_id)
                if not client:
                    raise RuntimeError("Device not connected")
                if method:
                    getattr(client, method)(*args, **kw_args)
                if unpair_after:
                    app_state.device_manager.unpair_id(device_id)
                return client.features

            window.run_in_thread(task, on_success=update)

        def update(features):
            self.features = features
            set_label_enabled()
            bl_hash = bh2u(features.bootloader_hash)
            bl_hash = "\n".join([bl_hash[:32], bl_hash[32:]])
            noyes = [_("No"), _("Yes")]
            endis = [_("Enable Passphrases"), _("Disable Passphrases")]
            disen = [_("Disabled"), _("Enabled")]
            setchange = [_("Set a PIN"), _("Change PIN")]

            version = "%d.%d.%d" % (features.major_version,
                                    features.minor_version,
                                    features.patch_version)

            device_label.setText(features.label)
            pin_set_label.setText(noyes[features.pin_protection])
            passphrases_label.setText(disen[features.passphrase_protection])
            bl_hash_label.setText(bl_hash)
            label_edit.setText(features.label)
            device_id_label.setText(features.device_id)
            initialized_label.setText(noyes[features.initialized])
            version_label.setText(version)
            clear_pin_button.setVisible(features.pin_protection)
            clear_pin_warning.setVisible(features.pin_protection)
            pin_button.setText(setchange[features.pin_protection])
            pin_msg.setVisible(not features.pin_protection)
            passphrase_button.setText(endis[features.passphrase_protection])
            language_label.setText(features.language)

        def set_label_enabled():
            label_apply.setEnabled(label_edit.text() != self.features.label)

        def rename():
            invoke_client('change_label', label_edit.text())

        def toggle_passphrase():
            title = _("Confirm Toggle Passphrase Protection")
            currently_enabled = self.features.passphrase_protection
            if currently_enabled:
                msg = _("After disabling passphrases, you can only pair this "
                        "ElectrumSV wallet if it had an empty passphrase.  "
                        "If its passphrase was not empty, you will need to "
                        "create a new wallet with the install wizard.  You "
                        "can use this wallet again at any time by re-enabling "
                        "passphrases and entering its passphrase.")
            else:
                msg = _("Your current ElectrumSV wallet can only be used with "
                        "an empty passphrase.  You must create a separate "
                        "wallet with the install wizard for other passphrases "
                        "as each one generates a new set of addresses.")
            msg += "\n\n" + _("Are you sure you want to proceed?")
            if not self.question(msg, title=title):
                return
            invoke_client('toggle_passphrase', unpair_after=currently_enabled)

        def set_pin():
            invoke_client('set_pin', remove=False)

        def clear_pin():
            invoke_client('set_pin', remove=True)

        def wipe_device():
            accounts = window._wallet.get_accounts_for_keystore(keystore)
            if sum(sum(account.get_balance()) for account in accounts):
                title = _("Confirm Device Wipe")
                msg = _("Are you SURE you want to wipe the device?\n"
                        "Your wallet still has bitcoins in it!")
                if not self.question(
                        msg, title=title, icon=QMessageBox.Critical):
                    return
            invoke_client('wipe_device', unpair_after=True)

        def slider_moved():
            mins = timeout_slider.sliderPosition()
            timeout_minutes.setText(_("%2d minutes") % mins)

        def slider_released():
            config.set_session_timeout(timeout_slider.sliderPosition() * 60)

        # Information tab
        info_tab = QWidget()
        info_layout = QVBoxLayout(info_tab)
        info_glayout = QGridLayout()
        info_glayout.setColumnStretch(2, 1)
        device_label = QLabel()
        pin_set_label = QLabel()
        passphrases_label = QLabel()
        version_label = QLabel()
        device_id_label = QLabel()
        bl_hash_label = QLabel()
        bl_hash_label.setWordWrap(True)
        language_label = QLabel()
        initialized_label = QLabel()
        rows = [
            (_("Device Label"), device_label),
            (_("PIN set"), pin_set_label),
            (_("Passphrases"), passphrases_label),
            (_("Firmware Version"), version_label),
            (_("Device ID"), device_id_label),
            (_("Bootloader Hash"), bl_hash_label),
            (_("Language"), language_label),
            (_("Initialized"), initialized_label),
        ]
        for row_num, (label, widget) in enumerate(rows):
            info_glayout.addWidget(QLabel(label), row_num, 0)
            info_glayout.addWidget(widget, row_num, 1)
        info_layout.addLayout(info_glayout)

        # Settings tab
        settings_tab = QWidget()
        settings_layout = QVBoxLayout(settings_tab)
        settings_glayout = QGridLayout()

        # Settings tab - Label
        label_msg = QLabel(
            _("Name this {}.  If you have multiple devices "
              "their labels help distinguish them.").format(plugin.device))
        label_msg.setWordWrap(True)
        label_label = QLabel(_("Device Label"))
        label_edit = QLineEdit()
        label_edit.setMinimumWidth(150)
        label_edit.setMaxLength(plugin.MAX_LABEL_LEN)
        label_apply = QPushButton(_("Apply"))
        label_apply.clicked.connect(rename)
        label_edit.textChanged.connect(set_label_enabled)
        settings_glayout.addWidget(label_label, 0, 0)
        settings_glayout.addWidget(label_edit, 0, 1, 1, 2)
        settings_glayout.addWidget(label_apply, 0, 3)
        settings_glayout.addWidget(label_msg, 1, 1, 1, -1)

        # Settings tab - PIN
        pin_label = QLabel(_("PIN Protection"))
        pin_button = QPushButton()
        pin_button.clicked.connect(set_pin)
        settings_glayout.addWidget(pin_label, 2, 0)
        settings_glayout.addWidget(pin_button, 2, 1)
        pin_msg = QLabel(
            _("PIN protection is strongly recommended.  "
              "A PIN is your only protection against someone "
              "stealing your bitcoins if they obtain physical "
              "access to your {}.").format(plugin.device))
        pin_msg.setWordWrap(True)
        pin_msg.setStyleSheet("color: red")
        settings_glayout.addWidget(pin_msg, 3, 1, 1, -1)

        # Settings tab - Session Timeout
        timeout_label = QLabel(_("Session Timeout"))
        timeout_minutes = QLabel()
        timeout_slider = QSlider(Qt.Horizontal)
        timeout_slider.setRange(1, 60)
        timeout_slider.setSingleStep(1)
        timeout_slider.setTickInterval(5)
        timeout_slider.setTickPosition(QSlider.TicksBelow)
        timeout_slider.setTracking(True)
        timeout_msg = QLabel(
            _("Clear the session after the specified period "
              "of inactivity.  Once a session has timed out, "
              "your PIN and passphrase (if enabled) must be "
              "re-entered to use the device."))
        timeout_msg.setWordWrap(True)
        timeout_slider.setSliderPosition(config.get_session_timeout() // 60)
        slider_moved()
        timeout_slider.valueChanged.connect(slider_moved)
        timeout_slider.sliderReleased.connect(slider_released)
        settings_glayout.addWidget(timeout_label, 6, 0)
        settings_glayout.addWidget(timeout_slider, 6, 1, 1, 3)
        settings_glayout.addWidget(timeout_minutes, 6, 4)
        settings_glayout.addWidget(timeout_msg, 7, 1, 1, -1)
        settings_layout.addLayout(settings_glayout)
        settings_layout.addStretch(1)

        # Advanced tab
        advanced_tab = QWidget()
        advanced_layout = QVBoxLayout(advanced_tab)
        advanced_glayout = QGridLayout()

        # Advanced tab - clear PIN
        clear_pin_button = QPushButton(_("Disable PIN"))
        clear_pin_button.clicked.connect(clear_pin)
        clear_pin_warning = QLabel(
            _("If you disable your PIN, anyone with physical access to your "
              "{} device can spend your bitcoins.").format(plugin.device))
        clear_pin_warning.setWordWrap(True)
        clear_pin_warning.setStyleSheet("color: red")
        advanced_glayout.addWidget(clear_pin_button, 0, 2)
        advanced_glayout.addWidget(clear_pin_warning, 1, 0, 1, 5)

        # Advanced tab - toggle passphrase protection
        passphrase_button = QPushButton()
        passphrase_button.clicked.connect(toggle_passphrase)
        passphrase_msg = WWLabel(PASSPHRASE_HELP)
        passphrase_warning = WWLabel(PASSPHRASE_NOT_PIN)
        passphrase_warning.setStyleSheet("color: red")
        advanced_glayout.addWidget(passphrase_button, 3, 2)
        advanced_glayout.addWidget(passphrase_msg, 4, 0, 1, 5)
        advanced_glayout.addWidget(passphrase_warning, 5, 0, 1, 5)

        # Advanced tab - wipe device
        wipe_device_button = QPushButton(_("Wipe Device"))
        wipe_device_button.clicked.connect(wipe_device)
        wipe_device_msg = QLabel(
            _("Wipe the device, removing all data from it.  The firmware "
              "is left unchanged."))
        wipe_device_msg.setWordWrap(True)
        wipe_device_warning = QLabel(
            _("Only wipe a device if you have the recovery seed written down "
              "and the device wallet(s) are empty, otherwise the bitcoins "
              "will be lost forever."))
        wipe_device_warning.setWordWrap(True)
        wipe_device_warning.setStyleSheet("color: red")
        advanced_glayout.addWidget(wipe_device_button, 6, 2)
        advanced_glayout.addWidget(wipe_device_msg, 7, 0, 1, 5)
        advanced_glayout.addWidget(wipe_device_warning, 8, 0, 1, 5)
        advanced_layout.addLayout(advanced_glayout)
        advanced_layout.addStretch(1)

        tabs = QTabWidget(self)
        tabs.addTab(info_tab, _("Information"))
        tabs.addTab(settings_tab, _("Settings"))
        tabs.addTab(advanced_tab, _("Advanced"))
        dialog_vbox = QVBoxLayout(self)
        dialog_vbox.addWidget(tabs)
        dialog_vbox.addLayout(Buttons(CloseButton(self)))

        # Update information
        invoke_client(None)
Esempio n. 37
0
    def initUI(self):
        """
        Set up the user interface, signals & slots
        For better understaning, I made some shortcuts for variables,
        which is the instance of the QtWidgets classes.
        List of shortcuts(made):
        *btn - QPushButton;
        *lbl - QLabel;
        *slr - QSlider;
        *lyt - Q_lyt;
        *ctrl - ctrl;
        """
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        #video widget
        self.videoframe = QFrame()
        self.palette = self.videoframe.palette()
        self.palette.setColor(QtGui.QPalette.Window, QtGui.QColor(0, 0, 0))
        self.videoframe.setPalette(self.palette)
        self.videoframe.setAutoFillBackground(True)

        #time value
        self.timevalue = QDateTimeEdit()
        self.timevalue.setDisplayFormat('hh:mm:ss')
        self.timevalue.setReadOnly(True)
        self.timevalue.setFixedSize(80, 30)

        #position slider
        self.position_slr = QSlider(QtCore.Qt.Horizontal, self)
        self.position_slr.setToolTip("Position")
        self.position_slr.setMaximum(1000)
        self.position_slr.sliderMoved.connect(self.set_position)

        #play button
        self.play_btn = QPushButton()
        self.play_btn.setProperty("onplay", True)
        self.play_btn.setObjectName("play")
        self.play_btn.clicked.connect(self.play_pause)

        #stop button
        self.stop_btn = QPushButton()
        self.stop_btn.setObjectName('stop')
        self.stop_btn.clicked.connect(self.stop)

        #analyse button
        self.analyse_btn = QPushButton('Analyse')
        self.analyse_btn.setObjectName('analyse')
        self.analyse_btn.setFixedSize(70, 28)
        self.analyse_btn.clicked.connect(self.start_analyse)
        self.analyse_window = Analyse(self)
        self.analyse_window.off()
        self.analyse_btn.setEnabled(False)
        self.on_analyse = False

        self.details_btn = QPushButton('Details')
        self.details_btn.setVisible(False)
        self.details_btn.setObjectName('details')
        self.details_btn.setFixedSize(70, 28)
        self.details_btn.clicked.connect(self.show_details)

        self.details_wd = pictureViewer()
        self.details_wd.close()

        self.threadpool = QtCore.QThreadPool()
        self.threadpool.setMaxThreadCount(1)
        worker = loadModules(self)
        self.threadpool.start(worker)

        self.path_input = pathLineEdit(self)
        self.path_input.setObjectName('path')

        self.folder_btn = QPushButton()
        self.folder_btn.setObjectName('folder')
        self.folder_btn.clicked.connect(
            lambda x: self.select_folder(foldername=''))

        self.fileslist_lbl = QLabel('Playlist:')
        self.fileslist_lbl.setObjectName('lbl')
        self.fileslist_lbl.setIndent(12)

        self.fileslist = QListWidget()
        self.fileslist.itemClicked.connect(self.select_file)

        self.warnings_lbl = QLabel('Warnings time:')
        self.warnings_lbl.setObjectName('lbl')
        self.warnings_lbl.setIndent(12)

        self.warningslist = QListWidget()

        #volume slider
        self.volume_slr = QSlider(QtCore.Qt.Horizontal, self)
        self.volume_slr.setMaximum(100)
        self.volume_slr.setValue(self.mediaplayer.audio_get_volume())
        self.volume_slr.setToolTip("Volume")
        self.volume_slr.valueChanged.connect(self.set_volume)

        #setting up layouts
        folder_lyt = QHBoxLayout()
        folder_lyt.addWidget(self.path_input)
        folder_lyt.addWidget(self.folder_btn)

        leftside_lyt = QVBoxLayout()
        leftside_lyt.setContentsMargins(0, 10, 0, 0)
        leftside_lyt.addSpacing(6)
        leftside_lyt.addWidget(self.fileslist_lbl)
        leftside_lyt.addWidget(self.fileslist)

        analyse_btns = QHBoxLayout()
        analyse_btns.addWidget(self.details_btn)
        analyse_btns.addWidget(self.analyse_btn)
        leftside_lyt.addLayout(analyse_btns)

        leftside_lyt.addWidget(self.warnings_lbl)
        leftside_lyt.addWidget(self.warningslist)
        leftside_lyt.addLayout(folder_lyt)
        leftside_lyt.addSpacing(6)

        self.leftside_bg = QWidget()
        self.leftside_bg.setObjectName("leftside_bg")
        self.leftside_bg.setLayout(leftside_lyt)

        ctrl_lyt = QHBoxLayout()
        ctrl_lyt.addSpacing(20)
        ctrl_lyt.addWidget(self.play_btn)
        ctrl_lyt.setSpacing(0)
        ctrl_lyt.addWidget(self.stop_btn)
        ctrl_lyt.addStretch(1)
        ctrl_lyt.addWidget(self.volume_slr)

        ctrl_panel_lyt = QVBoxLayout()
        ctrl_panel_lyt.setContentsMargins(60, 12, 60, 12)
        ctrl_panel_lyt.addWidget(self.timevalue, 0, QtCore.Qt.AlignLeft)
        ctrl_panel_lyt.addWidget(self.position_slr)
        ctrl_panel_lyt.addLayout(ctrl_lyt)

        rightside_lyt = QVBoxLayout()
        rightside_lyt.addWidget(self.videoframe)
        rightside_lyt.addLayout(ctrl_panel_lyt)

        main_lyt = QHBoxLayout()
        main_lyt.setSpacing(0)
        main_lyt.setContentsMargins(0, 0, 0, 0)
        main_lyt.addWidget(self.leftside_bg)
        main_lyt.addLayout(rightside_lyt, 60)

        self.widget.setLayout(main_lyt)

        self.timer = QtCore.QTimer(self)
        self.timer.setInterval(200)
        self.timer.timeout.connect(self.updateUI)

        #creates connection to db
        self.db = db_api.create_connection(
            os.path.join(os.getcwd(), 'db', 'data.db'))
Esempio n. 38
0
class Player(QWidget):

    fullScreenChanged = pyqtSignal(bool)

    def __init__(self, playlist, parent=None):
        super(Player, self).__init__(parent)
        _globals['quit']=False
        self.colorDialog = None
        self.trackInfo = ""
        self.statusInfo = ""
        self.duration = 0
        self.height0 = None
        self.player = QMediaPlayer()
        self.playlist = QMediaPlaylist()
        self.player.setPlaylist(self.playlist)

        self.player.durationChanged.connect(self.durationChanged)
        self.player.positionChanged.connect(self.positionChanged)
        self.player.metaDataChanged.connect(self.metaDataChanged)
        self.playlist.currentIndexChanged.connect(self.playlistPositionChanged)
        self.player.mediaStatusChanged.connect(self.statusChanged)
        self.player.bufferStatusChanged.connect(self.bufferingProgress)
        self.player.videoAvailableChanged.connect(self.videoAvailableChanged)
        self.player.error.connect(self.displayErrorMessage)

        self.videoWidget = VideoWidget()
        self.player.setVideoOutput(self.videoWidget)

        self.playlistModel = PlaylistModel()
        self.playlistModel.setPlaylist(self.playlist)

        self.playlistView = QListView()
        self.playlistView.setModel(self.playlistModel)
        self.playlistView.setCurrentIndex(
                self.playlistModel.index(self.playlist.currentIndex(), 0))

        self.playlistView.activated.connect(self.jump)

        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, self.player.duration() / 1000)

        self.labelDuration = QLabel()
        self.slider.sliderMoved.connect(self.seek)

        self.labelHistogram = QLabel()
        self.labelHistogram.setText("Histogram:")
        self.histogram = HistogramWidget()
        histogramLayout = QHBoxLayout()
        histogramLayout.addWidget(self.labelHistogram)
        histogramLayout.addWidget(self.histogram, 1)

        self.probe = QVideoProbe()
        self.probe.videoFrameProbed.connect(self.histogram.processFrame)
        self.probe.setSource(self.player)

        openButton = QPushButton("Open", clicked=self.open)

        controls = PlayerControls()
        controls.setState(self.player.state())
        controls.setVolume(self.player.volume())
        controls.setMuted(controls.isMuted())

        controls.play.connect(self.player.play)
        controls.pause.connect(self.player.pause)
        controls.stop.connect(self.player.stop)
        controls.next.connect(self.playlist.next)
        controls.previous.connect(self.previousClicked)
        controls.changeVolume.connect(self.player.setVolume)
        controls.changeMuting.connect(self.player.setMuted)
        controls.changeRate.connect(self.player.setPlaybackRate)
        controls.stop.connect(self.videoWidget.update)

        self.player.stateChanged.connect(controls.setState)
        self.player.volumeChanged.connect(controls.setVolume)
        self.player.mutedChanged.connect(controls.setMuted)

        self.fullScreenButton = QPushButton("FullScreen")
        self.fullScreenButton.setCheckable(True)

        self.colorButton = QPushButton("Color Options...")
        self.colorButton.setEnabled(False)
        self.colorButton.clicked.connect(self.showColorDialog)

        displayLayout = QHBoxLayout()
        displayLayout.addWidget(self.videoWidget)
        # displayLayout.addWidget(self.playlistView)

        controlLayout = QHBoxLayout()
        controlLayout.setContentsMargins(0, 0, 0, 0)
        controlLayout.addWidget(openButton)
        controlLayout.addStretch(1)
        controlLayout.addWidget(controls)
        controlLayout.addStretch(1)
        controlLayout.addWidget(self.fullScreenButton)
        controlLayout.addWidget(self.colorButton)

        
        layout = QVBoxLayout()
        layout.addLayout(displayLayout,1)
        hLayout = QHBoxLayout()
        
        hLayout.addWidget(self.slider)
        hLayout.addWidget(self.labelDuration)
        self.videoWidget.setMinimumHeight(300)

        layout.addLayout(hLayout)
        layout.addLayout(controlLayout)
        # layout.addLayout(histogramLayout)

        self.setLayout(layout)

        if not self.player.isAvailable():
            QMessageBox.warning(self, "Service not available",
                    "The QMediaPlayer object does not have a valid service.\n"
                    "Please check the media service plugins are installed.")

            controls.setEnabled(False)
            self.playlistView.setEnabled(False)
            openButton.setEnabled(False)
            self.colorButton.setEnabled(False)
            self.fullScreenButton.setEnabled(False)

        self.metaDataChanged()

        self.addToPlaylist(playlist)

    def closeEvent(self,e):
        print('close')
        _globals['quit'] = True
        self.player.stop()
    def open(self):
        fileNames, _ = QFileDialog.getOpenFileNames(self, "Open Files")
        self.addToPlaylist(fileNames)

    def addToPlaylist(self, fileNames):
        for name in fileNames:
            fileInfo = QFileInfo(name)
            if fileInfo.exists():
                url = QUrl.fromLocalFile(fileInfo.absoluteFilePath())
                if fileInfo.suffix().lower() == 'm3u':
                    self.playlist.load(url)
                else:
                    self.playlist.addMedia(QMediaContent(url))
            else:
                url = QUrl(name)
                if url.isValid():
                    self.playlist.addMedia(QMediaContent(url))

    def durationChanged(self, duration):
        duration /= 1000

        self.duration = duration
        self.slider.setMaximum(duration)

    def positionChanged(self, progress):
        progress /= 1000

        if not self.slider.isSliderDown():
            self.slider.setValue(progress)

        self.updateDurationInfo(progress)

    def metaDataChanged(self):
        if self.player.isMetaDataAvailable():
            self.setTrackInfo("%s - %s" % (
                    self.player.metaData(QMediaMetaData.AlbumArtist),
                    self.player.metaData(QMediaMetaData.Title)))

    def previousClicked(self):
        # Go to the previous track if we are within the first 5 seconds of
        # playback.  Otherwise, seek to the beginning.
        if self.player.position() <= 5000:
            self.playlist.previous()
        else:
            self.player.setPosition(0)

    def jump(self, index):
        if index.isValid():
            self.playlist.setCurrentIndex(index.row())
            self.player.play()

    def playlistPositionChanged(self, position):
        self.playlistView.setCurrentIndex(
                self.playlistModel.index(position, 0))

    def seek(self, seconds):
        self.player.setPosition(seconds * 1000)

    def statusChanged(self, status):
        self.handleCursor(status)

        if status == QMediaPlayer.LoadingMedia:
            self.setStatusInfo("Loading...")
        elif status == QMediaPlayer.StalledMedia:
            self.setStatusInfo("Media Stalled")
        elif status == QMediaPlayer.EndOfMedia:
            QApplication.alert(self)
        elif status == QMediaPlayer.InvalidMedia:
            self.displayErrorMessage()
        else:
            self.setStatusInfo("")

    def handleCursor(self, status):
        if status in (QMediaPlayer.LoadingMedia, QMediaPlayer.BufferingMedia, QMediaPlayer.StalledMedia):
            self.setCursor(Qt.BusyCursor)
        else:
            self.unsetCursor()

    def bufferingProgress(self, progress):
        self.setStatusInfo("Buffering %d%" % progress)

    def videoAvailableChanged(self, available):
        if available:
            self.fullScreenButton.clicked.connect(
                    self.videoWidget.setFullScreen)
            self.videoWidget.fullScreenChanged.connect(
                    self.fullScreenButton.setChecked)

            if self.fullScreenButton.isChecked():
                self.videoWidget.setFullScreen(True)
        else:
            self.fullScreenButton.clicked.disconnect(
                    self.videoWidget.setFullScreen)
            self.videoWidget.fullScreenChanged.disconnect(
                    self.fullScreenButton.setChecked)

            self.videoWidget.setFullScreen(False)

        self.colorButton.setEnabled(available)

    def setTrackInfo(self, info):
        self.trackInfo = info

        if self.statusInfo != "":
            self.setWindowTitle("%s | %s" % (self.trackInfo, self.statusInfo))
        else:
            self.setWindowTitle(self.trackInfo)

    def setStatusInfo(self, info):
        self.statusInfo = info

        if self.statusInfo != "":
            self.setWindowTitle("%s | %s" % (self.trackInfo, self.statusInfo))
        else:
            self.setWindowTitle(self.trackInfo)

    def displayErrorMessage(self):
        self.setStatusInfo(self.player.errorString())

    def updateDurationInfo(self, currentInfo):
        duration = self.duration
        if currentInfo or duration:
            currentTime = QTime((currentInfo/3600)%60, (currentInfo/60)%60,
                    currentInfo%60, (currentInfo*1000)%1000)
            totalTime = QTime((duration/3600)%60, (duration/60)%60,
                    duration%60, (duration*1000)%1000);

            format = 'hh:mm:ss' if duration > 3600 else 'mm:ss'
            tStr = currentTime.toString(format) + " / " + totalTime.toString(format)
        else:
            tStr = ""

        self.labelDuration.setText(tStr)

    def showColorDialog(self):
        if self.colorDialog is None:
            brightnessSlider = QSlider(Qt.Horizontal)
            brightnessSlider.setRange(-100, 100)
            brightnessSlider.setValue(self.videoWidget.brightness())
            brightnessSlider.sliderMoved.connect(
                    self.videoWidget.setBrightness)
            self.videoWidget.brightnessChanged.connect(
                    brightnessSlider.setValue)

            contrastSlider = QSlider(Qt.Horizontal)
            contrastSlider.setRange(-100, 100)
            contrastSlider.setValue(self.videoWidget.contrast())
            contrastSlider.sliderMoved.connect(self.videoWidget.setContrast)
            self.videoWidget.contrastChanged.connect(contrastSlider.setValue)

            hueSlider = QSlider(Qt.Horizontal)
            hueSlider.setRange(-100, 100)
            hueSlider.setValue(self.videoWidget.hue())
            hueSlider.sliderMoved.connect(self.videoWidget.setHue)
            self.videoWidget.hueChanged.connect(hueSlider.setValue)

            saturationSlider = QSlider(Qt.Horizontal)
            saturationSlider.setRange(-100, 100)
            saturationSlider.setValue(self.videoWidget.saturation())
            saturationSlider.sliderMoved.connect(
                    self.videoWidget.setSaturation)
            self.videoWidget.saturationChanged.connect(
                    saturationSlider.setValue)

            layout = QFormLayout()
            layout.addRow("Brightness", brightnessSlider)
            layout.addRow("Contrast", contrastSlider)
            layout.addRow("Hue", hueSlider)
            layout.addRow("Saturation", saturationSlider)

            button = QPushButton("Close")
            layout.addRow(button)

            self.colorDialog = QDialog(self)
            self.colorDialog.setWindowTitle("Color Options")
            self.colorDialog.setLayout(layout)

            button.clicked.connect(self.colorDialog.close)

        self.colorDialog.show()
Esempio n. 39
0
class PreferencesDialogBase(QDialog):
    def __init__(self, parent, app, **kwargs):
        flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
        super().__init__(parent, flags, **kwargs)
        self.app = app
        self._setupUi()

        self.filterHardnessSlider.valueChanged['int'].connect(
            self.filterHardnessLabel.setNum)
        self.buttonBox.clicked.connect(self.buttonClicked)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)

    def _setupScanTypeBox(self, labels):
        self.scanTypeHLayout = QHBoxLayout()
        self.scanTypeLabel = QLabel(self)
        self.scanTypeLabel.setText(tr("Scan Type:"))
        self.scanTypeLabel.setMinimumSize(QSize(100, 0))
        self.scanTypeLabel.setMaximumSize(QSize(100, 16777215))
        self.scanTypeHLayout.addWidget(self.scanTypeLabel)
        self.scanTypeComboBox = QComboBox(self)
        for label in labels:
            self.scanTypeComboBox.addItem(label)
        self.scanTypeHLayout.addWidget(self.scanTypeComboBox)
        self.widgetsVLayout.addLayout(self.scanTypeHLayout)

    def _setupFilterHardnessBox(self):
        self.filterHardnessHLayout = QHBoxLayout()
        self.filterHardnessLabel = QLabel(self)
        self.filterHardnessLabel.setText(tr("Filter Hardness:"))
        self.filterHardnessLabel.setMinimumSize(QSize(0, 0))
        self.filterHardnessHLayout.addWidget(self.filterHardnessLabel)
        self.filterHardnessVLayout = QVBoxLayout()
        self.filterHardnessVLayout.setSpacing(0)
        self.filterHardnessHLayoutSub1 = QHBoxLayout()
        self.filterHardnessHLayoutSub1.setSpacing(12)
        self.filterHardnessSlider = QSlider(self)
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.filterHardnessSlider.sizePolicy().hasHeightForWidth())
        self.filterHardnessSlider.setSizePolicy(sizePolicy)
        self.filterHardnessSlider.setMinimum(1)
        self.filterHardnessSlider.setMaximum(100)
        self.filterHardnessSlider.setTracking(True)
        self.filterHardnessSlider.setOrientation(Qt.Horizontal)
        self.filterHardnessHLayoutSub1.addWidget(self.filterHardnessSlider)
        self.filterHardnessLabel = QLabel(self)
        self.filterHardnessLabel.setText("100")
        self.filterHardnessLabel.setMinimumSize(QSize(21, 0))
        self.filterHardnessHLayoutSub1.addWidget(self.filterHardnessLabel)
        self.filterHardnessVLayout.addLayout(self.filterHardnessHLayoutSub1)
        self.filterHardnessHLayoutSub2 = QHBoxLayout()
        self.filterHardnessHLayoutSub2.setContentsMargins(-1, 0, -1, -1)
        self.moreResultsLabel = QLabel(self)
        self.moreResultsLabel.setText(tr("More Results"))
        self.filterHardnessHLayoutSub2.addWidget(self.moreResultsLabel)
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                 QSizePolicy.Minimum)
        self.filterHardnessHLayoutSub2.addItem(spacerItem)
        self.fewerResultsLabel = QLabel(self)
        self.fewerResultsLabel.setText(tr("Fewer Results"))
        self.filterHardnessHLayoutSub2.addWidget(self.fewerResultsLabel)
        self.filterHardnessVLayout.addLayout(self.filterHardnessHLayoutSub2)
        self.filterHardnessHLayout.addLayout(self.filterHardnessVLayout)

    def _setupBottomPart(self):
        # The bottom part of the pref panel is always the same in all editions.
        self.fontSizeLabel = QLabel(tr("Font size:"))
        self.fontSizeSpinBox = QSpinBox()
        self.fontSizeSpinBox.setMinimum(5)
        self.widgetsVLayout.addLayout(
            horizontalWrap([self.fontSizeLabel, self.fontSizeSpinBox, None]))
        self.languageLabel = QLabel(tr("Language:"), self)
        self.languageComboBox = QComboBox(self)
        for lang in SUPPORTED_LANGUAGES:
            self.languageComboBox.addItem(LANGNAMES[lang])
        self.widgetsVLayout.addLayout(
            horizontalWrap([self.languageLabel, self.languageComboBox, None]))
        self.copyMoveLabel = QLabel(self)
        self.copyMoveLabel.setText(tr("Copy and Move:"))
        self.widgetsVLayout.addWidget(self.copyMoveLabel)
        self.copyMoveDestinationComboBox = QComboBox(self)
        self.copyMoveDestinationComboBox.addItem(tr("Right in destination"))
        self.copyMoveDestinationComboBox.addItem(tr("Recreate relative path"))
        self.copyMoveDestinationComboBox.addItem(tr("Recreate absolute path"))
        self.widgetsVLayout.addWidget(self.copyMoveDestinationComboBox)
        self.customCommandLabel = QLabel(self)
        self.customCommandLabel.setText(
            tr("Custom Command (arguments: %d for dupe, %r for ref):"))
        self.widgetsVLayout.addWidget(self.customCommandLabel)
        self.customCommandEdit = QLineEdit(self)
        self.widgetsVLayout.addWidget(self.customCommandEdit)

    def _setupAddCheckbox(self, name, label, parent=None):
        if parent is None:
            parent = self
        cb = QCheckBox(parent)
        cb.setText(label)
        setattr(self, name, cb)

    def _setupPreferenceWidgets(self):
        # Edition-specific
        pass

    def _setupUi(self):
        self.setWindowTitle(tr("Preferences"))
        self.resize(304, 263)
        self.setSizeGripEnabled(False)
        self.setModal(True)
        self.mainVLayout = QVBoxLayout(self)
        self.widgetsVLayout = QVBoxLayout()
        self._setupPreferenceWidgets()
        self.mainVLayout.addLayout(self.widgetsVLayout)
        self.buttonBox = QDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok
                                          | QDialogButtonBox.RestoreDefaults)
        self.mainVLayout.addWidget(self.buttonBox)
        if (not ISOSX) and (not ISLINUX):
            self.mainVLayout.removeWidget(self.ignoreHardlinkMatches)
            self.ignoreHardlinkMatches.setHidden(True)

    def _load(self, prefs, setchecked):
        # Edition-specific
        pass

    def _save(self, prefs, ischecked):
        # Edition-specific
        pass

    def load(self, prefs=None):
        if prefs is None:
            prefs = self.app.prefs
        self.filterHardnessSlider.setValue(prefs.filter_hardness)
        self.filterHardnessLabel.setNum(prefs.filter_hardness)
        setchecked = lambda cb, b: cb.setCheckState(Qt.Checked
                                                    if b else Qt.Unchecked)
        setchecked(self.mixFileKindBox, prefs.mix_file_kind)
        setchecked(self.useRegexpBox, prefs.use_regexp)
        setchecked(self.removeEmptyFoldersBox, prefs.remove_empty_folders)
        setchecked(self.ignoreHardlinkMatches, prefs.ignore_hardlink_matches)
        setchecked(self.debugModeBox, prefs.debug_mode)
        self.copyMoveDestinationComboBox.setCurrentIndex(
            prefs.destination_type)
        self.customCommandEdit.setText(prefs.custom_command)
        self.fontSizeSpinBox.setValue(prefs.tableFontSize)
        try:
            langindex = SUPPORTED_LANGUAGES.index(self.app.prefs.language)
        except ValueError:
            langindex = 0
        self.languageComboBox.setCurrentIndex(langindex)
        self._load(prefs, setchecked)

    def save(self):
        prefs = self.app.prefs
        prefs.filter_hardness = self.filterHardnessSlider.value()
        ischecked = lambda cb: cb.checkState() == Qt.Checked
        prefs.mix_file_kind = ischecked(self.mixFileKindBox)
        prefs.use_regexp = ischecked(self.useRegexpBox)
        prefs.remove_empty_folders = ischecked(self.removeEmptyFoldersBox)
        prefs.ignore_hardlink_matches = ischecked(self.ignoreHardlinkMatches)
        prefs.debug_mode = ischecked(self.debugModeBox)
        prefs.destination_type = self.copyMoveDestinationComboBox.currentIndex(
        )
        prefs.custom_command = str(self.customCommandEdit.text())
        prefs.tableFontSize = self.fontSizeSpinBox.value()
        lang = SUPPORTED_LANGUAGES[self.languageComboBox.currentIndex()]
        oldlang = self.app.prefs.language
        if oldlang not in SUPPORTED_LANGUAGES:
            oldlang = 'en'
        if lang != oldlang:
            QMessageBox.information(
                self, "",
                tr("dupeGuru has to restart for language changes to take effect."
                   ))
        self.app.prefs.language = lang
        self._save(prefs, ischecked)

    #--- Events
    def buttonClicked(self, button):
        role = self.buttonBox.buttonRole(button)
        if role == QDialogButtonBox.ResetRole:
            self.resetToDefaults()
Esempio n. 40
0
    def initUI(self):

        #menu statusbar
        self.statusBar().showMessage('Ready')
        menubar = self.menuBar()
        fileMenu = menubar.addMenu('File')
        editMenu = menubar.addMenu('Edit')

        impMenu = QMenu('Import', self)
        impAct = QAction('Import mail', self)
        impMenu.addAction(impAct)

        newAct = QAction('New', self)

        fileMenu.addAction(newAct)
        fileMenu.addMenu(impMenu)

        #toolbar
        exitAct = QAction(QIcon('exit.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)

        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAct)

        self.setMinimumSize(QSize(180, 180))
        self.setWindowTitle("PyQt")
        self.setWindowIcon(QIcon('exit.png'))

        # Create Main Widget
        mainwidget = QWidget()
        self.setCentralWidget(mainwidget)

        grid = QGridLayout()
        mainwidget.setLayout(grid)
        # Buttons
        b1 = QPushButton('QUIT', self)
        b2 = QPushButton('button with long text', self)
        grid.addWidget(b1, 1, 1)
        grid.addWidget(b2, 2, 1)
        # Enter fields
        t1 = QLabel('text input')
        t2 = QLabel('multiline input')
        t1f = QLineEdit()
        t2f = QTextEdit()
        t2f.resize(50, 250)

        grid.addWidget(t1, 3, 0)
        grid.addWidget(t1f, 3, 1)
        grid.addWidget(t2, 4, 0)
        grid.addWidget(t2f, 4, 1)
        #Listbox
        l1t = QLabel('list')
        l1 = QListWidget(self)
        l1.resize(50, 50)
        for i in range(6):
            l1.addItem('alt%s' % (i + 1))
        grid.addWidget(l1t, 5, 0)
        grid.addWidget(l1, 5, 1)
        #Combo
        c1t = QLabel('combo')
        c1 = QComboBox(self)
        for i in range(6):
            c1.addItem('alt%s' % (i + 1))
        grid.addWidget(c1t, 6, 0)
        grid.addWidget(c1, 6, 1)
        #Radio
        groupBox = QGroupBox('Radio')
        layout = QHBoxLayout()
        self.b1 = QRadioButton("One")
        self.b1.setChecked(True)
        self.b1.toggled.connect(lambda: self.btnstate(self.b1))
        layout.addWidget(self.b1)

        self.b2 = QRadioButton("Two")
        self.b2.toggled.connect(lambda: self.btnstate(self.b2))
        layout.addWidget(self.b2)
        groupBox.setLayout(layout)
        grid.addWidget(groupBox, 7, 1)
        #Checkbox
        cb = QCheckBox('toggle', self)
        grid.addWidget(cb, 8, 0)
        #Slider
        s1t = QLabel('slider')
        s1 = QSlider(Qt.Horizontal)
        grid.addWidget(s1t, 9, 0)
        grid.addWidget(s1, 9, 1)
        #progress
        p1t = QLabel('progress')
        p1 = QProgressBar(self)
        p1.setValue(40)
        grid.addWidget(p1t, 10, 0)
        grid.addWidget(p1, 10, 1)
Esempio n. 41
0
class PlayerControls(QWidget):

    play = pyqtSignal()
    pause = pyqtSignal()
    stop = pyqtSignal()
    next = pyqtSignal()
    previous = pyqtSignal()
    changeVolume = pyqtSignal(int)
    changeMuting = pyqtSignal(bool)
    changeRate = pyqtSignal(float)

    def __init__(self, parent=None):
        super(PlayerControls, self).__init__(parent)

        self.playerState = QMediaPlayer.StoppedState
        self.playerMuted = False

        self.playButton = QToolButton(clicked=self.playClicked)
        self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))

        self.stopButton = QToolButton(clicked=self.stop)
        self.stopButton.setIcon(self.style().standardIcon(QStyle.SP_MediaStop))
        self.stopButton.setEnabled(False)

        self.nextButton = QToolButton(clicked=self.next)
        self.nextButton.setIcon(
                self.style().standardIcon(QStyle.SP_MediaSkipForward))

        self.previousButton = QToolButton(clicked=self.previous)
        self.previousButton.setIcon(
                self.style().standardIcon(QStyle.SP_MediaSkipBackward))

        self.muteButton = QToolButton(clicked=self.muteClicked)
        self.muteButton.setIcon(
                self.style().standardIcon(QStyle.SP_MediaVolume))

        self.volumeSlider = QSlider(Qt.Horizontal,
                sliderMoved=self.changeVolume)
        self.volumeSlider.setRange(0, 100)

        self.rateBox = QComboBox(activated=self.updateRate)
        self.rateBox.addItem("0.5x", 0.5)
        self.rateBox.addItem("1.0x", 1.0)
        self.rateBox.addItem("2.0x", 2.0)
        self.rateBox.setCurrentIndex(1)

        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.stopButton)
        layout.addWidget(self.previousButton)
        layout.addWidget(self.playButton)
        layout.addWidget(self.nextButton)
        layout.addWidget(self.muteButton)
        layout.addWidget(self.volumeSlider)
        layout.addWidget(self.rateBox)
        self.setLayout(layout)

    def state(self):
        return self.playerState

    def setState(self,state):
        if state != self.playerState:
            self.playerState = state

            if state == QMediaPlayer.StoppedState:

                
                self.stopButton.setEnabled(False)
                self.playButton.setIcon(
                        self.style().standardIcon(QStyle.SP_MediaPlay))
                if not _globals['quit']:
                    self.playClicked()
            elif state == QMediaPlayer.PlayingState:
                self.stopButton.setEnabled(True)
                self.playButton.setIcon(
                        self.style().standardIcon(QStyle.SP_MediaPause))
            elif state == QMediaPlayer.PausedState:
                self.stopButton.setEnabled(True)
                self.playButton.setIcon(
                        self.style().standardIcon(QStyle.SP_MediaPlay))

    def volume(self):
        return self.volumeSlider.value()

    def setVolume(self, volume):
        self.volumeSlider.setValue(volume)

    def isMuted(self):
        return self.playerMuted

    def setMuted(self, muted):
        if muted != self.playerMuted:
            self.playerMuted = muted

            self.muteButton.setIcon(
                    self.style().standardIcon(
                            QStyle.SP_MediaVolumeMuted if muted else QStyle.SP_MediaVolume))

    def playClicked(self):
        if self.playerState in (QMediaPlayer.StoppedState, QMediaPlayer.PausedState):
            self.play.emit()
        elif self.playerState == QMediaPlayer.PlayingState:
            self.pause.emit()

    def muteClicked(self):
        self.changeMuting.emit(not self.playerMuted)

    def playbackRate(self):
        return self.rateBox.itemData(self.rateBox.currentIndex())

    def setPlaybackRate(self, rate):
        for i in range(self.rateBox.count()):
            if qFuzzyCompare(rate, self.rateBox.itemData(i)):
                self.rateBox.setCurrentIndex(i)
                return

        self.rateBox.addItem("%dx" % rate, rate)
        self.rateBox.setCurrentIndex(self.rateBox.count() - 1)

    def updateRate(self):
        self.changeRate.emit(self.playbackRate())
Esempio n. 42
0
    def block1(self):
        self.block1_group_box = QGroupBox("Theme and utility")
        self.block1_group_box.setToolTip(self.tooltips["colors_and_opacity"])

        b1 = QPushButton()
        b1.setText("Background color")
        b1.setObjectName("background_color_button")
        b1.clicked.connect(self.on_click)

        self.background_color_line = QLineEdit()
        self.background_color_line.setReadOnly(True)

        self.background_color_prew = QLabel()
        self.background_color_prew.setMinimumSize(20, 1)

        b2 = QPushButton()
        b2.setText("Accent color")
        b2.setObjectName("accent_color_button")
        b2.clicked.connect(self.on_click)

        self.accent_color_line = QLineEdit()
        self.accent_color_line.setReadOnly(True)

        self.accent_color_prew = QLabel()
        self.accent_color_prew.setMinimumSize(20, 1)

        # opacity
        l1 = QLabel()
        l1.setText("Opacity")

        self.opacity_slider = QSlider(Qt.Horizontal)
        self.opacity_slider.setRange(10, 100)
        self.opacity_slider.valueChanged.connect(self.update_opacity)
        self.opacity_label = QLabel()
        self.opacity_label.setText("10.0")

        # Frame delay
        l2 = QLabel()
        l2.setText("Window invisibility time")
        l2.setToolTip(self.tooltips["frame_delay"])

        self.frame_delay_selector = QDoubleSpinBox()
        self.frame_delay_selector.setMinimum(0.0)
        self.frame_delay_selector.setSingleStep(0.1)
        self.frame_delay_selector.setToolTip(self.tooltips["frame_delay"])

        hbox1 = QHBoxLayout()
        hbox2 = QHBoxLayout()
        hbox3 = QHBoxLayout()
        hbox4 = QHBoxLayout()
        vbox = QVBoxLayout()

        hbox1.addWidget(b1)
        hbox1.addStretch()
        hbox1.addWidget(self.background_color_prew)
        hbox1.addWidget(self.background_color_line)

        hbox2.addWidget(b2)
        hbox2.addStretch()
        hbox2.addWidget(self.accent_color_prew)
        hbox2.addWidget(self.accent_color_line)

        hbox3.addWidget(l1)
        hbox3.addWidget(self.opacity_label)
        hbox3.addWidget(self.opacity_slider)

        hbox4.addWidget(l2)
        hbox4.addStretch()
        hbox4.addWidget(self.frame_delay_selector)

        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)
        vbox.addLayout(hbox4)

        self.block1_group_box.setLayout(vbox)
Esempio n. 43
0
class Qshot_settings(QMainWindow):

    # pyqtsignal has a bug so I have to write these here
    oppcity_emitter = pyqtSignal(float)
    background_color_emitter = pyqtSignal(str)
    accent_color_emitter = pyqtSignal(str)
    update_frame_emitter = pyqtSignal()
    hide_frame_emitter = pyqtSignal(bool)

    def __init__(self, cfg_path, default_cfg_path, statics_path):
        super().__init__()
        self.cfg_path = cfg_path
        self.default_cfg_path = default_cfg_path
        self.tooltips_path = os.path.join(statics_path, "texts",
                                          "tooltips.yaml")
        self.about_path = os.path.join(statics_path, "texts", "about.txt")
        self.icon_path = os.path.join(statics_path, "icons", "Qs.ico")

        self.is_settings_started = False

    # start frame and options
    def start_settings(self):
        """starts settings window
        this is not in the constructor because it slows startup of the main frame
        and if there is an error on the cfg file I want settings popup after main frames popup
        """
        self.is_settings_started = True  # once frame started I don't want to recreate it again (this variable used in the Quickshot.py)
        self.init_variables()
        self.set_static_variables()
        self.set_default_cfg()

        self.init_ui()

        cfg_status = self.read_cfg_file()
        if (cfg_status):
            self.variable_to_ui()

    def update_settings_ui(self):
        """refreshes the settings frame without recreating ui elements"""
        cfg_status = self.read_cfg_file()
        if (cfg_status):
            self.variable_to_ui()
        self.show()

    def init_ui(self):
        """inits ui"""
        self.setWindowTitle("Qshot Settings")
        self.setWindowIcon(QtGui.QIcon(self.icon_path))

        self.menu_bar()
        self.block1()
        self.block2()
        self.block3()
        self.block4()
        self.block5()

        self.setup_ui()
        self.show()

    def init_variables(self):
        """inits class variables"""
        self.ss_extensions_list = [".png", ".jpg"]
        self.png_compression_level_list = [
            "1", "2", "3", "4", "5", "6", "7", "8", "9"
        ]

    # read options and assign to local variable (file -> ui)
    def read_cfg_file(self):
        """Reads cfg file and makes assignment to local variables
        shows error popup if cfg file has errors
        """
        try:
            # read cfg file
            with open(self.cfg_path, "r") as file:
                cfg = yaml.safe_load(file)

            # quickshot_frame
            # theme
            self.background_color = cfg["quickshot_frame"]["theme"][
                "background_color"]
            self.accent_color = cfg["quickshot_frame"]["theme"]["accent_color"]
            self.opacity = cfg["quickshot_frame"]["theme"]["opacity"]

            # hotkeys
            self.ss_hotkey = cfg["quickshot_frame"]["hotkeys"]["ss_hotkey"]
            self.hide_hotkey = cfg["quickshot_frame"]["hotkeys"]["hide_hotkey"]

            # utilities
            self.frame_delay = cfg["quickshot_frame"]["utilities"][
                "frame_delay"]

            # ss ss_handler
            # naming
            self.save_path = os.path.normpath(
                cfg["ss_handler"]["naming"]["save_path"])  # convert to path
            self.create_root_file = cfg["ss_handler"]["naming"][
                "create_root_file"]
            self.before_ss_name = cfg["ss_handler"]["naming"]["before_ss_name"]
            self.after_ss_name = cfg["ss_handler"]["naming"]["after_ss_name"]
            self.before_number = cfg["ss_handler"]["naming"]["before_number"]
            self.after_number = cfg["ss_handler"]["naming"]["after_number"]
            self.date_formatting = cfg["ss_handler"]["naming"][
                "date_formatting"]
            self.use_system_local_date_naming = cfg["ss_handler"]["naming"][
                "use_system_local_date_naming"]

            # ss_options
            self.ss_extension = cfg["ss_handler"]["ss_options"]["ss_extension"]
            self.png_compression_level = cfg["ss_handler"]["ss_options"][
                "png_compression_level"]
            self.default_screen = cfg["ss_handler"]["ss_options"][
                "default_screen"]
            self.save_clipboard = cfg["ss_handler"]["ss_options"][
                "save_clipboard"]

            return True
        except Exception as e:
            print(e)
            self.show_alert_popup(
                "There is a problem with cfg file please reset settings and restart Quickshot"
            )
            return False

    def variable_to_ui(self):
        """assigns local variables to ui"""
        try:
            # theme and utilities
            self.opacity_slider.setSliderPosition(int(self.opacity * 100))
            self.background_color_line.setText(self.background_color)
            self.background_color_prew.setStyleSheet(
                "background-color: {0};".format(self.background_color))
            self.accent_color_line.setText(self.accent_color)
            self.accent_color_prew.setStyleSheet(
                "background-color: {0};".format(self.accent_color))

            # hotkeys
            self.ss_key_line.setText(self.ss_hotkey)
            self.hide_key.setText(self.hide_hotkey)

            # set the frame delay
            self.frame_delay_selector.setValue(self.frame_delay)

            # path and naming
            self.save_path_line.setText(self.save_path)
            self.root_file_line.setText(self.create_root_file)
            self.before_ss_name_line.setText(self.before_ss_name)
            self.after_ss_name_line.setText(self.after_ss_name)
            self.before_number_line.setText(self.before_number)
            self.after_number_line.setText(self.after_number)
            self.date_formatting_line.setText(self.date_formatting)

            if (self.use_system_local_date_naming):
                self.local_date_naming_checkbox.setChecked(True)
            else:
                self.local_date_naming_checkbox.setChecked(False)

            # ss options
            extension_index = self.extension_combobox.findText(
                self.ss_extension, QtCore.Qt.MatchFixedString)
            self.extension_combobox.setCurrentIndex(extension_index)

            compression_level_index = self.png_compression_combobox.findText(
                str(self.png_compression_level), QtCore.Qt.MatchFixedString)
            self.png_compression_combobox.setCurrentIndex(
                compression_level_index)

            # if all_screens_checkbox is checked disable the default_screen_selector
            if (self.default_screen == 0):
                self.all_screens_checkbox.setChecked(True)
                self.default_screen_selector.setDisabled(True)
            else:
                self.all_screens_checkbox.setChecked(False)
                self.default_screen_selector.setDisabled(False)
                self.default_screen_selector.setValue(self.default_screen)

            if (self.save_clipboard):
                self.save_clipboard_checkbox.setChecked(True)
            else:
                self.save_clipboard_checkbox.setChecked(False)

        except Exception as e:
            print(e)
            self.show_alert_popup(
                "There is a problem with cfg file please reset settings and restart Quickshot"
            )

    # get options from ui and write them to file (ui -> file)
    def ui_to_variable(self):
        """assign selected settings to new_cfg variable"""
        try:
            # colors and opacity
            self.new_cfg["quickshot_frame"]["theme"][
                "background_color"] = self.background_color_line.text()
            self.new_cfg["quickshot_frame"]["theme"][
                "accent_color"] = self.accent_color_line.text()
            self.new_cfg["quickshot_frame"]["theme"][
                "opacity"] = self.opacity_slider.value() / 100

            # hotkeys
            self.new_cfg["quickshot_frame"]["hotkeys"][
                "ss_hotkey"] = self.ss_key_line.text()
            self.new_cfg["quickshot_frame"]["hotkeys"][
                "hide_hotkey"] = self.hide_key.text()

            # set the frame delay
            self.new_cfg["quickshot_frame"]["utilities"][
                "frame_delay"] = self.frame_delay_selector.value()

            # path and naming
            self.new_cfg["ss_handler"]["naming"][
                "save_path"] = self.save_path_line.text()
            self.new_cfg["ss_handler"]["naming"][
                "create_root_file"] = self.root_file_line.text()
            self.new_cfg["ss_handler"]["naming"][
                "before_ss_name"] = self.before_ss_name_line.text()
            self.new_cfg["ss_handler"]["naming"][
                "after_ss_name"] = self.after_ss_name_line.text()
            self.new_cfg["ss_handler"]["naming"][
                "before_number"] = self.before_number_line.text()
            self.new_cfg["ss_handler"]["naming"][
                "after_number"] = self.after_number_line.text()
            self.new_cfg["ss_handler"]["naming"][
                "date_formatting"] = self.date_formatting_line.text()

            if (self.local_date_naming_checkbox.isChecked()):
                self.new_cfg["ss_handler"]["naming"][
                    "use_system_local_date_naming"] = 1
            else:
                self.new_cfg["ss_handler"]["naming"][
                    "use_system_local_date_naming"] = 0

            # ss options
            self.new_cfg["ss_handler"]["ss_options"][
                "ss_extension"] = self.extension_combobox.currentText()

            self.new_cfg["ss_handler"]["ss_options"][
                "png_compression_level"] = int(
                    self.png_compression_combobox.currentText())

            if (self.all_screens_checkbox.isChecked()):
                self.new_cfg["ss_handler"]["ss_options"]["default_screen"] = 0
            else:
                self.new_cfg["ss_handler"]["ss_options"][
                    "default_screen"] = self.default_screen_selector.value()

            if (self.save_clipboard_checkbox.isChecked()):
                self.new_cfg["ss_handler"]["ss_options"]["save_clipboard"] = 1
            else:
                self.new_cfg["ss_handler"]["ss_options"]["save_clipboard"] = 0

            return True
        except Exception as e:
            print(e)
            self.show_alert_popup(
                "There is a problem with saving values please check the values or reset settings"
            )
            return False

    def write_cfg_file(self, cfg):
        try:
            with open(self.cfg_path, "w") as file:
                yaml.dump(cfg, file, indent=4)
            return True
        except Exception as e:
            print(e)
            self.show_alert_popup(
                "There is a problem with saving values please check the values or reset settings"
            )
            return False

    def set_default_cfg(self):
        """Reads default_cfg_file and sets default_cfg and new_cfg"""
        try:
            # read default_cfg_file
            with open(self.default_cfg_path, "r") as file:
                self.default_cfg = yaml.safe_load(file)

            # new_cfg is just a copy of default_cfg but has to be deep copy, it is going to be changed according to ui
            self.new_cfg = copy.deepcopy(self.default_cfg)

        except Exception as e:
            print(e)
            self.show_alert_popup(
                "There is a problem with installation, please reinstall the application."
            )
            self.close()

    def set_static_variables(self):
        """Reads and sets set_static_variables"""
        try:
            with open(self.tooltips_path, "r") as file:
                self.tooltips = yaml.safe_load(file)

            with open(self.about_path, "r") as file:
                self.about_text = file.read()
        except Exception as e:
            print(e)
            self.show_alert_popup(
                "There is a problem with installation, please reinstall the application."
            )
            self.close()

    # ui elements
    def setup_ui(self):
        """sets up ui by assigning elements to layouts"""
        self.grid = QGridLayout()
        self.main_grid = QGridLayout()

        # top grid
        self.grid.addWidget(self.block1_group_box, 0, 0)
        self.grid.addWidget(self.block2_group_box, 0, 1)
        self.grid.addWidget(self.block3_group_box, 1, 0)
        self.grid.addWidget(self.block4_group_box, 1, 1)

        # bottom grid
        self.main_grid.addLayout(self.grid, 0, 0)
        self.main_grid.addLayout(self.bottom_layout, 1, 0)

        # central widget is required when using Q mainwindow
        self.central_widget = QtWidgets.QWidget(self)
        self.central_widget.setLayout(self.main_grid)
        self.setCentralWidget(self.central_widget)

    def block1(self):
        self.block1_group_box = QGroupBox("Theme and utility")
        self.block1_group_box.setToolTip(self.tooltips["colors_and_opacity"])

        b1 = QPushButton()
        b1.setText("Background color")
        b1.setObjectName("background_color_button")
        b1.clicked.connect(self.on_click)

        self.background_color_line = QLineEdit()
        self.background_color_line.setReadOnly(True)

        self.background_color_prew = QLabel()
        self.background_color_prew.setMinimumSize(20, 1)

        b2 = QPushButton()
        b2.setText("Accent color")
        b2.setObjectName("accent_color_button")
        b2.clicked.connect(self.on_click)

        self.accent_color_line = QLineEdit()
        self.accent_color_line.setReadOnly(True)

        self.accent_color_prew = QLabel()
        self.accent_color_prew.setMinimumSize(20, 1)

        # opacity
        l1 = QLabel()
        l1.setText("Opacity")

        self.opacity_slider = QSlider(Qt.Horizontal)
        self.opacity_slider.setRange(10, 100)
        self.opacity_slider.valueChanged.connect(self.update_opacity)
        self.opacity_label = QLabel()
        self.opacity_label.setText("10.0")

        # Frame delay
        l2 = QLabel()
        l2.setText("Window invisibility time")
        l2.setToolTip(self.tooltips["frame_delay"])

        self.frame_delay_selector = QDoubleSpinBox()
        self.frame_delay_selector.setMinimum(0.0)
        self.frame_delay_selector.setSingleStep(0.1)
        self.frame_delay_selector.setToolTip(self.tooltips["frame_delay"])

        hbox1 = QHBoxLayout()
        hbox2 = QHBoxLayout()
        hbox3 = QHBoxLayout()
        hbox4 = QHBoxLayout()
        vbox = QVBoxLayout()

        hbox1.addWidget(b1)
        hbox1.addStretch()
        hbox1.addWidget(self.background_color_prew)
        hbox1.addWidget(self.background_color_line)

        hbox2.addWidget(b2)
        hbox2.addStretch()
        hbox2.addWidget(self.accent_color_prew)
        hbox2.addWidget(self.accent_color_line)

        hbox3.addWidget(l1)
        hbox3.addWidget(self.opacity_label)
        hbox3.addWidget(self.opacity_slider)

        hbox4.addWidget(l2)
        hbox4.addStretch()
        hbox4.addWidget(self.frame_delay_selector)

        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)
        vbox.addLayout(hbox4)

        self.block1_group_box.setLayout(vbox)

    def block2(self):
        self.block2_group_box = QGroupBox("Hotkeys")
        self.block2_group_box.setToolTip(self.tooltips["hotkeys"])

        l1 = QLabel()
        l1.setText("Screenshot key")

        self.ss_key_line = QLineEdit()
        self.ss_key_line.setText("")

        l2 = QLabel()
        l2.setText("Hide key")

        self.hide_key = QLineEdit()
        self.hide_key.setText("")

        hbox1 = QHBoxLayout()
        hbox2 = QHBoxLayout()
        vbox = QVBoxLayout()

        hbox1.addWidget(l1)
        hbox1.addStretch()
        hbox1.addWidget(self.ss_key_line)

        hbox2.addWidget(l2)
        hbox2.addStretch()
        hbox2.addWidget(self.hide_key)

        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)

        self.block2_group_box.setLayout(vbox)

    def block3(self):
        self.block3_group_box = QGroupBox("Path and naming")

        # Save Path
        b1 = QPushButton()
        b1.setText("Chose save folder")
        b1.setObjectName("save_path_button")
        b1.clicked.connect(self.on_click)

        self.save_path_line = QLineEdit()
        self.save_path_line.setToolTip(self.tooltips["save_path"])

        # Root file
        l2 = QLabel()
        l2.setText("Root file")
        l2.setToolTip(self.tooltips["root_file"])

        self.root_file_line = QLineEdit()
        self.root_file_line.setToolTip(self.tooltips["root_file"])

        # Text before ss name
        l3 = QLabel()
        l3.setText("Text before ss name")
        l3.setToolTip(self.tooltips["text_before_ss-text_after_ss"])

        self.before_ss_name_line = QLineEdit()
        self.before_ss_name_line.setToolTip(
            self.tooltips["text_before_ss-text_after_ss"])

        # Text after ss name
        l4 = QLabel()
        l4.setText("Text after ss name")
        l4.setToolTip(self.tooltips["text_before_ss-text_after_ss"])

        self.after_ss_name_line = QLineEdit()
        self.after_ss_name_line.setToolTip(
            self.tooltips["text_before_ss-text_after_ss"])

        # Text before ss number
        l5 = QLabel()
        l5.setText("Text before ss number")
        l5.setToolTip(
            self.tooltips["text_before_ss_number-text_after_ss_number"])

        self.before_number_line = QLineEdit()
        self.before_number_line.setToolTip(
            self.tooltips["text_before_ss_number-text_after_ss_number"])

        # Text after ss number
        l6 = QLabel()
        l6.setText("Text after ss number")
        l6.setToolTip(
            self.tooltips["text_before_ss_number-text_after_ss_number"])

        self.after_number_line = QLineEdit()
        self.after_number_line.setToolTip(
            self.tooltips["text_before_ss_number-text_after_ss_number"])

        # Date formatting
        l7 = QLabel()
        l7.setText("Date formatting")
        l7.setToolTip(self.tooltips["date_formatting"])

        self.date_formatting_line = QLineEdit()
        self.date_formatting_line.setToolTip(self.tooltips["date_formatting"])

        # Use local date naming
        l8 = QLabel()
        l8.setText("Use local date naming")
        l8.setToolTip(self.tooltips["Use_local_date_naming"])

        self.local_date_naming_checkbox = QCheckBox()
        self.local_date_naming_checkbox.setToolTip(
            self.tooltips["Use_local_date_naming"])

        hbox1 = QHBoxLayout()
        hbox2 = QHBoxLayout()
        hbox3 = QHBoxLayout()
        hbox4 = QHBoxLayout()
        hbox5 = QHBoxLayout()
        hbox6 = QHBoxLayout()
        hbox7 = QHBoxLayout()
        hbox8 = QHBoxLayout()
        vbox = QVBoxLayout()

        hbox1.addWidget(b1)
        hbox1.addStretch()
        hbox1.addWidget(self.save_path_line)

        hbox2.addWidget(l2)
        hbox2.addStretch()
        hbox2.addWidget(self.root_file_line)

        hbox3.addWidget(l3)
        hbox3.addStretch()
        hbox3.addWidget(self.before_ss_name_line)

        hbox4.addWidget(l4)
        hbox4.addStretch()
        hbox4.addWidget(self.after_ss_name_line)

        hbox5.addWidget(l5)
        hbox5.addStretch()
        hbox5.addWidget(self.before_number_line)

        hbox6.addWidget(l6)
        hbox6.addStretch()
        hbox6.addWidget(self.after_number_line)

        hbox7.addWidget(l7)
        hbox7.addStretch()
        hbox7.addWidget(self.date_formatting_line)

        hbox8.addWidget(l8)
        hbox8.addStretch()
        hbox8.addWidget(self.local_date_naming_checkbox)

        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)
        vbox.addLayout(hbox4)
        vbox.addLayout(hbox5)
        vbox.addLayout(hbox6)
        vbox.addLayout(hbox7)
        vbox.addLayout(hbox8)

        self.block3_group_box.setLayout(vbox)

    def block4(self):
        self.block4_group_box = QGroupBox("Screenshot options")

        # extension
        l1 = QLabel()
        l1.setText("Extension")
        l1.setToolTip(self.tooltips["extension"])

        self.extension_combobox = QComboBox()
        self.extension_combobox.addItems(self.ss_extensions_list)
        self.extension_combobox.setToolTip(self.tooltips["extension"])

        # png compression level
        l2 = QLabel()
        l2.setText("png compression level")
        l2.setToolTip(self.tooltips["png_compression_level"])

        self.png_compression_combobox = QComboBox()
        self.png_compression_combobox.addItems(self.png_compression_level_list)
        self.png_compression_combobox.setToolTip(
            self.tooltips["png_compression_level"])

        # Default screen
        l4 = QLabel()
        l4.setText("Default screen")
        l4.setToolTip(self.tooltips["default_screen"])

        l5 = QLabel()
        l5.setText("All")
        l5.setToolTip(self.tooltips["default_screen"])

        self.all_screens_checkbox = QCheckBox()
        self.all_screens_checkbox.setObjectName("all_screens_checkbox")
        self.all_screens_checkbox.clicked.connect(self.on_click)
        self.all_screens_checkbox.setToolTip(self.tooltips["default_screen"])

        self.default_screen_selector = QSpinBox()
        self.default_screen_selector.setMinimum(1)
        self.default_screen_selector.setToolTip(
            self.tooltips["default_screen"])

        # save clipboard
        l6 = QLabel()
        l6.setText("Copy ss to clipboard")
        l6.setToolTip(self.tooltips["save_clipboard"])

        self.save_clipboard_checkbox = QCheckBox()
        self.save_clipboard_checkbox.setToolTip(
            self.tooltips["save_clipboard"])

        hbox1 = QHBoxLayout()
        hbox2 = QHBoxLayout()
        hbox3 = QHBoxLayout()
        hbox4 = QHBoxLayout()
        hbox5 = QHBoxLayout()
        vbox = QVBoxLayout()

        hbox1.addWidget(l1)
        hbox1.addStretch()
        hbox1.addWidget(self.extension_combobox)

        hbox2.addWidget(l2)
        hbox2.addStretch()
        hbox2.addWidget(self.png_compression_combobox)

        hbox4.addWidget(l4)
        hbox4.addStretch()
        hbox4.addWidget(l5)
        hbox4.addWidget(self.all_screens_checkbox)
        hbox4.addWidget(self.default_screen_selector)

        hbox5.addWidget(l6)
        hbox5.addStretch()
        hbox5.addWidget(self.save_clipboard_checkbox)

        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)
        vbox.addLayout(hbox4)
        vbox.addLayout(hbox5)

        self.block4_group_box.setLayout(vbox)

    def block5(self):
        self.bottom_layout = QHBoxLayout()

        l1 = QLabel()
        l1.setText("Hover over sections for tips")
        l1.setFont(QFont('Arial', 8, weight=QtGui.QFont.Bold))

        b1 = QPushButton()
        b1.setText("Save changes")
        b1.setObjectName("save_changes_button")
        b1.clicked.connect(self.on_click)

        b2 = QPushButton()
        b2.setText("Reset to default")
        b2.setObjectName("reset_button")
        b2.clicked.connect(self.on_click)

        self.bottom_layout.addWidget(l1)
        self.bottom_layout.addStretch()
        self.bottom_layout.addWidget(b2)
        self.bottom_layout.addWidget(b1)

    def menu_bar(self):
        """adds menu bar and actions under it"""
        # menu items
        self.bar = self.menuBar()

        self.file_menu = self.bar.addMenu("File")
        self.help_menu = self.bar.addMenu("Help")

        # File actions
        self.save_action = QAction("Save", self)
        self.save_action.setShortcut("Ctrl+S")
        self.save_action.setObjectName("save")
        self.save_action.triggered.connect(self.on_click)

        self.exit_action = QAction("Exit", self)
        self.exit_action.setShortcut("Ctrl+Q")
        self.exit_action.setObjectName("exit")
        self.exit_action.triggered.connect(self.on_click)

        self.file_menu.addAction(self.save_action)
        self.file_menu.addAction(self.exit_action)

        # Help actions
        self.about_action = QAction("About", self)
        self.about_action.setObjectName("about")
        self.about_action.triggered.connect(self.on_click)

        self.help_menu.addAction(self.about_action)

    # popups
    def show_alert_popup(self, alert_str):
        """shows alert popup with given message"""
        self.hide_frame_emitter.emit(
            True)  # hide the ss frame when showing popup
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Critical)
        msg.setWindowIcon(QtGui.QIcon(self.icon_path))
        msg.setWindowTitle("Alert")
        msg.setText(alert_str)
        msg.exec()
        self.hide_frame_emitter.emit(False)

    def show_success_popup(self, success_str):
        """shows success popup with given message"""
        self.hide_frame_emitter.emit(
            True)  # hide the ss frame when showing popup
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setWindowIcon(QtGui.QIcon(self.icon_path))
        msg.setWindowTitle("Success")
        msg.setText(success_str)
        msg.exec()
        self.hide_frame_emitter.emit(False)

    def show_about_popup(self):
        """shows about popup"""
        self.hide_frame_emitter.emit(
            True)  # hide the ss frame when showing popup
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setWindowIcon(QtGui.QIcon(self.icon_path))
        msg.setWindowTitle("About")
        msg.setTextFormat(Qt.RichText)
        msg.setText(self.about_text)
        msg.exec()
        self.hide_frame_emitter.emit(False)

    # preview functions
    def activate_preview(self):
        """activates preview mode"""
        self.background_color_emitter.emit(self.background_color_line.text())
        self.accent_color_emitter.emit(self.accent_color_line.text())
        self.oppcity_emitter.emit(self.opacity_slider.value() / 100)

        # self.setWindowOpacity(self.opacity_slider.value()/100)

    def revert_preview(self):
        """reverts to default values"""
        self.background_color_emitter.emit(None)
        self.accent_color_emitter.emit(None)
        self.oppcity_emitter.emit(-1)

        # self.setWindowOpacity(1)

    # event listeners
    def closeEvent(self, event):
        """actions before close"""
        self.revert_preview()

    def update_opacity(self, value):
        """updates opacity value on frame and emits signal to main frame to update opacity"""
        self.opacity_label.setText(str(value / 100))
        self.oppcity_emitter.emit(value / 100)

    def on_click(self):
        """on click function for listeners"""
        sender = self.sender()

        # buttons
        if (sender.objectName() == "background_color_button"):
            """writes background color code to lineedit, shows color on color label, emits color change signal to main frame"""
            self.hide_frame_emitter.emit(
                True)  # hide the ss frame when opening color picker
            color = QColorDialog.getColor()
            self.hide_frame_emitter.emit(False)
            if (color.isValid()):
                self.background_color_line.setText(color.name())
                self.background_color_prew.setStyleSheet(
                    "background-color: {0};".format(color.name()))
                self.background_color_emitter.emit(color.name())

        elif (sender.objectName() == "accent_color_button"):
            """writes accent color code to lineedit, shows color on color label, emits color change signal to main frame"""
            self.hide_frame_emitter.emit(
                True)  # hide the ss frame when opening color picker
            color = QColorDialog.getColor()
            self.hide_frame_emitter.emit(False)
            if (color.isValid()):
                self.accent_color_line.setText(color.name())
                self.accent_color_prew.setStyleSheet(
                    "background-color: {0};".format(color.name()))
                self.accent_color_emitter.emit(color.name())

        elif (sender.objectName() == "save_path_button"):
            """opens a folder dialog for save path location"""
            save_path = str(
                QFileDialog.getExistingDirectory(self, "Select Directory"))
            if (save_path):
                self.save_path_line.setText(save_path)

        elif (sender.objectName() == "reset_button"):
            """writes default values to cfg file, reads cfg file and updates ui, emits signal to main frame for updating, shows success popup (write_cfg_file has error popup so I don't need here)"""
            write_status = self.write_cfg_file(self.default_cfg)
            if (write_status):
                self.read_cfg_file()
                self.variable_to_ui()
                self.update_frame_emitter.emit()
                self.show_success_popup("Settings reset to default")

        elif (sender.objectName() == "save_changes_button"
              or sender.objectName() == "save"):
            """takes settings from ui writes them to cfg file, emits signal to main frame for updating, shows success popup (write_cfg_file has error popup so I don't need here)"""
            variable_status = self.ui_to_variable()
            if (variable_status):
                write_status = self.write_cfg_file(self.new_cfg)
                if (write_status):
                    self.update_frame_emitter.emit()
                    self.show_success_popup("Settings saved")

        # menu items
        elif (sender.objectName() == "exit"):
            self.close()
        elif (sender.objectName() == "about"):
            self.show_about_popup()

        # checkboxes
        elif (sender.objectName() == "all_screens_checkbox"):
            # if all_screens_checkbox is checked disable the default_screen_selector
            if (self.all_screens_checkbox.isChecked()):
                self.default_screen_selector.setDisabled(True)
            else:
                self.default_screen_selector.setDisabled(False)
Esempio n. 44
0
 def multisig_dialog(self, run_next):
     cw = CosignWidget(2, 2)
     m_edit = QSlider(Qt.Horizontal, self)
     n_edit = QSlider(Qt.Horizontal, self)
     n_edit.setMinimum(2)
     n_edit.setMaximum(15)
     m_edit.setMinimum(1)
     m_edit.setMaximum(2)
     n_edit.setValue(2)
     m_edit.setValue(2)
     n_label = QLabel()
     m_label = QLabel()
     grid = QGridLayout()
     grid.addWidget(n_label, 0, 0)
     grid.addWidget(n_edit, 0, 1)
     grid.addWidget(m_label, 1, 0)
     grid.addWidget(m_edit, 1, 1)
     def on_m(m):
         m_label.setText(_('Require {0} signatures').format(m))
         cw.set_m(m)
         backup_warning_label.setVisible(cw.m != cw.n)
     def on_n(n):
         n_label.setText(_('From {0} cosigners').format(n))
         cw.set_n(n)
         m_edit.setMaximum(n)
         backup_warning_label.setVisible(cw.m != cw.n)
     n_edit.valueChanged.connect(on_n)
     m_edit.valueChanged.connect(on_m)
     vbox = QVBoxLayout()
     vbox.addWidget(cw)
     vbox.addWidget(WWLabel(_("Choose the number of signatures needed to unlock funds in your wallet:")))
     vbox.addLayout(grid)
     vbox.addSpacing(2 * char_width_in_lineedit())
     backup_warning_label = WWLabel(_("Warning: to be able to restore a multisig wallet, "
                                      "you should include the master public key for each cosigner "
                                      "in all of your backups."))
     vbox.addWidget(backup_warning_label)
     on_n(2)
     on_m(2)
     self.exec_layout(vbox, _("Multi-Signature Wallet"))
     m = int(m_edit.value())
     n = int(n_edit.value())
     return (m, n)
Esempio n. 45
0
class StartWindow(QMainWindow):
    def __init__(self):
        self.inital_completed = False
        self.threadpool = QThreadPool()
        self.lock = Lock()
        self.video_stream = None
        root = Tk()
        root.withdraw()
        self.root_dir = askdirectory(
            initialdir="/",
            title="Select root directory containing all cage folders")
        if self.root_dir is ():
            raise AssertionError
        else:
            self.database_local_dir = 'database/homecage_database.sqlite'
            self.F = None
            super().__init__()

            self.widget_main = QWidget()
            self.play_speed = 0
            self.image_label = QLabel()
            self.image_label.resize(1280, 720)

            self.radio_group = [
                QRadioButton('Unlabeled'),
                QRadioButton('Labeled')
            ]

            self.components_left = [
                QLabel("Cage"),
                QComboBox(),
                QLabel("Animal"),
                QComboBox(),
                QLabel("Date"),
                QLabel("From"),
                QCalendarWidget(),
                QLabel("Till"),
                QCalendarWidget(),
                QLabel("Video List || Double click :)"),
                QListWidget()
            ]
            self.components_right_low = [
                QPushButton('Play(space)'),
                QPushButton('Speed(q): %d' % self.play_speed),
                QPushButton('Next Frame (d)'),
                QPushButton('Previous Frame (a)'),
                QPushButton('Start Labeling (s)'),
                QPushButton('Clean all labels')
            ]
            for i in range(len(self.components_right_low)):
                self.components_right_low[i].setDisabled(True)
            self.Playing_Flag = False
            self.layout_main = QGridLayout()
            self.layout_left = QVBoxLayout()
            self.layout_radio = QHBoxLayout()
            self.layout_right_high = QVBoxLayout()
            self.layout_right_low = QHBoxLayout()
            self.widget_main.setLayout(self.layout_main)
            for component in self.components_left:
                self.layout_left.addWidget(component)
            for component in self.components_right_low:
                self.layout_right_low.addWidget(component)
            for radio in self.radio_group:
                self.layout_radio.addWidget(radio)

            self.slider = QSlider(Qt.Horizontal)
            self.slider.setTickPosition(QSlider.TicksBothSides)
            self.slider.setTickInterval(10)
            self.slider.setSingleStep(1)
            self.slider.setValue(0)
            self.radio_group[0].setChecked(True)

            self.layout_right_high.addWidget(self.image_label)
            self.layout_right_high.addWidget(self.slider)
            self.components_left[6].setMaximumDate(datetime.datetime.now())
            self.components_left[8].setMaximumDate(datetime.datetime.now())
            self.min_date = datetime.datetime.now()
            self.max_date = datetime.datetime.now()

            self.layout_left.addLayout(self.layout_radio)
            self.layout_main.addLayout(self.layout_left, 0, 0, 4, 1)
            self.layout_main.addLayout(self.layout_right_high, 0, 2, 4, 4)
            self.layout_main.addLayout(self.layout_right_low, 4, 2, 5, 5)
            self.setCentralWidget(self.widget_main)
            self.overlay = Overlay(self.centralWidget())
            self.overlay.show()
            self.show()
            self.thread_get_cages()

            self.components_left[1].currentIndexChanged.connect(
                self.on_select_cage)
            self.components_left[3].currentIndexChanged.connect(
                self.on_select_animal)
            self.components_left[6].selectionChanged.connect(
                self.on_select_date_min)
            self.components_left[8].selectionChanged.connect(
                self.on_select_date_max)
            self.components_left[10].itemDoubleClicked.connect(
                self.on_select_video)
            self.components_left[10].setSelectionMode(
                QListWidget.SingleSelection)

            self.slider.sliderMoved.connect(self.on_slider)
            self.slider.sliderReleased.connect(self.on_slider_release)

            self.components_right_low[0].clicked.connect(self.on_play)
            self.components_right_low[1].clicked.connect(self.on_speed)
            self.components_right_low[2].clicked.connect(self.on_next_frame)
            self.components_right_low[3].clicked.connect(
                self.on_previous_frame)
            self.components_right_low[4].clicked.connect(self.on_labeling)
            self.components_right_low[5].clicked.connect(self.on_clean_all)

            for i in range(len(self.radio_group)):
                self.radio_group[i].clicked.connect(
                    lambda: self.on_radio(self.radio_group[i]))

            self.init_image = cv2.imread(os.path.join("pic", "init.jpg"))
            self.init_image = cv2.cvtColor(self.init_image, cv2.COLOR_BGR2RGB)
            self.init_image = cv2.resize(self.init_image, (1280, 720))
            self.th = imageThread()
            self.th.changePixmap.connect(self.update_image)
            self.th.start()
            self.th.frames_queue.put(self.init_image)
            self.animal = ""
            self.index = 0
            self.inital_completed = True
            self.start_frame = 0
            self.end_frame = 0
            self.event_dict = {
                0: "Knock Down",
                1: "Attemp",
                2: "Success",
                3: "Successful Lick",
                4: "Discard this event"
            }
            self.current_video_list_all = []
            self.current_video_list_unlabeled = []
            self.current_video_list_labeled = []
            self.video_path = None
            self.slider_queue = Queue()
            self.thread_update_slider()
            self.thread_update_database()

    def keyPressEvent(self, event):
        global FLAG_EVENT_START
        global FLAG_PLAYING
        self.components_right_low[0].setFocus()
        key_id = (event.key() & 0xFF) + 32
        if self.video_stream is not None:
            if FLAG_EVENT_START and key_id in range(80, 90):
                event_id = key_id - 80
                self.on_saving(event_id)
            if key_id == ord(" "):
                self.on_play()
            elif key_id == ord("q"):
                self.on_speed()
            elif key_id == ord("d"):
                if not FLAG_PLAYING:
                    self.on_next_frame()
            elif key_id == ord('a'):
                if not FLAG_PLAYING:
                    self.on_previous_frame()
            elif key_id == ord('s'):
                self.on_labeling()
                self.components_right_low[4].setDisabled(True)

    @pyqtSlot(QImage)
    def update_image(self, qImg):
        self.image_label.setPixmap(QPixmap.fromImage(qImg))

    def on_radio(self, r):
        if self.inital_completed:
            self.overlay.show()
        self.thread_update_list_radio()

    def on_play(self):
        self.components_right_low[0].setFocus()
        global FLAG_PLAYING
        FLAG_PLAYING = not FLAG_PLAYING

        if FLAG_PLAYING:
            self.components_right_low[0].setText("Pulse(space)")
            self.thread_play_video()
            self.components_right_low[2].setDisabled(True)
            self.components_right_low[3].setDisabled(True)
        else:
            self.components_right_low[0].setText("Play(space)")
            self.components_right_low[2].setDisabled(False)
            self.components_right_low[3].setDisabled(False)

    def on_speed(self):
        self.components_right_low[0].setFocus()
        self.play_speed = (self.play_speed + 1) % 3
        self.components_right_low[1].setText("Speed(q): %d" % self.play_speed)

    def on_slider(self):
        global FLAG_PLAYING
        FLAG_PLAYING = False
        self.slider_queue.empty()
        if self.video_stream is not None:
            if self.slider.value() % 20 == 0:
                self.video_stream.set(cv2.CAP_PROP_POS_FRAMES,
                                      self.slider.value())
                grab, frame = self.video_stream.read()
                self.th.frames_queue.put(frame)

    def on_slider_release(self):
        self.components_right_low[0].setFocus()
        global FLAG_PLAYING
        FLAG_PLAYING = True
        self.components_right_low[0].setText("Pulse(space)")
        self.thread_play_video()

    def on_select_cage(self):
        if self.inital_completed:
            self.overlay.show()
        self.thread_get_animals()

    def on_select_animal(self):
        if self.inital_completed:
            self.overlay.show()
        self.animal = self.components_left[3].currentText()
        self.thread_get_videos()

    def on_select_date_min(self):
        if self.inital_completed:
            self.overlay.show()
        self.thread_update_list_min()

    def on_select_date_max(self):
        if self.inital_completed:
            self.overlay.show()
        self.thread_update_list_max()

    def on_select_video(self):
        global FLAG_PLAYING
        if self.inital_completed:
            self.overlay.show()
        FLAG_PLAYING = False
        self.slider_queue.empty()
        self.slider_queue.put(1)
        self.video_path = self.components_left[10].selectedItems()[0].text()
        self.thread_load_video()
        self.components_right_low[2].setDisabled(False)
        self.components_right_low[3].setDisabled(False)

    def on_next_frame(self):
        self.components_right_low[0].setFocus()
        current_pos = self.slider.value() + 1
        if current_pos >= self.total_frames - 1:
            current_pos = 0
        self.slider_queue.put(current_pos)
        self.video_stream.set(cv2.CAP_PROP_POS_FRAMES, current_pos)
        grab, frame = self.video_stream.read()
        self.th.frames_queue.put(frame)

    def on_previous_frame(self):
        self.components_right_low[0].setFocus()
        current_pos = self.slider.value() - 1
        if current_pos <= 1:
            current_pos = self.total_frames - 2
        self.slider_queue.put(current_pos)
        self.video_stream.set(cv2.CAP_PROP_POS_FRAMES, current_pos)
        grab, frame = self.video_stream.read()
        self.th.frames_queue.put(frame)

    def on_clean_all(self):
        buttonReply = QMessageBox.question(
            self, 'PyQt5 message',
            "Do you want to delete all the labels in this video?",
            QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
            QMessageBox.Cancel)
        if buttonReply == QMessageBox.Yes:
            sql = sqlHandler(self.database_local_dir)
            sql.delete(self.video_path)
            sql.close()
            self._update_video_list()
        self.components_right_low[0].setFocus()

    def on_labeling(self):
        global FLAG_EVENT_START
        self.start_frame = self.slider.value()
        items = self.components_left[10].selectedItems()
        if len(items) > 0:
            FLAG_EVENT_START = True
        else:
            FLAG_EVENT_START = False
        self.components_right_low[4].setDisabled(True)
        self.components_right_low[0].setFocus()

    def on_saving(self, event_id):
        sql = sqlHandler(self.database_local_dir)
        global FLAG_EVENT_START
        self.end_frame = self.slider.value()
        if event_id in self.event_dict.keys():
            sql.insert(self.video_path, self.start_frame, self.end_frame,
                       self.event_dict[event_id])
        FLAG_EVENT_START = False
        sql.close()
        self.components_right_low[4].setDisabled(False)
###################################################################################################################

    def thread_get_cages(self):
        # Pass the function to execute
        worker = Worker(
            self._get_cages
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self._set_cages)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _get_cages(self, progress_callback):
        if self.F is None:
            self.F = FileStructure(self.root_dir)
        return self.F.get_cages()

    def _set_cages(self, cages):
        self.components_left[1].clear()
        self.components_left[3].clear()
        self.components_left[10].clear()
        for cage in cages:
            self.components_left[1].addItem(cage)
################################################################################################################

    def thread_get_animals(self):
        # Pass the function to execute
        worker = Worker(
            self._get_animals
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self._set_animals)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _get_animals(self, progress_callback):
        return self.F.get_animals(self.components_left[1].currentText())

    def _set_animals(self, animals):
        self.components_left[3].clear()
        self.components_left[10].clear()
        for animal in animals:
            self.components_left[3].addItem(animal)
#################################################################################################################

    def thread_get_videos(self):
        # Pass the function to execute
        worker = Worker(
            self._get_videos
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self._set_videos)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _get_videos(self, progress_callback):
        while self.animal == '':
            self.animal = self.components_left[3].currentText()
            time.sleep(0.5)
        self.F.get_video_list(self.animal)

    def _set_videos(self, animals):
        self._update_video_list()
#################################################################################################################

    def thread_load_video(self):
        # Pass the function to execute
        worker = Worker(
            self._load_video
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self._set_frame)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _load_video(self, progress_callback):
        shutil.rmtree('temp', ignore_errors=True)
        os.mkdir('temp')
        shutil.copyfile(
            self.video_path,
            os.path.join('temp', os.path.basename(self.video_path)))
        if self.video_stream is not None:
            self.video_stream.release()
        self.video_stream = cv2.VideoCapture(
            os.path.join('temp', os.path.basename(self.video_path)))
        self.total_frames = self.video_stream.get(cv2.CAP_PROP_FRAME_COUNT)
        self.slider.setRange(0, self.total_frames)
        return None

    def _set_frame(self, _):
        if not self.video_stream.isOpened():
            root = Tk()
            root.withdraw()
            messagebox.showerror("Error", "Broken video!")
            self.video_stream = None
        else:
            grab, frame = self.video_stream.read()
            self.th.frames_queue.put(frame)
            for i in range(len(self.components_right_low)):
                self.components_right_low[i].setDisabled(False)
            self.components_right_low[0].setFocus()
#################################################################################################################

    def thread_play_video(self):
        # Pass the function to execute
        worker = Worker(
            self._play_video
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self._close_video)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def showdialog(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setText("Are you sure there is no event in this video?")
        msg.setWindowTitle("No events confirmation")
        msg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
        retval = msg.exec_()
        msg.close()
        msg.destroy()
        return retval

    def _play_video(self, progress_callback):
        total_frames = self.video_stream.get(cv2.CAP_PROP_FRAME_COUNT)
        global FLAG_PLAYING

        while FLAG_PLAYING:
            current_pos = self.slider.value() + 1
            self.slider_queue.put(current_pos)
            time.sleep([0.05, 0.02, 0][self.play_speed])

            if current_pos < total_frames - 1:
                grab, frame = self.video_stream.read()
                if grab and frame is not None:
                    self.th.frames_queue.put(frame)

            else:
                FLAG_PLAYING = False
                self.components_right_low[2].setDisabled(False)
                self.components_right_low[3].setDisabled(False)
                break

    def _close_video(self, _):
        total_frames = self.video_stream.get(cv2.CAP_PROP_FRAME_COUNT)
        self.components_right_low[0].setText("Play(space)")
        if self.slider.value() > total_frames - 2:
            sql = sqlHandler(self.database_local_dir)
            flag = sql.is_labeled(self.video_path)
            sql.close()
            buttonReply = True
            if not flag:
                buttonReply = self.showdialog()
                if buttonReply == QMessageBox.Yes:
                    sql = sqlHandler(self.database_local_dir)
                    sql.insert(self.video_path, 0, 0, 'empty')
                    sql.close()
                    buttonReply = True
                else:
                    buttonReply = False

            if (self.video_path
                    not in self.current_video_list_labeled) and buttonReply:
                self.current_video_list_labeled.append(self.video_path)
            self.current_video_list_unlabeled = [
                item for item in self.current_video_list_all
                if item not in self.current_video_list_labeled
            ]
            self.components_left[10].clear()
            if self.radio_group[0].isChecked():
                if len(self.current_video_list_unlabeled) > 0:
                    self.components_left[10].addItems(
                        self.current_video_list_unlabeled)
            elif self.radio_group[1].isChecked():
                if len(self.current_video_list_labeled) > 0:
                    self.components_left[10].addItems(
                        self.current_video_list_labeled)

#################################################################################################################

    def thread_update_list_min(self):
        # Pass the function to execute
        worker = Worker(
            self._update_list_min
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self.print_output)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _update_list_min(self, progress_callback):
        self.components_left[10].clear()
        Q_min_date = self.components_left[6].selectedDate()
        self.min_date = datetime.datetime.strptime(
            "%d-%d-%d" %
            (Q_min_date.year(), Q_min_date.month(), Q_min_date.day()),
            "%Y-%m-%d")
        self.components_left[8].setMinimumDate(self.min_date)
        self._update_video_list()
#################################################################################################################

    def thread_update_list_max(self):
        # Pass the function to execute
        worker = Worker(
            self._update_list_max
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self.print_output)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _update_list_max(self, progress_callback):
        self.components_left[10].clear()
        Q_max_date = self.components_left[8].selectedDate()
        self.max_date = datetime.datetime.strptime(
            "%d-%d-%d" %
            (Q_max_date.year(), Q_max_date.month(), Q_max_date.day()),
            "%Y-%m-%d")
        self._update_video_list()
#################################################################################################################

    def thread_update_list_radio(self):
        # Pass the function to execute
        worker = Worker(
            self._update_list_radio
        )  # Any other args, kwargs are passed to the run function
        worker.signals.result.connect(self.print_output)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)
        # Execute
        self.threadpool.start(worker)

    def _update_list_radio(self, progress_callback):
        self._update_video_list()
#################################################################################################################

    def thread_update_slider(self):
        th = threading.Thread(target=self.process_slider)
        th.start()

    def process_slider(self):
        while True:
            if self.slider_queue.qsize() > 0:
                self.slider.setValue(self.slider_queue.get())
#################################################################################################################

    def thread_update_database(self):
        th = threading.Thread(target=self.update_database)
        th.start()

    def update_database(self):
        global FLAG_DATABASE_SAFE
        database_cloud_dir = os.path.join(self.root_dir, 'database')
        if not os.path.exists(database_cloud_dir):
            os.mkdir(database_cloud_dir)
        while True:
            time.sleep(60)
            if FLAG_DATABASE_SAFE:
                try:
                    shutil.copy(
                        self.database_local_dir,
                        os.path.join(database_cloud_dir,
                                     os.path.basename(
                                         self.database_local_dir)))
                    sys.stdout.write(
                        "\r [%s] Database synchronized into %s ..." %
                        (str(datetime.datetime.now()), database_cloud_dir))
                    sys.stdout.flush()
                except:
                    pass
            else:
                print("Database Not Safe! Will try next time...")


#################################################################################################################

    def _update_video_list(self):
        animal = self.components_left[3].currentText()
        filtered_items = self.F.get_filtered_video_list(
            animal, self.min_date, self.max_date)
        sql = sqlHandler(self.database_local_dir)
        self.current_video_list_all = filtered_items
        self.current_video_list_labeled = [
            item for item in self.current_video_list_all
            if sql.is_labeled(item)
        ]
        self.current_video_list_unlabeled = [
            item for item in self.current_video_list_all
            if item not in self.current_video_list_labeled
        ]
        sql.close()
        self.components_left[10].clear()
        if self.radio_group[0].isChecked():
            if len(self.current_video_list_unlabeled) > 0:
                self.components_left[10].addItems(
                    self.current_video_list_unlabeled)
        elif self.radio_group[1].isChecked():
            if len(self.current_video_list_labeled) > 0:
                self.components_left[10].addItems(
                    self.current_video_list_labeled)

    def progress_fn(self, n):
        pass

    def print_output(self, s):
        pass

    def thread_complete(self):
        global FLAG_COMPLETE
        FLAG_COMPLETE = True

    def resizeEvent(self, event):
        self.overlay.resize(event.size())
        event.accept()
Esempio n. 46
0
class dicomViewWidget(QWidget):
    """ GENERIC DICOM VIEWER WIDGET
        This class defines the layout only
        A controller is required to do anything
     """
    def __init__(self, parent=None, directory=None, **kwargs):
        super().__init__(parent=parent)

        self.parent = parent
        self.showingImage = False
        self.new_slice_to_show = True
        self.legend = None
        self.startingDirectory = "C:\\"  # Where to begin dicom im search

        self.createControls()
        self.createAxes()
        self.initializeModel()

        centralLayout = QHBoxLayout()
        centralLayout.addWidget(self.PlotWidge)
        centralLayout.addLayout(self.viewToolsLayout)
        self.setLayout(centralLayout)

    # def autoscale(self):
    #     for ax in self.myPlot:
    #         ax.

    def createAxes(self):
        PlotWidge = self.PlotWidge = self.getPlotWidgeObject()
        PlotWidge.setBackground(None)

        self.myPlot = self.createViews(PlotWidge)

        for ax in self.myPlot:
            plot = self.myPlot[ax]
            myView = plot.getViewBox()
            myView.setAspectLocked(True)
            # myView.invertY(True)
            myView.setBackgroundColor('#CCCCCC')
            # myView.setBackgroundColor('#000000')

            # plot.showAxis('left', False)
            # plot.showAxis('bottom', False)
            plot.setRange(xRange=(-200, 200))
            plot.hideButtons()
            # legend = self.legend = LegendItem()
            # legend.setParentItem(myPlot)

    def createViews(self, PlotWidge):
        views = {'z': PlotWidge.addPlot()}
        return views

    def getPlotWidgeObject(self):
        # For Default DicomViewWidget: use Default pyqtgraph Plot Widget
        # Can be overrode using this function in subclasses of DicomViewWidget
        return GraphicsLayoutWidget()

    def createControls(self):
        self.viewToolsLayout = depthLayout = QVBoxLayout()
        self.sliceSlider = QSlider()
        self.sliceSlider.setEnabled(True)
        self.sliceSlider.valueChanged.connect(self.sliderChanged)
        self.depthGauge = QLabel("0.0 mm")
        self.depthGauge.setMinimumWidth(50)
        self.sliceIndGauge = QLabel("Slice 0 / 0")
        self.dirFinder = QPushButton("Select Images")
        self.dirFinder.clicked.connect(self.selectImages)

        depthLayout.addWidget(self.dirFinder, 0, QtCore.Qt.AlignCenter)
        depthLayout.addWidget(self.depthGauge, 0, QtCore.Qt.AlignCenter)
        depthLayout.addWidget(self.sliceSlider, 1, QtCore.Qt.AlignHCenter)
        depthLayout.addWidget(self.sliceIndGauge, 0, QtCore.Qt.AlignCenter)

    def initializeModel(self, sliceLoc=0, sliceIndex=0):
        self.thisSliceLoc = sliceLoc
        self.thisSliceIndex = 0
        self.T_MRI_Ref = np.eye(4)
        self.T_patient_pixels = np.eye(4)
        self.T_pixels_patient = np.eye(4)
        self.PlottableContours = {}
        self.sliceIndGauge.setText("Slice 0 / 0")
        self.depthGauge.setText("0.0 mm")
        self.currentUID = 0
        self.UID_zero = 0
        self.PlottableImage = ImageItem()

    def updateScene(self, sliceUID):
        if self.showingImage:
            self.PlottableImage.updatePlottable(UID=sliceUID)
            for contour in self.PlottableContours.values():
                contour.updatePlottable(UID=sliceUID)

    def setupAddDataModel(self):
        self.dirFinder.setText("Select Images")
        self.dirFinder.clicked.disconnect()
        self.dirFinder.clicked.connect(self.selectImages)

    def selectImages(self):
        """ Open Dialog to find directory with Dicom Files """
        dicomDir = QFileDialog.getExistingDirectory(
            parent=self,
            caption="Select Dicom Directory",
            directory=self.startingDirectory)
        if dicomDir is '':
            return
        # try:
        self.ImVolume = DicomDataModel(diDir=dicomDir)

        self.addImages(imageModel=self.ImVolume)

    def addImages(self, imageModel):
        # Get DicomData Pixel Transformations
        # self.T_patient_pixels = imageModel.PP2IMTransformation
        # self.T_pixels_patient = imageModel.IM2PPTransformation
        TPat2Pix = imageModel.TPat2Pix
        self.UID_zero = imageModel.Ind2UID[0]
        self.currentUID = self.UID_zero

        # Add Image Object (for DICOM pixel array)
        self.PlottableImage = DicomImagePlotItem(dicomModel=imageModel)
        self.myPlot['z'].addItem(self.PlottableImage)
        # self.PlottableImage.rotate(45)

        # Add Contour Object (if there are any!)
        if bool(imageModel.contourObjs):
            self.createContourPlottables(contourDict=imageModel.contourObjs,
                                         Pat2PixTForm=TPat2Pix,
                                         UID2IndDict=imageModel.UID2Ind)

        # Tidy Up
        self.showingImage = True
        for plot in self.myPlot.values():
            plot.autoRange()
        self.configureSliceSlider()
        self.setupClearDataModel()

    def createContourPlottables(self, contourDict, *args, **kwargs):
        """ create/store list of 'active contour objects' for plotting
        also make, but don't store list of projections of contours """

        self.PlottableContours = {}
        for ROI in contourDict['ROI']:
            contourP = self.getContourPlottable(ROIDict=ROI, *args, **kwargs)
            self.PlottableContours[ROI['ROIName']] = contourP
            self.myPlot['z'].addItem(contourP)

        if bool(self.legend):
            self.populateLegend(legend=self.legend,
                                contourDict=self.PlottableContours)

    def getContourPlottable(self, *args, **kwargs):
        return DicomContourPlotItem(*args, **kwargs)

    def setupClearDataModel(self):
        """ Change bttn function to be CLEAR DATA """
        self.dirFinder.setText("Clear Data")
        self.dirFinder.clicked.disconnect()
        self.dirFinder.clicked.connect(self.clearImagesWarning)

    def clearImagesWarning(self, **kwargs):
        """ Confirm with User that they want to Clear Plot"""
        qbb = QDialog(**kwargs)
        qbb.setWindowTitle("Clear Data?")
        qbb.setWindowModality(QtCore.Qt.ApplicationModal)
        ok = QPushButton("Clear")
        no = QPushButton("Cancel")
        ok.clicked.connect(self.clearImages)
        ok.clicked.connect(qbb.close)
        no.clicked.connect(qbb.close)
        layout = QVBoxLayout(qbb)
        layout.addWidget(QLabel("Are you sure you want to clear data?"))
        layout.addSpacing(20)
        bttnLayout = QHBoxLayout()
        bttnLayout.addWidget(ok)
        bttnLayout.addWidget(no)
        layout.addLayout(bttnLayout)
        qbb.exec_()

    def clearImages(self):
        """ Reset and Clear Axes """
        self.myPlot['z'].clear()
        # for item in [self.PlottableImage]:
        # del item
        self.showingImage = False
        if bool(self.legend):
            self.clearLegend(self.legend)
        self.initializeModel()
        self.setupAddDataModel()

    def configureSliceSlider(self):
        dicomMin = min(self.ImVolume.Loc2Ind.keys())
        dicomMax = max(self.ImVolume.Loc2Ind.keys())
        # dicomRange = dicomMax - dicomMin
        self.sliceSlider.setEnabled(True)
        self.sliceSlider.setRange(dicomMin, dicomMax)
        self.sliceSlider.setValue(dicomMin)
        self.sliderChanged()

    def sliderChanged(self):
        if not self.showingImage:
            return
        """ on change of SliceSlider value: """
        newSliderVal = self.sliceSlider.value()
        newSliceLoc = min(self.ImVolume.Loc2Ind.keys(),
                          key=lambda x: abs(x - newSliderVal))
        newSliceIndex = self.ImVolume.Loc2Ind[newSliceLoc]
        newSliceLoc = round(newSliceLoc * 1000) / 1000
        maxInd = max(self.ImVolume.Ind2Loc.keys())
        self.depthGauge.setText("{:>1.2f} mm".format(newSliceLoc))
        self.sliceIndGauge.setText("Slice {}/{}".format(newSliceIndex, maxInd))

        newUID = self.ImVolume.Ind2UID[newSliceIndex]
        if not newUID == self.currentUID:
            self.currentUID = newUID
            self.updateScene(sliceUID=newUID)

    def updateGauges(self, newSliderVal=0):
        newSliderVal = self.dispView.sliceSlider.value()
        newSliceLocation = min(self.ImVolume.sliceLoc2Ind.keys(),
                               key=lambda x: abs(x - newSliderVal))
        newSliceIndex = self.ImVolume.sliceLoc2Ind[newSliceLocation]
        self.thisSliceIndex = newSliceIndex
        self.thisSliceLoc = newSliceLocation

    def populateLegend(self, legend, contourDict={}):
        for thisContour in contourDict:
            legend.addItem(item=contourDict[thisContour],
                           name=('   ' + thisContour))

    def clearLegend(self, legend):
        legend.items = []
        while legend.layout.count() > 0:
            legend.layout.removeAt(0)
        self.myPlot.removeItem(legend)

    def closeEvent(self, event):
        print("Closing the app")
        self.deleteLater()
 def createSlider(self, sliderName='Slider',
                        tickInterval=10,
                        tickStep=1,
                        min=0, max=50):
     """
         Function to create slider on main window
         
         INPUTS
             :sliderName: String of what label to put on slider
             :tickInterval: Interval of how much hotkey should increment by
             :tickStep: What is the minimum amount of change that can occur on slider
             :min: Min value of slider
             :max: Max value of slider
             
         OUTPUTS
             :groupBox: PyQt5 object for bbox of slider and contents
             :slider: Resulting set slider object
     """
     groupBox = QGroupBox(sliderName) # Create container for GUI objects
     
     slider = QSlider(Qt.Horizontal) # Create slider
     slider.setFocusPolicy(Qt.StrongFocus) # Set style
     slider.setTickPosition(QSlider.TicksBothSides) # Set functionality
     slider.setTickInterval(tickInterval) # Set tick interval
     slider.setSingleStep(tickStep) # Set min step
     slider.setMinimum(min) # Set min value
     slider.setMaximum(max) # Set max balue
     
     vbox=QVBoxLayout() # Put slider in bbox then add to container
     vbox.addWidget(slider)
     vbox.addStretch(1)
     groupBox.setLayout(vbox)
     
     return groupBox, slider
 def multisig_dialog(self, run_next):
     cw = CosignWidget(2, 2)
     m_edit = QSlider(Qt.Horizontal, self)
     n_edit = QSlider(Qt.Horizontal, self)
     n_edit.setMinimum(2)
     n_edit.setMaximum(15)
     m_edit.setMinimum(1)
     m_edit.setMaximum(2)
     n_edit.setValue(2)
     m_edit.setValue(2)
     n_label = QLabel()
     m_label = QLabel()
     grid = QGridLayout()
     grid.addWidget(n_label, 0, 0)
     grid.addWidget(n_edit, 0, 1)
     grid.addWidget(m_label, 1, 0)
     grid.addWidget(m_edit, 1, 1)
     def on_m(m):
         m_label.setText(_('Require {0} signatures').format(m))
         cw.set_m(m)
     def on_n(n):
         n_label.setText(_('From {0} cosigners').format(n))
         cw.set_n(n)
         m_edit.setMaximum(n)
     n_edit.valueChanged.connect(on_n)
     m_edit.valueChanged.connect(on_m)
     on_n(2)
     on_m(2)
     vbox = QVBoxLayout()
     vbox.addWidget(cw)
     vbox.addWidget(WWLabel(_("Choose the number of signatures needed to unlock funds in your wallet:")))
     vbox.addLayout(grid)
     self.exec_layout(vbox, _("Multi-Signature Wallet"))
     m = int(m_edit.value())
     n = int(n_edit.value())
     return (m, n)
    selectionGroupBox = QGroupBox("Selection Mode")

    modeNoneRB = QRadioButton("No selection")
    modeItemRB = QRadioButton("Item")
    modeSliceRowRB = QRadioButton("Row Slice")
    modeSliceColumnRB = QRadioButton("Column Slice")

    selectionVBox = QVBoxLayout()
    selectionVBox.addWidget(modeNoneRB)
    selectionVBox.addWidget(modeItemRB)
    selectionVBox.addWidget(modeSliceRowRB)
    selectionVBox.addWidget(modeSliceColumnRB)
    selectionGroupBox.setLayout(selectionVBox)

    axisMinSliderX = QSlider(Qt.Horizontal, minimum=0, tickInterval=1)
    axisMaxSliderX = QSlider(Qt.Horizontal, minimum=1, tickInterval=1)
    axisMinSliderZ = QSlider(Qt.Horizontal, minimum=0, tickInterval=1)
    axisMaxSliderZ = QSlider(Qt.Horizontal, minimum=1, tickInterval=1)

    rhoSlider = QSlider(Qt.Horizontal, minimum=0, maximum=200, tickInterval=1)
    rhoSlider.setValue(int(-0.4082482904638631 * 100) + 100)

    themeList = QComboBox()
    themeList.addItem("Qt")
    themeList.addItem("Primary Colors")
    themeList.addItem("Digia")
    themeList.addItem("Stone Moss")
    themeList.addItem("Army Blue")
    themeList.addItem("Retro")
    themeList.addItem("Ebony")
class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        # 파이썬 실행창을 항상 위로 유지해주는 코드
        self.setWindowFlags(Qt.WindowStaysOnTopHint)
        self.initUI()

    def initUI(self):
        #서버에서 json 값을 받아와 data 변수에 저장
        url = "http://ec2-54-180-94-182.ap-northeast-2.compute.amazonaws.com:3000/desk/qr"
        data = requests.get(url).json()

        # data 딕셔너리 중 randomNum 키의 value 값으로 qr코드 생성, 추후 다른 키 값과 조합하여 수정 예정
        self.setStyleSheet("background-color: #FFFFFF")
        qr = qrcode.QRCode(
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=10,
            border=0,
        )
        qr.add_data(str(data['id']) + data['randomNum'])
        qr.make(fit=True)
        img = qr.make_image(fill_color="black", back_color="white")
        qt_image = ImageQt.ImageQt(img)
        self.pixmap = QPixmap.fromImage(qt_image)

        self.lbl_img = QLabel()
        self.lbl_img.setPixmap(self.pixmap)

        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.lbl_img)
        self.setLayout(self.vbox)

        self.slider = QSlider(Qt.Horizontal, self)
        self.slider.setRange(10, 90)
        self.vbox.addWidget(self.slider)

        self.btn = QPushButton('초기화', self)
        self.vbox.addWidget(self.btn)

        self.slider.valueChanged.connect(self.setOpacity)
        self.btn.clicked.connect(self.button_clicked)

        self.setWindowTitle('투명도 조절')
        self.move(300, 300)
        self.show()

        t = threading.Thread(target=self.refreshImg)
        t.start()

    def refreshImg(self):
        url = "http://ec2-54-180-94-182.ap-northeast-2.compute.amazonaws.com:3000/desk/qr"
        while True:
            data = requests.get(url).json()
            img = qrcode.make(str(data['id']) + data['randomNum'])
            qt_image = ImageQt.ImageQt(img)
            self.pixmap = QPixmap.fromImage(qt_image)
            self.lbl_img.setPixmap(self.pixmap)
            time.sleep(1)

    def button_clicked(self):
        self.slider.setValue(1)

    def setOpacity(self, value):
        value = 1.1 - (value / 100)
        self.setWindowOpacity(value)
Esempio n. 51
0
    def __init__(self, window, plugin, keystore, device_id):
        title = _("{} Settings").format(plugin.device)
        super(SettingsDialog, self).__init__(window, title)
        self.setMaximumWidth(540)

        devmgr = plugin.device_manager()
        config = devmgr.config
        handler = keystore.handler
        thread = keystore.thread
        hs_cols, hs_rows = (128, 64)

        def invoke_client(method, *args, **kw_args):
            unpair_after = kw_args.pop('unpair_after', False)

            def task():
                client = devmgr.client_by_id(device_id)
                if not client:
                    raise RuntimeError("Device not connected")
                if method:
                    getattr(client, method)(*args, **kw_args)
                if unpair_after:
                    devmgr.unpair_id(device_id)
                return client.features

            thread.add(task, on_success=update)

        def update(features):
            self.features = features
            set_label_enabled()
            if features.bootloader_hash:
                bl_hash = bh2u(features.bootloader_hash)
                bl_hash = "\n".join([bl_hash[:32], bl_hash[32:]])
            else:
                bl_hash = "N/A"
            noyes = [_("No"), _("Yes")]
            endis = [_("Enable Passphrases"), _("Disable Passphrases")]
            disen = [_("Disabled"), _("Enabled")]
            setchange = [_("Set a PIN"), _("Change PIN")]

            version = "%d.%d.%d" % (features.major_version,
                                    features.minor_version,
                                    features.patch_version)

            device_label.setText(features.label)
            pin_set_label.setText(noyes[features.pin_protection])
            passphrases_label.setText(disen[features.passphrase_protection])
            bl_hash_label.setText(bl_hash)
            label_edit.setText(features.label)
            device_id_label.setText(features.device_id)
            initialized_label.setText(noyes[features.initialized])
            version_label.setText(version)
            clear_pin_button.setVisible(features.pin_protection)
            clear_pin_warning.setVisible(features.pin_protection)
            pin_button.setText(setchange[features.pin_protection])
            pin_msg.setVisible(not features.pin_protection)
            passphrase_button.setText(endis[features.passphrase_protection])
            language_label.setText(features.language)

        def set_label_enabled():
            label_apply.setEnabled(label_edit.text() != self.features.label)

        def rename():
            invoke_client('change_label', label_edit.text())

        def toggle_passphrase():
            title = _("Confirm Toggle Passphrase Protection")
            currently_enabled = self.features.passphrase_protection
            if currently_enabled:
                msg = _("After disabling passphrases, you can only pair this "
                        "ElectrumSys wallet if it had an empty passphrase.  "
                        "If its passphrase was not empty, you will need to "
                        "create a new wallet with the install wizard.  You "
                        "can use this wallet again at any time by re-enabling "
                        "passphrases and entering its passphrase.")
            else:
                msg = _(
                    "Your current ElectrumSys wallet can only be used with "
                    "an empty passphrase.  You must create a separate "
                    "wallet with the install wizard for other passphrases "
                    "as each one generates a new set of addresses.")
            msg += "\n\n" + _("Are you sure you want to proceed?")
            if not self.question(msg, title=title):
                return
            invoke_client('toggle_passphrase', unpair_after=currently_enabled)

        def change_homescreen():
            filename = getOpenFileName(
                parent=self,
                title=_("Choose Homescreen"),
                config=config,
            )
            if not filename:
                return  # user cancelled

            if filename.endswith('.toif'):
                img = open(filename, 'rb').read()
                if img[:8] != b'TOIf\x90\x00\x90\x00':
                    handler.show_error(
                        'File is not a TOIF file with size of 144x144')
                    return
            else:
                from PIL import Image  # FIXME
                im = Image.open(filename)
                if im.size != (128, 64):
                    handler.show_error('Image must be 128 x 64 pixels')
                    return
                im = im.convert('1')
                pix = im.load()
                img = bytearray(1024)
                for j in range(64):
                    for i in range(128):
                        if pix[i, j]:
                            o = (i + j * 128)
                            img[o // 8] |= (1 << (7 - o % 8))
                img = bytes(img)
            invoke_client('change_homescreen', img)

        def clear_homescreen():
            invoke_client('change_homescreen', b'\x00')

        def set_pin():
            invoke_client('set_pin', remove=False)

        def clear_pin():
            invoke_client('set_pin', remove=True)

        def wipe_device():
            wallet = window.wallet
            if wallet and sum(wallet.get_balance()):
                title = _("Confirm Device Wipe")
                msg = _("Are you SURE you want to wipe the device?\n"
                        "Your wallet still has syscoins in it!")
                if not self.question(
                        msg, title=title, icon=QMessageBox.Critical):
                    return
            invoke_client('wipe_device', unpair_after=True)

        def slider_moved():
            mins = timeout_slider.sliderPosition()
            timeout_minutes.setText(_("{:2d} minutes").format(mins))

        def slider_released():
            config.set_session_timeout(timeout_slider.sliderPosition() * 60)

        # Information tab
        info_tab = QWidget()
        info_layout = QVBoxLayout(info_tab)
        info_glayout = QGridLayout()
        info_glayout.setColumnStretch(2, 1)
        device_label = QLabel()
        pin_set_label = QLabel()
        passphrases_label = QLabel()
        version_label = QLabel()
        device_id_label = QLabel()
        bl_hash_label = QLabel()
        bl_hash_label.setWordWrap(True)
        language_label = QLabel()
        initialized_label = QLabel()
        rows = [
            (_("Device Label"), device_label),
            (_("PIN set"), pin_set_label),
            (_("Passphrases"), passphrases_label),
            (_("Firmware Version"), version_label),
            (_("Device ID"), device_id_label),
            (_("Bootloader Hash"), bl_hash_label),
            (_("Language"), language_label),
            (_("Initialized"), initialized_label),
        ]
        for row_num, (label, widget) in enumerate(rows):
            info_glayout.addWidget(QLabel(label), row_num, 0)
            info_glayout.addWidget(widget, row_num, 1)
        info_layout.addLayout(info_glayout)

        # Settings tab
        settings_tab = QWidget()
        settings_layout = QVBoxLayout(settings_tab)
        settings_glayout = QGridLayout()

        # Settings tab - Label
        label_msg = QLabel(
            _("Name this {}.  If you have multiple devices "
              "their labels help distinguish them.").format(plugin.device))
        label_msg.setWordWrap(True)
        label_label = QLabel(_("Device Label"))
        label_edit = QLineEdit()
        label_edit.setMinimumWidth(150)
        label_edit.setMaxLength(plugin.MAX_LABEL_LEN)
        label_apply = QPushButton(_("Apply"))
        label_apply.clicked.connect(rename)
        label_edit.textChanged.connect(set_label_enabled)
        settings_glayout.addWidget(label_label, 0, 0)
        settings_glayout.addWidget(label_edit, 0, 1, 1, 2)
        settings_glayout.addWidget(label_apply, 0, 3)
        settings_glayout.addWidget(label_msg, 1, 1, 1, -1)

        # Settings tab - PIN
        pin_label = QLabel(_("PIN Protection"))
        pin_button = QPushButton()
        pin_button.clicked.connect(set_pin)
        settings_glayout.addWidget(pin_label, 2, 0)
        settings_glayout.addWidget(pin_button, 2, 1)
        pin_msg = QLabel(
            _("PIN protection is strongly recommended.  "
              "A PIN is your only protection against someone "
              "stealing your syscoins if they obtain physical "
              "access to your {}.").format(plugin.device))
        pin_msg.setWordWrap(True)
        pin_msg.setStyleSheet("color: red")
        settings_glayout.addWidget(pin_msg, 3, 1, 1, -1)

        # Settings tab - Homescreen
        homescreen_label = QLabel(_("Homescreen"))
        homescreen_change_button = QPushButton(_("Change..."))
        homescreen_clear_button = QPushButton(_("Reset"))
        homescreen_change_button.clicked.connect(change_homescreen)
        try:
            import PIL
        except ImportError:
            homescreen_change_button.setDisabled(True)
            homescreen_change_button.setToolTip(
                _("Required package 'PIL' is not available - Please install it or use the Trezor website instead."
                  ))
        homescreen_clear_button.clicked.connect(clear_homescreen)
        homescreen_msg = QLabel(
            _("You can set the homescreen on your "
              "device to personalize it.  You must "
              "choose a {} x {} monochrome black and "
              "white image.").format(hs_cols, hs_rows))
        homescreen_msg.setWordWrap(True)
        settings_glayout.addWidget(homescreen_label, 4, 0)
        settings_glayout.addWidget(homescreen_change_button, 4, 1)
        settings_glayout.addWidget(homescreen_clear_button, 4, 2)
        settings_glayout.addWidget(homescreen_msg, 5, 1, 1, -1)

        # Settings tab - Session Timeout
        timeout_label = QLabel(_("Session Timeout"))
        timeout_minutes = QLabel()
        timeout_slider = QSlider(Qt.Horizontal)
        timeout_slider.setRange(1, 60)
        timeout_slider.setSingleStep(1)
        timeout_slider.setTickInterval(5)
        timeout_slider.setTickPosition(QSlider.TicksBelow)
        timeout_slider.setTracking(True)
        timeout_msg = QLabel(
            _("Clear the session after the specified period "
              "of inactivity.  Once a session has timed out, "
              "your PIN and passphrase (if enabled) must be "
              "re-entered to use the device."))
        timeout_msg.setWordWrap(True)
        timeout_slider.setSliderPosition(config.get_session_timeout() // 60)
        slider_moved()
        timeout_slider.valueChanged.connect(slider_moved)
        timeout_slider.sliderReleased.connect(slider_released)
        settings_glayout.addWidget(timeout_label, 6, 0)
        settings_glayout.addWidget(timeout_slider, 6, 1, 1, 3)
        settings_glayout.addWidget(timeout_minutes, 6, 4)
        settings_glayout.addWidget(timeout_msg, 7, 1, 1, -1)
        settings_layout.addLayout(settings_glayout)
        settings_layout.addStretch(1)

        # Advanced tab
        advanced_tab = QWidget()
        advanced_layout = QVBoxLayout(advanced_tab)
        advanced_glayout = QGridLayout()

        # Advanced tab - clear PIN
        clear_pin_button = QPushButton(_("Disable PIN"))
        clear_pin_button.clicked.connect(clear_pin)
        clear_pin_warning = QLabel(
            _("If you disable your PIN, anyone with physical access to your "
              "{} device can spend your syscoins.").format(plugin.device))
        clear_pin_warning.setWordWrap(True)
        clear_pin_warning.setStyleSheet("color: red")
        advanced_glayout.addWidget(clear_pin_button, 0, 2)
        advanced_glayout.addWidget(clear_pin_warning, 1, 0, 1, 5)

        # Advanced tab - toggle passphrase protection
        passphrase_button = QPushButton()
        passphrase_button.clicked.connect(toggle_passphrase)
        passphrase_msg = WWLabel(PASSPHRASE_HELP)
        passphrase_warning = WWLabel(PASSPHRASE_NOT_PIN)
        passphrase_warning.setStyleSheet("color: red")
        advanced_glayout.addWidget(passphrase_button, 3, 2)
        advanced_glayout.addWidget(passphrase_msg, 4, 0, 1, 5)
        advanced_glayout.addWidget(passphrase_warning, 5, 0, 1, 5)

        # Advanced tab - wipe device
        wipe_device_button = QPushButton(_("Wipe Device"))
        wipe_device_button.clicked.connect(wipe_device)
        wipe_device_msg = QLabel(
            _("Wipe the device, removing all data from it.  The firmware "
              "is left unchanged."))
        wipe_device_msg.setWordWrap(True)
        wipe_device_warning = QLabel(
            _("Only wipe a device if you have the recovery seed written down "
              "and the device wallet(s) are empty, otherwise the syscoins "
              "will be lost forever."))
        wipe_device_warning.setWordWrap(True)
        wipe_device_warning.setStyleSheet("color: red")
        advanced_glayout.addWidget(wipe_device_button, 6, 2)
        advanced_glayout.addWidget(wipe_device_msg, 7, 0, 1, 5)
        advanced_glayout.addWidget(wipe_device_warning, 8, 0, 1, 5)
        advanced_layout.addLayout(advanced_glayout)
        advanced_layout.addStretch(1)

        tabs = QTabWidget(self)
        tabs.addTab(info_tab, _("Information"))
        tabs.addTab(settings_tab, _("Settings"))
        tabs.addTab(advanced_tab, _("Advanced"))
        dialog_vbox = QVBoxLayout(self)
        dialog_vbox.addWidget(tabs)
        dialog_vbox.addLayout(Buttons(CloseButton(self)))

        # Update information
        invoke_client(None)
Esempio n. 52
0
    def __init__(self, setup: Setup):
        super().__init__()
        self.setWindowFlags(Qt.Window)
        self.setWindowTitle("Composite Enthalpy Diagram")

        self._setup = setup

        self._figure = Figure()
        self._canvas = FigureCanvasQTAgg(self._figure)
        self._plt_toolbar = NavigationToolbar2QT(self._canvas, self)

        slider = QSlider(self)
        self._slider = slider
        slider.setValue(self._setup.dt)
        slider.setMinimum(5)
        slider.setMaximum(30)
        slider.setSingleStep(2)
        slider.setOrientation(Qt.Horizontal)
        slider.sliderReleased.connect(self._on_dt_changed)

        setup.dt_changed.connect(self._plot_graph)

        layout = QVBoxLayout()
        layout.addWidget(slider)
        layout.addWidget(self._canvas)
        layout.addWidget(self._plt_toolbar)
        self.setLayout(layout)

        self._plot_graph()
Esempio n. 53
0
class DW(QDockWidget):

    key_pressed_signal = pyqtSignal(QEvent)
    volume_slider_moved_signal = pyqtSignal(int, int)
    view_signal = pyqtSignal(int, str, int)

    def __init__(self, id_, parent=None):
        super().__init__(parent)
        self.id_ = id_
        self.zoomed = False
        self.setWindowTitle(f"Player #{id_ + 1}")
        self.setObjectName(f"player{id_ + 1}")

        self.stack1 = QWidget()
        self.hlayout = QHBoxLayout()
        self.videoframe = Video_frame()
        self.videoframe.video_frame_signal.connect(self.view_signal_triggered)
        self.palette = self.videoframe.palette()
        self.palette.setColor(QPalette.Window, QColor(0, 0, 0))
        self.videoframe.setPalette(self.palette)
        self.videoframe.setAutoFillBackground(True)
        self.hlayout.addWidget(self.videoframe)
        self.volume_slider = QSlider(Qt.Vertical, self)
        self.volume_slider.setMaximum(100)
        self.volume_slider.setValue(50)
        self.volume_slider.sliderMoved.connect(self.volume_slider_moved)
        self.hlayout.addWidget(self.volume_slider)
        self.stack1.setLayout(self.hlayout)

        self.stack2 = QWidget()
        self.hlayout2 = QHBoxLayout()
        self.frame_viewer = Click_label(id_)

        self.frame_viewer.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Expanding)
        self.frame_viewer.setAlignment(Qt.AlignCenter)
        self.frame_viewer.setStyleSheet("QLabel {background-color: black;}")

        self.hlayout2.addWidget(self.frame_viewer)
        self.stack2.setLayout(self.hlayout2)

        self.stack = QStackedWidget(self)
        self.stack.addWidget(self.stack1)
        self.stack.addWidget(self.stack2)

        self.setWidget(self.stack)

    def volume_slider_moved(self):
        """
        emit signal when volume slider moved
        """
        self.volume_slider_moved_signal.emit(self.id_,
                                             self.volume_slider.value())

    def keyPressEvent(self, event):
        """
        emit signal when key pressed on dock widget
        """
        self.key_pressed_signal.emit(event)

    def view_signal_triggered(self, msg, button):
        """
        transmit signal received by video frame
        """
        self.view_signal.emit(self.id_, msg, button)
Esempio n. 54
0
class Conway(QWidget):
    """A PyQtWidget with all elements necessary to implement the famous
    Conway's game of life application."""
    def __init__(self):

        super().__init__()

        self.title = "Conway's Game of Life"
        self.width = 400
        self.height = 600
        self.baseSpeed = 101
        self.aliveColor = QtCore.Qt.blue
        self.deadColor = QtCore.Qt.white
        self.speed = self.baseSpeed
        self.initUI()
        self.center()

        self.gosper = False
        self.gridSize = 20
        self.squareSize = 50
        self.grid = np.random.randint(2, size=(self.gridSize, self.gridSize))

    def center(self):
        "Centers the Conway object window on the desktop."
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def getNeighbors(self, pos):
        """Retrieve a list of neighbors in a given cell.
        
        Conway's game of life is governed by rules involving the neighboring
        cells of each cell on the game board. This function identifies the 
        neighbor cells of a given position on the grid, so that the rules may
        be applied to the subject cell. 
        
        For the Gosper Glider Gun, the sides of the game board are unstitched, 
        as the gliders are intended to go on forever without interfering with
        their source.
        
        """
        up_row = pos[0] - 1
        down_row = pos[0] + 1
        left_col = pos[1] - 1
        right_col = pos[1] + 1

        if self.gosper:
            neighbor_list = [(up_row, left_col), (up_row, pos[1]),
                             (up_row, right_col), (pos[0], left_col),
                             (pos[0], right_col), (down_row, left_col),
                             (down_row, pos[1]), (down_row, right_col)]

            if up_row < 0:
                try:
                    neighbor_list.remove((up_row, left_col))
                    neighbor_list.remove((up_row, pos[1]))
                    neighbor_list.remove((up_row, right_col))
                except ValueError:
                    pass
            if left_col < 0:
                try:
                    neighbor_list.remove((up_row, left_col))
                except ValueError:
                    pass
                neighbor_list.remove((pos[0], left_col))
                neighbor_list.remove((down_row, left_col))
            if down_row > self.gridSize - 1:
                try:
                    neighbor_list.remove((down_row, left_col))
                except ValueError:
                    pass
                neighbor_list.remove((down_row, pos[1]))
                neighbor_list.remove((down_row, right_col))

            if right_col > self.gridSize - 1:
                try:
                    neighbor_list.remove((up_row, right_col))
                except ValueError:
                    pass
                try:
                    neighbor_list.remove((down_row, right_col))
                except ValueError:
                    pass

                neighbor_list.remove((pos[0], right_col))

        else:

            if up_row < 0:
                up_row = self.gridSize - 1
            if left_col < 0:
                left_col = self.gridSize - 1
            if down_row > self.gridSize - 1:
                down_row = 0
            if right_col > self.gridSize - 1:
                right_col = 0

            neighbor_list = [(up_row, left_col), (up_row, pos[1]),
                             (up_row, right_col), (pos[0], left_col),
                             (pos[0], right_col), (down_row, left_col),
                             (down_row, pos[1]), (down_row, right_col)]

        return neighbor_list

    def goToNextGen(self):
        """Calculate the next generation of cells.
        
        Uses the rules of Conway's Game of Life to create a new generation of
        cells based on the current generation of cells, then updates the window
        so the Painter object re-draws the grid.
        
        Conway's Game of Life Rules (per Wikipedia):
            
            1. Any live cell with two or three live neighbours survives.
            2. Any dead cell with three live neighbours becomes a live cell.
            3. All other live cells die in the next generation. Similarly, 
            all other dead cells stay dead.
            
        """
        nextgen = np.array([[0] * self.gridSize] * self.gridSize)
        for i in range(self.gridSize):
            for j in range(self.gridSize):
                neighbors = self.getNeighbors((i, j))
                testsum = self.grid[i, j]
                for n in neighbors:
                    testsum += self.grid[n[0], n[1]]
                if testsum == 3:
                    nextgen[i, j] = 1
                elif testsum == 4:
                    nextgen[i, j] = self.grid[i, j]
                else:
                    nextgen[i, j] = 0

        self.grid = nextgen
        self.update()

    def initUI(self):
        """Initialize User Interface
        
        Populates the window with userful UI elements, including:
            
            1. Start, Pause, and Reset buttons.
            2. A speed slider.
            3. Color selection buttons and associated dialogs
            4. Pulsar, Penta-Decathalon, and Gosper Glider Gun buttons, which
            change the initial state of the application for predictable 
            results. The initial states are read in from provided CSV files.
            
        Each of these elements are connected to functions that materialize
        their effects in the game board.
            
        """
        self.setWindowTitle(self.title)
        self.setFixedSize(self.width, self.height)

        # Media Buttons
        self.btnStart = QPushButton(self)
        self.btnStart.setGeometry(QtCore.QRect(155, 365, 45, 25))
        self.btnStart.setIcon(self.style().standardIcon(
            getattr(QStyle, 'SP_MediaPlay')))
        self.btnStart.setToolTip('Start')
        self.btnPause = QPushButton(self)
        self.btnPause.setGeometry(QtCore.QRect(195, 365, 45, 25))
        self.btnPause.setIcon(self.style().standardIcon(
            getattr(QStyle, 'SP_MediaPause')))
        self.btnPause.setToolTip('Pause')

        # Speed Slider
        lblSlow = QLabel("Slow", self)
        lblSlow.setGeometry(QtCore.QRect(65, 400, 25, 25))
        self.slSpeed = QSlider(QtCore.Qt.Horizontal, parent=self)
        self.slSpeed.setGeometry(QtCore.QRect(96, 400, 200, 25))
        self.slSpeed.setMinimum(-10)
        self.slSpeed.setMaximum(10)
        self.slSpeed.setValue(0)
        self.slSpeed.setTickPosition(QSlider.TicksBelow)
        self.slSpeed.setTickInterval(1)
        self.slSpeed.setToolTip('Change tick speed.')
        lblFast = QLabel("Fast", self)
        lblFast.setGeometry(QtCore.QRect(305, 400, 25, 25))

        # Color Selection
        group = QGroupBox("Change Colors", self)
        grid = QGridLayout()
        self.btnAliveColor = QPushButton("Alive...", self)
        self.btnAliveColor.setToolTip('Change color of alive cells.')
        self.btnDeadColor = QPushButton("Dead...", self)
        self.btnDeadColor.setToolTip('Change color of dead cells.')
        grid.addWidget(self.btnAliveColor, 0, 0)
        grid.addWidget(self.btnDeadColor, 0, 1)
        group.setLayout(grid)
        group.setGeometry(QtCore.QRect(35, 435, 325, 60))

        # Starting Conditions
        group = QGroupBox("Starting Conditions", self)

        grid = QGridLayout()

        self.btnPulsar = QPushButton("Pulsar", self)
        self.btnPulsar.setToolTip("Change to 'Pulsar' initial state.")
        self.btnPenta = QPushButton("Penta-Decathalon", self)
        self.btnPenta.setToolTip("Change to 'Penta-Decathalon' initial state.")
        self.btnGosper = QPushButton("Gosper Glider Gun", self)
        self.btnGosper.setToolTip("Change to 'Gosper Glider Gun' " +
                                  "initial state.")

        grid.addWidget(self.btnPulsar, 0, 0)
        grid.addWidget(self.btnPenta, 0, 1)
        grid.addWidget(self.btnGosper, 0, 2)

        group.setLayout(grid)
        group.setGeometry(QtCore.QRect(35, 500, 325, 60))

        # Reset Button
        self.btnReset = QPushButton('Reset', self)
        self.btnReset.setGeometry(QtCore.QRect(155, 565, 90, 25))
        self.btnReset.setToolTip("Reset program to a random initial state.")

        self.show()

        self.btnStart.clicked.connect(self.onClickStart)
        self.btnPause.clicked.connect(self.onClickPause)
        self.slSpeed.valueChanged.connect(self.onSpeedChange)
        self.btnReset.clicked.connect(self.onClickReset)
        self.btnAliveColor.clicked.connect(self.onClickAliveColor)
        self.btnDeadColor.clicked.connect(self.onClickDeadColor)
        self.btnPulsar.clicked.connect(self.onClickPulsar)
        self.btnPenta.clicked.connect(self.onClickPenta)
        self.btnGosper.clicked.connect(self.onClickGosper)

    def onClickAliveColor(self):
        "Changes the color of living cells to the user's choice."
        self.running = False
        self.aliveColor = QColorDialog.getColor()

    def onClickDeadColor(self):
        "Changes the color of dead cells to the user's choice."
        self.running = False
        self.deadColor = QColorDialog.getColor()

    def onClickGosper(self):
        "Changes the initial state of the game to the Gosper Glider Gun."
        self.running = False
        self.gosper = True
        self.baseSpeed = 101
        self.slSpeed.setValue(0)
        self.gridSize = 50
        self.squareSize = 20
        self.grid = np.loadtxt(open(ROOT + "inputs/gosper.txt", "rb"),
                               delimiter=",").T
        self.update()

    def onClickPause(self):
        "Pauses Conway's game of life on the game board."
        self.running = False

    def onClickPenta(self):
        "Changes the initial state of the game to the Penta-Decathalon."
        self.running = False
        self.baseSpeed = 801
        self.speed = self.baseSpeed
        self.slSpeed.setValue(0)
        self.gridSize = 20
        self.squareSize = 50
        self.grid = np.loadtxt(open(ROOT + "inputs/penta.txt", "rb"),
                               delimiter=",").T
        self.update()

    def onClickPulsar(self):
        "Changes the initial state of the game to the Pulsar."
        self.running = False
        self.baseSpeed = 801
        self.speed = self.baseSpeed
        self.slSpeed.setValue(0)
        self.gridSize = 20
        self.squareSize = 50
        self.grid = np.loadtxt(open(ROOT + "inputs/pulsar.txt", "rb"),
                               delimiter=",").T
        self.update()

    def onClickReset(self):
        """Resets the game to its initial state. This means a random intial 
        state for the game board, blue and white for alive and dead colors
        respectively, and changing the base speed back to 101."""
        self.running = False
        self.aliveColor = QtCore.Qt.blue
        self.deadColor = QtCore.Qt.white
        self.gridSize = 20
        self.squareSize = 50
        self.base_speed = 101
        self.speed = self.baseSpeed
        self.slSpeed.setValue(0)
        self.grid = np.random.randint(2, size=(self.gridSize, self.gridSize))
        self.update()

    def onClickStart(self):
        "Runs Conway's game of life on the game board."
        self.running = True
        while self.running:
            QtTest.QTest.qWait(self.speed)
            self.goToNextGen()

    def onSpeedChange(self):
        """Changes the speed of Conway's game of life by increasing or 
        decreasing the time in between updates."""
        self.speed = self.baseSpeed + (self.slSpeed.value() *
                                       -(self.baseSpeed * 0.1))

    def paintEvent(self, event):
        """Creates a painter object to construct a visual representation of 
        Conway's Game of Life."""
        painter = QPainter(self)
        painter.setPen(QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine))
        painter.setWindow(-100, -50, 1200, 1800)
        for row in range(self.gridSize):
            for col in range(self.gridSize):
                if self.grid[row, col] == 0:
                    painter.setBrush(
                        QBrush(self.deadColor, QtCore.Qt.SolidPattern))
                    painter.drawRect(row * self.squareSize,
                                     col * self.squareSize, self.squareSize,
                                     self.squareSize)
                else:
                    painter.setBrush(
                        QBrush(self.aliveColor, QtCore.Qt.SolidPattern))
                    painter.drawRect(row * self.squareSize,
                                     col * self.squareSize, self.squareSize,
                                     self.squareSize)
Esempio n. 55
0
    def set_layout(self) -> None:

        self.plot_tabs = QTabWidget()
        map_tab = QWidget()
        map_layout = QVBoxLayout()
        map_tab.setLayout(map_layout)

        self.map_plot = MapCanvas(parent=self, width=5, height=4)
        self.map_plot.move(0, 0)
        self.time_plot = TimeCanvas(parent=self, width=5, height=4)
        self.time_plot.move(0, 0)

        map_toolbar = NavigationToolbar2QT(self.map_plot, map_tab)
        map_toolbar.setVisible(False)
        map_layout.addWidget(map_toolbar)
        map_layout.addWidget(self.map_plot)
        map_toolbar.pan()

        time_tab = QWidget()
        time_layout = QVBoxLayout()
        time_tab.setLayout(time_layout)

        self.y_selector = QListWidget()
        self.sec_y_selector = QListWidget()
        self.y_selector.setSelectionMode(3)  # extended selection
        self.sec_y_selector.setSelectionMode(3)  # extended selection
        selector = QHBoxLayout()
        selector.addWidget(self.y_selector)
        selector.addWidget(self.sec_y_selector)

        time_layout.addLayout(selector)
        time_layout.addWidget(self.time_plot)

        self.plot_tabs.addTab(map_tab, "Map")
        self.plot_tabs.addTab(time_tab, "Plots")

        plot_column = QVBoxLayout()
        plot_column.addWidget(self.plot_tabs)

        self.interact_column = QVBoxLayout()

        self.open_options = ["Open file", "dump1090"]
        if "decoders" in config:
            self.open_options += list(config["decoders"])
        self.open_dropdown = QComboBox()
        for option in self.open_options:
            self.open_dropdown.addItem(option)
        self.interact_column.addWidget(self.open_dropdown)

        self.projections = ["EuroPP", "Lambert93", "Mercator"]
        self.projection_dropdown = QComboBox()
        more_projs = config.get("projections", "extra", fallback="")
        if more_projs != "":
            proj_list = more_projs.split(";")
            self.projections += list(x.strip() for x in proj_list)
        for proj in self.projections:
            self.projection_dropdown.addItem(proj)
        self.interact_column.addWidget(self.projection_dropdown)

        button_grid = QGridLayout()

        self.extent_button = QPushButton("Extent")
        button_grid.addWidget(self.extent_button, 0, 0)
        self.plot_button = QPushButton("Plot")
        button_grid.addWidget(self.plot_button, 0, 1)
        self.airport_button = QPushButton("Airport")
        button_grid.addWidget(self.airport_button, 1, 0)
        self.reset_button = QPushButton("Reset")
        button_grid.addWidget(self.reset_button, 1, 1)

        self.interact_column.addLayout(button_grid)

        self.area_input_description = QLabel("Area")
        self.area_input = QLineEdit()
        area_input_layout = QHBoxLayout()
        area_input_layout.addWidget(self.area_input_description)
        area_input_layout.addWidget(self.area_input)
        self.interact_column.addLayout(area_input_layout)

        self.area_select = QListWidget()
        self.interact_column.addWidget(self.area_select)

        self.time_slider = QSlider(QtCore.Qt.Horizontal)
        self.time_description = QLabel("Date max.")
        self.time_slider_info = QLabel()
        time_layout = QHBoxLayout()
        time_layout.addWidget(self.time_description)
        time_layout.addWidget(self.time_slider)
        time_layout.addWidget(self.time_slider_info)
        self.time_slider.setMinimum(0)
        self.time_slider.setMaximum(99)
        self.time_slider.setValue(99)
        self.time_slider.setEnabled(False)
        self.interact_column.addLayout(time_layout)

        self.altitude_slider = QSlider(QtCore.Qt.Horizontal)
        self.altitude_description = QLabel("Altitude max.")
        self.altitude_slider_info = QLabel("60000")
        self.altitude_slider.setSingleStep(5)
        self.altitude_slider.setPageStep(100)
        self.altitude_slider.setMinimum(0)
        self.altitude_slider.setMaximum(600)
        self.altitude_slider.setValue(600)
        altitude_layout = QHBoxLayout()
        altitude_layout.addWidget(self.altitude_description)
        altitude_layout.addWidget(self.altitude_slider)
        altitude_layout.addWidget(self.altitude_slider_info)
        self.interact_column.addLayout(altitude_layout)

        self.identifier_description = QLabel("Callsign/ID")
        self.identifier_input = QLineEdit()

        identifier_layout = QHBoxLayout()
        identifier_layout.addWidget(self.identifier_description)
        identifier_layout.addWidget(self.identifier_input)
        self.interact_column.addLayout(identifier_layout)

        self.identifier_select = QListWidget()
        self.identifier_select.setSelectionMode(3)  # extended selection
        self.interact_column.addWidget(self.identifier_select)

        mainLayout = QGridLayout()
        mainLayout.addLayout(plot_column, 0, 0)
        mainLayout.addLayout(self.interact_column, 0, 1)

        mainWidget = QWidget()
        mainWidget.setLayout(mainLayout)
        self.setCentralWidget(mainWidget)
Esempio n. 56
0
    def initUI(self):
        """Initialize User Interface
        
        Populates the window with userful UI elements, including:
            
            1. Start, Pause, and Reset buttons.
            2. A speed slider.
            3. Color selection buttons and associated dialogs
            4. Pulsar, Penta-Decathalon, and Gosper Glider Gun buttons, which
            change the initial state of the application for predictable 
            results. The initial states are read in from provided CSV files.
            
        Each of these elements are connected to functions that materialize
        their effects in the game board.
            
        """
        self.setWindowTitle(self.title)
        self.setFixedSize(self.width, self.height)

        # Media Buttons
        self.btnStart = QPushButton(self)
        self.btnStart.setGeometry(QtCore.QRect(155, 365, 45, 25))
        self.btnStart.setIcon(self.style().standardIcon(
            getattr(QStyle, 'SP_MediaPlay')))
        self.btnStart.setToolTip('Start')
        self.btnPause = QPushButton(self)
        self.btnPause.setGeometry(QtCore.QRect(195, 365, 45, 25))
        self.btnPause.setIcon(self.style().standardIcon(
            getattr(QStyle, 'SP_MediaPause')))
        self.btnPause.setToolTip('Pause')

        # Speed Slider
        lblSlow = QLabel("Slow", self)
        lblSlow.setGeometry(QtCore.QRect(65, 400, 25, 25))
        self.slSpeed = QSlider(QtCore.Qt.Horizontal, parent=self)
        self.slSpeed.setGeometry(QtCore.QRect(96, 400, 200, 25))
        self.slSpeed.setMinimum(-10)
        self.slSpeed.setMaximum(10)
        self.slSpeed.setValue(0)
        self.slSpeed.setTickPosition(QSlider.TicksBelow)
        self.slSpeed.setTickInterval(1)
        self.slSpeed.setToolTip('Change tick speed.')
        lblFast = QLabel("Fast", self)
        lblFast.setGeometry(QtCore.QRect(305, 400, 25, 25))

        # Color Selection
        group = QGroupBox("Change Colors", self)
        grid = QGridLayout()
        self.btnAliveColor = QPushButton("Alive...", self)
        self.btnAliveColor.setToolTip('Change color of alive cells.')
        self.btnDeadColor = QPushButton("Dead...", self)
        self.btnDeadColor.setToolTip('Change color of dead cells.')
        grid.addWidget(self.btnAliveColor, 0, 0)
        grid.addWidget(self.btnDeadColor, 0, 1)
        group.setLayout(grid)
        group.setGeometry(QtCore.QRect(35, 435, 325, 60))

        # Starting Conditions
        group = QGroupBox("Starting Conditions", self)

        grid = QGridLayout()

        self.btnPulsar = QPushButton("Pulsar", self)
        self.btnPulsar.setToolTip("Change to 'Pulsar' initial state.")
        self.btnPenta = QPushButton("Penta-Decathalon", self)
        self.btnPenta.setToolTip("Change to 'Penta-Decathalon' initial state.")
        self.btnGosper = QPushButton("Gosper Glider Gun", self)
        self.btnGosper.setToolTip("Change to 'Gosper Glider Gun' " +
                                  "initial state.")

        grid.addWidget(self.btnPulsar, 0, 0)
        grid.addWidget(self.btnPenta, 0, 1)
        grid.addWidget(self.btnGosper, 0, 2)

        group.setLayout(grid)
        group.setGeometry(QtCore.QRect(35, 500, 325, 60))

        # Reset Button
        self.btnReset = QPushButton('Reset', self)
        self.btnReset.setGeometry(QtCore.QRect(155, 565, 90, 25))
        self.btnReset.setToolTip("Reset program to a random initial state.")

        self.show()

        self.btnStart.clicked.connect(self.onClickStart)
        self.btnPause.clicked.connect(self.onClickPause)
        self.slSpeed.valueChanged.connect(self.onSpeedChange)
        self.btnReset.clicked.connect(self.onClickReset)
        self.btnAliveColor.clicked.connect(self.onClickAliveColor)
        self.btnDeadColor.clicked.connect(self.onClickDeadColor)
        self.btnPulsar.clicked.connect(self.onClickPulsar)
        self.btnPenta.clicked.connect(self.onClickPenta)
        self.btnGosper.clicked.connect(self.onClickGosper)
class WindowPlot(QMainWindow):
    def __init__(self, parent=None):
        pg.setConfigOption('background', 'w')  #before loading widget
        super(WindowPlot, self).__init__(parent)

        self.RNDbtn = False
        self.data = []  #np.random.normal(size=100)
        self.Xtime = []
        self.refreshInterval = 1000  # default refresh plot every 1s
        self.timer = pg.QtCore.QTimer()
        self.errReadEvent = ''  # holds error history
        self.counterTest = 0

        self.wid = QtGui.QWidget(self)
        self.setCentralWidget(self.wid)

        vbox = QVBoxLayout()
        self.createLayout1()
        vbox.addWidget(self.groupBoxPlot)
        vbox.addWidget(self.groupBoxData)
        self.wid.setLayout(vbox)

    def createLayout1(self):
        vboxlayoutPlot = QVBoxLayout()
        vboxlayoutData = QVBoxLayout()
        self.groupBoxPlot = QGroupBox("Plotting")
        self.groupBoxData = QGroupBox("Data")
        self.create_plot()
        vboxlayoutPlot.addLayout(self.layout)

        self.gridPlot = QGridLayout()
        self.gridData = QGridLayout()

        self.slider = QSlider(QTC.Horizontal)
        self.slider.setFocusPolicy(QTC.StrongFocus)
        self.slider.setTickPosition(QSlider.TicksBothSides)
        self.slider.setTickInterval(1)
        self.slider.setSingleStep(1)
        self.slider.setMaximum(10)
        self.slider.setMinimum(0)
        # self.slider.valueChanged.connect(self.SliderVal)
        self.slider.setValue(7)

        self.cb = QtWidgets.QComboBox()
        # self.cb.addItem("10")
        self.cb.addItems(["5", "2", "1"])
        self.cb.setCurrentIndex(2)
        self.cb.currentIndexChanged.connect(self.ComboInterval)

        self.Refr = QHBoxLayout()
        self.labelInterval = QLabel()
        self.labelInterval.setText("Refresh rate (s)")

        self.Refr.addWidget(self.labelInterval)
        self.Refr.addWidget(self.cb)

        # Error box START
        self.hboxErrSourceDt = QHBoxLayout()
        self.ErrorGroup = QGroupBox("Errors")
        self.vboxErrBox = QVBoxLayout()
        self.hboxErrLEDLBL = QHBoxLayout()
        self.hboxErrorEvents = QHBoxLayout()
        self.hboxErrorEvents.setSizeConstraint(QLayout.SetFixedSize)

        self.LEDError = QPushButton()  # used as error LED indicator
        self.LEDError.setEnabled(False)
        self.LEDError.setMaximumHeight(15)
        self.LEDError.setMaximumWidth(15)

        self.labelErrorRead = QLabel()
        self.labelErrorRead.setText("Error reading data")

        self.label_ErrorReadEvents = QLabel()
        self.label_ErrorReadEvents.setFont(QtGui.QFont("Sanserif", 10))
        self.label_ErrorReadEvents.setMinimumWidth(200)

        scrollErrors = QScrollArea()
        scrollErrors.setWidget(self.label_ErrorReadEvents)
        scrollErrors.setWidgetResizable(True)
        # scrollErrors.setMaximumHeight(80)
        scrollErrors.setMinimumWidth(200)

        self.hboxErrLEDLBL.addWidget(self.LEDError)
        self.hboxErrLEDLBL.addWidget(self.labelErrorRead)
        self.vboxErrBox.addLayout(self.hboxErrLEDLBL)
        self.vboxErrBox.addWidget(scrollErrors)
        self.ErrorGroup.setLayout(self.vboxErrBox)

        self.cbDataSource = QtWidgets.QComboBox()
        # self.cb.addItem("10")
        self.cbDataSource.addItems(
            ["Random generated test Data", "Remote data"])
        self.cbDataSource.setCurrentIndex(1)

        self.hboxErrSourceDt.addWidget(self.ErrorGroup)
        self.hboxErrSourceDt.addWidget(self.cbDataSource)
        # Error box END

        self.GetDataBtn = QPushButton("Start Plot")
        self.GetDataBtn.clicked.connect(self.ticker)
        self.GetDataBtn.setMinimumHeight(50)
        self.GetDataBtn.setMinimumWidth(180)

        self.gridPlot.addWidget(self.slider, 0, 0)
        self.gridPlot.addLayout(self.Refr, 1, 0)

        self.gridData.addLayout(self.hboxErrSourceDt, 0, 0)
        self.gridData.addWidget(self.GetDataBtn, 0, 1)

        vboxlayoutPlot.addLayout(self.gridPlot)
        self.groupBoxPlot.setLayout(vboxlayoutPlot)

        vboxlayoutData.addLayout(self.gridData)
        self.groupBoxData.setLayout(vboxlayoutData)

    # def SliderVal(self):
    #     print(self.slider.value())

    def ComboInterval(self):
        self.refreshInterval = int(self.cb.currentText()) * 1000
        if self.timer.isActive():
            self.timer.stop()
            self.timer.start(self.refreshInterval)

    def create_plot(self):

        self.stream_scroll = pg.PlotWidget(
            title='Stream Monitor',
            labels={'left': 'Channel'},
            axisItems={'bottom': TimeAxisItem(orientation='bottom')})

        self.stream_scroll.setYRange(-4, 4, padding=.01)

        # self.stream_scroll.setXRange(0,100, padding=.01)
        self.stream_scroll.setXRange(timestamp(), timestamp() + 100)

        self.layout = QtGui.QGridLayout()
        self.stream_scroll.plotItem.showGrid(True, True, .5)
        self.layout.addWidget(self.stream_scroll, 0, 0)

        C = pg.hsvColor(.7, alpha=.5)
        self.pen = pg.mkPen(color=C, width=1)
        self.curve = self.stream_scroll.plot(pen=self.pen)

    def update1(self):
        # global data
        if len(self.data) > 100:
            self.data[:-1] = self.data[
                1:]  # shift data in the array one, see also np.pull
            if self.cbDataSource.currentIndex() == 0:
                self.data[-1] = np.random.rand()  # .normal()
            else:
                self.data[-1] = self.FiledataConvert()
            self.Xtime[:-1] = self.Xtime[1:]
            self.Xtime[-1] = timestamp()  # int(round(time.time()*1000))+100

        else:
            if self.cbDataSource.currentIndex() == 0:
                self.data.append(np.random.rand())
            else:
                self.data.append(self.FiledataConvert())
            self.Xtime.append(timestamp())

        X = self.Xtime
        # Y=np.sin(np.arange(points)/points*3*np.pi+time.time()) # draw sin wave
        Y = self.data  # np.random.rand(100)
        self.curve.setData(X, Y)

    def FiledataConvert(self):
        f = open("output1.txt", "r")
        a = f.read()
        f.close()
        try:
            a = round(int(a) / 204, 3)
            self.LEDError.setStyleSheet("background-color: blue")
        except Exception as err:
            datetimeObj = datetime.now()
            a = 0
            self.LEDError.setStyleSheet("background-color: red")
            print(datetimeObj)
            print(traceback.format_exc())  # display error
            self.errReadEvent = self.errReadEvent + 'Error reading Data at:' + str(
                datetimeObj) + '\n'
            self.label_ErrorReadEvents.setText(self.errReadEvent)
            # print(sys.exc_info()[0])  # display error

        return a

    def ticker(self):
        if self.RNDbtn == False:
            self.timer = pg.QtCore.QTimer()
            self.timer.timeout.connect(self.update1)
            self.timer.start(self.refreshInterval)
            self.RNDbtn = True
            self.GetDataBtn.setStyleSheet("background-color: green")
            self.GetDataBtn.setText("Disconnect")

        else:
            self.timer.stop()
            self.RNDbtn = False
            self.GetDataBtn.setStyleSheet("background-color: red")
            self.GetDataBtn.setText("Connect")
Esempio n. 58
0
    def initUI(self):
        self.setGeometry(350, 200, 600, 400)
        self.setWindowTitle('Password generator')

        # title of the window
        self.title = QtWidgets.QLabel('Times', self)
        self.title.setFont(QFont('Times', 20))
        self.title.setText('Password Generator')
        self.title.move(180, 10)
        self.title.resize(250, 80)

        # atturtuibes of the password

        # length of the password
        self.length_of_password = QtWidgets.QLineEdit(self)
        self.length_of_password.setDisabled(True)
        self.length_of_password.setText('0')
        self.length_of_password.resize(150, 40)
        self.length_of_password.move(40, 115)

        self.add_length = QtWidgets.QPushButton(self)
        self.add_length.setText("A")
        self.add_length.move(170, 115)
        self.add_length.resize(20, 20)
        self.add_length.setObjectName("length_of_password")
        self.add_length.clicked.connect(self.add_or_sub)

        self.remove_length = QtWidgets.QPushButton(self)
        self.remove_length.setText("S")
        self.remove_length.move(170, 135)
        self.remove_length.resize(20, 20)
        self.remove_length.setObjectName("length_of_password")
        self.remove_length.clicked.connect(self.add_or_sub)

        self.len_of_pass = QtWidgets.QLabel(self)
        self.len_of_pass.setText('Length of password')
        self.len_of_pass.setFont(QFont('Times', 10))
        self.len_of_pass.move(40, 80)
        self.len_of_pass.resize(250, 40)

        # password add special characters

        self.add_special = QtWidgets.QLabel(self)
        self.add_special.setText(
            'Add special characters. (^ < > , . \' \" ` ~)')
        self.add_special.setFont(QFont('Times', 10))
        self.add_special.move(40, 150)
        self.add_special.resize(250, 40)

        self.checkbox1 = QCheckBox(self)
        self.checkbox1.move(300, 165)

        # password adds capital letters
        self.add_caps = QtWidgets.QLabel(self)
        self.add_caps.setText('Add capital letters. (A B C D)')
        self.add_caps.setFont(QFont('Times', 10))
        self.add_caps.move(40, 180)
        self.add_caps.resize(250, 40)

        self.checkbox2 = QCheckBox(self)
        self.checkbox2.move(300, 192)

        # password add letters
        self.add_letters = QtWidgets.QLabel(self)
        self.add_letters.setText('Add letters. (a b c d)')
        self.add_letters.setFont(QFont('Times', 10))
        self.add_letters.move(40, 210)
        self.add_letters.resize(250, 40)

        self.checkbox3 = QCheckBox(self)
        self.checkbox3.move(300, 219)

        self.add_numbers = QtWidgets.QLabel(self)
        self.add_numbers.setText('Add numbers. (1 2 3 4)')
        self.add_numbers.setFont(QFont('Times', 10))
        self.add_numbers.move(40, 240)
        self.add_numbers.resize(250, 40)

        self.checkbox4 = QCheckBox(self)
        self.checkbox4.move(300, 246)

        # password add math symbols
        self.add_math_symbols = QtWidgets.QLabel(self)
        self.add_math_symbols.setText('Add math symbols. (+ - = /)')
        self.add_math_symbols.setFont(QFont('Times', 10))
        self.add_math_symbols.move(40, 270)
        self.add_math_symbols.resize(250, 40)

        self.checkbox5 = QCheckBox(self)
        self.checkbox5.move(300, 280)

        # amount of passwords
        self.amount_of_passwords = QtWidgets.QLineEdit(self)
        self.amount_of_passwords.setDisabled(True)
        self.amount_of_passwords.setText('0')
        self.amount_of_passwords.resize(150, 40)
        self.amount_of_passwords.move(375, 115)

        self.add_passwords = QtWidgets.QPushButton(self)
        self.add_passwords.setText("A")
        self.add_passwords.move(505, 115)
        self.add_passwords.resize(20, 20)
        self.add_passwords.clicked.connect(self.add_or_sub)

        self.remove_passwords = QtWidgets.QPushButton(self)
        self.remove_passwords.setText("S")
        self.remove_passwords.move(505, 135)
        self.remove_passwords.resize(20, 20)
        self.remove_passwords.clicked.connect(self.add_or_sub)

        self.amount_of_pass = QtWidgets.QLabel(self)
        self.amount_of_pass.setText('Add amount of passwords')
        self.amount_of_pass.setFont(QFont('Times', 10))
        self.amount_of_pass.move(375, 80)
        self.amount_of_pass.resize(250, 40)

        # submit password with attrubites
        self.submit_password = QtWidgets.QPushButton(self)
        self.submit_password.setText("Get Passwords")
        self.submit_password.move(375, 165)
        self.submit_password.resize(150, 40)
        self.submit_password.clicked.connect(self.submit)

        #slide down for information
        self.slider = QSlider(Qt.Vertical, self)
        self.slider.valueChanged.connect(self.updateLabel)
        self.slider.resize(30, 75)
        self.slider.move(515, 250)
        self.slider.setInvertedAppearance(True)
        self.slider.setDisabled(True)

        #display passwords
        self.display_passwords = QtWidgets.QLabel(self)
        self.display_passwords.setFont(QFont('Times', 10))
        self.display_passwords.setText('')
        self.display_passwords.move(375, 230)
Esempio n. 59
0
class Mainwindow(QMainWindow):
    def __init__(self):
        super(mainwindow, self).__init__()
        self.initUI()
        self.password_attributes = []
        self.numbers = [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "0",
        ]
        self.math_symbols = [
            "*",
            "%",
            "(",
            ")",
            "/",
            "+",
            "=",
            "-",
            ">",
            "<",
        ]
        self.letters = [
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
        ]
        self.caps_letters = [letter.upper() for letter in self.letters]
        self.speical_chacathers = [
            "!", "`", "~", "@", "#", "$", "&", "_", "}", "{", "\"", "\'", ",",
            "."
        ]
        self.passwords = []

    def initUI(self):
        self.setGeometry(350, 200, 600, 400)
        self.setWindowTitle('Password generator')

        # title of the window
        self.title = QtWidgets.QLabel('Times', self)
        self.title.setFont(QFont('Times', 20))
        self.title.setText('Password Generator')
        self.title.move(180, 10)
        self.title.resize(250, 80)

        # atturtuibes of the password

        # length of the password
        self.length_of_password = QtWidgets.QLineEdit(self)
        self.length_of_password.setDisabled(True)
        self.length_of_password.setText('0')
        self.length_of_password.resize(150, 40)
        self.length_of_password.move(40, 115)

        self.add_length = QtWidgets.QPushButton(self)
        self.add_length.setText("A")
        self.add_length.move(170, 115)
        self.add_length.resize(20, 20)
        self.add_length.setObjectName("length_of_password")
        self.add_length.clicked.connect(self.add_or_sub)

        self.remove_length = QtWidgets.QPushButton(self)
        self.remove_length.setText("S")
        self.remove_length.move(170, 135)
        self.remove_length.resize(20, 20)
        self.remove_length.setObjectName("length_of_password")
        self.remove_length.clicked.connect(self.add_or_sub)

        self.len_of_pass = QtWidgets.QLabel(self)
        self.len_of_pass.setText('Length of password')
        self.len_of_pass.setFont(QFont('Times', 10))
        self.len_of_pass.move(40, 80)
        self.len_of_pass.resize(250, 40)

        # password add special characters

        self.add_special = QtWidgets.QLabel(self)
        self.add_special.setText(
            'Add special characters. (^ < > , . \' \" ` ~)')
        self.add_special.setFont(QFont('Times', 10))
        self.add_special.move(40, 150)
        self.add_special.resize(250, 40)

        self.checkbox1 = QCheckBox(self)
        self.checkbox1.move(300, 165)

        # password adds capital letters
        self.add_caps = QtWidgets.QLabel(self)
        self.add_caps.setText('Add capital letters. (A B C D)')
        self.add_caps.setFont(QFont('Times', 10))
        self.add_caps.move(40, 180)
        self.add_caps.resize(250, 40)

        self.checkbox2 = QCheckBox(self)
        self.checkbox2.move(300, 192)

        # password add letters
        self.add_letters = QtWidgets.QLabel(self)
        self.add_letters.setText('Add letters. (a b c d)')
        self.add_letters.setFont(QFont('Times', 10))
        self.add_letters.move(40, 210)
        self.add_letters.resize(250, 40)

        self.checkbox3 = QCheckBox(self)
        self.checkbox3.move(300, 219)

        self.add_numbers = QtWidgets.QLabel(self)
        self.add_numbers.setText('Add numbers. (1 2 3 4)')
        self.add_numbers.setFont(QFont('Times', 10))
        self.add_numbers.move(40, 240)
        self.add_numbers.resize(250, 40)

        self.checkbox4 = QCheckBox(self)
        self.checkbox4.move(300, 246)

        # password add math symbols
        self.add_math_symbols = QtWidgets.QLabel(self)
        self.add_math_symbols.setText('Add math symbols. (+ - = /)')
        self.add_math_symbols.setFont(QFont('Times', 10))
        self.add_math_symbols.move(40, 270)
        self.add_math_symbols.resize(250, 40)

        self.checkbox5 = QCheckBox(self)
        self.checkbox5.move(300, 280)

        # amount of passwords
        self.amount_of_passwords = QtWidgets.QLineEdit(self)
        self.amount_of_passwords.setDisabled(True)
        self.amount_of_passwords.setText('0')
        self.amount_of_passwords.resize(150, 40)
        self.amount_of_passwords.move(375, 115)

        self.add_passwords = QtWidgets.QPushButton(self)
        self.add_passwords.setText("A")
        self.add_passwords.move(505, 115)
        self.add_passwords.resize(20, 20)
        self.add_passwords.clicked.connect(self.add_or_sub)

        self.remove_passwords = QtWidgets.QPushButton(self)
        self.remove_passwords.setText("S")
        self.remove_passwords.move(505, 135)
        self.remove_passwords.resize(20, 20)
        self.remove_passwords.clicked.connect(self.add_or_sub)

        self.amount_of_pass = QtWidgets.QLabel(self)
        self.amount_of_pass.setText('Add amount of passwords')
        self.amount_of_pass.setFont(QFont('Times', 10))
        self.amount_of_pass.move(375, 80)
        self.amount_of_pass.resize(250, 40)

        # submit password with attrubites
        self.submit_password = QtWidgets.QPushButton(self)
        self.submit_password.setText("Get Passwords")
        self.submit_password.move(375, 165)
        self.submit_password.resize(150, 40)
        self.submit_password.clicked.connect(self.submit)

        #slide down for information
        self.slider = QSlider(Qt.Vertical, self)
        self.slider.valueChanged.connect(self.updateLabel)
        self.slider.resize(30, 75)
        self.slider.move(515, 250)
        self.slider.setInvertedAppearance(True)
        self.slider.setDisabled(True)

        #display passwords
        self.display_passwords = QtWidgets.QLabel(self)
        self.display_passwords.setFont(QFont('Times', 10))
        self.display_passwords.setText('')
        self.display_passwords.move(375, 230)

    def add_or_sub(self):
        sender = self.sender()
        if sender.objectName() == "length_of_password":
            if sender.text() == self.remove_passwords.text():
                if int(self.length_of_password.text()) != 0:
                    self.length_of_password.setText(
                        str(int(self.length_of_password.text()) - 1))
            else:
                self.length_of_password.setText(
                    str(int(self.length_of_password.text()) + 1))
        else:
            if sender.text() == self.remove_passwords.text():
                if int(self.amount_of_passwords.text()) != 0:
                    self.amount_of_passwords.setText(
                        str(int(self.amount_of_passwords.text()) - 1))
            else:
                self.amount_of_passwords.setText(
                    str(int(self.amount_of_passwords.text()) + 1))

    def submit(self):
        if int(self.length_of_password.text()) != 0 and int(
                self.amount_of_passwords.text()) != 0:
            minmal_len = 0
            amount_of_passwords = int(self.amount_of_passwords.text())
            lenght_of_password = int(self.length_of_password.text())
            if self.checkbox1.isChecked() == True:
                self.password_attributes.append(self.speical_chacathers)
                minmal_len += 1
            if self.checkbox2.isChecked() == True:
                self.password_attributes.append(self.caps_letters)
                minmal_len += 1

            if self.checkbox3.isChecked() == True:
                self.password_attributes.append(self.letters)
                minmal_len += 1

            if self.checkbox4.isChecked() == True:
                self.password_attributes.append(self.numbers)
                minmal_len += 1

            if self.checkbox5.isChecked() == True:
                self.password_attributes.append(self.math_symbols)
                minmal_len += 1

            if int(self.length_of_password.text()) < minmal_len:
                QMessageBox.about(
                    self, "Problem",
                    "Your password is not long enough for the attributes that you want"
                )
                self.password_attributes = []
            if minmal_len == 0:
                QMessageBox.about(self, "Problem",
                                  "Make sure you have atleast one attribute")
            else:
                for passwords in range(0, amount_of_passwords):
                    password = ''
                    must_have = [x for x in range(0, minmal_len)]
                    random.shuffle(must_have)
                    for letters in range(0, lenght_of_password):
                        if len(must_have) != 0:
                            password += random.choice(
                                self.password_attributes[must_have[0]])
                            must_have.pop(0)
                        else:
                            password += random.choice(
                                random.choice(self.password_attributes))
                    password = list(password)
                    random.shuffle(password)
                    self.passwords.append("".join(password))
                print(self.passwords)
                self.slider.setDisabled(False)
                self.slider.setRange(0, len(self.passwords))
                self.display_passwords.setText('\n'.join(self.passwords[0:5]))
                self.display_passwords.adjustSize()
                if len(self.passwords) <= 5:
                    self.slider.hide()
                else:
                    self.slider.setRange(5, len(self.passwords))
        else:
            QMessageBox.about(
                self, "Problem",
                "Make sure you have a password that is atleast 1 character and atleast 1 password"
            )

    def updateLabel(self, value):
        value = self.slider.value()
        self.display_passwords.setText('\n'.join(self.passwords[value -
                                                                5:value]))
    def createLayout1(self):
        vboxlayoutPlot = QVBoxLayout()
        vboxlayoutData = QVBoxLayout()
        self.groupBoxPlot = QGroupBox("Plotting")
        self.groupBoxData = QGroupBox("Data")
        self.create_plot()
        vboxlayoutPlot.addLayout(self.layout)

        self.gridPlot = QGridLayout()
        self.gridData = QGridLayout()

        self.slider = QSlider(QTC.Horizontal)
        self.slider.setFocusPolicy(QTC.StrongFocus)
        self.slider.setTickPosition(QSlider.TicksBothSides)
        self.slider.setTickInterval(1)
        self.slider.setSingleStep(1)
        self.slider.setMaximum(10)
        self.slider.setMinimum(0)
        # self.slider.valueChanged.connect(self.SliderVal)
        self.slider.setValue(7)

        self.cb = QtWidgets.QComboBox()
        # self.cb.addItem("10")
        self.cb.addItems(["5", "2", "1"])
        self.cb.setCurrentIndex(2)
        self.cb.currentIndexChanged.connect(self.ComboInterval)

        self.Refr = QHBoxLayout()
        self.labelInterval = QLabel()
        self.labelInterval.setText("Refresh rate (s)")

        self.Refr.addWidget(self.labelInterval)
        self.Refr.addWidget(self.cb)

        # Error box START
        self.hboxErrSourceDt = QHBoxLayout()
        self.ErrorGroup = QGroupBox("Errors")
        self.vboxErrBox = QVBoxLayout()
        self.hboxErrLEDLBL = QHBoxLayout()
        self.hboxErrorEvents = QHBoxLayout()
        self.hboxErrorEvents.setSizeConstraint(QLayout.SetFixedSize)

        self.LEDError = QPushButton()  # used as error LED indicator
        self.LEDError.setEnabled(False)
        self.LEDError.setMaximumHeight(15)
        self.LEDError.setMaximumWidth(15)

        self.labelErrorRead = QLabel()
        self.labelErrorRead.setText("Error reading data")

        self.label_ErrorReadEvents = QLabel()
        self.label_ErrorReadEvents.setFont(QtGui.QFont("Sanserif", 10))
        self.label_ErrorReadEvents.setMinimumWidth(200)

        scrollErrors = QScrollArea()
        scrollErrors.setWidget(self.label_ErrorReadEvents)
        scrollErrors.setWidgetResizable(True)
        # scrollErrors.setMaximumHeight(80)
        scrollErrors.setMinimumWidth(200)

        self.hboxErrLEDLBL.addWidget(self.LEDError)
        self.hboxErrLEDLBL.addWidget(self.labelErrorRead)
        self.vboxErrBox.addLayout(self.hboxErrLEDLBL)
        self.vboxErrBox.addWidget(scrollErrors)
        self.ErrorGroup.setLayout(self.vboxErrBox)

        self.cbDataSource = QtWidgets.QComboBox()
        # self.cb.addItem("10")
        self.cbDataSource.addItems(
            ["Random generated test Data", "Remote data"])
        self.cbDataSource.setCurrentIndex(1)

        self.hboxErrSourceDt.addWidget(self.ErrorGroup)
        self.hboxErrSourceDt.addWidget(self.cbDataSource)
        # Error box END

        self.GetDataBtn = QPushButton("Start Plot")
        self.GetDataBtn.clicked.connect(self.ticker)
        self.GetDataBtn.setMinimumHeight(50)
        self.GetDataBtn.setMinimumWidth(180)

        self.gridPlot.addWidget(self.slider, 0, 0)
        self.gridPlot.addLayout(self.Refr, 1, 0)

        self.gridData.addLayout(self.hboxErrSourceDt, 0, 0)
        self.gridData.addWidget(self.GetDataBtn, 0, 1)

        vboxlayoutPlot.addLayout(self.gridPlot)
        self.groupBoxPlot.setLayout(vboxlayoutPlot)

        vboxlayoutData.addLayout(self.gridData)
        self.groupBoxData.setLayout(vboxlayoutData)