class MyWindow(QWidget): def __init__(self): super().__init__() self.uiInit() def uiInit(self): self.value = 0 self.dial = QDial(self) self.dial.move(0, 100) self.dial.setRange(0, 9999) self.dial.setNotchesVisible(True) self.lcd = QLCDNumber(self) self.setGeometry(300, 300, 300, 300) self.setWindowTitle('来来来') # self.dial.valueChanged.connect(self.lcd.display) self.show() def mousePressEvent(self, e): self.value += 1 print(self.value) self.lcd.display(self.value)
def group4(window): groupbox = QGroupBox("Group 3") groupbox.setCheckable(True) groupbox.setChecked(True) input = QLineEdit("firmanslur", window) input.setEchoMode(QLineEdit.Password) spin = QSpinBox(window) spin.setValue(50) tanggal = QDateTimeEdit(window) tanggal.setDateTime(QDateTime.currentDateTime()) slider = QSlider(Qt.Horizontal, window) slider.setValue(50) scrollBar = QScrollBar(Qt.Horizontal, window) scrollBar.setValue(60) dial = QDial(window) dial.setValue(30) dial.setNotchesVisible(True) layout = QGridLayout() layout.addWidget(input, 0, 0, 1, 2) layout.addWidget(spin, 1, 0, 1, 2) layout.addWidget(tanggal, 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) groupbox.setLayout(layout) return groupbox
def createTopRightGroupBox(self): self.topRightGroupBox = QGroupBox("Group 2") togglePushButton = QPushButton("Toggle Push Button") togglePushButton.setCheckable(True) togglePushButton.setChecked(True) slider = QSlider(Qt.Horizontal, self.RadiiScaleGroupBox) slider.setValue(40) scrollBar = QScrollBar(Qt.Horizontal, self.RadiiScaleGroupBox) scrollBar.setValue(60) dial = QDial(self.RadiiScaleGroupBox) dial.setValue(30) dial.setNotchesVisible(True) layout = QVBoxLayout() layout.addWidget(self.openFileNameButton) layout.addWidget(togglePushButton) layout.addWidget(self.flatPushButton) layout.addWidget(slider) layout.addWidget(scrollBar) layout.addWidget(dial) layout.addStretch(1) self.topRightGroupBox.setLayout(layout)
def createBottomRightGroupBox(self): self.bottomRightGroupBox = QGroupBox("Audio Speed") lineEdit = QLineEdit('s3cRe7') lineEdit.setEchoMode(QLineEdit.Password) spinBox = QSpinBox(self.bottomRightGroupBox) spinBox.setValue(50) 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(spinBox, 1, 0, 1, 2) layout.addWidget(slider, 3, 0) layout.addWidget(scrollBar, 4, 0) layout.addWidget(dial, 3, 1, 2, 1) self.bottomRightGroupBox.setLayout(layout)
class Form(QWidget): def __init__(self, width=200, height=400): super().__init__() self.dial = QDial() self.dial.setNotchesVisible(True) self.spinbox = QSpinBox() self.width = width self.height = height self.picture = QLabel() self.pixmap1 = QPixmap("../images/chualar_sign.jpg") self.pixmap2 = QPixmap("../images/bit.jpg") self.picture.setPixmap(self.pixmap1) layout = QGridLayout() layout.addWidget(self.picture, 0, 0) layout.addWidget(self.dial, 1, 0) layout.addWidget(self.spinbox, 1, 1) self.setLayout(layout) self.setGeometry(100, 100, self.width, self.height) self.setWindowTitle("Signals and Slots") self.dial.valueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.dial.setValue) def set_size(self, width, height): self.width = width self.height = height self.setGeometry(100, 100, self.width, self.height) def change_pix(self): self.picture.setPixmap(self.pixmap2)
def createEditor(self, parent, option, index): editor = QDial(parent=parent) editor.setRange(-5, 5) editor.setNotchesVisible(True) editor.setAutoFillBackground(True) return editor
class Demo(QWidget): def __init__(self): super(Demo, self).__init__() # setWindowTitle()方法可以设置窗口标题; self.setWindowTitle('QDial') # 1 self.dial = QDial(self) # 实例化一个QDial控件后,通过setFixedSize()方法来固定QDial的大小 # 如果不设置该方法的话,我们会发现在改变表盘数值时,表盘的大小会发生改变; self.dial.setFixedSize(100, 100) # 2 # 使用setRange()方法来设置表盘数值范围, # 当然也可以使用setMinimum()和setMaximum()方法; self.dial.setRange(0, 100) # 3 # setNotchesVisible(True)可以显示刻度,刻度会根据我们设置的数值自动调整; self.dial.setNotchesVisible(True) # 4 # 当改变表盘数值时,会触发valueChanged信号,在槽函数中我们让QLabel显示出当前表盘数值。 self.dial.valueChanged.connect(self.on_change_func) # 5 self.label = QLabel('0', self) self.label.setFont(QFont('Arial Black', 0)) self.h_layout = QHBoxLayout() self.h_layout.addWidget(self.dial) self.h_layout.addWidget(self.label) self.setLayout(self.h_layout) def on_change_func(self): self.label.setText(str(self.dial.value())) self.label.setFont(QFont('Arial Black', (int(self.dial.value()) + 10)))
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)
class MainWindow(QMainWindow): def __init__(self): super().__init__() # 윈도우 설정 self.setGeometry(200, 100, 300, 300) # x, y, w, h self.setWindowTitle('삼인성호') # QSliter 추가 self.dial = QDial(self) self.dial.move(10, 10) self.dial.setFixedSize(100, 100) self.dial.setRange(0, 100) self.dial.setMinimum(1) self.dial.setMaximum(24) self.dial.setNotchesVisible(True) self.dial.valueChanged.connect(self.value_changed) # QSlider 데이터를 표시할 라벨 self.label = QLabel(self) self.label.setGeometry(10, 120, 200, 100) self.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.label.setStyleSheet("border-radius: 5px;" "border: 1px solid gray;" "background-color: #ffffff") # 슬라이드 시그널 valueChanged 연결 함수 def value_changed(self, value): self.label.setText(str(value) + "시") self.label.setFont(QtGui.QFont("Malgun Gothic", 40)) #폰트,크기 조절
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)
def createEditor(self, parent, option, index): editor = QDial(parent=parent) editor.setRange(-5, 5) editor.setNotchesVisible(True) editor.setAutoFillBackground(True) return editor
class MainWindow(QWidget): """Setup GUI window""" def __init__(self, width=200, height=400): super().__init__() # store object variables/attributes self.my_width = width self.my_height = height # create dial widget object self.dial = QDial() self.dial.setNotchesVisible(True) self.spinbox = QSpinBox() # create pixmap widget object (as part of a Qlabel widget) self.picture = QLabel() self.pixmap1 = QPixmap("../images/chualar_sign.jpg") self.pixmap2 = QPixmap("../images/bit.jpg") self.picture.setPixmap(self.pixmap1) # create button widget object self.button = QPushButton("Apply", self) # create a layout and place all of our elements layout = QGridLayout() layout.addWidget(self.picture, 0, 0) #layout.setColumnStretch(0, 1) layout.addWidget(self.dial, 1, 0) layout.addWidget(self.spinbox, 2, 0) layout.addWidget(self.button, 1, 1) #layout.setRowStretch(1, 1) # add our layout to the window self.setLayout(layout) self.setGeometry(100, 100, self.my_width, self.my_height) self.setWindowTitle("Photo Adjustment") # link dial and form self.dial.valueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.dial.setValue) # add listener to button click self.button.clicked.connect(self.on_click) @pyqtSlot() def on_click(self): print("Clicked") def set_size(self, width, height): self.width = width self.height = height self.setGeometry(100, 100, self.width, self.height) def change_pix(self): self.picture.setPixmap(self.pixmap2)
class TimerGB(QGroupBox): grab_timeout = pyqtSignal() gb_closed = pyqtSignal() def __init__(self, boxwidth, boxheight, parent=None): super(TimerGB, self).__init__(parent) QGroupBox("Set Interval") self.resize(boxwidth, boxheight) self.setWindowTitle("Timer") self.setFlat(True) self.timer_dial = QDial() self.timer_dial.setNotchesVisible(True) self.timer_dial.setMinimum(1) self.timer_dial.setMaximum(30) self.timer_dial.setValue(15) self.timer_dial.valueChanged.connect(self.on_dial_new_value) self.timer_dial.sliderReleased.connect(self.on_dial_released) self.value_display = QLabel() self.gbvlayout = QVBoxLayout() self.gbvlayout.addWidget(self.value_display) self.gbvlayout.addWidget(self.timer_dial) self.setLayout(self.gbvlayout) self.value_display.setText(str(self.timer_dial.value()) + " s") self.grab_timer = QTimer() def on_dial_new_value(self): self.value_display.setText(str(self.timer_dial.value()) + " s") def on_dial_released(self): self.timer_rate = self.timer_dial.value() #print("Timer rate is ", self.timer_rate) self.grab_timer = QTimer() # self.grab_timer.timeout.connect(self.on_grab_button) self.grab_timer.timeout.connect(self.on_grab_timer_timeout) self.grab_timer.start(self.timer_rate * 1000.0) def on_grab_timer_timeout(self): self.grab_timeout.emit() def closeEvent(self, event): self.gb_closed.emit() def get_width(self): return self.width() def get_height(self): return self.height()
class Form(QWidget): def __init__(self): super().__init__() self.dial = QDial() self.dial.setNotchesVisible(True) self.spinbox = QSpinBox() layout = QHBoxLayout() layout.addWidget(self.dial) layout.addWidget(self.spinbox) self.setLayout(layout) self.setWindowTitle("Signals and Slots") self.dial.valueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.dial.setValue)
class DialWidget(QWidget): valueChanged = pyqtSignal(float) def __init__(self, manometer: AnalogItemType, parent=None): super().__init__(parent=parent) self.setFont(QFont('Segoi UI', FONT_SIZE)) self.setFixedWidth(DIAL_WIDTH) self.setFixedHeight(DIAL_HEIGHT) self.vbox = QVBoxLayout() self.vbox.setContentsMargins(0, 0, 0, 0) self.setLayout(self.vbox) self.caption = QLabel(manometer.name) self.caption.setFont(QFont('Segoi UI', FONT_SIZE)) self.caption.setAlignment(Qt.AlignCenter) self.vbox.addWidget(self.caption) self.dial = QDial() self.vbox.addWidget(self.dial) self.dial.setMinimum(0) self.dial.setMaximum(round(manometer.eu_range.high * 100)) self.dial.setValue(0) self.dial.setNotchTarget(2) self.dial.setNotchesVisible(True) self.spin_box = QDoubleSpinBox() self.vbox.addWidget(self.spin_box) self.spin_box.setMinimum(0) self.spin_box.setMaximum(manometer.eu_range.high) self.spin_box.setValue(0) self.spin_box.setDecimals(2) self.spin_box.setSingleStep(0.01) self.spin_box.valueChanged.connect(self.on_spin_box_value_changed) self.dial.valueChanged.connect(self.on_dial_value_changed) self.valueChanged.connect(manometer.set_value) @pyqtSlot(float) def on_spin_box_value_changed(self, value: float): v = round(value * 100) self.dial.setValue(v) self.emit_signal(value) @pyqtSlot(int) def on_dial_value_changed(self, value: int): v = value / 100 self.spin_box.setValue(v) self.emit_signal(v) def emit_signal(self, value: float): value_ofset = value - self.spin_box.minimum() value_range = self.spin_box.maximum() - self.spin_box.minimum() value_percent = value_ofset / value_range signal = round(value_percent * 16000 + 4000) self.valueChanged.emit(signal)
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)
def __init__(self, parent=None): super(Form, self).__init__(parent) dial = QDial() dial.setNotchesVisible(True) spinbox = QSpinBox() layout = QHBoxLayout() layout.addWidget(dial) layout.addWidget(spinbox) self.setLayout(layout) dial.valueChanged.connect(spinbox.setValue) spinbox.valueChanged.connect(dial.setValue) self.setWindowTitle("Signals abd Slots")
def createBottomRightGroupBox(self): '''Create a checkable group widget useful in the case of form login etc''' self.bottomRightGroupBox = QGroupBox("Group 3") self.bottomRightGroupBox.setCheckable( True) # sets the state aware mode self.bottomRightGroupBox.setChecked( True) # sets the default state to active # # create the required widgets # a lineEdit Widget for password entry. Activate the security by setEchoMode() # a spinBox Widget which lets the field change using scroll # a Date Time Edit Widget # a Slider Widget responsive to scroll as well as press and move # a Scroll Widget responsive to scroll as well as press and move # a Dial Widget responsive to scroll as well as press and move # lineEdit = QLineEdit('s3cRe7') lineEdit.setEchoMode(QLineEdit.Password) spinBox = QSpinBox(self.bottomRightGroupBox) spinBox.setValue(25) 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) # # create the internal layout of the group Widget # layout = QGridLayout() layout.addWidget(lineEdit, 0, 0, 1, 3) 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, 2) layout.setRowStretch(50, 1) # ?? whatdoes RowStretch do? self.bottomRightGroupBox.setLayout(layout)
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)
def initUI(self): dial = QDial() dial.setNotchesVisible(True) spinBox = QSpinBox() layout = QHBoxLayout() layout.addWidget(dial) layout.addWidget(spinBox) self.setLayout(layout) # 无论是QDial还是QSpinBox都有valueChanged信号 # 将这两个的信号和setValue之间进行连接,构成了相互影响的两个不减 # 无论是哪个控件的值发生变化都会影响到另外一个部件。 dial.valueChanged.connect(spinBox.setValue) spinBox.valueChanged.connect(dial.setValue) self.setWindowTitle("Signals and slots")
class Demo(QWidget): def __init__(self): super(Demo, self).__init__() self.setWindowTitle('QDial') # 1 self.dial = QDial(self) self.dial.setFixedSize(100, 100) # 2 self.dial.setRange(0, 100) # 3 self.dial.setNotchesVisible(False) # 4 self.dial.valueChanged.connect(self.on_change_func) # 5 self.label = QLabel('0', self) self.label.setFont(QFont('Arial Black', 20)) self.h_layout = QHBoxLayout() self.h_layout.addWidget(self.dial) self.h_layout.addWidget(self.label) self.setLayout(self.h_layout) def on_change_func(self): self.label.setText(str(self.dial.value()))
def initUI(self): grid = QGridLayout() enabled = QCheckBox('Enabled') enabled.setObjectName(f"enabled{self.id}") enabled.toggle() enabled.stateChanged.connect(self.checkbox_update) grid.addWidget(enabled, 0, 0) amplitude = QDial() amplitude.setObjectName(f"amplitude{self.id}") amplitude.setMinimum(0) amplitude.setMaximum(100) amplitude.setValue(100) amplitude.setNotchesVisible(True) amplitude.setMaximumSize(80, 80) amplitude.valueChanged.connect(self.dial_update) # amplitude.setEnabled(False) grid.addWidget(amplitude, 1, 0) #grid.addWidget(amplitude, 0, 0, 2, 1) waveform = QComboBox(self) waveform.setObjectName(f"waveform{self.id}") waveform.addItem("Sine") waveform.addItem("Square") waveform.addItem("Sawtooth") waveform.addItem("Triangle") waveform.addItem("Random") waveform.currentTextChanged.connect(self.combobox_update) transpose = QLineEdit(self) transpose.setObjectName(f"transpose{self.id}") transpose.setValidator(QIntValidator()) transpose.setMaxLength(3) transpose.setText("0") transpose.textChanged.connect(self.lineedit_update) grid.addWidget(waveform, 0, 1) grid.addWidget(transpose, 0, 2) grid.addWidget(Envelope(self.id), 1, 1) self.setLayout(grid)
class 다이얼위젯(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.dial = QDial(self) self.dial.move(30, 20) self.dial2 = QDial(self) self.dial2.move(200, 20) self.dial2.setRange(0, 50) self.dial2.setNotchesVisible(True) self.label1 = QLabel('다이얼 1값', self) self.label1.move(40, 130) self.label2 = QLabel('다이얼 2값', self) self.label2.move(210, 130) btn = QPushButton('기본값으로 되돌리기', self) btn.move(150, 200) self.dial.valueChanged.connect(self.chageValue) self.dial2.valueChanged.connect(self.chageValue) btn.clicked.connect(self.btn_clicked) self.setGeometry(300, 300, 500, 400) self.setWindowTitle('QDial') self.show() def btn_clicked(self): self.dial.setValue(0) self.dial2.setValue(0) def chageValue(self): self.label1.setText(str(self.dial.value())) self.label2.setText(str(self.dial2.value()))
class MyApp(QWidget): def __init__(self): super().__init__() self.title = 'Ex5.8_QSlider_Qdial' self.posXY = (1200, 50) self.windowSize = (370, 250) self.initUI() def initUI(self): self.slider = QSlider(Qt.Horizontal, self) self.slider.move(30, 30) self.slider.setRange(0, 50) self.slider.setSingleStep(2) self.dial = QDial(self) self.dial.move(30, 60) self.dial.setRange(0, 50) self.dial.setNotchesVisible(True) btn = QPushButton('RESET', self) btn.move(35, 190) self.slider.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.slider.setValue) btn.clicked.connect(self.button_clicked) self.show_basic() def button_clicked(self): self.slider.setValue(0) self.dial.setValue(0) def show_basic(self): self.setWindowTitle(self.title) self.setGeometry(*self.posXY, *self.windowSize) self.show()
class Temperature_Page(QWidget): def __init__(self): QWidget.__init__(self) self.NowTemperature = QLCDNumber(self) self.WantTemperature = QLCDNumber(self) self.SettingDial = QDial(self) self.lbNow = QLabel("현재 온도", self) self.lbWant = QLabel("희망 온도", self) self.NowFont = self.lbNow.font() self.NowFont.setPointSize(40) self.NowFont.setBold(True) self.lbNow.resize(300, 50) self.lbNow.move(50, 50) self.lbNow.setAlignment(Qt.AlignCenter) self.lbNow.setFont(self.NowFont) self.lbWant.resize(300, 50) self.lbWant.move(400, 50) self.lbWant.setAlignment(Qt.AlignCenter) self.lbWant.setFont(self.NowFont) self.NowTemperature.resize(300, 100) self.NowTemperature.move(50, 130) self.WantTemperature.resize(300, 100) self.WantTemperature.move(400, 130) self.SettingDial.resize(190, 190) self.SettingDial.setRange(-20, 20) self.SettingDial.setNotchesVisible(True) self.SettingDial.move(460, 250) self.NowTemperature.display(sensorValue) self.SettingDial.valueChanged.connect(self.WantTemperature.display)
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()
from PyQt5.QtWidgets import QApplication, QDial def printValue(value): print(value, dial.value()) app = QApplication(sys.argv) dial = QDial() #dial.setMinimum(-15) #dial.setMaximum(15) dial.setRange(-15, 15) dial.setNotchesVisible(True) dial.setValue(5) # Initial value dial.valueChanged.connect(printValue) dial.show() # The mainloop of the application. The event handling starts from this point. # The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead. exit_code = app.exec_() # The sys.exit() method ensures a clean exit. # The environment will be informed, how the application ended. sys.exit(exit_code)
class Window(QWidget): def __init__(self): super().__init__() self.showMaximized() self.setWindowTitle('Barbequer') self.setWindowIcon(QIcon('BBQ.png')) self.init() def init(self): self.size_policy = (QSizePolicy.Expanding, QSizePolicy.Expanding) self.font = QFont() self.font.setPointSize(16) self.temp_display_label = QLabel(self) self.temp_display_label.setText('Current Temperature:') self.temp_display_label.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.temp_display_label.setFont(self.font) # self.temp_display_label.setAlignment(Qt.AlignRight) self.temp_display = QLCDNumber(self) self.temp_display.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.temp_display.setFont(self.font) self.temp_set_label = QLabel(self) self.temp_set_label.setText('Set Temperature:') self.temp_set_label.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.temp_set_label.setFont(self.font) # self.temp_set_label.setAlignment(Qt.AlignRight) self.temp_set = QLCDNumber(self) self.temp_set.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.temp_set.setFont(self.font) self.temp_dial = QDial(self) self.temp_dial.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.temp_dial.setProperty('value', 0) self.temp_dial.setSliderPosition(0) self.temp_dial.setNotchesVisible(True) self.temp_dial.setMaximum(600) self.temp_dial.setToolTip('Set Desired Temperature in Fahrenheit') self.temp_dial.valueChanged.connect(self.update_temperature) self.exhasut_fan = QRadioButton('&Enable Exhaust Fan') self.exhasut_fan.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.exhasut_fan.setFont(self.font) self.exhasut_fan.setToolTip('Enable exhaust fan') self.intake_fan = QRadioButton('&Enable Intake Fan') self.intake_fan.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.intake_fan.setFont(self.font) self.intake_fan.setToolTip('Enable intake fan') self.start_button = QPushButton('Start', self) self.start_button.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.start_button.setFont(self.font) self.start_button.setToolTip('Start Maintaining Temperature') self.start_button.clicked.connect(self.maintain_temperature) self.timer_button = QPushButton('Timer', self) self.timer_button.setSizePolicy(self.size_policy[0], self.size_policy[1]) self.timer_button.setFont(self.font) self.timer_button.setToolTip('Cook Time') qp = QPainter() qp.begin(self) qp.setPen(QPen(QColor(255, 80, 0), 3)) qp.setBrush(QColor(255, 80, 0)) qp.drawEllipse(QPoint(50, 60), 30, 30) qp.end() #add the grid layout to the interface self.layout = QGridLayout(self) self.layout.addWidget(self.temp_dial, 0, 0, 2, 2) self.layout.addWidget(self.temp_set_label, 2, 0) self.layout.addWidget(self.temp_set, 2, 1, 1, 2) self.layout.addWidget(self.temp_display_label, 3, 0) self.layout.addWidget(self.temp_display, 3, 1) self.layout.addWidget(self.exhasut_fan, 4, 0) self.layout.addWidget(self.intake_fan, 4, 1) self.layout.addWidget(self.start_button, 5, 0) self.layout.addWidget(self.timer_button, 5, 1) # self.layout.addWidget(qp,6,1) def update_temperature(self): self.temp_set.display(str(self.temp_dial.sliderPosition())) try: self.start_button.setEnabled(True) self.Temp.stop() except: '''do nothing here''' def maintain_temperature(self): self.Temp = temp_operation(self) self.start_button.setDisabled(True) self.Temp.isRunning = False time.sleep(1) if self.Temp.isRunning == False: self.Temp.isRunning = True self.Temp.set_temp = self.temp_dial.sliderPosition() self.Temp.display_update.connect(self.temp_display.display) self.Temp.start() print(self.Temp.isRunning)
class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Homer") # Fuel rods self.fuel_rod_label = QLabel("Fuel Rod Position") self.fuel_rod_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.fuel_rod_position_gauge = QDial() self.fuel_rod_position_gauge.setRange(0,100) self.fuel_rod_position_gauge.setSingleStep(1) self.fuel_rod_position_gauge.setNotchesVisible(True) self.fuel_rod_target_label = QLabel("Fuel Rod Position Target") self.fuel_rod_target_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.fuel_rod_position = QSpinBox() self.fuel_rod_position.setMinimum(0) self.fuel_rod_position.setMaximum(100) self.fuel_rod_position.setSingleStep(1) self.fuel_rod_position.valueChanged.connect(self.fuel_rod_position_changed) fuel_rod_layout = QVBoxLayout() fuel_rod_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) fuel_rod_layout.addWidget(self.fuel_rod_label) fuel_rod_layout.addWidget(self.fuel_rod_position_gauge) fuel_rod_layout.addWidget(self.fuel_rod_target_label) fuel_rod_layout.addWidget(self.fuel_rod_position) fuel_rod_widget = QWidget() fuel_rod_widget.setLayout(fuel_rod_layout) # Primary loop controls self.primary_temp_label = QLabel("Primary Coolant Temp") self.primary_temp_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.primary_temp_gauge = QDial() self.primary_temp_gauge.setRange(0,100) self.primary_temp_gauge.setSingleStep(1) self.primary_temp_gauge.setNotchesVisible(True) self.primary_temp_gauge.valueChanged.connect(self.primary_temp_value_changed) self.primary_pressure_label = QLabel("Primary Coolant Pressure") self.primary_pressure_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.primary_pressure_gauge = QDial() self.primary_pressure_gauge.setRange(0,100) self.primary_pressure_gauge.setSingleStep(1) self.primary_pressure_gauge.setNotchesVisible(True) self.primary_pump_rpm_label = QLabel("Primary Pump RPM") self.primary_pump_rpm_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.primary_pump_rpm = QSpinBox() self.primary_pump_rpm.setMinimum(0) self.primary_pump_rpm.setMaximum(100) self.primary_pump_rpm.setSingleStep(1) self.primary_pump_rpm.valueChanged.connect(self.primary_pump_rpm_changed) self.primary_relief_valve = QPushButton("vent primary") self.primary_relief_valve.setCheckable(True) self.primary_relief_valve.clicked.connect(self.primary_relief_valve_clicked) primary_loop_layout = QVBoxLayout() primary_loop_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) primary_loop_layout.addWidget(self.primary_temp_label) primary_loop_layout.addWidget(self.primary_temp_gauge) primary_loop_layout.addWidget(self.primary_pressure_label) primary_loop_layout.addWidget(self.primary_pressure_gauge) primary_loop_layout.addWidget(self.primary_pump_rpm_label) primary_loop_layout.addWidget(self.primary_pump_rpm) primary_loop_layout.addWidget(self.primary_relief_valve) primary_loop_widget = QWidget() primary_loop_widget.setLayout(primary_loop_layout) # Secondary loop controls self.secondary_temp_label = QLabel("Secondary Coolant Temp") self.secondary_temp_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.secondary_temp_gauge = QDial() self.secondary_temp_gauge.setRange(0,100) self.secondary_temp_gauge.setSingleStep(1) self.secondary_temp_gauge.setNotchesVisible(True) self.secondary_temp_gauge.valueChanged.connect(self.secondary_temp_value_changed) self.secondary_pressure_label = QLabel("Secondary Coolant Pressure") self.secondary_pressure_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.secondary_pressure_gauge = QDial() self.secondary_pressure_gauge.setRange(0,100) self.secondary_pressure_gauge.setSingleStep(1) self.secondary_pressure_gauge.setNotchesVisible(True) self.secondary_pump_rpm_label = QLabel("Secondary Pump RPM") self.secondary_pump_rpm_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.secondary_pump_rpm = QSpinBox() self.secondary_pump_rpm.setMinimum(0) self.secondary_pump_rpm.setMaximum(100) self.secondary_pump_rpm.setSingleStep(1) self.secondary_pump_rpm.valueChanged.connect(self.secondary_pump_rpm_changed) self.secondary_relief_valve = QPushButton("vent secondary") self.secondary_relief_valve.setCheckable(True) self.secondary_relief_valve.clicked.connect(self.secondary_relief_valve_clicked) secondary_loop_layout = QVBoxLayout() secondary_loop_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) secondary_loop_layout.addWidget(self.secondary_temp_label) secondary_loop_layout.addWidget(self.secondary_temp_gauge) secondary_loop_layout.addWidget(self.secondary_pressure_label) secondary_loop_layout.addWidget(self.secondary_pressure_gauge) secondary_loop_layout.addWidget(self.secondary_pump_rpm_label) secondary_loop_layout.addWidget(self.secondary_pump_rpm) secondary_loop_layout.addWidget(self.secondary_relief_valve) secondary_loop_widget = QWidget() secondary_loop_widget.setLayout(secondary_loop_layout) # Turbine/generator self.turbine_rpm_label = QLabel("Turbine RPM") self.turbine_rpm_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.turbine_rpm_gauge = QDial() self.turbine_rpm_gauge.setRange(0,100) self.turbine_rpm_gauge.setSingleStep(1) self.turbine_rpm_gauge.setNotchesVisible(True) self.generator_current_label = QLabel("Generator Current") self.generator_current_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.generator_current_gauge = QDial() self.generator_current_gauge.setRange(0,100) self.generator_current_gauge.setSingleStep(1) self.generator_current_gauge.setNotchesVisible(True) turbine_layout = QVBoxLayout() turbine_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) turbine_layout.addWidget(self.turbine_rpm_label) turbine_layout.addWidget(self.turbine_rpm_gauge) turbine_layout.addWidget(self.generator_current_label) turbine_layout.addWidget(self.generator_current_gauge) turbine_layout_widget = QWidget() turbine_layout_widget.setLayout(turbine_layout) # Layout all the controls main_layout = QGridLayout() # Fuel rods main_layout.addWidget(fuel_rod_widget, 0,0) # Primary loop main_layout.addWidget(primary_loop_widget, 0, 1) # Secondary loop main_layout.addWidget(secondary_loop_widget,0,2) # TODO: Condenser # Turbine main_layout.addWidget(turbine_layout_widget,0,3) main_widget = QWidget() main_widget.setLayout(main_layout) self.setCentralWidget(main_widget) # timer self.timer = QTimer() self.timer.setInterval(1000) self.timer.timeout.connect(self.recurring_timer) self.timer.start() # Event handlers def recurring_timer(self): reactor.tick() self.fuel_rod_position_gauge.setValue(reactor.rod_position) self.primary_temp_gauge.setValue(reactor.primary_temp) self.primary_pressure_gauge.setValue(reactor.primary_pressure) self.secondary_temp_gauge.setValue(reactor.secondary_temp) self.secondary_pressure_gauge.setValue(reactor.secondary_pressure) self.turbine_rpm_gauge.setValue(reactor.turbine_rpm) self.generator_current_gauge.setValue(reactor.generator_current) def fuel_rod_position_changed(self, i): reactor.set_rod_position(i) def primary_temp_value_changed(self, i): print(i) def primary_relief_valve_clicked(self, checked): print(checked) if checked: reactor.open_primary_relief_valve() else: reactor.close_primary_relief_valve() def primary_pump_rpm_changed(self, i): reactor.set_primary_pump_rpm(i) def secondary_temp_value_changed(self, i): print(i) def secondary_relief_valve_clicked(self, checked): print(checked) if checked: reactor.open_secondary_relief_valve() else: reactor.close_secondary_relief_valve() def secondary_pump_rpm_changed(self, i): reactor.set_secondary_pump_rpm(i)
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_()
def setupTab2(self, tab2): """Special widgets for preview panel""" scrollContainer = QVBoxLayout() scrollArea = QScrollArea() scrollArea.setWidgetResizable(True) mainWidget = QWidget() layout = QVBoxLayout() mainWidget.setLayout(layout) mainWidget.setMinimumSize(QSize(420, 800)) scrollArea.setWidget(mainWidget) scrollContainer.addWidget(scrollArea) tab2.setLayout(scrollContainer) # Dialog group0 = QGroupBox("Dialog") group1Layout = QVBoxLayout() layoutRow1 = QHBoxLayout() layoutRow2 = QHBoxLayout() group1Layout.addLayout(layoutRow1) group1Layout.addLayout(layoutRow2) group0.setLayout(group1Layout) layout.addWidget(group0) b1 = QPushButton(self.tr("Info")) b1.clicked.connect(lambda: QMessageBox.information( self, "Info", self.tr("This is a message."), QMessageBox.Ok, QMessageBox.Ok)) b2 = QPushButton(self.tr("Question")) b2.clicked.connect(lambda: QMessageBox.question( self, "question", self.tr("Are you sure?"), QMessageBox.No | QMessageBox.Yes, QMessageBox.Yes)) b3 = QPushButton(self.tr("Warning")) b3.clicked.connect(lambda: QMessageBox.warning( self, "warning", self.tr("This is a warning."), QMessageBox.No | QMessageBox.Yes, QMessageBox.Yes)) b4 = QPushButton(self.tr("Error")) b4.clicked.connect(lambda: QMessageBox.critical( self, "error", self.tr("It's a error."), QMessageBox.No | QMessageBox.Yes, QMessageBox.Yes)) b5 = QPushButton(self.tr("About")) b5.clicked.connect(lambda: QMessageBox.about( self, "about", self.tr("About this software"))) b6 = QPushButton(self.tr("Input")) # ,"输入对话框")) b6.clicked.connect(lambda: QInputDialog.getInt( self, self.tr("input"), self.tr("please input int"))) b6.clicked.connect(lambda: QInputDialog.getDouble( self, self.tr("input"), self.tr("please input float"))) b6.clicked.connect(lambda: QInputDialog.getItem( self, self.tr("input"), self.tr("please select"), ["aaa", "bbb"])) b7 = QPushButton(self.tr("Color")) # ,"颜色对话框")) b7.clicked.connect(lambda: QColorDialog.getColor()) b8 = QPushButton(self.tr("Font")) # ,"字体对话框")) b8.clicked.connect(lambda: QFontDialog.getFont()) b9 = QPushButton(self.tr("OpenFile")) # ,"打开对话框")) b9.clicked.connect(lambda: QFileDialog.getOpenFileName( self, "open", "", "Text(*.txt *.text)")) b10 = QPushButton(self.tr("SaveFile")) # ,"保存对话框")) b10.clicked.connect(lambda: QFileDialog.getSaveFileName()) layoutRow1.addWidget(b1) layoutRow1.addWidget(b2) layoutRow1.addWidget(b3) layoutRow1.addWidget(b4) layoutRow1.addWidget(b5) layoutRow2.addWidget(b6) layoutRow2.addWidget(b7) layoutRow2.addWidget(b8) layoutRow2.addWidget(b9) layoutRow2.addWidget(b10) # DateTime group1 = QGroupBox("DateTime") group1.setCheckable(True) group1Layout = QHBoxLayout() layoutRow1 = QVBoxLayout() layoutRow2 = QVBoxLayout() group1Layout.addLayout(layoutRow1) group1Layout.addLayout(layoutRow2) group1.setLayout(group1Layout) layout.addWidget(group1) group1.setMaximumHeight(240) dt1 = QDateEdit() dt1.setDate(QDate.currentDate()) dt2 = QTimeEdit() dt2.setTime(QTime.currentTime()) dt3 = QDateTimeEdit() dt3.setDateTime(QDateTime.currentDateTime()) dt4 = QDateTimeEdit() dt4.setCalendarPopup(True) dt5 = QCalendarWidget() dt5.setMaximumSize(QSize(250, 240)) layoutRow1.addWidget(dt1) layoutRow1.addWidget(dt2) layoutRow1.addWidget(dt3) layoutRow1.addWidget(dt4) layoutRow2.addWidget(dt5) # Slider group2 = QGroupBox("Sliders") group2.setCheckable(True) group2Layout = QVBoxLayout() layoutRow1 = QHBoxLayout() layoutRow2 = QHBoxLayout() group2Layout.addLayout(layoutRow1) group2Layout.addLayout(layoutRow2) group2.setLayout(group2Layout) layout.addWidget(group2) slider = QSlider() slider.setOrientation(Qt.Horizontal) slider.setMaximum(100) progress = QProgressBar() slider.valueChanged.connect(progress.setValue) slider.setValue(50) scroll1 = QScrollBar() scroll2 = QScrollBar() scroll3 = QScrollBar() scroll1.setMaximum(255) scroll2.setMaximum(255) scroll3.setMaximum(255) scroll1.setOrientation(Qt.Horizontal) scroll2.setOrientation(Qt.Horizontal) scroll3.setOrientation(Qt.Horizontal) c = QLabel(self.tr("Slide to change color")) # , "拖动滑块改变颜色")) c.setAutoFillBackground(True) c.setAlignment(Qt.AlignCenter) # c.setStyleSheet("border:1px solid gray;") c.setStyleSheet("background:rgba(0,0,0,100);") def clr(): # clr=QColor(scroll1.getValue(),scroll2.getValue(),scroll3.getValue(),100) # p=QPalette() # p.setColor(QPalette.Background,clr) # c.setPalette(p) c.setStyleSheet("background: rgba({},{},{},100);".format( scroll1.value(), scroll2.value(), scroll3.value())) scroll1.valueChanged.connect(clr) scroll2.valueChanged.connect(clr) scroll3.valueChanged.connect(clr) scroll1.setValue(128) layoutRow1.addWidget(slider) layoutRow1.addWidget(progress) layCol1 = QVBoxLayout() layCol1.addWidget(scroll1) layCol1.addWidget(scroll2) layCol1.addWidget(scroll3) layoutRow2.addLayout(layCol1) layoutRow2.addWidget(c) # Meter group3 = QGroupBox("Meters") group3.setCheckable(True) layRow = QHBoxLayout() group3.setLayout(layRow) layout.addWidget(group3) dial1 = QDial() dial2 = QDial() dial2.setNotchesVisible(True) dial1.valueChanged.connect(dial2.setValue) layRow.addWidget(dial1) layRow.addWidget(dial2) layout.addStretch(1)
class MainGUI(QDialog): def __init__(self, parent=None, imageoperator=None): super(MainGUI, self).__init__(parent) self.inputfile = None self.batchfilenames = None self.imageoperator = imageoperator self.originalPalette = QApplication.palette() self.btnFileOpen = QPushButton("Choose image file...") self.btnFileOpen.clicked.connect(self.getfile) self.leInputImage = QLabel() self.leInputImage.setPixmap( QPixmap( os.path.abspath( os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', 'resources', 'emptyspace.png'))).scaledToHeight(400)) self.leOutputImage = QLabel() self.leOutputImage.setPixmap( QPixmap( os.path.abspath( os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', 'resources', 'emptyspace.png'))).scaledToHeight(400)) self.createBottomLeftTabWidget() self.createBottomRightTabWidget() self.createProgressBar() # Top row of GUI, with image displays topLeftLayout = QGroupBox("Input Image") layout = QVBoxLayout() layout.addWidget(self.leInputImage) layout.addWidget(self.btnFileOpen) layout.addStretch(1) topLeftLayout.setLayout(layout) topRightLayout = QGroupBox("Output Image") layout = QVBoxLayout() layout.addWidget(self.leOutputImage) layout.addStretch(1) topRightLayout.setLayout(layout) topLayout = QHBoxLayout() topLayout.addWidget(topLeftLayout) topLayout.addWidget(topRightLayout) # Bottom row of GUI, with processing functions bottomLeftLayout = QGroupBox("Processing") layout = QVBoxLayout() layout.addWidget(self.bottomLeftTabWidget) layout.addStretch(1) bottomLeftLayout.setLayout(layout) bottomRightLayout = QGroupBox("Results") layout = QVBoxLayout() layout.addWidget(self.bottomRightTabWidget) layout.addStretch(1) bottomRightLayout.setLayout(layout) bottomLayout = QHBoxLayout() bottomLayout.addWidget(bottomLeftLayout) bottomLayout.addWidget(bottomRightLayout) mainLayout = QGridLayout() mainLayout.addLayout(topLayout, 0, 0, 1, 2) mainLayout.addLayout(bottomLayout, 1, 0, 1, 2) mainLayout.addWidget(self.bottomLeftTabWidget, 1, 0) mainLayout.addWidget(self.bottomRightTabWidget, 1, 1) mainLayout.addWidget(self.progressBar, 3, 0, 1, 2) mainLayout.setRowStretch(0, 1) mainLayout.setRowStretch(1, 1) mainLayout.setRowMinimumHeight(1, 200) mainLayout.setColumnStretch(0, 1) mainLayout.setColumnStretch(1, 1) self.setLayout(mainLayout) self.setWindowTitle("Pituitary Cytokeratin Spatial Frequency") QApplication.setStyle(QStyleFactory.create('Fusion')) QApplication.setPalette(QApplication.style().standardPalette()) def createBottomLeftTabWidget(self): self.bottomLeftTabWidget = QTabWidget() self.bottomLeftTabWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Ignored) tab1 = QWidget() self.btnProcess = QPushButton("Process!") self.btnProcess.setStyleSheet( "font: bold;background-color: green;font-size: 36px;height: 48px;width: 300px;" ) self.btnProcess.clicked.connect(self.processInputImage) self.dial = QDial() self.dial.setMinimum(1) self.dial.setMaximum(20) self.dial.setValue(6) self.dial.setSingleStep(1) self.dial.setNotchesVisible(True) self.dial.valueChanged.connect(self.handleDialMove) self.SpaceConstLabel = QLabel() self.SpaceConstLabel.setText("Space Constant: " + str(self.dial.value())) tab1hbox = QHBoxLayout() tab1hbox.setContentsMargins(5, 5, 5, 5) tab1hbox.addStretch(0) tab1hbox.addWidget(self.btnProcess) tab1hbox.addStretch(0) tab1hbox.addWidget(self.dial) tab1hbox.addWidget(self.SpaceConstLabel) tab1hbox.addStretch(0) tab1.setLayout(tab1hbox) tab2 = QWidget() self.batchTableWidget = QTableWidget(10, 1) self.batchTableWidget.setHorizontalHeaderLabels(["Filename"]) header = self.batchTableWidget.horizontalHeader() header.setSectionResizeMode(0, QHeaderView.Stretch) tab2hbox = QHBoxLayout() tab2hbox.setContentsMargins(5, 5, 5, 5) tab2hbox.addWidget(self.batchTableWidget) self.buttonBatchLoad = QPushButton("Load Files") self.buttonBatchLoad.clicked.connect(self.handleBatchLoad) tab2hbox.addWidget(self.buttonBatchLoad) tab2.setLayout(tab2hbox) self.bottomLeftTabWidget.addTab(tab1, "&Processing") self.bottomLeftTabWidget.addTab(tab2, "&Batch") def createBottomRightTabWidget(self): self.bottomRightTabWidget = QTabWidget() self.bottomRightTabWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Ignored) tab1 = QWidget() self.tableWidget = QTableWidget(10, 2) self.tableWidget.setHorizontalHeaderLabels( ["Filename", "Density Index"]) header = self.tableWidget.horizontalHeader() header.setSectionResizeMode(0, QHeaderView.Stretch) header.setSectionResizeMode(1, QHeaderView.ResizeToContents) self.TableRowCursor = 0 tab1hbox = QHBoxLayout() tab1hbox.setContentsMargins(5, 5, 5, 5) tab1hbox.addWidget(self.tableWidget) self.buttonSave = QPushButton("Save CSV") self.buttonSave.clicked.connect(self.handleSave) tab1hbox.addWidget(self.buttonSave) tab1.setLayout(tab1hbox) tab2 = QWidget() textEdit = QTextEdit() textEdit.setPlainText( "The Magi\n" "W. B. Yeats - 1865-1939\n" "\n" "Now as at all times I can see in the mind's eye,\n" "In their stiff, painted clothes, the pale unsatisfied ones\n" "Appear and disappear in the blue depth of the sky\n" "With all their ancient faces like rain-beaten stones,\n" "And all their helms of silver hovering side by side,\n" "And all their eyes still fixed, hoping to find once more,\n" "Being by Calvary's turbulence unsatisfied,\n" "The uncontrollable mystery on the bestial floor.\n") tab2hbox = QHBoxLayout() tab2hbox.setContentsMargins(5, 5, 5, 5) tab2hbox.addWidget(textEdit) tab2.setLayout(tab2hbox) self.bottomRightTabWidget.addTab(tab1, "&Results") self.bottomRightTabWidget.addTab(tab2, "Free &Text") def createProgressBar(self): self.progressBar = QProgressBar() self.progressBar.setRange(0, 10000) self.progressBar.setValue(0) def advanceProgressBar(self): curVal = self.progressBar.value() maxVal = self.progressBar.maximum() self.progressBar.setValue(curVal + (maxVal - curVal) / 100) def getfile(self): self.inputfname = QFileDialog.getOpenFileName(self, 'Open file', '~', "Image files (*.*)") if os.path.isfile(self.inputfname[0]): self.inputfile = self.inputfname[0] self.leInputImage.setPixmap( QPixmap(self.inputfile).scaledToHeight(400)) def handleDialMove(self): self.SpaceConstLabel.setText("Space Constant: " + str(self.dial.value())) def handleBatchLoad(self): userlist = QFileDialog.getOpenFileNames(self, 'Open file', '~', "Image files (*.*)") self.batchfilenames = userlist[0] self.batchTableWidget.setRowCount(len(self.batchfilenames)) self.batchTableWidget.clear() for row in range(len(self.batchfilenames)): self.inputfile = None self.batchTableWidget.setItem( row - 1, 1, QTableWidgetItem(os.path.basename(self.batchfilenames[row]))) def processInputImage(self): if (self.inputfile): filelist = [self.inputfile] display_output_image = True elif (self.batchfilenames): filelist = self.batchfilenames display_output_image = False else: filelist = [] print("No input file(s) specified!") return (0) self.imageoperator.setlims([self.dial.value(), 10 * self.dial.value()]) self.progressBar.setRange(0, len(filelist)) self.progressBar.setValue(0) for row in range(len(filelist)): infl = filelist[row] r = self.imageoperator.processImage(infl) di = r['density_index'] if (display_output_image): imout = np.int8( np.floor(255 * np.stack((r['bpdiffim'], ) * 3, axis=-1))) h, w, c = imout.shape bytesPerLine = w * 3 qpix = QPixmap.fromImage( QImage(imout, w, h, bytesPerLine, QImage.Format_RGB888)) self.leOutputImage.setPixmap(qpix.scaledToHeight(400)) #print("Density index: {0:.2f}".format(di)) nr = self.tableWidget.rowCount() if nr <= self.TableRowCursor: self.tableWidget.insertRow(nr) self.tableWidget.setItem(self.TableRowCursor, 0, QTableWidgetItem(os.path.basename(infl))) self.tableWidget.setItem(self.TableRowCursor, 1, QTableWidgetItem(str(di))) self.TableRowCursor = self.TableRowCursor + 1 self.progressBar.setValue(row + 1) def handleSave(self): p = QFileDialog.getSaveFileName(self, 'Save File', '', 'CSV(*.csv)') path = p[0] if len(path): with open(path, 'w') as stream: writer = csv.writer(stream) for row in range(self.tableWidget.rowCount()): rowdata = [] emptyrow = True for column in range(self.tableWidget.columnCount()): item = self.tableWidget.item(row, column) if item is not None: rowdata.append(item.text()) emptyrow = False else: rowdata.append('') if not emptyrow: writer.writerow(rowdata)
class WidgetGallery(QDialog): def __init__(self, parent=None): super(WidgetGallery, self).__init__(parent) self.init_mediaplayer() self.originalPalette = QApplication.palette() styleComboBox = QComboBox() styleComboBox.addItems(QStyleFactory.keys()) styleLabel = QLabel("&Style:") styleLabel.setBuddy(styleComboBox) disableWidgetsCheckBox = QCheckBox("&Inactive Buttons") self.createTopLeftGroupBox() self.createTopRightGroupBox() styleComboBox.activated[str].connect(self.changeStyle) disableWidgetsCheckBox.toggled.connect( self.topLeftGroupBox.setDisabled) disableWidgetsCheckBox.toggled.connect( self.topRightGroupBox.setDisabled) topLayout = QHBoxLayout() topLayout.addWidget(styleLabel) topLayout.addWidget(styleComboBox) topLayout.addStretch(1) topLayout.addWidget(disableWidgetsCheckBox) mainLayout = QGridLayout() mainLayout.addLayout(topLayout, 0, 0, 1, 2) mainLayout.addWidget(self.topLeftGroupBox, 1, 0) mainLayout.addWidget(self.topRightGroupBox, 1, 1) mainLayout.setRowStretch(5, 5) mainLayout.setRowStretch(2, 1) mainLayout.setColumnStretch(0, 1) mainLayout.setColumnStretch(1, 1) self.setLayout(mainLayout) self.setWindowTitle("Radios Angola") self.changeStyle('windows') def init_mediaplayer(self): self.instance = vlc.Instance( '--quiet --audio-visual visualizer --effect-list spectrum') self.media = None # Create an empty vlc media player self.mediaplayer = self.instance.media_player_new() self.mediaplayer.video_set_aspect_ratio("16:5") self.mediaplayer.video_set_scale(0.25) self.alsa = alsaaudio.Mixer(alsaaudio.mixers()[0]) self.is_paused = False def getStatus(self): status = { "stream length": self.mediaplayer.get_length(), "current time": self.mediaplayer.get_time(), "volume media player": self.mediaplayer.audio_get_volume(), "volume ": self.alsa.getvolume()[0], "state": self.mediaplayer.get_state() } return status def changeStyle(self, styleName): QApplication.setStyle(QStyleFactory.create(styleName)) def select_radio(self, qmodelindex): self.stop_stream() self.station_name = self.radio_stations_list.currentItem() if self.station_name is None: self.video_frame.setText("reloading ... ") else: self.radio_obj = network.get_station_obj(self.radio_json) self.selected = [ radio for radio in self.radio_obj if radio.r_name == self.station_name.text() ] self.load_station(self.selected[0]) def set_volume(self, volume): self.alsa.setvolume(volume) def refresh_stream(self): self.video_frame.setText("reloading ... ") self.stop_stream() self.play_pause() def previous_station(self, qmodelindex): self.stop_stream() try: curr_position = self.radio_stations_list.indexFromItem( self.station_name).row() previous_pos = curr_position - 1 if previous_pos < 0: previous_station = self.radio_stations_list.item( len(self.radio_obj) - 1) self.radio_stations_list.setCurrentItem(previous_station) self.select_radio(qmodelindex) else: previous_station = self.radio_stations_list.item(previous_pos) self.radio_stations_list.setCurrentItem(previous_station) self.select_radio(qmodelindex) except AttributeError: self.video_frame.setText("select a radio station") pass def next_station(self, qmodelindex): self.stop_stream() try: curr_position = self.radio_stations_list.indexFromItem( self.station_name).row() next_pos = curr_position + 1 if (next_pos > len(self.radio_obj) - 1): next_station = self.radio_stations_list.item(0) self.radio_stations_list.setCurrentItem(next_station) self.select_radio(qmodelindex) else: next_station = self.radio_stations_list.item(next_pos) self.radio_stations_list.setCurrentItem(next_station) self.select_radio(qmodelindex) except AttributeError: self.video_frame.setText("select a radio station") pass def stop_stream(self): self.reset_video_frame() self.mediaplayer.stop() self.b_play.setIcon(QIcon('application/img/play.png')) self.is_paused = False def load_station(self, radio_station): self.video_frame.setText("loading ... ") try: self.media = self.instance.media_new(radio_station.stream_link) self.mediaplayer.set_media(self.media) self.media.parse() # for Linux using the X Server if sys.platform.startswith('linux'): self.mediaplayer.set_xwindow(self.video_frame.winId()) # for Windows elif sys.platform == "win32": self.mediaplayer.set_hwnd(self.video_frame.winId()) # for MacOS( elif sys.platform == "darwin": self.mediaplayer.set_nsobject(int(self.video_frame.winId())) self.play_pause() except VLCException as err: raise err def play_pause(self): if self.mediaplayer.is_playing(): self.stop_stream() self.b_play.setIcon(QIcon('application/img/play.png')) self.is_paused = True else: if self.mediaplayer.play() == -1: self.video_frame.setText("select a radio station") self.video_frame.setAlignment(Qt.AlignCenter) return self.mediaplayer.play() self.b_play.setIcon(QIcon('application/img/pause.png')) self.is_paused = False self.video_frame.setText("") def createTopLeftGroupBox(self): self.topLeftGroupBox = QGroupBox("") self.video_frame = QLabel() self.reset_video_frame() self.b_refresh = QPushButton() self.b_refresh.setIcon(QIcon("application/img/refresh.png")) self.b_refresh.setIconSize(QSize(30, 30)) self.b_refresh.setGeometry(QRect(30, 10, 10, 30)) self.b_refresh.setToolTip("Refresh stream") self.b_refresh.clicked.connect(self.refresh_stream) self.b_previous = QPushButton() self.b_previous.setIcon(QIcon("application/img/back.png")) self.b_previous.setIconSize(QSize(30, 30)) self.b_previous.setGeometry(QRect(30, 10, 10, 30)) self.b_previous.setToolTip("Previous Radio Station") self.b_previous.clicked.connect(self.previous_station) self.b_play = QPushButton() self.b_play.setIcon(QIcon("application/img/play.png")) self.b_play.setIconSize(QSize(30, 30)) self.b_play.setGeometry(QRect(30, 30, 30, 30)) self.b_play.clicked.connect(self.play_pause) self.b_next = QPushButton() self.b_next.setIcon(QIcon("application/img/next.png")) self.b_next.setIconSize(QSize(30, 30)) self.b_next.setGeometry(QRect(30, 30, 30, 30)) self.b_next.setToolTip("Next Radio Station") self.b_next.clicked.connect(self.next_station) self.b_stop = QPushButton() self.b_stop.setIcon(QIcon("application/img/stop.png")) self.b_stop.setIconSize(QSize(30, 30)) self.b_stop.setGeometry(QRect(30, 30, 30, 3)) self.b_stop.setToolTip("Stop Streaming") self.b_stop.clicked.connect(self.stop_stream) layoutbuttons = QHBoxLayout() layoutbuttons.addWidget(self.b_refresh) layoutbuttons.addWidget(self.b_previous) layoutbuttons.addWidget(self.b_play) layoutbuttons.addWidget(self.b_next) layoutbuttons.addWidget(self.b_stop) self.dial_volume = QDial() #self.dial_volume.setMaximum(100) #self.dial_volume.setValue(self.mediaplayer.audio_get_volume()) self.dial_volume.setValue(self.alsa.getvolume()[0]) self.dial_volume.setNotchesVisible(True) self.dial_volume.setToolTip("Volume") self.dial_volume.valueChanged.connect(self.set_volume) layoutbuttons.addWidget(self.dial_volume) layout = QVBoxLayout() layout.addWidget(self.video_frame) layout.addLayout(layoutbuttons) self.topLeftGroupBox.setLayout(layout) def createTopRightGroupBox(self): self.topRightGroupBox = QGroupBox("radio stations") self.radio_json = network.get_stations_from_api() if self.radio_json is not None: self.station_names = network.get_station_names(self.radio_json) self.radio_stations_list = QListWidget() self.radio_stations_list.insertItems(0, self.station_names) self.radio_stations_list.clicked.connect(self.select_radio) else: self.radio_stations_list = QListWidget() self.radio_stations_list.insertItems( 0, ["Server Down .... no radio stations"]) layout = QVBoxLayout() layout.addWidget(self.radio_stations_list) self.topRightGroupBox.setLayout(layout) def reset_video_frame(self): self.video_frame.setStyleSheet("background-color: black") self.video_frame.setAutoFillBackground(True)