class Window(QWidget): def __init__(self, val): super().__init__() self.title = "QDial" self.top = 100 self.left = 100 self.width = 400 self.height = 120 self.iconName = "logo.png" self.setWindowTitle(self.title) self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() self.label = QLabel(self) self.label.setFont(QtGui.QFont("Elephant", 10)) self.dial = QDial() self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(30) self.dial.valueChanged.connect(self.dial_change) vbox.addWidget(self.dial) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def dial_change(self): getvalue = self.dial.value() self.label.setText("Dial is changed to " + str(getvalue))
class Window(QWidget): def __init__(self): super().__init__() self.title = "Pyqt5 QDial" self.top = 500 self.left = 500 self.width = 600 self.height = 200 self.iconName = "transistor.jpg" self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() self.label = QLabel(self) self.label.setFont(QtGui.QFont("Sanserif", 15)) self.dial = QDial() self.dial.setMinimum(0) self.dial.setMaximum(1000) self.dial.setValue(30) self.dial.valueChanged.connect(self.dial_changed) vbox.addWidget(self.label) vbox.addWidget(self.dial) self.setLayout(vbox) self.show() def dial_changed(self): getValue = self.dial.value() self.label.setText(f'Dial is Changing: {getValue}')
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)) #폰트,크기 조절
class Window(QWidget): def __init__(self): super().__init__() self.title = "PyQt5 - QDial" self.left = 500 self.top = 200 self.width = 200 self.height = 200 self.iconName = "_imagens/mouse.ico" self.setWindowTitle(self.title) self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() self.label = QLabel() self.label.setFont(QtGui.QFont("Sanserif", 15)) self.dial = QDial() self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(30) self.dial.valueChanged.connect(self.dial_changed) vbox.addWidget(self.dial) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def dial_changed(self): getValue = self.dial.value() self.label.setText("Dial changed to " + str(getValue))
class KnobsLedpanel(QWidget): def __init__(self, parent=None, device=None): super(KnobsLedpanel, self).__init__(parent) layout = QHBoxLayout() self.knob_yellow_led = QDial() self.knob_blue_led = QDial() self.knob_yellow_led.setMinimum(0) self.knob_yellow_led.setMaximum(255) self.knob_yellow_led.setValue(0) self.knob_yellow_led.sliderReleased.connect(self.yellow_sliderMoved) self.knob_blue_led.setMinimum(0) self.knob_blue_led.setMaximum(255) self.knob_blue_led.setValue(0) self.knob_blue_led.sliderReleased.connect(self.blue_sliderMoved) layout.addSpacing(15) layout.addWidget(self.knob_yellow_led) layout.addWidget(self.knob_blue_led) self.setLayout(layout) # self.setGeometry(10, 10, 350, 250) self.device = device def yellow_sliderMoved(self): self.device.wr_cmd(f"yled.intensity({self.knob_yellow_led.value()})") print(f"Yellow Led intensity: {self.knob_yellow_led.value()}") def blue_sliderMoved(self): self.device.wr_cmd(f"bled.intensity({self.knob_blue_led.value()})") print(f"Blue Led intensity: {self.knob_blue_led.value()}")
class Window(QWidget): def __init__(self): super().__init__() self.title = "PyQt5 Dial" self.left = 500 self.top = 200 self.width = 300 self.height = 250 self.iconName = "icon.png" self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() self.dial = QDial() self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(30) self.dial.valueChanged.connect(self.dial_changed) vbox.addWidget(self.dial) self.label = QLabel() self.label.setAlignment(Qt.AlignCenter) self.label.setFont(QtGui.QFont('Sanserif', 14)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def dial_changed(self): dialValue = self.dial.value() self.label.setText("Currerent Value is : {}".format(dialValue))
def __init__(self, parent, index=0): QDial.__init__(self, parent) self.fMinimum = 0.0 self.fMaximum = 1.0 self.fRealValue = 0.0 self.fIsHovered = False self.fHoverStep = self.HOVER_MIN self.fIndex = index self.fPixmap = QPixmap(":/bitmaps/dial_01d.png") self.fPixmapNum = "01" if self.fPixmap.width() > self.fPixmap.height(): self.fPixmapOrientation = self.HORIZONTAL else: self.fPixmapOrientation = self.VERTICAL self.fLabel = "" self.fLabelPos = QPointF(0.0, 0.0) self.fLabelFont = QFont(self.font()) self.fLabelFont.setPointSize(6) self.fLabelWidth = 0 self.fLabelHeight = 0 if self.palette().window().color().lightness() > 100: # Light background c = self.palette().dark().color() self.fLabelGradientColor1 = c self.fLabelGradientColor2 = QColor(c.red(), c.green(), c.blue(), 0) self.fLabelGradientColorT = [ self.palette().buttonText().color(), self.palette().mid().color() ] else: # Dark background self.fLabelGradientColor1 = QColor(0, 0, 0, 255) self.fLabelGradientColor2 = QColor(0, 0, 0, 0) self.fLabelGradientColorT = [Qt.white, Qt.darkGray] self.fLabelGradient = QLinearGradient(0, 0, 0, 1) self.fLabelGradient.setColorAt(0.0, self.fLabelGradientColor1) self.fLabelGradient.setColorAt(0.6, self.fLabelGradientColor1) self.fLabelGradient.setColorAt(1.0, self.fLabelGradientColor2) self.fLabelGradientRect = QRectF(0.0, 0.0, 0.0, 0.0) self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_NULL self.fCustomPaintColor = QColor(0xff, 0xff, 0xff) self.updateSizes() # Fake internal value, 10'000 precision QDial.setMinimum(self, 0) QDial.setMaximum(self, 10000) QDial.setValue(self, 0) self.valueChanged.connect(self.slot_valueChanged)
class SlidersGroup(QGroupBox): valueChanged = pyqtSignal(int) def __init__(self, orientation, title, parent=None): super(SlidersGroup, self).__init__(title, parent) self.slider = QSlider(orientation) self.slider.setFocusPolicy(Qt.StrongFocus) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setTickInterval(10) self.slider.setSingleStep(1) self.scrollBar = QScrollBar(orientation) self.scrollBar.setFocusPolicy(Qt.StrongFocus) self.dial = QDial() self.dial.setFocusPolicy(Qt.StrongFocus) self.slider.valueChanged.connect(self.scrollBar.setValue) self.scrollBar.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.slider.setValue) self.dial.valueChanged.connect(self.valueChanged) if orientation == Qt.Horizontal: direction = QBoxLayout.TopToBottom else: direction = QBoxLayout.LeftToRight slidersLayout = QBoxLayout(direction) slidersLayout.addWidget(self.slider) slidersLayout.addWidget(self.scrollBar) slidersLayout.addWidget(self.dial) self.setLayout(slidersLayout) def setValue(self, value): self.slider.setValue(value) def setMinimum(self, value): self.slider.setMinimum(value) self.scrollBar.setMinimum(value) self.dial.setMinimum(value) def setMaximum(self, value): self.slider.setMaximum(value) self.scrollBar.setMaximum(value) self.dial.setMaximum(value) def invertAppearance(self, invert): self.slider.setInvertedAppearance(invert) self.scrollBar.setInvertedAppearance(invert) self.dial.setInvertedAppearance(invert) def invertKeyBindings(self, invert): self.slider.setInvertedControls(invert) self.scrollBar.setInvertedControls(invert) self.dial.setInvertedControls(invert)
def __init__(self, parent, index=0): QDial.__init__(self, parent) self.fMinimum = 0.0 self.fMaximum = 1.0 self.fRealValue = 0.0 self.fIsHovered = False self.fHoverStep = self.HOVER_MIN self.fIndex = index self.fPixmap = QPixmap(":/bitmaps/dial_01d.png") self.fPixmapNum = "01" if self.fPixmap.width() > self.fPixmap.height(): self.fPixmapOrientation = self.HORIZONTAL else: self.fPixmapOrientation = self.VERTICAL self.fLabel = "" self.fLabelPos = QPointF(0.0, 0.0) self.fLabelFont = QFont(self.font()) self.fLabelFont.setPointSize(6) self.fLabelWidth = 0 self.fLabelHeight = 0 if self.palette().window().color().lightness() > 100: # Light background c = self.palette().dark().color() self.fLabelGradientColor1 = c self.fLabelGradientColor2 = QColor(c.red(), c.green(), c.blue(), 0) self.fLabelGradientColorT = [self.palette().buttonText().color(), self.palette().mid().color()] else: # Dark background self.fLabelGradientColor1 = QColor(0, 0, 0, 255) self.fLabelGradientColor2 = QColor(0, 0, 0, 0) self.fLabelGradientColorT = [Qt.white, Qt.darkGray] self.fLabelGradient = QLinearGradient(0, 0, 0, 1) self.fLabelGradient.setColorAt(0.0, self.fLabelGradientColor1) self.fLabelGradient.setColorAt(0.6, self.fLabelGradientColor1) self.fLabelGradient.setColorAt(1.0, self.fLabelGradientColor2) self.fLabelGradientRect = QRectF(0.0, 0.0, 0.0, 0.0) self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_NULL self.fCustomPaintColor = QColor(0xff, 0xff, 0xff) self.updateSizes() # Fake internal value, 10'000 precision QDial.setMinimum(self, 0) QDial.setMaximum(self, 10000) QDial.setValue(self, 0) self.valueChanged.connect(self.slot_valueChanged)
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))
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 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 SlidersGroup(QGroupBox): valueChanged = QtCore.pyqtSignal(int) def __init__(self, orientation, name, title, parent=None): super(SlidersGroup, self).__init__(title, parent) self.name = name self.value = 0.0 valueLabel = QLabel("Current value:") #self.valueSpinBox = QDoubleSpinBox () self.valueSpinBox = QSpinBox() self.valueSpinBox.setSingleStep(1) self.valueSpinBox.setFocusPolicy(QtCore.Qt.StrongFocus) self.slider = QSlider(orientation) self.slider.setFocusPolicy(QtCore.Qt.StrongFocus) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setTickInterval(10) self.slider.setSingleStep(1) self.dial = QDial() self.dial.setFocusPolicy(QtCore.Qt.StrongFocus) self.slider.valueChanged.connect(self.setValue) self.dial.valueChanged.connect(self.setValue) direction = QBoxLayout.TopToBottom slidersLayout = QBoxLayout(direction) slidersLayout.addWidget(valueLabel) slidersLayout.addWidget(self.valueSpinBox) slidersLayout.addWidget(self.slider) #slidersLayout.addWidget(self.dial) self.setLayout(slidersLayout) def setValue(self, value): self.valueSpinBox.setValue(value) self.slider.setValue(value) self.dial.setValue(value) self.value = value def setMinimum(self, value): self.slider.setMinimum(value) self.dial.setMinimum(value) def setMaximum(self, value): self.valueSpinBox.setRange(0, value) self.slider.setMaximum(value) self.dial.setMaximum(value)
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)
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 addDial(self, title, x, y, w, h, labelX, minimum, maximum, key): label = QLabel(self.window) label.setText(title) label.setGeometry(labelX, y + h, w, 20) dial = QDial(self.window) dial.setGeometry(x, y, w, h) dial.setMinimum(minimum) dial.setMaximum(maximum) dial.valueChanged.connect(lambda: self.updateDial(dial)) valueLabel = QLabel(self.window) valueLabel.setText(str(dial.value())) valueLabel.setGeometry( dial.geometry().x() + int(dial.geometry().width() / 2) - 5, y - 35, w, h) self.dialList.append([key, dial, label, valueLabel])
class Window(QDialog): def __init__(self, val): super().__init__() self.title = "QDial" self.left = 300 self.top = 100 self.width = 500 self.height = 500 self.IconName = "Icon/python.png" self.color = 'red' self.val = val self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon(self.IconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) #self.setStyleSheet('background-color:green') vbox = QVBoxLayout() self.dial = QDial() self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(30) self.dial.valueChanged.connect(self.DialChange) self.label = QLabel(self) self.label.setFont(QtGui.QFont("Sanserif", 15)) vbox.addWidget(self.dial) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def DialChange(self): getValue = self.dial.value() self.label.setText("Dial Value : " + str(getValue))
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 QdialWindow(QWidget): def __init__(self, parent=None): super().__init__(parent) self.setupUi() def setupUi(self): layout = QGridLayout() self.setLayout(layout) self.dial = QDial() self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(0) self.dial.valueChanged.connect(self.dialerMoved) self.label = QLabel("0") layout.addWidget(self.dial) layout.addWidget(self.label) self.show() def dialerMoved(self): print(f'Dial Value is : {self.dial.value()}') self.label.setText(f'Dial Value is : {self.dial.value()}')
class Window(QWidget): def __init__(self): super().__init__() self.title = "This is first thing" self.height = 700 self.width = 1100 self.top = 100 self.left = 200 self.iconName = "plioky.ico" self.dial = QDial() self.label = QLabel(self) self.init_window() def init_window(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() self.label.setFont(QtGui.QFont("Sanserif", 50)) self.dial.valueChanged.connect(self.dial_changed) self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(0) vbox.addWidget(self.dial) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def dial_changed(self): size = self.dial.value() self.label.setText(str(size))
class Demo(QWidget): def __init__(self): super().__init__() self.setWindowTitle("QDial Demo") self.setGeometry(300, 300, 500, 500) self.dial = QDial() self.dial.setMaximum(100) self.dial.setMinimum(0) self.dial.setValue(0) self.dial.valueChanged.connect(self.print_dial_value) self.label = QLabel("Dial Value is " + str(self.dial.value())) self.label.setFont(QFont("Open Sans", 20)) self.layout = QVBoxLayout() self.layout.addWidget(self.dial) self.layout.addWidget(self.label) self.setLayout(self.layout) def print_dial_value(self): self.label.setText("Dial Value is " + str(self.dial.value()))
class Window(QWidget): def __init__(self): super().__init__() self.title = "PyQt QDial" self.top = 100 self.left = 100 self.width = 400 self.height = 300 self.vbox = QVBoxLayout() self.dial = QDial() self.label = QLabel(self) self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon("home.png")) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.Dial() self.setLayout(self.vbox) self.show() def Dial(self): self.dial.setMinimum(0) self.dial.setMaximum(100) self.dial.setValue(30) self.dial.valueChanged.connect(self.dial_changed) self.vbox.addWidget(self.dial) self.vbox.addWidget(self.label) def dial_changed(self): val = self.dial.value() self.label.setText("Dial value is: " + str(val))
class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("Client") vbox = QVBoxLayout() hbox = QHBoxLayout() hbox2 = QHBoxLayout() wheel_stack = QStackedLayout() widget = QWidget() accelerate_btn = QPushButton(widget) accelerate_btn.setText("Accelerate") # accelerate_btn.move(64, 32) accelerate_btn.clicked.connect(accelerate) decelerate_btn = QPushButton(widget) decelerate_btn.setText("Decelerate") # decelerate_btn.move(64, 64) decelerate_btn.clicked.connect(decelerate) left_btn = QPushButton(widget) left_btn.setText("Left") # left_btn.move(32, 64) left_btn.clicked.connect(left) right_btn = QPushButton(widget) right_btn.setText("Right") # right_btn.move(96, 64) right_btn.clicked.connect(right) self.throttle = QSlider(widget) self.throttle.setOrientation(0x2) self.throttle.setProperty("value", 0) ss = "::handle {image: url(pedal.svg)}" self.throttle.setStyleSheet(ss) self.steering = QDial(widget) self.steering.setMinimum(0) self.steering.setMaximum(100) self.steering.setProperty("value", 50) self.steering.valueChanged.connect(change_steering) self.throttle.valueChanged.connect(change_throttle) self.steering_wheel = QPixmap('steering-wheel.svg') self.wheel_label = QLabel(self) self.wheel_label.setAlignment(QtCore.Qt.AlignCenter) self.wheel_label.setMinimumSize(400, 400) self.wheel_label.setPixmap(self.steering_wheel) self.accel_shortcut = QShortcut(QKeySequence("w"), self) self.accel_shortcut.activated.connect(accelerate) self.decel_shortcut = QShortcut(QKeySequence("s"), self) self.decel_shortcut.activated.connect(decelerate) self.left_shortcut = QShortcut(QKeySequence("a"), self) self.left_shortcut.activated.connect(left) self.right_shortcut = QShortcut(QKeySequence("d"), self) self.right_shortcut.activated.connect(right) hbox.addWidget(left_btn) hbox.addWidget(decelerate_btn) hbox.addWidget(right_btn) vbox.addWidget(accelerate_btn) vbox.addLayout(hbox) hbox2.addWidget(self.throttle) wheel_stack.addWidget(self.wheel_label) wheel_stack.addWidget(self.steering) hbox2.addLayout(wheel_stack) vbox.addLayout(hbox2) main_widget = QWidget() main_widget.setLayout(vbox) self.setCentralWidget(main_widget) def set_throttle(self, tval): self.throttle.setProperty("value", tval) def set_steering(self, sval): self.steering.setProperty("value", sval) transform = QTransform() transform.rotate(sval * 2 - 100) steering_wheel = QPixmap('steering-wheel.svg') self.steering_wheel = steering_wheel.transformed(transform) self.wheel_label.setPixmap(self.steering_wheel)
def __init__(self, parent, index=0): QDial.__init__(self, parent) self.fDialMode = self.MODE_LINEAR self.fMinimum = 0.0 self.fMaximum = 1.0 self.fRealValue = 0.0 self.fPrecision = 10000 self.fIsInteger = False self.fIsHovered = False self.fIsPressed = False self.fHoverStep = self.HOVER_MIN self.fLastDragPos = None self.fLastDragValue = 0.0 self.fIndex = index self.fImage = QSvgWidget(":/scalable/dial_03.svg") self.fImageNum = "01" if self.fImage.sizeHint().width() > self.fImage.sizeHint().height(): self.fImageOrientation = self.HORIZONTAL else: self.fImageOrientation = self.VERTICAL self.fLabel = "" self.fLabelPos = QPointF(0.0, 0.0) self.fLabelFont = QFont(self.font()) self.fLabelFont.setPixelSize(8) self.fLabelWidth = 0 self.fLabelHeight = 0 if self.palette().window().color().lightness() > 100: # Light background c = self.palette().dark().color() self.fLabelGradientColor1 = c self.fLabelGradientColor2 = QColor(c.red(), c.green(), c.blue(), 0) self.fLabelGradientColorT = [ self.palette().buttonText().color(), self.palette().mid().color() ] else: # Dark background self.fLabelGradientColor1 = QColor(0, 0, 0, 255) self.fLabelGradientColor2 = QColor(0, 0, 0, 0) self.fLabelGradientColorT = [Qt.white, Qt.darkGray] self.fLabelGradient = QLinearGradient(0, 0, 0, 1) self.fLabelGradient.setColorAt(0.0, self.fLabelGradientColor1) self.fLabelGradient.setColorAt(0.6, self.fLabelGradientColor1) self.fLabelGradient.setColorAt(1.0, self.fLabelGradientColor2) self.fLabelGradientRect = QRectF(0.0, 0.0, 0.0, 0.0) self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_NULL self.fCustomPaintColor = QColor(0xff, 0xff, 0xff) self.updateSizes() # Fake internal value, custom precision QDial.setMinimum(self, 0) QDial.setMaximum(self, self.fPrecision) QDial.setValue(self, 0) self.valueChanged.connect(self.slot_valueChanged)
class Start(QMainWindow): def __init__(self): super(Start, self).__init__() self.titles = "Media Player" self.left = 500 self.top = 300 self.width = 400 self.height = 200 self.window_main() self.adding_menus() def openMultipleFile(self): dialogs = QFileDialog(self) self.fnames, _ = dialogs.getOpenFileNames( self, 'Open Media Files', QDir.homePath(), "Videos (*.mp4 *.mkv *.3pg)") if self.fnames != '': self.playlist = QMediaPlaylist(self) self.fnamelist = [] for playlst in self.fnames: self.fnamelist.append( QMediaContent(QUrl.fromLocalFile(playlst))) self.playlist.addMedia(self.fnamelist) self.playlist.setCurrentIndex(1) self.videoWidget = QVideoWidget(self) self.mediaPlayer.setVideoOutput(self.videoWidget) # self.videoWidget.setAspectRatioMode(60, 60,Qt.KeepAspectRatioByExpanding) self.mediaPlayer.setPlaylist(self.playlist) self.playlist.currentIndexChanged.connect(self.mediaNameChange) self.mediaPlayer.play() self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPause)) self.play.setEnabled(True) self.stop.setEnabled(True) self.loop.setEnabled(True) if (len(self.fnamelist) > 1): self.forw.setEnabled(True) self.shuffl.setEnabled(True) self.l1.setText("00:00") mediaName = self.fnames[0].rsplit('/', 1)[-1] self.fulltitle = mediaName + " - " + self.titles self.setWindowTitle(self.fulltitle) self.mediaPlayer.durationChanged.connect(self.sliderDuration) def openFile(self): self.fname, _ = QFileDialog.getOpenFileName( self, 'Open Media Files', QDir.homePath(), "Videos (*.mp4 *.mkv *.3pg)") if self.fname != '': mediaName = self.fname.rsplit('/', 1)[-1] self.fulltitle = mediaName + " - " + self.titles self.setWindowTitle(self.fulltitle) self.playlist = QMediaPlaylist(self) self.playlist.addMedia( QMediaContent(QUrl.fromLocalFile(self.fname))) self.playlist.setCurrentIndex(1) self.mediaPlayer.setPlaylist(self.playlist) self.playlist.currentIndexChanged.connect(self.mediaNameChange) self.mediaPlayer.play() self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPause)) self.play.setEnabled(True) self.stop.setEnabled(True) self.loop.setEnabled(True) self.l1.setText("00:00") self.mediaPlayer.durationChanged.connect(self.sliderDuration) def window_main(self): self.setWindowTitle(self.titles) qw = QWidget() self.setGeometry(self.left, self.top, qw.maximumWidth(), qw.maximumHeight()) self.setMinimumSize(540, 0) self.setWindowIcon(QIcon("mediaplayer.png")) self.video() self.show() def sliderChanged(self, position): pos = position * 1000 self.mediaPlayer.setPosition(pos) self.slider.setValue(position) def adding_menus(self): menu = Allmenu(self) def volumeChange(self, vol): self.mediaPlayer.setVolume(vol) def sliderDuration(self, duratn): milisec = self.mediaPlayer.duration() sec = int(milisec / 1000) hour = int(sec / 3600) min = int((sec / 60) - (hour * 60)) secs = int(sec - (min * 60) - (hour * 60 * 60)) self.l2.setText(str(hour) + ":" + str(min) + ":" + str(secs)) self.slider.setMaximum(sec) def sliderDuration2(self, duratn): second = int(duratn / 1000) self.slider.setValue(second) hour = int(second / 3600) min = int((second / 60) - (hour * 60)) secs = int(second - (min * 60) - (hour * 60 * 60)) if (min < 10): min = "0" + str(min) else: min = str(min) if (secs < 10): secs = "0" + str(secs) else: secs = str(secs) if (hour == 0): self.l1.setText(min + ":" + secs) else: self.l1.setText(str(hour) + ":" + min + ":" + secs) def mediaNameChange(self, index): mediaName = self.fnames[index].rsplit('/', 1)[-1] self.fulltitle = mediaName + " - " + self.titles self.setWindowTitle(self.fulltitle) if (self.playlist.playbackMode() == 4): self.forw.setEnabled(True) self.back.setEnabled(True) else: if ((index + 1) == self.playlist.mediaCount()): self.forw.setEnabled(False) self.back.setEnabled(True) else: self.back.setEnabled(True) def video(self): self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.mediaPlayer.positionChanged.connect(self.sliderDuration2) self.mediaPlayer.setVolume(10) videoWidget = QVideoWidget() layout = QVBoxLayout() wid = QWidget(self) self.play = QPushButton() self.play.setEnabled(False) self.play.setFixedWidth(40) self.play.setFixedHeight(30) self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.play.setIconSize(QSize(20, 20)) self.play.clicked.connect(self.playAction) self.play.setShortcut(QKeySequence("Space")) self.back = QPushButton() self.back.setEnabled(False) self.back.setFixedWidth(40) self.back.setFixedHeight(25) self.back.setStyleSheet("margin-left: 10px") self.back.setIcon(self.style().standardIcon( QStyle.SP_MediaSeekBackward)) self.back.setIconSize(QSize(14, 14)) self.back.clicked.connect(self.prevAction) self.back.setShortcut(QKeySequence("Ctrl+b")) self.stop = QPushButton() self.stop.setEnabled(False) self.stop.setFixedWidth(40) self.stop.setFixedHeight(25) self.stop.setStyleSheet("margin-left: 0px") self.stop.setIcon(self.style().standardIcon(QStyle.SP_MediaStop)) self.stop.setIconSize(QSize(14, 14)) self.stop.clicked.connect(self.stopAction) self.stop.setShortcut(QKeySequence("s")) self.forw = QPushButton() self.forw.setEnabled(False) self.forw.setFixedWidth(40) self.forw.setFixedHeight(25) self.forw.setStyleSheet("margin-left: 0px") self.forw.setIcon(self.style().standardIcon( QStyle.SP_MediaSeekForward)) self.forw.setIconSize(QSize(14, 14)) self.forw.clicked.connect(self.forwAction) self.forw.setShortcut(QKeySequence("Ctrl+f")) self.loop = QPushButton() self.loop.setEnabled(False) self.loop.setFixedWidth(40) self.loop.setFixedHeight(25) self.loop.setStyleSheet("margin-left: 10px") self.loop.setIcon(QIcon(QPixmap("loop.svg"))) self.loop.setIconSize(QSize(14, 14)) self.loop.clicked.connect(self.loopAction) self.loop.setShortcut(QKeySequence("Ctrl+l")) self.shuffl = QPushButton() self.shuffl.setEnabled(False) self.shuffl.setFixedHeight(25) self.shuffl.setStyleSheet("margin-left: 0px") self.shuffl.setFixedWidth(40) self.shuffl.setFixedHeight(25) self.shuffl.setStyleSheet("margin-left: 0px") self.shuffl.setIcon(QIcon(QPixmap("shuffl.svg"))) self.shuffl.setIconSize(QSize(14, 14)) self.shuffl.clicked.connect(self.shufflAction) self.shuffl.setShortcut(QKeySequence("Ctrl+shift+s")) spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.volume = QDial() self.volume.setFixedWidth(40) self.volume.setFixedHeight(40) self.volume.setMaximum(100) self.volume.setMinimum(0) self.volume.setToolTip("Volume") self.volume.valueChanged.connect(self.volumeChange) hlayout = QHBoxLayout() hlayout.addWidget(self.play) hlayout.addWidget(self.back) hlayout.addWidget(self.stop) hlayout.addWidget(self.forw) hlayout.addWidget(self.loop) hlayout.addWidget(self.shuffl) hlayout.addItem(spacer) hlayout.addWidget(self.volume) hslayout = QHBoxLayout() self.slider = QSlider(Qt.Horizontal) self.slider.setMinimum(0) self.slider.setMaximum(0) self.l1 = QLabel() self.l1.setText("--:--:--") self.l2 = QLabel() self.l2.setText("--:--:--") self.slider.sliderMoved.connect(self.sliderChanged) hslayout.addWidget(self.l1) hslayout.addWidget(self.slider) hslayout.addWidget(self.l2) layout.addWidget(videoWidget) layout.addLayout(hslayout) layout.addLayout(hlayout) wid.setLayout(layout) self.setCentralWidget(wid) self.mediaPlayer.setVideoOutput(videoWidget) def playAction(self): if (self.mediaPlayer.state() == 1): self.mediaPlayer.pause() self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) elif (self.mediaPlayer.state() == 2): self.mediaPlayer.play() self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPause)) else: self.back.setEnabled(False) self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) def stopAction(self): self.mediaPlayer.stop() self.play.setEnabled(False) self.play.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.setWindowTitle(self.titles) self.l1.setText("--:--:--") self.l2.setText("--:--:--") def forwAction(self): if (self.playlist.playbackMode() == 4): self.forw.setEnabled(True) self.back.setEnabled(True) indexes = random.randint(0, (self.playlist.mediaCount() - 1)) self.playlist.setCurrentIndex(indexes) elif (self.playlist.playbackMode() == 1): self.playlist.next() else: print(self.playlist.currentIndex()) if ((self.playlist.currentIndex() + 2) == self.playlist.mediaCount()): self.forw.setEnabled(False) self.playlist.next() self.back.setEnabled(True) else: self.playlist.next() self.back.setEnabled(True) def prevAction(self): if (self.playlist.playbackMode() == 4): self.forw.setEnabled(True) self.back.setEnabled(True) indexes = random.randint(0, (self.playlist.mediaCount() - 1)) self.playlist.setCurrentIndex(indexes) elif (self.playlist.playbackMode() == 1): self.playlist.previous() else: if (self.playlist.currentIndex() == 1): self.forw.setEnabled(True) self.playlist.previous() self.back.setEnabled(False) else: self.playlist.previous() self.forw.setEnabled(True) def loopAction(self): if (self.playlist.playbackMode() != 1): self.playlist.setPlaybackMode(QMediaPlaylist.CurrentItemInLoop) self.loop.setIcon(QIcon(QPixmap("greenloop.svg"))) self.shuffl.setIcon(QIcon(QPixmap("shuffl.svg"))) else: self.playlist.setPlaybackMode(QMediaPlaylist.Sequential) self.loop.setIcon(QIcon(QPixmap("loop.svg"))) def shufflAction(self): if (self.playlist.playbackMode() != 4): self.playlist.setPlaybackMode(QMediaPlaylist.Random) self.shuffl.setIcon(QIcon(QPixmap("greenshuffl.svg"))) self.loop.setIcon(QIcon(QPixmap("loop.svg"))) else: self.playlist.setPlaybackMode(QMediaPlaylist.Sequential) self.shuffl.setIcon(QIcon(QPixmap("shuffl.svg"))) def close(self): sys.exit(1)
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
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 SpinnerDialComboWidget(QWidget): value_changed = pyqtSignal() # name: The string name that will be displayed on top of the widget # default_value: The value that will be initially set as the widget's value # min_val: The minimum value that will be initially set # max_val: The maximum value that will be initially set def __init__(self, name="", default_value=0, min_val=0, max_val=100, parent=None): QWidget.__init__(self, parent=parent) # The minimum value that can be set self.min_val = min_val # The maximum value that can be set self.max_val = max_val # The widget's current value self.value = default_value self.title_label = QLabel(name) # The widget's dial self.dial = QDial(self) self.dial.setSingleStep(1) self.dial.setPageStep(1) self.dial.setMinimum(min_val) self.dial.setMaximum(max_val) self.dial.setValue(default_value) self.dial.valueChanged.connect(self.on_dial_changed) # The widget's spin box self.spinner = QSpinBox(self) self.spinner.setMinimum(min_val) self.spinner.setMaximum(max_val) self.spinner.setValue(default_value) self.spinner.valueChanged.connect(self.on_spinner_changed) self.setup_gui() # Sets up the positioning of the UI elements def setup_gui(self): vertical_layout = QVBoxLayout(self) vertical_layout.addStretch(1) vertical_layout.addWidget(self.title_label) vertical_layout.addWidget(self.spinner) vertical_layout.addWidget(self.dial) # The callback for when the dial is changes @pyqtSlot() def on_dial_changed(self): self.value = self.dial.value() self.spinner.blockSignals(True) self.spinner.setValue(self.dial.value()) self.spinner.blockSignals(False) self.value_changed.emit() # The callback for when the spin box is changed @pyqtSlot() def on_spinner_changed(self): self.value = self.spinner.value() self.dial.blockSignals(True) self.dial.setValue(self.spinner.value()) self.dial.blockSignals(False) self.value_changed.emit() # Sets the minimum value # new_min: The new minimum value to be set def set_min(self, new_min): if new_min > self.max_val: return self.min_val = new_min self.dial.blockSignals(True) self.spinner.blockSignals(True) self.spinner.setMinimum(new_min) self.dial.setMinimum(new_min) self.dial.blockSignals(False) self.spinner.blockSignals(False) self.value_changed.emit() # Sets the maximum value # new_max: The new maximum value to be set def set_max(self, new_max): if new_max < self.min_val: return self.max_val = new_max self.dial.blockSignals(True) self.spinner.blockSignals(True) self.spinner.setMaximum(new_max) self.dial.setMaximum(new_max) self.dial.blockSignals(False) self.spinner.blockSignals(False) self.value_changed.emit() # Sets the widget value # value: The value to be set def set_value(self, value): self.value = value self.dial.blockSignals(True) self.spinner.blockSignals(True) self.dial.setValue(value) self.spinner.setValue(value) self.dial.blockSignals(False) self.spinner.blockSignals(False) self.value_changed.emit()
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_()
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)
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()