Exemplo n.º 1
0
    def dial(self, func=None, X=200, Y=200, radius=50, wrap=False):
        knob = QDial(self)
        knob.move(X, Y)
        knob.resize(radius, radius)
        knob.setWrapping(wrap)

        if func is not None:
            func
        # TODO:something something show number in a box nearby

        return knob
Exemplo n.º 2
0
class MouseTracker(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
        self.setMouseTracking(True)

    def initUI(self):
        self.setGeometry(300, 300, 700, 700)
        self.setWindowTitle('Mouse Tracker')
        self.label = QLabel(self)
        self.label.resize(200, 40)
        self.label.move(100, 40)

        self.laabel = QLabel(self)
        self.laabel.resize(200, 40)
        self.laabel.move(200, 300)

        self.laabel1 = QLabel(self)
        self.laabel1.resize(200, 40)
        self.laabel1.move(300, 100)

        self.dial = QDial(self)
        self.dial.move(xmove - 50, ymove - 50)
        self.dial.setValue(30)
        self.dial.resize(100, 100)
        self.dial.setWrapping(True)
        self.dial.setMinimum(0)
        self.dial.setMaximum(360)
        self.show()

    def mouseMoveEvent(self, event):
        x = event.x()
        y = event.y()
        if x < xmove and y < ymove: q = 1
        elif x > xmove and y < ymove: q = 2
        elif x > xmove and y > ymove: q = 3
        elif x < xmove and y > ymove: q = 4
        self.label.setText('Mouse coords: ( %d : %d )' % (x, y))
        if y != ymove and x != xmove:
            a = math.degrees(
                math.atan((ymove - event.y()) / (xmove - event.x())))
            if q == 1: a = a
            elif q == 2: a = 180 + a
            elif q == 3: a = 180 + a
            elif q == 4: a = a
        else:
            if x < xmove and y == ymove: a = 0
            elif x == xmove and y < ymove: a = 90
            elif x > xmove and y == ymove: a = 180
            elif x == xmove and y > ymove: a = 270

        self.dial.setValue(int(a) + 90)
        self.laabel1.setText(str(a))
Exemplo n.º 3
0
class ServoControls(QGroupBox):

    valueChanged = pyqtSignal(int)

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

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

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

        self.lcd_display = QLCDNumber()
        self.lcd_display.display(22)

        self.slider.valueChanged.connect(self.dial.setValue)
        self.dial.valueChanged.connect(self.lcd_display.display)
        self.dial.valueChanged.connect(self.slider.setValue)
        self.dial.valueChanged.connect(self.valueChanged)

        boxLayout = QBoxLayout(QBoxLayout.TopToBottom)
        boxLayout.addWidget(self.slider)
        boxLayout.addWidget(self.dial)
        boxLayout.addWidget(self.lcd_display)
        boxLayout.setStretchFactor(self.dial, 20)
        self.setLayout(boxLayout)

        self.setMinimum(0)
        self.setMaximum(100)
        self.dial.setWrapping(True)

    # This shit isnt even getting called
    def setValue(self, value):
        print("Slider Value: " + str(value))
        self.slider.setValue(value)
        self.dial.setValue(value)
        self.lcd_display.display(value)

    def setMinimum(self, value):
        self.slider.setMinimum(value)
        self.dial.setMinimum(value)

    def setMaximum(self, value):
        self.slider.setMaximum(value)
        self.dial.setMaximum(value)
Exemplo n.º 4
0
class MyWindow(QWidget):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.initGUI("PyQt5 学习 QDial")

        mainLayout = QGridLayout()
        self.setLayout(mainLayout)

        self.dial = QDial()
        self.dial.setMinimum(0)
        self.dial.setMaximum(100)
        self.dial.setValue(50)
        # 最好不要启用 setNotchTarget(),因为默认样式就挺好的
        # self.dial.setNotchTarget(10)
        self.dial.setNotchesVisible(True)
        self.dial.setWrapping(False)

        self.dial.sliderPressed.connect(self.on_slider_pressed_func)
        self.dial.sliderReleased.connect(self.on_slider_released_func)
        self.dial.sliderMoved.connect(self.on_slider_moved_func)
        self.dial.valueChanged.connect(self.on_value_changed)

        mainLayout.addWidget(self.dial, 0, 0, 1, 1)

    def on_slider_pressed_func(self):
        print("Dial --- Pressed")

    def on_slider_released_func(self):
        print("Dial --- Released @ %d" % (self.dial.value()))

    def on_slider_moved_func(self, value):
        print("Dial move to value = %d" % (value))

    def on_value_changed(self):
        print("Current dial value: %i" % (self.dial.value()))

    def initGUI(self, title):
        """
        设置窗口大小和位置,以及标题
        """
        startx = 800
        starty = 400
        width = 480
        height = 320
        self.setGeometry(startx, starty, width, height)
        self.setWindowTitle(title)
Exemplo n.º 5
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1871, 1200)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.transformsGroupBox = QGroupBox(self.centralwidget)
        self.transformsGroupBox.setGeometry(QRect(1500, 170, 240, 500))
        self.transformsGroupBox.setMaximumSize(QSize(240, 600))
        font = QFont()
        font.setFamily("MS Shell Dlg 2")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.transformsGroupBox.setFont(font)
        self.transformsGroupBox.setToolTip("")
        self.transformsGroupBox.setWhatsThis("")
        self.transformsGroupBox.setObjectName("transformsGroupBox")
        self.edgesButton = QPushButton(self.transformsGroupBox)
        self.edgesButton.setGeometry(QRect(110, 180, 120, 30))
        self.edgesButton.setObjectName("edgesButton")
        self.brightnessButton = QPushButton(self.transformsGroupBox)
        self.brightnessButton.setGeometry(QRect(110, 20, 120, 30))
        font = QFont()
        font.setPointSize(8)
        self.brightnessButton.setFont(font)
        self.brightnessButton.setObjectName("brightnessButton")
        self.getSizeButton = QPushButton(self.transformsGroupBox)
        self.getSizeButton.setGeometry(QRect(0, 470, 75, 23))
        self.getSizeButton.setObjectName("getSizeButton")
        self.paramsGroupBox = QGroupBox(self.transformsGroupBox)
        self.paramsGroupBox.setGeometry(QRect(10, 29, 91, 321))
        font = QFont()
        font.setPointSize(8)
        self.paramsGroupBox.setFont(font)
        self.paramsGroupBox.setObjectName("paramsGroupBox")
        self.leftSlider = QSlider(self.paramsGroupBox)
        self.leftSlider.setGeometry(QRect(10, 50, 20, 240))
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.leftSlider.sizePolicy().hasHeightForWidth())
        self.leftSlider.setSizePolicy(sizePolicy)
        self.leftSlider.setOrientation(Qt.Vertical)
        self.leftSlider.setTickPosition(QSlider.TicksAbove)
        self.leftSlider.setObjectName("leftSlider")
        self.rightSlider = QSlider(self.paramsGroupBox)
        self.rightSlider.setGeometry(QRect(50, 50, 20, 240))
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.rightSlider.sizePolicy().hasHeightForWidth())
        self.rightSlider.setSizePolicy(sizePolicy)
        self.rightSlider.setOrientation(Qt.Vertical)
        self.rightSlider.setTickPosition(QSlider.TicksAbove)
        self.rightSlider.setObjectName("rightSlider")
        self.leftLabel = QLabel(self.paramsGroupBox)
        self.leftLabel.setGeometry(QRect(10, 20, 20, 15))
        self.leftLabel.setTextFormat(Qt.PlainText)
        self.leftLabel.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
        self.leftLabel.setObjectName("leftLabel")
        self.rightLabel = QLabel(self.paramsGroupBox)
        self.rightLabel.setGeometry(QRect(50, 20, 20, 15))
        self.rightLabel.setTextFormat(Qt.PlainText)
        self.rightLabel.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
        self.rightLabel.setObjectName("rightLabel")
        self.adaptiveThresholdButton = QPushButton(self.transformsGroupBox)
        self.adaptiveThresholdButton.setGeometry(QRect(110, 140, 120, 30))
        font = QFont()
        font.setPointSize(8)
        self.adaptiveThresholdButton.setFont(font)
        self.adaptiveThresholdButton.setObjectName("adaptiveThresholdButton")
        self.gray2colSelButton = QPushButton(self.transformsGroupBox)
        self.gray2colSelButton.setGeometry(QRect(110, 100, 120, 30))
        font = QFont()
        font.setPointSize(8)
        self.gray2colSelButton.setFont(font)
        self.gray2colSelButton.setObjectName("gray2colSelButton")
        self.gray2colAllButton = QPushButton(self.transformsGroupBox)
        self.gray2colAllButton.setGeometry(QRect(110, 60, 120, 30))
        font = QFont()
        font.setPointSize(8)
        self.gray2colAllButton.setFont(font)
        self.gray2colAllButton.setObjectName("gray2colAllButton")
        self.fftButton = QPushButton(self.transformsGroupBox)
        self.fftButton.setGeometry(QRect(110, 220, 120, 30))
        self.fftButton.setObjectName("fftButton")
        self.dftButton = QPushButton(self.transformsGroupBox)
        self.dftButton.setGeometry(QRect(110, 260, 120, 30))
        self.dftButton.setObjectName("dftButton")
        self.gaborButton = QPushButton(self.transformsGroupBox)
        self.gaborButton.setGeometry(QRect(110, 300, 120, 30))
        self.gaborButton.setObjectName("gaborButton")
        self.differenceButton = QPushButton(self.transformsGroupBox)
        self.differenceButton.setGeometry(QRect(110, 340, 120, 30))
        self.differenceButton.setObjectName("differenceButton")
        self.RGB2GrayButton = QPushButton(self.transformsGroupBox)
        self.RGB2GrayButton.setGeometry(QRect(110, 380, 120, 30))
        self.RGB2GrayButton.setObjectName("RGB2GrayButton")
        self.invertedCheckBox = QCheckBox(self.transformsGroupBox)
        self.invertedCheckBox.setGeometry(QRect(110, 430, 121, 17))
        self.invertedCheckBox.setObjectName("invertedCheckBox")
        self.angleDial = QDial(self.transformsGroupBox)
        self.angleDial.setGeometry(QRect(20, 360, 81, 64))
        self.angleDial.setMinimum(1)
        self.angleDial.setMaximum(4)
        self.angleDial.setPageStep(1)
        self.angleDial.setSliderPosition(1)
        self.angleDial.setWrapping(False)
        self.angleDial.setNotchesVisible(True)
        self.angleDial.setObjectName("angleDial")
        self.groupButtonsBox = QGroupBox(self.centralwidget)
        self.groupButtonsBox.setGeometry(QRect(1500, 730, 241, 141))
        self.groupButtonsBox.setMaximumSize(QSize(250, 600))
        font = QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.groupButtonsBox.setFont(font)
        self.groupButtonsBox.setObjectName("groupButtonsBox")
        self.addImgButton = QPushButton(self.groupButtonsBox)
        self.addImgButton.setGeometry(QRect(50, 20, 150, 30))
        palette = QPalette()
        brush = QBrush(QColor(180, 146, 66))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Active, QPalette.Button, brush)
        brush = QBrush(QColor(180, 146, 66))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Inactive, QPalette.Button, brush)
        brush = QBrush(QColor(180, 146, 66))
        brush.setStyle(Qt.SolidPattern)
        palette.setBrush(QPalette.Disabled, QPalette.Button, brush)
        self.addImgButton.setPalette(palette)
        font = QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.addImgButton.setFont(font)
        self.addImgButton.setObjectName("addImgButton")
        self.saveSceneImgButton = QPushButton(self.groupButtonsBox)
        self.saveSceneImgButton.setGeometry(QRect(50, 60, 150, 30))
        font = QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.saveSceneImgButton.setFont(font)
        self.saveSceneImgButton.setObjectName("saveSceneImgButton")
        self.saveImgButton = QPushButton(self.groupButtonsBox)
        self.saveImgButton.setGeometry(QRect(50, 100, 150, 30))
        font = QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        self.saveImgButton.setFont(font)
        self.saveImgButton.setObjectName("saveImgButton")
        self.graphicsView = QGraphicsView(self.centralwidget)
        self.graphicsView.setGeometry(QRect(10, 15, 1471, 900))
        self.graphicsView.setMaximumSize(QSize(4000, 3000))
        self.graphicsView.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.graphicsView.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.graphicsView.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
        self.graphicsView.setObjectName("graphicsView")
        self.scene = TransformScene()
        self.graphicsView.setScene(self.scene)
        self.scaleEditLabel = QLabel(self.centralwidget)
        self.scaleEditLabel.setGeometry(QRect(1500, 100, 47, 13))
        font = QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.scaleEditLabel.setFont(font)
        self.scaleEditLabel.setObjectName("scaleEditLabel")
        self.scaleBox = QDoubleSpinBox(self.centralwidget)
        self.scaleBox.setGeometry(QRect(1550, 100, 62, 22))
        font = QFont()
        font.setBold(True)
        font.setWeight(75)
        self.scaleBox.setFont(font)
        self.scaleBox.setMinimum(0.1)
        self.scaleBox.setMaximum(10.0)
        self.scaleBox.setSingleStep(0.1)
        self.scaleBox.setProperty("value", 0.5)
        self.scaleBox.setObjectName("scaleBox")
        self.infoLabel = QLabel(self.centralwidget)
        self.infoLabel.setGeometry(QRect(1499, 130, 230, 20))
        self.infoLabel.setFrameShape(QFrame.WinPanel)
        self.infoLabel.setText("")
        self.infoLabel.setAlignment(Qt.AlignCenter)
        self.infoLabel.setObjectName("infoLabel")
        self.infoLabel_2 = QLabel(self.centralwidget)
        self.infoLabel_2.setGeometry(QRect(1500, 20, 230, 20))
        font = QFont()
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.infoLabel_2.setFont(font)
        self.infoLabel_2.setFrameShape(QFrame.WinPanel)
        self.infoLabel_2.setText("")
        self.infoLabel_2.setAlignment(Qt.AlignCenter)
        self.infoLabel_2.setObjectName("infoLabel_2")
        self.infoLabel_3 = QLabel(self.centralwidget)
        self.infoLabel_3.setGeometry(QRect(1500, 60, 230, 20))
        font = QFont()
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.infoLabel_3.setFont(font)
        self.infoLabel_3.setFrameShape(QFrame.Box)
        self.infoLabel_3.setText("")
        self.infoLabel_3.setAlignment(Qt.AlignCenter)
        self.infoLabel_3.setObjectName("infoLabel_3")
        self.clearImgButton = QPushButton(self.centralwidget)
        self.clearImgButton.setGeometry(QRect(1550, 690, 150, 30))
        font = QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.clearImgButton.setFont(font)
        self.clearImgButton.setObjectName("clearImgButton")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setGeometry(QRect(0, 0, 1871, 21))
        self.menubar.setObjectName("menubar")
        self.menuHelp = QMenu(self.menubar)
        self.menuHelp.setObjectName("menuHelp")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.actionHelp = QAction(MainWindow)
        self.actionHelp.setObjectName("actionHelp")
        self.actionAbout = QAction(MainWindow)
        self.actionAbout.setObjectName("actionAbout")
        self.actionDefault_Values = QAction(MainWindow)
        self.actionDefault_Values.setObjectName("actionDefault_Values")
        self.menuHelp.addAction(self.actionHelp)
        self.menuHelp.addAction(self.actionAbout)
        self.menuHelp.addSeparator()
        self.menuHelp.addAction(self.actionDefault_Values)
        self.menubar.addAction(self.menuHelp.menuAction())

        self.retranslateUi(MainWindow)
        QMetaObject.connectSlotsByName(MainWindow)
        self.scene.file_signal.connect(on_file_signal)
        self.scene.info_signal.connect(on_info_signal)
        self.scene.sliders_reset_signal.connect(on_sliders_reset_signal)
        

    def retranslateUi(self, MainWindow):
        _translate = QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Green Monkey"))
        self.transformsGroupBox.setTitle(_translate("MainWindow", "Transformations"))
        self.edgesButton.setText(_translate("MainWindow", "Edges, Sobel"))
        self.brightnessButton.setToolTip(_translate("MainWindow", "You can change brightness with left slider and blur with rigt one."))
        self.brightnessButton.setWhatsThis(_translate("MainWindow", "You can change brightness with left slider and blur with rigt one."))
        self.brightnessButton.setText(_translate("MainWindow", "Brightness and Blur"))
        self.getSizeButton.setText(_translate("MainWindow", "get Size"))
        self.paramsGroupBox.setTitle(_translate("MainWindow", "Parameters"))
        self.leftSlider.setToolTip(_translate("MainWindow", "Adaptive Threshold\n"
"blockSize – Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on."))
        self.leftSlider.setWhatsThis(_translate("MainWindow", "Adaptive Threshold\n"
"blockSize – Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on."))
        self.rightSlider.setToolTip(_translate("MainWindow", "Adaptive Threshold\n"
"C – Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well."))
        self.rightSlider.setWhatsThis(_translate("MainWindow", "Adaptive Threshold\n"
"C – Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well."))
        self.leftLabel.setText(_translate("MainWindow", "0"))
        self.rightLabel.setText(_translate("MainWindow", "0"))
        self.adaptiveThresholdButton.setText(_translate("MainWindow", "Adaptive Threshold"))
        self.gray2colSelButton.setToolTip(_translate("MainWindow", "Gray scale 0..255 to color with selected method only.\n"
"Image is converted to gray and finally to color."))
        self.gray2colSelButton.setWhatsThis(_translate("MainWindow", "Gray scale 0..255 to color with selected method only.\n"
"Image is converted to gray and  and finally to color."))
        self.gray2colSelButton.setText(_translate("MainWindow", "Gray2Color Sel."))
        self.gray2colAllButton.setToolTip(_translate("MainWindow", "Gray scale 0..255 to color for all available methods.\n"
"Image resized as per scale window and then  is converted to gray and finally to color."))
        self.gray2colAllButton.setWhatsThis(_translate("MainWindow", "Gray scale 0..255 to color for all available methods.\n"
"Image resized as per scale window and then  is converted to gray and finally to color."))
        self.gray2colAllButton.setText(_translate("MainWindow", "Gray2Color All"))
        self.fftButton.setText(_translate("MainWindow", "FFT"))
        self.dftButton.setText(_translate("MainWindow", "DFT"))
        self.gaborButton.setToolTip(_translate("MainWindow", "Applies Gabor Filter"))
        self.gaborButton.setWhatsThis(_translate("MainWindow", "Applies Gabor Filter"))
        self.gaborButton.setText(_translate("MainWindow", "Gabor Filter"))
        self.differenceButton.setText(_translate("MainWindow", "Difference"))
        self.RGB2GrayButton.setText(_translate("MainWindow", "RGB to Gray"))
        self.invertedCheckBox.setText(_translate("MainWindow", "Inverted Image"))
        self.angleDial.setToolTip(_translate("MainWindow", "GABOR Filter - angle 1..4 ~ 1*np.pi/angle"))
        self.angleDial.setWhatsThis(_translate("MainWindow", "GABOR Filter - angle 1..4 ~ 1*np.pi/angle"))
        self.groupButtonsBox.setTitle(_translate("MainWindow", "Images"))
        self.addImgButton.setText(_translate("MainWindow", "Add Image(s)"))
        self.addImgButton.setShortcut(_translate("MainWindow", "Ctrl+A"))
        self.saveSceneImgButton.setText(_translate("MainWindow", "Save Scene as Image"))
        self.saveImgButton.setText(_translate("MainWindow", "Save Selected as Image"))
        self.scaleEditLabel.setText(_translate("MainWindow", "Scale:"))
        self.clearImgButton.setText(_translate("MainWindow", "Clear Image(s)"))
        self.menuHelp.setTitle(_translate("MainWindow", "Help"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))
        self.actionHelp.setText(_translate("MainWindow", "Help"))
        self.actionAbout.setText(_translate("MainWindow", "About"))
        self.actionDefault_Values.setText(_translate("MainWindow", "Default Values"))

        self.actionHelp.setShortcut('F1')
        self.actionHelp.setStatusTip('Help')  
        self.actionHelp.triggered.connect(self.showHelp)
        self.actionAbout.setStatusTip('About')  
        self.actionAbout.triggered.connect(self.showAbout)
        self.actionDefault_Values.setStatusTip('Default folders and other values')
        self.actionDefault_Values.triggered.connect(self.updateINI)
   
        self.addImgButton.clicked.connect(partial(self.scene.addImg))
        self.clearImgButton.clicked.connect(self.scene.dialogClearScene)
        self.saveSceneImgButton.clicked.connect(partial(self.scene.saveScene))
        self.saveImgButton.clicked.connect(partial(self.scene.saveImg))
        self.scaleBox.valueChanged.connect(self.onScaleBoxValueChanged)
        self.getSizeButton.clicked.connect(self.showSceneSize)
        self.brightnessButton.clicked.connect(self.startBrightnessAndBlur)
        self.gray2colAllButton.clicked.connect(self.startGray2colAllButton)
        self.gray2colSelButton.clicked.connect(self.startGray2colSelButton)
        self.adaptiveThresholdButton.clicked.connect(self.startAdaptiveThreshold)
        self.edgesButton.clicked.connect(self.startSobelXY)
        self.fftButton.clicked.connect(self.startFFT)
        self.dftButton.clicked.connect(self.startDFT)
        self.gaborButton.clicked.connect(self.startGabor)
        self.differenceButton.clicked.connect(self.startDifference)
        self.RGB2GrayButton.clicked.connect(self.starRGB2Gray)

        
 
        self.leftSlider.valueChanged['int'].connect(self. leftSliderChanged)
        self.rightSlider.valueChanged['int'].connect(self.rightSliderChanged)
        self.angleDial.valueChanged['int'].connect(self.angleDialChanged)
        
    def setStart(self):
        self.graphicsView.setAlignment(Qt.AlignLeft|Qt.AlignTop)
        self.scene.setSceneRect(0, 0, 0, 0)
        self.scene.imgScale = self.scaleBox.value()
        self.clearSliders()
        self.infoLabel.setText("")
        self.scene.cv2Images = {}
        self.transformsGroupBox.setEnabled(False)
        self.transformsGroupBox.setEnabled(False)
        self.invertedCheckBox.setChecked(False)

        
        
    def clearSliders(self):
        self.infoLabel_2.setText('')
        self.infoLabel_3.setText('')
        self.scene.currentTransform = 0
        self.leftSlider.setEnabled(False)
        self.leftSlider.setToolTip("")
        self.leftSlider.setWhatsThis("")
        self.leftSlider.setMaximum(99)
        self.leftSlider.setMinimum(0)
        self.leftSlider.setTickInterval(10)        
        self.leftSlider.setSingleStep(1)
        self.leftSlider.setTickPosition(11)

        self.rightSlider.setEnabled(False)
        self.rightSlider.setToolTip("")
        self.rightSlider.setWhatsThis("")
        self.rightSlider.setMaximum(99)
        self.rightSlider.setMinimum(0)
        self.rightSlider.setTickInterval(10)        
        self.rightSlider.setSingleStep(1)
        self.rightSlider.setTickPosition(0) 
        self.paramsGroupBox.setFlat(False)
        self.paramsGroupBox.setStyleSheet('QGroupBox * {color: black; font-weight: normal;}') 
        
        self.angleDial.setEnabled(False)
        self.angleDial.setToolTip(" ")
        self.angleDial.setWhatsThis("")



    def invertCheckBoxEvent(self, checked):
        self.scene.inverted = checked
               
    def showSceneSize(self):
        x = self.scene.sceneRect().width()
        y = self.scene.sceneRect().height()      
        self.infoLabel.setText(f'size: {x}x{y}, {self.scene.findSceneArea()}')

    def onScaleBoxValueChanged(self, val):
        self.scene.imgScale = val
          
    def startBrightnessAndBlur(self):
        self.scene.currentTransform = 1
        self.infoLabel_2.setText('Adaptive Threshold')      
        self.scene.currentBrightnessValue = 0
        self.scene.currentBlurValue = 0
        self.scene.transform1()

        self.infoLabel_2.setText('Brightness and Blur')
        self.scene.currentTransform = 1
        self.leftSlider.setEnabled(True)
        self.rightSlider.setEnabled(True)
        self.leftSlider.setToolTip("Change Brightness  -> 0 .. 99")
        self.leftSlider.setWhatsThis("Change Brightness  -> 0 .. 99")
        self.rightSlider.setToolTip("Change Blur  -> 0 .. 99")
        self.rightSlider.setWhatsThis("Change Blur  -> 0 .. 99")
        self.leftSlider.setMaximum(99)
        self.leftSlider.setMinimum(0)
        self.leftSlider.setTickInterval(10)        
        self.leftSlider.setSingleStep(1)
        self.leftSlider.setTickPosition(11)
        self.rightSlider.setMaximum(99)
        self.rightSlider.setMinimum(0)
        self.rightSlider.setTickInterval(10)        
        self.rightSlider.setSingleStep(1)
        self.rightSlider.setTickPosition(0) 
        self.paramsGroupBox.setFlat(True)
        self.paramsGroupBox.setStyleSheet('QGroupBox * {color: red; font-weight: bold;}')
        
    def startGray2colAllButton(self):
        self.infoLabel_2.setText('Gray to Color All Methods')
        self.scene.currentTransform = 2
        self.scene.transform2(1, 1)
        
    def startGray2colSelButton(self):
        self.scene.currentTransform = 3
        self.infoLabel_2.setText(' Gray to Color')
        self.scene.transform2(0, 1)   
    
    def startSobelXY(self):
        self.scene.currentTransform = 4
        self.infoLabel_2.setText('Edge Detection')
        self.scene.transform4()
 
    def startFFT(self):
        self.scene.currentTransform = 7
        self.infoLabel_2.setText('FFT')
        self.scene.transform7()
    
    def startDFT(self):
        self.scene.currentTransform = 6
        self.infoLabel_2.setText('DFT')
        self.scene.transform6()
        
    def startDenoising(self):
        self.scene.currentTransform = 8
        self.infoLabel_2.setText('Denoising')
        self.scene.transform8()
        
    def startDifference(self):
        self.scene.currentTransform = 9
        self.infoLabel_2.setText('Difference')
        self.scene.transform9()
        
    def starRGB2Gray(self):
        self.scene.currentTransform = 10
        #txt = self.infoLabel_2.text()
        self.infoLabel_2.setText('RGB to Gray')
        self.scene.transform10()
        
    def startAdaptiveThreshold(self):
        self.scene.currentTransform = 5
        self.infoLabel_2.setText('Adaptive Threshold')      
        self.scene.currentBlockSizeValue = 11
        self.scene.currentCValue = 5
        self.scene.transform5()

        self.leftSlider.setEnabled(True)
        self.rightSlider.setEnabled(True)
        self.leftSlider.setToolTip("Adaptive Threshold\n"
"blockSize – Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.")
        self.leftSlider.setWhatsThis("Adaptive Threshold\n"
"blockSize – Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.")
        self.rightSlider.setToolTip("Adaptive Threshold\n"
"C – Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.")
        self.rightSlider.setWhatsThis("Adaptive Threshold\n"
"C – Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.")
        self.leftSlider.setMaximum(16)
        self.leftSlider.setMinimum(1)
        self.leftSlider.setTickInterval(1)        
        self.leftSlider.setSingleStep(1)
        self.leftSlider.setTickPosition(11)
        self.rightSlider.setMaximum(20)
        self.rightSlider.setMinimum(-5)
        self.rightSlider.setTickInterval(1)        
        self.rightSlider.setSingleStep(1)
        self.rightSlider.setTickPosition(5)     
        self.paramsGroupBox.setFlat(True)
        self.paramsGroupBox.setStyleSheet('QGroupBox * {color: red; font-weight: bold;}')       

    def startGabor(self):
        self.scene.currentTransform = 8
        self.infoLabel_2.setText('Gabor Filter') 
        self.scene.currentKernelSizeValue = 10
        self.scene.currentSigmaValue = 10
        self.scene.thetaCurrentValue
        self.scene.transform8()
        self.angleDial.setEnabled(True)
        self.leftSlider.setEnabled(True)
        self.rightSlider.setEnabled(True)
        self.leftSlider.setToolTip("Gabor Filter\n"
                                  "kernelSize – Size of a kernel 1..50")
        self.leftSlider.setWhatsThis("Gabor Filter\n"
                                  "kernelSize – Size of a kernel")
        self.rightSlider.setToolTip("Gabor Filter\n"
                                  "Standard Deviation – 1..30")
        self.rightSlider.setWhatsThis("Gabor Filter\n"
                                  "Standard Deviation – 1..30")
        self.angleDial.setToolTip("GABOR Filter - angle 1..4 ~ 1*np.pi/angle")
        self.angleDial.setWhatsThis("GABOR Filter - angle 1..4 ~ 1*np.pi/angle")       
        self.leftSlider.setMaximum(50)
        self.leftSlider.setMinimum(1)
        self.leftSlider.setTickInterval(5)        
        self.leftSlider.setSingleStep(5)
        self.leftSlider.setTickPosition(10)
        self.rightSlider.setMaximum(30)
        self.rightSlider.setMinimum(1)
        self.rightSlider.setTickInterval(5)        
        self.rightSlider.setSingleStep(5)
        self.rightSlider.setTickPosition(10)     
        self.paramsGroupBox.setFlat(True)
        self.paramsGroupBox.setStyleSheet('QGroupBox * {color: red; font-weight: bold;}')       


    def leftSliderChanged(self, value):
        self.leftLabel.setText(str(value))
        if self.scene.currentTransform == 1:
            self.scene.currentBrightnessValue = value
        elif self.scene.currentTransform == 5:
            if value % 2 == 1:return 
            self.scene.currentBlockSizeValue = value
        elif self.scene.currentTransform == 8:
            self.scene.currentKernelSizeValue = value
        else:
            pass
        self.update()
                    
    def rightSliderChanged(self, value):
        self.rightLabel.setText(str(value))
        if self.scene.currentTransform == 1:
            self.scene.currentBlurValue = value
        elif self.scene.currentTransform == 5:
             self.scene.currentCValue = value
        elif self.scene.currentTransform == 8:
            self.scene.currentSigmaValue = value
        else:
            pass
        self.update()  

    def angleDialChanged(self, value): 
        if self.scene.currentTransform == 8:
            self.scene.thetaCurrentValue = value
        self.update()
           
    def update(self):
        if self.scene.currentTransform == 1:
            if len(self.scene.selectedItems()) > 0:
                self.scene.transform1()
        elif self.scene.currentTransform == 5:
            self.infoLabel_2.setText(f'Adaptive Threshold {self.scene.currentBlockSizeValue} {self.scene.currentCValue}')
            if len(self.scene.selectedItems()) > 0:
                self.scene.transform5()
        elif self.scene.currentTransform == 8:
            if len(self.scene.selectedItems()) > 0:
                self.scene.transform8()
        else:
            ...

    def updateINI(self):
        Dialog = QDialog()
        ui = Ui_INI_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        Dialog.exec_()
        self.readINI()
        
    def readINI(self):
        self.scene.source_dir = ''
        self.scene.result_dir = ''
        self.scene.color_map = '' 
        self.scene.scale = ''
        if os.path.exists("elilik.ini"):
            f = open("elilik.ini", "r")
            Lines = f.readlines()
            # Strips the newline character
            for line in Lines:
                l = line.strip()
                if "source_dir : " in l:
                    self.scene.source_dir = l.replace("source_dir : ","").strip()
                elif "result_dir : " in l:
                    self.scene.result_dir = l.replace("result_dir : ","").strip()  
                elif "color_map : " in l:
                     s = l.replace("color_map : ","").strip()
                     self.scene.color_map = s.split()
                elif "scale : " in l:
                    self.scene.scale = l.replace("scale : ","").strip()
                else:
                    ...

    def showHelp(self):
        help = showText(os.getcwd()+"/help.html") 
        help.exec_()
 
    def showAbout(self):
        about = showText(os.getcwd()+"/about.html")
        about.resize(280,250)
        about.exec_()
