def _setup(self): LMFitBaseTab._setup(self) self.orbital_options = LMFitOrbitalOptions() self.tree = LMFitTree(self.model.orbitals, self.model.parameters) self.interpolation = LMFitInterpolation() self.lmfit_options = LMFitOptions(self) self.change_axis() self.model.set_crosshair(self.crosshair.model) self._change_background(self.lmfit_options.get_background()) layout = QVBoxLayout() layout.setContentsMargins(3, 3, 3, 3) layout.setSpacing(3) self.scroll_area.widget().setLayout(layout) layout.insertWidget(0, self.slider) layout.insertWidget(1, self.orbital_options) layout.insertWidget(2, self.interpolation) layout.insertWidget(3, self.lmfit_options) layout.insertWidget(4, self.colormap) layout.insertWidget(5, self.crosshair) self.layout.insertWidget(1, self.tree)
class LateralPanel(QWidget): def __init__(self, parent=None): super(LateralPanel, self).__init__(parent) self.has_component = False self.vbox = QVBoxLayout(self) self.vbox.setContentsMargins(0, 0, 0, 0) self.vbox.setSpacing(0) # ui_tools.ComboBoxButton(self.combo, self.combo.clear, # self.style().standardPixmap(self.style().SP_TrashIcon)) # FIXME: translations # self.combo.setToolTip("Select the item from the Paste " # "%s\nor Paste them using: {}".format( # resources.get_shortcut("History-Copy").toString( # QKeySequence.NativeText), # resources.get_shortcut("History-Paste").toString( # QKeySequence.NativeText))) def add_component(self, widget): self.vbox.insertWidget(0, widget) self.has_component = True def add_new_copy(self, copy): pass def get_paste(self): pass
class CMyLove(QtWidgets.QWidget): def __init__(self, parent=None): super(CMyLove, self).__init__(parent) self.m_Num = 0 self.m_Lst = [] self._InitUI() def _InitUI(self): self.setGeometry(300, 200, 500, 300) self.m_Box = QVBoxLayout(self) btn = QPushButton("+", self) self.m_Box.addWidget(btn) btn.clicked.connect(self.S_Add) item = QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) self.m_Box.addItem(item) def S_Add(self): """同一帧添加的控件获取相对父控件位置为0""" self.m_Num += 1 btn = QPushButton("Test" + str(self.m_Num), self) self.m_Box.insertWidget(self.m_Num, btn) self.m_Lst.append(btn) for btn in self.m_Lst: # pos = btn.mapToParent(QPoint(0, 0)) pos = btn.pos() print("%s 相对父控件坐标:" % btn.text(), pos.x(), pos.y()) print("-" * 50)
class ScrollWidget(QScrollArea): def __init__(self): super(ScrollWidget, self).__init__() self._numWidget = 0 self._layout = QVBoxLayout() self._layout.addStretch(1) self._mainW = QWidget() self._mainW.setLayout(self._layout) self.setWidget(self._mainW) self.setWidgetResizable(True) def addWidgetItem(self, widget: QWidget, isTail=False): if isTail: self._layout.insertWidget(self._numWidget, widget) else: self._layout.insertWidget(0, widget) self._numWidget += 1 def delWidgetItem(self, widget: QWidget): self._layout.removeWidget(widget) self._numWidget -= 1 def resizeEvent(self, e: QResizeEvent): super().resizeEvent(e) width = e.size().width() if width > 0: self._mainW.setMaximumWidth(width)
class LogWidget(QWidget): ''' docstring: 统一处理和显示折叠消息盒 ''' def __init__(self, parent=None): super().__init__(parent) self.lay = QVBoxLayout(self) self.scrollarea = QScrollArea() self.lay.addWidget(self.scrollarea) self.content = QWidget() self.scrollarea.setWidget(self.content) self.scrollarea.setWidgetResizable(True) self.contentarea = QVBoxLayout(self.content) self.contentarea.addStretch() # 设置区间范围改变信号 self.scrollarea.verticalScrollBar().rangeChanged.connect( self.modifyBarValue) def modifyBarValue(self, min, max): if self.modifytime: bar = self.scrollarea.verticalScrollBar() bar.setValue(max) self.modifytime -= 1 # print(bar.maximum(), bar.minimum(), bar.value(), self.modifytime) def addLog(self, title, message, flag=False): ''' docstring: 添加日志消息,默认选项卡关闭 ''' index = self.contentarea.count() box = CollapsibleMessageBox(Title=title, defaultLayout=True, Message=message) self.contentarea.insertWidget(index - 1, box) if flag: box.toggle_button.animateClick() self.modifytime = 1
class VarPositionalParser(QScrollArea): def __init__(self, loadSaved=False): super().__init__() self.arg_list = [] self.mainWidget = QWidget() self.layout = QVBoxLayout(self.mainWidget) self.layout.setSizeConstraint(QLayout.SetFixedSize) self.argName = QLabel('args*') self.button_line = QWidget() self.button_line_layout = QHBoxLayout(self.button_line) self.addButton = QPushButton() self.addButton.setIcon(self.style().standardIcon(QStyle.SP_ArrowDown)) self.removeButton = QPushButton() self.removeButton.setIcon(self.style().standardIcon(QStyle.SP_ArrowUp)) self.button_line_layout.addWidget(self.addButton) self.button_line_layout.addWidget(self.removeButton) self.layout.addWidget(self.argName) self.layout.addWidget(self.button_line) # BAUSTELLE # wird durch edit->methodChanged->updateParams und edit->updateParams aufgerufen() self.addButton.clicked.connect(self.addArgument) self.removeButton.clicked.connect(self.removeArgument) #self.setLayout(self.layout) self.setWidget(self.mainWidget) self.setWidgetResizable(True) def addArgument(self, argName=None, argValue=None): argument = VarArg() if argName: argument.s_arg_name = argName if argValue: argument.s_arg_val = argValue # this is called when loading saved arguments if argName or argValue: argument.setText() self.layout.insertWidget(self.layout.count() - 1, argument) self.arg_list.append(argument) def removeArgument(self): #self.layout.removeWidget(self.lastAddedArgument) if self.arg_list: lastAddedArgument = self.arg_list[-1] lastAddedArgument.deleteLater() lastAddedArgument = None del self.arg_list[-1]
class ResultsList(QScrollArea): def __init__(self): super(ResultsList, self).__init__() self.setMaximumWidth(250) central = QWidget() self.setWidget(central) self.setWidgetResizable(True) self.layout = QVBoxLayout(central) self.layout.addStretch() self.widgets = [] timing.new_solve.register(self.new_solve) timing.discipline_changed.register(self.discipline_changed) def new_solve(self, solve, records): self.widgets.append(ResultWidget(self, solve)) self.layout.insertWidget(0, self.widgets[-1]) def remove_widget(self, widget): self.layout.removeWidget(widget) widget.setParent(None) def discipline_changed(self): for w in self.widgets: self.remove_widget(w) self.widgets = []
class InstallPage(QWidget): """Settings page for the installed plugins""" def __init__(self, parent, repo): """QWidget Dictionary -> Void Consumes the parent and the repository dictionary and sets up the install page in the settings area""" QWidget.__init__(self, parent) self._userPlugins = helper.getPlugins() self._repo = repo # Add a scrollArea that if they are more plugins that fit into the # settings page scrollArea = QScrollArea(self) scrollArea.setWidgetResizable(True) scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) baseLayout = QVBoxLayout() baseLayout.setAlignment(Qt.AlignTop) self.setLayout(baseLayout) baseWidget = QWidget() scrollArea.setWidget(baseWidget) baseLayout.addWidget(scrollArea) self._vbox = QVBoxLayout() baseWidget.setLayout(self._vbox) def update(self, userPlugins): """ListOfUserpluginEntry -> Void Consume a list of UserpluginEntry and repopulates the install page""" for i in reversed(range(self._vbox.count())): try: self._vbox.itemAt(i).widget().setParent(None) except AttributeError as e: qWarning("Can't call setParent of None type") labelText = "<h2>Install Plugins</h2>" if (len(self._repo["plugins"]) < 1): labelText += "<p>It seems we could not load the plugin repository.</p>" labelText += "<p style='color:red'>Make shure your internet connection is working and restart Enki.</p><p></p>" self._vbox.addWidget(QLabel(labelText)) for entry in self._repo["plugins"]: isInstalled = helper.isPluginInstalled(entry["name"], userPlugins) if isInstalled: self._vbox.addWidget(pluginspage.PluginTitlecard(isInstalled)) else: self._vbox.addWidget(InstallableTitlecard(entry, self)) def addPluginToUserPlugins(self, installableTitlecard): """InstallableTitlecard -> Void Consumes an InstallableTitlecard and insert an PluginTitleCard instead of itself""" index = self._vbox.indexOf(installableTitlecard) name = installableTitlecard.modulename() pluginEntry = helper.initPlugin(name) if pluginEntry: self._userPlugins.append(pluginEntry) self._vbox.insertWidget(index, pluginspage.PluginTitlecard(pluginEntry))
class Tab(QWidget): layout_inputs = None name = "Novo" amount = 0 inputs = [] parent = None def __init__(self, parent, name, amount): super(Tab, self).__init__() self.name = name self.amount = amount self.parent = parent self.init_ui() def init_ui(self): self.layout_inputs = QVBoxLayout() self.setLayout(self.layout_inputs) for i in range(self.amount): value = QLineEdit() value.textChanged.connect(self.keep_valid) # value.textChanged.connect(self.parent.input_changed) value.setText('0') value.setInputMask('9999999') value.setCursorPosition(0) self.inputs.append(value) self.layout_inputs.addWidget(value) l = QVBoxLayout() l.addSpacing(1) l.addStretch(-1) self.layout_inputs.addLayout(l) def update_tab(self, amount): if amount > self.amount: for i in range(amount - self.amount): value = QLineEdit() value.textChanged.connect(self.keep_valid) # value.textChanged.connect(self.parent.input_changed) value.setText('0') value.setInputMask('9999999') value.setCursorPosition(0) self.inputs.append(value) self.layout_inputs.insertWidget(0, value) else: for i in range(amount, self.amount): self.layout_inputs.removeWidget(self.inputs[-1]) self.inputs[-1].hide() self.inputs[-1].close() self.inputs.remove(self.inputs[-1]) self.amount = amount def keep_valid(self, txt): if txt == "": self.value.setText("0") self.value.setCursorPosition(0)
def __init__(self, parent=None): super(GChGraphFromNT, self).__init__(parent=parent) main_vbox = QVBoxLayout(self) self.canvas = ChStaticMplCanvas(self) main_vbox.addWidget(self.canvas) self.toolbar = NavigationToolbar(self.canvas, self) main_vbox.insertWidget(0, self.toolbar)
class NavigationContainer(QWidget): def __init__(self, parent=None): super(NavigationContainer, self).__init__(parent) self._layout = None # QVBoxLayout self._tabBar = None # TabBar self._layout = QVBoxLayout(self) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self.setLayout(self._layout) self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) def addWidget(self, widget): ''' @param: widget QWidget ''' self._layout.addWidget(widget) def setTabBar(self, tabBar): ''' @param: tabBar TabBar ''' self._tabBar = tabBar self._layout.addWidget(self._tabBar) self.toggleTabsOnTop(gVar.qzSettings.tabsOnTop) def toggleTabsOnTop(self, enable): self.setUpdatesEnabled(False) self._layout.removeWidget(self._tabBar) index = 0 if not enable: index = self._layout.count() self._layout.insertWidget(index, self._tabBar) top = enable and 2 or 0 bottom = enable and 2 or 0 self._layout.setContentsMargins(0, top, 0, bottom) self.setUpdatesEnabled(True) # private: # override def paintEvent(self, event): ''' @param: event QPaintEvent ''' super(NavigationContainer, self).paintEvent(event) # Draw line at the bottom of navigation bar if tabs are on top # To visually distinguish navigation bar from the page if gVar.qzSettings.tabsOnTop: p = QPainter(self) lineRect = QRect(0, self.height() - 1, self.width(), 1) color = self.palette().window().color().darker(125) p.fillRect(lineRect, color)
class SelectData(QWidget): def __init__(self, HDV): QWidget.__init__(self) self.HDV = HDV self.data_items = list() self._initUI() self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint) def _initUI(self): self.setGeometry(350, 350, 400, 300) self.setWindowTitle('Select Data') # self.setStyleSheet("background-color: gray;") self._make_widgets() self._make_layout() self._make_connect() def closeEvent(self, event): pass def _make_widgets(self): pass def _make_layout(self): self.layout = QVBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addStretch() def _make_connect(self): pass # self.dataTree.itemChanged.connect(self.onChangeHandler) def addFolder(self, folder): pass def add_data_handle(self, data_handle): self.data_items.append(DataListItem(data_handle, parent=self)) data_handle.set_data_item(self.data_items[-1]) self.layout.insertWidget(self.layout.count() - 1, self.data_items[-1]) def remove_data_handle(self, data_handle): self.layout.removeWidget(data_handle.data_item) self.data_items.remove(data_handle.data_item) data_handle.data_item.deleteLater()
class QScrollableBox(QWidget): def __init__(self, parent): super(QScrollableBox, self).__init__(parent) mainLayout = QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) self.scrollArea = QScrollArea(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) self.scrollArea.setSizePolicy(sizePolicy) self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.scrollArea.setWidgetResizable(True) mainLayout.addWidget(self.scrollArea) self.setLayout(mainLayout) scrollContents = QWidget() self.m_layout = QVBoxLayout() self.m_layout.setContentsMargins(0, 0, 0, 0) self.m_layout.setSizeConstraint(QLayout.SetNoConstraint) scrollContents.setLayout(self.m_layout) self.scrollArea.setWidget(scrollContents) def addWidget(self, w): if not w: return count = self.m_layout.count() if count > 1: self.m_layout.removeItem(self.m_layout.itemAt(count - 1)) self.m_layout.addWidget(w) w.show() self.m_layout.addStretch() self.scrollArea.update() def removeWidget(self, w): self.m_layout.removeWidget(w) self.scrollArea.update() def insertWidget(self, i, w): self.m_layout.insertWidget(i, w) self.scrollArea.update() def clearWidgets(self): item = self.m_layout.takeAt(0) while item != None: item.widget().deleteLater() self.m_layout.removeItem(item) del item self.scrollArea.update() def indexOf(self, w): return self.m_layout.indexOf(w)
class ResizableFramelessContainer(QWidget): """A resizable frameless container ResizableFramelessContainer can be moved and resized by mouse. Call `attach_widget` to attach an inner widget and `detach` to detach the inner widget. NOTE: this is mainly designed for picture in picture mode currently. """ def __init__(self, ): super().__init__(parent=None) self._widget = None self._old_pos = None self._widget = None # setup window layout self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint) self._layout = QVBoxLayout(self) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self.setMouseTracking(True) QShortcut(QKeySequence.Cancel, self).activated.connect(self.hide) def attach_widget(self, widget): """set inner widget""" self._widget = widget self._widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._layout.insertWidget(0, self._widget) def detach(self): self._layout.removeWidget(self._widget) self._widget = None def mousePressEvent(self, e): self._old_pos = e.globalPos() def mouseMoveEvent(self, e): # NOTE: e.button() == Qt.LeftButton don't work on Windows # on Windows, even I drag with LeftButton, the e.button() return 0, # which means no button if self._old_pos is not None: delta = e.globalPos() - self._old_pos self.move(self.x() + delta.x(), self.y() + delta.y()) self._old_pos = e.globalPos() def mouseReleaseEvent(self, e): self._old_pos = None def resizeEvent(self, e): super().resizeEvent(e)
class AccountsSummaryContentPanel(SummaryContentPanel, SetupableComponent): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setFixedWidth(400) self.setFixedHeight(355) self.__identifierFont = QFont("Nimbus Sans L", 14) self.__driveIcon = QPixmap(":/googledrive.png").scaled( 24, 24, Qt.IgnoreAspectRatio) self.__dropboxIcon = QPixmap(":/dropbox.png").scaled( 24, 24, Qt.IgnoreAspectRatio) self.__accountWidgets = [] self.__layout = None self._setup() def _setup(self): self.__layout = QVBoxLayout() self.__layout.setContentsMargins(5, 5, 5, 5) self.__layout.setAlignment(Qt.AlignTop | Qt.AlignHCenter) self.__layout.setSpacing(5) self.__layout.addStretch(1) self.setLayout(self.__layout) def setData(self, accounts): currentAccountCount = len(self.__accountWidgets) newAccountCount = len(accounts) for i in range(newAccountCount): identifier = accounts[i].identifier pixMap = self.__driveIcon if accounts[ i].accountType == AccountTypes.GoogleDrive else self.__dropboxIcon if i > currentAccountCount - 1: accountWidget = AccountSummaryCard( accountIdentifier=identifier, accountIdentifierFont=self.__identifierFont, accountIcon=pixMap) self.__accountWidgets.append(accountWidget) self.__layout.insertWidget(i, accountWidget) else: self.__accountWidgets[i].setData(identifier, pixMap) self.__accountWidgets[i].setUnderline( True) if i < newAccountCount - 1 else self.__accountWidgets[ i].setUnderline(False) if currentAccountCount > newAccountCount: for i in range(newAccountCount, currentAccountCount): self.__accountWidgets[i].hide() self.__layout.removeWidget(self.__accountWidgets[i]) del self.__accountWidgets[newAccountCount:]
class BasePage(QWidget): finished = pyqtSignal() def __init__(self, parent=None): super().__init__(parent=parent) self._pager = None self.nextEnabled = True self.previousEnabled = True self.layout = QVBoxLayout(self) self.layout.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.setSizePolicy( QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)) self.setStyleSheet("QLabel {font: 20pt}") self.labels = [] self.picture = None @pyqtSlot() def onEnter(self): pass def setPager(self, pager): self._pager = pager def getButtonHeight(self): if self._pager is not None: return self._pager.getButtonHeight() else: return 100 @pyqtSlot() def onExit(self): pass def getPictureSize(self): s = self.size() - QSize(0, self.getButtonHeight()) for l in self.labels: s -= QSize(0, l.size().height()) return QSize(max(400, s.width()), max(400, s.height())) def resizeEvent(self, event): if self.picture is not None: i = self.layout.indexOf(self.picture) self.layout.removeWidget(self.picture) self.picture.setParent(None) self.picture = QLabel(self) self.picture.setPixmap( self.pixMap.scaled(self.getPictureSize(), Qt.KeepAspectRatio)) self.layout.insertWidget(i, self.picture)
class CenterWidget(QWidget): def __init__(self): super().__init__() # use qwidget to creat window self.initUI() def initUI(self): self.setMouseTracking(True) self.pathway = PathDialog() self.vbox = QVBoxLayout(self) self.vbox.addWidget(self.pathway) self.setLayout(self.vbox) self.setGeometry(100, 100, 100, 40) self.setWindowTitle('hahahaha') self.setAcceptDrops(True) # 允许拖拽 verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.vbox.addItem(verticalSpacer) self.calcium_plane() def mini_plane(self): global gl_DATA if hasattr(self, 'miniplane'): if self.miniplane.isVisible(): self.miniplane.setVisible(False) else: self.miniplane.setVisible(True) else: self.miniplane = MiniPlane() self.vbox.insertWidget(1, self.miniplane) def calcium_plane(self): if hasattr(self, 'calciplane'): if self.calciplane.isVisible(): self.calciplane.setVisible(False) else: self.calciplane.setVisible(True) else: self.calciplane = CalciumPlane() self.vbox.insertWidget(1, self.calciplane)
class Example(QMainWindow): def __init__(self): super().__init__() self.count_of_buttons = 1 self.centralWidget = QWidget() self.setCentralWidget(self.centralWidget) self.setGeometry(700, 200, 500, 400) self.button_add = QPushButton('Add') self.button_add.clicked.connect(self.add_button) self.button_clear = QPushButton('Clear') # +++ self.button_clear.clicked.connect(self.clear_button) # +++ self.layout_buttons = QVBoxLayout() self.layout_buttons.addStretch() self.frame = QFrame() self.frame.setMinimumSize(200, 200) self.frame.setFrameStyle(QFrame.Box) self.frame.setLayout(self.layout_buttons) self.main_layout = QGridLayout(self.centralWidget) # QGridLayout self.main_layout.addWidget(self.button_add, 0, 0) self.main_layout.addWidget(self.button_clear, 0, 1) # +++ self.main_layout.addWidget(self.frame, 1, 0, 1, 2) # +++ def add_button(self): # - self.main_layout.addWidget(self.frame) self.button = QPushButton(f"Кнопка № {self.count_of_buttons}") self.button.clicked.connect( lambda ch, btn=self.button: self.pressed_btn(btn)) self.count_of_buttons += 1 self.layout_buttons.insertWidget(0, self.button) def pressed_btn(self, btn): print(f"кнопка нажата: {btn.text()}") # +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv def clear_button(self): widgets = self.frame.layout().count() if widgets > 1: for i in range(widgets - 1): widget = self.frame.layout().itemAt(0).widget() self.frame.layout().removeWidget(widget) widget.hide()
class ModelFrameWindow(FrameWindow): def __init__(self): super(ModelFrameWindow, self).__init__() self.holder = DataHolder() self.setupView() def setupView(self): self.dataArea = DataArea(self.holder) self.layout = QVBoxLayout() self.layout.setContentsMargins(2, 2, 2, 2) self.layout.setSpacing(5) self.layout.setAlignment(Qt.AlignLeft) self.layout.addStretch(1) self.setCentralLayout(self.layout) def insertWidget(self, idx, widget): self.layout.insertWidget(idx, widget, alignment=Qt.AlignBottom)
class _GrampsGuiWidget(QWidget): def __init__(self, configuration: GrampsConfiguration, *args, **kwargs): super().__init__(*args, **kwargs) self._configuration = configuration self._layout = QVBoxLayout() self.setLayout(self._layout) self._family_trees_widget = None self._build_family_trees() self._add_family_tree_button = QPushButton('Add a family tree') self._add_family_tree_button.released.connect(self._add_family_tree) self._layout.addWidget(self._add_family_tree_button, 1) @reactive(on_trigger_call=True) def _build_family_trees(self) -> None: if self._family_trees_widget is not None: self._layout.removeWidget(self._family_trees_widget) self._family_trees_widget.setParent(None) del self._family_trees_widget self._family_trees_widget = QWidget() family_trees_layout = QGridLayout() self._family_trees_widget.setLayout(family_trees_layout) self._family_trees_widget._remove_buttons = [] for i, family_tree in enumerate(self._configuration.family_trees): def _remove_family_tree() -> None: del self._configuration.family_trees[i] family_trees_layout.addWidget(Text(str(family_tree.file_path)), i, 0) self._family_trees_widget._remove_buttons.insert( i, QPushButton('Remove')) self._family_trees_widget._remove_buttons[i].released.connect( _remove_family_tree) family_trees_layout.addWidget( self._family_trees_widget._remove_buttons[i], i, 1) self._layout.insertWidget(0, self._family_trees_widget, alignment=Qt.AlignTop) def _add_family_tree(self): window = _AddFamilyTreeWindow(self._configuration.family_trees, self) window.show()
def _create_rule_widget(self, layout: QVBoxLayout, rule: Rule) -> RuleWidget: rule_widget = RuleWidget(rule) rule_widget.register_callbacks( lambda: layout.insertWidget( layout.indexOf(rule_widget), self._create_rule_widget(layout, Rule({"type": "app"}))), lambda: rule_widget.remove_from(layout)) return rule_widget
class QtLayerList(QScrollArea): def __init__(self): super().__init__() self.setWidgetResizable(True) #self.setFixedWidth(315) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scrollWidget = QWidget() self.setWidget(scrollWidget) self.layersLayout = QVBoxLayout(scrollWidget) self.layersLayout.addStretch(1) def insert(self, index, total, layer): """Inserts a layer widget at a specific index """ if layer._qt is not None: self.layersLayout.insertWidget(total - index-1, layer._qt) def remove(self, layer): """Removes a layer widget """ if layer._qt is not None: self.layersLayout.removeWidget(layer._qt) layer._qt.deleteLater() layer._qt = None def reorder(self, layerList): """Reorders list of layer widgets by looping through all widgets in list sequentially removing them and inserting them into the correct place in final list. """ for i in range(len(layerList)): layer = layerList[i] if layer._qt is not None: self.layersLayout.removeWidget(layer._qt) self.layersLayout.insertWidget(len(layerList) - i-1,layer._qt) def mouseReleaseEvent(self, event): """Unselects all layer widgets """ self.layersLayout.itemAt(0).widget().unselectAll()
class ScrollPreviewComponent(QFrame): def __init__(self, top): super().__init__() self.top = top self.setMinimumSize(380, 330) self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.scroll = QScrollArea(self) self.scroll.setFixedSize(380, 330) self.scroll.setMinimumHeight(100) self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scroll.setWidgetResizable(True) self.scroll.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.scrollContents = QWidget() self.scrollContents.setGeometry(QRect(0, 0, 380, 330)) self.spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.vLayout = QVBoxLayout(self.scrollContents) self.vLayout.addSpacerItem(self.spacer) self.scroll.setWidget(self.scrollContents) self.itemPreviewList = [] def addItemPreview(self, description: str, imgPath: str): ip = ItemPreviewComponent(self, description, imgPath) self.vLayout.insertWidget(0, ip) self.itemPreviewList.append(ip) def clearAll(self): while self.itemPreviewList: self.vLayout.removeWidget(self.itemPreviewList[0]) self.itemPreviewList.pop(0) def getLayout(self) -> QVBoxLayout: return self.vLayout def getPreviewList(self): return self.itemPreviewList
class ProductTableWidget(QFrame): def __init__(self, parent=None): super().__init__(parent=parent) self.initUI() def initUI(self): self.layout = QVBoxLayout() self.layout.setContentsMargins(10, 13, 10, 0) self.layout.setSpacing(0) self.layout.addWidget(ProductTableHeaderWidget()) self.products_layout = QVBoxLayout() table = QWidget() # table.setStyleSheet('border: none; background: transparent') table.setLayout(self.products_layout) scroll = QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(table) # scroll.setStyleSheet('border: none; background: transparent') self.layout.addWidget(scroll, 1) table.setLayout(self.products_layout) self.products_layout.addStretch(1) self.setLayout(self.layout) self.setStyleSheet(get_styles('style')) self.setStyleSheet(get_styles('product-table')) # def update_cart(self): # for p in cart: # self.layout.addWidget(ProductTableItemWidget(p)) def add2cart(self, product: Product): self.products_layout.insertWidget(self.products_layout.count() - 1, ProductTableItemWidget(product))
class LateralPanel(QWidget): def __init__(self, parent=None): super(LateralPanel, self).__init__(parent) self.has_component = False self.vbox = QVBoxLayout(self) self.vbox.setContentsMargins(0, 0, 0, 0) self.vbox.setSpacing(0) # hbox = QHBoxLayout() # hbox.setContentsMargins(0, 0, 0, 0) # hbox.setSpacing(0) # self.combo = QComboBox() # ui_tools.ComboBoxButton(self.combo, self.combo.clear, # self.style().standardPixmap(self.style().SP_TrashIcon)) # FIXME: translations # self.combo.setToolTip("Select the item from the Paste " # "History list.\nYou can Copy items into this list with: " # "%s\nor Paste them using: {}".format( # resources.get_shortcut("History-Copy").toString( # QKeySequence.NativeText), # resources.get_shortcut("History-Paste").toString( # QKeySequence.NativeText))) # self.combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) # hbox.addWidget(self.combo) # self.vbox.addLayout(hbox) def add_component(self, widget): self.vbox.insertWidget(0, widget) self.has_component = True def add_new_copy(self, copy): pass # self.combo.insertItem(0, copy) # self.combo.setCurrentIndex(0) # if self.combo.count() > settings.COPY_HISTORY_BUFFER: # self.combo.removeItem(self.combo.count() - 1) def get_paste(self): pass
class PlayListTable(QScrollArea): '''播放列表主体''' def __init__(self, parent): super().__init__(parent) self.setObjectName('PlayListTable') self.set_UI() def set_UI(self): self.setFrameShape(QFrame.NoFrame) ''' QScrollArea只能设置一个widget 因此要在这一个widget上添加其他widget ''' self.contents = QFrame(self) self.contents.setObjectName('Contents') self.contents.setFrameShape(QFrame.NoFrame) '''这个layout是给contents的''' self.set_layout() '''设置滚动条''' self.scroll_bar = QScrollBar(self) self.setVerticalScrollBar(self.scroll_bar) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.setWidgetResizable(True) self.setWidget(self.contents) with open('.\\QSS\\play_list_table.qss', 'r') as file_obj: self.setStyleSheet(file_obj.read()) def set_layout(self): self.layout = QVBoxLayout() self.layout.setSpacing(0) self.layout.addStretch(1) self.layout.setContentsMargins(0, 0, 0, 0) self.contents.setLayout(self.layout) def insert_entry(self, entry, index): self.layout.insertWidget(index, entry)
class LateralPanel(QWidget): splitEditor = pyqtSignal('QObject*', 'QObject*', bool) closeSplit = pyqtSignal(QWidget) def __init__(self, parent=None): super(LateralPanel, self).__init__(parent) self.has_component = False self.vbox = QVBoxLayout(self) self.vbox.setContentsMargins(0, 0, 0, 0) hbox = QHBoxLayout() hbox.setContentsMargins(0, 0, 5, 5) self.combo = QComboBox() ui_tools.ComboBoxButton(self.combo, self.combo.clear, self.style().standardPixmap(self.style().SP_TrashIcon)) self.combo.setToolTip(self.tr("Select the item from the Paste " "History list.\nYou can Copy items into this list with: " "%s\nor Paste them using: %s") % (resources.get_shortcut("History-Copy").toString( QKeySequence.NativeText), resources.get_shortcut("History-Paste").toString( QKeySequence.NativeText))) self.combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) hbox.addWidget(self.combo) self.vbox.addLayout(hbox) def add_component(self, widget): self.vbox.insertWidget(0, widget) self.has_component = True def add_new_copy(self, copy): self.combo.insertItem(0, copy) self.combo.setCurrentIndex(0) if self.combo.count() > settings.COPY_HISTORY_BUFFER: self.combo.removeItem(self.combo.count() - 1) def get_paste(self): return self.combo.currentText()
class ElementOption(QWidget): def __init__( self, controller: TouchManagerController, model: TouchManagerModel, ): super(QWidget, self).__init__() self.model = model self.controller = controller self.main_lay = QVBoxLayout() self.wid: QWidget = ButtonOption(self, controller, model) self.currentType: ShowAreaState = ShowAreaState.Buttons self.setupUI() self.initControllers() self.areatypeChanged(self.controller.currentAreaType) def reset(self): self.lblInfoDesc.clear() def setupUI(self): self.main_lay.setAlignment(Qt.AlignTop) self.main_lay.setContentsMargins(0, 0, 0, 0) # self.setFixedHeight(150) self.main_lay.addWidget(self.wid) self.setLayout(self.main_lay) def initControllers(self): self.controller.onCurrentShowAreaChanged.connect(self.areatypeChanged) self.controller.onElementSelectionChanged.connect( self.onElementChanged) def onElementChanged(self): self.wid.changeData(self.controller.currentCoordinates) def areatypeChanged(self, new_type: ShowAreaState): self.clearLayout() if new_type == ShowAreaState.Buttons: self.wid.deleteLater() self.wid.setParent(None) self.wid = ButtonOption(self.main_lay, self.controller, self.model) self.main_lay.insertWidget(0, self.wid) elif new_type == ShowAreaState.Movements: self.wid.deleteLater() self.wid.setParent(None) self.wid = MovementOption(self.main_lay, self.controller, self.model) self.main_lay.insertWidget(0, self.wid) elif new_type == ShowAreaState.FrameCheck: self.wid.deleteLater() self.wid.setParent(None) self.wid = FrameCheckOption(self.main_lay, self.controller, self.model) self.main_lay.insertWidget(0, self.wid) def clearLayout(self): self.wid.setParent(None)
def __init__(self, figure_canvas, ttoolbar=toolbar_type.ALL, parent=None): super(GChGraphWidget, self).__init__(parent=parent) main_vbox = QVBoxLayout(self) if ttoolbar != toolbar_type.NAVIGATION_TOOLBAR: splitter = QSplitter(QtCore.Qt.Horizontal, self) splitter.setStyle(QStyleFactory.create('Cleanlooks')) self.canvas = ChStaticMplCanvas(splitter) splitter.addWidget(self.canvas) self.properties = GChGraphPoperties(self.canvas, self) splitter.addWidget(self.properties) main_vbox.addWidget(splitter) else: figure_canvas.setParent(self) self.canvas = figure_canvas main_vbox.addWidget(self.canvas) if ttoolbar in (toolbar_type.NAVIGATION_TOOLBAR, toolbar_type.ALL): self.toolbar = NavigationToolbar(self.canvas, self) main_vbox.insertWidget(0, self.toolbar)
def _setup(self): LMFitBaseTab._setup(self) self.result = LMFitResult(self.current_result[1], self.model) self.tree = LMFitResultTree( self.model.orbitals, self.current_result[1].params, self.model.background_equation[1]) self.crosshair._set_model(self.model.crosshair) layout = QVBoxLayout() self.scroll_area.widget().setLayout(layout) layout.insertWidget(0, self.slider) layout.insertWidget(1, self.result) layout.insertWidget(3, self.colormap) layout.insertWidget(4, self.crosshair) self.layout.insertWidget(1, self.tree)
class notifyTab(QWidget): def __init__(self,parent_): super(notifyTab,self).__init__(parent_) self.parent_=parent_ self.obj=parent_.obj self.initUI() def initUI(self): self.btn = [] self.notif_lbl = [] self.tag_lbl = [] self.nFrames =[] self.d_ = False for i in range(0,len(self.obj.notif)): pixmap=QPixmap(self.obj.tagDict[self.obj.notif[i].tag]) pixmap = pixmap.scaled(45, 45) self.tag_lbl.append(QLabel(self)) self.tag_lbl[i].setPixmap(pixmap) for i1 in range(0,len(self.obj.notif)): self.notif_lbl.append(QLabel(self)) self.notif_lbl[i1].setScaledContents(False) self.notif_lbl[i1].setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.notif_lbl[i1].setText(self.obj.notif[i1].notif_text) self.notif_lbl[i1].setObjectName("nlbl") self.btn.append(QPushButton('Get Link')) self.btn[i1].setObjectName("btn") for i2 in range(0,len(self.obj.notif)): self.nFrames.append(notifyFrames(self.notif_lbl[i2],self.tag_lbl[i2],self.btn[i2])) tag = self.obj.notif[i2].tag if tag ==2 or tag==3 or tag==4: self.nFrames[i2].setObjectName('nFrameOdd') else: self.nFrames[i2].setObjectName('nFrameEven') self.widget = QWidget(self) self.vbox = QVBoxLayout() for index, frame in enumerate(self.nFrames): self.vbox.addWidget(frame) if len(self.nFrames)<4: self.dframe = QFrame() self.dframe.setObjectName('nFrameDummy') self.vbox.addWidget(self.dframe) self.d_ = True self.vbox.setContentsMargins(0,0,0,0) self.vbox.setSpacing(3) self.widget.setLayout(self.vbox) self.scroll = QScrollArea(self) self.scroll.setWidget(self.widget) self.scroll.setWidgetResizable(True) self.scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) vbox1 = QVBoxLayout() vbox1.setContentsMargins(0,0,0,0) vbox1.setSpacing(0) vbox1.addWidget(self.scroll) self.setLayout(vbox1) def updater(self): marker=len(self.nFrames) marker1 = len(self.nFrames) for i in range(0,len(self.obj.notif)): pixmap=QPixmap(self.obj.tagDict[self.obj.notif[i].tag]) pixmap = pixmap.scaled(45, 45) self.tag_lbl.append(QLabel(self)) self.tag_lbl[marker].setPixmap(pixmap) marker=marker+1 marker=marker1 for i1 in range(0,len(self.obj.notif)): self.notif_lbl.append(QLabel(self)) self.notif_lbl[marker].setScaledContents(False) self.notif_lbl[marker].setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.notif_lbl[marker].setText(self.obj.notif[i1].notif_text) self.notif_lbl[marker].setObjectName("nlbl") self.btn.append(QPushButton('Get Link')) self.btn[marker].setObjectName("btn") marker+=1 marker=marker1 for i2 in range(0,len(self.obj.notif)): self.nFrames.append(notifyFrames(self.notif_lbl[marker],self.tag_lbl[marker],self.btn[marker])) marker+=1 marker=marker1 for i3 in range(len(self.nFrames)-1,marker-1,-1): self.vbox.insertWidget(0,self.nFrames[i3]) tag = self.obj.notif[i3-marker].tag if tag ==2 or tag==3 or tag==4: self.nFrames[i3].setObjectName('nFrameOdd') self.nFrames[i3].setStyleSheet(' #nFrameOdd{background-color:#F5F5DC;min-height:110px;max-height:110px;min-width:805px;}') else: self.nFrames[i3].setObjectName('nFrameEven') self.nFrames[i3].setStyleSheet(' #nFrameEven{background-color: rgb(255, 250, 175);min-height:110px;max-height:110px;min-width:805px;}') if len(self.nFrames)>=4 and self.d_==True: child = self.vbox.takeAt(len(self.nFrames)) if child.widget() is not None: child.widget().deleteLater() elif child.layout() is not None: clearLayout(child.layout()) self.dframe.deleteLater() self.d_=False
class PlotWindow(QWidget): def __init__(self, tab): super(PlotWindow, self).__init__() self.tab = tab self.allAxes = {} self.curveList = [] self.extraLines = [] self.layout = QHBoxLayout() self.graph_layout = QVBoxLayout() self.gbox_layout = QVBoxLayout() self.tabGBActor = QTabWidget() self.dateplot = DatePlot(self) self.customize = Customize(self) self.button_arrow = self.ButtonArrow() self.button_del_graph = self.ButtonDelete() self.gbox_layout.addWidget(self.dateplot) self.gbox_layout.addWidget(self.customize) self.gbox_layout.addWidget(self.tabGBActor) self.gbox_layout.addWidget(self.button_del_graph) self.layout.addLayout(self.graph_layout) self.layout.addWidget(self.button_arrow) self.layout.addLayout(self.gbox_layout) for widget in [self.dateplot, self.customize, self.tabGBActor]: widget.setMaximumWidth(400) self.setLayout(self.layout) @property def mainwindow(self): return self.tab.mainwindow @property def config(self): return self.dateplot.config @property def axes2curves(self): d = {ax: [] for ax in [None] + list(self.allAxes.values())} for curve in self.curveList: d[curve.getAxes()].append(curve) return d @property def line2Curve(self): return {curve.line: curve for curve in self.curveList} @property def axes2id(self): d = {ax: id for id, ax in self.allAxes.items()} d[None] = None return d def createGraph(self, custom): try: self.graph.close() self.graph_layout.removeWidget(self.graph) self.graph.deleteLater() except AttributeError: pass self.graph = Graph(self, custom) self.graph_layout.insertWidget(0, self.graph) def getAxes(self, newType, i=-1): for i, ax in self.allAxes.items(): try: curve = self.axes2curves[ax][0] if curve.type == newType: return ax except IndexError: return ax if i == 3: raise ValueError('No Axe available') return i + 1 def setAxes(self, allAxes): for idAxes, oldAxes in list(self.allAxes.items()): self.unsetLines(oldAxes, allAxes) self.allAxes.pop(idAxes, None) self.allAxes = allAxes def unsetLines(self, axes, newAxes): while axes.lines: line = axes.lines[0] axes.lines.remove(line) try: curve = self.line2Curve[line] curve.line = False if curve.getAxes() not in newAxes.values(): curve.setAxes(None) except KeyError: pass del line def addCurve(self, curveConf): new_curve = Curve(self, curveConf) axes = self.getAxes(new_curve.type) if isinstance(axes, int): idAxes = axes self.customize.allAxes[idAxes].checkbox.setChecked(2) axes = self.allAxes[idAxes] new_curve.setAxes(axes) self.appendCurve(new_curve) self.graph.plotCurves(new_curve) return new_curve def appendCurve(self, new_curve): self.curveList.append(new_curve) self.customize.appendRow(new_curve) def switchCurve(self, axeId, curve): ax = self.allAxes[axeId] if axeId is not None else None self.graph.switchCurve(ax, curve) def removeCurve(self, curve): self.curveList.remove(curve) self.graph.removeCurve(curve) try: checkbox = curve.checkbox checkbox.setCheckable(True) checkbox.setChecked(0) except RuntimeError: pass # Checkbox could have been already deleted def constructGroupbox(self, config): while self.tabGBActor.count(): widget = self.tabGBActor.widget(0) self.clearLayout(widget.layout()) self.tabGBActor.removeTab(0) widget.close() widget.deleteLater() sortedModule = self.sortCfg(config) for actorname in sorted(sortedModule): config = sortedModule[actorname] if config: t = TabActor(self, config) self.tabGBActor.addTab(t, actorname) def showhideConfig(self, button_arrow): if not self.tabGBActor.isHidden(): self.tabGBActor.hide() self.dateplot.hide() self.customize.hide() self.button_del_graph.hide() button_arrow.setIcon(self.mainwindow.icon_arrow_left) else: self.tabGBActor.show() self.button_del_graph.show() self.dateplot.show() self.customize.show() button_arrow.setIcon(self.mainwindow.icon_arrow_right) def ButtonDelete(self): button = QPushButton('Remove Graph') button.clicked.connect(partial(self.removeGraph, self.layout)) return button def ButtonArrow(self): button_arrow = QPushButton() button_arrow.setIcon(self.mainwindow.icon_arrow_right) button_arrow.clicked.connect(partial(self.showhideConfig, button_arrow)) button_arrow.setStyleSheet('border: 0px') return button_arrow def removeGraph(self, layout): self.clearLayout(layout) self.tab.removeGraph(self) def clearLayout(self, layout): if layout is not None: while layout.count(): item = layout.takeAt(0) widget = item.widget() if widget is not None: widget.deleteLater() else: self.clearLayout(item.layout()) def table2label(self, tablename, mergeAIT=False): for key, label in self.mainwindow.cuArms.items(): if key in tablename: return label if mergeAIT: return 'AIT' else: return tablename.split('__')[0].upper() def sortCfg(self, config): sortedDict = {} for dev in config: label = self.table2label(tablename=dev.tablename, mergeAIT=False) try: sortedDict[label].append(dev) except KeyError: sortedDict[label] = [dev] return sortedDict