def __init__(self, pixmap, title="", parentItem=None, **kwargs): super().__init__(parentItem, **kwargs) self.setFocusPolicy(Qt.StrongFocus) self._title = None self._size = QSizeF() layout = QGraphicsLinearLayout(Qt.Vertical, self) layout.setSpacing(2) layout.setContentsMargins(5, 5, 5, 5) self.setContentsMargins(0, 0, 0, 0) self.pixmapWidget = GraphicsPixmapWidget(pixmap, self) self.labelWidget = GraphicsTextWidget(title, self) layout.addItem(self.pixmapWidget) layout.addItem(self.labelWidget) layout.addStretch() layout.setAlignment(self.pixmapWidget, Qt.AlignCenter) layout.setAlignment(self.labelWidget, Qt.AlignHCenter | Qt.AlignBottom) self.setLayout(layout) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setTitle(title) self.setTitleWidth(100)
def __init__(self, pixmap, title="", parent=None): QGraphicsWidget.__init__(self, parent) self._title = None self._size = QSizeF() layout = QGraphicsLinearLayout(Qt.Vertical, self) layout.setSpacing(2) layout.setContentsMargins(5, 5, 5, 5) self.setContentsMargins(0, 0, 0, 0) self.pixmapWidget = GraphicsPixmapWidget(pixmap, self) self.labelWidget = GraphicsTextWidget(title, self) layout.addItem(self.pixmapWidget) layout.addItem(self.labelWidget) layout.setAlignment(self.pixmapWidget, Qt.AlignCenter) layout.setAlignment(self.labelWidget, Qt.AlignHCenter | Qt.AlignBottom) self.setLayout(layout) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setTitle(title) self.setTitleWidth(100)
def setLayout(self): global labels self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet) setLabels(self.applet) for label in labels: self.layout.addItem(label) self.applet.setLayout(self.layout)
def setLayout(self): global label self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet) label = Plasma.Label(self.applet) setLabel() self.layout.addItem(label) self.applet.setLayout(self.layout)
def init(self): #TODO: have a configuration interface to set keybroad shortcut #self.setHasConfigurationInterface(True) self.setAspectRatioMode(Plasma.ConstrainedSquare) self.setBackgroundHints(self.NoBackground) self.sessionBus = dbus.SessionBus() self.powerdevil = self.sessionBus.get_object( 'org.freedesktop.PowerManagement', '/modules/powerdevil') self.icon = Plasma.IconWidget(KIcon('preferences-desktop-screensaver'), '', self.applet) if KGlobalSettings.singleClick(): self.connect(self.icon, SIGNAL('clicked()'), self.turn_off_screen) else: self.connect(self.icon, SIGNAL('doubleClicked()'), self.turn_off_screen) self.connect(self, SIGNAL('active()'), self.turn_off_screen) self.layout = QGraphicsLinearLayout(self.applet) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) self.layout.addItem(self.icon) self.setLayout(self.layout) self.resize(25, 25)
def __init__(self, labels=[], orientation=Qt.Vertical, parent=None): QGraphicsWidget.__init__(self, parent) layout = QGraphicsLinearLayout(orientation) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) self.orientation = orientation self.alignment = Qt.AlignCenter self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.label_items = [] self.set_labels(labels)
def init(self): global labels self.setHasConfigurationInterface(False) self.setAspectRatioMode(Plasma.Square) self.theme = Plasma.Svg(self) self.theme.setImagePath("widgets/background") self.setBackgroundHints(Plasma.Applet.DefaultBackground) self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet) makeLabels(self.applet) for label in labels: self.layout.addItem(label) self.applet.setLayout(self.layout) self.startTimer(8000) self.resize(400, 200)
def setupMainUI(self): print 'setup' self.setAspectRatioMode(Plasma.IgnoreAspectRatio) self.setBackgroundHints(Plasma.Applet.TranslucentBackground) self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet) self.label = Plasma.Label(self.applet) self.label.setText(self.model.message) self.label.setStyleSheet('''font-size: 18pt;''') self.label.setAlignment(Qt.AlignCenter | Qt.AlignVCenter) self.layout.addItem(self.label) self.applet.setLayout(self.layout) self.connectToEngine() self.model.messageChanged.connect(self.handleMessageChanged)
def init(self): global label self.setHasConfigurationInterface(False) self.setAspectRatioMode(Plasma.IgnoreAspectRatio) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.setMinimumWidth(425) self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet) label = Plasma.Label(self.applet) label.setText("Waiting for XMonad...") self.layout.addItem(label) self.applet.setLayout(self.layout) self.setup_dbus() self.label_signal.connect(update_label)
def __init__(self, parent=None, direction=Qt.LeftToRight, node=None, icon=None, iconSize=None, **args): QGraphicsWidget.__init__(self, parent, **args) self.setAcceptedMouseButtons(Qt.NoButton) self.__direction = direction self.setLayout(QGraphicsLinearLayout(Qt.Horizontal)) # Set the maximum size, otherwise the layout can't grow beyond its # sizeHint (and we need it to grow so the widget can grow and keep the # contents centered vertically. self.layout().setMaximumSize(QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__iconSize = iconSize or QSize(64, 64) self.__icon = icon self.__iconItem = QGraphicsPixmapItem(self) self.__iconLayoutItem = GraphicsItemLayoutItem(item=self.__iconItem) self.__channelLayout = QGraphicsGridLayout() self.__channelAnchors = [] if self.__direction == Qt.LeftToRight: self.layout().addItem(self.__iconLayoutItem) self.layout().addItem(self.__channelLayout) channel_alignemnt = Qt.AlignRight else: self.layout().addItem(self.__channelLayout) self.layout().addItem(self.__iconLayoutItem) channel_alignemnt = Qt.AlignLeft self.layout().setAlignment(self.__iconLayoutItem, Qt.AlignCenter) self.layout().setAlignment(self.__channelLayout, Qt.AlignVCenter | channel_alignemnt) if node is not None: self.setSchemeNode(node)
def init(self): self.setHasConfigurationInterface(False) self.setAspectRatioMode(Plasma.Square) self.theme = Plasma.Svg(self) self.theme.setImagePath("widgets/background") self.setBackgroundHints(Plasma.Applet.DefaultBackground) self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet) self.monitoring = {} self.widgets = {} for source in self.connectToEngine(): label = Plasma.Label(self.applet) label.setText("%s:" % source) self.layout.addItem(label) self.widgets[str(source)] = label self.monitoring[str(source)] = {"in": 0, "out": 0} self.applet.setLayout(self.layout)
def __init__(self, *args, **kwargs): QGraphicsWidget.__init__(self, *args, **kwargs) self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton) self.source = None self.sink = None # QGraphicsWidget/Items in the scene. self.sourceNodeWidget = None self.sourceNodeTitle = None self.sinkNodeWidget = None self.sinkNodeTitle = None self.__links = [] self.__textItems = [] self.__iconItems = [] self.__tmpLine = None self.__dragStartItem = None self.setLayout(QGraphicsLinearLayout(Qt.Vertical)) self.layout().setContentsMargins(0, 0, 0, 0)
def __init__(self, parent=None): super().__init__(parent) self.matrix = None self.items = None self.linkmatrix = None self.root = None self._displayed_root = None self.cutoff_height = 0.0 self._invalidated = False gui.comboBox(gui.widgetBox(self.controlArea, "Linkage"), self, "linkage", items=LINKAGE, callback=self._invalidate_clustering) box = gui.widgetBox(self.controlArea, "Annotation") self.label_cb = gui.comboBox(box, self, "annotation_idx", callback=self._update_labels) self.label_cb.setModel(itemmodels.VariableListModel()) self.label_cb.model()[:] = ["None", "Enumeration"] box = gui.radioButtons(self.controlArea, self, "pruning", box="Pruning", callback=self._invalidate_pruning) grid = QGridLayout() box.layout().addLayout(grid) grid.addWidget(gui.appendRadioButton(box, "None", addToLayout=False), 0, 0) self.max_depth_spin = gui.spin(box, self, "max_depth", minv=1, maxv=100, callback=self._invalidate_pruning, keyboardTracking=False) grid.addWidget( gui.appendRadioButton(box, "Max depth", addToLayout=False), 1, 0) grid.addWidget(self.max_depth_spin, 1, 1) box = gui.radioButtons(self.controlArea, self, "selection_method", box="Selection", callback=self._selection_method_changed) grid = QGridLayout() box.layout().addLayout(grid) grid.addWidget(gui.appendRadioButton(box, "Manual", addToLayout=False), 0, 0) grid.addWidget( gui.appendRadioButton(box, "Height ratio", addToLayout=False), 1, 0) self.cut_ratio_spin = gui.spin(box, self, "cut_ratio", 0, 100, step=1e-1, spinType=float, callback=self._selection_method_changed) self.cut_ratio_spin.setSuffix("%") grid.addWidget(self.cut_ratio_spin, 1, 1) grid.addWidget(gui.appendRadioButton(box, "Top N", addToLayout=False), 2, 0) self.top_n_spin = gui.spin(box, self, "top_n", 1, 20, callback=self._selection_method_changed) grid.addWidget(self.top_n_spin, 2, 1) box.layout().addLayout(grid) self.controlArea.layout().addStretch() box = gui.widgetBox(self.controlArea, "Output") gui.checkBox(box, self, "append_clusters", "Append cluster IDs", callback=self._invalidate_output) ibox = gui.indentedBox(box) name_edit = gui.lineEdit(ibox, self, "cluster_name") name_edit.editingFinished.connect(self._invalidate_output) cb = gui.comboBox( ibox, self, "cluster_role", callback=self._invalidate_output, items=["Attribute", "Class variable", "Meta variable"]) form = QFormLayout(fieldGrowthPolicy=QFormLayout.AllNonFixedFieldsGrow, labelAlignment=Qt.AlignLeft, spacing=8) form.addRow("Name", name_edit) form.addRow("Place", cb) ibox.layout().addSpacing(5) ibox.layout().addLayout(form) ibox.layout().addSpacing(5) cb = gui.checkBox(box, self, "autocommit", "Commit automatically") b = gui.button(box, self, "Commit", callback=self.commit, default=True) gui.setStopper(self, b, cb, "_invalidated", callback=self.commit) self.scene = QGraphicsScene() self.view = QGraphicsView( self.scene, horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff, verticalScrollBarPolicy=Qt.ScrollBarAlwaysOn, alignment=Qt.AlignLeft | Qt.AlignVCenter) def axis_view(orientation): ax = pg.AxisItem(orientation=orientation, maxTickLength=7) scene = QGraphicsScene() scene.addItem(ax) view = QGraphicsView( scene, horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff, verticalScrollBarPolicy=Qt.ScrollBarAlwaysOn, alignment=Qt.AlignLeft | Qt.AlignVCenter) view.setFixedHeight(ax.size().height()) ax.line = SliderLine(orientation=Qt.Horizontal, length=ax.size().height()) scene.addItem(ax.line) return view, ax self.top_axis_view, self.top_axis = axis_view("top") self.mainArea.layout().setSpacing(1) self.mainArea.layout().addWidget(self.top_axis_view) self.mainArea.layout().addWidget(self.view) self.bottom_axis_view, self.bottom_axis = axis_view("bottom") self.mainArea.layout().addWidget(self.bottom_axis_view) self._main_graphics = QGraphicsWidget() self._main_layout = QGraphicsLinearLayout(Qt.Horizontal) self._main_layout.setSpacing(1) self._main_graphics.setLayout(self._main_layout) self.scene.addItem(self._main_graphics) self.dendrogram = DendrogramWidget() self.dendrogram.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.dendrogram.selectionChanged.connect(self._invalidate_output) self.dendrogram.selectionEdited.connect(self._selection_edited) fm = self.fontMetrics() self.dendrogram.setContentsMargins(5, fm.lineSpacing() / 2, 5, fm.lineSpacing() / 2) self.labels = GraphicsSimpleTextList() self.labels.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.labels.setAlignment(Qt.AlignLeft) self.labels.setMaximumWidth(200) self.labels.layout().setSpacing(0) self._main_layout.addItem(self.dendrogram) self._main_layout.addItem(self.labels) self._main_layout.setAlignment(self.dendrogram, Qt.AlignLeft | Qt.AlignVCenter) self._main_layout.setAlignment(self.labels, Qt.AlignLeft | Qt.AlignVCenter) self.view.viewport().installEventFilter(self) self.top_axis_view.viewport().installEventFilter(self) self.bottom_axis_view.viewport().installEventFilter(self) self._main_graphics.installEventFilter(self) self.cut_line = SliderLine(self.dendrogram, orientation=Qt.Horizontal) self.cut_line.valueChanged.connect(self._dendrogram_slider_changed) self.cut_line.hide() self.bottom_axis.line.valueChanged.connect(self._axis_slider_changed) self.top_axis.line.valueChanged.connect(self._axis_slider_changed) self.dendrogram.geometryChanged.connect(self._dendrogram_geom_changed) self._set_cut_line_visible(self.selection_method == 1)
def init(self): # Setting some Plasma-specific settings self.setHasConfigurationInterface( False) # We dont have a configuration interface, yet. self.setAspectRatioMode(Plasma.IgnoreAspectRatio) self.theme = Plasma.Svg(self) self.setBackgroundHints(Plasma.Applet.DefaultBackground) self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet) self.applet.setLayout(self.layout) self.icon = self.package().path( ) + "plasmafreq.svg" # Finding a path for our apps icon # Adding a nice-looking GroupBox for RadioButtons self.setGovernorBox = Plasma.GroupBox(self.applet) self.setGovernorBox.setText("Mode selection") self.setGovernorBox.setLayout( QGraphicsLinearLayout(Qt.Vertical, self.setGovernorBox)) self.setGovernorBox.setSizePolicy( QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)) self.layout.addItem(self.setGovernorBox) self.governorGroup = QButtonGroup( self.applet ) # Creating a abstract ButtonGroup in order to link RadioButtons together # Creating a QFileSystemWatcher to watch changes in current frequency and governor self.watcher = QFileSystemWatcher(self) QObject.connect(self.watcher, SIGNAL("fileChanged(const QString&)"), self.file_changed) # Setting paths for cpufreq self.cpuCores = glob(path.join("/sys/devices/system/cpu/", "cpu?")) # List all CPU cores self.cpufreqGovPath = [] # This is going to be ugly...but hey, it works (at least if you dont have many physical CPUs. Cores are ok) for x in self.cpuCores: self.cpufreqGovPath.append( x + "/cpufreq/scaling_governor" ) # path.join doesn't work here, dunno why # Initializing some variables and setting variables to them. self.availableFrequencies = self.listFrequencies() self.availableGovernors = self.listGovernors() self.currentGovernorStr = self.currentGovernor() self.currentFrequencyStr = self.currentFrequency() self.radioButton = {} # This contains texts and tooltips for RadioButtons self.governorTextsDict = { 'conservative': [ 'Conservative', 'Similiar to On Demand, but CPU clock speed switches gradually through all its available frequencies based on system load ' ], 'ondemand': [ 'On Demand', 'Dynamically switches between the CPU available clock speeds based on system load ' ], 'userspace': ['User Defined', 'Lets user to manually configure clock speeds'], 'powersave': ['Powersave', 'Runs the CPU at minimum clock speeds'], 'performance': ['Performance', 'Runs the CPU at maximum clock speeds'] } for x in self.availableGovernors: # Makes a RadioButton for each governor available. self.radioButton[x] = Plasma.RadioButton(self.applet) self.radioButton[x].setText( self.governorTextsDict[x][0] ) # Sets the text for radioButton from governorTextsDict above self.radioButton[x].setToolTip(self.governorTextsDict[x][1]) self.radioButton[x].setSizePolicy( QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)) self.governorGroup.addButton(self.radioButton[x].nativeWidget( )) # We need to add radioButton's native widget self.setGovernorBox.layout().addItem(self.radioButton[x]) if x == self.currentGovernorStr: self.radioButton[x].setChecked( True ) # Checks if x is current governor and should we have a tick on RadioButton # Add a button for applying changes self.applyButton = Plasma.PushButton(self.applet) self.applyButton.setText("Apply") self.applyButton.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)) self.layout.addItem(self.applyButton) QObject.connect(self.applyButton, SIGNAL("clicked()"), self.applyChanges)