From 3364694f14f8a0b92ce70ca608a73966c4043256 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 24 Dec 2020 04:56:55 -0700 Subject: switch from wxpython to tkinter --- vidslice.py | 164 ++++++++++++++++++++++++------------------------------------ 1 file changed, 65 insertions(+), 99 deletions(-) (limited to 'vidslice.py') diff --git a/vidslice.py b/vidslice.py index dc37412..632e426 100644 --- a/vidslice.py +++ b/vidslice.py @@ -1,10 +1,9 @@ import json import subprocess -import sys import urllib.request - -import wx -import wx.adv +from tkinter import * +from tkinter import messagebox +from tkinter import ttk from options import OptionsPanel from output import OutputPanel @@ -19,8 +18,9 @@ def check_update(parent): latest_release_obj = json.load(latest_release_response) newest_version = latest_release_obj['tag_name'].lstrip('v') if VERSION != newest_version: - answer = wx.MessageBox("vidslice update available. download?", "Update", wx.YES_NO, parent) - if answer == wx.YES: + open_update = messagebox.askyesno(message="vidslice update available. download?", title="Update", + parent=parent) + if open_update: import webbrowser webbrowser.open("https://github.com/boringcactus/vidslice/releases/latest") @@ -35,118 +35,84 @@ def has_ffmpeg(): return False -class VidsliceFrame(wx.Frame): - """ - A Frame that contains vidslice logic - """ - - def __init__(self, *args, **kw): - # ensure the parent's __init__ is called - super(VidsliceFrame, self).__init__(*args, **kw) +class VidsliceFrame: + def __init__(self, root: Tk): + self.root = root + root.title('vidslice') - root_sizer = wx.BoxSizer(wx.VERTICAL) - self.SetSizer(root_sizer) - main = wx.Panel(self) - root_sizer.Add(main, proportion=1, flag=wx.EXPAND, border=5) - main_sizer = wx.GridBagSizer(5, 5) - main.SetSizer(main_sizer) + mainframe = ttk.Frame(root, padding="3 3 12 12") + mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) + root.columnconfigure(0, weight=1) + root.rowconfigure(0, weight=1) # set up sources panel - self.sources_panel = SourcesPanel(main) - main_sizer.Add(self.sources_panel, wx.GBPosition(0, 0), wx.GBSpan(1, 2), flag=wx.EXPAND) + self.sources_panel = SourcesPanel(mainframe) + self.sources_panel.grid(column=0, row=0, columnspan=2, sticky=(W, E), padx=5, pady=5) # set up options panel - self.options_panel = OptionsPanel(main) - main_sizer.Add(self.options_panel, wx.GBPosition(1, 0), flag=wx.EXPAND) - main_sizer.AddGrowableRow(1, proportion=1) - self.sources_panel.on_update(self.options_panel.update) + self.options_panel = OptionsPanel(mainframe) + self.options_panel.grid(column=0, row=1, sticky=(W, E, N), padx=5, pady=5) + mainframe.rowconfigure(1, weight=1) + self.sources_panel.on_update(self.options_panel.update_info) # set up output panel - self.output_panel = OutputPanel(main, get_ffmpeg_args=self.options_panel.ffmpeg_opts) - main_sizer.Add(self.output_panel, wx.GBPosition(1, 1), flag=wx.EXPAND) - main_sizer.AddGrowableCol(1, proportion=1) + self.output_panel = OutputPanel(mainframe, get_ffmpeg_args=self.options_panel.ffmpeg_opts, + get_frame_count=self.options_panel.frame_count) + self.output_panel.grid(column=1, row=1, sticky=(W, E, N, S), padx=5, pady=5) + mainframe.columnconfigure(1, weight=1) self.sources_panel.on_update(lambda data: self.output_panel.set_input_path(self.sources_panel.get_file(), data)) # create a menu bar - self.make_menu_bar() - - size = root_sizer.GetMinSize() - self.SetMinClientSize(size) + self.make_menu_bar(root) if len(sys.argv) > 1: self.sources_panel.file_text.SetValue(sys.argv[1]) - def make_menu_bar(self): - """ - A menu bar is composed of menus, which are composed of menu items. - This method builds a set of menus and binds handlers to be called - when the menu item is selected. - """ - - # Make a file menu with Hello and Exit items - file_menu = wx.Menu() - # The "\t..." syntax defines an accelerator key that also triggers - # the same event - update_item = file_menu.Append(-1, "Update youtube-dl") - file_menu.AppendSeparator() - # When using a stock ID we don't need to specify the menu item's - # label - exit_item = file_menu.Append(wx.ID_EXIT) - - # Now a help menu for the about item - help_menu = wx.Menu() - about_item = help_menu.Append(wx.ID_ABOUT) - - # Make the menu bar and add the two menus to it. The '&' defines - # that the next letter is the "mnemonic" for the menu item. On the - # platforms that support it those letters are underlined and can be - # triggered from the keyboard. - menu_bar = wx.MenuBar() - menu_bar.Append(file_menu, "&File") - menu_bar.Append(help_menu, "&Help") - - # Give the menu bar to the frame - self.SetMenuBar(menu_bar) - - # Finally, associate a handler function with the EVT_MENU event for - # each of the menu items. That means that when that menu item is - # activated then the associated handler function will be called. - self.Bind(wx.EVT_MENU, self.on_update, update_item) - self.Bind(wx.EVT_MENU, self.on_exit, exit_item) - self.Bind(wx.EVT_MENU, self.on_about, about_item) - - def on_exit(self, event): - """Close the frame, terminating the application.""" - self.Close(True) - - def on_update(self, event): - import threading - threading.Thread(target=update_ytdl, args=(self,)).start() + def make_menu_bar(self, root): + root.option_add('*tearOff', FALSE) - def on_about(self, event): - """Display an About Dialog""" - info = wx.adv.AboutDialogInfo() - info.SetName("vidslice") - info.SetVersion(VERSION) - info.SetDescription("video manipulator wrapping youtube-dl and ffmpeg") - info.SetWebSite("https://github.com/boringcactus/vidslice") + menubar = Menu(root) + root['menu'] = menubar - wx.adv.AboutBox(info) + file_menu = Menu(menubar) + menubar.add_cascade(menu=file_menu, label='File', underline=0) + file_menu.add_command(label="Update youtube-dl", command=self.on_update, underline=0) + file_menu.add_separator() + file_menu.add_command(label='Exit', command=self.on_exit, underline=1) + help_menu = Menu(menubar) + menubar.add_cascade(menu=help_menu, label='Help', underline=0) + help_menu.add_command(label='About', command=self.on_about, underline=0) -if __name__ == '__main__': - # When this module is run (not imported) then create the app, the - # frame, show it, and start the event loop. - app = wx.App() + def on_exit(self, *args): + self.root.destroy() + + def on_update(self, *args): + import threading + threading.Thread(target=update_ytdl, args=(self.root,)).start() + + def on_about(self, *args): + messagebox.showinfo(message=f"vidslice {VERSION}") + + +def check_ffmpeg(root: Tk): if not has_ffmpeg(): - answer = wx.MessageBox("Could not find ffmpeg. Open vidslice README?", "Error", wx.YES_NO, None) - if answer == wx.YES: + open_readme = messagebox.askyesno(message="Could not find ffmpeg. Open vidslice README?", title="Error", + icon='error', parent=root) + if open_readme: import webbrowser webbrowser.open("https://github.com/boringcactus/vidslice/blob/master/README.md") - else: - frm = VidsliceFrame(None, title='vidslice') - app.SetTopWindow(frm) - frm.Show() - check_update(frm) - app.MainLoop() + root.after(1000, root.destroy) + + +def main(): + root = Tk() + frame = VidsliceFrame(root) + root.after_idle(check_ffmpeg, root) + root.after(1000, check_update, root) + root.mainloop() + + +if __name__ == '__main__': + main() -- cgit v1.2.3