Пример #1
0
def list_options(youtubeLink):
    global YTLINK
    YTLINK = youtubeLink.get()
    getVideoList()
    FRAME = Frame(APP, width=APPW, height=APPH)
    nav = Frame(FRAME)
    nav.pack(side=BOTTOM, expand=True)

    label = Label(FRAME, text='Select the video to download:')
    label.pack()

    videoVar = StringVar(FRAME)
    OptionMenu(FRAME, videoVar, *VIDLIST.keys()).pack()

    label = Label(FRAME,
                  text='Application will exit when the download is complete')
    label.pack()

    padx = pady = 5
    submit = Button(FRAME,
                    text='Download',
                    command=lambda: downloadFile(VIDLIST, videoVar.get()))
    submit.pack(in_=nav, side=LEFT, padx=padx, pady=pady)
    FRAME.pack()
    FRAME.tkraise()
Пример #2
0
class AdditionalTagWindow:
    def __init__(self):
        self.tags = []
        self.entries = []
        self.root = Tk()
        self.root.title("Additional Tags")
        self.root.minsize(width=400, height=400)

        self.frame = Frame(self.root)
        self.add_entry_button = Button(self.frame,
                                       text="New Entry",
                                       command=self.add_entry)
        self.confirm_button = Button(self.frame,
                                     text="Confirm",
                                     command=self.submit)
        self.cancel_button = Button(self.frame,
                                    text="Cancel",
                                    command=self.root.destroy)

    def add_entry(self):
        tag = TagField(self.frame)
        self.entries.append(tag)

        self.update_frame()

    def submit(self):
        for tag in self.entries:
            if tag.key_field.get() != "" and tag.value_field.get() != "":
                self.tags.append((tag.key_field.get(), tag.value_field.get()))
        self.root.destroy()

    def update_frame(self):
        for i, tag in enumerate(self.entries):
            tag.key_field.grid(row=i, column=0)
            tag.value_field.grid(row=i, column=1)

        n = len(self.entries)

        self.add_entry_button.grid(row=n, column=0)
        self.confirm_button.grid(row=n, column=1)
        self.cancel_button.grid(row=n, column=2)

        self.frame.grid(row=0, column=0)
        self.frame.tkraise()

    def get_user_tags(self) -> List:
        self.add_entry()
        self.root.mainloop()

        return self.tags
Пример #3
0
class LoginScreen(Window):
    def __init__(self, program):
        super().__init__(program)
        self.levels = None
        self.settings = program.settings
        self.level_handler = LevelHandler(program.settings)
        self.frame = Frame(program.master, width=800, height=800)
        self.frame.pack(side='top', fill='both', expand=1)
        self.show()

    def add_button(self, text, command):
        button = Button(self.frame,
                        text=text,
                        width=100,
                        height=20,
                        command=command)
        button.pack()

    def dispose(self):
        self.frame.pack_forget()
        self.frame.destroy()
        self.frame = None

    def show(self):
        self.add_button('New Game', self.new_game)
        self.add_button('Load Game', self.load_game)
        self.add_button('Exit', self.exit)
        self.frame.tkraise()

    def new_game(self):
        self.dispose()
        g = Game(self.program)
        g.new()
        self.change(Game(self.program))

    def exit(self):
        self.program.exit()

    def load_game(self):
        self.dispose()
        lg = LoadGame(self.program)
        lg.show()
        self.change(lg)

    def clear(self):
        self.frame.pack_forget()
        self.level_handler = None
        self.frame.destroy()
 def switch_frame_to(self, frame: tk.Frame):
     """
     This function allows navigation between frame (views).
     """
     # tries to find the frame instance in self.frames
     frame = self.frames[frame]
     if frame != None:  # check if there is an initialize frame that has been created.
         self.PreviousFrame.grid_remove(
         )  # remove the last frame so the page will resize to best fit heigh and width
         frame.grid(row=0, sticky="news")
         self.PreviousFrame = frame
         # then re-build the frame but with the new frame.
         frame.render(
         )  # each frame view should have this method, it allows me to re-render views with updated Data
         frame.tkraise()  # brings the fram to the front of the window.
     return
Пример #5
0
def printMainFrame(canvas, user):

    canvas.config(height=500, width=690)

    frame = Frame()
    frame.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)


    frame1 = Frame(frame)
    frame1.config(bd=1, relief="solid")
    frame1.grid(column=0, row=0, padx= 20, ipadx=10, ipady=10)
    frame1.tkraise()

    frame2 = Frame(frame)
    frame2.config(bd=1, relief="solid")
    frame2.grid(column=1, row=0, padx=20, ipadx=10, ipady=10)
    frame2.tkraise()


    uis = getUIByID_user(user.id)
    for ui in uis:
        if ui[0] == 'RegistryOfAuxiliary': 
            RegistryOfAuxiliary(frame1, 0)
        elif ui[0] == 'RegistryOfExams': 
            RegistryOfExams(frame2, 0)
        elif ui[0] == 'ListOfApplications': 
            ListOfApplications(frame1, 0, user.id)
        elif ui[0] == 'SeeExamNotes': 
            SeeExamNotes(frame2, 1, user.id)
        elif ui[0] == 'SeeListOfStudents': 
            SeeListOfStudents(frame1, 0, user.id)
        elif ui[0] == 'TakeAttendeeList': 
            TakeAttendeeList(frame2, 1, user.id)
        
        



    # RegistryOfAuxiliary(frame, 0)
    # RegistryOfExams(frame, 1)

    # ListOfApplications(frame, 0, user.id)
    # SeeExamNotes(frame, 1, user.id)

    # SeeListOfStudents(frame, 0, user.id)
    # TakeAttendeeList(frame, 1, user.id)