Exemplo n.º 6
0
class dial_4vent(QWidget):
    style ='''
    QDial
    {
        background-color: rgb(255,255,255);
        font: 15px Menlo;
        color: rgb(0, 0, 131);
        /*text-align: left;*/
    }
    QLabel {
        /*border: 1px solid white;*/
        border-radius: 5px;
        background-color:  rgb(172, 236, 217);
        font: 15px Verdana, sans-serif;
        color:  rgb(0, 0, 131);
        text-align: center;
    }
    '''
    def __init__(self, title, min, max, **kwargs):
        super().__init__()
        self.title = title
        self.min   = min;self.max = max; self.moved_cbs = []
        self.layout = QGridLayout()
        self.label0 = QLabel(self)
        self.label  = QLabel(self)
        self.dial   = QDial()
        self.bar    = _Bar(["#5e4fa2", "#3288bd", "#66c2a5", "#abdda4",
                            "#e6f598", "#ffffbf", "#fee08b", "#fdae61",
                            "#f46d43", "#d53e4f", "#9e0142"])
        #_Bar(20) for pink ["#49006a", "#7a0177", "#ae017e", "#dd3497", "#f768a1", "#fa9fb5", "#fcc5c0", "#fde0dd", "#fff7f3"]
        self.label0.setStyleSheet(self.style)
        self.dial.setStyleSheet(self.style)
        self.label.setStyleSheet(self.style)
        self.dial.setMinimum(self.min)
        self.dial.setMaximum(self.max)
        self.dial.setValue(self.max)
        self.dial.setNotchesVisible(True)
        self.dial.valueChanged.connect(self.slider_moved)
        self.dial.setWrapping(False)
        self.dial.setGeometry(QtCore.QRect(25,25,100,100))
        self.layout.addWidget(self.label0, 0, 0, 1, 1)
        self.layout.addWidget(self.dial,1,0,1,1)
        self.layout.addWidget(self.bar,1,1,1,1)
        self.layout.addWidget(self.label,2,0, 1, 1)
        self.setLayout(self.layout)
        self.label0.setText(self.title)
        self.label.setStyleSheet("font-family: Impact, Charcoal, sans-serif");
        self.label.setText(str(self.dial.value()))
        #self.dial.installEventFilter(self) ## disables person using mouse
        self.show()
        ## Bar related initalization
        self.add_slider_moved(self.bar._trigger_refresh)
        # Take NO feedback from click events on the meter.
        self.bar.installEventFilter(self)

    def __getattr__(self, name):
        if name in self.__dict__:
            return self[name]
        return getattr(self.dial, name)

    def eventFilter(self, source, event):
        if (source is self.dial and isinstance(event, (
            QtGui.QMouseEvent, QtGui.QWheelEvent, QtGui.QKeyEvent))):
            return True
        return QtGui.QWidget.eventFilter(self, source, event)

    def slider_moved(self):
        self.label.setText(str(self.dial.value()))
        for fn in self.moved_cbs:
            fn()
    def add_slider_moved(self, func):
        self.moved_cbs.append(func)

    def setColor(self, color):
        self.bar.steps = [color] * self.bar.n_steps
        self.bar.update()

    def setColors(self, colors):
        self.bar.n_steps = len(colors)
        self.bar.steps = colors
        self.bar.update()

    def setBarPadding(self, i):
        self.bar._padding = int(i)
        self.bar.update()

    def setBarSolidPercent(self, f):
        self.bar.bar_solid_percent = float(f)
        self.bar.update()

    def setBackgroundColor(self, color):
        self.bar._background_color = QtGui.QColor(color)
        self.bar.update()
