class ChannelAnchor(QGraphicsRectItem): """ A rectangular Channel Anchor indicator. """ def __init__(self, parent=None, channel=None, rect=None, **kwargs): QGraphicsRectItem.__init__(self, **kwargs) self.setAcceptHoverEvents(True) self.setAcceptedMouseButtons(Qt.NoButton) self.__channel = None if rect is None: rect = QRectF(0, 0, 20, 20) self.setRect(rect) if channel: self.setChannel(channel) self.__shadow = QGraphicsDropShadowEffect(blurRadius=5, offset=QPointF(0, 0)) self.setGraphicsEffect(self.__shadow) self.__shadow.setEnabled(False) def setChannel(self, channel): """ Set the channel description. """ if channel != self.__channel: self.__channel = channel if hasattr(channel, "description"): self.setToolTip(channel.description) # TODO: Should also include name, type, flags, dynamic in the # tool tip as well as add visual clues to the anchor def channel(self): """ Return the channel description. """ return self.__channel def hoverEnterEvent(self, event): self.__shadow.setEnabled(True) QGraphicsRectItem.hoverEnterEvent(self, event) def hoverLeaveEvent(self, event): self.__shadow.setEnabled(False) QGraphicsRectItem.hoverLeaveEvent(self, event)
def __init__(self, parent=None): """Init class.""" super(MainWindow, self).__init__() self.setWindowTitle(__doc__.strip().capitalize()) self.statusBar().showMessage(" Choose one App and move the sliders !") self.setMinimumSize(480, 240) self.setMaximumSize(640, 2048) self.setWindowIcon(QIcon.fromTheme("preferences-system")) self.center() QShortcut("Ctrl+q", self, activated=lambda: self.close()) self.menuBar().addMenu("&File").addAction("Exit", exit) windowMenu = self.menuBar().addMenu("&Window") windowMenu.addAction("Minimize", lambda: self.showMinimized()) windowMenu.addAction("Maximize", lambda: self.showMaximized()) windowMenu.addAction("Restore", lambda: self.showNormal()) windowMenu.addAction("FullScreen", lambda: self.showFullScreen()) windowMenu.addAction("Center", lambda: self.center()) windowMenu.addAction("Top-Left", lambda: self.move(0, 0)) windowMenu.addAction("To Mouse", lambda: self.move_to_mouse_position()) windowMenu.addSeparator() windowMenu.addAction( "Increase size", lambda: self.resize(self.size().width() * 1.4, self.size().height() * 1.4)) windowMenu.addAction("Decrease size", lambda: self.resize( self.size().width() // 1.4, self.size().height() // 1.4)) windowMenu.addAction("Minimum size", lambda: self.resize(self.minimumSize())) windowMenu.addAction("Maximum size", lambda: self.resize(self.maximumSize())) windowMenu.addAction("Horizontal Wide", lambda: self.resize( self.maximumSize().width(), self.minimumSize().height())) windowMenu.addAction("Vertical Tall", lambda: self.resize( self.minimumSize().width(), self.maximumSize().height())) windowMenu.addSeparator() windowMenu.addAction("Disable Resize", lambda: self.setFixedSize(self.size())) windowMenu.addAction("Set Interface Font...", lambda: self.setFont(QFontDialog.getFont()[0])) helpMenu = self.menuBar().addMenu("&Help") helpMenu.addAction("About Qt 5", lambda: QMessageBox.aboutQt(self)) helpMenu.addAction("About Python 3", lambda: open_new_tab('https://www.python.org')) helpMenu.addAction("About" + __doc__, lambda: QMessageBox.about(self, __doc__, HELP)) helpMenu.addSeparator() helpMenu.addAction( "Keyboard Shortcut", lambda: QMessageBox.information(self, __doc__, "<b>Quit = CTRL+Q")) helpMenu.addAction("View Source Code", lambda: call('xdg-open ' + __file__, shell=True)) helpMenu.addAction("View GitHub Repo", lambda: open_new_tab(__url__)) helpMenu.addAction("Report Bugs", lambda: open_new_tab( 'https://github.com/juancarlospaco/pyority/issues?state=open')) helpMenu.addAction("Check Updates", lambda: Downloader(self)) container, child_container = QWidget(), QWidget() container_layout = QVBoxLayout(container) child_layout = QHBoxLayout(child_container) self.setCentralWidget(container) # widgets group0 = QGroupBox("My Apps") group1, group2 = QGroupBox("CPU Priority"), QGroupBox("HDD Priority") child_layout.addWidget(group0) child_layout.addWidget(group1) child_layout.addWidget(group2) container_layout.addWidget(child_container) # table self.table = QTableWidget() self.table.setColumnCount(1) self.table.verticalHeader().setVisible(True) self.table.horizontalHeader().setVisible(False) self.table.setShowGrid(False) self.table.setAlternatingRowColors(True) self.table.setIconSize(QSize(64, 64)) self.table.setSelectionMode(QAbstractItemView.SingleSelection) self.table.setEditTriggers(QAbstractItemView.NoEditTriggers) # Graphic effect glow = QGraphicsDropShadowEffect(self) glow.setOffset(0) glow.setBlurRadius(9) glow.setColor(QColor(99, 255, 255)) self.table.setGraphicsEffect(glow) glow.setEnabled(True) processes = self.generate_process_list() self.table.setRowCount(len(processes)) for index, process in enumerate(processes): item = QTableWidgetItem( QIcon.fromTheme(process.name().split()[0].split('/')[0]), process.name().split()[0].split('/')[0].strip()) item.setData(Qt.UserRole, process) item.setToolTip("{}, {}, {}, {}".format( process.name(), process.nice(), process.ionice()[1], process.pid)) self.table.setItem(index, 0, item) self.table.clicked.connect(lambda: self.sliderhdd.setDisabled(False)) self.table.clicked.connect(lambda: self.slidercpu.setDisabled(False)) self.table.clicked.connect(lambda: self.slidercpu.setValue( int(tuple(self.table.currentItem().toolTip().split(","))[1]))) self.table.clicked.connect(lambda: self.sliderhdd.setValue( int(tuple(self.table.currentItem().toolTip().split(","))[2]))) self.table.resizeColumnsToContents() # self.table.resizeRowsToContents() # sliders self.slidercpu = QSlider() self.slidercpu.setRange(0, 19) self.slidercpu.setSingleStep(1) self.slidercpu.setTickPosition(3) self.slidercpu.setDisabled(True) self.slidercpu.setInvertedAppearance(True) self.slidercpu.setInvertedControls(True) self.slidercpu.valueChanged.connect(self.set_cpu_value) self.slidercpu.valueChanged.connect( lambda: self.slidercpu.setToolTip(str(self.slidercpu.value()))) # Timer to start self.slidercpu_timer = QTimer(self) self.slidercpu_timer.setSingleShot(True) self.slidercpu_timer.timeout.connect(self.on_slidercpu_timer_timeout) QLabel(self.slidercpu).setPixmap( QIcon.fromTheme("list-add").pixmap(16)) QVBoxLayout(group1).addWidget(self.slidercpu) self.sliderhdd = QSlider() self.sliderhdd.setRange(0, 7) self.sliderhdd.setSingleStep(1) self.sliderhdd.setTickPosition(3) self.sliderhdd.setDisabled(True) self.sliderhdd.setInvertedAppearance(True) self.sliderhdd.setInvertedControls(True) self.sliderhdd.valueChanged.connect(self.set_hdd_value) self.sliderhdd.valueChanged.connect( lambda: self.sliderhdd.setToolTip(str(self.sliderhdd.value()))) # Timer to start self.sliderhdd_timer = QTimer(self) self.sliderhdd_timer.setSingleShot(True) self.sliderhdd_timer.timeout.connect(self.on_sliderhdd_timer_timeout) QLabel(self.sliderhdd).setPixmap( QIcon.fromTheme("list-add").pixmap(16)) QVBoxLayout(group2).addWidget(self.sliderhdd) QVBoxLayout(group0).addWidget(self.table)
class ArrowAnnotation(Annotation): def __init__(self, parent=None, line=None, **kwargs): Annotation.__init__(self, parent, **kwargs) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFocusPolicy(Qt.ClickFocus) if line is None: line = QLineF(0, 0, 20, 0) self.__line = line self.__color = QColor(Qt.red) self.__arrowItem = ArrowItem(self) self.__arrowItem.setLine(line) self.__arrowItem.setBrush(self.__color) self.__arrowItem.setPen(QPen(Qt.NoPen)) self.__arrowItem.setArrowStyle(ArrowItem.Concave) self.__arrowItem.setLineWidth(5) self.__shadow = QGraphicsDropShadowEffect( blurRadius=5, offset=QPointF(1.0, 2.0), ) self.__arrowItem.setGraphicsEffect(self.__shadow) self.__shadow.setEnabled(True) self.__autoAdjustGeometry = True def setAutoAdjustGeometry(self, autoAdjust): """ If set to `True` then the geometry will be adjusted whenever the arrow is changed with `setLine`. Otherwise the geometry of the item is only updated so the `line` lies within the `geometry()` rect (i.e. it only grows). True by default """ self.__autoAdjustGeometry = autoAdjust if autoAdjust: self.adjustGeometry() def autoAdjustGeometry(self): """ Should the geometry of the item be adjusted automatically when `setLine` is called. """ return self.__autoAdjustGeometry def setLine(self, line): """ Set the arrow base line (a `QLineF` in object coordinates). """ if self.__line != line: self.__line = line # local item coordinate system geom = self.geometry().translated(-self.pos()) if geom.isNull() and not line.isNull(): geom = QRectF(0, 0, 1, 1) arrow_shape = arrow_path_concave(line, self.lineWidth()) arrow_rect = arrow_shape.boundingRect() if not (geom.contains(arrow_rect)): geom = geom.united(arrow_rect) if self.__autoAdjustGeometry: # Shrink the geometry if required. geom = geom.intersected(arrow_rect) # topLeft can move changing the local coordinates. diff = geom.topLeft() line = QLineF(line.p1() - diff, line.p2() - diff) self.__arrowItem.setLine(line) self.__line = line # parent item coordinate system geom.translate(self.pos()) self.setGeometry(geom) def line(self): """ Return the arrow base line (`QLineF` in object coordinates). """ return QLineF(self.__line) def setColor(self, color): """ Set arrow brush color. """ if self.__color != color: self.__color = QColor(color) self.__updateBrush() def color(self): """ Return the arrow brush color. """ return QColor(self.__color) def setLineWidth(self, lineWidth): """ Set the arrow line width. """ self.__arrowItem.setLineWidth(lineWidth) def lineWidth(self): """ Return the arrow line width. """ return self.__arrowItem.lineWidth() def adjustGeometry(self): """ Adjust the widget geometry to exactly fit the arrow inside while preserving the arrow path scene geometry. """ # local system coordinate geom = self.geometry().translated(-self.pos()) line = self.__line arrow_rect = self.__arrowItem.shape().boundingRect() if geom.isNull() and not line.isNull(): geom = QRectF(0, 0, 1, 1) if not (geom.contains(arrow_rect)): geom = geom.united(arrow_rect) geom = geom.intersected(arrow_rect) diff = geom.topLeft() line = QLineF(line.p1() - diff, line.p2() - diff) geom.translate(self.pos()) self.setGeometry(geom) self.setLine(line) def shape(self): arrow_shape = self.__arrowItem.shape() return self.mapFromItem(self.__arrowItem, arrow_shape) def itemChange(self, change, value): if change == QGraphicsItem.ItemSelectedHasChanged: self.__updateBrush() return Annotation.itemChange(self, change, value) def __updateBrush(self): """ Update the arrow brush. """ if self.isSelected(): color = self.__color.darker(150) else: color = self.__color self.__arrowItem.setBrush(color)
class MainWindow(QMainWindow): """Voice Changer main window.""" def __init__(self, parent=None): super(MainWindow, self).__init__() self.statusBar().showMessage("Move Dial to Deform Microphone Voice !.") self.setWindowTitle(__doc__) self.setMinimumSize(240, 240) self.setMaximumSize(480, 480) self.resize(self.minimumSize()) self.setWindowIcon(QIcon.fromTheme("audio-input-microphone")) self.tray = QSystemTrayIcon(self) self.center() QShortcut("Ctrl+q", self, activated=lambda: self.close()) self.menuBar().addMenu("&File").addAction("Quit", lambda: exit()) self.menuBar().addMenu("Sound").addAction( "STOP !", lambda: call('killall rec', shell=True)) windowMenu = self.menuBar().addMenu("&Window") windowMenu.addAction("Hide", lambda: self.hide()) windowMenu.addAction("Minimize", lambda: self.showMinimized()) windowMenu.addAction("Maximize", lambda: self.showMaximized()) windowMenu.addAction("Restore", lambda: self.showNormal()) windowMenu.addAction("FullScreen", lambda: self.showFullScreen()) windowMenu.addAction("Center", lambda: self.center()) windowMenu.addAction("Top-Left", lambda: self.move(0, 0)) windowMenu.addAction("To Mouse", lambda: self.move_to_mouse_position()) # widgets group0 = QGroupBox("Voice Deformation") self.setCentralWidget(group0) self.process = QProcess(self) self.process.error.connect( lambda: self.statusBar().showMessage("Info: Process Killed", 5000)) self.control = QDial() self.control.setRange(-10, 20) self.control.setSingleStep(5) self.control.setValue(0) self.control.setCursor(QCursor(Qt.OpenHandCursor)) self.control.sliderPressed.connect( lambda: self.control.setCursor(QCursor(Qt.ClosedHandCursor))) self.control.sliderReleased.connect( lambda: self.control.setCursor(QCursor(Qt.OpenHandCursor))) self.control.valueChanged.connect( lambda: self.control.setToolTip(f"<b>{self.control.value()}")) self.control.valueChanged.connect( lambda: self.statusBar().showMessage( f"Voice deformation: {self.control.value()}", 5000)) self.control.valueChanged.connect(self.run) self.control.valueChanged.connect(lambda: self.process.kill()) # Graphic effect self.glow = QGraphicsDropShadowEffect(self) self.glow.setOffset(0) self.glow.setBlurRadius(99) self.glow.setColor(QColor(99, 255, 255)) self.control.setGraphicsEffect(self.glow) self.glow.setEnabled(False) # Timer to start self.slider_timer = QTimer(self) self.slider_timer.setSingleShot(True) self.slider_timer.timeout.connect(self.on_slider_timer_timeout) # an icon and set focus QLabel(self.control).setPixmap( QIcon.fromTheme("audio-input-microphone").pixmap(32)) self.control.setFocus() QVBoxLayout(group0).addWidget(self.control) self.menu = QMenu(__doc__) self.menu.addAction(__doc__).setDisabled(True) self.menu.setIcon(self.windowIcon()) self.menu.addSeparator() self.menu.addAction( "Show / Hide", lambda: self.hide() if self.isVisible() else self.showNormal()) self.menu.addAction("STOP !", lambda: call('killall rec', shell=True)) self.menu.addSeparator() self.menu.addAction("Quit", lambda: exit()) self.tray.setContextMenu(self.menu) self.make_trayicon() def run(self): """Run/Stop the QTimer.""" if self.slider_timer.isActive(): self.slider_timer.stop() self.glow.setEnabled(True) call('killall rec ; killall play', shell=True) self.slider_timer.start(3000) def on_slider_timer_timeout(self): """Run subprocess to deform voice.""" self.glow.setEnabled(False) value = int(self.control.value()) * 100 command = f'play -q -V0 "|rec -q -V0 -n -d -R riaa bend pitch {value} "' print(f"Voice Deformation Value: {value}") print(f"Voice Deformation Command: {command}") self.process.start(command) if self.isVisible(): self.statusBar().showMessage("Minimizing to System TrayIcon", 3000) print("Minimizing Main Window to System TrayIcon now...") sleep(3) self.hide() def center(self): """Center Window on the Current Screen,with Multi-Monitor support.""" window_geometry = self.frameGeometry() mousepointer_position = QApplication.desktop().cursor().pos() screen = QApplication.desktop().screenNumber(mousepointer_position) centerPoint = QApplication.desktop().screenGeometry(screen).center() window_geometry.moveCenter(centerPoint) self.move(window_geometry.topLeft()) def move_to_mouse_position(self): """Center the Window on the Current Mouse position.""" window_geometry = self.frameGeometry() window_geometry.moveCenter(QApplication.desktop().cursor().pos()) self.move(window_geometry.topLeft()) def make_trayicon(self): """Make a Tray Icon.""" if self.windowIcon() and __doc__: self.tray.setIcon(self.windowIcon()) self.tray.setToolTip(__doc__) self.tray.activated.connect( lambda: self.hide() if self.isVisible() else self.showNormal()) return self.tray.show()
class MainWindow(QMainWindow): """Voice Changer main window.""" def __init__(self, parent=None): super(MainWindow, self).__init__() self.statusBar().showMessage("Move Dial to Deform Microphone Voice !.") self.setWindowTitle(__doc__) self.setMinimumSize(240, 240) self.setMaximumSize(480, 480) self.resize(self.minimumSize()) self.setWindowIcon(QIcon.fromTheme("audio-input-microphone")) self.tray = QSystemTrayIcon(self) self.center() QShortcut("Ctrl+q", self, activated=lambda: self.close()) self.menuBar().addMenu("&File").addAction("Quit", lambda: exit()) self.menuBar().addMenu("Sound").addAction( "STOP !", lambda: call('killall rec', shell=True)) windowMenu = self.menuBar().addMenu("&Window") windowMenu.addAction("Hide", lambda: self.hide()) windowMenu.addAction("Minimize", lambda: self.showMinimized()) windowMenu.addAction("Maximize", lambda: self.showMaximized()) windowMenu.addAction("Restore", lambda: self.showNormal()) windowMenu.addAction("FullScreen", lambda: self.showFullScreen()) windowMenu.addAction("Center", lambda: self.center()) windowMenu.addAction("Top-Left", lambda: self.move(0, 0)) windowMenu.addAction("To Mouse", lambda: self.move_to_mouse_position()) # widgets group0 = QGroupBox("Voice Deformation") self.setCentralWidget(group0) self.process = QProcess(self) self.process.error.connect( lambda: self.statusBar().showMessage("Info: Process Killed", 5000)) self.control = QDial() self.control.setRange(-10, 20) self.control.setSingleStep(5) self.control.setValue(0) self.control.setCursor(QCursor(Qt.OpenHandCursor)) self.control.sliderPressed.connect( lambda: self.control.setCursor(QCursor(Qt.ClosedHandCursor))) self.control.sliderReleased.connect( lambda: self.control.setCursor(QCursor(Qt.OpenHandCursor))) self.control.valueChanged.connect( lambda: self.control.setToolTip("<b>" + str(self.control.value()))) self.control.valueChanged.connect(lambda: self.statusBar().showMessage( "Voice deformation: " + str(self.control.value()), 5000)) self.control.valueChanged.connect(self.run) self.control.valueChanged.connect(lambda: self.process.kill()) # Graphic effect self.glow = QGraphicsDropShadowEffect(self) self.glow.setOffset(0) self.glow.setBlurRadius(99) self.glow.setColor(QColor(99, 255, 255)) self.control.setGraphicsEffect(self.glow) self.glow.setEnabled(False) # Timer to start self.slider_timer = QTimer(self) self.slider_timer.setSingleShot(True) self.slider_timer.timeout.connect(self.on_slider_timer_timeout) # an icon and set focus QLabel(self.control).setPixmap( QIcon.fromTheme("audio-input-microphone").pixmap(32)) self.control.setFocus() QVBoxLayout(group0).addWidget(self.control) self.menu = QMenu(__doc__) self.menu.addAction(__doc__).setDisabled(True) self.menu.setIcon(self.windowIcon()) self.menu.addSeparator() self.menu.addAction( "Show / Hide", lambda: self.hide() if self.isVisible() else self.showNormal()) self.menu.addAction("STOP !", lambda: call('killall rec', shell=True)) self.menu.addSeparator() self.menu.addAction("Quit", lambda: exit()) self.tray.setContextMenu(self.menu) self.make_trayicon() def run(self): """Run/Stop the QTimer.""" if self.slider_timer.isActive(): self.slider_timer.stop() self.glow.setEnabled(True) call('killall rec', shell=True) self.slider_timer.start(3000) def on_slider_timer_timeout(self): """Run subprocess to deform voice.""" self.glow.setEnabled(False) value = int(self.control.value()) * 100 cmd = 'play -q -V0 "|rec -q -V0 -n -d -R riaa bend pitch {0} "' command = cmd.format(int(value)) log.debug("Voice Deformation Value: {0}".format(value)) log.debug("Voice Deformation Command: {0}".format(command)) self.process.start(command) if self.isVisible(): self.statusBar().showMessage("Minimizing to System TrayIcon", 3000) log.debug("Minimizing Main Window to System TrayIcon now...") sleep(3) self.hide() def center(self): """Center Window on the Current Screen,with Multi-Monitor support.""" window_geometry = self.frameGeometry() mousepointer_position = QApplication.desktop().cursor().pos() screen = QApplication.desktop().screenNumber(mousepointer_position) centerPoint = QApplication.desktop().screenGeometry(screen).center() window_geometry.moveCenter(centerPoint) self.move(window_geometry.topLeft()) def move_to_mouse_position(self): """Center the Window on the Current Mouse position.""" window_geometry = self.frameGeometry() window_geometry.moveCenter(QApplication.desktop().cursor().pos()) self.move(window_geometry.topLeft()) def make_trayicon(self): """Make a Tray Icon.""" if self.windowIcon() and __doc__: self.tray.setIcon(self.windowIcon()) self.tray.setToolTip(__doc__) self.tray.activated.connect( lambda: self.hide() if self.isVisible() else self.showNormal()) return self.tray.show()
class RoundedPushButton(QAbstractButton): def __init__(self, parent=None, *, text: str = '', icon: QIcon = None, radius: int = 20, background_color: QColor or str = 'white'): self._radius = radius self._text = text self._icon = icon if isinstance(background_color, str): if background_color == 'transparent': background_color = QColor(0, 0, 0, 0) else: background_color = QColor(background_color) self._background_color = background_color super().__init__(parent) self.__init_shadow__() self._pressed = False if self._icon: self.setFixedSize(self._radius, self._radius) def __init_shadow__(self): self.shadow = QGraphicsDropShadowEffect() self.shadow.setBlurRadius(self._radius) self.shadow.setXOffset(3) self.shadow.setYOffset(3) self.setGraphicsEffect(self.shadow) def _get_painter(self): painter = QPainter(self) brush = QBrush() brush.setColor(self._background_color) brush.setStyle(Qt.SolidPattern) painter.setBrush(brush) painter.setPen(Qt.NoPen) painter.setRenderHint(QPainter.Antialiasing) return painter def paintEvent(self, QPaintEvent): painter = self._get_painter() # TODO: fix icon position and size bug when pressed if self._pressed: rect = QRect(0, 3, painter.device().width(), int(painter.device().height() * 0.9)) else: rect = QRect(0, 0, painter.device().width(), painter.device().height()) painter.drawRoundedRect(rect, self._radius, self._radius) if self._icon: pixmap = self._icon.pixmap(self.size()) painter.drawPixmap(0, 0, pixmap) def mousePressEvent(self, QMouseEvent): super().mousePressEvent(QMouseEvent) if QMouseEvent.button() == Qt.LeftButton: self._pressed = True self.shadow.setEnabled(False) def mouseReleaseEvent(self, QMouseEvent): self._pressed = False super().mouseReleaseEvent(QMouseEvent) self.shadow.setEnabled(True) self.shadow.setBlurRadius(self._radius)
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.configOptions, self.checkBoxList, self.configBool = {}, {}, None # Check for root privileges if geteuid() != 0: msg = ("{} is not root. You need to run with root priviliges\n" "Please use kdesudo, gksu or sudo/sux.").format(getuser()) QMessageBox.critical(self, __doc__ + "- Error", msg) sys.exit(1) else: msg = "This tool is running with root priviliges." QMessageBox.warning(self, __doc__ + "- Warning", msg) # title, icon and sizes self.setWindowTitle(__doc__) self.setMinimumSize(400, 400) self.setMaximumSize(2048, 2048) self.resize(600, 600) self.setWindowIcon(QIcon.fromTheme("preferences-system")) self.menuBar().addMenu("&File").addAction("Exit", exit) QShortcut("Ctrl+q", self, activated=lambda: self.close()) # main group main_group = QGroupBox("Module configuration") self.setCentralWidget(main_group) self.layout = QVBoxLayout(main_group) # scrollarea widgets self.scrollArea, self.window = QScrollArea(), QWidget() self.layout.addWidget(self.scrollArea) self.vbox = QVBoxLayout(self.window) # Graphic effect glow = QGraphicsDropShadowEffect(self) glow.setOffset(0) glow.setBlurRadius(99) glow.setColor(QColor(99, 255, 255)) self.scrollArea.setGraphicsEffect(glow) glow.setEnabled(True) # config loading stuff self.findConfig(CONFIG_DIR) for eachOption in tuple(self.configOptions.keys()): self.readConfig(eachOption, self.configOptions) self.subLayout = QHBoxLayout() self.checkBoxName = "checkBox_" + eachOption checkBoxList = QCheckBox(self.checkBoxName, self) self.checkBoxList[self.checkBoxName] = checkBoxList checkBoxList.setObjectName(self.checkBoxName) checkBoxList.setText("Enable module {}".format(eachOption)) if self.tooltip is not '': checkBoxList.setToolTip(self.tooltip) else: tooltip = "Configuration settings for {}".format(eachOption) checkBoxList.setToolTip(tooltip) if self.configBool: checkBoxList.setChecked(True) self.subLayout.addWidget(checkBoxList) self.vbox.addLayout(self.subLayout) self.scrollArea.setWidget(self.window) # Bottom Buttons Bar self.pushButtonSleep = QPushButton("Sleep") self.pushButtonSleep.setToolTip("Trigger Suspend to RAM aka Sleep") self.pushButtonSleep.clicked.connect(self.sleep) self.pushButtonHibernate = QPushButton("Hibernate") self.pushButtonHibernate.setToolTip("Trigger Suspend to Disk Hibernate") self.pushButtonHibernate.clicked.connect(self.hibernate) self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Close | QDialogButtonBox.Help) self.buttonBox.addButton(self.pushButtonHibernate, QDialogButtonBox.ActionRole) self.buttonBox.addButton(self.pushButtonSleep, QDialogButtonBox.ActionRole) self.layout.addWidget(self.buttonBox) self.buttonBox.rejected.connect(exit) self.buttonBox.accepted.connect(self.writeConfig) self.buttonBox.helpRequested.connect(lambda: open_new_tab(WEBPAGE_URL))
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.configOptions, self.checkBoxList, self.configBool = {}, {}, None # Check for root privileges if geteuid() != 0: msg = ("{} is not root. You need to run with root priviliges\n" "Please use kdesudo, gksu or sudo/sux.").format(getuser()) QMessageBox.critical(self, __doc__ + "- Error", msg) sys.exit(1) else: msg = "This tool is running with root priviliges." QMessageBox.warning(self, __doc__ + "- Warning", msg) # title, icon and sizes self.setWindowTitle(__doc__) self.setMinimumSize(400, 400) self.setMaximumSize(2048, 2048) self.resize(600, 600) self.setWindowIcon(QIcon.fromTheme("preferences-system")) self.menuBar().addMenu("&File").addAction("Exit", exit) QShortcut("Ctrl+q", self, activated=lambda: self.close()) # main group main_group = QGroupBox("Module configuration") self.setCentralWidget(main_group) self.layout = QVBoxLayout(main_group) # scrollarea widgets self.scrollArea, self.window = QScrollArea(), QWidget() self.layout.addWidget(self.scrollArea) self.vbox = QVBoxLayout(self.window) # Graphic effect glow = QGraphicsDropShadowEffect(self) glow.setOffset(0) glow.setBlurRadius(99) glow.setColor(QColor(99, 255, 255)) self.scrollArea.setGraphicsEffect(glow) glow.setEnabled(True) # config loading stuff self.findConfig(CONFIG_DIR) for eachOption in tuple(self.configOptions.keys()): self.readConfig(eachOption, self.configOptions) self.subLayout = QHBoxLayout() self.checkBoxName = "checkBox_" + eachOption checkBoxList = QCheckBox(self.checkBoxName, self) self.checkBoxList[self.checkBoxName] = checkBoxList checkBoxList.setObjectName(self.checkBoxName) checkBoxList.setText("Enable module {}".format(eachOption)) if self.tooltip is not '': checkBoxList.setToolTip(self.tooltip) else: tooltip = "Configuration settings for {}".format(eachOption) checkBoxList.setToolTip(tooltip) if self.configBool: checkBoxList.setChecked(True) self.subLayout.addWidget(checkBoxList) self.vbox.addLayout(self.subLayout) self.scrollArea.setWidget(self.window) # Bottom Buttons Bar self.pushButtonSleep = QPushButton("Sleep") self.pushButtonSleep.setToolTip("Trigger Suspend to RAM aka Sleep") self.pushButtonSleep.clicked.connect(self.sleep) self.pushButtonHibernate = QPushButton("Hibernate") self.pushButtonHibernate.setToolTip( "Trigger Suspend to Disk Hibernate") self.pushButtonHibernate.clicked.connect(self.hibernate) self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Close | QDialogButtonBox.Help) self.buttonBox.addButton(self.pushButtonHibernate, QDialogButtonBox.ActionRole) self.buttonBox.addButton(self.pushButtonSleep, QDialogButtonBox.ActionRole) self.layout.addWidget(self.buttonBox) self.buttonBox.rejected.connect(exit) self.buttonBox.accepted.connect(self.writeConfig) self.buttonBox.helpRequested.connect(lambda: open_new_tab(WEBPAGE_URL))
class LinkCurveItem(QGraphicsPathItem): """ Link curve item. The main component of a :class:`LinkItem`. """ def __init__(self, parent): QGraphicsPathItem.__init__(self, parent) if not isinstance(parent, LinkItem): raise TypeError("'LinkItem' expected") self.setAcceptedMouseButtons(Qt.NoButton) self.__canvasLink = parent self.setAcceptHoverEvents(True) self.shadow = QGraphicsDropShadowEffect(blurRadius=5, color=QColor(SHADOW_COLOR), offset=QPointF(0, 0)) self.normalPen = QPen(QBrush(QColor("#9CACB4")), 2.0) self.hoverPen = QPen(QBrush(QColor("#7D7D7D")), 2.1) self.setPen(self.normalPen) self.setGraphicsEffect(self.shadow) self.shadow.setEnabled(False) self.__hover = False self.__enabled = True self.__shape = None def linkItem(self): """ Return the :class:`LinkItem` instance this curve belongs to. """ return self.__canvasLink def setHoverState(self, state): self.prepareGeometryChange() self.__shape = None self.__hover = state self.__update() def setLinkEnabled(self, state): self.prepareGeometryChange() self.__shape = None self.__enabled = state self.__update() def isLinkEnabled(self): return self.__enabled def setCurvePenSet(self, pen, hoverPen): self.prepareGeometryChange() if pen is not None: self.normalPen = pen if hoverPen is not None: self.hoverPen = hoverPen self.__shape = None self.__update() def shape(self): if self.__shape is None: path = self.path() pen = QPen(self.pen()) pen.setWidthF(max(pen.widthF(), 7.0)) pen.setStyle(Qt.SolidLine) self.__shape = stroke_path(path, pen) return self.__shape def setPath(self, path): self.__shape = None QGraphicsPathItem.setPath(self, path) def __update(self): shadow_enabled = self.__hover if self.shadow.isEnabled() != shadow_enabled: self.shadow.setEnabled(shadow_enabled) link_enabled = self.__enabled if link_enabled: pen_style = Qt.SolidLine else: pen_style = Qt.DashLine if self.__hover: pen = self.hoverPen else: pen = self.normalPen pen.setStyle(pen_style) self.setPen(pen)
class Ui_MainWindow(object): def setupUi(self, MainWindow): self.s = None self.shadow = QGraphicsDropShadowEffect(blurRadius=18, offset=QPointF(0.0, 0.0), color=QColor("#009dff")) self.btnShadow1 = QGraphicsDropShadowEffect(blurRadius=20, offset=QPointF(0.0, 0.0), color=QColor("#e5ff00")) self.btnShadow2 = QGraphicsDropShadowEffect(blurRadius=20, offset=QPointF(0.0, 0.0), color=QColor("#077a05")) self.btnShadow3 = QGraphicsDropShadowEffect(blurRadius=20, offset=QPointF(0.0, 0.0), color=QColor("#ff1500")) # Setting Database self.sdb = SettingsDatabase() # Thresh Hold value self.thresh = self.sdb.get_sensitivity() # admin password self.passwd = self.sdb.get_password() # camera ip self.camera_ip = 0 # Style Sheet self.style_sheet = """ QPushButton{ border: 1px solid #009dff; border-radius :1px 5px 5px 1px; background-color:#ffffff; } QPushButton:hover{ background-color:#009dff; border-radius :15px; color: #ffffff; font-weight: 200; border-color: transparent; } QPushButton#btn_alarm,QPushButton#btn_start_system,QPushButton#bnt_stop_system{ border-radius :10px 15px 15px 10px; } QPushButton#btn_alarm:hover,QPushButton#btn_start_system:hover,QPushButton#bnt_stop_system:hover{ border-color:transparent; border-radius :20px 20px 50px 50px; } QPushButton#btn_alarm{ border: 1px solid #e5ff00; } QPushButton#btn_start_system{ border: 1px solid #3dfc03; } QPushButton#bnt_stop_system{ border: 1px solid #fc7844; } QPushButton#btn_github:hover{ background-color:#000000; color:#ffffff; } QPushButton#btn_apppage:hover{ background-color:#6d1bfa; color:#ffffff; } QPushButton#btn_blog:hover{ background-color:#fa691b; color:#ffffff; } QLineEdit{ border: 1px solid #009dff; border-radius: 10px; } #toolBox{ background-color : #d4eeff; border: 1px solid #032473; } """ MainWindow.setObjectName("MainWindow") MainWindow.resize(640, 480) MainWindow.setMinimumSize(QtCore.QSize(640, 480)) MainWindow.setMaximumSize(QtCore.QSize(640, 480)) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("Assets/PNGs/camera.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded) MainWindow.setDockNestingEnabled(True) MainWindow.setUnifiedTitleAndToolBarOnMac(True) MainWindow.setGraphicsEffect(self.shadow) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.tab_group = QtWidgets.QTabWidget(self.centralwidget) self.tab_group.setGeometry(QtCore.QRect(10, 0, 621, 431)) self.tab_group.setObjectName("tab_group") self.tab_group.setGraphicsEffect(self.shadow) self.shadow.setEnabled(True) self.tab_home = QtWidgets.QWidget() self.tab_home.setObjectName("tab_home") self.frame_home = QtWidgets.QFrame(self.tab_home) self.frame_home.setGeometry(QtCore.QRect(-10, -10, 631, 411)) self.frame_home.setStyleSheet("") self.frame_home.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_home.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_home.setObjectName("frame_home") self.btn_alarm = QtWidgets.QPushButton(self.frame_home) self.btn_alarm.setGeometry(QtCore.QRect(440, 180, 161, 41)) self.btn_alarm.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.btn_alarm.setAutoFillBackground(False) icon1 = QtGui.QIcon() icon1.addPixmap( QtGui.QPixmap(":/PICTURES/PNGs/Icon-material-access-alarm.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.btn_alarm.setIcon(icon1) self.btn_alarm.setIconSize(QtCore.QSize(32, 32)) self.btn_alarm.setAutoRepeat(False) self.btn_alarm.setAutoDefault(False) self.btn_alarm.setDefault(False) self.btn_alarm.setFlat(False) self.btn_alarm.setObjectName("btn_alarm") self.btn_alarm.setGraphicsEffect(self.btnShadow1) self.btn_start_system = QtWidgets.QPushButton(self.frame_home) self.btn_start_system.setGeometry(QtCore.QRect(440, 240, 161, 41)) self.btn_start_system.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.btn_start_system.setAutoFillBackground(False) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/home/32x32/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.btn_start_system.setIcon(icon2) self.btn_start_system.setIconSize(QtCore.QSize(48, 48)) self.btn_start_system.setAutoRepeat(False) self.btn_start_system.setAutoDefault(False) self.btn_start_system.setDefault(False) self.btn_start_system.setFlat(False) self.btn_start_system.setObjectName("btn_start_system") self.btn_start_system.setGraphicsEffect(self.btnShadow2) self.home_picture = QtWidgets.QLabel(self.frame_home) self.home_picture.setGeometry(QtCore.QRect(20, 40, 371, 321)) self.home_picture.setText("") self.home_picture.setPixmap( QtGui.QPixmap(":/PICTURES/PNGs/Group 9.png")) self.home_picture.setScaledContents(True) self.home_picture.setObjectName("home_picture") self.bnt_stop_system = QtWidgets.QPushButton(self.frame_home) self.bnt_stop_system.setGeometry(QtCore.QRect(440, 300, 161, 41)) self.bnt_stop_system.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.bnt_stop_system.setLayoutDirection(QtCore.Qt.LeftToRight) self.bnt_stop_system.setAutoFillBackground(False) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/All/32x32/busy.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.bnt_stop_system.setIcon(icon3) self.bnt_stop_system.setIconSize(QtCore.QSize(48, 48)) self.bnt_stop_system.setAutoRepeat(False) self.bnt_stop_system.setAutoDefault(False) self.bnt_stop_system.setDefault(False) self.bnt_stop_system.setFlat(False) self.bnt_stop_system.setObjectName("bnt_stop_system") self.bnt_stop_system.setGraphicsEffect(self.btnShadow3) self.logo = QtWidgets.QLabel(self.frame_home) self.logo.setGeometry(QtCore.QRect(370, 40, 251, 91)) self.logo.setText("") self.logo.setPixmap(QtGui.QPixmap(":/PICTURES/PNGs/logo.png")) self.logo.setScaledContents(True) self.logo.setObjectName("logo") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/home/32x32/home.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tab_group.addTab(self.tab_home, icon4, "") self.tab_settings = QtWidgets.QWidget() self.tab_settings.setObjectName("tab_settings") self.frame_settings = QtWidgets.QFrame(self.tab_settings) self.frame_settings.setGeometry(QtCore.QRect(10, -10, 631, 411)) self.frame_settings.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_settings.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_settings.setObjectName("frame_settings") self.toolBox = QtWidgets.QToolBox(self.frame_settings) self.toolBox.setGeometry(QtCore.QRect(20, 40, 411, 311)) font = QtGui.QFont() font.setPointSize(12) self.toolBox.setFont(font) self.toolBox.setFrameShape(QtWidgets.QFrame.NoFrame) self.toolBox.setObjectName("toolBox") self.page = QtWidgets.QWidget() self.page.setGeometry(QtCore.QRect(0, 0, 411, 212)) self.page.setObjectName("page") self.label_2 = QtWidgets.QLabel(self.page) self.label_2.setGeometry(QtCore.QRect(20, 20, 141, 31)) self.label_2.setFrameShape(QtWidgets.QFrame.NoFrame) self.label_2.setObjectName("label_2") self.ip_input = QtWidgets.QLineEdit(self.page) self.ip_input.setGeometry(QtCore.QRect(170, 20, 231, 31)) self.ip_input.setObjectName("ip_input") self.label_4 = QtWidgets.QLabel(self.page) self.label_4.setGeometry(QtCore.QRect(20, 120, 141, 31)) self.label_4.setFrameShape(QtWidgets.QFrame.NoFrame) self.label_4.setObjectName("label_4") self.layoutWidget = QtWidgets.QWidget(self.page) self.layoutWidget.setGeometry(QtCore.QRect(170, 120, 231, 31)) self.layoutWidget.setObjectName("layoutWidget") self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget) self.horizontalLayout_3.setSizeConstraint( QtWidgets.QLayout.SetNoConstraint) self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_3.setSpacing(3) self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.threshOP_low = QtWidgets.QLabel(self.layoutWidget) self.threshOP_low.setEnabled(True) font = QtGui.QFont() font.setFamily("Lucida Sans Unicode") self.threshOP_low.setFont(font) self.threshOP_low.setFrameShape(QtWidgets.QFrame.NoFrame) self.threshOP_low.setAlignment(QtCore.Qt.AlignCenter) self.threshOP_low.setObjectName("threshOP_low") self.horizontalLayout_3.addWidget(self.threshOP_low) self.threshIN = QtWidgets.QSlider(self.layoutWidget) self.threshIN.setMouseTracking(False) self.threshIN.setMinimum(1) self.threshIN.setMaximum(500) self.threshIN.setOrientation(QtCore.Qt.Horizontal) self.threshIN.setTickPosition(QtWidgets.QSlider.TicksAbove) self.threshIN.setObjectName("threshIN") self.threshIN.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.horizontalLayout_3.addWidget(self.threshIN) self.threshOP_high = QtWidgets.QLabel(self.layoutWidget) self.threshOP_high.setEnabled(True) font = QtGui.QFont() font.setFamily("Lucida Sans Unicode") self.threshOP_high.setFont(font) self.threshOP_high.setFrameShape(QtWidgets.QFrame.NoFrame) self.threshOP_high.setAlignment(QtCore.Qt.AlignCenter) self.threshOP_high.setObjectName("threshOP_high") self.horizontalLayout_3.addWidget(self.threshOP_high) self.threshOP = QtWidgets.QLabel(self.layoutWidget) self.threshOP.setEnabled(True) font = QtGui.QFont() font.setFamily("Lucida Sans Unicode") self.threshOP.setFont(font) self.threshOP.setFrameShape(QtWidgets.QFrame.Panel) self.threshOP.setFrameShadow(QtWidgets.QFrame.Raised) self.threshOP.setAlignment(QtCore.Qt.AlignCenter) self.threshOP.setObjectName("threshOP") self.horizontalLayout_3.addWidget(self.threshOP) self.btn_reset_thresh = QtWidgets.QPushButton(self.page) self.btn_reset_thresh.setGeometry(QtCore.QRect(240, 160, 111, 31)) font = QtGui.QFont() font.setPointSize(10) self.btn_reset_thresh.setFont(font) self.btn_reset_thresh.setObjectName("btn_reset_thresh") self.btn_reset_thresh.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.btn_ip = QtWidgets.QPushButton(self.page) self.btn_ip.setGeometry(QtCore.QRect(240, 60, 111, 31)) self.btn_ip.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(10) self.btn_ip.setFont(font) self.btn_ip.setObjectName("btn_ip") self.line = QtWidgets.QFrame(self.page) self.line.setGeometry(QtCore.QRect(10, 100, 391, 16)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.line_2 = QtWidgets.QFrame(self.page) self.line_2.setGeometry(QtCore.QRect(0, 200, 411, 16)) self.line_2.setFrameShape(QtWidgets.QFrame.HLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_2.setObjectName("line_2") icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/PICTURES/PNGs/camera-vector.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolBox.addItem(self.page, icon5, "") self.page_2 = QtWidgets.QWidget() self.page_2.setGeometry(QtCore.QRect(0, 0, 411, 212)) self.page_2.setObjectName("page_2") self.label_3 = QtWidgets.QLabel(self.page_2) self.label_3.setGeometry(QtCore.QRect(20, 10, 141, 31)) self.label_3.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label_3.setObjectName("label_3") self.mobile_in = QtWidgets.QLineEdit(self.page_2) self.mobile_in.setGeometry(QtCore.QRect(170, 10, 231, 31)) self.mobile_in.setObjectName("mobile_in") self.label_5 = QtWidgets.QLabel(self.page_2) self.label_5.setGeometry(QtCore.QRect(20, 60, 141, 31)) self.label_5.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label_5.setObjectName("label_5") self.msg_in = QtWidgets.QLineEdit(self.page_2) self.msg_in.setGeometry(QtCore.QRect(170, 60, 231, 31)) self.msg_in.setObjectName("msg_in") self.label_6 = QtWidgets.QLabel(self.page_2) self.label_6.setGeometry(QtCore.QRect(20, 110, 141, 31)) self.label_6.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label_6.setObjectName("label_6") self.email_in = QtWidgets.QLineEdit(self.page_2) self.email_in.setGeometry(QtCore.QRect(170, 110, 231, 31)) self.email_in.setObjectName("email_in") self.line_3 = QtWidgets.QFrame(self.page_2) self.line_3.setGeometry(QtCore.QRect(0, 200, 411, 16)) self.line_3.setFrameShape(QtWidgets.QFrame.HLine) self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_3.setObjectName("line_3") icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap(":/All/32x32/future-projects.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolBox.addItem(self.page_2, icon6, "") self.page_3 = QtWidgets.QWidget() self.page_3.setObjectName("page_3") self.label_7 = QtWidgets.QLabel(self.page_3) self.label_7.setGeometry(QtCore.QRect(10, 10, 141, 31)) self.label_7.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label_7.setObjectName("label_7") self.pass_in = QtWidgets.QLineEdit(self.page_3) self.pass_in.setGeometry(QtCore.QRect(160, 10, 231, 31)) self.pass_in.setObjectName("pass_in") self.line_4 = QtWidgets.QFrame(self.page_3) self.line_4.setGeometry(QtCore.QRect(0, 170, 411, 16)) self.line_4.setFrameShape(QtWidgets.QFrame.HLine) self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_4.setObjectName("line_4") icon7 = QtGui.QIcon() icon7.addPixmap(QtGui.QPixmap(":/All/32x32/lock.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolBox.addItem(self.page_3, icon7, "") self.btn_setting_save = QtWidgets.QPushButton(self.frame_settings) self.btn_setting_save.setGeometry(QtCore.QRect(450, 270, 141, 51)) font = QtGui.QFont() font.setPointSize(12) font.setBold(False) font.setItalic(False) font.setWeight(50) self.btn_setting_save.setFont(font) self.btn_setting_save.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) icon8 = QtGui.QIcon() icon8.addPixmap(QtGui.QPixmap(":/All/32x32/check.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.btn_setting_save.setIcon(icon8) self.btn_setting_save.setObjectName("btn_setting_save") self.btn_settings_reset = QtWidgets.QPushButton(self.frame_settings) self.btn_settings_reset.setGeometry(QtCore.QRect(450, 200, 141, 51)) font = QtGui.QFont() font.setPointSize(12) font.setBold(False) font.setItalic(False) font.setWeight(50) self.btn_settings_reset.setFont(font) self.btn_settings_reset.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.btn_settings_reset.setObjectName("btn_settings_reset") self.label_8 = QtWidgets.QLabel(self.frame_settings) self.label_8.setGeometry(QtCore.QRect(30, 370, 551, 31)) font = QtGui.QFont() font.setPointSize(12) self.label_8.setFont(font) self.label_8.setObjectName("label_8") self.label_9 = QtWidgets.QLabel(self.frame_settings) self.label_9.setGeometry(QtCore.QRect(450, 60, 151, 91)) self.label_9.setText("") self.label_9.setPixmap(QtGui.QPixmap(":/PICTURES/PNGs/Group 10.png")) self.label_9.setScaledContents(True) self.label_9.setObjectName("label_9") icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap(":/settings/32x32/config.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tab_group.addTab(self.tab_settings, icon9, "") self.tab_about = QtWidgets.QWidget() self.tab_about.setObjectName("tab_about") self.frame_about = QtWidgets.QFrame(self.tab_about) self.frame_about.setGeometry(QtCore.QRect(-10, -10, 631, 421)) self.frame_about.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_about.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_about.setObjectName("frame_about") self.btn_github = QtWidgets.QPushButton(self.frame_about) self.btn_github.setGeometry(QtCore.QRect(420, 300, 81, 31)) self.btn_github.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_github.setFont(font) self.btn_github.setObjectName("btn_github") self.label = QtWidgets.QLabel(self.frame_about) self.label.setGeometry(QtCore.QRect(400, 20, 211, 211)) self.label.setText("") self.label.setPixmap( QtGui.QPixmap(":/PICTURES/Pictures/vikas_icon.jpg")) self.label.setScaledContents(True) self.label.setObjectName("label") self.textEdit = QtWidgets.QTextEdit(self.frame_about) self.textEdit.setGeometry(QtCore.QRect(20, 20, 371, 271)) font = QtGui.QFont() font.setPointSize(14) self.textEdit.setFont(font) self.textEdit.setObjectName("textEdit") self.textBrowser = QtWidgets.QTextBrowser(self.frame_about) self.textBrowser.setGeometry(QtCore.QRect(80, 240, 256, 71)) self.textBrowser.setObjectName("textBrowser") self.btn_twitter = QtWidgets.QPushButton(self.frame_about) self.btn_twitter.setGeometry(QtCore.QRect(516, 300, 81, 31)) self.btn_twitter.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_twitter.setFont(font) self.btn_twitter.setObjectName("btn_twitter") self.btn_blog = QtWidgets.QPushButton(self.frame_about) self.btn_blog.setGeometry(QtCore.QRect(420, 262, 81, 31)) self.btn_blog.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_blog.setFont(font) self.btn_blog.setObjectName("btn_blog") self.btn_apppage = QtWidgets.QPushButton(self.frame_about) self.btn_apppage.setGeometry(QtCore.QRect(516, 262, 81, 31)) self.btn_apppage.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_apppage.setFont(font) self.btn_apppage.setObjectName("btn_apppage") icon10 = QtGui.QIcon() icon10.addPixmap(QtGui.QPixmap(":/about-person/32x32/user.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tab_group.addTab(self.tab_about, icon10, "") self.tab_contact = QtWidgets.QWidget() self.tab_contact.setObjectName("tab_contact") self.frame_contact = QtWidgets.QFrame(self.tab_contact) self.frame_contact.setGeometry(QtCore.QRect(-10, -10, 631, 421)) self.frame_contact.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_contact.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_contact.setObjectName("frame_contact") self.groupBox = QtWidgets.QGroupBox(self.frame_contact) self.groupBox.setGeometry(QtCore.QRect(30, 30, 571, 71)) font = QtGui.QFont() font.setPointSize(12) self.groupBox.setFont(font) self.groupBox.setObjectName("groupBox") self.plainTextEdit = QtWidgets.QPlainTextEdit(self.groupBox) self.plainTextEdit.setGeometry(QtCore.QRect(60, 30, 261, 31)) self.plainTextEdit.setObjectName("plainTextEdit") self.btn_email = QtWidgets.QPushButton(self.groupBox) self.btn_email.setGeometry(QtCore.QRect(380, 30, 131, 31)) self.btn_email.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_email.setFont(font) self.btn_email.setObjectName("btn_email") self.groupBox_2 = QtWidgets.QGroupBox(self.frame_contact) self.groupBox_2.setGeometry(QtCore.QRect(30, 110, 571, 71)) font = QtGui.QFont() font.setPointSize(12) self.groupBox_2.setFont(font) self.groupBox_2.setObjectName("groupBox_2") self.plainTextEdit_2 = QtWidgets.QPlainTextEdit(self.groupBox_2) self.plainTextEdit_2.setGeometry(QtCore.QRect(60, 30, 261, 31)) self.plainTextEdit_2.setObjectName("plainTextEdit_2") self.btn_website = QtWidgets.QPushButton(self.groupBox_2) self.btn_website.setGeometry(QtCore.QRect(380, 30, 131, 31)) self.btn_website.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_website.setFont(font) self.btn_website.setObjectName("btn_website") self.groupBox_3 = QtWidgets.QGroupBox(self.frame_contact) self.groupBox_3.setGeometry(QtCore.QRect(30, 190, 571, 161)) font = QtGui.QFont() font.setPointSize(12) self.groupBox_3.setFont(font) self.groupBox_3.setObjectName("groupBox_3") self.plainTextEdit_3 = QtWidgets.QPlainTextEdit(self.groupBox_3) self.plainTextEdit_3.setGeometry(QtCore.QRect(60, 30, 261, 31)) self.plainTextEdit_3.setObjectName("plainTextEdit_3") self.btn_twitter_2 = QtWidgets.QPushButton(self.groupBox_3) self.btn_twitter_2.setGeometry(QtCore.QRect(380, 30, 131, 31)) self.btn_twitter_2.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_twitter_2.setFont(font) self.btn_twitter_2.setObjectName("btn_twitter_2") self.plainTextEdit_4 = QtWidgets.QPlainTextEdit(self.groupBox_3) self.plainTextEdit_4.setGeometry(QtCore.QRect(60, 70, 261, 31)) self.plainTextEdit_4.setObjectName("plainTextEdit_4") self.btn_github_2 = QtWidgets.QPushButton(self.groupBox_3) self.btn_github_2.setGeometry(QtCore.QRect(380, 70, 131, 31)) self.btn_github_2.setCursor(QtGui.QCursor( QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_github_2.setFont(font) self.btn_github_2.setObjectName("btn_github_2") self.btn_instamojo = QtWidgets.QPushButton(self.groupBox_3) self.btn_instamojo.setGeometry(QtCore.QRect(380, 110, 131, 31)) self.btn_instamojo.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_instamojo.setFont(font) self.btn_instamojo.setObjectName("btn_instamojo") self.plainTextEdit_5 = QtWidgets.QPlainTextEdit(self.groupBox_3) self.plainTextEdit_5.setGeometry(QtCore.QRect(60, 110, 261, 31)) self.plainTextEdit_5.setObjectName("plainTextEdit_5") icon11 = QtGui.QIcon() icon11.addPixmap(QtGui.QPixmap(":/home/32x32/contact.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tab_group.addTab(self.tab_contact, icon11, "") self.tab_donate = QtWidgets.QWidget() self.tab_donate.setObjectName("tab_donate") self.frame_donate = QtWidgets.QFrame(self.tab_donate) self.frame_donate.setGeometry(QtCore.QRect(-10, -10, 631, 421)) self.frame_donate.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_donate.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_donate.setObjectName("frame_donate") self.groupBox_4 = QtWidgets.QGroupBox(self.frame_donate) self.groupBox_4.setGeometry(QtCore.QRect(30, 40, 571, 71)) font = QtGui.QFont() font.setPointSize(12) self.groupBox_4.setFont(font) self.groupBox_4.setObjectName("groupBox_4") self.plainTextEdit_6 = QtWidgets.QPlainTextEdit(self.groupBox_4) self.plainTextEdit_6.setGeometry(QtCore.QRect(60, 30, 261, 31)) self.plainTextEdit_6.setObjectName("plainTextEdit_6") self.btn_paypal = QtWidgets.QPushButton(self.groupBox_4) self.btn_paypal.setGeometry(QtCore.QRect(380, 30, 131, 31)) self.btn_paypal.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) font = QtGui.QFont() font.setPointSize(12) self.btn_paypal.setFont(font) self.btn_paypal.setObjectName("btn_paypal") self.groupBox_5 = QtWidgets.QGroupBox(self.frame_donate) self.groupBox_5.setGeometry(QtCore.QRect(30, 130, 571, 71)) font = QtGui.QFont() font.setPointSize(12) self.groupBox_5.setFont(font) self.groupBox_5.setObjectName("groupBox_5") self.plainTextEdit_7 = QtWidgets.QPlainTextEdit(self.groupBox_5) self.plainTextEdit_7.setGeometry(QtCore.QRect(60, 30, 261, 31)) self.plainTextEdit_7.setObjectName("plainTextEdit_7") icon12 = QtGui.QIcon() icon12.addPixmap(QtGui.QPixmap(":/home/32x32/donate.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tab_group.addTab(self.tab_donate, icon12, "") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 23)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusBar = QtWidgets.QStatusBar(MainWindow) self.statusBar.setObjectName("statusBar") MainWindow.setStatusBar(self.statusBar) MainWindow.setStyleSheet(self.style_sheet) self.statusBar.showMessage( 'Services Started | Click Start System to Start the Serveillance System' ) """ bind buttons with actions """ ######################################################### self.threshIN.setValue(int(self.thresh)) self.threshOP.setText(self.thresh) self.btn_blog.clicked.connect(self.openBlog) self.btn_website.clicked.connect(self.openBlog) self.btn_apppage.clicked.connect(self.openAppPage) self.btn_twitter.clicked.connect(self.openTwitter) self.btn_twitter_2.clicked.connect(self.openTwitter) self.btn_github.clicked.connect(self.openGithub) self.btn_github_2.clicked.connect(self.openGithub) self.btn_instamojo.clicked.connect(self.openInstamojo) self.btn_paypal.clicked.connect(self.openPaypal) self.btn_email.clicked.connect(self.sendEmail) self.btn_start_system.clicked.connect(self.startSystem) # start system self.bnt_stop_system.clicked.connect(self.stopSystem) # stop system self.btn_alarm.clicked.connect(self.startAlarm) # start alarm self.btn_ip.clicked.connect(self.saveCameraIP) # connect self.btn_reset_thresh.clicked.connect(self.resetThresh) # resetThresh self.btn_settings_reset.clicked.connect(self.cancelIt) # cancel self.btn_setting_save.clicked.connect( self.saveSettings) # save Settings self.threshIN.valueChanged.connect( self.getThresh) # Sensitivity slider self.btn_alarm.setEnabled(False) self.bnt_stop_system.setEnabled(False) ######################################################### self.retranslateUi(MainWindow) self.tab_group.setCurrentIndex(0) self.toolBox.setCurrentIndex(0) self.threshIN.valueChanged['int'].connect(self.threshOP.setNum) QtCore.QMetaObject.connectSlotsByName(MainWindow) ######################################################### def openBlog(self): docDir = "www.villageprogrammer.blogspot.com/" QDesktopServices.openUrl(QUrl(docDir)) def openAppPage(self): docDir = "www.villageprogrammer.blogspot.com/" QDesktopServices.openUrl(QUrl(docDir)) def openGithub(self): docDir = "https://www.github.com/vikaspatelp83" QDesktopServices.openUrl(QUrl(docDir)) def openTwitter(self): docDir = "https://www.twitter.com/devdp430" QDesktopServices.openUrl(QUrl(docDir)) def openInstamojo(self): docDir = "https://www.instamojo.com/villageprogrammer" QDesktopServices.openUrl(QUrl(docDir)) def openPaypal(self): docDir = "https://www.paypal.me/vikaspatelp83" QDesktopServices.openUrl(QUrl(docDir)) def sendEmail(self): docDir = 'mailto:[email protected]?Subject=Hello%20from%20third%20eye!' QDesktopServices.openUrl(QUrl(docDir)) #****************** def saveCameraIP(self): ip = self.ip_input.text() if ip != "" or ip != "": self.camera_ip = ip else: self.camera_ip = 0 print(self.camera_ip) self.statusBar.showMessage("📽 Video Feed Address Saved : " + str(self.camera_ip)) """ Will implement later""" def saveSettings(self): password = self.pass_in.text() thresh = self.thresh mob = self.mobile_in.text() email = self.email_in.text() msg = self.msg_in.text() print(email) if not thresh == "" and not mob == "" and not email == "" and not msg == "": if password == self.passwd: self.sdb.set_sensitivity(thresh) self.sdb.set_mobile(mob) self.sdb.set_email(email) self.sdb.set_message(msg) print("Saving settings") self.statusBar.showMessage("💾 Settings Saved") else: self.statusBar.showMessage("❌❌❌❌❌Wrong Password") elif not thresh == "" and mob == "" and email == "" and msg == "": if password == self.passwd: self.sdb.set_sensitivity(thresh) print("Sensitivity Updated") self.statusBar.showMessage("💾 Sensitivity Updated") else: self.statusBar.showMessage("❌❌❌❌❌ Wrong Password") else: self.statusBar.showMessage( "Empty Imput Field. Please fill the correct info.") print(self.sdb.getAll()) def getThresh(self, value): self.thresh = value print(self.thresh) def resetThresh(self): print(self.thresh) self.sdb.set_sensitivity(20) self.statusBar.showMessage("Sensitivity Set to Default") def cancelIt(self): pass """ Main Actions """ def startAlarm(self): surv.start_alarm(self.s) print("Alarm Started") self.statusBar.showMessage("✅ Alarm Started") def startSystem(self): self.s = surv.start_system(self.camera_ip) self.btn_alarm.setEnabled(True) self.bnt_stop_system.setEnabled(True) self.btn_start_system.setEnabled(False) print("System started") self.statusBar.showMessage("😀 System Started") def stopSystem(self): surv.stop_system(self.s) self.btn_start_system.setEnabled(True) self.btn_alarm.setEnabled(False) self.bnt_stop_system.setEnabled(False) print("system stopped") self.statusBar.showMessage("❌ System Stopped") ######################################################### def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle( _translate("MainWindow", "Third Eye : Surveillance System")) self.btn_alarm.setText(_translate("MainWindow", " START ALARM")) self.btn_start_system.setText( _translate("MainWindow", " START SYSTEM")) self.bnt_stop_system.setText( _translate("MainWindow", " STOP SYSTEM")) self.tab_group.setTabText(self.tab_group.indexOf(self.tab_home), _translate("MainWindow", "Home")) self.label_2.setText(_translate("MainWindow", "IP Address")) self.label_4.setText(_translate("MainWindow", "Sensitivity")) self.threshOP_low.setText(_translate("MainWindow", "0")) self.threshOP_high.setText(_translate("MainWindow", "500")) self.threshOP.setText(_translate("MainWindow", str(self.thresh))) self.btn_reset_thresh.setText( _translate("MainWindow", "Reset Sensitivity")) self.btn_ip.setText(_translate("MainWindow", "Connect")) self.toolBox.setItemText(self.toolBox.indexOf(self.page), _translate("MainWindow", "Camera Settings")) self.label_3.setText(_translate("MainWindow", "Mobile Number")) self.label_5.setText(_translate("MainWindow", "Alert Message")) self.label_6.setText(_translate("MainWindow", "Alert Email")) self.toolBox.setItemText(self.toolBox.indexOf(self.page_2), _translate("MainWindow", "Alert Settings")) self.label_7.setText(_translate("MainWindow", "Password")) self.toolBox.setItemText(self.toolBox.indexOf(self.page_3), _translate("MainWindow", "Admin Password")) self.btn_setting_save.setText(_translate("MainWindow", "Save Settings")) self.btn_settings_reset.setText(_translate("MainWindow", "Cancel")) self.label_8.setText( _translate( "MainWindow", "Enter your admin password and click \"Save Settings\" to save new settings." )) self.tab_group.setTabText(self.tab_group.indexOf(self.tab_settings), _translate("MainWindow", "Settings")) self.btn_github.setText(_translate("MainWindow", "GitHub")) self.textEdit.setHtml( _translate( "MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Third Eye</span> is a Surveillance System. Capable of detecting motion and will alert you in case of security breach using SMS, Email and Alarm System.</p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Third Eye is developed by <a href=\"https://www.github.com/vikaspatelp83\"><span style=\" font-weight:600; text-decoration: underline; color:#0000ff;\">Vikas Patel </span></a>at DTech Software aka Villageprogrammer.</p></body></html>" )) self.textBrowser.setHtml( _translate( "MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt; font-weight:600;\">Open Source Software</span></p></body></html>" )) self.btn_twitter.setText(_translate("MainWindow", "Twitter")) self.btn_blog.setText(_translate("MainWindow", "Blog")) self.btn_apppage.setText(_translate("MainWindow", "App Page")) self.tab_group.setTabText(self.tab_group.indexOf(self.tab_about), _translate("MainWindow", "About")) self.groupBox.setTitle(_translate("MainWindow", "Email Me")) self.plainTextEdit.setPlainText( _translate("MainWindow", "*****@*****.**")) self.btn_email.setText(_translate("MainWindow", "Send Email")) self.groupBox_2.setTitle(_translate("MainWindow", "Website")) self.plainTextEdit_2.setPlainText( _translate("MainWindow", "www.villageprogrammer.tech")) self.btn_website.setText(_translate("MainWindow", "Open in Browser")) self.groupBox_3.setTitle(_translate("MainWindow", "Follow Me")) self.plainTextEdit_3.setPlainText(_translate("MainWindow", "Twitter")) self.btn_twitter_2.setText(_translate("MainWindow", "Open in Browser")) self.plainTextEdit_4.setPlainText(_translate("MainWindow", "GitHub")) self.btn_github_2.setText(_translate("MainWindow", "Open in Browser")) self.btn_instamojo.setText(_translate("MainWindow", "Open in Browser")) self.plainTextEdit_5.setPlainText( _translate("MainWindow", "Buy Books at Instamojo")) self.tab_group.setTabText(self.tab_group.indexOf(self.tab_contact), _translate("MainWindow", "Contact")) self.groupBox_4.setTitle(_translate("MainWindow", "Paypal")) self.plainTextEdit_6.setPlainText( _translate("MainWindow", "www.paypal.me/vikaspatelp83")) self.btn_paypal.setText(_translate("MainWindow", "Open Paypal")) self.groupBox_5.setTitle(_translate("MainWindow", "Paytm/Google Pay")) self.plainTextEdit_7.setPlainText( _translate("MainWindow", "9575357966")) self.tab_group.setTabText(self.tab_group.indexOf(self.tab_donate), _translate("MainWindow", "Donate"))
class NodeBodyItem(GraphicsPathObject): """ The central part (body) of the `NodeItem`. """ def __init__(self, parent=None): GraphicsPathObject.__init__(self, parent) assert(isinstance(parent, NodeItem)) self.__processingState = 0 self.__progress = -1 self.__animationEnabled = False self.__isSelected = False self.__hasFocus = False self.__hover = False self.__shapeRect = QRectF(-10, -10, 20, 20) self.setAcceptHoverEvents(True) self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges, True) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.setPen(QPen(Qt.NoPen)) self.setPalette(default_palette()) self.shadow = QGraphicsDropShadowEffect( blurRadius=3, color=QColor(SHADOW_COLOR), offset=QPointF(0, 0), ) self.setGraphicsEffect(self.shadow) self.shadow.setEnabled(True) self.__blurAnimation = QPropertyAnimation(self.shadow, b"blurRadius", self) self.__blurAnimation.setDuration(100) self.__blurAnimation.finished.connect(self.__on_finished) self.__pingAnimation = QPropertyAnimation(self, b"scale", self) self.__pingAnimation.setDuration(250) self.__pingAnimation.setKeyValues([(0.0, 1.0), (0.5, 1.1), (1.0, 1.0)]) # TODO: The body item should allow the setting of arbitrary painter # paths (for instance rounded rect, ...) def setShapeRect(self, rect): """ Set the item's shape `rect`. The item should be confined within this rect. """ path = QPainterPath() path.addEllipse(rect) self.setPath(path) self.__shapeRect = rect def setPalette(self, palette): """ Set the body color palette (:class:`QPalette`). """ self.palette = palette self.__updateBrush() def setAnimationEnabled(self, enabled): """ Set the node animation enabled. """ if self.__animationEnabled != enabled: self.__animationEnabled = enabled def setProcessingState(self, state): """ Set the processing state of the node. """ if self.__processingState != state: self.__processingState = state if not state and self.__animationEnabled: self.ping() def setProgress(self, progress): """ Set the progress indicator state of the node. `progress` should be a number between 0 and 100. """ self.__progress = progress self.update() def ping(self): """ Trigger a 'ping' animation. """ animation_restart(self.__pingAnimation) def hoverEnterEvent(self, event): self.__hover = True self.__updateShadowState() return GraphicsPathObject.hoverEnterEvent(self, event) def hoverLeaveEvent(self, event): self.__hover = False self.__updateShadowState() return GraphicsPathObject.hoverLeaveEvent(self, event) def paint(self, painter, option, widget): """ Paint the shape and a progress meter. """ # Let the default implementation draw the shape if option.state & QStyle.State_Selected: # Prevent the default bounding rect selection indicator. option.state = option.state ^ QStyle.State_Selected GraphicsPathObject.paint(self, painter, option, widget) if self.__progress >= 0: # Draw the progress meter over the shape. # Set the clip to shape so the meter does not overflow the shape. painter.setClipPath(self.shape(), Qt.ReplaceClip) color = self.palette.color(QPalette.ButtonText) pen = QPen(color, 5) painter.save() painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing) span = max(1, int(self.__progress * 57.60)) painter.drawArc(self.__shapeRect, 90 * 16, -span) painter.restore() def __updateShadowState(self): if self.__hasFocus: color = QColor(FOCUS_OUTLINE_COLOR) self.setPen(QPen(color, 1.5)) else: self.setPen(QPen(Qt.NoPen)) radius = 3 enabled = False if self.__isSelected: enabled = True radius = 7 if self.__hover: radius = 17 enabled = True if enabled and not self.shadow.isEnabled(): self.shadow.setEnabled(enabled) if self.__animationEnabled: if self.__blurAnimation.state() == QPropertyAnimation.Running: self.__blurAnimation.pause() self.__blurAnimation.setStartValue(self.shadow.blurRadius()) self.__blurAnimation.setEndValue(radius) self.__blurAnimation.start() else: self.shadow.setBlurRadius(radius) def __updateBrush(self): palette = self.palette if self.__isSelected: cg = QPalette.Active else: cg = QPalette.Inactive palette.setCurrentColorGroup(cg) c1 = palette.color(QPalette.Light) c2 = palette.color(QPalette.Button) grad = radial_gradient(c2, c1) self.setBrush(QBrush(grad)) # TODO: The selected and focus states should be set using the # QStyle flags (State_Selected. State_HasFocus) def setSelected(self, selected): """ Set the `selected` state. .. note:: The item does not have `QGraphicsItem.ItemIsSelectable` flag. This property is instead controlled by the parent NodeItem. """ self.__isSelected = selected self.__updateBrush() def setHasFocus(self, focus): """ Set the `has focus` state. .. note:: The item does not have `QGraphicsItem.ItemIsFocusable` flag. This property is instead controlled by the parent NodeItem. """ self.__hasFocus = focus self.__updateShadowState() def __on_finished(self): if self.shadow.blurRadius() == 0: self.shadow.setEnabled(False)
class NodeAnchorItem(GraphicsPathObject): """ The left/right widget input/output anchors. """ def __init__(self, parent, *args): self.__boundingRect = None GraphicsPathObject.__init__(self, parent, *args) self.setAcceptHoverEvents(True) self.setPen(QPen(Qt.NoPen)) self.normalBrush = QBrush(QColor("#CDD5D9")) self.connectedBrush = QBrush(QColor("#9CACB4")) self.setBrush(self.normalBrush) self.shadow = QGraphicsDropShadowEffect( blurRadius=10, color=QColor(SHADOW_COLOR), offset=QPointF(0, 0) ) self.setGraphicsEffect(self.shadow) self.shadow.setEnabled(False) # Does this item have any anchored links. self.anchored = False if isinstance(parent, NodeItem): self.__parentNodeItem = parent else: self.__parentNodeItem = None self.__anchorPath = QPainterPath() self.__points = [] self.__pointPositions = [] self.__fullStroke = None self.__dottedStroke = None self.__shape = None self.prepareGeometryChange() self.__boundingRect = None def parentNodeItem(self): """ Return a parent :class:`NodeItem` or ``None`` if this anchor's parent is not a :class:`NodeItem` instance. """ return self.__parentNodeItem def setAnchorPath(self, path): """ Set the anchor's curve path as a :class:`QPainterPath`. """ self.prepareGeometryChange() self.__boundingRect = None self.__anchorPath = path # Create a stroke of the path. stroke_path = QPainterPathStroker() stroke_path.setCapStyle(Qt.RoundCap) # Shape is wider (bigger mouse hit area - should be settable) stroke_path.setWidth(12) self.__shape = stroke_path.createStroke(path) # The full stroke stroke_path.setWidth(3) self.__fullStroke = stroke_path.createStroke(path) # The dotted stroke (when not connected to anything) stroke_path.setDashPattern(Qt.DotLine) self.__dottedStroke = stroke_path.createStroke(path) if self.anchored: self.setPath(self.__fullStroke) self.setBrush(self.connectedBrush) else: self.setPath(self.__dottedStroke) self.setBrush(self.normalBrush) def anchorPath(self): """ Return the anchor path (:class:`QPainterPath`). This is a curve on which the anchor points lie. """ return self.__anchorPath def setAnchored(self, anchored): """ Set the items anchored state. When ``False`` the item draws it self with a dotted stroke. """ self.anchored = anchored if anchored: self.setPath(self.__fullStroke) self.setBrush(self.connectedBrush) else: self.setPath(self.__dottedStroke) self.setBrush(self.normalBrush) def setConnectionHint(self, hint=None): """ Set the connection hint. This can be used to indicate if a connection can be made or not. """ raise NotImplementedError def count(self): """ Return the number of anchor points. """ return len(self.__points) def addAnchor(self, anchor, position=0.5): """ Add a new :class:`AnchorPoint` to this item and return it's index. The `position` specifies where along the `anchorPath` is the new point inserted. """ return self.insertAnchor(self.count(), anchor, position) def insertAnchor(self, index, anchor, position=0.5): """ Insert a new :class:`AnchorPoint` at `index`. See also -------- NodeAnchorItem.addAnchor """ if anchor in self.__points: raise ValueError("%s already added." % anchor) self.__points.insert(index, anchor) self.__pointPositions.insert(index, position) anchor.setParentItem(self) anchor.setPos(self.__anchorPath.pointAtPercent(position)) anchor.destroyed.connect(self.__onAnchorDestroyed) self.__updatePositions() self.setAnchored(bool(self.__points)) return index def removeAnchor(self, anchor): """ Remove and delete the anchor point. """ anchor = self.takeAnchor(anchor) anchor.hide() anchor.setParentItem(None) anchor.deleteLater() def takeAnchor(self, anchor): """ Remove the anchor but don't delete it. """ index = self.__points.index(anchor) del self.__points[index] del self.__pointPositions[index] anchor.destroyed.disconnect(self.__onAnchorDestroyed) self.__updatePositions() self.setAnchored(bool(self.__points)) return anchor def __onAnchorDestroyed(self, anchor): try: index = self.__points.index(anchor) except ValueError: return del self.__points[index] del self.__pointPositions[index] def anchorPoints(self): """ Return a list of anchor points. """ return list(self.__points) def anchorPoint(self, index): """ Return the anchor point at `index`. """ return self.__points[index] def setAnchorPositions(self, positions): """ Set the anchor positions in percentages (0..1) along the path curve. """ if self.__pointPositions != positions: self.__pointPositions = list(positions) self.__updatePositions() def anchorPositions(self): """ Return the positions of anchor points as a list of floats where each float is between 0 and 1 and specifies where along the anchor path does the point lie (0 is at start 1 is at the end). """ return list(self.__pointPositions) def shape(self): if self.__shape is not None: return self.__shape else: return GraphicsPathObject.shape(self) def boundingRect(self): if self.__boundingRect is None: self.__boundingRect = super(NodeAnchorItem, self).boundingRect() \ .adjusted(-5, -5, 5, 5) return self.__boundingRect def hoverEnterEvent(self, event): self.prepareGeometryChange() self.__boundingRect = None self.shadow.setEnabled(True) return GraphicsPathObject.hoverEnterEvent(self, event) def hoverLeaveEvent(self, event): self.prepareGeometryChange() self.__boundingRect = None self.shadow.setEnabled(False) return GraphicsPathObject.hoverLeaveEvent(self, event) def __updatePositions(self): """Update anchor points positions. """ self.prepareGeometryChange() self.__boundingRect = None for point, t in zip(self.__points, self.__pointPositions): pos = self.__anchorPath.pointAtPercent(t) point.setPos(pos)