Пример #6
0
def enter_video():
    global YTLINK
    FRAME = Frame(APP, width=APPW, height=APPH)
    FRAME.winfo_toplevel().title('YouTube Video Download')
    nav = Frame(FRAME)
    nav.pack(side=BOTTOM, expand=True)

    label = Label(FRAME, text='Enter Youtube Video Link: (Paste is CTRL+V)')
    label.pack()

    youtubeLink = StringVar(FRAME)
    yt_entry = Entry(FRAME, textvariable=youtubeLink)
    yt_entry.pack()
    yt_entry.focus()

    padx = pady = 5
    submit = Button(FRAME,
                    text='Get List',
                    command=lambda: list_options(youtubeLink))
    submit.pack(in_=nav, side=LEFT, padx=padx, pady=pady)
    FRAME.pack()
    FRAME.tkraise()
Пример #7
0
def downloadFile(VIDLIST, option):
    FRAME = Frame(APP, width=APPW, height=APPH)
    nav = Frame(FRAME)
    nav.pack(side=BOTTOM, expand=True)

    label = Label(FRAME, text='Downloading File')
    label.pack()

    FRAME.pack()
    FRAME.tkraise()

    for video, key in VIDLIST.items():
        if video == option:
            proc = subprocess.Popen([ytdl, "-f", key, YTLINK],
                                    stdout=subprocess.PIPE)
            while True:
                line = proc.stdout.readline().decode()
                if line != '' and DEBUG:
                    print(line)
                else:
                    break
    openFileLocation()
