class Demo(QWidget): sb_roundness = None sb_opacity = None sb_fadeperc = None sb_lines = None sb_line_length = None sb_line_width = None sb_inner_radius = None sb_rev_s = None btn_start = None btn_stop = None btn_pick_color = None spinner = None def __init__(self): super().__init__() self.init_ui() def init_ui(self): grid = QGridLayout() groupbox1 = QGroupBox() groupbox1_layout = QHBoxLayout() groupbox2 = QGroupBox() groupbox2_layout = QGridLayout() button_hbox = QHBoxLayout() self.setLayout(grid) self.setWindowTitle("QtWaitingSpinner Demo") self.setWindowFlags(Qt.Dialog) # SPINNER self.spinner = WaitingSpinner(self) # Spinboxes self.sb_roundness = QDoubleSpinBox() self.sb_opacity = QDoubleSpinBox() self.sb_fadeperc = QDoubleSpinBox() self.sb_lines = QSpinBox() self.sb_line_length = QDoubleSpinBox() self.sb_line_width = QDoubleSpinBox() self.sb_inner_radius = QDoubleSpinBox() self.sb_rev_s = QDoubleSpinBox() # set spinbox default values self.sb_roundness.setValue(70) self.sb_roundness.setRange(0, 9999) self.sb_opacity.setValue(15) self.sb_opacity.setRange(0, 9999) self.sb_fadeperc.setValue(70) self.sb_fadeperc.setRange(0, 9999) self.sb_lines.setValue(12) self.sb_lines.setRange(1, 9999) self.sb_line_length.setValue(10) self.sb_line_length.setRange(0, 9999) self.sb_line_width.setValue(5) self.sb_line_width.setRange(0, 9999) self.sb_inner_radius.setValue(10) self.sb_inner_radius.setRange(0, 9999) self.sb_rev_s.setValue(1) self.sb_rev_s.setRange(0.1, 9999) # Buttons self.btn_start = QPushButton("Start") self.btn_stop = QPushButton("Stop") self.btn_pick_color = QPushButton("Pick Color") self.btn_show_init = QPushButton("Show init args") # Connects self.sb_roundness.valueChanged.connect(self.set_roundness) self.sb_opacity.valueChanged.connect(self.set_opacity) self.sb_fadeperc.valueChanged.connect(self.set_fadeperc) self.sb_lines.valueChanged.connect(self.set_lines) self.sb_line_length.valueChanged.connect(self.set_line_length) self.sb_line_width.valueChanged.connect(self.set_line_width) self.sb_inner_radius.valueChanged.connect(self.set_inner_radius) self.sb_rev_s.valueChanged.connect(self.set_rev_s) self.btn_start.clicked.connect(self.spinner_start) self.btn_stop.clicked.connect(self.spinner_stop) self.btn_pick_color.clicked.connect(self.show_color_picker) self.btn_show_init.clicked.connect(self.show_init_args) # Layout adds groupbox1_layout.addWidget(self.spinner) groupbox1.setLayout(groupbox1_layout) groupbox2_layout.addWidget(QLabel("Roundness:"), *(1, 1)) groupbox2_layout.addWidget(self.sb_roundness, *(1, 2)) groupbox2_layout.addWidget(QLabel("Opacity:"), *(2, 1)) groupbox2_layout.addWidget(self.sb_opacity, *(2, 2)) groupbox2_layout.addWidget(QLabel("Fade Perc:"), *(3, 1)) groupbox2_layout.addWidget(self.sb_fadeperc, *(3, 2)) groupbox2_layout.addWidget(QLabel("Lines:"), *(4, 1)) groupbox2_layout.addWidget(self.sb_lines, *(4, 2)) groupbox2_layout.addWidget(QLabel("Line Length:"), *(5, 1)) groupbox2_layout.addWidget(self.sb_line_length, *(5, 2)) groupbox2_layout.addWidget(QLabel("Line Width:"), *(6, 1)) groupbox2_layout.addWidget(self.sb_line_width, *(6, 2)) groupbox2_layout.addWidget(QLabel("Inner Radius:"), *(7, 1)) groupbox2_layout.addWidget(self.sb_inner_radius, *(7, 2)) groupbox2_layout.addWidget(QLabel("Rev/s:"), *(8, 1)) groupbox2_layout.addWidget(self.sb_rev_s, *(8, 2)) groupbox2.setLayout(groupbox2_layout) button_hbox.addWidget(self.btn_start) button_hbox.addWidget(self.btn_stop) button_hbox.addWidget(self.btn_pick_color) button_hbox.addWidget(self.btn_show_init) grid.addWidget(groupbox1, *(1, 1)) grid.addWidget(groupbox2, *(1, 2)) grid.addLayout(button_hbox, *(2, 1)) self.spinner.start() self.show() def set_roundness(self): self.spinner.setRoundness(self.sb_roundness.value()) def set_opacity(self): self.spinner.setMinimumTrailOpacity(self.sb_opacity.value()) def set_fadeperc(self): self.spinner.setTrailFadePercentage(self.sb_fadeperc.value()) def set_lines(self): self.spinner.setNumberOfLines(self.sb_lines.value()) def set_line_length(self): self.spinner.setLineLength(self.sb_line_length.value()) def set_line_width(self): self.spinner.setLineWidth(self.sb_line_width.value()) def set_inner_radius(self): self.spinner.setInnerRadius(self.sb_inner_radius.value()) def set_rev_s(self): self.spinner.setRevolutionsPerSecond(self.sb_rev_s.value()) def spinner_start(self): self.spinner.start() def spinner_stop(self): self.spinner.stop() def show_color_picker(self): self.spinner.setColor(QColorDialog.getColor()) def show_init_args(self): text = ('WaitingSpinner(\n' ' parent,\n' ' roundness={}, opacity={},\n' ' fade={}, radius={}, lines={},\n' ' line_length={}, line_width={},\n' ' speed={}, color={}\n' ')\n').format(self.sb_roundness.value(), self.sb_opacity.value(), self.sb_fadeperc.value(), self.sb_inner_radius.value(), self.sb_lines.value(), self.sb_line_length.value(), self.sb_line_width.value(), self.sb_rev_s.value(), self.spinner.color.getRgb()[:3]) msg_box = QMessageBox(text=text) msg_box.setWindowTitle('Text was copied to clipboard') cb = QApplication.clipboard() cb.clear(mode=cb.Clipboard) cb.setText(text, mode=cb.Clipboard) print(text) msg_box.exec_()
class SplashScreen(QtWidgets.QSplashScreen): """ Generic splashcreen. Must always be spawned in a new thread, while the original thread executes qt_app.processEvents() in a while loop, until it should be stopped. """ def __init__(self, background=True): """ background: set the image as the background. The layout changes if background ist set. Without: the spinner plays in the middle. A screenshot is taken when the splashcreen initializes and set as background, so changing elements in the gui are not seen by the user. With: background image is scaled and spinner plays in the bottom middle. """ self._is_background_set = background self._label = None self._spinner = None if background: pixmap = QtGui.QPixmap(str(get_asset_file("gui_base", "loading"))) pixmap = pixmap.scaled(800, 480, transformMode=Qt.SmoothTransformation) else: if not config.qt_app: return # can not really happen... screen = config.qt_app.primaryScreen() pixmap = screen.grabWindow(voidptr(0)) QtWidgets.QSplashScreen.__init__(self, pixmap) if config.DEBUG_LEVEL > 0: # unlock gui when debugging self.setWindowFlags(Qt.FramelessWindowHint) def mousePressEvent(self, event): # pylint: disable=unused-argument, invalid-name, no-self-use """ Do nothing on mouse click. Otherwise it disappears. """ return def showEvent(self, event): # pylint: disable=unused-argument, invalid-name """ Start movie, when it is shown. """ # show version label if self._is_background_set: self._label = QtWidgets.QLabel(self) self._label.setText(WAQD_VERSION + " ") self._label.setAlignment(Qt.AlignmentFlag(Qt.AlignBottom | Qt.AlignRight)) self._label.setGeometry(0, 0, 800, 480) self._label.show() self._spinner = WaitingSpinner(self, centerOnParent=False, radius=30, roundness=60, line_length=20, line_width=6, speed=0.5, color=(15, 67, 116)) if self._is_background_set: self._spinner.setGeometry(int(self.width()/2 - self._spinner.width()/2), int(self.height() - self._spinner.height() - 20), self._spinner.width(), self._spinner.height()) else: self._spinner.setColor("white") self._spinner.setInnerRadius(40) self._spinner.setLineLength(40) self._spinner.setLineWidth(8) self._spinner.setTrailFadePercentage(90) self._spinner.setGeometry(int(self.width()/2 - self._spinner.width()/2), int(self.height()/2 - self._spinner.height()/2), self._spinner.width(), self._spinner.height()) self._spinner.start() def hideEvent(self, event): # pylint: disable=unused-argument, invalid-name """ Stop movie, when it is hidden. """ if self._spinner: self._spinner.stop()