Exemplo n.º 1
0
    def take_photo(self):
        import photo

        self._photo_ready.wait()

        with self._photo_lock:
            return photo.Photo(self._photo_latest)
Exemplo n.º 2
0
    def load_photo(self):
        self.canvas.delete("text")

        if self.canvas.find_withtag("photo"):
            self.canvas.delete("photo")

        try:
            image_path = filedialog.askopenfilename(title="Select photo of a receipt",
                                                    filetypes=(("jpeg files", "*.jpg"),
                                                               ("png files", "*.png"),
                                                               ("all files", "*.*")))
            self.image = photo.Photo(image_path)
            self.set_canvas_photo()
            self.canvas.focus_set()
            self.controller.pass_photo_to("DatabaseEntryForm", self.image)
        except OSError: # if user chose a file which is not an image
            self.canvas.delete("photo")
            self.canvas.create_text(400, 300, tag="text",
                                    text="File is not an image")
        except AttributeError: # if nothing was chosen
            if not self.canvas.find_withtag("photo"):
                self.canvas.create_text(400, 300, tag="text",
                                        text="File not chosen")

        self.canvas.configure(scrollregion=self.canvas.bbox("all"))
Exemplo n.º 3
0
    def openMedia(self):
        #if hasattr(self, "player"):#Удаляет медиаплеер
        #self.player.deleteLater()
        #del self.player

        if hasattr(self, "hbox"):  #Удаляет отрисовку
            self.hbox.deleteLater()
            del self.hbox

        self.pathSourceObject = self.path[:self.path.rfind(".")]
        self.fileType = self.path[self.path.rfind(".") + 1:]
        if self.fileType in {"png", "jpg", "JPG"}:
            self.mediaObject = photo.Photo(self.path)
            self.mediaQt.MediaStackedWidget.setCurrentIndex(1)
            self.mediaQt.editPanelStacked.setCurrentIndex(3)
            self.mediaQt.controlPanelStacked.setCurrentIndex(2)
            self.startMedia()
        if self.fileType in {"mp4"}:
            self.mediaObject = video.Video(self.path)
            self.mediaQt.MediaStackedWidget.setCurrentIndex(0)
            self.mediaQt.editPanelStacked.setCurrentIndex(0)
            self.mediaQt.controlPanelStacked.setCurrentIndex(0)

            self.startMedia()
        elif self.fileType in {"mp3"}:
            self.mediaObject = audio.Audio(self.path)
            self.mediaQt.MediaStackedWidget.setCurrentIndex(2)
            self.mediaQt.editPanelStacked.setCurrentIndex(1)
            self.mediaQt.controlPanelStacked.setCurrentIndex(0)
            self.startMedia()
    def _prep_photo(self):
        import photo

        with open("test_data/sample1.jpg", "rb") as fp:
            s = fp.read()

        return photo.Photo(s)
Exemplo n.º 5
0
    def build_for(filename):

        file_type = MediaFile.guess_file_type(filename)
        if file_type is 'photo':
            import photo  # delayed import to avoid circular dependencies
            return photo.Photo(filename)
        else:
            return MediaFile(filename)
Exemplo n.º 6
0
    def test_photo(self):
        import photo
        import tempfile
        import os

        s = self._prep_photo()
        p = photo.Photo(s)
        p.save(tempfile.gettempdir())
        img_path = os.path.join(tempfile.gettempdir(), p.name)
        thm_path = os.path.join(tempfile.gettempdir(), p.thumbnail)
        self.assertTrue(os.path.isfile(img_path))
        self.assertTrue(os.path.isfile(thm_path))
        os.unlink(img_path)
        os.unlink(thm_path)

        p.get_base64_contents()
        p.get_contents()
Exemplo n.º 7
0
# Initialize the check in system
_check_in = check_in.CheckIn(screen)

def handle_keyboard(key):
    global _check_in
    if key == pygame.K_ESCAPE:
        sys.exit()
    if key == pygame.K_c:
        _check_in.check_in("0011")

# Intialize photos list
photos = []
for i in range(18):
    if i == 2:
        _photo = photo.Photo(image_width, image_height, True)
    else:
        _photo = photo.Photo(image_width, image_height)
    photos.append(_photo)