Пример #8
0
class SaveMenu(BaseWindow):
	def __init__(self, controller, image_data, gif = False):
		BaseWindow.__init__(self, controller)
		self.geometry(f"{WIDTH}x{HEIGHT}")
		self.set_exit_function()
		self.set_title("Export")
		self.resizable(True, True)
		self.image_data = image_data
		self.gif = gif

		# sizing_options = [(SIZING_OPTIONS[SCALAR], SCALAR), (SIZING_OPTIONS[PIXELS], PIXELS)]
		# self.size_selection = selection_box("SIZING", sizing_options, self)
		# self.size_selection.pack(fill = "x", expand = False, padx = 4, anchor = "n")

		# color_and_format_frame = Frame(self)
		# color_options = [(COLOR_OPTIONS[RGB], RGB), (COLOR_OPTIONS[GRAYSCALE], GRAYSCALE), (COLOR_OPTIONS[BLACKANDWHITE], BLACKANDWHITE)]
		# self.color_selection = selection_box("COLOR", color_options, color_and_format_frame)
		# self.color_selection.pack(fill = "both", expand = True, side = "left", padx = 4, )
		# format_options = [
		# 	(OUTPUT_OPTIONS[PNG], PNG),
		# 	(OUTPUT_OPTIONS[JPG], JPG),
		# 	(OUTPUT_OPTIONS[BMP], BMP),
		# 	(OUTPUT_OPTIONS[PXSTUDIO], PXSTUDIO)
		# 	]
		# self.format_selection = selection_box("FORMAT", format_options, color_and_format_frame)
		# self.format_selection.pack(fill = "both", expand = True, side = "left", padx = 4)
		# color_and_format_frame.pack(side = "top", expand = False, fill = "x")
		self.outer_frame = Frame(self)
		self.outer_frame.pack(fill = "both", expand = True)
		sizing_and_color_frame = Frame(self.outer_frame)
		sizing_and_color_frame.pack(expand = True, fill = "both")
		sizing_options = [(SIZING_OPTIONS[SCALAR], SCALAR), (SIZING_OPTIONS[PIXELS], PIXELS)]
	
		#-------------------------------------------------
		#Size

		size_selection_and_size_option_frame = Frame(sizing_and_color_frame)
		size_selection_and_size_option_frame.pack(fill = "both", expand = True, padx = 4)
		self.size_selection = selection_box("SIZING", sizing_options, self.on_size_select, size_selection_and_size_option_frame)
		self.size_selection.pack(side = "left", fill = "y")

		selection_frame_frame = ttk.LabelFrame(size_selection_and_size_option_frame, text = "SIZE OPTIONS")
		selection_frame_frame.pack(fill = "both", expand = True, side = "left")
		self.scaling_frame = Frame(selection_frame_frame)
		self.scaling_frame.place(relwidth = 1, relheight = 1)
		self.scaling_factor = LabeledEntry("Scaling Factor - ", 1, self.scaling_frame)
		self.scaling_factor.place(relwidth = 1, relheight = 1)

		self.custom_dimensions_frame = Frame(selection_frame_frame)
		self.custom_dimensions_frame.place(relwidth = 1, relheight = 1)
		self.dimension_x_entry = LabeledEntry("Width - ", "16", self.custom_dimensions_frame)
		self.dimension_x_entry.pack(fill = "both", expand = True, anchor = "w")
		self.dimension_y_entry = LabeledEntry("Height - ", "16", self.custom_dimensions_frame)
		self.dimension_y_entry.pack(fill = "both", expand = True, anchor = "w")
		self.on_size_select()

		#Loop--------------------------------------------
		if self.gif:
			gif_option_frame = Frame(sizing_and_color_frame)
			gif_option_frame.pack(fill = "both", expand = True, padx = 4)
			loop_options = [(LOOP_OPTIONS[LOOP], LOOP), (LOOP_OPTIONS[NO_LOOP], NO_LOOP)]
			self.loop_selection = selection_box("LOOP OPTIONS", loop_options, self.on_loop_select, gif_option_frame)
			self.loop_selection.pack(side = "left", fill = "y")

			loop_frame = ttk.LabelFrame(gif_option_frame, text = "LOOP OPTIONS")
			loop_frame.pack(fill = "both", expand = True, side = "left")
			self.number_of_loops_frame = Frame(loop_frame)
			self.number_of_loops_frame.place(relwidth = 1, relheight = 1)
			self.number_of_loops = LabeledEntry("Loops, blank for limitless -", "", self.number_of_loops_frame)
			self.number_of_loops.place(relwidth = 1, relheight = 1)

			self.no_loop_frame = Frame(loop_frame)
			self.no_loop_frame.place(relwidth = 1, relheight = 1)
			Label(self.no_loop_frame, text = "Don't loop gif.").place(relwidth = 1, relheight = 1)

			self.on_loop_select()

		#Color--------------------------------------------

		color_options = [(COLOR_OPTIONS[RGBA], RGBA), (COLOR_OPTIONS[GRAYSCALE], GRAYSCALE), (COLOR_OPTIONS[BLACKANDWHITE], BLACKANDWHITE)]
		self.color_selection = selection_box("COLOR", color_options, self.on_color_select, sizing_and_color_frame)
		self.color_selection.pack(fill = "both", expand = True, side = "top", padx = 4, )

		if self.gif:
			duration_frame = ttk.LabelFrame(sizing_and_color_frame, text = "GIF PLAYBACK")
			duration_frame.pack(side = "top", expand = True, fill = "x", padx = 2)
			self.duration_entry = LabeledEntry("Frame Duration (Divide 1000 by fps) - ", 100, duration_frame)
			self.duration_entry.pack(side = "top", expand = True, fill = "both", padx = 2)

		footer = ttk.LabelFrame(self.outer_frame, text = "FILE")

		select_path_frame = Frame(footer)
		select_path_frame.pack(fill = "both", expand = True)
		self.file_path_entry = LabeledEntry("File path", "", select_path_frame)
		self.file_path_entry.pack(fill = "both", expand = True, side = "left", padx = (2, 2))
		select_path_button = Button(select_path_frame, command = self.set_save_path, text = "Select file").pack(side = "right", pady = (4,6), padx = (2, 2), expand = False)

		Button(footer, text = "Save", command = self.save if not self.gif else self.save_gif).pack(fill = "x", expand = False, padx = 4, pady = 4)

		footer.pack(fill = "x", expand = False, padx = 4, side = "top", pady = 4)

		grip = ttk.Sizegrip(self)
		grip.place(relx=1.0, rely=1.0, anchor="se")

	def set_save_path(self):
		if self.gif:
			save_as = filedialog.asksaveasfilename(
				defaultextension = ".*",
				filetypes = [("GIF files", ".gif")]
			)
		else:
			save_as = filedialog.asksaveasfilename(
				defaultextension = ".*",
				filetypes = [
						("All files", ".*"), 
						("PNG files", ".png"), 
						("JPEG files", ".jpg .jpeg"), 
						("BMP files", ".bmp"), 
						("ICO files", ".ico")
				]
			)
		self.file_path_entry.set(save_as)

	def on_size_select(self):
		sizing_mode = self.size_selection.get()
		def handle_scalar():self.scaling_frame.tkraise()
		def handle_pixels():self.custom_dimensions_frame.tkraise()
		modes = {SCALAR : handle_scalar,PIXELS : handle_pixels}
		modes[sizing_mode]()

	def on_loop_select(self):
		loop_mode = self.loop_selection.get()
		def handle_loop(): self.number_of_loops_frame.tkraise()
		def handle_no_loop(): self.no_loop_frame.tkraise()
		modes = { LOOP : handle_loop, NO_LOOP : handle_no_loop }
		modes[loop_mode]()

	def on_color_select(self):
		pass

	def save(self):
		print("Beginning image conversion")
		image_data = self.image_data #Make a copy of the image data for manipulation in case save fails and needs to bre redone
		def handle_scalar(image):
			print("Appling scalar resize to image")
			try:
				factor = int(self.scaling_factor.get())
				print(f"Resizing image by factor {factor}")
			except Exception as e:
				self.error(f"Invalid scaling factor: {e}")
				return
			if not factor:
				self.error(f"Scaling factor cannot be zero")
				return

			if factor == 1:
				return image
			else:
				return image.resize((int(image.height) * int(factor), int(image.width) * int(factor)), Image.BOX)

		def handle_pixels(image): 
			try:
				width = self.dimension_x_entry.get()
				height = self.dimension_y_entry.get()
				print(f"Resizing image to {width} x {height}")
			except Exception as e:
				self.error(f"Invalid pixel resize values {e}")
				return

			try:
				return image.resize((int(height), int(width)), Image.BOX)
			except Exception as e:
				self.error(f"Error resizing image - {e}")
				return
			
		def handle_RGBA(image):
			print(f"ALREADY RGBA")
			return image

		sizing_options = {
			SCALAR : handle_scalar,
			PIXELS : handle_pixels
		}
		sizing_mode = self.size_selection.get()
		image_data = sizing_options[sizing_mode](image_data)
		if not image_data: return

		color_options = {
			RGBA : handle_RGBA,
			GRAYSCALE : convert_image_to_grayscale,
			BLACKANDWHITE : convert_image_to_blackandwhite
		}
		color_mode = self.color_selection.get()
		try:
			mode = color_options[color_mode]
			if not mode:
				self.error("Unable to determine color mode")
				return
		except Exception as e:
			self.error(f"Error determining color mode: {e}")
			return
		try:
			image_data = mode(image_data)
			if not image_data:
				self.error("Invalid data after applying color mode")
				return
		except Exception as e:
			self.error(f"Error applying color mode: {e}")
			return

		try:
			filename = self.file_path_entry.get()
		except Exception as e:
			self.error(f"Error getting file name: {e}")
			return
		if not filename:
			self.error(f"No filename specified")
			return

		try:
			print("Saving...")
			image_data.save(filename)
		except Exception as e:
			self.error(f"Error saving image: {e}")
			return

		self.destroy() #Sucessful!

	def save_gif(self):
		print("Beginning image conversion")
		def handle_scalar(image):
			print("Appling scalar resize to image")
			try:
				factor = int(self.scaling_factor.get())
				print(f"Resizing image by factor {factor}")
			except Exception as e:
				self.error(f"Invalid scaling factor: {e}")
				return
			if not factor:
				self.error(f"Scaling factor cannot be zero")
				return

			if factor == 1:
				return image
			else:
				return image.resize((int(image.height) * int(factor), int(image.width) * int(factor)), Image.BOX)

		def handle_pixels(image): 
			try:
				width = self.dimension_x_entry.get()
				height = self.dimension_y_entry.get()
				print(f"Resizing image to {width} x {height}")
			except Exception as e:
				self.error(f"Invalid pixel resize values {e}")
				return

			try:
				return image.resize((int(height), int(width)), Image.BOX)
			except Exception as e:
				self.error(f"Error resizing image - {e}")
				return
			
		def handle_RGBA(image):
			print(f"ALREADY RGBA")
			return image

		sizing_options = {
			SCALAR : handle_scalar,
			PIXELS : handle_pixels
		}
		sizing_mode = self.size_selection.get()

		images = []
		
		try:
			for i in self.image_data: images.append(sizing_options[sizing_mode](i))
		except Exception as e:
			self.error(f"Error resizing images: {e}")
			return
		for i in images:
			if not i:
				self.error(f"Invalid image data after applying resize")
				return

		color_options = {
			RGBA : handle_RGBA,
			GRAYSCALE : convert_image_to_grayscale,
			BLACKANDWHITE : convert_image_to_blackandwhite
		}
		color_mode = self.color_selection.get()
		try:
			mode = color_options[color_mode]
			if not mode:
				self.error("Unable to determine color mode")
				return
		except Exception as e:
			self.error(f"Error determining color mode: {e}")
			return
		try:
			images = [mode(i) for i in images]
			for i in images:
				if not i:
					self.error("Invalid data after applying color mode")
					return
		except Exception as e:
			self.error(f"Error applying color mode: {e}")
			return

		try:
			filename = self.file_path_entry.get()
		except Exception as e:
			self.error(f"Error getting file name: {e}")
			return
		if not filename:
			self.error(f"No filename specified")
			return

		duration = 100

		def handle_loop():
			if self.number_of_loops.get(): return int(self.number_of_loops.get())
			else: return 0
		def handle_no_loop(): return 1

		loop_options = {
			LOOP : handle_loop,
			NO_LOOP : handle_no_loop,
		}

		loop = loop_options[self.loop_selection.get()]()
		duration = int(self.duration_entry.get())
		try:
			images[0].save(filename, format='GIF', save_all=True, append_images=images[1:], duration=int(duration), loop=int(loop), transparency=255, optimize = False, disposal = 2)
		except Exception as e:
			self.error(f"Error saving image: {e}")
			return

		self.destroy() #Sucessful!


	def error(self, error):
		error_frame = error_window(error, self.outer_frame)
		error_frame.place(relwidth = 1, relheight = 1)
