def load_known():
    #global afp_dir, afp, bfp_dir, bfp
    current_dir = os.path.abspath(__file__).replace('\\', '/')
    current_dir = get_folder_from_file(current_dir)

    afp_folder = current_dir + 'support_files/afp/'
    bfp_folder = current_dir + 'support_files/bfp/'

    afp_dir = os.listdir(afp_folder)
    bfp_dir = os.listdir(bfp_folder)

    afp = []
    for file in afp_dir:
        img_temp = cv2.imread(afp_folder + file)
        afp.append(img_temp)
        #print(file)

    bfp = []
    for file in bfp_dir:
        img_temp = cv2.imread(bfp_folder + file)
        bfp.append(img_temp)
    return afp_dir, afp, bfp_dir, bfp
    def initUI(self):

        self.current_dir = os.path.abspath(__file__).replace('\\', '/')
        self.current_dir = get_folder_from_file(self.current_dir)
        self.current_dir += 'support_files/'

        #self.afp_dir, self.afp, self.bfp_dir, self.bfp = load_known()
        print(self.current_dir)
        self.get_hwnd()
        self.scan_speed = 1
        self.total_range = 20

        self.font = cv2.FONT_HERSHEY_SIMPLEX

        self.mouse_pos_initial()

        self.canvas_blank = np.zeros((512, 512), dtype=np.int8)

        exitAct = QAction(QIcon(self.current_dir + 'quit.png'), '&Quit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)

        help_contact = QAction(QIcon(self.current_dir + 'email.png'),
                               'Contact', self)
        help_contact.triggered.connect(self.contact)

        help_about = QAction('About', self)
        help_about.triggered.connect(self.about)

        self.menubar = self.menuBar()

        FileMenu = self.menubar.addMenu('&File')
        FileMenu.addAction(exitAct)

        HelpMenu = self.menubar.addMenu('&Help')
        HelpMenu.addAction(help_contact)
        HelpMenu.addAction(help_about)

        self.read_button = QToolButton()
        self.read_button.setIcon(QIcon(self.current_dir + 'read.png'))
        self.read_button.setToolTip('Read Ctrl+R')
        self.read_button.clicked.connect(self.read)
        self.read_button.setShortcut('Ctrl+R')

        self.select_button = QToolButton()
        self.select_button.setIcon(QIcon(self.current_dir + 'select.png'))
        self.select_button.setToolTip('Select')
        self.select_button.clicked.connect(self.select_move_shape)
        self.select_button.setCheckable(True)
        self.select = False
        self.selecting = False
        self.select_rec = Rectangle()
        self.cursor_on_select = False
        self.moving = False
        self.move_start = [0, 0]
        self.move_end = [0, 0]

        self.drag_button = QToolButton()
        self.drag_button.setIcon(QIcon(self.current_dir + 'drag.png'))
        self.drag_button.setToolTip('Move')
        self.drag_button.clicked.connect(self.drag_shape)

        self.draw_shape_action_list = []
        self.draw_shape_list = []
        self.draw_shape_action_list_for_redo = []
        self.draw_shape_count = 1

        self.line_button = QToolButton()
        self.line_button.setIcon(QIcon(self.current_dir + 'line.png'))
        self.line_button.setToolTip('Draw line')
        self.line_button.clicked.connect(self.draw_line)
        self.line_button.setCheckable(True)
        self.draw_shape_line = False
        self.drawing_shape_line = False
        self.show_distance = False

        self.grating_button = QToolButton()
        self.grating_button.setIcon(QIcon(self.current_dir + 'grating.png'))
        self.grating_button.setToolTip('Grating')
        self.grating_button.clicked.connect(self.draw_grating)

        #        line = Line(0,0,100,100)

        self.eraser_button = QToolButton()
        self.eraser_button.setIcon(QIcon(self.current_dir + 'eraser.png'))
        self.eraser_button.setToolTip('eraser')
        self.eraser_button.clicked.connect(self.erase_shape)
        self.eraser_button.setCheckable(True)
        self.erase = False
        self.drawing_eraser = False

        self.undo_button = QToolButton()
        self.undo_button.setIcon(
            QIcon(self.current_dir + 'undo_gray_opacity.png'))
        self.undo_button.setToolTip('undo  Ctrl+Z')
        self.undo_button.clicked.connect(self.undo_draw)
        self.undo_button.setShortcut('Ctrl+Z')

        self.redo_button = QToolButton()
        self.redo_button.setIcon(
            QIcon(self.current_dir + 'redo_gray_opacity.png'))
        self.redo_button.setToolTip('redo  Ctrl+Y')
        self.redo_button.clicked.connect(self.redo_draw)
        self.redo_button.setShortcut('Ctrl+Y')

        self.clear_button = QToolButton()
        self.clear_button.setIcon(QIcon(self.current_dir + 'clear.png'))
        self.clear_button.setToolTip('clear drawing')
        self.clear_button.clicked.connect(self.clear_draw)

        self.run_button = QToolButton()
        self.run_button.setIcon(QIcon(self.current_dir + 'run.png'))
        self.run_button.setToolTip('Run F5')
        self.run_button.clicked.connect(self.run_cut)
        self.run_button.setShortcut('F5')

        self.repeat_button = QToolButton()
        self.repeat_button.setIcon(QIcon(self.current_dir + 'repeat.png'))
        self.repeat_button.setToolTip('Repeat')
        self.repeat_button.clicked.connect(self.repeat_cut)

        self.stop_button = QToolButton()
        self.stop_button.setIcon(QIcon(self.current_dir + 'stop.png'))
        self.stop_button.setToolTip('Stop')
        self.stop_button.clicked.connect(self.stop_cut)

        self.toolbar1 = self.addToolBar('Read')
        self.toolbar1.addWidget(self.read_button)

        self.toolbar2 = self.addToolBar('Select')
        self.toolbar2.addWidget(self.select_button)
        self.toolbar2.addWidget(self.drag_button)

        self.toolbar3 = self.addToolBar('Draw')
        self.toolbar3.addWidget(self.line_button)
        self.toolbar3.addWidget(self.grating_button)
        self.toolbar3.addWidget(self.undo_button)
        self.toolbar3.addWidget(self.redo_button)
        self.toolbar3.addWidget(self.eraser_button)
        self.toolbar3.addWidget(self.clear_button)

        self.toolbar4 = self.addToolBar('Run')
        self.toolbar4.addWidget(self.run_button)
        self.toolbar4.addWidget(self.repeat_button)
        self.toolbar4.addWidget(self.stop_button)

        self.toolbar = self.addToolBar(' ')

        self.pixmap = QPixmap()
        self.lbl_main = QLabel(self)
        self.lbl_main.setAlignment(Qt.AlignTop)
        #        self.lbl_main.setAlignment(Qt.AlignCenter)
        self.lbl_main.setPixmap(self.pixmap)
        self.lbl_main.setMouseTracking(True)

        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.lbl_main)

        self.central_widget = QWidget()
        self.central_widget.setMouseTracking(True)

        self.layout = QVBoxLayout(self.central_widget)
        self.setCentralWidget(self.central_widget)
        self.layout.addLayout(self.vbox)

        self.refresh_timer = QTimer()
        self.refresh_timer.timeout.connect(self.refresh_show)

        self.setMouseTracking(True)
        self.setWindowTitle('Auto Cut')
        self.show()
        points = [[x1, y1]]
        x_start, y_start = x1, y1
        for i in range(len(x_temp)):
            if self.get_distance(x_temp[i], y_temp[i], x_start, y_start) > 2:
                points.append([x_temp[i], y_temp[i]])
                x_start, y_start = x_temp[i], y_temp[i]
        if points[-1][0] != x2 or points[-1][1] != y2:
            points.append([x2, y2])
        return points

    def wait_cut(self):
        pass

    def repeat_cut(self):
        print('repeat cut')