Exemplo n.º 7
0
class ChromAbWidget(QWidget):
    def __init__(self, parent=None):
        super(ChromAbWidget, self).__init__(parent)

        self.maxD = 20
        self.deadZ = 5
        self.isShapeRadial = True
        self.isFalloffExp = True
        self.direction = 100
        self.interpolate = False
        self.numThreads = 4

        self.shapeInfo = QLabel("Shape and Direction:", self)
        self.shapeChoice = QButtonGroup(self)
        self.shapeBtn1 = QRadioButton("Radial")
        self.shapeBtn2 = QRadioButton("Linear")
        self.shapeChoice.addButton(self.shapeBtn1)
        self.shapeChoice.addButton(self.shapeBtn2)
        self.shapeBtn1.setChecked(True)
        self.shapeBtn1.pressed.connect(self.changeShape1)
        self.shapeBtn2.pressed.connect(self.changeShape2)

        self.theDial = QDial()
        self.theDial.setMinimum(0)
        self.theDial.setMaximum(359)
        self.theDial.setValue(100)
        self.theDial.setWrapping(True)
        self.theDial.valueChanged.connect(self.updateDial)

        self.maxInfo = QLabel("Max Displacement: 20px", self)
        self.maxDisplace = QSlider(Qt.Horizontal, self)
        self.maxDisplace.setRange(1, 300)
        self.maxDisplace.setValue(20)
        self.maxDisplace.valueChanged.connect(self.updateMax)

        self.falloffInfo = QLabel("Falloff:", self)
        self.falloffChoice = QButtonGroup(self)
        self.foBtn1 = QRadioButton("Exponential")
        self.foBtn2 = QRadioButton("Linear")
        self.falloffChoice.addButton(self.foBtn1)
        self.falloffChoice.addButton(self.foBtn2)
        self.foBtn1.setChecked(True)
        self.foBtn1.pressed.connect(self.changeFalloff1)
        self.foBtn2.pressed.connect(self.changeFalloff2)

        self.deadInfo = QLabel("Deadzone: 5%", self)
        self.deadzone = QSlider(Qt.Horizontal, self)
        self.deadzone.setRange(0, 100)
        self.deadzone.setValue(5)
        self.deadzone.valueChanged.connect(self.updateDead)

        self.biFilter = QCheckBox(
            "Bilinear Interpolation (slow, but smooths colors)", self)
        self.biFilter.stateChanged.connect(self.updateInterp)

        self.threadInfo = QLabel(
            "Number of Worker Threads (FOR ADVANCED USERS): 4", self)
        self.workThreads = QSlider(Qt.Horizontal, self)
        self.workThreads.setRange(1, 64)
        self.workThreads.setValue(4)
        self.workThreads.valueChanged.connect(self.updateThread)

        vbox = QVBoxLayout()
        vbox.addWidget(self.shapeInfo)
        vbox.addWidget(self.shapeBtn1)
        vbox.addWidget(self.shapeBtn2)
        vbox.addWidget(self.theDial)
        vbox.addWidget(self.maxInfo)
        vbox.addWidget(self.maxDisplace)
        vbox.addWidget(self.falloffInfo)
        vbox.addWidget(self.foBtn1)
        vbox.addWidget(self.foBtn2)
        vbox.addWidget(self.deadInfo)
        vbox.addWidget(self.deadzone)
        vbox.addWidget(self.biFilter)
        vbox.addWidget(self.threadInfo)
        vbox.addWidget(self.workThreads)

        self.setLayout(vbox)
        self.show()

    # Update labels and members
    def updateMax(self, value):
        self.maxInfo.setText("Max Displacement: " + str(value) + "px")
        self.maxD = value

    def updateDead(self, value):
        self.deadInfo.setText("Deadzone: " + str(value) + "%")
        self.deadZ = value

    def changeShape1(self):
        self.isShapeRadial = True

    def changeShape2(self):
        self.isShapeRadial = False

    def changeFalloff1(self):
        self.isFalloffExp = True

    def changeFalloff2(self):
        self.isFalloffExp = False

    def updateDial(self, value):
        self.direction = value

    def updateInterp(self, state):
        if state == Qt.Checked:
            self.interpolate = True
        else:
            self.interpolate = False

    def updateThread(self, value):
        self.threadInfo.setText(
            "Number of Worker Threads (FOR ADVANCED USERS): " + str(value))
        self.numThreads = value

    # Call into C library to process the image
    def applyFilter(self, imgData, imgSize):
        newData = create_string_buffer(imgSize[0] * imgSize[1] * 4)

        dll = LibHandler.GetSharedLibrary()
        dll.ApplyLinearAberration.argtypes = [
            c_longlong, c_longlong, LinearFilterData, Coords, c_void_p,
            c_void_p
        ]
        dll.ApplyRadialAberration.argtypes = [
            c_longlong, c_longlong, RadialFilterData, Coords, c_void_p,
            c_void_p
        ]

        imgCoords = Coords(imgSize[0], imgSize[1])
        # python makes it hard to get a pointer to existing buffers for some reason
        cimgData = c_char * len(imgData)
        threadPool = []
        interp = 0
        if self.interpolate:
            interp = 1
        if self.isShapeRadial:
            falloff = 0
            if self.isFalloffExp:
                falloff = 1
            filterSettings = RadialFilterData(self.maxD, self.deadZ, falloff,
                                              interp)
        else:
            filterSettings = LinearFilterData(self.maxD, self.direction,
                                              interp)
        idx = 0
        for i in range(self.numThreads):
            numPixels = (imgSize[0] * imgSize[1]) // self.numThreads
            if i == self.numThreads - 1:
                numPixels = (imgSize[0] * imgSize[1]
                             ) - idx  # Give the last thread the remainder
            if self.isShapeRadial:
                workerThread = Thread(target=dll.ApplyRadialAberration,
                                      args=(
                                          idx,
                                          numPixels,
                                          filterSettings,
                                          imgCoords,
                                          cimgData.from_buffer(imgData),
                                          byref(newData),
                                      ))
            else:
                workerThread = Thread(target=dll.ApplyLinearAberration,
                                      args=(
                                          idx,
                                          numPixels,
                                          filterSettings,
                                          imgCoords,
                                          cimgData.from_buffer(imgData),
                                          byref(newData),
                                      ))
            threadPool.append(workerThread)
            threadPool[i].start()
            idx += numPixels
        # Join threads to finish
        for i in range(self.numThreads):
            threadPool[i].join()
        return bytes(newData)