Пример #9
0
class ConfSelectWizard(Toplevel):
    def __init__(self,
                 master=None,
                 conf_path='',
                 width=0.35,
                 height=0.1,
                 use_factor=True):

        Toplevel.__init__(self, master=master)

        w, h, x, y = get_geometry(self, width, height, use_factor)

        self.geometry('%dx%d+%d+%d' % (w, h, x, y))

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

        self.minsize(int(w), int(h))
        self.maxsize(int(w), int(h))

        # Top Frame
        self.__start_frame = Frame(self)
        # Description og the configuration file
        for msg in SELECT_CONF_LABEL.splitlines(False):
            label = Label(self.__start_frame, text=msg)
            label.config(font=(FONT_NAME, int(w / 50)))
            # Deploy
            label.pack(anchor=NW, side=TOP, padx=5)

        # Buttons
        next_btn = Button(self.__start_frame,
                          text=NEXT,
                          width=6,
                          command=self.__next_frame)

        top_run_btn = Button(self.__start_frame,
                             text=RUN,
                             width=6,
                             command=self.__run)

        top_cancel_btn = Button(self.__start_frame,
                                text=CANCEL,
                                width=6,
                                command=self.__cancel)

        # Deploy
        top_cancel_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)
        top_run_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)
        next_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)

        # Selection Frame
        self.__conf_select_frame = Frame(self)
        # Description
        select_title_label = Label(self.__conf_select_frame,
                                   text=SELECT_USE_CONF_LABEL)
        select_title_label.config(font=(FONT_NAME, int(w / 50)))
        select_title_label.pack(anchor=NW, side=TOP, padx=5, pady=5)

        # Conf entry
        entry_frame = Frame(self.__conf_select_frame)
        self.__conf_path_var = StringVar()
        self.__conf_path_var.set(conf_path)
        self.__save_path = conf_path
        conf_entry = Entry(entry_frame, textvariable=self.__conf_path_var)
        conf_entry.config(font=(FONT_NAME, int(w / 50)))
        conf_entry.bind(KEY_RELEASE_EVENT, self.__on_change)

        refer_btn = Button(entry_frame,
                           text=SELECT,
                           width=6,
                           command=self.__select_conf)

        # Deploy
        refer_btn.pack(side=RIGHT, padx=5, pady=5)
        conf_entry.pack(side=RIGHT, fill=X, expand=YES, padx=5, pady=5)

        entry_frame.pack(side=TOP, fill=X)

        # Buttons
        prev_btn = Button(self.__conf_select_frame,
                          text=PREV,
                          width=6,
                          command=self.__prev_frame)
        select_cancel_btn = Button(self.__conf_select_frame,
                                   text=CANCEL,
                                   width=6,
                                   command=self.__cancel)
        self.__select_run_btn = Button(self.__conf_select_frame,
                                       text=RUN,
                                       width=6,
                                       command=self.__run)
        self.__view_btn = Button(self.__conf_select_frame,
                                 text=VIEW,
                                 width=6,
                                 command=self.__view_conf)

        # Deploy
        select_cancel_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)
        self.__select_run_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)
        self.__view_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)
        if not conf_path:
            prev_btn.pack(anchor=NE, side=RIGHT, padx=5, pady=3)

        # Deploy
        frame = Frame(self.__conf_select_frame)
        self.__start_frame.grid(row=0, column=0, sticky=NSEW)
        frame.pack()
        self.__conf_select_frame.grid(row=0, column=0, sticky=NSEW)

        self.__is_run = False
        self.__viewing = False

        # If it has already been selected, a selection frame is displayed
        self.__check_conf_path()
        if not conf_path:
            self.__start_frame.tkraise()
        else:
            self.__conf_select_frame.tkraise()

        self.protocol(WM_DELETE_WINDOW, self.__close)

    def __close(self):
        if not self.__viewing:
            self.destroy()

    def __on_change(self, event):
        event.widget.configure(state=DISABLED)
        try:
            self.__check_conf_path()
        finally:
            event.widget.configure(state=NORMAL)

    def __check_conf_path(self):
        # Switching the state of the button
        if (pathlib.Path(self.conf_path).is_file()
                and pathlib.Path(self.conf_path).exists()):

            self.__view_btn.configure(state=ACTIVE)
            self.__select_run_btn.configure(state=ACTIVE)

        elif not self.conf_path:
            self.__view_btn.configure(state=DISABLED)
            self.__select_run_btn.configure(state=ACTIVE)

        else:
            self.__view_btn.configure(state=DISABLED)
            self.__select_run_btn.configure(state=DISABLED)

    @property
    def is_run(self):
        return self.__is_run

    @is_run.deleter
    def is_run(self):
        del self.__is_run

    @property
    def conf_path(self):
        return self.__conf_path_var.get()

    def __next_frame(self):
        if self.__save_path:
            self.__conf_path_var.set(self.__save_path)
        self.__conf_select_frame.tkraise()

    def __prev_frame(self):
        if self.conf_path:
            self.__save_path = self.conf_path

        self.__conf_path_var.set('')
        self.__start_frame.tkraise()

    def __run(self):
        self.__is_run = True
        self.destroy()

    def __cancel(self):
        self.__is_run = False
        self.destroy()

    def __select_conf(self):

        # Show conf file selection dialog
        if self.conf_path:
            init_dir = pathlib.Path(self.conf_path).parent.resolve()
            init_file = pathlib.Path(self.conf_path).name
            file_path = filedialog.askopenfilename(parent=self,
                                                   filetypes=[('JSON File',
                                                               '*.json')],
                                                   title=SELECT_USE_CONF_LABEL,
                                                   initialdir=init_dir,
                                                   initialfile=init_file)
        else:
            file_path = filedialog.askopenfilename(parent=self,
                                                   filetypes=[('JSON File',
                                                               '*.json')],
                                                   title=SELECT_USE_CONF_LABEL)

        if file_path:
            self.__conf_path_var.set(file_path)
            self.__check_conf_path()

    def __view_conf(self):
        try:
            with open(self.conf_path, encoding=UTF8) as rs:
                j_data = json.load(rs)

        except json.JSONDecodeError:
            return

        msg_wizard = Toplevel(master=self.master)

        w, h, x, y = get_geometry(msg_wizard, 0.5, 0.35)

        msg_wizard.geometry('%dx%d+%d+%d' % (w, h, x, y))
        msg_wizard.minsize(int(w), int(h))

        viewer = ScrolledText(msg_wizard, font=(FONT_NAME, 15), height=1)
        viewer.insert(END, json.dumps(j_data, indent=2))
        viewer.configure(state=DISABLED)
        viewer.pack(fill=BOTH, anchor=NW, expand=YES, padx=5, pady=5)

        self.__viewing = True
        show_wizard(msg_wizard, 'Configuration(%s)' % self.conf_path)
        self.__viewing = False
