class RetroBox(QWidget): submit_signal = Signal(dict) def __init__(self, label, *args, **kwargs): super(RetroBox, self).__init__(*args, **kwargs) self.setContentsMargins(QtCore.QMargins(0, 0, 0, 0)) self.layout = QVBoxLayout() #|------------------------------| #| [Label Text] [Add-Button] | #| |--------------------------| | #| ||------------------------|| | #| || [Retro Tile] || | #| ||------------------------|| | #| | | | #| | | | #| |--------------------------| | #|------------------------------| # Header has Label and Add Button # self.header = QHBoxLayout() self.label = QLabel(label) self.add_button = QPushButton("+") self.add_button.setEnabled(False) # End Header # # Scroll Area # self.tile_list = TileList() self.scroll_area = QScrollArea(self) self.scroll_area.setFixedSize(500, 200) self.scroll_area.setWidget(self.tile_list) self.scroll_area.setWidgetResizable(True) # Tile Panel # self.tile_panel = QVBoxLayout() self.retro_tiles_list = list() # End Tile Panel components # self._setup() def _setup(self): self.add_button.clicked.connect(self.accept_input) self.add_button.setFixedSize(50, 50) self.header.addWidget(self.label) self.header.addWidget(self.add_button) self.layout.addLayout(self.header) self.layout.addWidget(self.scroll_area) self.setLayout(self.layout) def init_update(self, data): print("Just joined? Let's set up all the data we know about") pass def update(self, data): self.retro_tiles_list = data for tile in self.retro_tiles_list: self.tile_list.addWidget(tile, self.update_signal) def setEnabled(self, enabled): self.add_button.setEnabled(enabled) def update_signal(self, payload): if len(payload["user_response"]) == 0: # No update, maybe delete? return payload.update({ "event": "update_submission", "category": self.label.text() }) self.submit_signal.emit(payload) def accept_input(self): text, ok = QInputDialog().getMultiLineText(self, self.label.text(), self.label.text()) if len(text) == 0 or not ok: return payload = { "event": "submission", "category": self.label.text(), "user_response": text } self.submit_signal.emit(payload)
class MainWindow(QMainWindow): def __init__(self, app): super(MainWindow, self).__init__() self.app = app self.central_widget_setup() self.default_vbox_setup() self.layout.addWidget(PrimaryMonitorSelect(self)) self.add_application_button_setup() self.application_boxes_setup() self.application_grid_setup() self.application_scroll_setup() self.window_setup() def window_setup(self): self.adjustSize() self.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, self.size(), QGuiApplication.primaryScreen().availableGeometry(), )) self.setWindowTitle("Saharah Paper") self.setWindowIcon(QIcon(f"{sys.argv[0]}/assets/app_icon.png")) def central_widget_setup(self): self.centralWidget = QWidget() self.setCentralWidget(self.centralWidget) self.layout = QVBoxLayout() self.layout.setAlignment(Qt.AlignCenter | Qt.AlignTop) self.centralWidget.setLayout(self.layout) def default_vbox_setup(self): self.defaultVBox = QHBoxLayout() self.defaultVBox.addWidget(WallpaperBox(self, 0, True)) self.defaultVBox.addWidget(WallpaperBox(self, 1, True)) self.layout.addLayout(self.defaultVBox) def add_application_button_setup(self): self.addApplicationButton = AddApplicationButton(self) self.layout.addWidget(self.addApplicationButton, alignment=Qt.AlignCenter) def application_boxes_setup(self): self.applicationBoxes = list() for i in range(0, len(applicationSettings.list)): self.applicationBoxes.append(WallpaperBox(self, i)) def application_grid_setup(self): self.applicationGrid = QVBoxLayout() self.applicationGridContainer = QWidget() self.applicationGridContainer.setLayout(self.applicationGrid) self.applicationGridContainer.setFixedWidth(1340) self.application_grid_arrange() def application_grid_arrange(self): for i in reversed(range(0, self.applicationGrid.count())): layout = self.applicationGrid.itemAt(i).layout() for j in reversed(range(0, layout.count())): widget = layout.itemAt(j).widget() widget.hide() for i in range(0, len(self.applicationBoxes)): r = math.floor((i) / 4) item = self.applicationGrid.itemAt(r) if item is None: layout = QHBoxLayout() layout.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.applicationGrid.addLayout(layout) else: layout = item.layout() applicationBox = self.applicationBoxes[i] applicationBox.set_index(i) applicationBox.show() layout.addWidget(applicationBox) self.applicationGridContainer.setFixedHeight( self.applicationGrid.count() * 250) def application_scroll_setup(self): self.applicationScroll = QScrollArea() self.applicationScroll.setWidget(self.applicationGridContainer) self.applicationScroll.setFixedSize(1370, 510) self.layout.addWidget(self.applicationScroll) def closeEvent(self, event): self.app.mainWindow.hide() event.accept()
# self.chrome_driver.close() # self.chrome_driver.quit() return self.data_list if __name__ == '__main__': config = ConfigFactory(config_file='py_metasploit.ini').get_config() logger = LoggerFactory(config_factory=config).get_logger() ossim = OssimWeb(config=config, logger=logger) result = ossim.get_data() app = QApplication(sys.argv) mainWindow = QMainWindow() mainWindow.setWindowTitle('软件机器人抓取数据') mainWindow.resize(320, 240) labal = QLabel(str(result)) labal.setWordWrap(True) scroll_label = QScrollArea() scroll_label.setFixedSize(300, 200) layout = QVBoxLayout() layout.addWidget(labal) scroll_label.setLayout(layout) mainWindow.setCentralWidget(scroll_label) mainWindow.show() sys.exit(app.exec_())