def initUI(self): self.setWindowIcon(QIcon(SRC_DIR + "desc.ico")) self.lb_name = QLabel() self.lb_name.setText("文件夹名:") self.lb_name.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.tx_name = QLineEdit() self.lb_desc = QLabel() self.tx_desc = QTextEdit() self.lb_desc.setText("描 述:") self.lb_desc.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("取消") self.grid = QGridLayout() self.grid.setSpacing(10) self.grid.addWidget(self.lb_name, 1, 0) self.grid.addWidget(self.tx_name, 1, 1) self.grid.addWidget(self.lb_desc, 2, 0) self.grid.addWidget(self.tx_desc, 2, 1, 5, 1) self.grid.addWidget(self.buttonBox, 7, 1, 1, 1) self.setLayout(self.grid) self.buttonBox.accepted.connect(self.btn_ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject)
def __init__(self, parent, top): super(QWidget, self).__init__(parent) self.top = top hlayout = QHBoxLayout() self.layout = QGridLayout() hlayout.addLayout(self.layout) hlayout.setAlignment(hlayout, Qt.Alignment.AlignTop) self.setLayout(hlayout) self.row = 0 self.__addLabel__("Federate Name") self.federateName = QLineEdit('REMOTE_WORKSTATION') self.__addInput__(self.federateName) self.__addLabel__("Message Directory Cache") self.messageDirectoryCache = QLineEdit(self) self.__addInputAndSelect__(self.messageDirectoryCache, self.top) self.__addLabel__("Map Data Cache") self.mapDataCache = QLineEdit(self) self.__addInputAndSelect__(self.mapDataCache, self.top) self.__addLabel__("Raster Map Cache") self.rasterMapCache = QLineEdit(self) self.__addInputAndSelect__(self.rasterMapCache, self.top) self.__addLabel__("Remote Control Location") self.remoteControlLocation = QLineEdit(self) self.__addInputAndSelect__(self.remoteControlLocation, self.top)
class App(QDialog): def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Grid Layout') self.setGeometry(100, 100, 320, 100) self.CreateGridLayout() self.windowLayout = QVBoxLayout() self.windowLayout.addWidget(self.horizontalGroupBox) self.setLayout(self.windowLayout) self.show() sys.exit(app.exec()) def CreateGridLayout(self): self.horizontalGroupBox = QGroupBox("Grid") self.layout = QGridLayout() self.layout.setColumnStretch(2, 4) self.layout.setColumnStretch(1, 4) for label in "123456789": self.MakeButton(label) self.horizontalGroupBox.setLayout(self.layout) def MakeButton(self, label): button = QPushButton(label) button.clicked.connect(lambda: self.on_click(button)) self.layout.addWidget(button) def on_click(self, pushButton): print('PyQt5 {0} button clicked.'.format(pushButton.text()))
def _createButtons(self): """Create the buttons.""" self.buttons = {} buttonsLayout = QGridLayout() # Button text | position on the QGridLayout buttons = { "7": (0, 0), "8": (0, 1), "9": (0, 2), "/": (0, 3), "C": (0, 4), "4": (1, 0), "5": (1, 1), "6": (1, 2), "*": (1, 3), "(": (1, 4), "1": (2, 0), "2": (2, 1), "3": (2, 2), "-": (2, 3), ")": (2, 4), "0": (3, 0), "00": (3, 1), ".": (3, 2), "+": (3, 3), "=": (3, 4), } # Create the buttons and add them to the grid layout for btnText, pos in buttons.items(): self.buttons[btnText] = QPushButton(btnText) self.buttons[btnText].setFixedSize(40, 40) buttonsLayout.addWidget(self.buttons[btnText], pos[0], pos[1]) # Add buttonsLayout to the general layout self.generalLayout.addLayout(buttonsLayout)
def __init__(self, parent, top): super(QWidget, self).__init__(parent) self.top = top hlayout = QHBoxLayout() self.layout = QGridLayout() hlayout.addLayout(self.layout) hlayout.setAlignment(hlayout, Qt.Alignment.AlignTop) self.setLayout(hlayout) self.row = 0 self.__addLabel__("Gateway Services") self.__addLabel__("Gateway Host Name/IP Address") self.gatewayHostName = QLineEdit(self) self.__addInput__(self.gatewayHostName) self.__addLabel__("Exercise Data Server Host Name/IP Address") self.productionEDS = QLineEdit(self) self.prodEnable = QRadioButton("Production") self.prodEnable.setChecked(True) self.prodEnable.toggled.connect(self.radioProdClicked) self.prodEnable.setStyleSheet("QRadioButton{ width: 100; }") self.__addInputAndRadio__(self.productionEDS, self.prodEnable) self.testEDS = QLineEdit(self) self.testEnable = QRadioButton("Test") self.testEnable.toggled.connect(self.radioTestClicked) self.testEnable.setStyleSheet("QRadioButton{ width: 100; }") self.__addInputAndRadio__(self.testEDS, self.testEnable) self.__addLabel__("Messaging Port") self.messagePort = QLineEdit("61616") self.__addInput__(self.messagePort)
def __init__(self, parent=None): super(Manual, self).__init__() self.manual = QWebEngineView() webpage = QtCore.QUrl('https://wingtorres.github.io/morphometrix/') self.manual.setUrl(webpage) self.grid = QGridLayout() self.grid.addWidget(self.manual,1,0) self.setLayout(self.grid)
def __init__(self, parent=None): #init methods runs every time, use for core app stuff) super(Window, self).__init__() #self.setWindowTitle("MorphoMetriX") #self.setGeometry(50, 50, 100, 200) #x,y,width,height #self.setStyleSheet("background-color: rgb(0,0,0)") #change color #self.setStyleSheet("font-color: rgb(0,0,0)") #change color self.label_id = QLabel("Image ID") self.id = QLineEdit() self.id.setText('0000') #Define custom attributes for pixel -> SI conversion self.label_foc = QLabel("Focal Length (mm):") self.focal = QLineEdit() self.focal.setText('50') self.label_alt = QLabel("Altitude (m):") self.altitude = QLineEdit() self.altitude.setText('50') self.label_pd = QLabel("Pixel Dimension (mm/pixel)") self.pixeldim = QLineEdit() self.pixeldim.setText('0.00391667') self.label_widths = QLabel("# Width Segments:") self.numwidths = QLineEdit() self.numwidths.setText('10') self.label_not = QLabel("Notes:") self.notes = QPlainTextEdit() # self.manual = QWebEngineView() #fpath = os.path.abspath('/Users/WalterTorres/Dropbox/KC_WT/MorphoMetrix/morphometrix/README.html') #webpage = QtCore.QUrl.fromLocalFile(fpath) # webpage = QtCore.QUrl('https://wingtorres.github.io/morphometrix/') # self.manual.setUrl(webpage) self.exit = QPushButton("Exit", self) self.exit.clicked.connect(self.close_application) self.grid = QGridLayout() self.grid.addWidget(self.label_id, 1, 0) self.grid.addWidget(self.id, 1, 1) self.grid.addWidget(self.label_foc, 2, 0) self.grid.addWidget(self.focal, 2, 1) self.grid.addWidget(self.label_alt, 3, 0) self.grid.addWidget(self.altitude, 3, 1) self.grid.addWidget(self.label_pd, 4, 0) self.grid.addWidget(self.pixeldim, 4, 1) self.grid.addWidget(self.label_widths, 5, 0) self.grid.addWidget(self.numwidths, 5, 1) self.grid.addWidget(self.label_not, 6, 0) self.grid.addWidget(self.notes, 6, 1) # self.grid.addWidget(self.manual, 8,0,1,4) self.grid.addWidget(self.exit, 7, 3) self.setLayout(self.grid)
def CreateGridLayout(self): self.horizontalGroupBox = QGroupBox("Grid") self.layout = QGridLayout() self.layout.setColumnStretch(2, 4) self.layout.setColumnStretch(1, 4) for label in "123456789": self.MakeButton(label) self.horizontalGroupBox.setLayout(self.layout)
def __init__(self): logger.debug('Ui class initializing') self.eog = False self.app = QApplication([]) super().__init__() self.field = [] self.layout = QGridLayout() self.gui_init()
def show_setting(self, conf: dict, layout: QGridLayout): groups = list() x = 0 y = 0 shape = 3 for key in conf.keys(): if type(conf[key]) == bool or type(conf[key]) == str: continue conf_title = conf[key]["title"] conf_enabled = conf[key]["enabled"] conf_times = conf[key]["times"] group = QGroupBox(conf_title) group.setStyleSheet("QGroupBox{border-radius:5px;}") group.setToolTip(conf_title + " 的设置") enabled = QCheckBox("启用") enabled.setObjectName(key) enabled.setToolTip("单击切换开关状态") enabled.setChecked(conf_enabled) enabled.setStyleSheet( "QCheckBox::indicator{width:10px;height:10px;border:none;border-radius:5px;background:#9BE3DE;}QCheckBox::indicator:unchecked{background:#BEEBE9;}QCheckBox::indicator:unchecked:hover{background:#9AD3BC;}QCheckBox::indicator:checked{background:#95E1D3;}QCheckBox::indicator:checked:hover{background:#98DED9;}" ) times = QHBoxLayout() times_label = QLabel("次数:") times_label.setStyleSheet( "QLabel{background:transparent;border:none;border-radius:5px;}" ) times_input = EnhancedEdit() times_input.setObjectName(key) times_input.setText(str(conf_times)) times_input.setToolTip("仅限正整数") times_input.setValidator( QRegularExpressionValidator( QRegularExpression("^[1-9][0-9]{1,8}$"))) times_input.setStyleSheet( "QLineEdit{border:1px solid #F3EAC2;border-radius:5px;background:transparent;}QLineEdit:hover{border:1px solid #F5B461;}" ) times.addWidget(times_label) times.addWidget(times_input) group_layout = QVBoxLayout() group_layout.addWidget(enabled) group_layout.addLayout(times) group.setLayout(group_layout) group.setObjectName(key) groups.append(group) for group in groups: if y >= shape: x = x + 1 y = 0 layout.addWidget(group, x, y) y = y + 1 self.logger.debug("最后的元素位置:(%d,%d)" % (x, y)) return (x, y)
def _setupUi(self): """Create UI elements.""" self.vbox = QVBoxLayout() self.vbox.setObjectName(self.player.title + "BoxVertLayout") self.grid = QGridLayout() self.grid.setObjectName(self.player.title + "BoxCardPicsLayout") self.hbox = QHBoxLayout() self.hbox.setObjectName(self.player.title + "BoxHorizLayout") self.vbox.addLayout(self.hbox) self.vbox.addLayout(self.grid) self.setLayout(self.vbox) self._setupLabels() self._setupCards()
def setup_ui(self): self.setObjectName("Dialog") self.resize(497, 235) self.gridLayout = l = QGridLayout(self) l.setObjectName("gridLayout") self.icon_label = la = QLabel('') la.setMaximumSize(QSize(68, 68)) la.setScaledContents(False) la.setObjectName("icon_label") l.addWidget(la) self.msg = la = QLabel(self) la.setWordWrap(True), la.setMinimumWidth(400) la.setOpenExternalLinks(True) la.setObjectName("msg") l.addWidget(la, 0, 1, 1, 1) self.det_msg = dm = QPlainTextEdit(self) dm.setReadOnly(True) dm.setObjectName("det_msg") l.addWidget(dm, 1, 0, 1, 2) self.bb = bb = QDialogButtonBox(self) bb.setStandardButtons(QDialogButtonBox.StandardButton.Ok) bb.setObjectName("bb") bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) l.addWidget(bb, 3, 0, 1, 2) self.toggle_checkbox = tc = QCheckBox(self) tc.setObjectName("toggle_checkbox") l.addWidget(tc, 2, 0, 1, 2)
class Workstation(QWidget): def __init__(self, parent, top): super(QWidget, self).__init__(parent) self.top = top hlayout = QHBoxLayout() self.layout = QGridLayout() hlayout.addLayout(self.layout) hlayout.setAlignment(hlayout, Qt.Alignment.AlignTop) self.setLayout(hlayout) self.row = 0 self.__addLabel__("Federate Name") self.federateName = QLineEdit('REMOTE_WORKSTATION') self.__addInput__(self.federateName) self.__addLabel__("Message Directory Cache") self.messageDirectoryCache = QLineEdit(self) self.__addInputAndSelect__(self.messageDirectoryCache, self.top) self.__addLabel__("Map Data Cache") self.mapDataCache = QLineEdit(self) self.__addInputAndSelect__(self.mapDataCache, self.top) self.__addLabel__("Raster Map Cache") self.rasterMapCache = QLineEdit(self) self.__addInputAndSelect__(self.rasterMapCache, self.top) self.__addLabel__("Remote Control Location") self.remoteControlLocation = QLineEdit(self) self.__addInputAndSelect__(self.remoteControlLocation, self.top) def __addLabel__(self, label): lbl = QLabel(label) self.layout.addWidget(lbl, self.row, 0, 1, -1) self.row += 1 def __addInput__(self, input): self.layout.addWidget(input, self.row, 0, 1, 4) self.row += 1 def __addSelect__(self, input): self.layout.addWidget(BrowseButton(self, input), self.row - 1, 4, 1, 1) def __addInputAndSelect__(self, input, top): hbox = QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.addWidget(input) browseButton = BrowseButton(self, input, top) browseButton.adjustSize() hbox.addWidget(browseButton) widget = QWidget(self) widget.setLayout(hbox) self.layout.addWidget(widget, self.row, 0, 1, -1) self.row += 1 def tabName(self): return 'Workstation'
def initUI(self): grid = QGridLayout() x = 0 y = 0 self.text = f'x: {x}, y: {y}' self.label = QLabel(self.text, self) grid.addWidget(self.label, 0, 0, Qt.AlignmentFlag.AlignTop) self.setMouseTracking(True) self.setLayout(grid) self.setGeometry(300, 300, 450, 300) self.setWindowTitle('Event object') self.show()
def createLayout(self): self.groupBox = QGroupBox( "What is your favorite programming language?") gridLayout = QGridLayout() button1 = QPushButton("Python", self) gridLayout.addWidget(button1, 0, 0) button2 = QPushButton("C++", self) gridLayout.addWidget(button2, 0, 1) button3 = QPushButton("Java", self) gridLayout.addWidget(button3, 1, 0) button4 = QPushButton("C#", self) gridLayout.addWidget(button4, 1, 1) self.groupBox.setLayout(gridLayout)
def initUI(self): self.setWindowTitle("请稍等……") self.setWindowIcon(QIcon(SRC_DIR + "password.ico")) self.lb_oldpwd = QLabel() self.lb_oldpwd.setText("当前提取码:") self.lb_oldpwd.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.tx_oldpwd = QLineEdit() # 当前提取码 只读 self.tx_oldpwd.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.tx_oldpwd.setReadOnly(True) self.lb_newpwd = QLabel() self.lb_newpwd.setText("新的提取码:") self.lb_newpwd.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.tx_newpwd = QLineEdit() self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("取消") self.grid = QGridLayout() self.grid.setSpacing(10) self.grid.addWidget(self.lb_oldpwd, 1, 0) self.grid.addWidget(self.tx_oldpwd, 1, 1) self.grid.addWidget(self.lb_newpwd, 2, 0) self.grid.addWidget(self.tx_newpwd, 2, 1) self.grid.addWidget(self.buttonBox, 3, 0, 1, 2) self.setLayout(self.grid) self.buttonBox.accepted.connect(self.btn_ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.accepted.connect(self.set_tip) self.buttonBox.rejected.connect(self.reject) self.buttonBox.rejected.connect(self.set_tip) self.setMinimumWidth(280)
def setup_ui(self): self.lay = lay = QGridLayout(self) self.la = la = QLabel(self.msg) la.setWordWrap(True) lay.addWidget(la, 0, 0, 1, -1) self.setMaximumWidth(self.parent().width()) self.setMaximumHeight(self.parent().height()) self.cb = cb = QCheckBox(_('&Suppress future alerts from this site'), self) cb.toggled.connect(self.suppress_toggled) lay.addWidget(cb, 1, 0) lay.addWidget(self.bb, 1, 1), self.bb.setStandardButtons( QDialogButtonBox.StandardButton.Close)
def setupUi(self, KeysWidget): self.mainLayout = QGridLayout(KeysWidget) self.buttons = [] self.exercises = [] if KeysWidget.classifyExercises is not None: for ind in range(0, len(KeysWidget.classifyExercises.exercises)): self.exercises.append( KeysWidget.classifyExercises.exercises[ind]) self.createRow( exercise=KeysWidget.classifyExercises.exercises[ind], index=ind) self.actions = QHBoxLayout() self.supportedKeys = QPushButton('Supported keys') self.supportedKeys.setIcon(QIcon.fromTheme("dialog-information")) self.supportedKeys.clicked.connect(self.allKeyDialog) self.saveProfile = QPushButton('Save keys') self.actions.addWidget(self.supportedKeys) self.actions.addWidget(self.saveProfile) self.mainLayout.addLayout(self.actions, self.mainLayout.rowCount(), 0)
def initUI(self): self.setWindowTitle("移动文件(夹)") self.setWindowIcon(QIcon(SRC_DIR + "move.ico")) self.lb_name = QLabel() self.lb_name.setText("文件(夹)名:") self.lb_name.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.tx_name = AutoResizingTextEdit() self.tx_name.setFocusPolicy(Qt.FocusPolicy.NoFocus) # 只读 self.tx_name.setReadOnly(True) self.lb_new_path = QLabel() self.lb_new_path.setText("目标文件夹:") self.lb_new_path.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.tx_new_path = QComboBox() self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("取消") self.grid = QGridLayout() self.grid.setSpacing(10) self.grid.addWidget(self.lb_name, 1, 0) self.grid.addWidget(self.tx_name, 1, 1) self.grid.addWidget(self.lb_new_path, 2, 0) self.grid.addWidget(self.tx_new_path, 2, 1) self.grid.addWidget(self.buttonBox, 3, 0, 1, 2) self.setLayout(self.grid) self.buttonBox.accepted.connect(self.btn_ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.setMinimumWidth(280)
def initUI(self): grid = QGridLayout() self.setLayout(grid) names = ['Cls', 'Bck', '', 'Close', '7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', '0', '.', '=', '+'] positions = [(i, j) for i in range(5) for j in range(4)] for position, name in zip(positions, names): if name == '': continue button = QPushButton(name) grid.addWidget(button, *position) self.move(300, 150) self.setWindowTitle('Calculator') self.show()
def __init__(self, parent=None): super(MainWidget, self).__init__(parent) self.setWindowTitle("QThread Demo") self.thread = Worker() self.listFile = QListWidget() self.buttonStart = QPushButton("开始") layout = QGridLayout(self) layout.addWidget(self.listFile, 0, 0, 1, 2) layout.addWidget(self.buttonStart, 1, 1) self.buttonStart.clicked.connect(self.slotStart) self.thread.sinOut.connect(self.slodAdd)
def setup_ui(self): self.l = l = QGridLayout(self) self.ic = la = QLabel(self) ic = self.style().standardIcon( QStyle.StandardPixmap.SP_MessageBoxWarning) la.setPixmap(ic.pixmap(64, 64)) l.addWidget(la, 0, 0) self.la = la = QLabel(self.msg) la.setWordWrap(True) l.addWidget(la, 0, 1) self.permanent = p = QCheckBox( _('Permanently store permission for this site')) p.setToolTip( _('If checked you will never be asked for confirmation for this site again,' '\notherwise, you will be asked again after restarting the browser.' )) p.setChecked(gprefs.get('permanently_store_ssl_exception', True)) p.toggled.connect(self.permanent_toggled) l.addWidget(p, 1, 0, 1, -1) l.addWidget(self.bb, 2, 0, 1, -1) self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Yes | QDialogButtonBox.StandardButton.No) l.setColumnStretch(1, 100)
def __init__(self, parent=None): super(WinForm, self).__init__(parent) self.setWindowTitle("QTimer demo") self.listFile = QListWidget() self.label = QLabel("显示当前时间") self.startButton = QPushButton("开始") self.endButton = QPushButton("结束") layout = QGridLayout(self) # 初始化定时器 self.timer = QTimer(self) # 显示时间 self.timer.timeout.connect( self.showTime) # timeout 信号连接到特定的槽,当定时器超时,发出 timeout 信号 layout.addWidget(self.label, 0, 0, 1, 2) layout.addWidget(self.startButton, 1, 0) layout.addWidget(self.endButton, 1, 1) self.startButton.clicked.connect(self.start_timer) self.endButton.clicked.connect(self.end_timer) self.setLayout(layout)
class Services(QWidget): def __init__(self, parent, top): super(QWidget, self).__init__(parent) self.top = top hlayout = QHBoxLayout() self.layout = QGridLayout() hlayout.addLayout(self.layout) hlayout.setAlignment(hlayout, Qt.Alignment.AlignTop) self.setLayout(hlayout) self.row = 0 self.__addLabel__("Gateway Services") self.__addLabel__("Gateway Host Name/IP Address") self.gatewayHostName = QLineEdit(self) self.__addInput__(self.gatewayHostName) self.__addLabel__("Exercise Data Server Host Name/IP Address") self.productionEDS = QLineEdit(self) self.prodEnable = QRadioButton("Production") self.prodEnable.setChecked(True) self.prodEnable.toggled.connect(self.radioProdClicked) self.prodEnable.setStyleSheet("QRadioButton{ width: 100; }") self.__addInputAndRadio__(self.productionEDS, self.prodEnable) self.testEDS = QLineEdit(self) self.testEnable = QRadioButton("Test") self.testEnable.toggled.connect(self.radioTestClicked) self.testEnable.setStyleSheet("QRadioButton{ width: 100; }") self.__addInputAndRadio__(self.testEDS, self.testEnable) self.__addLabel__("Messaging Port") self.messagePort = QLineEdit("61616") self.__addInput__(self.messagePort) def radioProdClicked(self): if self.sender().isChecked(): self.testEnable.setChecked(False) def radioTestClicked(self): if self.sender().isChecked(): self.prodEnable.setChecked(False) def __addLabel__(self, label): lbl = QLabel(label) self.layout.addWidget(lbl, self.row, 0, 1, -1) self.row += 1 def __addInput__(self, input): self.layout.addWidget(input, self.row, 0, 1, 4) self.row += 1 def __addInputAndRadio__(self, input, radio): hbox = QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.addWidget(input) hbox.addWidget(radio) widget = QWidget(self) widget.setLayout(hbox) self.layout.addWidget(widget, self.row, 0, 1, -1) self.row += 1 def tabName(self): return 'Services'
def __init__(self): super().__init__() self.logger = logging.getLogger(__name__) formatter = logging.Formatter( fmt="%(asctime)s-%(levelname)s-%(message)s", datefmt="%Y-%m-%d %H:%M:%S") filehandler = logging.FileHandler(filename="logs.log", mode="w", encoding="utf-8") handler = QLogger(update_signal=self.update_signal) handler.setLevel(logging.INFO) filehandler.setLevel(logging.INFO) self.logger.setLevel(logging.INFO) if os.path.exists("config.json") == False: self.gen_conf() with open(file="config.json", mode="r", encoding="utf-8") as conf_reader: conf = json.loads(conf_reader.read()) debug = bool(conf["debug"]) if debug == True: handler.setLevel(logging.DEBUG) filehandler.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG) handler.setFormatter(formatter) filehandler.setFormatter(formatter) self.logger.addHandler(handler) self.logger.addHandler(filehandler) self.logger.debug("当前调试状态:%s" % debug) self.resize(1024, 768) self.setWindowOpacity(0.9) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setWindowFlag(Qt.WindowFlags.FramelessWindowHint) self.setAutoFillBackground(True) self.work = Work(show_qr_signal=self.show_qr_signal, finish_signal=self.finish_signal, close_qr_signal=self.close_qr_signal) self.work_thread = QThread() self.work.moveToThread(self.work_thread) self.main_layout = QGridLayout() self.setLayout(self.main_layout) self.title = QLabel("ChinaUniOnlineGUI") self.title.setStyleSheet( "QLabel{border:none;border-radius:5px;background:transparent;color:#9AD3BC;font-size:60px;}" ) self.title.setAlignment(Qt.Alignment.AlignCenter) handler.widget.setStyleSheet( "QPlainTextEdit{font-family:Microsoft YaHei;background:#F3EAC2;border:none;border-radius:5px;}QScrollBar:vertical,QScrollBar::handle:vertical{background:#F3EAC2;border:none;border-radius:8px;width:16px;}QScrollBar::handle:vertical:hover{background:#F5B461;}QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:#FFFDF9;border:none;border-radius:8px;width:16px;}QScrollBar::down-arrow:vertical,QScrollBar::up-arrow:vertical{background:#F5B461;border:none;border-radius:8px;width:16px;height:16px;}QScrollBar::sub-line:vertical,QScrollBar::add-line:vertical{background:transparent;border:none;}" ) self.control = QVBoxLayout() self.control_close = QPushButton() self.control_close.setToolTip("关闭") self.control_close.setStyleSheet( "QPushButton{background:#FFE3ED;border-radius:5px;border:none;}QPushButton:hover{background:#EC524B;}" ) self.contron_max = QPushButton() if self.isMaximized() == False: self.contron_max.setToolTip("最大化") else: self.contron_max.setToolTip("还原") self.contron_max.setStyleSheet( "QPushButton{background:#FFFDF9;border-radius:5px;border:none;}QPushButton:hover{background:#F5B461;}" ) self.control_min = QPushButton() self.control_min.setToolTip("最小化") self.control_min.setStyleSheet( "QPushButton{background:#BEEBE9;border-radius:5px;border:none;}QPushButton:hover{background:#F3EAC2;}" ) self.start_button = QPushButton("开始(&S)") self.start_button.setStyleSheet( "QPushButton{background:#9BE3DE;border:none;border-radius:5px;font-size:20px;font-family:DengXian;}QPushButton:hover{background:#9AD3BC;}" ) self.start_button.setToolTip("开始") self.start_button.setFixedSize(120, 60) self.start_button.setDefault(True) setting_button = QPushButton("设置") setting_button.setToolTip("设置") setting_button.setFixedSize(60, 60) setting_button.setStyleSheet( "QPushButton{background:#9BE3DE;border:none;border-radius:5px;font-size:20px;font-family:DengXian;}QPushButton:hover{background:#9AD3BC;}" ) setting_button.clicked.connect(self.setting_callback) start = QHBoxLayout() start.addWidget(self.start_button, 2) start.addWidget(setting_button, 1) self.control_close.clicked.connect(self.close) self.control_min.clicked.connect(self.min_callback) self.contron_max.clicked.connect(self.max_callback) self.start_button.clicked.connect(self.start_callback) self.work_thread.started.connect(self.work.start) self.finish_signal.connect(self.finish_callback) self.close_qr_signal.connect(self.close_qr) self.control.addWidget(self.control_min) self.control.addWidget(self.contron_max) self.control.addWidget(self.control_close) self.main_layout.addLayout(self.control, 0, 0) self.main_layout.addWidget(self.title, 0, 1) self.main_layout.addLayout(start, 0, 2) self.main_layout.addWidget(handler.widget, 1, 1) self.update_signal.connect(handler.widget.appendPlainText) handler.widget.textChanged.connect(handler.scroll_widget_to_bottom) self.show_qr_signal.connect(self.show_qr) self.logger.debug("已初始化UI")
class UI(QWidget): update_signal = pyqtSignal(str) show_qr_signal = pyqtSignal(bytes) finish_signal = pyqtSignal() close_qr_signal = pyqtSignal() def __init__(self): super().__init__() self.logger = logging.getLogger(__name__) formatter = logging.Formatter( fmt="%(asctime)s-%(levelname)s-%(message)s", datefmt="%Y-%m-%d %H:%M:%S") filehandler = logging.FileHandler(filename="logs.log", mode="w", encoding="utf-8") handler = QLogger(update_signal=self.update_signal) handler.setLevel(logging.INFO) filehandler.setLevel(logging.INFO) self.logger.setLevel(logging.INFO) if os.path.exists("config.json") == False: self.gen_conf() with open(file="config.json", mode="r", encoding="utf-8") as conf_reader: conf = json.loads(conf_reader.read()) debug = bool(conf["debug"]) if debug == True: handler.setLevel(logging.DEBUG) filehandler.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG) handler.setFormatter(formatter) filehandler.setFormatter(formatter) self.logger.addHandler(handler) self.logger.addHandler(filehandler) self.logger.debug("当前调试状态:%s" % debug) self.resize(1024, 768) self.setWindowOpacity(0.9) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setWindowFlag(Qt.WindowFlags.FramelessWindowHint) self.setAutoFillBackground(True) self.work = Work(show_qr_signal=self.show_qr_signal, finish_signal=self.finish_signal, close_qr_signal=self.close_qr_signal) self.work_thread = QThread() self.work.moveToThread(self.work_thread) self.main_layout = QGridLayout() self.setLayout(self.main_layout) self.title = QLabel("ChinaUniOnlineGUI") self.title.setStyleSheet( "QLabel{border:none;border-radius:5px;background:transparent;color:#9AD3BC;font-size:60px;}" ) self.title.setAlignment(Qt.Alignment.AlignCenter) handler.widget.setStyleSheet( "QPlainTextEdit{font-family:Microsoft YaHei;background:#F3EAC2;border:none;border-radius:5px;}QScrollBar:vertical,QScrollBar::handle:vertical{background:#F3EAC2;border:none;border-radius:8px;width:16px;}QScrollBar::handle:vertical:hover{background:#F5B461;}QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:#FFFDF9;border:none;border-radius:8px;width:16px;}QScrollBar::down-arrow:vertical,QScrollBar::up-arrow:vertical{background:#F5B461;border:none;border-radius:8px;width:16px;height:16px;}QScrollBar::sub-line:vertical,QScrollBar::add-line:vertical{background:transparent;border:none;}" ) self.control = QVBoxLayout() self.control_close = QPushButton() self.control_close.setToolTip("关闭") self.control_close.setStyleSheet( "QPushButton{background:#FFE3ED;border-radius:5px;border:none;}QPushButton:hover{background:#EC524B;}" ) self.contron_max = QPushButton() if self.isMaximized() == False: self.contron_max.setToolTip("最大化") else: self.contron_max.setToolTip("还原") self.contron_max.setStyleSheet( "QPushButton{background:#FFFDF9;border-radius:5px;border:none;}QPushButton:hover{background:#F5B461;}" ) self.control_min = QPushButton() self.control_min.setToolTip("最小化") self.control_min.setStyleSheet( "QPushButton{background:#BEEBE9;border-radius:5px;border:none;}QPushButton:hover{background:#F3EAC2;}" ) self.start_button = QPushButton("开始(&S)") self.start_button.setStyleSheet( "QPushButton{background:#9BE3DE;border:none;border-radius:5px;font-size:20px;font-family:DengXian;}QPushButton:hover{background:#9AD3BC;}" ) self.start_button.setToolTip("开始") self.start_button.setFixedSize(120, 60) self.start_button.setDefault(True) setting_button = QPushButton("设置") setting_button.setToolTip("设置") setting_button.setFixedSize(60, 60) setting_button.setStyleSheet( "QPushButton{background:#9BE3DE;border:none;border-radius:5px;font-size:20px;font-family:DengXian;}QPushButton:hover{background:#9AD3BC;}" ) setting_button.clicked.connect(self.setting_callback) start = QHBoxLayout() start.addWidget(self.start_button, 2) start.addWidget(setting_button, 1) self.control_close.clicked.connect(self.close) self.control_min.clicked.connect(self.min_callback) self.contron_max.clicked.connect(self.max_callback) self.start_button.clicked.connect(self.start_callback) self.work_thread.started.connect(self.work.start) self.finish_signal.connect(self.finish_callback) self.close_qr_signal.connect(self.close_qr) self.control.addWidget(self.control_min) self.control.addWidget(self.contron_max) self.control.addWidget(self.control_close) self.main_layout.addLayout(self.control, 0, 0) self.main_layout.addWidget(self.title, 0, 1) self.main_layout.addLayout(start, 0, 2) self.main_layout.addWidget(handler.widget, 1, 1) self.update_signal.connect(handler.widget.appendPlainText) handler.widget.textChanged.connect(handler.scroll_widget_to_bottom) self.show_qr_signal.connect(self.show_qr) self.logger.debug("已初始化UI") def min_callback(self): if self.isMinimized() == False: self.showMinimized() def max_callback(self): if self.isMaximized() == False: self.showMaximized() self.contron_max.setToolTip("还原") else: self.showNormal() self.contron_max.setToolTip("最大化") def start_callback(self): self.start_time = time.time() self.work_thread.start() self.start_button.setEnabled(False) self.start_button.setText("执行中...") def finish_callback(self): self.start_button.setEnabled(True) self.start_button.setText("开始") passed_time = time.time() - self.start_time mins, secs = divmod(passed_time, 60) hours, mins = divmod(mins, 60) self.logger.info("执行完成,共计用时 {:0>2d}:{:0>2d}:{:0>2d}".format( int(hours), int(mins), int(secs))) def show_qr(self, qr: bytes): title_label = QLabel("请使用微信扫描小程序码完成登陆") title_label.setStyleSheet( "QLabel{color:#ffe3ed;border:none;background-color:transparent;border-radius:5px;}" ) title_label.setAlignment(Qt.Alignment.AlignCenter) title_label.setFixedHeight(20) qr_label = QLabel() pixmap = QPixmap() pixmap.loadFromData(qr) qr_label.setPixmap(pixmap) qr_label.setStyleSheet( "QLabel{color:#ffe3ed;border:none;background-color:transparent;border-radius:5px;}" ) layout_ = QVBoxLayout() layout_.addWidget(title_label, 1) layout_.addWidget(qr_label, 9) self.qr_dialog = QWidget(self) self.qr_dialog.setLayout(layout_) self.main_layout.addWidget(self.qr_dialog, 1, 1, Qt.Alignment.AlignCenter) self.qr_dialog.show() def close_qr(self): self.qr_dialog.close() def setting_callback(self): setting = SettingWindow(parent=self) setting.setStyleSheet( "QDialog{border:none;border-radius:5px;background:#F3EAC2;}") setting.show() def gen_conf(self): default_conf = { "debug": False, "hero": { "title": "英雄篇", "enabled": True, "times": 1 }, "revival": { "title": "复兴篇", "enabled": True, "times": 1 }, "creation": { "title": "创新篇", "enabled": True, "times": 1 }, "belief": { "title": "信念篇", "enabled": True, "times": 1 }, "limit_time": { "title": "限时赛", "enabled": True, "times": 1 }, "rob": { "title": "抢十赛", "enabled": True, "times": 1 } } with open(file="config.json", mode="w", encoding="utf-8") as conf_writer: conf_writer.write( json.dumps(default_conf, indent=4, sort_keys=True, ensure_ascii=False)) self.logger.info("已生成默认配置文件") def mousePressEvent(self, event: QMouseEvent): self.logger.debug("触发鼠标按压事件") super().mousePressEvent(event) self.setFocus() self.m_flag = True if event.button() == Qt.MouseButtons.LeftButton and self.isMaximized( ) == False and self.hasFocus() == True: self.old_pos = event.globalPosition() #获取鼠标相对窗口的位置 self.logger.debug("已获取鼠标位置") self.setCursor(QtGui.QCursor( Qt.CursorShape.SizeAllCursor)) #更改鼠标图标 def mouseMoveEvent(self, event: QMouseEvent): self.logger.debug("触发鼠标移动事件") super().mouseMoveEvent(event) if self.m_flag == True: delta_x = int(event.globalPosition().x() - self.old_pos.x()) delta_y = int(event.globalPosition().y() - self.old_pos.y()) self.move(self.x() + delta_x, self.y() + delta_y) #更改窗口位置 self.logger.debug("已更改窗口位置") self.old_pos = event.globalPosition() def mouseReleaseEvent(self, event: QMouseEvent): self.logger.debug("触发鼠标释放事件") super().mouseReleaseEvent(event) self.m_flag = False self.setCursor(QtGui.QCursor(Qt.CursorShape.ArrowCursor))
def __init__(self, parent: QWidget): super().__init__() self.logger = logging.getLogger(__name__) with open(file="config.json", mode="r", encoding="utf-8") as conf_reader: self.conf = json.loads(conf_reader.read()) self.logger.debug("初始化设置界面。设置内容:%s" % self.conf) layout = QGridLayout() self.setLayout(layout) self.setModal(True) self.setParent(parent) self.resize(400, 300) title = QLabel("设置") title.setStyleSheet( "QLabel{border:none;border-radius:5px;background:transparent;color:#9AD3BC;font-size:20px;}" ) title.setAlignment(Qt.Alignment.AlignCenter) layout.addWidget(title, 0, 1, Qt.Alignment.AlignCenter) control_close = QPushButton() control_close.setStyleSheet( "QPushButton{background:#FFE3ED;border-radius:5px;border:none;}QPushButton:hover{background:#EC524B;}" ) control_close.setToolTip("关闭") control_close.setFixedHeight(20) control_close.clicked.connect(self.close_callback) layout.addWidget(control_close, 0, 0) debug_check = QCheckBox("调试模式") debug_check.setChecked(self.conf["debug"]) debug_check.setToolTip("单击切换开关状态") debug_check.setStyleSheet( "QCheckBox::indicator{width:10px;height:10px;border:none;border-radius:5px;background:#9BE3DE;}QCheckBox::indicator:unchecked{background:#BEEBE9;}QCheckBox::indicator:unchecked:hover{background:#9AD3BC;}QCheckBox::indicator:checked{background:#95E1D3;}QCheckBox::indicator:checked:hover{background:#98DED9;}" ) self.content = QGridLayout() (x, y) = self.show_setting(conf=self.conf, layout=self.content) # 返回content的最后一个元素的x,y proxy = QGroupBox() proxy.setObjectName("proxy") proxy_layout = QVBoxLayout() proxy_label = QLabel("代理地址:") proxy_label.setStyleSheet( "QLabel{background:transparent;border:none;}") proxy_input = EnhancedEdit() proxy_input.setText(self.conf["proxy"]) proxy_input.setToolTip("格式为协议://IP:端口,留空保持直连") proxy_input.setStyleSheet( "QLineEdit{border:1px solid #F3EAC2;border-radius:5px;background:transparent;}QLineEdit:hover{border:1px solid #F5B461;}" ) proxy_layout.addWidget(proxy_label) proxy_layout.addWidget(proxy_input) proxy.setLayout(proxy_layout) proxy.setStyleSheet("QGroupBox{border-radius:5px;}") proxy.setToolTip("代理设置") if y + 1 >= 3: y_ = 0 x_ = x + 1 else: y_ = y + 1 x_ = x self.content.addWidget(proxy, x_, y_) self.content.addWidget(debug_check) layout.addLayout(self.content, 1, 1)
class SettingWindow(QDialog): def __init__(self, parent: QWidget): super().__init__() self.logger = logging.getLogger(__name__) with open(file="config.json", mode="r", encoding="utf-8") as conf_reader: self.conf = json.loads(conf_reader.read()) self.logger.debug("初始化设置界面。设置内容:%s" % self.conf) layout = QGridLayout() self.setLayout(layout) self.setModal(True) self.setParent(parent) self.resize(400, 300) title = QLabel("设置") title.setStyleSheet( "QLabel{border:none;border-radius:5px;background:transparent;color:#9AD3BC;font-size:20px;}" ) title.setAlignment(Qt.Alignment.AlignCenter) layout.addWidget(title, 0, 1, Qt.Alignment.AlignCenter) control_close = QPushButton() control_close.setStyleSheet( "QPushButton{background:#FFE3ED;border-radius:5px;border:none;}QPushButton:hover{background:#EC524B;}" ) control_close.setToolTip("关闭") control_close.setFixedHeight(20) control_close.clicked.connect(self.close_callback) layout.addWidget(control_close, 0, 0) debug_check = QCheckBox("调试模式") debug_check.setChecked(self.conf["debug"]) debug_check.setToolTip("单击切换开关状态") debug_check.setStyleSheet( "QCheckBox::indicator{width:10px;height:10px;border:none;border-radius:5px;background:#9BE3DE;}QCheckBox::indicator:unchecked{background:#BEEBE9;}QCheckBox::indicator:unchecked:hover{background:#9AD3BC;}QCheckBox::indicator:checked{background:#95E1D3;}QCheckBox::indicator:checked:hover{background:#98DED9;}" ) self.content = QGridLayout() (x, y) = self.show_setting(conf=self.conf, layout=self.content) # 返回content的最后一个元素的x,y proxy = QGroupBox() proxy.setObjectName("proxy") proxy_layout = QVBoxLayout() proxy_label = QLabel("代理地址:") proxy_label.setStyleSheet( "QLabel{background:transparent;border:none;}") proxy_input = EnhancedEdit() proxy_input.setText(self.conf["proxy"]) proxy_input.setToolTip("格式为协议://IP:端口,留空保持直连") proxy_input.setStyleSheet( "QLineEdit{border:1px solid #F3EAC2;border-radius:5px;background:transparent;}QLineEdit:hover{border:1px solid #F5B461;}" ) proxy_layout.addWidget(proxy_label) proxy_layout.addWidget(proxy_input) proxy.setLayout(proxy_layout) proxy.setStyleSheet("QGroupBox{border-radius:5px;}") proxy.setToolTip("代理设置") if y + 1 >= 3: y_ = 0 x_ = x + 1 else: y_ = y + 1 x_ = x self.content.addWidget(proxy, x_, y_) self.content.addWidget(debug_check) layout.addLayout(self.content, 1, 1) def close_callback(self): self.save_settings() self.logger.debug("已保存设置") self.close() def save_settings(self): settings = dict() enabled = True times = 1 for i in range(self.content.count()): layoutitem = self.content.itemAt(i) if type(layoutitem.widget()) == QCheckBox: settings["debug"] = layoutitem.widget().isChecked() elif type(layoutitem.widget()) == QGroupBox: group = layoutitem.widget() for j in group.children(): if group.objectName() == "proxy": data = "" if type(j) == EnhancedEdit: data = str(j.text()) else: if type(j) == QCheckBox: enabled = j.isChecked() elif type(j) == EnhancedEdit: times = int(j.text()) data = { "title": group.title(), "enabled": enabled, "times": times } settings[group.objectName()] = data self.logger.debug("设置数据:%s" % settings) with open(file="config.json", mode="w", encoding="utf-8") as conf_writer: conf_writer.write( json.dumps(settings, ensure_ascii=False, sort_keys=True, indent=4)) def show_setting(self, conf: dict, layout: QGridLayout): groups = list() x = 0 y = 0 shape = 3 for key in conf.keys(): if type(conf[key]) == bool or type(conf[key]) == str: continue conf_title = conf[key]["title"] conf_enabled = conf[key]["enabled"] conf_times = conf[key]["times"] group = QGroupBox(conf_title) group.setStyleSheet("QGroupBox{border-radius:5px;}") group.setToolTip(conf_title + " 的设置") enabled = QCheckBox("启用") enabled.setObjectName(key) enabled.setToolTip("单击切换开关状态") enabled.setChecked(conf_enabled) enabled.setStyleSheet( "QCheckBox::indicator{width:10px;height:10px;border:none;border-radius:5px;background:#9BE3DE;}QCheckBox::indicator:unchecked{background:#BEEBE9;}QCheckBox::indicator:unchecked:hover{background:#9AD3BC;}QCheckBox::indicator:checked{background:#95E1D3;}QCheckBox::indicator:checked:hover{background:#98DED9;}" ) times = QHBoxLayout() times_label = QLabel("次数:") times_label.setStyleSheet( "QLabel{background:transparent;border:none;border-radius:5px;}" ) times_input = EnhancedEdit() times_input.setObjectName(key) times_input.setText(str(conf_times)) times_input.setToolTip("仅限正整数") times_input.setValidator( QRegularExpressionValidator( QRegularExpression("^[1-9][0-9]{1,8}$"))) times_input.setStyleSheet( "QLineEdit{border:1px solid #F3EAC2;border-radius:5px;background:transparent;}QLineEdit:hover{border:1px solid #F5B461;}" ) times.addWidget(times_label) times.addWidget(times_input) group_layout = QVBoxLayout() group_layout.addWidget(enabled) group_layout.addLayout(times) group.setLayout(group_layout) group.setObjectName(key) groups.append(group) for group in groups: if y >= shape: x = x + 1 y = 0 layout.addWidget(group, x, y) y = y + 1 self.logger.debug("最后的元素位置:(%d,%d)" % (x, y)) return (x, y)
def __init__(self): super().__init__() self.setWindowTitle('GitHub Abuz!') self.setWindowIcon(QIcon('icon.png')) layout = QGridLayout() vl = QVBoxLayout() hl = QHBoxLayout() hl2 = QHBoxLayout() hl3 = QHBoxLayout() self.y = QComboBox() self.name = QLineEdit() self.email = QLineEdit() self.passw = QLineEdit() self.repo = QLineEdit() self.type = QLineEdit() self.fonts = QComboBox() self.err = QMessageBox() self.nc = QSpinBox() lbl = QLabel('Commits/day:') prev = QPushButton('Translate') invert = QPushButton('Invert') leggo = QPushButton('Do it') invert.clicked.connect(self.invert) leggo.clicked.connect(self.doit) prev.clicked.connect(self.textCheck) self.name.textChanged[str].connect(self.rmph) self.email.textChanged[str].connect(self.rmph) self.passw.textChanged[str].connect(self.rmph) self.type.textChanged[str].connect(self.rmph) self.repo.textChanged[str].connect(self.rmph) self.y.addItem('Year (default: last 52 weeks)') for yr in range(datetime.datetime.now().year + 5, datetime.datetime.now().year - 20, -1): self.y.addItem(str(yr)) self.fonts.addItems(os.listdir('Fonts')) self.name.setPlaceholderText('Committer name') self.email.setPlaceholderText('Committer email') self.passw.setPlaceholderText('Password') self.passw.setEchoMode(QLineEdit.EchoMode.Password) self.repo.setPlaceholderText('Link to repo') self.type.setPlaceholderText('Translate text to tile art!') self.nc.setMinimum(1) self.nc.setValue(1) self.err.setWindowIcon(QIcon('icon.png')) self.err.setWindowTitle('Error!') hl.addWidget(self.name) hl.addWidget(self.email) hl.addWidget(self.passw) hl3.addWidget(self.repo) hl3.addWidget(self.y) hl3.addWidget(lbl) hl3.addWidget(self.nc) hl2.addWidget(self.type) hl2.addWidget(self.fonts) hl2.addWidget(prev) hl2.addWidget(invert) vl.addLayout(hl) vl.addLayout(hl3) vl.addLayout(layout) vl.addLayout(hl2) vl.addWidget(leggo) self.setLayout(vl) self.checkM = [list() for i in range(7)] for i in range(7): for j in range(52): m = QCheckBox() layout.addWidget(m, i, j) self.checkM[i].append(m)
def initUI(self): self.grid = QGridLayout(self) self.file_control_grid = QGridLayout() self.file_control_grid.setSpacing(3) self.grid.addLayout(self.file_control_grid, 0, 0) self.file_tree_grid = QGridLayout() self.file_tree_grid.setSpacing(3) self.grid.addLayout(self.file_tree_grid, 1, 0) self.group_control_grid = QGridLayout() self.group_control_grid.setSpacing(3) self.grid.addLayout(self.group_control_grid, 0, 1) self.attribute_grid = QGridLayout() self.attribute_grid.setSpacing(3) self.grid.addLayout(self.attribute_grid, 1, 1) self.roi_control_grid = QGridLayout() self.roi_control_grid.setSpacing(3) self.grid.addLayout(self.roi_control_grid, 0, 2) self.plot_grid = QGridLayout() self.plot_grid.setSpacing(3) self.grid.addLayout(self.plot_grid, 1, 2) # # # # File control browser: # # # # # # # # (0,0) loadButton = QPushButton("Load expt. file", self) loadButton.clicked.connect(self.selectDataFile) # Label with current expt file self.currentExperimentLabel = QLabel('') self.file_control_grid.addWidget(loadButton, 0, 0) self.file_control_grid.addWidget(self.currentExperimentLabel, 1, 0) directoryButton = QPushButton("Select data directory", self) directoryButton.clicked.connect(self.selectDataDirectory) self.file_control_grid.addWidget(directoryButton, 0, 1) self.data_directory_display = QLabel('') self.data_directory_display.setFont(QtGui.QFont('SansSerif', 8)) self.file_control_grid.addWidget(self.data_directory_display, 1, 1) # Attach metadata to file attachDatabutton = QPushButton("Attach metadata to file", self) attachDatabutton.clicked.connect(self.attachData) self.file_control_grid.addWidget(attachDatabutton, 2, 0, 1, 2) # Select image data file selectImageDataFileButton = QPushButton("Select image data file", self) selectImageDataFileButton.clicked.connect(self.selectImageDataFile) self.file_control_grid.addWidget(selectImageDataFileButton, 3, 0, 1, 2) # # # # File tree: # # # # # # # # (1,0) self.groupTree = QTreeWidget(self) self.groupTree.setHeaderHidden(True) self.groupTree.itemClicked.connect(self.onTreeItemClicked) self.file_tree_grid.addWidget(self.groupTree, 3, 0, 2, 7) # # # # Group control: # # # # # # # # (0, 1) deleteGroupButton = QPushButton("Delete selected group", self) deleteGroupButton.clicked.connect(self.deleteSelectedGroup) self.group_control_grid.addWidget(deleteGroupButton, 0, 0, 1, 2) # File name display self.currentImageFileNameLabel = QLabel('') self.group_control_grid.addWidget(self.currentImageFileNameLabel, 1, 0) # Channel drop down ch_label = QLabel('Channel:') self.ChannelComboBox = QComboBox(self) self.ChannelComboBox.addItem("1") self.ChannelComboBox.addItem("0") self.ChannelComboBox.activated.connect(self.selectChannel) self.group_control_grid.addWidget(ch_label, 2, 0) self.group_control_grid.addWidget(self.ChannelComboBox, 2, 1) # # # # Attribute table: # # # # # # # # (1, 1) self.tableAttributes = QTableWidget() self.tableAttributes.setStyleSheet("") self.tableAttributes.setColumnCount(2) self.tableAttributes.setObjectName("tableAttributes") self.tableAttributes.setRowCount(0) item = QTableWidgetItem() font = QtGui.QFont() font.setPointSize(10) item.setFont(font) item.setBackground(QtGui.QColor(121, 121, 121)) brush = QtGui.QBrush(QtGui.QColor(91, 91, 91)) brush.setStyle(QtCore.Qt.BrushStyle.SolidPattern) item.setForeground(brush) self.tableAttributes.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() item.setBackground(QtGui.QColor(123, 123, 123)) brush = QtGui.QBrush(QtGui.QColor(91, 91, 91)) brush.setStyle(QtCore.Qt.BrushStyle.SolidPattern) item.setForeground(brush) self.tableAttributes.setHorizontalHeaderItem(1, item) self.tableAttributes.horizontalHeader().setCascadingSectionResizes( True) self.tableAttributes.horizontalHeader().setHighlightSections(False) self.tableAttributes.horizontalHeader().setSortIndicatorShown(True) self.tableAttributes.horizontalHeader().setStretchLastSection(True) self.tableAttributes.verticalHeader().setVisible(False) self.tableAttributes.verticalHeader().setHighlightSections(False) item = self.tableAttributes.horizontalHeaderItem(0) item.setText("Attribute") item = self.tableAttributes.horizontalHeaderItem(1) item.setText("Value") self.tableAttributes.itemChanged.connect(self.update_attrs_to_file) self.attribute_grid.addWidget(self.tableAttributes, 3, 0, 1, 8) # # # # Roi control # # # # # # # # (0, 2) # ROI type drop-down self.RoiTypeComboBox = QComboBox(self) self.RoiTypeComboBox.addItem("freehand") radii = [1, 2, 3, 4, 6, 8] for radius in radii: self.RoiTypeComboBox.addItem("circle:" + str(radius)) self.RoiTypeComboBox.activated.connect(self.selectRoiType) self.roi_control_grid.addWidget(self.RoiTypeComboBox, 0, 0) # Clear all ROIs button self.clearROIsButton = QPushButton("Clear ROIs", self) self.clearROIsButton.clicked.connect(self.clearRois) self.roi_control_grid.addWidget(self.clearROIsButton, 0, 2) # Response display type dropdown self.RoiResponseTypeComboBox = QComboBox(self) self.RoiResponseTypeComboBox.addItem("RawTrace") self.RoiResponseTypeComboBox.addItem("TrialAverage") self.RoiResponseTypeComboBox.addItem("TrialResponses") self.RoiResponseTypeComboBox.addItem("TrialAverageDFF") self.roi_control_grid.addWidget(self.RoiResponseTypeComboBox, 2, 2) # ROIset file name line edit box self.defaultRoiSetName = "roi_set_name" self.le_roiSetName = QLineEdit(self.defaultRoiSetName) self.roi_control_grid.addWidget(self.le_roiSetName, 1, 1) # Save ROIs button self.saveROIsButton = QPushButton("Save ROIs", self) self.saveROIsButton.clicked.connect(self.saveRois) self.roi_control_grid.addWidget(self.saveROIsButton, 1, 0) # Load ROI set combobox self.loadROIsComboBox = QComboBox(self) self.loadROIsComboBox.addItem("(load existing ROI set)") self.loadROIsComboBox.activated.connect(self.selectedExistingRoiSet) self.roi_control_grid.addWidget(self.loadROIsComboBox, 1, 2) self.updateExistingRoiSetList() # Delete current roi button self.deleteROIButton = QPushButton("Delete ROI", self) self.deleteROIButton.clicked.connect(self.deleteRoi) self.roi_control_grid.addWidget(self.deleteROIButton, 2, 0) # Current roi slider self.roiSlider = QSlider(QtCore.Qt.Orientation.Horizontal, self) self.roiSlider.setMinimum(0) self.roiSlider.setMaximum(self.max_rois) self.roiSlider.valueChanged.connect(self.sliderUpdated) self.roi_control_grid.addWidget(self.roiSlider, 2, 1, 1, 1) ctx = plt.rc_context({ 'xtick.major.size': 1, 'axes.spines.top': False, 'axes.spines.right': False, 'xtick.labelsize': 'xx-small', 'ytick.labelsize': 'xx-small', 'xtick.major.size': 1.0, 'ytick.major.size': 1.0, 'xtick.major.pad': 1.0, 'ytick.major.pad': 1.0 }) with ctx: self.responseFig = plt.figure(frameon=False, layout='constrained') self.responsePlot = self.responseFig.add_subplot(111) self.responseCanvas = FigureCanvas(self.responseFig) self.responseCanvas.draw_idle() self.plot_grid.addWidget(self.responseCanvas, 0, 0) # # # # Image canvas # # # # # # # # (1, 2) self.roi_fig = plt.figure() self.roi_ax = self.roi_fig.add_subplot(111) self.roi_canvas = FigureCanvas(self.roi_fig) self.toolbar = NavigationToolbar(self.roi_canvas, self) self.roi_ax.set_aspect('equal') self.roi_ax.set_axis_off() self.plot_grid.addWidget(self.toolbar, 1, 0) self.plot_grid.addWidget(self.roi_canvas, 2, 0) self.plot_grid.setRowStretch(0, 1) self.plot_grid.setRowStretch(1, 3) self.plot_grid.setRowStretch(2, 3) # Current z slice slider self.zSlider = QSlider(QtCore.Qt.Orientation.Horizontal, self) self.zSlider.setMinimum(0) self.zSlider.setMaximum(50) self.zSlider.setValue(0) self.zSlider.valueChanged.connect(self.zSliderUpdated) self.plot_grid.addWidget(self.zSlider, 3, 0) self.roi_fig.tight_layout() self.setWindowTitle('Visanalysis') self.setGeometry(200, 200, 1200, 600) self.show()