Пример #10
0
class MainWin(Tk):

    def __init__(self, client):
        Tk.__init__(self)
        self.client = client
        self.programPanel = ProgramPanel(client)
        self.programPanel.grid(row = 0, column = 0, sticky = NSEW)

        self.frame = Frame(self)
        self.frame.grid(row = 0, column = 0, sticky = NSEW)
        nextRow = Counter()

        # Create the menu.
        menu = Frame(self.frame)
        addButton = Menubutton(menu, text = 'Add')
        addButton.pack()
        menu.grid(row = nextRow(), column = 0, sticky = W)

        # Create the program panel.
        self.program = ProgramWidget(self.frame, client)
        self.program.grid(row = nextRow(), column = 0, columnspan = 2,
                          sticky = W)

        label = Label(self.frame, text = 'AWB')
        label.grid(row = nextRow(), column = 0)

        self.recordMode = Button(self.frame, text = 'P',
                                 command = self.toggleRecord)
        modeRow = nextRow()
        self.recordMode.grid(row = modeRow, column = 0, sticky = W)
        self.status = Label(self.frame, text = 'Idle')
        self.status.grid(row = modeRow, column = 1)

        self.channels = []
        self.channelFrame = Frame(self.frame)
        self.channelFrame.grid(row = nextRow(), columnspan = 2)

        self.bind('q', self.terminate)
        self.bind('f', self.foo)

        self.bind('r', self.toggleRecord)
        self.bind('k', self.toggleSticky)
        self.bind('.', self.nextSection)
        self.bind(',', self.prevSection)
        self.bind('<space>', self.togglePause)
        self.bind('K', self.clearAllState)
        self.protocol('WM_DELETE_WINDOW', self.destroy)

        self.bind('<F1>', lambda evt: self.frame.tkraise())
        self.bind('<F2>', lambda evt: self.programPanel.tkraise())

        for i in range(0, 8):

            # Bind number key.
            self.bind(str(i),
                      lambda evt, channel = i: self.toggleChannel(channel)
                      )

            # Create channel
            channel = Channel(self.channelFrame, i)
            self.channels.append(channel)
            channel.pack(side = LEFT)

            client.addChannelSubscriber(
                i,
                lambda ch, status, channel = channel:
                    channel.changeStatus(status)
            )

    def foo(self, event):
        print('got foo')

    def terminate(self, event):
        self.destroy()

    def toggleRecord(self, event):
        self.client.recordEnabled = not self.client.recordEnabled
        self.recordMode.configure(text = self.client.recordEnabled and 'R' or
                                  'P'
                                  )

    def togglePause(self, event):
        self.client.togglePause()
        if self.client.paused:
            self.status.configure(text = 'Paused')
        else:
            self.status.configure(text = 'Playing')

    def clearAllState(self, event):
        self.client.clearAllState()
        self.status.configure(text = 'Idle')
        for channel in self.channels:
            channel.changeStatus(0)

    def toggleChannel(self, channel):
        # using "channel" as program
        self.client.activate(channel)
        if self.client.recording.get(channel):
            self.client.endRecord(channel)
        elif self.client.recordEnabled:
            self.client.startRecord(channel)
        self.status.configure(text = 'Recording on %s' % channel)

    def __getActiveChannel(self):
        # Move this to awb_client
        for i, ch in enumerate(self.channels):
            if ch.active:
                return i

    def toggleSticky(self, event):
        channel = self.__getActiveChannel()
        self.client.toggleChannelSticky(channel)

    def nextSection(self, event):
        self.client.nextOrNewSection()

    def prevSection(self, event):
        self.client.prevSection()
