def __init__(self, modules: dict, parent=None): super(CodeGenDialog, self).__init__(parent) self.modules = modules main_layout = QVBoxLayout() imports_group_box = QGroupBox('Imports') imports_group_box.setLayout(QVBoxLayout()) info_text_edit = QPlainTextEdit( '''I found the following imports in the inspected components. Please unselect all imports whose source code you want me to include in the output. All checked modules remain imported using the import statements. Notice that import alias names (import ... as ...) of course won\'t work when including the module\'s source. Same goes for imports using 'from' (indicated in the list below). And for those, the whole (direct) source will be included if you unselect a module.''' ) info_text_edit.setReadOnly(True) imports_group_box.layout().addWidget(info_text_edit) imports_scroll_area = QScrollArea() imports_scroll_area.setLayout(QVBoxLayout()) self.import_widget_assignment = {'imports': {}, 'fromimports': {}} # imports imports_scroll_area.layout().addWidget(QLabel('imports:')) for i in modules['imports'].keys(): import_check_box = QCheckBox(i) import_check_box.setChecked(True) imports_scroll_area.layout().addWidget(import_check_box) self.import_widget_assignment['imports'][import_check_box] = i # from-imports imports_scroll_area.layout().addWidget(QLabel('\'from\'-imports:')) for i in modules['fromimports'].keys(): names = modules['fromimports'][i][2] from_names_list = ', '.join(names) import_check_box = QCheckBox(i + ': ' + from_names_list) import_check_box.setChecked(True) imports_scroll_area.layout().addWidget(import_check_box) self.import_widget_assignment['fromimports'][import_check_box] = i imports_group_box.layout().addWidget(imports_scroll_area) main_layout.addWidget(imports_group_box) button_box = QDialogButtonBox() button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) main_layout.addWidget(button_box) self.setLayout(main_layout) self.resize(500, 500) self.setWindowTitle('Source Code Gen Manager')
class TagsCheckboxWindow(QWidget): def __init__(self, path, owner): QWidget.__init__(self) self.path = path self.scroll_area = QScrollArea() self.num_columns = 3 self.owner = owner # self.checkboxes_widget = QWidget() for paper in Index.gPapers: if paper['path'] == self.path: self.paper = paper self.columns = [] for i in range(self.num_columns): layout = QVBoxLayout() layout.setSpacing(0) layout.setMargin(0) self.columns.append(layout) self.checkboxes = [] self.tags_copy = Index.gTags.copy() self.tags_copy.sort(key=lambda s: s) count = 0 for tag in self.tags_copy: checkbox = QCheckBox(tag) self.checkboxes.append(checkbox) self.columns[int( (self.num_columns * count) / len(self.tags_copy))].addWidget( checkbox) #add the checkbox to the appropriate column if 'tags' in self.paper: if tag in self.paper['tags']: checkbox.setChecked(True) checkbox.clicked.connect(self.checkbox_click_creator(checkbox)) count += 1 # self.checkboxes_widget.setLayout(self.layout) # self.scroll_area.setWidget(self.checkboxes_widget) self.layout = QHBoxLayout() for col in self.columns: self.layout.addLayout(col) self.scroll_area.setLayout(self.layout) self.scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.scroll_area.setWidgetResizable(True) self.full_layout = QHBoxLayout() self.full_layout.addWidget(self.scroll_area) self.setLayout(self.full_layout) def checkbox_click_creator(self, box): @Slot() def checkbox_click(): if box.isChecked() == True: # print('checkbox for', self.path, 'is true') if 'tags' not in self.paper: self.paper['tags'] = [] if box.text() not in self.paper['tags']: self.paper['tags'].append(box.text()) Index.save_json(Index.gJSONfilename) # self.owner.PapersView = Index.gPapers.copy() # self.owner.update() self.owner.copy_sort_update() # for paper in Index.gPapers: # if paper['path'] == self.path: # if 'tags' not in paper: # paper['tags'] = [] # if box.text() not in paper['tags']: # paper['tags'].append(box.text()) # Index.save_json(Index.gJSONfilename) # break else: print('checkbox', box.text(), 'for', self.path, 'is false') if 'tags' not in self.paper: self.paper['tags'] = [] if box.text() in self.paper['tags']: self.paper['tags'].remove(box.text()) Index.save_json(Index.gJSONfilename) # self.owner.PapersView = Index.gPapers.copy() # self.owner.update() self.owner.copy_sort_update() # for paper in Index.gPapers: # if paper['path'] == self.path: # if 'tags' not in paper: # paper['tags'] = [] # if box.text() in paper['tags']: # paper['tags'].remove(box.text()) # Index.save_json(Index.gJSONfilename) # break return checkbox_click
# 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_())