Exemplo n.º 8
0
class MainWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(0, 0, 1000, 800)
        self.setStyleSheet('background-color:rgb(0, 0, 0)')
        self.setWindowTitle("*****가야금을 연주해보자******")

        #Title text frame
        self.titleFrame = QFrame(self)
        self.titleFrame.setGeometry(QRect(0, 0, 800, 150))
        self.titleFrameLayout = QVBoxLayout(self.titleFrame)

        #set Title font
        self.font = QFont()
        self.font.setFamily("Source Code Pro")
        self.font.setPointSize(35)
        # self.font.setBold(True)
        # self.font.setItalic(True)

        self.l2 = QLabel(self)
        self.l2.setText("Press a Key\nTo Start Playing!")

        self.l2.setFont(self.font)
        self.l2.setStyleSheet('color : white')
        self.titleFrameLayout.addWidget(self.l2, 0, Qt.AlignHCenter)

        #set frame
        self.frame1 = QFrame(self)
        self.frame1.setGeometry(QRect(0, 150, 250, 650))
        # self.frame1.setStyleSheet('background-color:white')
        self.frame1Layout = QVBoxLayout(self.frame1)

        #add buttons for keys
        self.key1 = MyButton(1)
        self.key1.setText("Eb1  (1)")
        self.frame1Layout.addWidget(self.key1, 0, Qt.AlignHCenter)

        self.key2 = MyButton(2)
        self.key2.setText("F1    (2)")
        self.frame1Layout.addWidget(self.key2, 0, Qt.AlignHCenter)

        self.key3 = MyButton(3)
        self.key3.setText("Ab1  (3)")
        self.frame1Layout.addWidget(self.key3, 0, Qt.AlignHCenter)

        self.key4 = MyButton(4)
        self.key4.setText("Bb1  (4)")
        self.frame1Layout.addWidget(self.key4, 0, Qt.AlignHCenter)

        self.key5 = MyButton(5)
        self.key5.setText("Cb1  (5)")
        self.frame1Layout.addWidget(self.key5, 0, Qt.AlignHCenter)

        self.key6 = MyButton(6)
        self.key6.setText("Eb1  (6)")
        self.frame1Layout.addWidget(self.key6, 0, Qt.AlignHCenter)

        self.key7 = MyButton(7)
        self.key7.setText("F2    (7)")
        self.frame1Layout.addWidget(self.key7, 0, Qt.AlignHCenter)

        self.key8 = MyButton(8)
        self.key8.setText("Ab2  (8)")
        self.frame1Layout.addWidget(self.key8, 0, Qt.AlignHCenter)

        self.key9 = MyButton(9)
        self.key9.setText("Bb2  (9)")
        self.frame1Layout.addWidget(self.key9, 0, Qt.AlignHCenter)

        self.key10 = MyButton(10)
        self.key10.setText("C2    (0)")
        self.frame1Layout.addWidget(self.key10, 0, Qt.AlignHCenter)

        self.key11 = MyButton(11)
        self.key11.setText("Eb3   (-)")
        self.frame1Layout.addWidget(self.key11, 0, Qt.AlignHCenter)

        self.key12 = MyButton(12)
        self.key12.setText("F3    (+)")
        self.frame1Layout.addWidget(self.key12, 0, Qt.AlignHCenter)

        self.volumeUI()

    #     self.stringColor(bool)
    #
    # def stringColor(self, enabled):
    #
    #     self.pen1 = QPen()
    #     self.pen1.setColor(Qt.white)
    #     self.pen1.setWidth(2)
    #
    #     self.pen2 = QPen()
    #     self.pen2.setColor(Qt.red)
    #     self.pen2.setWidth(2)
    #
    #     self.pen = QPen()
    #     if enabled == True:
    #         self.pen = self.pen2
    #     else:
    #         self.pen = self.pen1

    def paintEvent(self, event):
        self.pen1 = QPen()
        self.pen1.setColor(Qt.white)
        self.pen1.setWidth(1)

        # self.pen2 = QPen()
        # self.pen2.setColor(Qt.red)
        # self.pen2.setWidth(2)
        p = QPainter(self)

        p.setPen(self.pen1)

        for i in range(12):
            p.drawEllipse(255 + 40 * i, 180 + 50 * i, 5, 40)
            p.drawLine(250, 200 + 50 * i, 700, 200 + 50 * i)

    def volumeUI(self):
        # Title text
        self.titleFrame2 = QFrame(self)
        self.titleFrame2.setGeometry(QRect(800, 0, 200, 150))
        self.titleFrame2.setStyleSheet('background-color:rgb(239, 49, 141)')
        self.titleFrame2Layout = QVBoxLayout(self.titleFrame2)

        self.l2 = QLabel()
        self.l2.setText("Adjust\nVolume.")
        self.l2.setFont(self.font)
        self.l2.setStyleSheet('color:black')
        self.titleFrame2Layout.addWidget(self.l2, 0, Qt.AlignHCenter)

        # frame3
        self.frame = QFrame(self)
        self.frame.setGeometry(QRect(800, 150, 200, 650))
        self.frame.setStyleSheet('background-color:rgb(239, 49, 141)')
        self.frameLayout = QVBoxLayout(self.frame)

        # VolumeDial
        self.volumeDial = QDial(self)
        self.volumeDial.setStyleSheet('background-color:white')
        self.volumeDial.setWrapping(True)
        self.frameLayout.addWidget(self.volumeDial)

        # VolumeBar
        self.volumeBar = QProgressBar(self)
        self.volumeBar.setProperty("value", 0)
        self.volumeBar.setOrientation(Qt.Vertical)
        self.frameLayout.addWidget(self.volumeBar, 0, Qt.AlignHCenter)

        # dial connect to bar
        self.volumeDial.valueChanged['int'].connect(self.volumeBar.setValue)
        self.volumeDial.setValue(10)

        # volume label
        self.l3 = QLabel()
        self.l3.setFont(self.font)
        self.l3.setText(str(self.volumeDial.value()))
        self.l3.setStyleSheet('color:black')
        self.frameLayout.addWidget(self.l3, 0, Qt.AlignHCenter)

        mixer.init()
        self.setChannel()

        for i in range(12):
            mixer.Channel(i).set_volume(0.1)

        # connect volume dial to sound volume
        self.volumeDial.valueChanged['int'].connect(self.setVolume)

    def setVolume(self, value):
        self.value = value
        for i in range(12):
            mixer.Channel(i).set_volume(self.value * 0.01)
            self.l3.setText(str(int(100 * mixer.Channel(i).get_volume())))
        return self.value

    # volume change with up, down key
    def upDownKeyEvent(self, event):
        if event.key() == Qt.Key_Up:
            self.volumeDial.valueChange(1)

        if event.key() == Qt.Key_Down:
            self.volumeDial.valueChange(-1)

    def setChannel(self):
        mixer.set_num_channels(12)

    def keyPressEvent(self, e):
        if e.key() == Qt.Key_1:
            mixer.Channel(0).play(mixer.Sound('Eb1_gayageum.wav'))
            print(mixer.Channel(0).get_volume())
            self.key1.setChecked(True)

        if e.key() == Qt.Key_2:
            mixer.Channel(1).play(mixer.Sound('F1_gayageum.wav'))
            print(mixer.Channel(1).get_volume())
            self.key2.setChecked(True)

        if e.key() == Qt.Key_3:
            mixer.Channel(2).play(mixer.Sound('Ab1_gayageum.wav'))
            print(mixer.Channel(2).get_volume())
            self.key3.setChecked(True)

        if e.key() == Qt.Key_4:
            mixer.Channel(3).play(mixer.Sound('Bb1_gayageum.wav'))
            print(mixer.Channel(3).get_volume())
            self.key4.setChecked(True)

        if e.key() == Qt.Key_5:
            mixer.Channel(4).play(mixer.Sound('C1_gayageum.wav'))
            print(mixer.Channel(4).get_volume())
            self.key5.setChecked(True)

        if e.key() == Qt.Key_6:
            mixer.Channel(5).play(mixer.Sound('Eb2_gayageum.wav'))
            print(mixer.Channel(5).get_volume())
            self.key6.setChecked(True)

        if e.key() == Qt.Key_7:
            mixer.Channel(6).play(mixer.Sound('F2_gayageum.wav'))
            print(mixer.Channel(6).get_volume())
            self.key7.setChecked(True)

        if e.key() == Qt.Key_8:
            mixer.Channel(7).play(mixer.Sound('Ab2_gayageum.wav'))
            print(mixer.Channel(7).get_volume())
            self.key8.setChecked(True)

        if e.key() == Qt.Key_9:
            mixer.Channel(8).play(mixer.Sound('Bb2_gayageum.wav'))
            print(mixer.Channel(8).get_volume())
            self.key9.setChecked(True)

        if e.key() == Qt.Key_0:
            mixer.Channel(9).play(mixer.Sound('C2_gayageum.wav'))
            print(mixer.Channel(9).get_volume())
            self.key10.setChecked(True)

        if e.key() == Qt.Key_Minus:
            mixer.Channel(10).play(mixer.Sound('Eb3_gayageum.wav'))
            print(mixer.Channel(10).get_volume())
            self.key11.setChecked(True)

        if e.key() == Qt.Key_Equal:
            mixer.Channel(11).play(mixer.Sound('F3_gayageum.wav'))
            print(mixer.Channel(11).get_volume())
            self.key12.setChecked(True)