Пример #11
0
class App(Tk):
    def __init__(self, icon='', *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.host = ''
        self.port = None
        self.username = ''
        self.pw = ''
        self.target_device = ''
        self.rx_topic = ''  # subscribe topic
        self.tx_topic = ''  # publish topic
        self.status_topic = ''
        self.client_id = 'Arduino-Remote-' + randomId(8)
        self.stream_fp = os.path.join(os.getcwd(), 'temp/parsed_hex')

        self.protocol("WM_DELETE_WINDOW", self.onClosing)
        self.iconphoto(False, PhotoImage(file=icon))
        self.minsize(720, 540)
        self.geometry('720x540')
        self.side_pane = Frame(self, bg='#d9d9d9')
        self.side_pane.pack(side='left', fill='both')
        self.status_frame = Frame(self.side_pane, padx=5, bg='#d9d9d9')
        self.status_frame.grid_columnconfigure(0, weight=1)
        self.status_frame.pack(pady=10, anchor='w')
        self.menu_frame = Frame(self.side_pane, bg='#d9d9d9')
        self.menu_frame.pack(pady=30)
        self.selection_ind = Frame(self.menu_frame,
                                   bg='#00d5ff',
                                   width=5,
                                   height=15)
        self.action_pane = Frame(self, bg='white', width=620)
        self.action_pane.pack(side='left', fill='both', expand=True)

        # Side pane
        self.refresh_img = PhotoImage(file=REFRESH_IMG)
        self.refresh_button = Button(self.status_frame,
                                     bg='#d9d9d9',
                                     relief='flat',
                                     bd=0,
                                     activebackground='#d9d9d9',
                                     image=self.refresh_img,
                                     command=self.refreshConnection)
        self.refresh_button.grid(row=0,
                                 column=0,
                                 sticky='nsw',
                                 padx=5,
                                 pady=10)
        self.conn_status_frame = Frame(self.status_frame, bg='#d9d9d9')
        self.conn_status_frame.grid(row=1, column=0, sticky='nsew')
        self.conn_status_img = PhotoImage(file=CONNECTION_STATUS_IMG)
        self.conn_status_img_label = Label(self.conn_status_frame,
                                           bg='#d9d9d9',
                                           image=self.conn_status_img)
        self.conn_status_img_label.pack(side='left', padx=5)
        self.connection_status = tk.StringVar(self, value='Disconnected')
        self.connection_status_label = Label(
            self.conn_status_frame,
            bg='#d9d9d9',
            fg='#ff0000',
            textvariable=self.connection_status)
        self.connection_status_label.pack(side='left')

        self.dev_status_frame = Frame(self.status_frame, bg='#d9d9d9')
        self.dev_status_frame.grid(row=2, column=0, sticky='nsew')
        self.dev_status_img = PhotoImage(file=DEVICE_STATUS_IMG)
        self.dev_status_img_label = Label(self.dev_status_frame,
                                          bg='#d9d9d9',
                                          image=self.dev_status_img)
        self.dev_status_img_label.pack(side='left', padx=5)
        self.device_status = tk.StringVar(self, value='Unknown')
        self.device_status_label = Label(self.dev_status_frame,
                                         bg='#d9d9d9',
                                         fg='#ff0000',
                                         textvariable=self.device_status)
        self.device_status_label.pack(side='left')

        self.OTA_button = CustomButton(master=self.menu_frame,
                                       width=120,
                                       height=60,
                                       img_fp=OTA_IMG,
                                       text='OTA',
                                       compound='left',
                                       anchor='w',
                                       indicator=self.selection_ind,
                                       padx=20)
        self.debug_button = CustomButton(master=self.menu_frame,
                                         width=120,
                                         height=60,
                                         img_fp=DEBUG_IMG,
                                         text='Log',
                                         compound='left',
                                         anchor='w',
                                         indicator=self.selection_ind,
                                         padx=20)
        self.setting_button = CustomButton(master=self.menu_frame,
                                           width=120,
                                           height=60,
                                           img_fp=SETTING_IMG,
                                           text='Setting',
                                           compound='left',
                                           anchor='w',
                                           indicator=self.selection_ind,
                                           padx=20)

        self.selection_ind.tkraise()  # Bring selection indicator forward

        # Action pane

        ## -> OTA frame
        self.OTA_frame = OTAFrame(main_win=self,
                                  master=self.action_pane,
                                  button=self.OTA_button,
                                  bg='#fbfbfb')

        ## -> Debug frame
        self.debug_frame = DebugFrame(main_win=self,
                                      master=self.action_pane,
                                      button=self.debug_button,
                                      bg='#fbfbfb')

        ## -> Setting frame
        self.setting_frame = SettingFrame(main_win=self,
                                          master=self.action_pane,
                                          button=self.setting_button,
                                          bg='#fbfbfb')

        self.remote = ArduinoRemote(
            self.stream_fp, self.client_id, self.host, self.port,
            self.username, self.pw, self.tx_topic, self.rx_topic,
            self.status_topic, self.connectionStatusLog, self.deviceStatusLog,
            self.OTA_frame.log, self.debug_frame.log)

    def refreshConnection(self):
        self.remote._connect()

    def connectionStatusLog(self, log):
        self.connection_status.set(log)
        self.connection_status_label[
            'fg'] = '#11d438' if self.remote.is_connected else '#ff0000'

    def deviceStatusLog(self, log):
        self.device_status.set(log)
        if log.strip().lower() == 'online':
            self.device_status_label['fg'] = '#11d438'

        else:
            self.remote.debugStop()
            self.debug_frame.debug_button['text'] = 'Debug'
            self.device_status_label['fg'] = '#ff0000'

    def onClosing(self):
        if messagebox.askokcancel("Quit", "Do you want to quit?"):
            self.destroy()
Пример #12
0
            )
        self.button.grid(row=0, column=0)
        
        qBtn = Button(frame2, text="QUIT", command=frame2.quit)
        qBtn.grid(row=0, column=0)
        
        self.dialog.mainloop()
        #self.frame.destroy()
        print("QUIT")

