def menuBatchOperation(self, list): itemList = [] #标记本次批量操作所有记录的类别是否一致,如果不一致就不进行右键批量操作 itemTpye = None for modelIndex in list: item = self.treeModel.itemFromIndex(modelIndex) if itemTpye != None: if itemTpye != item.type: return itemTpye = item.type itemList.append(item) menu = QMenu() if itemTpye == ITEM_TYPE_HISTORY: deleteAction = QAction( IconTool.buildQIcon('clear.png'), '&Delete', self, triggered=lambda: self.deleteHistoryBatch(itemList)) deleteAction.setShortcut('Ctrl+D') menu.addAction(deleteAction) if itemTpye == ITEM_TYPE_FAVORITES: deleteAction = QAction( IconTool.buildQIcon('clear.png'), '&Delete', self, triggered=lambda: self.deleteFavoritesBatch(itemList)) deleteAction.setShortcut('Ctrl+D') menu.addAction(deleteAction) menu.exec_(QCursor.pos())
def initUI(self): # 只显示关闭按钮, 不显示最大化, 最小化, 并且固定窗口大小 self.setWindowFlags(Qt.WindowCloseButtonHint) self.setFixedSize(460, 150) self.ipLabel = QLabel(self) self.ipLabel.setPixmap(IconTool.buildQPixmap('ip.png')) self.ipLabel.move(40, 28) self.helpLabel = QLabel(self) self.helpLabel.setPixmap(IconTool.buildQPixmap('help.png')) self.helpLabel.move(380, 28) self.helpLabel.setToolTip('''格式: ip[:adb port][:xul port] default adb port is 5555 default xul port is 55550 EX: 192.168.200.2:5555:55550''') self.ipComboBox = QComboBox(self) self.ipComboBox.move(80, 30) self.ipComboBox.resize(290, 25) self.ipComboBox.setEditable(True) self.ipComboBox.setMaxVisibleItems(5) self.ipComboBox.setInsertPolicy(QComboBox.InsertAtTop) ipListWidget = QListWidget() self.ipComboBox.setView(ipListWidget) self.ipComboBox.setModel(ipListWidget.model()) # self.ipComboBox.addItem('localhost') for pos, device in enumerate(self.getDevicesFromDB()): item = self.ComboBoxItem(pos, device[0]) ipListItem = QListWidgetItem(ipListWidget) ipListWidget.setItemWidget(ipListItem, item) # combobox绘制子项完成,再向子项添加内容 for pos, device in enumerate(self.getDevicesFromDB()): self.ipComboBox.setItemText(pos, device[0]) self.connectButton = QPushButton('connect', self) self.connectButton.setGeometry(150, 90, 120, 25) self.connectButton.clicked.connect(self.onConnectClick) self.detailLabel = QPushButton(self) self.detailLabel.setText('↓detail') self.detailLabel.move(350, 110) self.detailLabel.setFlat(True) self.detailLabel.setStyleSheet("QPushButton{background: transparent;}") self.detailLabel.clicked.connect(self.onDetailClick) self.detailEdit = QTextEdit(self) self.detailEdit.move(25, 150) self.detailEdit.resize(420, 180) self.autoLogin = QCheckBox('自动登录', self) self.autoLogin.move(350, 88) self.autoLogin.clicked.connect(self.changeAutoLoginState) self.initAutoLogin() super().initWindow()
def initMenuBar(self): menuBar = self.menuBar() fileMenu = menuBar.addMenu('File') disConnectAction = QAction(IconTool.buildQIcon('disconnect.png'), '&Disconnect', self) disConnectAction.setShortcut('Ctrl+D') disConnectAction.setShortcutContext(Qt.ApplicationShortcut) disConnectAction.triggered.connect(self.restartProgram) settingAction = QAction(IconTool.buildQIcon('setting.png'), '&Setting...', self) settingAction.setShortcut('Ctrl+Shift+S') settingAction.setShortcutContext(Qt.ApplicationShortcut) settingAction.triggered.connect(lambda: STCLogger().d('setting')) clearCacheAction = QAction(IconTool.buildQIcon('clearCache.png'), '&ClearCache', self) clearCacheAction.setShortcut('Ctrl+Alt+C') clearCacheAction.setShortcutContext(Qt.ApplicationShortcut) clearCacheAction.triggered.connect(self.clearCache) clearSearchHistoryAction = QAction( IconTool.buildQIcon('clearCache.png'), '&ClearSearchHistory', self) clearSearchHistoryAction.triggered.connect(self.clearSearchHistory) settingLogPathAction = QAction(IconTool.buildQIcon('path.png'), '&LogPath', self) settingLogPathAction.triggered.connect(self.setLogPath) fileMenu.addAction(disConnectAction) fileMenu.addAction(clearCacheAction) fileMenu.addAction(settingLogPathAction) fileMenu.addAction(clearSearchHistoryAction) # fileMenu.addAction(settingAction) # fileMenu.addAction(showLogAction) # settingAction.triggered.connect(self.openSettingWindow) editMenu = menuBar.addMenu('Edit') findAction = QAction(IconTool.buildQIcon('find.png'), '&Find', self) findAction.setShortcut('Ctrl+F') findAction.triggered.connect(self.findActionClick) editMenu.addAction(findAction) focusItemAction = QAction(IconTool.buildQIcon('focus.png'), '&Focus Item', self) focusItemAction.triggered.connect(self.focusChooseItem) editMenu.addAction(focusItemAction) self.chooseItemType = '' self.chooseItemId = '' settingMenu = menuBar.addMenu('Setting') autoLoginAction = QAction(IconTool.buildQIcon('setting.png'), '&Auto Login', self) autoLoginAction.setShortcutContext(Qt.ApplicationShortcut) autoLoginAction.triggered.connect(self.setAutoState) settingMenu.addAction(autoLoginAction) helpMenu = menuBar.addMenu('Help') aboutAction = QAction(IconTool.buildQIcon('about.png'), '&About', self) aboutAction.triggered.connect(self.openAboutWindow) helpMenu.addAction(aboutAction)
def initMenuBar(self): menuBar = self.menuBar() fileMenu = menuBar.addMenu('Logcat') showLogAction = QAction('Show Log', self) fileMenu.addAction(showLogAction) helpMenu = menuBar.addMenu('Setting') aboutAction = QAction(IconTool.buildQIcon('setting.png'), 'About', self) helpMenu.addAction(aboutAction)
def initUi(self): self.tabBar = QTabBar() self.consoleView = ConsoleWindow() self.tabBar.tabBarClicked.connect(self.status) self.tabBar.setExpanding(False) self.setTabBar(self.tabBar) self.addTab(self.consoleView,IconTool.buildQIcon('logcat.png'), "Logcat") self.consoleView.setVisible(False) self.setFixedHeight(Utils.getItemHeight()) self.setTabPosition(QTabWidget.South) self.setStyleSheet("QTabBar::tab {border: none; height: "+str(Utils.getItemHeight())+"px; width:100px;color:black;}" "QTabBar::tab:selected { border: none;background: lightgray; } ")
def ComboBoxItem(self, pos, ip_src): qWidget = QWidget() deledeButton = QPushButton() deledeButton.setStyleSheet("background:transparent;") deledeButton.setIcon(QIcon(IconTool.buildQIcon('delete.png'))) deledeButton.clicked.connect( lambda: self.onDeleteComBoxItem(pos, ip_src)) boxLayout = QHBoxLayout() boxLayout.addStretch() boxLayout.addWidget(deledeButton) boxLayout.setContentsMargins(0, 0, 0, 0) boxLayout.setSpacing(5) qWidget.setLayout(boxLayout) return qWidget
def openContextMenu(self, point): index = self.treeView.indexAt(point) if not index.isValid(): return item = self.treeModel.itemFromIndex(index) menu = QMenu() if item.type == ITEM_TYPE_PROVIDER: queryAction = QAction( IconTool.buildQIcon('data.png'), '&Query Data...', self, triggered=lambda: self.showQueryDialog(item.data)) queryAction.setShortcut('Alt+Q') menu.addAction(queryAction) copyAction = QAction( IconTool.buildQIcon('copy.png'), '&Copy', self, triggered=lambda: pyperclip.copy('%s' % index.data())) copyAction.setShortcut(QKeySequence.Copy) menu.addAction(copyAction) menu.exec_(self.treeView.viewport().mapToGlobal(point))
def __init__(self, parent=None): super(ConsoleWindow, self).__init__(parent) self.isConUrl = False # 上 self.searchButton = QLineEdit() self.searchButton.setPlaceholderText("搜索") self.searchButton.setMaximumWidth(300) self.searchButton.setMaximumHeight(32) self.searchButton.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Minimum) self.combo = QComboBox(self) self.combo.insertItem(0, 'Error') self.combo.insertItem(1, 'Debug') self.combo.insertItem(2, 'Verbose') self.combo.insertItem(3, 'Warning') self.combo.setCurrentIndex(0) layout_top = QHBoxLayout() layout_top.setAlignment(Qt.AlignRight) layout_top.setSpacing(20) # layout_top.addWidget(self.combo) # layout_top.addWidget(self.searchButton) self.functionTabWiget = QWidget() self.functionTabWiget.setAutoFillBackground(True) self.functionTabWiget.setFixedHeight(20) self.functionTabWiget.setLayout(layout_top) # 左 self.clearButton = QPushButton(self) icon = QIcon(IconTool.buildQIcon('clear.png')) self.clearButton.setIcon(icon) self.clearButton.setFixedWidth(18) self.clearButton.setFixedHeight(20) self.clearButton.clicked.connect(self.clear) self.clearButton.setToolTip("Clear the logcat") self.setStyleSheet(''' QPushButton{ border: none; background-color: #0000 ; } QPushButton:hover { border: 1px solid #C0C0C0; background-color: yellow; border-style: inset; border-radius:2px; background-color:#C0C0C0; border-style: solid; } ''') self.layoutLeft = QVBoxLayout() self.layoutLeft.setAlignment(Qt.AlignTop) self.layoutLeft.setSpacing(1) self.layoutLeft.addWidget(self.clearButton) self.layoutLeft.setContentsMargins(4, 0, 0, 0) self.leftWiget = QWidget() self.leftWiget.setAutoFillBackground(True) self.leftWiget.setLayout(self.layoutLeft) self.leftWiget.setFixedWidth(22) # 右 self.textEdit = QTextBrowser() self.textEdit.setOpenLinks(True) self.textEdit.setOpenExternalLinks(True) self.textEdit.setReadOnly(True) self.rightWiget = QWidget() self.rightWiget.setAutoFillBackground(True) self.rightWiget.setFixedWidth(15) self.messageSplitter = QSplitter(Qt.Horizontal) self.messageSplitter.addWidget(self.leftWiget) self.messageSplitter.addWidget(self.textEdit) self.messageSplitter.addWidget(self.rightWiget) self.mainSplitter = QSplitter(Qt.Vertical) self.mainSplitter.addWidget(self.functionTabWiget) self.mainSplitter.addWidget(self.messageSplitter) self.setCentralWidget(self.mainSplitter) # 重定向输出 sys.stdout = ConsoleEmittor(textWritten=self.normalOutputWritten) sys.stderr = ConsoleEmittor(textWritten=self.normalOutputWritten)
def menuOperation(self, point): index = self.indexAt(point) if not index.isValid(): return item = self.treeModel.itemFromIndex(index) menu = QMenu() if item.type == ITEM_TYPE_HISTORY: queryAction = QAction(IconTool.buildQIcon('data.png'), '&Edit ...', self, triggered=lambda: self.showQueryDialog(item)) queryAction.setShortcut('Alt+E') menu.addAction(queryAction) favoritesAction = QAction( IconTool.buildQIcon('star.png'), 'Add to &favorites', self, triggered=lambda: self.add2Favorites(item)) favoritesAction.setShortcut('Alt+F') menu.addAction(favoritesAction) deleteAction = QAction(IconTool.buildQIcon('clear.png'), '&Delete', self, triggered=lambda: self.deleteHistory(item)) deleteAction.setShortcut('Ctrl+D') menu.addAction(deleteAction) if item.type == ITEM_TYPE_FAVORITES: queryAction = QAction(IconTool.buildQIcon('data.png'), '&Edit ...', self, triggered=lambda: self.showQueryDialog(item)) queryAction.setShortcut('Alt+E') menu.addAction(queryAction) disFavoritesAction = QAction( IconTool.buildQIcon('remove_favorites.png'), 'Remove from &favorites', self, triggered=lambda: self.remove2Favorites(item)) disFavoritesAction.setShortcut('Alt+F') menu.addAction(disFavoritesAction) deleteAction = QAction(IconTool.buildQIcon('clear.png'), '&Delete', self, triggered=lambda: self.deleteFavorite(item)) deleteAction.setShortcut('Ctrl+D') menu.addAction(deleteAction) if item.type == ITEM_TYPE_URL: copyAction = QAction( IconTool.buildQIcon('copy.png'), 'Copy', self, triggered=lambda: pyperclip.copy('%s' % index.data())) copyAction.setShortcut('Ctrl+C') menu.addAction(copyAction) menu.exec_(self.viewport().mapToGlobal(point))
def initWindow(self): self.setWindowTitle(self.title) self.setWindowIcon(IconTool.buildQIcon('icon.png')) self.resize(500, 300) self.center()
def initSearchView(self): self.settings = QSettings('XulDebugTool') self.searchHistory = self.settings.value('searchHistory', []) self.searchWidget = QWidget() self.searchWidget.setStyleSheet( ".QWidget{border:1px solid rgb(220, 220, 220)}") searchPageLayout = QHBoxLayout() self.searchLineEdit = QLineEdit() self.searchIcon = QAction(self) self.searchIcon.setIcon(IconTool.buildQIcon('find_h.png')) self.searchMenu = QMenu(self) for text in self.searchHistory: self.action = QAction( text, self, triggered=lambda: self.searchLineEdit.setText(text)) self.searchMenu.addAction(self.action) self.searchIcon.setMenu(self.searchMenu) self.searchDelIcon = QAction(self) self.searchDelIcon.setIcon(IconTool.buildQIcon('del.png')) self.searchLineEdit.addAction(self.searchIcon, QLineEdit.LeadingPosition) self.searchLineEdit.addAction(self.searchDelIcon, QLineEdit.TrailingPosition) self.searchDelIcon.setVisible(False) self.searchLineEdit.setStyleSheet( "border:2px groove gray;border-radius:10px;padding:2px 4px") searchPageLayout.addWidget(self.searchLineEdit) self.searchLineEdit.textChanged.connect(self.searchPage) self.searchLineEdit.editingFinished.connect(self.saveSearchHistory) self.searchDelIcon.triggered.connect(self.searchDelClick) self.previousBtn = QPushButton() self.previousBtn.setStyleSheet("background:transparent;") self.previousBtn.setIcon(IconTool.buildQIcon('up.png')) self.previousBtn.setFixedSize(15, 20) searchPageLayout.addWidget(self.previousBtn) self.previousBtn.clicked.connect( lambda: self.previousBtnClick(self.searchLineEdit.text())) self.nextBtn = QPushButton() self.nextBtn.setIcon(IconTool.buildQIcon('down.png')) self.nextBtn.setStyleSheet("background:transparent;") self.nextBtn.setFixedSize(15, 20) self.nextBtn.clicked.connect( lambda: self.nextBtnClick(self.searchLineEdit.text())) searchPageLayout.addWidget(self.nextBtn) self.matchCase = QCheckBox("Match Case") self.matchCase.setChecked(False) self.matchCase.stateChanged.connect(self.matchCaseChange) searchPageLayout.addWidget(self.matchCase) self.matchTips = QLabel() self.matchTips.setFixedWidth(100) self.searchClose = QPushButton("×") self.searchClose.setFixedWidth(10) self.searchClose.setStyleSheet("background:transparent;") self.searchClose.clicked.connect(self.searchCloseClick) searchPageLayout.addWidget(self.matchTips) searchPageLayout.addWidget(self.searchClose) self.searchWidget.setLayout(searchPageLayout) return self.searchWidget
def initLayout(self): # ----------------------------left layout---------------------------- # self.treeModel = QStandardItemModel() self.pageItem = QStandardItem(ROOT_ITEM_PAGE) self.pageItem.type = ITEM_TYPE_PAGE_ROOT self.buildPageItem() self.userobjectItem = QStandardItem(ROOT_ITEM_USER_OBJECT) self.userobjectItem.type = ITEM_TYPE_USER_OBJECT_ROOT self.buildUserObjectItem() self.providerRequestItem = QStandardItem(ROOT_ITEM_PROVIDER_REQUESTS) self.providerRequestItem.type = ITEM_TYPE_PROVIDER_REQUESTS_ROOT self.pluginItem = QStandardItem(ROOT_ITEM_PLUGIN) self.pluginItem.type = ITEM_TYPE_PLUGIN_ROOT self.treeModel.appendColumn([ self.pageItem, self.userobjectItem, self.providerRequestItem, self.pluginItem ]) self.treeModel.setHeaderData(0, Qt.Horizontal, 'Model') self.treeView = QTreeView() self.treeView.setModel(self.treeModel) self.treeView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.treeView.setContextMenuPolicy(Qt.CustomContextMenu) self.treeView.customContextMenuRequested.connect(self.openContextMenu) self.treeView.doubleClicked.connect(self.onTreeItemDoubleClicked) self.treeView.clicked.connect(self.getDebugData) leftContainer = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 6, 0) # left, top, right, bottom layout.addWidget(self.treeView) leftContainer.setLayout(layout) # ----------------------------middle layout---------------------------- # middleContainer = QWidget() # search shall start not before the user completed typing # filter_delay = DelayedExecutionTimer(self) # new_column.search_bar.textEdited[str].connect(filter_delay.trigger) # filter_delay.triggered[str].connect(self.search) self.tabBar = QTabBar() self.tabBar.setUsesScrollButtons(False) self.tabBar.setDrawBase(False) # self.tabBar.addTab('tab1') # self.tabBar.addTab('tab2') self.pathBar = QWidget() layout = QHBoxLayout() layout.setAlignment(Qt.AlignLeft) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(1) self.pathBar.setLayout(layout) self.searchHolder = QWidget() layout = QHBoxLayout() layout.addWidget(self.tabBar) layout.addWidget(self.pathBar) layout.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding)) self.searchHolder.setLayout(layout) self.searchHolder.layout().setContentsMargins(6, 6, 6, 0) self.tabContentWidget = QWidget() self.browser = QWebEngineView() self.browser.setZoomFactor(1.3) self.channel = QWebChannel() self.webObject = WebShareObject() self.channel.registerObject('bridge', self.webObject) self.browser.page().setWebChannel(self.channel) self.webObject.jsCallback.connect(lambda value: self.addUpdate(value)) qwebchannel_js = QFile(':/qtwebchannel/qwebchannel.js') if not qwebchannel_js.open(QIODevice.ReadOnly): raise SystemExit('Failed to load qwebchannel.js with error: %s' % qwebchannel_js.errorString()) qwebchannel_js = bytes(qwebchannel_js.readAll()).decode('utf-8') script = QWebEngineScript() script.setSourceCode(qwebchannel_js) script.setInjectionPoint(QWebEngineScript.DocumentCreation) script.setName('qtwebchannel.js') script.setWorldId(QWebEngineScript.MainWorld) script.setRunsOnSubFrames(True) self.browser.page().scripts().insert(script) Utils.scriptCreator(os.path.join('..', 'resources', 'js', 'event.js'), 'event.js', self.browser.page()) self.browser.page().setWebChannel(self.channel) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.initQCheckBoxUI()) layout.addWidget(self.initSearchView()) layout.addWidget(self.browser) self.tabContentWidget.setLayout(layout) self.searchWidget.hide() middleContainer.stackedWidget = QStackedWidget() self.url = XulDebugServerHelper.HOST + 'list-pages' self.showXulDebugData(self.url) middleContainer.stackedWidget.addWidget(self.tabContentWidget) middleContainer.stackedWidget.addWidget(QLabel('tab2 content')) self.tabBar.currentChanged.connect( lambda: middleContainer.stackedWidget.setCurrentIndex( self.tabBar.currentIndex())) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.searchHolder) layout.addWidget(middleContainer.stackedWidget) middleContainer.setLayout(layout) # ----------------------------right layout---------------------------- # self.rightSiderClickInfo = 'Property' self.rightSiderTabWidget = QTabWidget() self.rightSiderTabBar = QTabBar() self.rightSiderTabWidget.setTabBar(self.rightSiderTabBar) self.rightSiderTabWidget.setTabPosition(QTabWidget.East) self.favoriteTreeView = FavoriteTreeView(self) # self.propertyEditor = PropertyEditor(['Key', 'Value']) self.inputWidget = UpdateProperty() self.rightSiderTabWidget.addTab(self.inputWidget, IconTool.buildQIcon('property.png'), 'Property') self.rightSiderTabWidget.setStyleSheet( ('QTab::tab{height:60px;width:32px;color:black;padding:0px}' 'QTabBar::tab:selected{background:lightgray}')) # self.rightSiderTabWidget.addTab(self.propertyEditor,IconTool.buildQIcon('property.png'),'property') self.rightSiderTabWidget.addTab(self.favoriteTreeView, IconTool.buildQIcon('favorites.png'), 'Favorites') self.rightSiderTabBar.tabBarClicked.connect(self.rightSiderClick) # ----------------------------entire layout---------------------------- # self.contentSplitter = QSplitter(Qt.Horizontal) self.contentSplitter.setHandleWidth(0) # thing to grab the splitter self.contentSplitter.addWidget(leftContainer) self.contentSplitter.addWidget(middleContainer) self.contentSplitter.addWidget(self.rightSiderTabWidget) self.contentSplitter.setStretchFactor(0, 0) self.contentSplitter.setStretchFactor(1, 6) self.contentSplitter.setStretchFactor(2, 6) self.mainSplitter = QSplitter(Qt.Vertical) self.mainSplitter.setHandleWidth(0) self.mainSplitter.addWidget(self.contentSplitter) self.mainSplitter.addWidget(self.consoleWindow) self.mainSplitter.setStretchFactor(1, 0) self.mainSplitter.setStretchFactor(2, 1) self.setCentralWidget(self.mainSplitter) # 默认隐藏掉复选框 self.groupBox.setHidden(True)