class WidgetContent(QWidget): def __init__(self, mdi): super(WidgetContent, self).__init__() self.mdi = mdi self.layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) self.setLayout(self.layout) self.menu_btn = QPushButton("Menu") self.menu_btn.clicked.connect(self.show_menu) self.layout.addWidget(self.menu_btn) def show_menu(self): self.animation = QPropertyAnimation(self.mdi.menu, b"size") self.animation.setDuration(150) self.animation.setStartValue(QSize(0, self.mdi.height())) self.animation.setEndValue(QSize(270, self.mdi.height())) self.animation.start() self.mdi.overlay.show() self.mdi.menu.show() self.mdi.setActiveSubWindow(self.mdi.overlay) self.mdi.setActiveSubWindow(self.mdi.menu) def paintEvent(self, event): opt = QStyleOption() opt.initFrom(self) p = QPainter(self) self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)
class OptionalCurrencyComboBox(QWidget): changed = Signal() name_updated = Signal(str) def __init__(self, parent): QWidget.__init__(self, parent) self._id = 0 self.layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.null_flag = QCheckBox(parent) self.null_flag.setChecked(False) self.null_flag.setText(self.tr("Currency")) self.layout.addWidget(self.null_flag) self.currency = CurrencyComboBox(parent) self.currency.setEnabled(False) self.layout.addWidget(self.currency) self.setLayout(self.layout) self.setFocusProxy(self.null_flag) self.null_flag.clicked.connect(self.onClick) self.currency.changed.connect(self.onCurrencyChange) def setText(self, text): self.null_flag.setText(text) def getId(self): return self._id if self._id else None def setId(self, new_value): if self._id == new_value: return self._id = new_value self.updateView() name = JalDB().get_asset_name(self._id) self.name_updated.emit('' if name is None else name) currency_id = Property(int, getId, setId, notify=changed, user=True) def updateView(self): has_value = True if self._id else False if has_value: self.currency.selected_id = self._id self.null_flag.setChecked(has_value) self.currency.setEnabled(has_value) @Slot() def onClick(self): if self.null_flag.isChecked(): if self.currency.selected_id == 0: self.currency.selected_id = JalSettings().getValue('BaseCurrency') self.currency_id = self.currency.selected_id else: self.currency_id = 0 self.changed.emit() @Slot() def onCurrencyChange(self, _id): self.currency_id = self.currency.selected_id self.changed.emit()
def __init__(self, base, name, callback, *args, **kwargs): TritonWidget.__init__(self, base, *args, **kwargs) self.callback = callback self.setWindowTitle(name) self.setBackgroundColor(self, Qt.white) self.boxLayout = QVBoxLayout(self) self.boxLayout.setContentsMargins(0, 5, 0, 0) layout = None for i, icon in enumerate(os.listdir('icons')): if (not layout) or i % 10 == 0: widget = QWidget() layout = QHBoxLayout(widget) layout.setContentsMargins(5, 5, 5, 5) self.boxLayout.addWidget(widget) name = os.path.join('icons', icon) button = PixmapButton(QPixmap(name).scaled(48, 48)) button.clicked.connect(self.makeIconCallback(name)) button.setToolTip(icon) layout.addWidget(button) self.setFixedSize(self.sizeHint()) self.center() self.show()
def __init__(self): super(Window, self).__init__() self.installEventFilter(self) layout = QHBoxLayout() layout.setSpacing(0) layout.setContentsMargins(10, 10, 10, 10) layout.addWidget(self.createMainSection()) layout.setStretch(0, 580) self.patchbay = self.createPatchbay() layout.addWidget(self.patchbay) layout.setStretch(1, 280) layout.setSpacing(8) self.setStyleSheet(mainWindowStyleSheet()) centralWidget = QWidget(self) self.setCentralWidget(centralWidget) centralWidget.setLayout(layout) self.setWindowTitle("Sharm v2") path = join("gui", "images", "icon.svg") self.setWindowIcon(QtGui.QIcon(path)) # self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint) self.setFocus()
class ChartWidget(QWidget): def __init__(self, parent, quotes, trades, data_range, currency_name): QWidget.__init__(self, parent) self.setMinimumWidth(600) self.setMinimumHeight(400) self.quotes_series = QLineSeries() for point in quotes: # Conversion to 'float' in order not to get 'int' overflow on some platforms self.quotes_series.append(float(point['timestamp']), point['quote']) self.trade_series = QScatterSeries() for point in trades: # Conversion to 'float' in order not to get 'int' overflow on some platforms self.trade_series.append(float(point['timestamp']), point['price']) self.trade_series.setMarkerSize(5) self.trade_series.setBorderColor(CustomColor.LightRed) self.trade_series.setBrush(CustomColor.DarkRed) axisX = QDateTimeAxis() axisX.setTickCount(11) axisX.setRange(QDateTime().fromSecsSinceEpoch(data_range[0]), QDateTime().fromSecsSinceEpoch(data_range[1])) axisX.setFormat("yyyy/MM/dd") axisX.setLabelsAngle(-90) axisX.setTitleText("Date") axisY = QValueAxis() axisY.setTickCount(11) axisY.setRange(data_range[2], data_range[3]) axisY.setTitleText("Price, " + currency_name) self.chartView = QChartView() self.chartView.chart().addSeries(self.quotes_series) self.chartView.chart().addSeries(self.trade_series) self.chartView.chart().addAxis(axisX, Qt.AlignBottom) self.chartView.chart().setAxisX(axisX, self.quotes_series) self.chartView.chart().setAxisX(axisX, self.trade_series) self.chartView.chart().addAxis(axisY, Qt.AlignLeft) self.chartView.chart().setAxisY(axisY, self.quotes_series) self.chartView.chart().setAxisY(axisY, self.trade_series) self.chartView.chart().legend().hide() self.chartView.setViewportMargins(0, 0, 0, 0) self.chartView.chart().layout().setContentsMargins( 0, 0, 0, 0) # To remove extra spacing around chart self.chartView.chart().setBackgroundRoundness( 0) # To remove corner rounding self.chartView.chart().setMargins(QMargins( 0, 0, 0, 0)) # Allow chart to fill all space self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) # Remove extra space around layout self.layout.addWidget(self.chartView) self.setLayout(self.layout)
def createBottomControls(self): widget = QWidget() layout = QHBoxLayout() layout.addWidget(self.createGeneralSection()) layout.addWidget(self.createFilterSection()) layout.setContentsMargins(0, 0, 0, 0) widget.setContentsMargins(0, 0, 0, 0) widget.setLayout(layout) return widget
def __init__(self, parent, data): super(SegmentsWidget, self).__init__(parent) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setVerticalSpacing(1) layout.setHorizontalSpacing(UIContext.getScaledWindowSize(16, 16).width()) self.segments = [] for segment in data.segments: if segment.readable or segment.writable or segment.executable: self.segments.append(segment) self.segments.sort(key = lambda segment: segment.start) row = 0 for segment in self.segments: begin = "0x%x" % segment.start end = "0x%x" % segment.end permissions = "" if segment.readable: permissions += "r" else: permissions += "-" if segment.writable: permissions += "w" else: permissions += "-" if segment.executable: permissions += "x" else: permissions += "-" rangeLayout = QHBoxLayout() rangeLayout.setContentsMargins(0, 0, 0, 0) beginLabel = headers.ClickableAddressLabel(begin) dashLabel = QLabel("-") dashLabel.setFont(binaryninjaui.getMonospaceFont(self)) endLabel = headers.ClickableAddressLabel(end) rangeLayout.addWidget(beginLabel) rangeLayout.addWidget(dashLabel) rangeLayout.addWidget(endLabel) layout.addLayout(rangeLayout, row, 0) permissionsLabel = QLabel(permissions) permissionsLabel.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(permissionsLabel, row, 1) row += 1 layout.setColumnStretch(2, 1) self.setLayout(layout)
def set_item_data(self, i, DisplayName, name, sid): check_box_layout = QHBoxLayout() check_box_layout.setAlignment(Qt.AlignmentFlag.AlignCenter) check_box = QCheckBox() check_box.setObjectName('check_box_' + str(i)) check_box_layout.addWidget(check_box) check_box_layout.setContentsMargins(0, 0, 0, 0) check_box_widget = QWidget() check_box_widget.setLayout(check_box_layout) self.tableWidget.item(i, 2).setText(DisplayName) self.tableWidget.item(i, 3).setText(name) self.tableWidget.item(i, 4).setText(sid) self.tableWidget.setCellWidget(i, 0, check_box_widget)
def test_pixmap_vertical(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters( 300, 240, 'scaled_label_pixmap_vertical') as (actual, expected): ex_widget = QWidget() ex_widget.resize(300, 240) expected.drawPixmap(0, 0, ex_widget.grab()) icon = GridDisplay.create_icon(GridDisplay.player2_colour) expected.drawPixmap( 0, 0, icon.scaled(150, 150, Qt.KeepAspectRatio, Qt.SmoothTransformation)) expected.drawPixmap( 150, 70, icon.scaled(100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)) expected.drawPixmap( 250, 190, icon.scaled(50, 50, Qt.KeepAspectRatio, Qt.SmoothTransformation)) widget = QWidget() layout = QHBoxLayout(widget) label1 = ScaledLabel() label2 = ScaledLabel() label3 = ScaledLabel() label1.setPixmap(icon) label2.setPixmap(icon) label3.setPixmap(icon) size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) label1.setSizePolicy(size_policy) label2.setSizePolicy(size_policy) label3.setSizePolicy(size_policy) label1.setScaledContents(True) label2.setScaledContents(True) label3.setScaledContents(True) label1.setAlignment(Qt.AlignTop) label2.setAlignment(Qt.AlignCenter) label3.setAlignment(Qt.AlignBottom) layout.addWidget(label1) layout.addWidget(label2) layout.addWidget(label3) layout.setStretch(0, 3) layout.setStretch(1, 2) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) widget.resize(300, 240) actual.drawPixmap(0, 0, widget.grab())
class Ui_IncomeSpendingReportWidget(object): def setupUi(self, IncomeSpendingReportWidget): if not IncomeSpendingReportWidget.objectName(): IncomeSpendingReportWidget.setObjectName( u"IncomeSpendingReportWidget") IncomeSpendingReportWidget.resize(595, 347) self.verticalLayout = QVBoxLayout(IncomeSpendingReportWidget) self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.ReportParamsFrame = QFrame(IncomeSpendingReportWidget) self.ReportParamsFrame.setObjectName(u"ReportParamsFrame") self.ReportParamsFrame.setFrameShape(QFrame.Panel) self.ReportParamsFrame.setFrameShadow(QFrame.Sunken) self.horizontalLayout = QHBoxLayout(self.ReportParamsFrame) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setObjectName(u"horizontalLayout") self.horizontalLayout.setContentsMargins(2, 2, 2, 2) self.ReportRange = DateRangeSelector(self.ReportParamsFrame) self.ReportRange.setObjectName(u"ReportRange") self.ReportRange.setProperty("ItemsList", u"QTD;YTD;this_year;last_year") self.horizontalLayout.addWidget(self.ReportRange) self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(self.horizontalSpacer) self.verticalLayout.addWidget(self.ReportParamsFrame) self.ReportTreeView = QTreeView(IncomeSpendingReportWidget) self.ReportTreeView.setObjectName(u"ReportTreeView") self.ReportTreeView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.ReportTreeView.setAlternatingRowColors(True) self.ReportTreeView.header().setStretchLastSection(False) self.verticalLayout.addWidget(self.ReportTreeView) self.retranslateUi(IncomeSpendingReportWidget) QMetaObject.connectSlotsByName(IncomeSpendingReportWidget) # setupUi def retranslateUi(self, IncomeSpendingReportWidget): IncomeSpendingReportWidget.setWindowTitle( QCoreApplication.translate("IncomeSpendingReportWidget", u"Income/Spending", None))
def __init__(self, parent=None): QWidget.__init__(self) self.setParent(parent) # Set the colour of the overlay self.setStyleSheet("QWidget { background-color: rgba(255, 255, 255, 0.05)}") # Set OverlayBottom heights # TODO: Change heights with increasing resolution self.setFixedHeight(100) # Create layout with margins/spacings layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # Initialise buttons buttons = [] args = ["home", "user", "windows", "back", "play-pause", "next"] for i in args: button = QToolButton() button.setIcon(QIcon("icons/{}.svg".format(i))) button.setAutoRaise(True) button.setStyleSheet("QToolButton:pressed { background-color: rgba(255, 255, 255, 0.1)}") buttons.append(button) # TODO: Solve this. Lambda functions cannot be used in loops. This is a stupid workaround buttons[0].clicked.connect(lambda: self.buttonAction(args[0])) buttons[1].clicked.connect(lambda: self.buttonAction(args[1])) buttons[2].clicked.connect(lambda: self.buttonAction(args[2])) buttons[3].clicked.connect(lambda: self.buttonAction(args[3])) buttons[4].clicked.connect(lambda: self.buttonAction(args[4])) buttons[5].clicked.connect(lambda: self.buttonAction(args[5])) # Add blank widget to start and end to group and center buttons (pt1) layout.addWidget(QWidget()) # Set IconSize, widths, and SizePolicy of each button. Then proceed to add to layout for x in buttons: x.setIconSize(QSize(35, 35)) # TODO: Scale with resize x.setFixedWidth(150) x.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) layout.addWidget(x) # Add blank widget to start and end to group and center buttons (pt2) layout.addWidget(QWidget()) self.setLayout(layout)
class KaitaiStatusBarWidget(StatusBarWidget): def __init__(self, parent): StatusBarWidget.__init__(self, parent) self.kaitaiView = parent self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0,0,0,0) self.options = KaitaiOptionsWidget(self) self.layout.addWidget(self.options) def updateStatus(self): #print 'updateStatus()' pass
class TopBar(QWidget): def __init__(self): QWidget.__init__(self) self.view_type = ViewTypeWidget() self.layout = QHBoxLayout() self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.view_type) self.about_button = AboutButton() self.layout.addWidget(self.about_button) self.close_button = CloseButton(config()['window']['frameless']) self.layout.addWidget(self.close_button) self.setLayout(self.layout)
def createTopControls(self): widget = QWidget() layout = QHBoxLayout() layout.addWidget(self.createSequencerControls()) layout.addStretch(1) layout.addWidget(self.createVcoSection()) layout.setContentsMargins(0, 0, 0, 0) layout.setStretch(0, 8) layout.setStretch(2, 8) widget.setContentsMargins(0, 0, 0, 0) widget.setLayout(layout) return widget
def __init__(self, w, parent=None): QWidget.__init__(self, parent) self._w = w self.setupUi() contentLayout = QHBoxLayout() contentLayout.setContentsMargins(0, 0, 0, 0) contentLayout.addWidget(w) self.windowContent.setLayout(contentLayout) self.setWindowTitle(w.windowTitle()) self.setGeometry(w.geometry()) # Adding attribute to clean up the parent window when the child is closed self._w.setAttribute(Qt.WA_DeleteOnClose, True) self._w.destroyed.connect(self.__child_was_closed)
class Window(QWidget): """The main application Window.""" def __init__(self): super().__init__() self.setWindowTitle("Example") self.layout = QHBoxLayout() self.layout.setContentsMargins(6, 6, 6, 6) self.loading_bar = QProgressBar() self.loading_bar.setTextVisible(False) self.loading_bar.setFixedHeight(25) self.layout.addWidget(self.loading_bar) self.quit_btn = FixedWindowsButton("Quit") self.quit_btn.setFixedHeight(25) self.quit_btn.clicked.connect(self.onQuitBtnClicked) self.layout.addWidget(self.quit_btn) self.run_btn = FixedWindowsButton("Run") self.run_btn.setFixedHeight(25) self.run_btn.clicked.connect(self.onRunBtnClicked) self.layout.addWidget(self.run_btn) self.setLayout(self.layout) def onRunBtnClicked(self): self.run_btn.setText("Loading...") self.run_btn.setEnabled(False) self.quit_btn.setEnabled(False) self.quit_btn.setHidden(True) self.calc = LongRunningProcess() self.calc.progress_changed.connect(self.onProgressChanged) self.calc.finished.connect(self.onProgressFinished) self.calc.start() def onQuitBtnClicked(self): self.close() def onProgressChanged(self, value): self.loading_bar.setValue(value) def onProgressFinished(self): self.quit_btn.setHidden(False) self.quit_btn.setEnabled(True) self.run_btn.setEnabled(True) self.run_btn.setText("Run") self.loading_bar.setValue(0)
class TextboxWidget(TritonWidget): def __init__(self, base, name): TritonWidget.__init__(self, base) self.name = name self.setBackgroundColor(self, Qt.white) self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.label = QLabel() self.label.setText(name) self.label.setFont(QFont('Helvetica', 10)) self.box = QLineEdit() self.box.setFixedWidth(250) self.box.setFont(QFont('Helvetica', 10)) self.layout.addWidget(self.label) self.layout.addWidget(self.box)
def createEditor(self, parent, option, index): editor = QFrame(parent) layout = QHBoxLayout(editor) text = QLineEdit(parent=editor) button = QPushButton(QIcon(":/icons/edit-white-48dp.svg"), "", parent=editor) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) editor.setLayout(layout) text.setFrame(False) text.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) layout.addWidget(text) layout.addWidget(button) button.clicked.connect(self.edit_dialog) return editor
def set_item_data(i, fun_name, fun_content): # 显示虚拟机名称、状态 self.tableWidget.item(i, 0).setText(fun_name) if fun_name in self.fun_explain: self.tableWidget.item(i, 1).setText(self.fun_explain[fun_name]) self.tableWidget.item(i, 2).setText(fun_content) # 显示修改框 if fun_name in self.fun_modifiable: lineedit = QLineEdit() lineedit.setObjectName("lineEdit_1_{}".format(i)) lineedit.setPlaceholderText("请输入修改值") lineedit.setStyleSheet("QLineEdit {border: none;}") self.lineedit_list.append(lineedit) # 存储lineedit lineedit_layout = QHBoxLayout() lineedit_layout.setAlignment(Qt.AlignmentFlag.AlignCenter) lineedit_layout.setContentsMargins(0, 0, 0, 0) lineedit_layout.addWidget(lineedit) lineedit_widget = QWidget() lineedit_widget.setLayout(lineedit_layout) self.tableWidget.setCellWidget(i, 3, lineedit_widget)
def __init__(self, parent=None) -> None: super().__init__() self.parent = parent # self.message_label = QLabel(self) self.sep1 = QLabel("|", self) self.curr_pos_label = QLabel(self) self.sep2 = QLabel("|", self) self.file_name_label = QLabel(self) self.sep3 = QLabel("|", self) self.resolution_label = QLabel(self) self.sep4 = QLabel("|", self) # self.memory_label = QLabel(self) # self.sep5 = QLabel("|", self) self.mode_label = QLabel(self) self.sep5 = QLabel("|", self) self.progressbar = QProgressBar(self) self.progressbar.setMaximumWidth(150) self.progressbar.setMaximumHeight(15) self.progressbar.hide() # layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.layout().addWidget(self.message_label) self.layout().addWidget(self.sep1) self.layout().addWidget(self.curr_pos_label) self.layout().addWidget(self.sep2) self.layout().addWidget(self.resolution_label) self.layout().addWidget(self.sep3) self.layout().addWidget(self.file_name_label) self.layout().addWidget(self.sep4) # self.layout().addWidget(self.memory_label) # self.layout().addWidget(self.sep5) self.layout().addWidget(self.mode_label) self.layout().addWidget(self.sep5) self.layout().addWidget(self.progressbar) # self.message_timer = None
def __init__(self, parent, name, data): if not type(data) == binaryninja.binaryview.BinaryView: raise Exception('expected widget data to be a BinaryView') self.bv = data QWidget.__init__(self, parent) DockContextHandler.__init__(self, self, name) self.actionHandler = UIActionHandler() self.actionHandler.setupActionHandler(self) layout = QVBoxLayout() self.consoleText = QTextEdit(self) self.consoleText.setReadOnly(True) self.consoleText.setFont(getMonospaceFont(self)) layout.addWidget(self.consoleText, 1) inputLayout = QHBoxLayout() inputLayout.setContentsMargins(4, 4, 4, 4) promptLayout = QVBoxLayout() promptLayout.setContentsMargins(0, 5, 0, 5) inputLayout.addLayout(promptLayout) self.consoleEntry = QLineEdit(self) inputLayout.addWidget(self.consoleEntry, 1) self.entryLabel = QLabel("dbg>>> ", self) self.entryLabel.setFont(getMonospaceFont(self)) promptLayout.addWidget(self.entryLabel) promptLayout.addStretch(1) self.consoleEntry.returnPressed.connect(lambda: self.sendLine()) layout.addLayout(inputLayout) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout)
class ModernWindow(QWidget): """ Modern window. Args: w (QWidget): Main widget. parent (QWidget, optional): Parent widget. """ def __init__(self, w, parent=None): QWidget.__init__(self, parent) self._w = w self.setupUi() contentLayout = QHBoxLayout() contentLayout.setContentsMargins(0, 0, 0, 0) contentLayout.addWidget(w) self.windowContent.setLayout(contentLayout) self.setWindowTitle(w.windowTitle()) self.setGeometry(w.geometry()) # Adding attribute to clean up the parent window when the child is closed self._w.setAttribute(Qt.WA_DeleteOnClose, True) self._w.destroyed.connect(self.__child_was_closed) def setupUi(self): # create title bar, content self.vboxWindow = QVBoxLayout(self) self.vboxWindow.setContentsMargins(0, 0, 0, 0) self.windowFrame = QWidget(self) self.windowFrame.setObjectName('windowFrame') self.vboxFrame = QVBoxLayout(self.windowFrame) self.vboxFrame.setContentsMargins(0, 0, 0, 0) self.titleBar = WindowDragger(self, self.windowFrame) self.titleBar.setObjectName('titleBar') self.titleBar.setSizePolicy( QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)) self.hboxTitle = QHBoxLayout(self.titleBar) self.hboxTitle.setContentsMargins(0, 0, 0, 0) self.hboxTitle.setSpacing(0) self.lblTitle = QLabel('Title') self.lblTitle.setObjectName('lblTitle') self.lblTitle.setAlignment(Qt.AlignCenter) spButtons = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.btnMinimize = QToolButton(self.titleBar) self.btnMinimize.setObjectName('btnMinimize') self.btnMinimize.setSizePolicy(spButtons) self.btnRestore = QToolButton(self.titleBar) self.btnRestore.setObjectName('btnRestore') self.btnRestore.setSizePolicy(spButtons) self.btnMaximize = QToolButton(self.titleBar) self.btnMaximize.setObjectName('btnMaximize') self.btnMaximize.setSizePolicy(spButtons) self.btnClose = QToolButton(self.titleBar) self.btnClose.setObjectName('btnClose') self.btnClose.setSizePolicy(spButtons) self.vboxFrame.addWidget(self.titleBar) self.windowContent = QWidget(self.windowFrame) self.vboxFrame.addWidget(self.windowContent) self.vboxWindow.addWidget(self.windowFrame) if PLATFORM == "Darwin": self.hboxTitle.addWidget(self.btnClose) self.hboxTitle.addWidget(self.btnMinimize) self.hboxTitle.addWidget(self.btnRestore) self.hboxTitle.addWidget(self.btnMaximize) self.hboxTitle.addWidget(self.lblTitle) else: self.hboxTitle.addWidget(self.lblTitle) self.hboxTitle.addWidget(self.btnMinimize) self.hboxTitle.addWidget(self.btnRestore) self.hboxTitle.addWidget(self.btnMaximize) self.hboxTitle.addWidget(self.btnClose) # set window flags self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint) if QT_VERSION >= (5, ): self.setAttribute(Qt.WA_TranslucentBackground) # set stylesheet with open(_FL_STYLESHEET) as stylesheet: self.setStyleSheet(stylesheet.read()) # automatically connect slots QMetaObject.connectSlotsByName(self) def __child_was_closed(self): self._w = None # The child was deleted, remove the reference to it and close the parent window self.close() def closeEvent(self, event): if not self._w: event.accept() else: self._w.close() event.setAccepted(self._w.isHidden()) def setWindowTitle(self, title): """ Set window title. Args: title (str): Title. """ super(ModernWindow, self).setWindowTitle(title) self.lblTitle.setText(title) def _setWindowButtonState(self, hint, state): btns = { Qt.WindowCloseButtonHint: self.btnClose, Qt.WindowMinimizeButtonHint: self.btnMinimize, Qt.WindowMaximizeButtonHint: self.btnMaximize } button = btns.get(hint) maximized = bool(self.windowState() & Qt.WindowMaximized) if button == self.btnMaximize: # special rules for max/restore self.btnRestore.setEnabled(state) self.btnMaximize.setEnabled(state) if maximized: self.btnRestore.setVisible(state) self.btnMaximize.setVisible(False) else: self.btnMaximize.setVisible(state) self.btnRestore.setVisible(False) else: button.setEnabled(state) allButtons = [ self.btnClose, self.btnMinimize, self.btnMaximize, self.btnRestore ] if True in [b.isEnabled() for b in allButtons]: for b in allButtons: b.setVisible(True) if maximized: self.btnMaximize.setVisible(False) else: self.btnRestore.setVisible(False) self.lblTitle.setContentsMargins(0, 0, 0, 0) else: for b in allButtons: b.setVisible(False) self.lblTitle.setContentsMargins(0, 2, 0, 0) def setWindowFlag(self, Qt_WindowType, on=True): buttonHints = [ Qt.WindowCloseButtonHint, Qt.WindowMinimizeButtonHint, Qt.WindowMaximizeButtonHint ] if Qt_WindowType in buttonHints: self._setWindowButtonState(Qt_WindowType, on) else: QWidget.setWindowFlag(self, Qt_WindowType, on) def setWindowFlags(self, Qt_WindowFlags): buttonHints = [ Qt.WindowCloseButtonHint, Qt.WindowMinimizeButtonHint, Qt.WindowMaximizeButtonHint ] for hint in buttonHints: self._setWindowButtonState(hint, bool(Qt_WindowFlags & hint)) QWidget.setWindowFlags(self, Qt_WindowFlags) @Slot() def on_btnMinimize_clicked(self): self.setWindowState(Qt.WindowMinimized) @Slot() def on_btnRestore_clicked(self): if self.btnMaximize.isEnabled() or self.btnRestore.isEnabled(): self.btnRestore.setVisible(False) self.btnRestore.setEnabled(False) self.btnMaximize.setVisible(True) self.btnMaximize.setEnabled(True) self.setWindowState(Qt.WindowNoState) @Slot() def on_btnMaximize_clicked(self): if self.btnMaximize.isEnabled() or self.btnRestore.isEnabled(): self.btnRestore.setVisible(True) self.btnRestore.setEnabled(True) self.btnMaximize.setVisible(False) self.btnMaximize.setEnabled(False) self.setWindowState(Qt.WindowMaximized) @Slot() def on_btnClose_clicked(self): self.close() @Slot() def on_titleBar_doubleClicked(self): if not bool(self.windowState() & Qt.WindowMaximized): self.on_btnMaximize_clicked() else: self.on_btnRestore_clicked()
class ChartWindow(MdiWidget): def __init__(self, account_id, asset_id, currency_id, _asset_qty, parent=None): super().__init__(parent) self.account_id = account_id self.asset_id = asset_id self.currency_id = currency_id if asset_id != currency_id else 1 # Check whether we have currency or asset self.asset_name = JalDB().get_asset_name(self.asset_id) self.quotes = [] self.trades = [] self.currency_name = '' self.range = [0, 0, 0, 0] self.prepare_chart_data() self.chart = ChartWidget(self, self.quotes, self.trades, self.range, self.currency_name) self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) # Remove extra space around layout self.layout.addWidget(self.chart) self.setLayout(self.layout) self.setWindowTitle(self.tr("Price chart for ") + self.asset_name) self.ready = True def prepare_chart_data(self): self.currency_name = JalDB().get_asset_name( JalDB().get_account_currency(self.account_id)) start_time = readSQL( "SELECT MAX(ts) FROM " # Take either last "empty" timestamp "(SELECT coalesce(MAX(timestamp), 0) AS ts " "FROM ledger WHERE account_id=:account_id AND asset_id=:asset_id " "AND book_account=:assets_book AND amount_acc==0 " "UNION " # or first timestamp where position started to appear "SELECT coalesce(MIN(timestamp), 0) AS ts " "FROM ledger WHERE account_id=:account_id AND asset_id=:asset_id " "AND book_account=:assets_book AND amount_acc!=0)", [(":account_id", self.account_id), (":asset_id", self.asset_id), (":assets_book", BookAccount.Assets)]) # Get asset quotes query = executeSQL( "SELECT timestamp, quote FROM quotes " "WHERE asset_id=:asset_id AND currency_id=:currency_id AND timestamp>:last", [(":asset_id", self.asset_id), (":currency_id", self.currency_id), (":last", start_time)]) while query.next(): quote = readSQLrecord(query, named=True) self.quotes.append({ 'timestamp': quote['timestamp'] * 1000, 'quote': quote['quote'] }) # timestamp to ms # Get deals prices query = executeSQL( "SELECT timestamp, price, qty FROM trades " "WHERE account_id=:account_id AND asset_id=:asset_id AND timestamp>=:last", [(":account_id", self.account_id), (":asset_id", self.asset_id), (":last", start_time)]) while query.next(): trade = readSQLrecord(query, named=True) self.trades.append({ 'timestamp': trade['timestamp'] * 1000, 'price': trade['price'], 'qty': trade['qty'] }) if self.quotes or self.trades: min_price = min([x['quote'] for x in self.quotes] + [x['price'] for x in self.trades]) max_price = max([x['quote'] for x in self.quotes] + [x['price'] for x in self.trades]) min_ts = min([x['timestamp'] for x in self.quotes] + [x['timestamp'] for x in self.trades]) / 1000 max_ts = max([x['timestamp'] for x in self.quotes] + [x['timestamp'] for x in self.trades]) / 1000 else: self.range = [0, 0, 0, 0] return # push range apart if we have too close points if min_price == max_price: min_price = 0.95 * min_price max_price = 1.05 * max_price if min_ts == max_ts: min_ts = 0.95 * min_ts max_ts = 1.05 * max_ts # Round min/max values to near "round" values in order to have 10 nice intervals step = 10**floor(log10(max_price - min_price)) min_price = floor(min_price / step) * step max_price = ceil(max_price / step) * step # Add a gap at the beginning and end min_ts = int(min_ts - 86400 * 3) max_ts = int(max_ts + 86400 * 3) self.range = [min_ts, max_ts, min_price, max_price]
class ChartWindow(QDialog): def __init__(self, account_id, asset_id, _asset_qty, position, parent=None): super().__init__(parent) self.account_id = account_id self.asset_id = asset_id self.asset_name = JalDB().get_asset_name(self.asset_id) self.quotes = [] self.trades = [] self.currency_name = '' self.range = [0, 0, 0, 0] self.prepare_chart_data() self.chart = ChartWidget(self, self.quotes, self.trades, self.range, self.currency_name) self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) # Remove extra space around layout self.layout.addWidget(self.chart) self.setLayout(self.layout) self.setWindowTitle(self.tr("Price chart for ") + self.asset_name) self.setWindowFlag(Qt.Tool) self.setGeometry(position.x(), position.y(), self.width(), self.height()) self.ready = True def prepare_chart_data(self): min_price = max_price = 0 min_ts = max_ts = 0 self.currency_name = JalDB().get_asset_name(JalDB().get_account_currency(self.account_id)) start_time = readSQL("SELECT MAX(ts) FROM " # Take either last "empty" timestamp "(SELECT coalesce(MAX(timestamp), 0) AS ts " "FROM ledger_sums WHERE account_id=:account_id AND asset_id=:asset_id " "AND book_account=:assets_book AND sum_amount==0 " "UNION " # or first timestamp where position started to appear "SELECT coalesce(MIN(timestamp), 0) AS ts " "FROM ledger_sums WHERE account_id=:account_id AND asset_id=:asset_id " "AND book_account=:assets_book AND sum_amount!=0)", [(":account_id", self.account_id), (":asset_id", self.asset_id), (":assets_book", BookAccount.Assets)]) # Get quotes quotes query = executeSQL("SELECT timestamp, quote FROM quotes WHERE asset_id=:asset_id AND timestamp>:last", [(":asset_id", self.asset_id), (":last", start_time)]) while query.next(): quote = readSQLrecord(query, named=True) self.quotes.append({'timestamp': quote['timestamp'] * 1000, 'quote': quote['quote']}) # timestamp to ms min_price = quote['quote'] if min_price == 0 or quote['quote'] < min_price else min_price max_price = quote['quote'] if quote['quote'] > max_price else max_price min_ts = quote['timestamp'] if min_ts == 0 or quote['timestamp'] < min_ts else min_ts max_ts = quote['timestamp'] if quote['timestamp'] > max_ts else max_ts # Get deals quotes query = executeSQL("SELECT timestamp, price, qty FROM trades " "WHERE account_id=:account_id AND asset_id=:asset_id AND timestamp>=:last", [(":account_id", self.account_id), (":asset_id", self.asset_id), (":last", start_time)]) while query.next(): trade = readSQLrecord(query, named=True) self.trades.append({'timestamp': trade['timestamp'] * 1000, 'price': trade['price'], 'qty': trade['qty']}) min_price = trade['price'] if min_price == 0 or trade['price'] < min_price else min_price max_price = trade['price'] if trade['price'] > max_price else max_price min_ts = trade['timestamp'] if min_ts == 0 or trade['timestamp'] < min_ts else min_ts max_ts = trade['timestamp'] if trade['timestamp'] > max_ts else max_ts # Round min/max values to near "round" values in order to have 10 nice intervals step = 10 ** floor(log10(max_price - min_price)) min_price = floor(min_price / step) * step max_price = ceil(max_price / step) * step # Add a gap at the beginning and end min_ts -= 86400 * 3 max_ts += 86400 * 3 self.range = [min_ts, max_ts, min_price, max_price]
def __init__(self, parent, data): assert type(data) == BinaryView self.bv = data QDialog.__init__(self, parent) debug_state = binjaplug.get_state(self.bv) self.setWindowTitle("Debug Adapter Settings") self.setMinimumSize(UIContext.getScaledWindowSize(400, 130)) self.setAttribute(Qt.WA_DeleteOnClose) layout = QVBoxLayout() layout.setSpacing(0) titleLabel = QLabel("Adapter Settings") titleLayout = QHBoxLayout() titleLayout.setContentsMargins(0, 0, 0, 0) titleLayout.addWidget(titleLabel) self.adapterEntry = QPushButton(self) self.adapterMenu = QMenu(self) for adapter in DebugAdapter.ADAPTER_TYPE: if not DebugAdapter.ADAPTER_TYPE.can_use(adapter): continue def select_adapter(adapter): return lambda: self.selectAdapter(adapter) self.adapterMenu.addAction(adapter.name, select_adapter(adapter)) if adapter == debug_state.adapter_type: self.adapterEntry.setText(adapter.name) self.adapterEntry.setMenu(self.adapterMenu) self.argumentsEntry = QLineEdit(self) self.addressEntry = QLineEdit(self) self.portEntry = QLineEdit(self) self.requestTerminalEmulator = QCheckBox(self) self.formLayout = QFormLayout() self.formLayout.addRow("Adapter Type", self.adapterEntry) self.formLayout.addRow("Command Line Arguments", self.argumentsEntry) self.formLayout.addRow("Address", self.addressEntry) self.formLayout.addRow("Port", self.portEntry) self.formLayout.addRow("Request Terminal Emulator", self.requestTerminalEmulator) buttonLayout = QHBoxLayout() buttonLayout.setContentsMargins(0, 0, 0, 0) self.cancelButton = QPushButton("Cancel") self.cancelButton.clicked.connect(lambda: self.reject()) self.acceptButton = QPushButton("Accept") self.acceptButton.clicked.connect(lambda: self.accept()) self.acceptButton.setDefault(True) buttonLayout.addStretch(1) buttonLayout.addWidget(self.cancelButton) buttonLayout.addWidget(self.acceptButton) layout.addLayout(titleLayout) layout.addSpacing(10) layout.addLayout(self.formLayout) layout.addStretch(1) layout.addSpacing(10) layout.addLayout(buttonLayout) self.setLayout(layout) self.addressEntry.setText(debug_state.remote_host) self.portEntry.setText(str(debug_state.remote_port)) self.addressEntry.textEdited.connect(lambda: self.apply()) self.portEntry.textEdited.connect(lambda: self.apply()) self.argumentsEntry.setText(' '.join( shlex.quote(arg) for arg in debug_state.command_line_args)) self.argumentsEntry.textEdited.connect(lambda: self.updateArguments()) self.requestTerminalEmulator.setChecked( debug_state.request_terminal_emulator) self.requestTerminalEmulator.stateChanged.connect(lambda: self.apply()) self.accepted.connect(lambda: self.apply())
class Ui_DealsReportWidget(object): def setupUi(self, DealsReportWidget): if not DealsReportWidget.objectName(): DealsReportWidget.setObjectName(u"DealsReportWidget") DealsReportWidget.resize(821, 280) self.verticalLayout = QVBoxLayout(DealsReportWidget) self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.ReportParamsFrame = QFrame(DealsReportWidget) self.ReportParamsFrame.setObjectName(u"ReportParamsFrame") self.ReportParamsFrame.setFrameShape(QFrame.Panel) self.ReportParamsFrame.setFrameShadow(QFrame.Sunken) self.horizontalLayout = QHBoxLayout(self.ReportParamsFrame) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setObjectName(u"horizontalLayout") self.horizontalLayout.setContentsMargins(2, 2, 2, 2) self.ReportRange = DateRangeSelector(self.ReportParamsFrame) self.ReportRange.setObjectName(u"ReportRange") self.ReportRange.setProperty("ItemsList", u"QTD;YTD;this_year;last_year") self.horizontalLayout.addWidget(self.ReportRange) self.ReportGroupCheck = QCheckBox(self.ReportParamsFrame) self.ReportGroupCheck.setObjectName(u"ReportGroupCheck") self.horizontalLayout.addWidget(self.ReportGroupCheck) self.ReportAccountLbl = QLabel(self.ReportParamsFrame) self.ReportAccountLbl.setObjectName(u"ReportAccountLbl") self.horizontalLayout.addWidget(self.ReportAccountLbl) self.ReportAccountBtn = AccountButton(self.ReportParamsFrame) self.ReportAccountBtn.setObjectName(u"ReportAccountBtn") self.horizontalLayout.addWidget(self.ReportAccountBtn) self.ReportFrameSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(self.ReportFrameSpacer) self.verticalLayout.addWidget(self.ReportParamsFrame) self.ReportTableView = QTableView(DealsReportWidget) self.ReportTableView.setObjectName(u"ReportTableView") self.ReportTableView.setFrameShape(QFrame.Panel) self.ReportTableView.setFrameShadow(QFrame.Sunken) self.ReportTableView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.ReportTableView.setAlternatingRowColors(True) self.ReportTableView.setGridStyle(Qt.DotLine) self.ReportTableView.setWordWrap(False) self.ReportTableView.verticalHeader().setVisible(False) self.ReportTableView.verticalHeader().setMinimumSectionSize(20) self.ReportTableView.verticalHeader().setDefaultSectionSize(20) self.verticalLayout.addWidget(self.ReportTableView) self.retranslateUi(DealsReportWidget) QMetaObject.connectSlotsByName(DealsReportWidget) # setupUi def retranslateUi(self, DealsReportWidget): DealsReportWidget.setWindowTitle( QCoreApplication.translate("DealsReportWidget", u"Deals", None)) self.ReportGroupCheck.setText( QCoreApplication.translate("DealsReportWidget", u"Group dates", None)) self.ReportAccountLbl.setText( QCoreApplication.translate("DealsReportWidget", u"Account:", None))
class Ui_TaxEstimationDialog(object): def setupUi(self, TaxEstimationDialog): if not TaxEstimationDialog.objectName(): TaxEstimationDialog.setObjectName(u"TaxEstimationDialog") TaxEstimationDialog.resize(754, 191) self.verticalLayout = QVBoxLayout(TaxEstimationDialog) self.verticalLayout.setSpacing(2) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSpacing(2) self.horizontalLayout.setObjectName(u"horizontalLayout") self.RateFrame = QFrame(TaxEstimationDialog) self.RateFrame.setObjectName(u"RateFrame") self.RateFrame.setFrameShape(QFrame.StyledPanel) self.RateFrame.setFrameShadow(QFrame.Raised) self.horizontalLayout_2 = QHBoxLayout(self.RateFrame) self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) self.LastQuoteLbl = QLabel(self.RateFrame) self.LastQuoteLbl.setObjectName(u"LastQuoteLbl") font = QFont() font.setBold(True) self.LastQuoteLbl.setFont(font) self.horizontalLayout_2.addWidget(self.LastQuoteLbl) self.QuoteLbl = QLabel(self.RateFrame) self.QuoteLbl.setObjectName(u"QuoteLbl") self.horizontalLayout_2.addWidget(self.QuoteLbl) self.RateSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_2.addItem(self.RateSpacer) self.horizontalLayout.addWidget(self.RateFrame) self.QuoteFrame = QFrame(TaxEstimationDialog) self.QuoteFrame.setObjectName(u"QuoteFrame") self.QuoteFrame.setFrameShape(QFrame.StyledPanel) self.QuoteFrame.setFrameShadow(QFrame.Raised) self.horizontalLayout_3 = QHBoxLayout(self.QuoteFrame) self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0) self.CurrentRateLbl = QLabel(self.QuoteFrame) self.CurrentRateLbl.setObjectName(u"CurrentRateLbl") self.CurrentRateLbl.setFont(font) self.horizontalLayout_3.addWidget(self.CurrentRateLbl) self.RateLbl = QLabel(self.QuoteFrame) self.RateLbl.setObjectName(u"RateLbl") self.horizontalLayout_3.addWidget(self.RateLbl) self.QuoteSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_3.addItem(self.QuoteSpacer) self.horizontalLayout.addWidget(self.QuoteFrame) self.verticalLayout.addLayout(self.horizontalLayout) self.DealsView = QTableView(TaxEstimationDialog) self.DealsView.setObjectName(u"DealsView") self.DealsView.setSelectionBehavior(QAbstractItemView.SelectRows) self.DealsView.verticalHeader().setVisible(False) self.DealsView.verticalHeader().setMinimumSectionSize(20) self.DealsView.verticalHeader().setDefaultSectionSize(20) self.verticalLayout.addWidget(self.DealsView) self.retranslateUi(TaxEstimationDialog) QMetaObject.connectSlotsByName(TaxEstimationDialog) # setupUi def retranslateUi(self, TaxEstimationDialog): TaxEstimationDialog.setWindowTitle(QCoreApplication.translate("TaxEstimationDialog", u"Tax Estimation", None)) self.LastQuoteLbl.setText(QCoreApplication.translate("TaxEstimationDialog", u"Last quote:", None)) self.QuoteLbl.setText(QCoreApplication.translate("TaxEstimationDialog", u"X.XX", None)) self.CurrentRateLbl.setText(QCoreApplication.translate("TaxEstimationDialog", u"Current rate:", None)) self.RateLbl.setText(QCoreApplication.translate("TaxEstimationDialog", u"X.XX", None))
class Ui_MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowIcon(QIcon(resource_path('icon.ico'))) self.setFixedSize(540, 470) def setupUi(self): self.centralwidget = QWidget(self) with open(resource_path('style.css'), 'r') as file: self.centralwidget.setStyleSheet(file.read()) self.appswidget = QWidget(self.centralwidget) self.appswidget.setGeometry(50, 0, 490, 470) self.appswidget.setProperty('class', 'appswidget') self.sidebar = QFrame(self.centralwidget) self.sidebar.setFrameShape(QFrame.StyledPanel) self.sidebar.setGeometry(0, 0, 50, 470) self.sidebar.setProperty('class', 'sidebar') self.refresh_btn = QPushButton(self.sidebar) self.refresh_btn.setGeometry(QRect(0, 0, 51, 51)) self.refresh_btn.setProperty('class', 'sidebar_btns') self.refresh_btn.setIcon(QIcon(':/icon/refresh_icon.png')) self.refresh_btn.setIconSize(QSize(24, 24)) self.refresh_bind = QShortcut(QKeySequence('Ctrl+R'), self) self.store_btn = QPushButton(self.sidebar) self.store_btn.setGeometry(QRect(0, 51, 51, 51)) self.store_btn.setProperty('class', 'sidebar_btns') self.store_btn.setIcon(QIcon(':/icon/store_icon.png')) self.store_btn.setIconSize(QSize(24, 24)) self.store_bind = QShortcut(QKeySequence('Ctrl+S'), self) self.homepage_btn = QPushButton(self.sidebar) self.homepage_btn.setGeometry(QRect(0, 102, 51, 51)) self.homepage_btn.setProperty('class', 'sidebar_btns') self.homepage_btn.setIcon(QIcon(':/icon/github_icon.png')) self.homepage_btn.setIconSize(QSize(24, 24)) self.homepage_bind = QShortcut(QKeySequence('Ctrl+G'), self) self.about_btn = QPushButton(self.sidebar) self.about_btn.setGeometry(QRect(0, 153, 51, 51)) self.about_btn.setProperty('class', 'sidebar_btns') self.about_btn.setIcon(QIcon(':/icon/about_icon.png')) self.about_btn.setIconSize(QSize(24, 24)) self.about_bind = QShortcut(QKeySequence('Ctrl+A'), self) self.quit_btn = QPushButton(self.sidebar) self.quit_btn.setGeometry(QRect(0, 420, 51, 51)) self.quit_btn.setProperty('class', 'sidebar_btns_quit') self.quit_btn.setIcon(QIcon(':/icon/quit_icon.png')) self.quit_btn.setIconSize(QSize(24, 24)) self.quit_bind = QShortcut(QKeySequence('Ctrl+Q'), self) self.font = QFont() self.font.setPointSize(8) self.font.setStyleStrategy(QFont.PreferAntialias) self.label_refresh = QLabel(self.appswidget) self.label_refresh.setFont(self.font) self.label_refresh.setGeometry(QRect(20, 10, 441, 15)) self.label_info = QLabel(self.appswidget) self.label_info.setFont(self.font) self.label_info.setGeometry(QRect(20, 10, 441, 30)) self.progressbar = QProgressBar(self.appswidget) self.progressbar.setGeometry(QRect(20, 30, 441, 20)) self.layout_widget_checkboxes = QWidget(self.appswidget) self.layout_widget_checkboxes.setGeometry(QRect(20, 55, 155, 311)) self.layout_checkboxes = QVBoxLayout(self.layout_widget_checkboxes) self.layout_checkboxes.setContentsMargins(0, 0, 0, 0) self.layout_widget_checkboxes_2 = QWidget(self.appswidget) self.layout_widget_checkboxes_2.setGeometry(QRect(175, 55, 155, 311)) self.layout_checkboxes_2 = QVBoxLayout(self.layout_widget_checkboxes_2) self.layout_checkboxes_2.setContentsMargins(0, 0, 0, 0) self.layout_widget_checkboxes_3 = QWidget(self.appswidget) self.layout_widget_checkboxes_3.setGeometry(QRect(330, 55, 155, 311)) self.layout_checkboxes_3 = QVBoxLayout(self.layout_widget_checkboxes_3) self.layout_checkboxes_3.setContentsMargins(0, 0, 0, 0) self.layout_widget_labels = QWidget(self.appswidget) self.layout_widget_labels.setGeometry(QRect(20, 390, 350, 16)) self.layout_labels = QHBoxLayout(self.layout_widget_labels) self.layout_labels.setContentsMargins(0, 0, 0, 0) self.label_space = QLabel(self.appswidget) self.label_space.setFont(self.font) self.layout_labels.addWidget(self.label_space) self.label_size = QLabel(self.appswidget) self.label_size.setFont(self.font) self.layout_labels.addWidget(self.label_size) self.layout_widget_buttons = QWidget(self.appswidget) self.layout_widget_buttons.setGeometry(QRect(20, 420, 454, 31)) self.layout_buttons = QHBoxLayout(self.layout_widget_buttons) self.layout_buttons.setContentsMargins(0, 0, 0, 0) self.button_select_all = QPushButton(self.layout_widget_buttons) self.button_select_all.setIcon(QIcon(':/icon/check_icon.png')) self.button_select_all.setIconSize(QSize(18, 18)) self.button_select_all.setLayoutDirection(Qt.RightToLeft) self.layout_buttons.addWidget(self.button_select_all) self.button_select_all.setMinimumSize(100, 30) self.button_select_all.setProperty('class', 'Aqua') self.button_deselect_all = QPushButton(self.layout_widget_buttons) self.button_deselect_all.setIcon(QIcon(':/icon/cancel_icon.png')) self.button_deselect_all.setIconSize(QSize(18, 18)) self.button_deselect_all.setLayoutDirection(Qt.RightToLeft) self.layout_buttons.addWidget(self.button_deselect_all) self.button_deselect_all.setMinimumSize(100, 30) self.button_deselect_all.setProperty('class', 'Aqua') self.layout_buttons.addStretch() self.button_uninstall = QPushButton(self.layout_widget_buttons) self.button_uninstall.setIcon(QIcon(':/icon/trash_icon.png')) self.button_uninstall.setIconSize(QSize(18, 18)) self.button_uninstall.setLayoutDirection(Qt.RightToLeft) self.layout_buttons.addWidget(self.button_uninstall) self.button_uninstall.setMinimumSize(100, 30) self.button_uninstall.setProperty('class', 'Grapefruit') self.setCentralWidget(self.centralwidget) self.retranslateUi() QMetaObject.connectSlotsByName(self) def retranslateUi(self): QToolTip.setFont(self.font) self.setWindowTitle(QCoreApplication.translate("Title", "PyDebloatX")) self.label_info.setText(QCoreApplication.translate("Label", "")) self.app_name_list = list( ( # Convert tuple to list, because lupdate ignores initial lists QCoreApplication.translate("AppName", "3D Builder"), QCoreApplication.translate("AppName", "3D Viewer"), QCoreApplication.translate("AppName", "Alarms and Clock"), QCoreApplication.translate("AppName", "Calculator"), QCoreApplication.translate("AppName", "Calendar and Mail"), QCoreApplication.translate("AppName", "Camera"), QCoreApplication.translate("AppName", "Feedback Hub"), QCoreApplication.translate("AppName", "Get Help"), QCoreApplication.translate("AppName", "Groove Music"), QCoreApplication.translate("AppName", "Maps"), QCoreApplication.translate("AppName", "Messaging"), QCoreApplication.translate("AppName", "Mixed Reality Portal"), QCoreApplication.translate("AppName", "Mobile Plans"), QCoreApplication.translate("AppName", "Money"), QCoreApplication.translate("AppName", "Movies && TV"), QCoreApplication.translate("AppName", "News"), QCoreApplication.translate("AppName", "Office"), QCoreApplication.translate("AppName", "OneNote"), QCoreApplication.translate("AppName", "Paint 3D"), QCoreApplication.translate("AppName", "People"), QCoreApplication.translate("AppName", "Photos"), QCoreApplication.translate("AppName", "Print 3D"), QCoreApplication.translate("AppName", "Skype"), QCoreApplication.translate("AppName", "Snip && Sketch"), QCoreApplication.translate("AppName", "Solitaire"), QCoreApplication.translate("AppName", "Sports"), QCoreApplication.translate("AppName", "Spotify"), QCoreApplication.translate("AppName", "Sticky Notes"), QCoreApplication.translate("AppName", "Tips"), QCoreApplication.translate("AppName", "Translator"), QCoreApplication.translate("AppName", "Voice Recorder"), QCoreApplication.translate("AppName", "Weather"), QCoreApplication.translate("AppName", "Xbox"), QCoreApplication.translate("AppName", "Xbox Game Bar"), QCoreApplication.translate("AppName", "Your Phone"))) self.tooltip_list = list(( QCoreApplication.translate( "ToolTip", "View, create, and personalize 3D objects."), QCoreApplication.translate( "ToolTip", "View 3D models and animations in real-time."), QCoreApplication.translate( "ToolTip", "A combination of alarm clock, world clock, timer, and stopwatch." ), QCoreApplication.translate( "ToolTip", "A calculator that includes standard, scientific, and programmer modes, as well as a unit converter." ), QCoreApplication.translate( "ToolTip", "Stay up to date with email and schedule managing."), QCoreApplication.translate( "ToolTip", "Point and shoot to take pictures on Windows 10."), QCoreApplication.translate( "ToolTip", "Provide feedback about Windows and apps by sharing suggestions or problems." ), QCoreApplication.translate( "ToolTip", "Provide a way to ask a question and get recommended solutions or contact assisted support." ), QCoreApplication.translate( "ToolTip", "Listen to music on Windows, iOS, and Android devices."), QCoreApplication.translate( "ToolTip", "Search for places to get directions, business info, and reviews." ), QCoreApplication.translate( "ToolTip", "Quick, reliable SMS, MMS and RCS messaging from your phone."), QCoreApplication.translate( "ToolTip", "Discover Windows Mixed Reality and dive into more than 3,000 games and VR experiences from Steam VR and Microsoft Store." ), QCoreApplication.translate( "ToolTip", "Sign up for a data plan and connect with mobile operators in your area. You will need a supported SIM card." ), QCoreApplication.translate( "ToolTip", "Finance calculators, currency exchange rates and commodity prices from around the world." ), QCoreApplication.translate( "ToolTip", "All your movies and TV shows, all in one place, on all your devices." ), QCoreApplication.translate( "ToolTip", "Deliver breaking news and trusted, in-depth reporting from the world\'s best journalists." ), QCoreApplication.translate( "ToolTip", "Find all your Office apps and files in one place."), QCoreApplication.translate( "ToolTip", "Digital notebook for capturing and organizing everything across your devices." ), QCoreApplication.translate( "ToolTip", "Make 2D masterpieces or 3D models that you can play with from all angles." ), QCoreApplication.translate( "ToolTip", "Connect with all your friends, family, colleagues, and acquaintances in one place." ), QCoreApplication.translate( "ToolTip", "View and edit your photos and videos, make movies, and create albums." ), QCoreApplication.translate( "ToolTip", "Quickly and easily prepare objects for 3D printing on your PC." ), QCoreApplication.translate( "ToolTip", "Instant message, voice or video call application."), QCoreApplication.translate( "ToolTip", "Quickly annotate screenshots, photos and other images and save, paste or share with other apps." ), QCoreApplication.translate( "ToolTip", "Solitaire is one of the most played computer card games of all time." ), QCoreApplication.translate( "ToolTip", "Live scores and in-depth game experiences for more than 150 leagues." ), QCoreApplication.translate( "ToolTip", "Play your favorite songs and albums free on Windows 10 with Spotify." ), QCoreApplication.translate( "ToolTip", "Create notes, type, ink or add a picture, add text formatting, or stick them to the desktop." ), QCoreApplication.translate( "ToolTip", "Provide users with information and tips about operating system features." ), QCoreApplication.translate( "ToolTip", "Translate text and speech, have translated conversations, and even download AI-powered language packs to use offline." ), QCoreApplication.translate( "ToolTip", "Record sounds, lectures, interviews, and other events."), QCoreApplication.translate( "ToolTip", "Latest weather conditions, accurate 10-day and hourly forecasts." ), QCoreApplication.translate( "ToolTip", "Browse the catalogue, view recommendations, and discover PC games with Xbox Game Pass." ), QCoreApplication.translate( "ToolTip", "Instant access to widgets for screen capture and sharing, and chatting with Xbox friends." ), QCoreApplication.translate( "ToolTip", "Link your Android phone and PC to view and reply to text messages, access mobile apps, and receive notifications." ))) self.app_data_list = [{ "name": "*Microsoft.3DBuilder*", "link": "/?PFN=Microsoft.3DBuilder_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.Microsoft3DViewer*", "link": "/?PFN=Microsoft.Microsoft3DViewer_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.WindowsAlarms*", "link": "/?PFN=Microsoft.WindowsAlarms_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.WindowsCalculator*", "link": "/?PFN=Microsoft.WindowsCalculator_8wekyb3d8bbwe", "size": 0 }, { "name": "*microsoft.windowscommunicationsapps*", "link": "/?PFN=Microsoft.windowscommunicationsapps_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.WindowsCamera*", "link": "/?PFN=Microsoft.WindowsCamera_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.WindowsFeedbackHub*", "link": "/?PFN=Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.GetHelp*", "link": "/?PFN=Microsoft.Gethelp_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.ZuneMusic*", "link": "/?PFN=Microsoft.ZuneMusic_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.WindowsMaps*", "link": "/?PFN=Microsoft.WindowsMaps_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.Messaging*", "link": "/?PFN=Microsoft.Messaging_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.MixedReality.Portal*", "link": "/?PFN=Microsoft.MixedReality.Portal_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.OneConnect*", "link": "/?PFN=Microsoft.OneConnect_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.BingFinance*", "link": "/?PFN=Microsoft.BingFinance_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.ZuneVideo*", "link": "/?PFN=Microsoft.ZuneVideo_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.BingNews*", "link": "/?PFN=Microsoft.BingNews_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.MicrosoftOfficeHub*", "link": "/?PFN=Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.Office.OneNote*", "link": "/?PFN=Microsoft.Office.OneNote_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.MSPaint*", "link": "/?PFN=Microsoft.MSPaint_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.People*", "link": "/?PFN=Microsoft.People_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.Windows.Photos*", "link": "/?PFN=Microsoft.Windows.Photos_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.Print3D*", "link": "/?PFN=Microsoft.Print3D_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.SkypeApp*", "link": "/?PFN=Microsoft.SkypeApp_kzf8qxf38zg5c", "size": 0 }, { "name": "*Microsoft.ScreenSketch*", "link": "/?PFN=Microsoft.ScreenSketch_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.MicrosoftSolitaireCollection*", "link": "/?PFN=Microsoft.MicrosoftSolitaireCollection_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.BingSports*", "link": "/?PFN=Microsoft.BingSports_8wekyb3d8bbwe", "size": 0 }, { "name": "*SpotifyAB.SpotifyMusic*", "link": "/?PFN=SpotifyAB.SpotifyMusic_zpdnekdrzrea0", "size": 0 }, { "name": "*Microsoft.MicrosoftStickyNotes*", "link": "/?PFN=Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.Getstarted*", "link": "/?PFN=Microsoft.Getstarted_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.BingTranslator*", "link": "/?PFN=Microsoft.BingTranslator_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.WindowsSoundRecorder*", "link": "/?PFN=Microsoft.WindowsSoundRecorder_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.BingWeather*", "link": "/?PFN=Microsoft.BingWeather_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.GamingApp*", "link": "/?PFN=Microsoft.GamingApp_8wekyb3d8bbwe", "size": 0 }, { "name": "*Xbox*", "link": "/?PFN=Microsoft.XboxGameOverlay_8wekyb3d8bbwe", "size": 0 }, { "name": "*Microsoft.YourPhone*", "link": "/?PFN=Microsoft.YourPhone_8wekyb3d8bbwe", "size": 0 }] if version.parse(platform.version()) >= version.parse("10.0.19041"): insort(self.app_name_list, QCoreApplication.translate("AppName", "Cortana")) cortana_index = self.app_name_list.index("Cortana") self.tooltip_list.insert( cortana_index, QCoreApplication.translate("ToolTip", "Personal intelligence assistant.")) self.app_data_list.insert( cortana_index, { "name": "*Microsoft.549981C3F5F10*", "link": "/?PFN=Microsoft.549981C3F5F10_8wekyb3d8bbwe", "size": 0 }) self.checkbox_list = [] for i, _ in enumerate(self.app_name_list): self.checkbox_list.append(QCheckBox()) if i % 3 == 2: self.layout_checkboxes_3.addWidget(self.checkbox_list[i]) elif i % 3 == 1: self.layout_checkboxes_2.addWidget(self.checkbox_list[i]) else: self.layout_checkboxes.addWidget(self.checkbox_list[i]) self.apps_dict = {} for i, checkbox in enumerate(self.checkbox_list): checkbox.setText(self.app_name_list[i]) checkbox.setToolTip(self.tooltip_list[i]) checkbox.setFont(self.font) self.apps_dict[checkbox] = self.app_data_list[i] self.label_space.setText( QCoreApplication.translate("Label", "Total amount of disk space:")) self.label_size.setText(QCoreApplication.translate("Label", "0 MB")) self.button_select_all.setText( QCoreApplication.translate("Button", "Select All")) self.button_deselect_all.setText( QCoreApplication.translate("Button", "Deselect All")) self.button_uninstall.setText( QCoreApplication.translate("Button", "Uninstall"))
def __init__(self, *args, **kwargs): super(TitleBar, self).__init__(*args, **kwargs) # Поддержка настройки фона qss self.setAttribute(Qt.WA_StyledBackground, True) self.mPos = None self.iconSize = 20 # Размер значка по умолчанию # Установите цвет фона по умолчанию, иначе он будет прозрачным из-за влияния родительского окна self.setAutoFillBackground(True) palette = self.palette() palette.setColor(palette.Window, QColor(240, 240, 240)) self.setPalette(palette) # Подключение стиля self.setStyleSheet('Titlebar.qss') self.setStyleSheet(open("Titlebar.qss", "r").read()) # макет layout = QHBoxLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) # значок окна # название окна self.titleLabel = QLabel(self) self.titleLabel.setMargin(2) self.font_id = QFontDatabase.addApplicationFont( "Roboto/Roboto-Bold.ttf") font = QFont("Roboto-Bold", 12) font.setFamily(u"Roboto") font.setBold(True) self.buttonMy = QPushButton(self, clicked=self.showButtonMy, objectName='buttonMy') self.buttonMy.setIcon(QIcon('icon-white.ico')) layout.addWidget(self.buttonMy) layout.addStretch() self.titleLabel.setFont(font) layout.addStretch() layout.addWidget(self.titleLabel, alignment=Qt.AlignCenter) # Средний телескопический бар layout.addSpacerItem( QSpacerItem(40, 100, QSizePolicy.Expanding, QSizePolicy.Minimum)) # Использовать шрифты Webdings для отображения значков font = self.font() or QFont() font.setFamily('Webdings') # Своя Кнопка # Свернуть кнопку self.buttonMinimum = QPushButton('0', self, clicked=self.windowMinimumed.emit, font=font, objectName='buttonMinimum') layout.addWidget(self.buttonMinimum) # Кнопка Max / restore self.buttonMaximum = QPushButton('1', self, clicked=self.showMaximized, font=font, objectName='buttonMaximum') layout.addWidget(self.buttonMaximum) # Кнопка закрытия self.buttonClose = QPushButton('r', self, clicked=self.windowClosed.emit, font=font, objectName='buttonClose') layout.addWidget(self.buttonClose) # начальная высота self.setHeight()
class AbstractReferenceSelector(QWidget): changed = Signal() def __init__(self, parent=None): QWidget.__init__(self, parent) self.completer = None self.p_selected_id = 0 self.layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.name = QLineEdit() self.name.setText("") self.layout.addWidget(self.name) self.details = QLabel() self.details.setText("") self.details.setVisible(False) self.layout.addWidget(self.details) self.button = QPushButton("...") self.button.setFixedWidth( self.button.fontMetrics().horizontalAdvance("XXXX")) self.layout.addWidget(self.button) self.setLayout(self.layout) self.setFocusProxy(self.name) self.button.clicked.connect(self.on_button_clicked) if self.details_field: self.name.setFixedWidth( self.name.fontMetrics().horizontalAdvance("X") * 15) self.details.setVisible(True) self.completer = QCompleter(self.dialog.model.completion_model) self.completer.setCompletionColumn( self.dialog.model.completion_model.fieldIndex(self.selector_field)) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.name.setCompleter(self.completer) self.completer.activated[QModelIndex].connect(self.on_completion) def getId(self): return self.p_selected_id def setId(self, selected_id): if self.p_selected_id == selected_id: return self.p_selected_id = selected_id self.name.setText( self.dialog.model.getFieldValue(selected_id, self.selector_field)) if self.details_field: self.details.setText( self.dialog.model.getFieldValue(selected_id, self.details_field)) selected_id = Property(int, getId, setId, notify=changed, user=True) def setFilterValue(self, filter_value): self.dialog.setFilterValue(filter_value) def on_button_clicked(self): ref_point = self.mapToGlobal(self.name.geometry().bottomLeft()) self.dialog.setGeometry(ref_point.x(), ref_point.y(), self.dialog.width(), self.dialog.height()) res = self.dialog.exec(enable_selection=True, selected=self.selected_id) if res: self.selected_id = self.dialog.selected_id self.changed.emit() @Slot(QModelIndex) def on_completion(self, index): model = index.model() self.selected_id = model.data(model.index(index.row(), 0), Qt.DisplayRole) self.changed.emit() def isCustom(self): return True