def say_hi(self):
        print ("hi there, everyone!")

if __name__ == '__main__':
    dialogRoot=Tk()
    frame=Frame(dialogRoot)
    
    
    frame2=Frame(dialogRoot)
    
    thread=testThread(dialogRoot, frame, frame2)
    thread.start()
    
    print("Wait")
    time.sleep(10)
    #frame.destroy()
    
    print("change")
    frame.tkraise(frame2)
    
    print("done")
Пример #13
0
class SaveMenu(Toplevel):
    def __init__(self, controller, image_data):
        Toplevel.__init__(self)
        self.geometry(f"{350}x{200}")
        self.title("Export")
        self.resizable(True, True)
        self.attributes('-topmost', True)
        self.image_data = image_data
        self.outer_frame = Frame(self)
        self.outer_frame.pack(fill="both", expand=True)
        sizing_and_color_frame = Frame(self.outer_frame)
        sizing_and_color_frame.pack(expand=True, fill="both")
        sizing_options = [(SIZING_OPTIONS[SCALAR], SCALAR),
                          (SIZING_OPTIONS[PIXELS], PIXELS)]

        size_selection_and_size_option_frame = Frame(sizing_and_color_frame)
        size_selection_and_size_option_frame.pack(fill="both",
                                                  expand=True,
                                                  padx=4)
        self.size_selection = selection_box(
            "SIZING", sizing_options, self.on_size_select,
            size_selection_and_size_option_frame)
        self.size_selection.pack(side="left", fill="y")

        selection_frame_frame = ttk.LabelFrame(
            size_selection_and_size_option_frame, text="SIZE OPTIONS")
        selection_frame_frame.pack(fill="both", expand=True, side="left")
        self.scaling_frame = Frame(selection_frame_frame)
        self.scaling_frame.place(relwidth=1, relheight=1)
        self.scaling_factor = LabeledEntry("Scaling Factor - ", 1,
                                           self.scaling_frame)
        self.scaling_factor.place(relwidth=1, relheight=1)

        self.custom_dimensions_frame = Frame(selection_frame_frame)
        self.custom_dimensions_frame.place(relwidth=1, relheight=1)
        self.dimension_x_entry = LabeledEntry("Width - ", "16",
                                              self.custom_dimensions_frame)
        self.dimension_x_entry.pack(fill="both", expand=True, anchor="w")
        self.dimension_y_entry = LabeledEntry("Height - ", "16",
                                              self.custom_dimensions_frame)
        self.dimension_y_entry.pack(fill="both", expand=True, anchor="w")
        self.on_size_select()

        footer = ttk.LabelFrame(self.outer_frame, text="FILE")

        select_path_frame = Frame(footer)
        select_path_frame.pack(fill="both", expand=True)
        self.file_path_entry = LabeledEntry("File path", "", select_path_frame)
        self.file_path_entry.pack(fill="both",
                                  expand=True,
                                  side="left",
                                  padx=(2, 2))
        select_path_button = Button(select_path_frame,
                                    command=self.set_save_path,
                                    text="Select file").pack(side="right",
                                                             pady=(4, 6),
                                                             padx=(2, 2),
                                                             expand=False)
        Button(footer, text="Save", command=self.save).pack(fill="x",
                                                            expand=False,
                                                            padx=4,
                                                            pady=4)
        footer.pack(fill="x", expand=False, padx=4, side="top", pady=4)

    def set_save_path(self):
        save_as = filedialog.asksaveasfilename(defaultextension=".*",
                                               filetypes=[
                                                   ("All files", ".*"),
                                                   ("PNG files", ".png"),
                                                   ("JPEG files",
                                                    ".jpg .jpeg"),
                                                   ("BMP files", ".bmp"),
                                                   ("ICO files", ".ico")
                                               ])
        self.file_path_entry.set(save_as)

    def on_size_select(self):
        sizing_mode = self.size_selection.get()

        def handle_scalar():
            self.scaling_frame.tkraise()

        def handle_pixels():
            self.custom_dimensions_frame.tkraise()

        modes = {SCALAR: handle_scalar, PIXELS: handle_pixels}
        modes[sizing_mode]()

    def on_loop_select(self):
        loop_mode = self.loop_selection.get()

        def handle_loop():
            self.number_of_loops_frame.tkraise()

        def handle_no_loop():
            self.no_loop_frame.tkraise()

        modes = {LOOP: handle_loop, NO_LOOP: handle_no_loop}
        modes[loop_mode]()

    def save(self):
        print("Beginning image conversion")
        image_data = self.image_data  #Make a copy of the image data for manipulation in case save fails and needs to be redone

        def handle_scalar(image):
            print("Appling scalar resize to image")
            try:
                factor = int(self.scaling_factor.get())
                print(f"Resizing image by factor {factor}")
            except Exception as e:
                return self.error(f"Invalid scaling factor: {e}")
            if not factor:
                return self.error(f"Scaling factor cannot be zero")
            if factor == 1: return image
            else:
                return image.resize((int(image.height) * int(factor),
                                     int(image.width) * int(factor)),
                                    Image.BOX)

        def handle_pixels(image):
            try:
                width = self.dimension_x_entry.get()
                height = self.dimension_y_entry.get()
                print(f"Resizing image to {width} x {height}")
            except Exception as e:
                return self.error(f"Invalid pixel resize values {e}")

            try:
                return image.resize((int(height), int(width)), Image.BOX)
            except Exception as e:
                return self.error(f"Error resizing image - {e}")

        sizing_options = {SCALAR: handle_scalar, PIXELS: handle_pixels}
        sizing_mode = self.size_selection.get()
        image_data = sizing_options[sizing_mode](image_data)
        if not image_data: return

        try:
            filename = self.file_path_entry.get()
        except Exception as e:
            return self.error(f"Error getting file name: {e}")
        if not filename:
            return self.error(f"No filename specified")

        try:
            print("Saving...")
            image_data.save(filename)
        except Exception as e:
            return self.error(f"Error saving image: {e}")

        self.destroy()  #Sucessful!

    def error(self, error):
        print(error)
        error_frame = error_window(error, self.outer_frame)
        error_frame.place(relwidth=1, relheight=1)
                text="commencer",
                width=10,
                command=lambda: reveil(frame_second, expected_time))
button.pack()
button = Button(frame_second,
                text="Retour menu",
                width=10,
                command=lambda: back_principal_frame(frame_principal))
button.pack()

question_1 = Label(
    frame_principal,
    text=
    "Dans combien de temps souhaitez-vous vous réveiller? Ex:hours/minutes/secondes"
)
question_1.pack()
expected_time = Entry(frame_principal, bg="yellow", bd=3, fg="blue")
expected_time.pack()
question_2 = Label(
    frame_principal,
    text=
    "Intervalles de rappel et nombres de fois(Ex: nombres de fois/intervalles de rappel(secondes)"
)
question_2.pack()
time_recall = Entry(frame_principal, bg="yellow", bd=3, fg="blue")
time_recall.pack()
frame_principal.grid(row=0, column=0, sticky="nsew")
frame_second.grid(row=0, column=0, sticky="nsew")
frame_principal.tkraise()
root.mainloop()
Пример #15
0
 def show_page(self, frame: tk.Frame):
     frame.tkraise()
Пример #16
0
def _activate_frame(frame: tkinter.Frame) -> None:
    frame.tkraise()
    frame.focus_set()