# Layout the photos on the screen
i = 0
for y in range(3):
    for x in range(5):
        photos[i].transform(x,y)
        i += 1

# The main system loop
while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
Exemplo n.º 8
0
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.rowconfigure(7, weight=1)
        
        self.controller = controller
        self.photo = photo.Photo("")

        row_index = 0
        self.saved = False

        # create a space for messages for the user
        self.message = tk.Label(self)
        self.message.grid(row=row_index, column=0, columnspan=4)

        row_index += 1

        # display the recognized amount
        self.amount = ""
        self.amount_label = tk.Label(self, text="Amount: "+ self.amount)
        self.amount_label.grid(row=row_index, column=0, columnspan=2)

        # instruct the user how to enter tags
        self.tags_disclaimer = tk.Label(self, text="ENTER TAGS SEPARATED WITH A COMA AND SPACE",
                                        fg="blue")
        self.tags_disclaimer.grid(row=row_index, column=2, columnspan=2)

        row_index += 1

        # create a field to enter the year value and a validation function for it
        self.year_label = tk.Label(self, text="Year:")
        year_vcmd = (self.register(self.validate_year))
        self.year_field = tk.Entry(self, validate="all", validatecommand=(year_vcmd, "%P"),
                                   exportselection=False)
        self.year_field.insert("end", "2019")

        self.year_label.grid(row=row_index, column=0)
        self.year_field.grid(row=row_index, column=1)

        # display available tags
        self.current_tags_label = tk.Label(self, text="Current tags: ")
        self.current_tags_listed = tk.Label(self, text=self.controller.database.get_tags(),
                                            justify="left")

        self.current_tags_label.grid(row=row_index, column=2)
        self.current_tags_listed.grid(row=row_index, column=3, rowspan=2, sticky="n")
        self.current_tags_listed["wraplength"] = 500 - self.current_tags_listed.winfo_rootx()

        row_index += 1

        # create a field to chose the month
        self.month_label = tk.Label(self, text="Month:")
        self.month_field = tk.Listbox(self, height=12, selectbackground="light blue")
        for month in ("January", "February", "March", "April", "May", "June",
                      "July", "August", "September", "October", "November",
                      "December"):
            self.month_field.insert("end", month)
        self.month_field.selection_set(0)

        self.month_label.grid(row=row_index, column=0)
        self.month_field.grid(row=row_index, column=1)

        row_index += 1

        # create a field to enter the day value and a validation function for it
        self.day_label = tk.Label(self, text="Day:")
        day_vcmd = (self.register(self.validate_day))
        self.day_field = tk.Entry(self, validate="all", validatecommand=(day_vcmd, "%P"),
                                  exportselection=False)
        self.day_field.insert("end", "1")

        self.day_label.grid(row=row_index, column=0)
        self.day_field.grid(row=row_index, column=1)

        # create a field for tags
        self.tags_entry_label = tk.Label(self, text="Tags:")
        self.tags_field = tk.Entry(self, exportselection=False)

        self.tags_entry_label.grid(row=row_index, column=2)
        self.tags_field.grid(row=row_index, column=3)

        row_index += 1

        # create buttons
        self.add_button = tk.Button(self, text="Add receipt to database",
                                    command=self.add_receipt)
        self.add_button.grid(row=row_index, columnspan=5, sticky="ew")

        row_index += 1

        self.load_photo_button = tk.Button(self, text="Load another photo",
                                           command=self.load_photo)
        self.load_photo_button.grid(row=row_index, columnspan=5, sticky="ew")

        row_index += 1

        # display the photo of receipt under the form
        self.photo_frame = tk.Frame(self)
        self.photo_frame.grid(row=row_index, columnspan=4, sticky="nsew")

        row_index += 1

        self.canvas = tk.Canvas(self.photo_frame, width=800)

        canvas_img = ImageTk.PhotoImage(self.photo.get_PIL())
        self.canvas.create_image(0, 0, anchor="nw", tag="photo",
                                 image=canvas_img)
        self.canvas.image = canvas_img
        
        self.create_scrollbars()

        self.canvas.configure(scrollregion=self.canvas.bbox("photo"))