if __name__ == '__main__':
    #os.environ["CUDA_VISIBLE_DEVICES"] = "1"
    app = QApplication(sys.argv)

    splash_path = os.path.abspath(__file__).replace('\\', '/')
    splash_path = get_folder_from_file(splash_path)
    splash = QSplashScreen(QPixmap(splash_path + 'support_files/drawing.jpg'))

    splash.show()
    splash.showMessage('Loading……')

    window = MainWindow()
    splash.close()
    sys.exit(app.exec_())
Beispiel #4
0
    def initUI(self):

        self.current_dir = os.path.abspath(__file__).replace('\\', '/')
        self.current_dir = get_folder_from_file(self.current_dir)
        self.current_dir += 'support_files/'

        self.blanck = cv2.imread(self.current_dir + 'blanck.jpg')
        self.blanck_simu = cv2.imread(self.current_dir + 'blanck_simu.jpg')
        self.img = self.blanck
        print(self.current_dir)
        #        self.font = cv2.FONT_HERSHEY_SIMPLEX

        self.time_start = 0
        self.time_usage = 50

        self.canvas_blank = np.zeros((512, 512), dtype=np.int8)

        openAct = QAction(QIcon(self.current_dir + 'open.png'), '&Open', self)
        openAct.setShortcut('Ctrl+F')
        openAct.triggered.connect(self.open_file)

        exitAct = QAction(QIcon(self.current_dir + 'quit.png'), '&Quit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)

        help_contact = QAction(QIcon(self.current_dir + 'email.png'),
                               'Contact', self)
        help_contact.triggered.connect(self.contact)

        help_about = QAction('About', self)
        help_about.triggered.connect(self.about)

        self.menubar = self.menuBar()

        FileMenu = self.menubar.addMenu('&File')
        FileMenu.addAction(openAct)
        FileMenu.addAction(exitAct)

        HelpMenu = self.menubar.addMenu('&Help')
        HelpMenu.addAction(help_contact)
        HelpMenu.addAction(help_about)

        self.open_button = QToolButton()
        self.open_button.setIcon(QIcon(self.current_dir + 'galery.png'))
        self.open_button.setToolTip('Open File Ctr+F')
        self.open_button.clicked.connect(self.open_file)
        self.open_button.setShortcut('Ctr+F')

        self.run_button = QToolButton()
        self.run_button.setIcon(QIcon(self.current_dir + 'run.png'))
        self.run_button.setToolTip('Run F5')
        #        self.run_button.clicked.connect(self.run_cut)
        self.run_button.setShortcut('F5')

        self.toolbar1 = self.addToolBar('Read')
        self.toolbar1.addWidget(self.open_button)

        self.pixmap = QPixmap()
        self.lbl_main = Label('', self)
        self.lbl_main.new_img.connect(self.refresh_img)
        #        self.lbl_main.setAlignment(Qt.AlignTop)

        #        self.lbl_main.setAlignment(Qt.AlignCenter)
        self.lbl_main.setPixmap(self.pixmap)

        self.img_qi = QImage(self.blanck[:], self.blanck.shape[1], self.blanck.shape[0],\
                          self.blanck.shape[1] * 3, QImage.Format_RGB888)
        self.pixmap = QPixmap(self.img_qi)
        self.lbl_main.setPixmap(self.pixmap)


        img_qi = QImage(self.blanck_simu[:], self.blanck_simu.shape[1], self.blanck_simu.shape[0],\
                          self.blanck_simu.shape[1] * 3, QImage.Format_RGB888)
        pixmap = QPixmap(img_qi)
        self.lbl_simu = QLabel(self)
        self.lbl_simu.setPixmap(pixmap)

        self.lbl_L1 = QLabel('L_1', self)
        self.text_L1 = QLineEdit('1', self)
        self.lbl_L1_ly = QLabel('light year(s)', self)

        self.lbl_L2 = QLabel('L_2', self)
        self.text_L2 = QLineEdit('1', self)
        self.lbl_L2_ly = QLabel('light year(s)', self)

        self.lbl_mass = QLabel('M', self)
        self.text_mass = QLineEdit('1e11', self)
        self.lbl_msun = QLabel('M_sun', self)

        self.lbl_height = QLabel('height', self)
        self.text_height = QLineEdit('1', self)
        self.lbl_height_ly = QLabel('light year(s)', self)

        self.start_button = QPushButton('Start Simulation', self)
        self.start_button.clicked.connect(self.start_simulation)

        self.pbar = QProgressBar(self)
        self.step = 0
        self.progress_timer = QTimer()
        self.progress_timer.timeout.connect(self.step_pbar)

        #        self.stop_button = QPushButton('Stop', self)
        #        self.stop_button.clicked.connect(self.stop_simulation)

        self.panel = QGridLayout()
        self.panel.addWidget(self.lbl_L1, 0, 0)
        self.panel.addWidget(self.text_L1, 0, 1)
        self.panel.addWidget(self.lbl_L1_ly, 0, 2)
        self.panel.addWidget(self.lbl_L2, 1, 0)
        self.panel.addWidget(self.text_L2, 1, 1)
        self.panel.addWidget(self.lbl_L2_ly, 1, 2)
        self.panel.addWidget(self.lbl_mass, 2, 0)
        self.panel.addWidget(self.text_mass, 2, 1)
        self.panel.addWidget(self.lbl_msun, 2, 2)
        self.panel.addWidget(self.lbl_height, 3, 0)
        self.panel.addWidget(self.text_height, 3, 1)
        self.panel.addWidget(self.lbl_height_ly, 3, 2)
        self.panel.addWidget(self.start_button, 4, 1)
        self.panel.addWidget(self.pbar, 5, 1)

        self.vbox = QVBoxLayout()
        self.vbox.addStretch(0)
        self.vbox.addLayout(self.panel)
        self.vbox.addStretch(0)

        self.hbox = QHBoxLayout()
        self.hbox.addWidget(self.lbl_main)
        self.hbox.addWidget(self.lbl_simu)
        self.hbox.addLayout(self.vbox, Qt.AlignRight)

        self.central_widget = QWidget()
        self.central_widget.setMouseTracking(True)

        self.layout = QVBoxLayout(self.central_widget)
        self.setCentralWidget(self.central_widget)
        self.layout.addLayout(self.hbox)

        desktop = QDesktopWidget()
        self.screen_width = desktop.screenGeometry().width()
        self.screen_height = desktop.screenGeometry().height()
        self.img_width = int((self.screen_width - 500) / 2)
        self.img_height = int(self.screen_height - 100)
        print(self.screen_height, self.screen_width)

        self.setWindowIcon(QIcon(self.current_dir + 'lensing.png'))
        self.setWindowTitle('Gravitational Lens Simulation')
        self.show()