class ChromAbWidget(QWidget):
    def __init__(self, parent=None):
        super(ChromAbWidget, self).__init__(parent)

        self.maxD = 0.01
        self.deadZ = 5
        self.isShapeRadial = True
        self.isFalloffExp = True
        self.direction = 100
        self.interpolate = False
        self.numThreads = 4

        self.shapeInfo = QLabel("Shape and Direction:", self)
        self.shapeChoice = QButtonGroup(self)
        self.shapeBtn1 = QRadioButton("Radial")
        self.shapeBtn2 = QRadioButton("Linear")
        self.shapeChoice.addButton(self.shapeBtn1)
        self.shapeChoice.addButton(self.shapeBtn2)
        self.shapeBtn1.setChecked(True)
        self.shapeBtn1.pressed.connect(self.changeShape1)
        self.shapeBtn2.pressed.connect(self.changeShape2)

        self.theDial = QDial()
        self.theDial.setMinimum(0)
        self.theDial.setMaximum(359)
        self.theDial.setValue(100)
        self.theDial.setWrapping(True)
        self.theDial.setEnabled(False)
        self.theDial.valueChanged.connect(self.updateDial)

        self.maxInfo = QLabel("Max Displacement: 1%", self)
        self.maxDisplace = QSlider(Qt.Horizontal, self)
        self.maxDisplace.setRange(1, 500)
        self.maxDisplace.setValue(10)
        self.maxDisplace.valueChanged.connect(self.updateMax)

        self.falloffInfo = QLabel("Falloff:", self)
        self.falloffChoice = QButtonGroup(self)
        self.foBtn1 = QRadioButton("Exponential")
        self.foBtn2 = QRadioButton("Linear")
        self.falloffChoice.addButton(self.foBtn1)
        self.falloffChoice.addButton(self.foBtn2)
        self.foBtn1.setChecked(True)
        self.foBtn1.pressed.connect(self.changeFalloff1)
        self.foBtn2.pressed.connect(self.changeFalloff2)

        self.deadInfo = QLabel("Deadzone: 5%", self)
        self.deadzone = QSlider(Qt.Horizontal, self)
        self.deadzone.setRange(0, 100)
        self.deadzone.setValue(5)
        self.deadzone.valueChanged.connect(self.updateDead)

        self.biFilter = QCheckBox(
            "Bilinear Interpolation (slow, but smooths colors)", self)
        self.biFilter.stateChanged.connect(self.updateInterp)

        self.threadInfo = QLabel(
            "Number of Worker Threads (FOR ADVANCED USERS): 4", self)
        self.workThreads = QSlider(Qt.Horizontal, self)
        self.workThreads.setRange(1, 64)
        self.workThreads.setValue(4)
        self.workThreads.valueChanged.connect(self.updateThread)

        vbox = QVBoxLayout()
        vbox.addWidget(self.shapeInfo)
        vbox.addWidget(self.shapeBtn1)
        vbox.addWidget(self.shapeBtn2)
        vbox.addWidget(self.theDial)
        vbox.addWidget(self.maxInfo)
        vbox.addWidget(self.maxDisplace)
        vbox.addWidget(self.falloffInfo)
        vbox.addWidget(self.foBtn1)
        vbox.addWidget(self.foBtn2)
        vbox.addWidget(self.deadInfo)
        vbox.addWidget(self.deadzone)
        vbox.addWidget(self.biFilter)
        vbox.addWidget(self.threadInfo)
        vbox.addWidget(self.workThreads)

        self.setLayout(vbox)
        self.show()

    # Update labels and members
    def updateMax(self, value):
        self.maxInfo.setText("Max Displacement: " + str(value / 10) + "%")
        self.maxD = value / 1000

    def updateDead(self, value):
        self.deadInfo.setText("Deadzone: " + str(value) + "%")
        self.deadZ = value

    def changeShape1(self):
        self.isShapeRadial = True
        # Change UI so only valid options can be changed
        self.theDial.setEnabled(False)
        self.theDial.repaint()
        self.foBtn1.setEnabled(True)
        self.foBtn1.repaint()
        self.foBtn2.setEnabled(True)
        self.foBtn2.repaint()
        self.deadzone.setEnabled(True)
        self.deadzone.repaint()

    def changeShape2(self):
        self.isShapeRadial = False
        # Change UI so only valid options can be changed
        self.theDial.setEnabled(True)
        self.theDial.repaint()
        self.foBtn1.setEnabled(False)
        self.foBtn1.repaint()
        self.foBtn2.setEnabled(False)
        self.foBtn2.repaint()
        self.deadzone.setEnabled(False)
        self.deadzone.repaint()

    def changeFalloff1(self):
        self.isFalloffExp = True

    def changeFalloff2(self):
        self.isFalloffExp = False

    def updateDial(self, value):
        self.direction = value

    def updateInterp(self, state):
        if state == Qt.Checked:
            self.interpolate = True
        else:
            self.interpolate = False

    def updateThread(self, value):
        self.threadInfo.setText(
            "Number of Worker Threads (FOR ADVANCED USERS): " + str(value))
        self.numThreads = value

    # Required for main window to call into
    def getWindowName(self):
        return "Chromatic Aberration"

    def saveSettings(self, settings):
        settings.setValue("CA_maxD", self.maxD * 1000)
        settings.setValue("CA_deadZ", self.deadZ)
        if self.isShapeRadial:
            shape = 1
        else:
            shape = 0
        settings.setValue("CA_isShapeRadial", shape)
        if self.isFalloffExp:
            falloff = 1
        else:
            falloff = 0
        settings.setValue("CA_isFalloffExp", falloff)
        settings.setValue("CA_direction", self.direction)
        if self.interpolate:
            interp = 1
        else:
            interp = 0
        settings.setValue("CA_interpolate", interp)
        settings.setValue("CA_numThreads", self.numThreads)

    def readSettings(self, settings):
        self.updateMax(int(settings.value("CA_maxD", 10)))
        self.updateDead(int(settings.value("CA_deadZ", 5)))
        shapeRadial = int(settings.value("CA_isShapeRadial", 1))
        if shapeRadial == 1:
            self.isShapeRadial = True
        else:
            self.isShapeRadial = False
        falloffExp = int(settings.value("CA_isFalloffExp", 1))
        if falloffExp == 1:
            self.isFalloffExp = True
        else:
            self.isFalloffExp = False
        self.direction = int(settings.value("CA_direction", 100))
        interp = int(settings.value("CA_interpolate", 0))
        if interp == 1:
            self.interpolate = True
        else:
            self.interpolate = False
        self.updateThread(int(settings.value("CA_numThreads", 4)))
        # Update interactable UI elements
        self.theDial.setValue(self.direction)
        self.shapeBtn1.setChecked(self.isShapeRadial)
        self.shapeBtn2.setChecked(not self.isShapeRadial)
        self.maxDisplace.setValue(int(self.maxD * 1000))
        self.foBtn1.setChecked(self.isFalloffExp)
        self.foBtn2.setChecked(not self.isFalloffExp)
        self.deadzone.setValue(self.deadZ)
        self.biFilter.setChecked(self.interpolate)
        self.workThreads.setValue(self.numThreads)
        if self.isShapeRadial:
            self.changeShape1()
        else:
            self.changeShape2()

    def getBlendMode(self):
        return "normal"

    # Call into C library to process the image
    def applyFilter(self, imgData, imgSize):
        newData = create_string_buffer(imgSize[0] * imgSize[1] * 4)
        dll = GetSharedLibrary()
        imgCoords = Coords(imgSize[0], imgSize[1])
        # python makes it hard to get a pointer to existing buffers for some reason
        cimgData = c_char * len(imgData)
        threadPool = []
        interp = 0
        if self.interpolate:
            interp = 1
        if self.isShapeRadial:
            falloff = 0
            if self.isFalloffExp:
                falloff = 1
            filterSettings = RadialFilterData(int(self.maxD * imgSize[0]),
                                              self.deadZ, falloff, interp)
        else:
            filterSettings = LinearFilterData(int(self.maxD * imgSize[0]),
                                              self.direction, interp)
        idx = 0
        for i in range(self.numThreads):
            numPixels = (imgSize[0] * imgSize[1]) // self.numThreads
            if i == self.numThreads - 1:
                numPixels = (imgSize[0] * imgSize[1]
                             ) - idx  # Give the last thread the remainder
            if self.isShapeRadial:
                workerThread = Thread(target=dll.VFXRadialAberration,
                                      args=(
                                          idx,
                                          numPixels,
                                          filterSettings,
                                          imgCoords,
                                          cimgData.from_buffer(imgData),
                                          byref(newData),
                                      ))
            else:
                workerThread = Thread(target=dll.VFXLinearAberration,
                                      args=(
                                          idx,
                                          numPixels,
                                          filterSettings,
                                          imgCoords,
                                          cimgData.from_buffer(imgData),
                                          byref(newData),
                                      ))
            threadPool.append(workerThread)
            threadPool[i].start()
            idx += numPixels
        # Join threads to finish
        # If a crash happens, it would freeze here. User can still cancel though
        for i in range(self.numThreads):
            threadPool[i].join()
        return bytes(newData)

    def postFilter(self, app, doc, node):
        pass
