예제 #1
0
 def open_cartel_fix(self):
     """
     Open a CartelFix overlay with the data given by the widgets.
     Also determines the correct icons to use and calculates the
     correct position for the CartelFix.
     """
     # If a CartelFix is running, then the CartelFix should be closed, as this callback also provides
     # functionality for closing an open CartelFix
     if self.cartelfix:
         self.cartelfix.listener.stop()
         self.cartelfix.listener.join()
         self.cartelfix.destroy()
         self.cartelfix_button.config(text="Open CartelFix")
         self.cartelfix = None
         return
     # Perform checks to determine if the options entered are valid
     options = ["Slug Railgun", "Ion Railgun", "Plasma Railgun"]
     first = self.cartelfix_first.get()
     second = self.cartelfix_second.get()
     faction = self.cartelfix_faction.get()
     if first == second:
         mb.showerror("Error", "Please choose two different railguns, not two the same railguns.")
         return
     if first not in options or second not in options:
         mb.showerror("Error", "Please select the railguns")
         raise ValueError("Error", "Unkown railgun found: {0}, {1}".format(first, second))
     # Determine the icons for the Railguns
     gui_profile = GSFInterface(self.cartelfix_gui_profile.get() + ".xml")
     first = open_icon_pil(CartelFix.generate_icon_path(faction, first))
     second = open_icon_pil(CartelFix.generate_icon_path(faction, second))
     # Scale the images
     scale = gui_profile.get_element_scale(gui_profile.get_element_object("FreeFlightShipAmmo"))
     size = (int(round(45.0 * scale, 0)), int(round(45.0 * scale, 0)))
     first = PhotoImage(first.resize(size, Image.ANTIALIAS))
     second = PhotoImage(second.resize(size, Image.ANTIALIAS))
     # Determine coordinates
     x, y = gui_profile.get_secondary_icon_coordinates()
     # Open CartelFix
     self.cartelfix = CartelFix(variables.main_window, first, second, (x, y))
     self.cartelfix_button.config(text="Close CartelFix")
     self.cartelfix.start_listener()
예제 #2
0
파일: main.py 프로젝트: TeeKay18/WWTBAM
def resize_image(image: ImageTk.PhotoImage, width: int,
                 height: int) -> ImageTk.PhotoImage:
    image = image.resize((width, height), Image.ANTIALIAS)
    return ImageTk.PhotoImage(image)
예제 #3
0
class Application(Frame):
    def __init__(self, root):
        # Initial variables
        self.root = root
        self.image = None
        self.file_name = None
        self.id_reader = IdCardReader()
        self.default_background_image = 'assets/background_400x400.png'

        Frame.__init__(self, self.root, background='white')

        self.frame_left = Frame(self)
        self.frame_left.rowconfigure(1, pad=15)
        self.frame_left.grid(row=0, column=0, sticky=(N, W, E, S))

        self.canvas = Canvas(self.frame_left,
                             highlightthickness=1,
                             highlightbackground='#ccc')
        self.canvas.bind("<ButtonRelease-1>", self.open_image)
        self.canvas.config(width=400, height=400)
        self.canvas.grid(row=0, column=0, padx=(10, 0), pady=10)

        self.image = PILImage.open(self.default_background_image)
        self.image = self.image.resize((400, 400), PILImage.ANTIALIAS)
        self.image = PILPhotoImage(self.image)
        self.canvas.create_image(1, 1, image=self.image, anchor=NW)

        self.frame_right = Frame(self, padx=10, pady=10)
        self.frame_right.rowconfigure(1, pad=15)
        self.frame_right.grid(row=0, column=1, sticky=(N, W, E, S))

        self.lbl1 = Label(self.frame_right, text='Số:')
        self.lbl1.grid(row=0, column=0, sticky=W)

        self.id_number = StringVar()
        self.lbl_id_number = Label(self.frame_right,
                                   textvariable=self.id_number,
                                   font='Helvetica 18 bold')
        self.lbl_id_number.grid(row=0, column=0, padx=(20, 0))

        self.btn_analysis = Button(self.frame_right,
                                   text='Phân tích',
                                   width=20,
                                   command=self.analysis)
        self.btn_analysis.grid(row=1, column=0)

        self.btn_reset = Button(self.frame_right,
                                text='Làm mới',
                                width=20,
                                command=self.reset)
        self.btn_reset.grid(row=2, column=0)

        self.btn_quit = Button(self.frame_right,
                               text='Thoát',
                               width=20,
                               command=self.quit)
        self.btn_quit.grid(row=3, column=0)

        self.pack(fill=BOTH, expand=1)
        self.root.title('Trích xuất thông tin Căn cước công dân')
        self.root.mainloop()

    def open_image(self, event):
        file_name = filedialog.askopenfilename(
            title='Chọn file ảnh',
            filetypes=(('jpeg files', '*.jpg'), ('png files', '*.png'),
                       ('tif files', '*.tif')))

        if file_name:
            self.file_name = file_name
            self.image = PILImage.open(file_name)
            self.image = self.image.resize((400, 400), PILImage.ANTIALIAS)
            self.image = PILPhotoImage(self.image)
            self.canvas.create_image(1, 1, image=self.image, anchor=NW)
            self.id_number.set('')

    def analysis(self):
        if self.file_name:
            id_number = self.id_reader.extract_id_number(self.file_name)
            if id_number != '':
                self.lbl_id_number.configure(fg='green')
                self.id_number.set(id_number)
            else:
                self.lbl_id_number.configure(fg='red')
                self.id_number.set('Không tìm thấy')
        else:
            messagebox.showinfo('Cảnh báo', 'Bạn chưa chọn ảnh.')

    def reset(self):
        self.image = PILImage.open(self.default_background_image)
        self.image = self.image.resize((400, 400), PILImage.ANTIALIAS)
        self.image = PILPhotoImage(self.image)
        self.canvas.create_image(1, 1, image=self.image, anchor=NW)
        self.file_name = None
        self.id_number.set('')