Exemplo n.º 10
0
class ChromAbWidget(QWidget):
    def __init__(self, parent=None):
        super(ChromAbWidget, self).__init__(parent)

        self.maxD = 20
        self.deadZ = 5
        self.isShapeRadial = True
        self.isFalloffExp = True
        self.direction = 100

        self.shapeInfo = QLabel("Shape and Direction:", self)
        self.shapeChoice = QButtonGroup(self)
        self.shapeBtn1 = QRadioButton("Radial")
        self.shapeBtn2 = QRadioButton("Linear")
        self.shapeChoice.addButton(self.shapeBtn1)
        self.shapeChoice.addButton(self.shapeBtn2)
        self.shapeBtn1.setChecked(True)
        self.shapeBtn1.pressed.connect(self.changeShape1)
        self.shapeBtn2.pressed.connect(self.changeShape2)

        self.theDial = QDial()
        self.theDial.setMinimum(0)
        self.theDial.setMaximum(359)
        self.theDial.setValue(100)
        self.theDial.setWrapping(True)
        self.theDial.valueChanged.connect(self.updateDial)

        self.maxInfo = QLabel("Max Displacement: 20px", self)
        self.maxDisplace = QSlider(Qt.Horizontal, self)
        self.maxDisplace.setRange(1, 300)
        self.maxDisplace.setValue(20)
        self.maxDisplace.valueChanged.connect(self.updateMax)

        self.falloffInfo = QLabel("Falloff:", self)
        self.falloffChoice = QButtonGroup(self)
        self.foBtn1 = QRadioButton("Exponential")
        self.foBtn2 = QRadioButton("Linear")
        self.falloffChoice.addButton(self.foBtn1)
        self.falloffChoice.addButton(self.foBtn2)
        self.foBtn1.setChecked(True)
        self.foBtn1.pressed.connect(self.changeFalloff1)
        self.foBtn2.pressed.connect(self.changeFalloff2)

        self.deadInfo = QLabel("Deadzone: 5%", self)
        self.deadzone = QSlider(Qt.Horizontal, self)
        self.deadzone.setRange(0, 100)
        self.deadzone.setValue(5)
        self.deadzone.valueChanged.connect(self.updateDead)

        vbox = QVBoxLayout()
        vbox.addWidget(self.shapeInfo)
        vbox.addWidget(self.shapeBtn1)
        vbox.addWidget(self.shapeBtn2)
        vbox.addWidget(self.theDial)
        vbox.addWidget(self.maxInfo)
        vbox.addWidget(self.maxDisplace)
        vbox.addWidget(self.falloffInfo)
        vbox.addWidget(self.foBtn1)
        vbox.addWidget(self.foBtn2)
        vbox.addWidget(self.deadInfo)
        vbox.addWidget(self.deadzone)

        self.setLayout(vbox)
        self.show()

    # Update labels and members
    def updateMax(self, value):
        self.maxInfo.setText("Max Displacement: " + str(value) + "px")
        self.maxD = value

    def updateDead(self, value):
        self.deadInfo.setText("Deadzone: " + str(value) + "%")
        self.deadZ = value

    def changeShape1(self):
        self.isShapeRadial = True

    def changeShape2(self):
        self.isShapeRadial = False

    def changeFalloff1(self):
        self.isFalloffExp = True

    def changeFalloff2(self):
        self.isFalloffExp = False

    def updateDial(self, value):
        self.direction = value

    # Return the new color of the pixel at the specified index
    def applyOnePixel(self, coords, imgData, imgSize):
        baseColor = getColorAtIndex((coords[1] * imgSize[0]) + coords[0],
                                    imgData)
        # linear direction is easy
        if not self.isShapeRadial:
            displace = [
                -1 * math.sin(math.radians(self.direction)),
                math.cos(math.radians(self.direction))
            ]
            displace = scaleVect(displace, self.maxD)
        else:
            # get direction vector
            floatDeadzone = self.deadZ / 100
            center = ((imgSize[0] - 1) / 2, (imgSize[1] - 1) / 2)
            displace = addVect(coords, scaleVect(center, -1))
            # normalize, length of displace will be [0,1]
            displace = scaleVect(displace, 1 / lenVect(center))
            # if inside the deadzone, return original color
            if lenVect(displace) <= floatDeadzone:
                return baseColor
            else:
                # scale vector to 0 at the edge of deadzone, 1 at edge of screen
                displace = scaleVect(displace,
                                     (lenVect(displace) - floatDeadzone) *
                                     (1 / (1 - floatDeadzone)))
                # use exponential falloff
                if self.isFalloffExp:
                    displace = scaleVect(displace, lenVect(displace))
                # scale vector to final length based on max displacement
                displace = scaleVect(displace, self.maxD)
        # blend original green channel with blue and red from other pixels
        redChannel = sampleAt(addVect(coords, displace), imgData, imgSize)
        blueChannel = sampleAt(addVect(coords, scaleVect(displace, -1)),
                               imgData, imgSize)
        return [redChannel[0], baseColor[1], blueChannel[2], baseColor[3]]

    # Iterate over the image applying the filter
    def applyFilter(self, imgData, imgSize):
        newData = []
        idx = 0
        while idx < imgData.length():
            # convert to x,y coordinates
            coords = ((idx / 4) % imgSize[0], (idx / 4) // imgSize[0])
            newPixel = self.applyOnePixel(coords, imgData, imgSize)
            for i in range(4):
                # truncate to int
                newData.append(int(newPixel[i]))
            idx += 4
        return bytes(newData)
Exemplo n.º 11
0
class GuiWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(GuiWidget, self).__init__(parent=parent)
        layoutV1 = QtGui.QVBoxLayout()

        self.setWindowTitle('CCD_High_Speed_50Hz')

        #
        ################################################################################
        #
        #    Show input text function
        #
        self.label_Com_device = QtGui.QLabel('COM-device')
        self.label_Com_device.setStyleSheet('color: red')
        self.label_Com_device.setFont(
            QtGui.QFont("Arial", 14, QtGui.QFont.Black))
        self.lineEdit_Com_device = QtGui.QLineEdit(configs.port)

        #self.Spin
        self.Connect = QtGui.QPushButton('CONNECT')
        #self.Connect.setStyleSheet('''border-image:url("C:/Users/ceo/Desktop/CCD_High_Speed_50Hz/COM.jpg");''')
        #self.button = QPushButton("Start Progressbar")
        self.Connect.setStyleSheet("background-color:rgb(192,192,192)")

        self.label_start_time = QtGui.QLabel(
            'T num: min 7296 <=======> 7500 max')
        self.label_start_time.setStyleSheet('color: red')
        self.label_start_time.setFont(
            QtGui.QFont("Arial", 10, QtGui.QFont.Black))

        self.lineEdit_Com_device = QtGui.QLineEdit(configs.port)

        #self.lineEdit_Start_time = QtGui.QLineEdit(str(configs.t_Num))
        self.lineEdit_Start_time = QtGui.QSlider(Qt.Horizontal)
        self.lineEdit_Start_time.setMinimum(int(
            configs.t_Num))  # value is 7296
        self.lineEdit_Start_time.setMaximum(int(
            configs.t_Num_max))  # value max is  7500
        self.lineEdit_Start_time.setValue(10)
        self.lineEdit_Start_time.setTickPosition(QtGui.QSlider.TicksBelow)
        self.lineEdit_Start_time.setTickInterval(0.05)

        self.label_Lower_limit_value = QtGui.QLabel(
            'Lower limit value is from: 0')
        self.label_Lower_limit_value.setStyleSheet('color: red')
        self.label_Lower_limit_value.setFont(
            QtGui.QFont("Arial", 10, QtGui.QFont.Black))

        self.lineEdit_Lower_limit_value = QtGui.QSlider(Qt.Horizontal)
        self.lineEdit_Lower_limit_value.setMinimum(int(
            configs.lowLimVal))  # value is 0
        self.lineEdit_Lower_limit_value.setMaximum(int(
            configs.upperLimVal))  # value max is  21
        self.lineEdit_Lower_limit_value.setValue(0)
        self.lineEdit_Lower_limit_value.setTickPosition(
            QtGui.QSlider.TicksBelow)
        self.lineEdit_Lower_limit_value.setTickInterval(0.05)

        self.label_Upper_limit_value = QtGui.QLabel(
            'Upper limit value is from: 21')
        self.label_Upper_limit_value.setStyleSheet('color: red')
        self.label_Upper_limit_value.setFont(
            QtGui.QFont("Arial", 10, QtGui.QFont.Black))
        #self.lineEdit_Upper_limit_value = QtGui.QLineEdit(str(configs.upperLimVal))
        self.lineEdit_Upper_limit_value = QtGui.QSlider(Qt.Horizontal)
        self.lineEdit_Upper_limit_value.setMinimum(int(
            configs.upperLimVal))  # value is 21
        self.lineEdit_Upper_limit_value.setMaximum(31)
        self.lineEdit_Upper_limit_value.setValue(0)
        self.lineEdit_Upper_limit_value.setTickPosition(
            QtGui.QSlider.TicksBelow)
        self.lineEdit_Upper_limit_value.setTickInterval(0.05)

        ############################# Qdial #################################
        self.label = QtGui.QLabel(self)
        self.label.setFont(QtGui.QFont("Sanserif", 15))
        self.dial = QDial()
        self.dial.setMaximum(0)
        self.dial.setMaximum(100)
        self.dial.setValue(30)
        self.dial.setWrapping(True)
        self.dial.valueChanged.connect(self.dialer_changed)

        self.Update = QtGui.QPushButton('Update')
        self.Update.setStyleSheet("background-color:rgb(255,255,153)")

        self.StopBtn = QtGui.QPushButton('STOP')
        self.StopBtn.setStyleSheet("background-color:rgb(255,0,0)")
        #self.button_save = QtGui.QPushButton('SAVE to CSV')

        self.label_image = QtGui.QLabel()

        layoutV1.addSpacing(40)
        layoutV1.addWidget(self.label_Com_device)
        layoutV1.addWidget(self.lineEdit_Com_device)
        layoutV1.addSpacing(10)
        layoutV1.addWidget(self.Connect)
        layoutV1.addSpacing(30)
        layoutV1.addWidget(self.label_start_time)
        layoutV1.addWidget(self.lineEdit_Start_time)
        layoutV1.addSpacing(10)

        layoutV1.addWidget(self.label_Lower_limit_value)
        layoutV1.addWidget(self.lineEdit_Lower_limit_value)
        layoutV1.addSpacing(10)

        layoutV1.addWidget(self.label_Upper_limit_value)
        layoutV1.addWidget(self.lineEdit_Upper_limit_value)
        layoutV1.addSpacing(50)
        layoutV1.addWidget(self.dial)
        layoutV1.addWidget(self.label)
        layoutV1.addSpacing(20)
        layoutV1.addWidget(self.Update)
        layoutV1.addWidget(self.StopBtn)
        layoutV1.addSpacing(30)

        layoutV1.addSpacing(100)
        layoutV1.addWidget(self.label_image)
        layoutV1.addStretch(10)

        #
        ################################################################################
        #
        #   Graph Show function
        #

        layoutH2 = QtGui.QHBoxLayout()
        self.plot1 = pg.PlotWidget(title="CCD 50Hz plot")
        self.plot2 = pg.PlotWidget(title="CCD 50Hz_filter plot")
        self.plot3 = pg.PlotWidget(title="CCD 50Hz Pixel plot")

        #self.plot4 = pg.GraphicsWindow(title="Basic plotting examples")
        #self.plot4.setWindowTitle

        layoutH2.addWidget(self.plot1)
        layoutH2.addWidget(self.plot2)
        layoutH2.addWidget(self.plot3)

        #layoutH3 = QtGui.QHBoxLayout()
        #self.plot4 = pg.PlotWidget(title="Time_Data filtered Frequency Weighting")
        #self.plot5 = pg.PlotWidget(title="Equal Sensation Curves of Vertical Whole-Body Vibration(Comfort limit)")
        #self.plot6 = pg.PlotWidget(title="VDV curve according to vibration duration")
        #layoutH3.addWidget(self.plot4)
        #layoutH3.addWidget(self.plot5)
        #layoutH3.addWidget(self.plot6)

        layoutV2 = QtGui.QVBoxLayout()
        layoutV2.addLayout(layoutH2)
        #layoutV2.addLayout(layoutH3)

        layout = QtGui.QHBoxLayout()
        layout.addLayout(layoutV1)
        layout.addLayout(layoutV2)

        layout.setStretchFactor(layoutV1, 0)
        ################### graph layout #################
        layout.setStretchFactor(layoutV2, 1)
        self.setLayout(layout)

    def dialer_changed(self):
        getValue = self.dial.value()
        self.label.setText(" Dialer Value : " + str(getValue))
Exemplo n.º 12
0
class controll_class(QWidget):
    dataControl = QtCore.pyqtSignal(list, float, int)                           
    
    def __init__(self, parent):                                                 
        super(QWidget, self).__init__(parent)
        parent.send_control_init.connect(self.controlInit)                      
        
        self.setMaximumSize(195, 240)                                           
        self.control_layoutV = QVBoxLayout(self)                                
        self.controlLayout()                                                    
        self.setLayout(self.control_layoutV)                                    
            
    def controlLayout(self):                                                    
        self.control_tabs = QTabWidget() 
        
        self.tab_contr1 = QWidget()                                             
        self.tab_contr2 = QWidget()                                             
        self.tab_contr3 = QWidget()                                             
        
        
        tab_contr1_layout = QFormLayout()
        tab_contr2_layout = QGridLayout()
        tab_contr3_layout = QFormLayout()
        check_axis_layout = QHBoxLayout()
    
        
        self.list1   = ["x", "y", "z", "α", "v"]                                
        self.change1 = 3                                                        
        self.spin1   = []                                                       
        
        for i in range(len(self.list1)):
            self.spin1.append(i)                                                
            self.spin1[i] = QDoubleSpinBox()                                    
            self.spin1[i].setRange    (-9999,9999)                              
            self.spin1[i].setDecimals (1)                                       
            if    i < self.change1: 
                self.spin1[i].setSuffix(' mm')                                  
            elif i == self.change1:
                self.spin1[i].setSuffix(' °')                                   
                self.spin1[i].setRange (-151, 151)                              
            else:                
                self.spin1[i].setSuffix(' %')                                   
                self.spin1[i].setValue (10)                                     
                self.spin1[i].setRange (0, 100) 
                self.spin1[2].setRange (-9999, -1)                              
                                 
            tab_contr1_layout.addRow(self.list1[i] + ":", self.spin1[i])        
                
        butt_save = QPushButton("Write")                                        
        butt_save.clicked.connect(self.click_butt_save)                         
        tab_contr1_layout.addRow(butt_save)                                     
    
        
        self.spin2_step = QDoubleSpinBox()                                      
        self.spin2_step.setRange     (0,5)                                      
        self.spin2_step.setDecimals  (1  )  
        self.spin2_step.setSingleStep(0.1)
        self.spin2_step.setValue     (1.0)
        self.spin2_step.setSuffix    (' mm')
        tab_contr2_layout.addWidget(QLabel("Step:"), 0, 0)                      
        tab_contr2_layout.addWidget(self.spin2_step, 0, 1, 1, 2)                
        
        self.label2 = ["x", "y", "z", "α"]                                      
        self.butt2  = []                                                        
        self.button2_Group = QButtonGroup()                                     
        self.button2_Group.buttonClicked[int].connect(self.click_butt_xyz)      
        
        for i in range(int(len(self.label2)*2)):                                
            self.butt2.append(i)                                                
            if(i%2): self.butt2[i] = QPushButton("+" + self.label2[int(i/2)])   
            else:    self.butt2[i] = QPushButton("-" + self.label2[int(i/2)])   
            self.butt2[i].setMaximumWidth (50)                                  
            self.butt2[i].setMinimumHeight(25)                                  
            self.button2_Group.addButton(self.butt2[i], i+1)                    
        
        for i in range(len(self.label2)):                                       
            tab_contr2_layout.addWidget(QLabel(self.label2[i] + ":"), i+1, 0)
            tab_contr2_layout.addWidget(self.butt2[i*2],              i+1, 1)
            tab_contr2_layout.addWidget(self.butt2[i*2+1],            i+1, 2)
        
        
        self.spin3_step = QDoubleSpinBox()                                      
        self.spin3_step.setDecimals  (1)                                        
        self.spin3_step.setRange     (0,2)
        self.spin3_step.setSingleStep(0.1)
        self.spin3_step.setValue     (1.0)
        self.spin3_step.setSuffix    (' mm')
        
        self.radioLabel = ["x:", "y:", "z:", "α"]                               
        self.radio = []                                                         
        
        for i in range(len(self.radioLabel)):                                   
            self.radio.append(i)
            self.radio[i] = QRadioButton(self.radioLabel[i])
            check_axis_layout.addWidget(self.radio[i])
            
        self.radio[0].setChecked(True)                                          
        
        self.spin_dial = QDoubleSpinBox()                                       
        self.spin_dial.setRange    (-9999,9999)                                 
        self.dial = QDial() 
        self.dial.setMinimumSize   (120,120)                                    
        self.dial.setValue         (0)                                          
        self.dial.setWrapping      (True)                                       
        self.dial.setNotchesVisible(True)                                       
        self.dial.valueChanged.connect(self.dail_loop)                          
        self.dial.valueChanged.connect(self.spin_dial.setValue)                 
        
        tab_contr3_layout.addRow(QLabel("Step:"),self.spin3_step)               
        tab_contr3_layout.addRow(check_axis_layout)                
        tab_contr3_layout.addRow(self.dial)
        
        self.tab_contr1.setLayout(tab_contr1_layout)                                      
        self.tab_contr2.setLayout(tab_contr2_layout)                       
        self.tab_contr3.setLayout(tab_contr3_layout)                            
        
        self.control_tabs.addTab(self.tab_contr1,"Tab 1")                            
        self.control_tabs.addTab(self.tab_contr2,"Tab 2")                     
        self.control_tabs.addTab(self.tab_contr3,"Tab 3")
        
        self.button_home = QPushButton("Home")
        self.button_home.setMinimumHeight(20)
        self.button_home.clicked.connect(self.click_butt_home)
        self.button_home.setStyleSheet('color: black; background-color: yellow;') 
        
        self.button_home_set = QPushButton("")
        self.button_home_set.setMinimumHeight(20)
        self.button_home_set.setIcon(QIcon('settings_icon.png'))
        self.button_home_set.setIconSize(QSize(16,16))
        self.button_home_set.clicked.connect(self.click_butt_home_set)
        
        self.buttol_layout = QHBoxLayout(self)
        self.buttol_layout.addWidget(self.button_home) 
        self.buttol_layout.addWidget(self.button_home_set) 
        self.control_layoutV.addWidget(self.control_tabs)                       
        self.control_layoutV.addLayout(self.buttol_layout)
        
        self.daialValue1 = 0                                                    
        self.daialValue2 = 0                                                    
        self.home_x      = 0
        self.home_y      = 0
        self.home_z      = -100
        self.control_tabs.currentChanged.connect(self.Tabs_number)
        self.click_butt_home()

    def controlInit(self, dataInit, angle):
        self.spin1[0].setValue(dataInit[0])                                     
        self.spin1[1].setValue(dataInit[1])
        self.spin1[2].setValue(dataInit[2])
        self.spin1[3].setValue(angle)
        
    def Tabs_number(self):                                                      
        if self.control_tabs.currentIndex() == 2:
            self.button_home.hide()
            self.button_home_set.hide()
        else:
            self.button_home.show()
            self.button_home_set.show()
       
    def click_butt_home(self):                                                  
        self.spin1[0].setValue(self.home_x)                                     
        self.spin1[1].setValue(self.home_y)
        self.spin1[2].setValue(self.home_z)
        self.spin1[3].setValue(0)
        self.dataEmit()        

    def click_butt_home_set(self):                                              
        x, okPressed = QInputDialog.getDouble(self, "Home","cooordinate X:", self.home_x, -1000, 0, 2)
        if okPressed:
            self.home_x = x  
        y, okPressed = QInputDialog.getDouble(self, "Home","cooordinate Y:", self.home_y, -1000, 0, 2)
        if okPressed:
            self.home_y = y  
        z, okPressed = QInputDialog.getDouble(self, "Home","cooordinate Z:", self.home_z, -1000, 0, 2)
        if okPressed:
            self.home_z = z  

    def click_butt_save(self):                                                  
        self.dataEmit()                                                         
        
    def click_butt_xyz(self, i):                                                
        self.butt2[i-1].setAutoRepeat        (True)                             
        self.butt2[i-1].setAutoRepeatDelay   (70)                               
        self.butt2[i-1].setAutoRepeatInterval(70)                               
        if  (i == 1): self.spin1[i-1].setValue(self.spin1[i-1].value() - self.spin2_step.value())
        elif(i == 2): self.spin1[i-2].setValue(self.spin1[i-2].value() + self.spin2_step.value())
        elif(i == 3): self.spin1[i-2].setValue(self.spin1[i-2].value() - self.spin2_step.value())
        elif(i == 4): self.spin1[i-3].setValue(self.spin1[i-3].value() + self.spin2_step.value())
        elif(i == 5): self.spin1[i-3].setValue(self.spin1[i-3].value() - self.spin2_step.value())
        elif(i == 6): self.spin1[i-4].setValue(self.spin1[i-4].value() + self.spin2_step.value())
        elif(i == 7): self.spin1[i-4].setValue(self.spin1[i-4].value() - self.spin2_step.value())
        elif(i == 8): self.spin1[i-5].setValue(self.spin1[i-5].value() + self.spin2_step.value())
        
        self.dataEmit()                                                         
            
    def dail_loop(self):                                                        
        self.daialValue1 = self.spin_dial.value()  
        if self.daialValue1 > self.daialValue2:
            for i in range(len(self.radio)):
                if  (self.radio[i].isChecked()): self.spin1[i].setValue(self.spin1[i].value() + self.spin3_step.value())
        else:
            for i in range(len(self.radio)):
                if  (self.radio[i].isChecked()): self.spin1[i].setValue(self.spin1[i].value() - self.spin3_step.value())
  
        self.daialValue2 = self.daialValue1
        self.dataEmit()  
                                                               
    def dataEmit(self):
        dataSend = [self.spin1[0].value(),self.spin1[1].value(), self.spin1[2].value()]        
        self.dataControl.emit(dataSend, self.spin1[3].value(), self.spin1[4].value()) 
Exemplo n.º 13
0
class MouseTracker(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 700, 700)
        self.setWindowTitle('Mouse Tracker')
        self.label = QLabel(self)
        self.label.resize(200, 40)
        self.label.move(100, 40)
        self.setMouseTracking(True)

        self.laabel = QLabel(self)
        self.laabel.resize(200, 40)
        self.laabel.move(200, 300)

        self.laabel1 = QLabel(self)
        self.laabel1.resize(200, 40)
        self.laabel1.move(300, 100)

        self.dial1 = QDial(self)
        self.dial1.move(X1, Y1)
        self.dial1.resize(100, 100)
        self.dial1.setWrapping(True)
        self.dial1.setMinimum(0)
        self.dial1.setMaximum(360)

        self.dial2 = QDial(self)
        self.dial2.move(X2, Y2)
        self.dial2.resize(100, 100)
        self.dial2.setWrapping(True)
        self.dial2.setMinimum(0)
        self.dial2.setMaximum(360)

        self.show()

    def mouseMoveEvent(self, event):
        x = event.x()
        y = event.y()
        if x < (X1 + xshift1) and y < (Y1 + yshift1): q = 1
        elif x > (X1 + xshift1) and y < (Y1 + yshift1): q = 2
        elif x > (X1 + xshift1) and y > (Y1 + yshift1): q = 3
        elif x < (X1 + xshift1) and y > (Y1 + yshift1): q = 4
        self.label.setText('Mouse coords: ( %d : %d )' % (x, y))
        if y != (Y1 + yshift1) and x != (X1 + xshift1):
            a = math.degrees(
                math.atan(((Y1 + yshift1) - y) / ((X1 + xshift1) - x)))
            if q == 1: a = a
            elif q == 2: a = 180 + a
            elif q == 3: a = 180 + a
            elif q == 4: a = a
        else:
            if x < (X1 + xshift1) and y == (Y1 + yshift1): a = 0
            elif x == (X1 + xshift1) and y < (Y1 + yshift1): a = 90
            elif x > (X1 + xshift1) and y == (Y1 + yshift1): a = 180
            elif x == (X1 + xshift1) and y > (Y1 + yshift1): a = 270

        x = event.x()
        y = event.x()
        q2 = 0
        b = 0
        if x < (X2 + xshift2) and y < (Y2 + yshift2): q2 = 1
        elif x > (X2 + xshift2) and y < (Y2 + yshift2): q2 = 2
        elif x > (X2 + xshift2) and y > (Y2 + yshift2): q2 = 3
        elif x < (X2 + xshift2) and y > (Y2 + yshift2): q2 = 4
        self.label.setText('Mouse coords: ( %d : %d )' % (x, y))
        if (y - 150) != (Y2 + yshift2) and (x - 150) != (X2 + xshift2):
            b = math.degrees(
                math.atan(((Y2 + yshift2) - (y - 150)) / ((X2 + xshift2) -
                                                          (x - 150))))
            if q2 == 1: b = b
            elif q2 == 2: b = 180 + b
            elif q2 == 3: b = 180 + b
            elif q2 == 4: b = b
        else:
            if x < (X2 + xshift2) and y == (Y2 + yshift2): b = 0
            elif x == (X2 + xshift2) and y < (Y2 + yshift2): b = 90
            elif x > (X2 + xshift2) and y == (Y2 + yshift2): b = 180
            elif x == (X2 + xshift2) and y > (Y2 + yshift2): b = 270

        self.dial1.setValue(int(a) + 90)
        self.dial2.setValue(int(b) + 90)
        self.laabel1.setText(str(a))