Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # GUI module generated by PAGE version 4.20
- # in conjunction with Tcl version 8.6
- # Feb 26, 2019 03:41:37 AM PST platform: Windows NT
- import sys
- import subprocess
- import io
- import os
- import threading
- import webbrowser
- import requests
- import random
- from tkinter import filedialog
- from tkinter import messagebox
- try:
- import Tkinter as tk
- except ImportError:
- import tkinter as tk
- try:
- import ttk
- py3 = False
- except ImportError:
- import tkinter.ttk as ttk
- py3 = True
- def vp_start_gui():
- '''Starting point when module is the main routine.'''
- global val, w, root
- root = tk.Tk()
- root.iconbitmap("grabbitbunny.ico")
- top = MainWindow(root)
- root.mainloop()
- w = None
- def create_MainWindow(root, *args, **kwargs):
- '''Starting point when module is imported by another program.'''
- global w, w_win, rt
- rt = root
- w = tk.Toplevel(root)
- top = MainWindow(w)
- return (w, top)
- def destroy_MainWindow():
- global w
- w.destroy()
- w = None
- class MainWindow:
- def __init__(self, top=None):
- currentDirectory = os.getcwd()
- defFolder = os.path.normpath(os.path.expanduser("~/Documents/Grabbit Downloads"))
- settings = []
- folders = []
- folders.append(defFolder)
- try:
- with open("settings.txt","r") as file:
- for line in file:
- settings.append(line)
- dirs = settings[0]
- if not os.path.exists(dirs):
- os.makedirs(dirs)
- folders = [dirs]
- except FileNotFoundError as e:
- dirs = os.path.normpath(os.path.expanduser("~/Documents/Grabbit Downloads"))
- if not os.path.exists(dirs):
- os.makedirs(dirs)
- except IndexError as e:
- dirs = os.path.normpath(os.path.expanduser("~/Documents/Grabbit Downloads"))
- if not os.path.exists(dirs):
- os.makedirs(dirs)
- folders = [dirs]
- def DownVid(button, *argv):
- def ProcCom(commands):
- process = subprocess.Popen(commands, startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE,stdin=subprocess.DEVNULL, cwd=folders[0]) # pipes commands from if statements into youtube-dl.exe Popen
- for line in io.TextIOWrapper(process.stdout, encoding="utf-8"):
- if len(line) >= 70:
- thl = [line[i:i + 67] for i in range(0, len(line), 67)]
- for bit in thl:
- self.DownloadHistory.insert(tk.END,bit)
- self.DownloadHistory.see(tk.END)
- else:
- self.DownloadHistory.insert(tk.END, line) #line
- self.DownloadHistory.see(tk.END)
- link = self.UrlBox.get()
- startupinfo = None
- if os.name == 'nt':
- startupinfo = subprocess.STARTUPINFO()
- startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
- #TODO move all commands into one central list, each button appends or removes certain entries
- if button == "UP":
- command = ["youtube-dl","--update"]
- ProcCom(command)
- if button == "PV": # PLAYLIST VIDEOS
- reso = str(self.ResoList.get()).replace("p", "")
- if reso == "Best":
- command = ["youtube-dl","--restrict-filenames","--retries","30","--fragment-retries","30","--format", "bestvideo+bestaudio[ext=m4a]",
- "--merge-output-format", "mp4","-o","%(playlist_index)s-%(title)s.%(ext)s",
- link]
- else:
- command = ["youtube-dl","--restrict-filenames","--retries","30","--fragment-retries","30","--format", "bestvideo[height<=%s]+bestaudio[ext=m4a]"%reso,
- "--merge-output-format", "mp4","-o","%(playlist_index)s-%(title)s.%(ext)s",
- link]
- try:
- ProcCom(command)
- self.DownloadHistory.insert(tk.END,
- "---------------------------------------------------------------------")
- except Exception as e:
- self.DownloadHistory.insert(tk.END,e)
- self.DownloadHistory.see(tk.END)
- if button == "PM": # PLAYLIST MUSIC
- command = ["youtube-dl","--restrict-filenames", "--retries", "30", "--fragment-retries", "30", "--add-metadata",
- "--extract-audio", "--audio-format", "mp3", "-o", "%(playlist_index)s-%(title)s.%(ext)s",
- link]
- try:
- ProcCom(command)
- self.DownloadHistory.insert(tk.END,
- "---------------------------------------------------------------------")
- except Exception as e:
- self.DownloadHistory.insert(tk.END,e)
- self.DownloadHistory.see(tk.END)
- if button == "JV": # VIDEO
- reso = str(self.ResoList.get()).replace("p","")
- if reso == "Best":
- command = ["youtube-dl","--restrict-filenames", "--retries", "30", "--fragment-retries", "30", "--format",
- "bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio",
- "--merge-output-format", "mp4",
- r"-o %(title)s.%(ext)s", link]
- else:
- command = ["youtube-dl","--restrict-filenames", "--retries", "30", "--fragment-retries", "30", "--format",
- "bestvideo[height<=%s]+bestaudio[ext=m4a]"%reso, "--merge-output-format", "mp4",
- r"-o %(title)s.%(ext)s", link]
- try:
- ProcCom(command)
- self.DownloadHistory.insert(tk.END,
- "---------------------------------------------------------------------")
- except Exception as e:
- self.DownloadHistory.insert(tk.END,e)
- self.DownloadHistory.see(tk.END)
- if button == "JM": # MUSIC
- command = ["youtube-dl","--restrict-filenames", "--retries", "30", "--fragment-retries", "30", "--add-metadata",
- "--extract-audio", "--audio-format", "mp3", "-o", "%(title)s.%(ext)s", link]
- try:
- ProcCom(command)
- self.DownloadHistory.insert(tk.END,
- "---------------------------------------------------------------------")
- except Exception as e:
- self.DownloadHistory.insert(tk.END,e)
- self.DownloadHistory.see(tk.END)
- def TDownVid(button):
- threading.Thread(target=DownVid(button)).start()
- def GetVideo():
- TDownVid("JV")
- def TGetVideo():
- threading.Thread(target=GetVideo).start()
- def GetSong():
- TDownVid("JM")
- def TGetSong():
- threading.Thread(target=GetSong).start()
- #TODO fix update youtube-dl in executable
- def UpdateYT():
- startupinfo=None
- doit=["Youtube-dl","--update"]
- response = messagebox.askyesno("Please confirm","Are you sure you would like to update youtube-dl?")
- if response == True:
- process = subprocess.Popen(doit, startupinfo=startupinfo, stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.DEVNULL,
- cwd=os.getcwd()) # pipes commands from if statements into youtube-dl.exe
- for line in io.TextIOWrapper(process.stdout, encoding="utf-8"):
- self.DownloadHistory.insert(tk.END, line)
- self.DownloadHistory.see(tk.END)
- else:
- pass
- def FileDirec(*argv):
- my_filetypes = [('all files', '.*'), ('text files', '.txt')]
- answer = filedialog.askdirectory(parent=root,
- initialdir=os.path.join(folders[0]),
- title="Please select a folder:")
- del folders[:]
- folders.append(answer)
- self.DownloadHistory.insert(tk.END,"Saving to %s"%answer)
- self.DownloadHistory.insert(tk.END,
- "---------------------------------------------------------------------")
- self.DownloadHistory.see(tk.END)
- def FileDirecDef(*argv):
- folder = filedialog.askdirectory(parent=root,
- initialdir=os.path.join(defFolder),
- title="Please select default save location")
- with open("settings.txt","w") as file:
- file.seek(0)
- file.write(folder)
- file.close
- del folders[:]
- folders.append(folder)
- self.DownloadHistory.insert(tk.END, folder)
- self.DownloadHistory.insert(tk.END,
- "---------------------------------------------------------------------")
- def OpenFolder(*argv):
- answers = r"%s" % folders[0]
- os.startfile(answers)
- def GrabGitHub(*argv):
- webbrowser.open_new_tab("https://github.com/TrashRat/Grabbit")
- def YTDLGitHub(*argv):
- webbrowser.open_new_tab("https://github.com/ytdl-org/youtube-dl")
- def SupportedWebsites(*argv):
- webbrowser.open_new_tab("http://ytdl-org.github.io/youtube-dl/supportedsites.html")
- def UpdateGrabbit(*argv):
- def download_file_from_google_drive(id, destination):
- URL = "https://docs.google.com/uc?export=download"
- session = requests.Session()
- response = session.get(URL, params={'id': id}, stream=True)
- token = get_confirm_token(response)
- if token:
- params = {'id': id, 'confirm': token}
- response = session.get(URL, params=params, stream=True)
- save_response_content(response, destination)
- def get_confirm_token(response):
- for key, value in response.cookies.items():
- if key.startswith('download_warning'):
- return value
- return None
- def save_response_content(response, destination):
- CHUNK_SIZE = 32768
- with open(destination, "wb") as f:
- for chunk in response.iter_content(CHUNK_SIZE):
- if chunk: # filter out keep-alive new chunks
- f.write(chunk)
- file_id = '1trxQXYtcNGfZQZbno96TK5ZUYJgaTsra'
- destination = os.getcwd() + "\\Grabbit-{}.exe".format(random.randint(0,999))
- response = messagebox.askyesno("Please confirm","Are you sure you would like to update Grabbit?")
- if response == True:
- self.DownloadHistory.insert(tk.END,"Updating Grabbit...this window will freeze as the update is downloaded")
- download_file_from_google_drive(file_id, destination)
- self.DownloadHistory.insert(tk.END,"Grabbit Updated! Please close this window and delete old executable")
- else:
- pass
- def popupmsg(*argv):
- def vp_start_gui():
- '''Starting point when module is the main routine.'''
- global val, w, roott
- roott = tk.Tk()
- top = PlaylistMenu(roott)
- roott.mainloop()
- w = None
- class PlaylistMenu:
- def __init__(self, top=None):
- def DestroyWinV():
- roott.destroy()
- TDownVid("PV") # FLAGS TO CALL WHICH BUTTON IS BEING PRESSED
- def TDestroyWinV():
- threading.Thread(target=DestroyWinV).start()
- def DestroyWinM():
- roott.destroy()
- TDownVid("PM")
- def TDestroyWinM():
- threading.Thread(target=DestroyWinM).start()
- '''This class configures and populates the toplevel window.
- top is the toplevel containing window.'''
- _bgcolor = '#d9d9d9' # X11 color: 'gray85'
- _fgcolor = '#000000' # X11 color: 'black'
- _compcolor = '#d9d9d9' # X11 color: 'gray85'
- _ana1color = '#d9d9d9' # X11 color: 'gray85'
- _ana2color = '#ececec' # Closest X11 color: 'gray92'
- top.geometry("136x89+713+366")
- top.title("")
- top.configure(background="#d9d9d9")
- self.VidPlaylist = tk.Radiobutton(top)
- self.VidPlaylist.place(relx=0.147, rely=0.112, relheight=0.393
- , relwidth=0.721)
- self.VidPlaylist.configure(activebackground="#ececec")
- self.VidPlaylist.configure(activeforeground="#000000")
- self.VidPlaylist.configure(background="#d9d9d9")
- self.VidPlaylist.configure(disabledforeground="#a3a3a3")
- self.VidPlaylist.configure(foreground="#000000")
- self.VidPlaylist.configure(highlightbackground="#d9d9d9")
- self.VidPlaylist.configure(highlightcolor="black")
- self.VidPlaylist.configure(justify='left')
- self.VidPlaylist.configure(text='''Video Playlist''')
- self.VidPlaylist.configure(width=98)
- self.VidPlaylist.configure(command=TDestroyWinV)
- self.MusicPlaylist = tk.Radiobutton(top)
- self.MusicPlaylist.place(relx=0.147, rely=0.449, relheight=0.393
- , relwidth=0.735)
- self.MusicPlaylist.configure(activebackground="#ececec")
- self.MusicPlaylist.configure(activeforeground="#000000")
- self.MusicPlaylist.configure(background="#d9d9d9")
- self.MusicPlaylist.configure(disabledforeground="#a3a3a3")
- self.MusicPlaylist.configure(foreground="#000000")
- self.MusicPlaylist.configure(highlightbackground="#d9d9d9")
- self.MusicPlaylist.configure(highlightcolor="black")
- self.MusicPlaylist.configure(justify='left')
- self.MusicPlaylist.configure(text='''Music Playlist''')
- self.MusicPlaylist.configure(width=100)
- self.MusicPlaylist.configure(command=TDestroyWinM)
- if __name__ == '__main__':
- vp_start_gui()
- '''This class configures and populates the toplevel window.
- top is the toplevel containing window.'''
- _bgcolor = '#d9d9d9' # X11 color: 'gray85'
- _fgcolor = '#000000' # X11 color: 'black'
- _compcolor = '#d9d9d9' # X11 color: 'gray85'
- _ana1color = '#d9d9d9' # X11 color: 'gray85'
- _ana2color = '#ececec' # Closest X11 color: 'gray92'
- self.style = ttk.Style()
- if sys.platform == "win32":
- self.style.theme_use('winnative')
- self.style.configure('.', background=_bgcolor)
- self.style.configure('.', foreground=_fgcolor)
- self.style.configure('.', font="TkDefaultFont")
- self.style.map('.', background=
- [('selected', _compcolor), ('active', _ana2color)])
- top.geometry("584x280+769+298")
- top.title("Grabbit - Downloading made easy")
- top.configure(background="#d9d9d9") # BG COLOR
- top.configure(highlightbackground="#d9d9d9")
- top.configure(highlightcolor="black")
- self.DownloadHistory = ScrolledListBox(top)
- self.DownloadHistory.place(relx=0.017, rely=0.268, relheight=0.696
- , relwidth=0.962)
- self.DownloadHistory.configure(background="white")
- self.DownloadHistory.configure(disabledforeground="#a3a3a3")
- self.DownloadHistory.configure(font="TkFixedFont")
- self.DownloadHistory.configure(foreground="black")
- self.DownloadHistory.configure(highlightbackground="#d9d9d9")
- self.DownloadHistory.configure(highlightcolor="#d9d9d9")
- self.DownloadHistory.configure(selectbackground="#c4c4c4")
- self.DownloadHistory.configure(selectforeground="black")
- self.DownloadHistory.configure(width=10)
- self.menubar = tk.Menu(top, font="TkMenuFont", bg=_bgcolor, fg=_fgcolor)
- top.configure(menu=self.menubar)
- self.sub_menu = tk.Menu(top, tearoff=0)
- self.menubar.add_cascade(menu=self.sub_menu,
- activebackground="#ececec",
- activeforeground="#000000",
- background="#d9d9d9",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Settings")
- self.sub_menu.add_command(
- activebackground="#d9d9d9",
- activeforeground="#000000",
- background="#ececec",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Set default save location",
- command=FileDirecDef)
- self.sub_menu.add_command(
- activebackground="#d9d9d9",
- activeforeground="#000000",
- background="#ececec",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Update Grabbit",
- command=UpdateGrabbit)
- self.sub_menu.add_command(
- activebackground="#d9d9d9",
- activeforeground="#000000",
- background="#ececec",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Update youtube-dl",
- command=UpdateYT)
- self.about_menu = tk.Menu(top, tearoff=0)
- self.menubar.add_cascade(menu=self.about_menu,
- activebackground="#ececec",
- activeforeground="#000000",
- background="#d9d9d9",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="About")
- self.about_menu.add_command(
- activebackground="#d9d9d9",
- activeforeground="#000000",
- background="#ececec",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Supported websites",
- command=SupportedWebsites)
- self.about_menu.add_command(
- activebackground="#d9d9d9",
- activeforeground="#000000",
- background="#ececec",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Grabbit GitHub",
- command=GrabGitHub)
- self.about_menu.add_command(
- activebackground="#d9d9d9",
- activeforeground="#000000",
- background="#ececec",
- compound="left",
- font="TkMenuFont",
- foreground="#000000",
- label="Youtube-dl GitHub",
- command=YTDLGitHub)
- self.UrlBox = ttk.Entry(top)
- self.UrlBox.place(relx=0.017, rely=0.018, relheight=0.075
- , relwidth=0.725)
- self.UrlBox.configure(takefocus="")
- self.UrlBox.configure(cursor="ibeam")
- self.ResoList = ttk.Combobox(root,values=("144p", "240p", "480p", "720p", "1080p", "Best"))
- self.ResoList.place(relx=0.736, rely=0.018, relheight=0.075
- , relwidth=0.108)
- self.ResoList.configure(takefocus="",state="readonly")
- self.ResoList.current(5)
- self.DVideo = tk.Button(top)
- self.DVideo.place(relx=0.017, rely=0.125, height=34, width=147)
- self.DVideo.configure(activebackground="#ececec")
- self.DVideo.configure(activeforeground="#000000")
- self.DVideo.configure(background="#d9d9d9")
- self.DVideo.configure(disabledforeground="#a3a3a3")
- self.DVideo.configure(foreground="#000000")
- self.DVideo.configure(highlightbackground="#d9d9d9")
- self.DVideo.configure(highlightcolor="black")
- self.DVideo.configure(pady="0")
- self.DVideo.configure(relief='groove')
- self.DVideo.configure(text='''Download Video''')
- self.DVideo.configure(width=147)
- self.DVideo.configure(command=TGetVideo)
- self.DSong = tk.Button(top)
- self.DSong.place(relx=0.291, rely=0.125, height=34, width=147)
- self.DSong.configure(activebackground="#ececec")
- self.DSong.configure(activeforeground="#000000")
- self.DSong.configure(background="#d9d9d9")
- self.DSong.configure(disabledforeground="#a3a3a3")
- self.DSong.configure(foreground="#000000")
- self.DSong.configure(highlightbackground="#d9d9d9")
- self.DSong.configure(highlightcolor="black")
- self.DSong.configure(pady="0")
- self.DSong.configure(relief='groove')
- self.DSong.configure(text='''Download Song''')
- self.DSong.configure(command=TGetSong)
- self.DPlaylist = tk.Button(top)
- self.DPlaylist.place(relx=0.565, rely=0.125, height=34, width=147)
- self.DPlaylist.configure(activebackground="#ececec")
- self.DPlaylist.configure(activeforeground="#000000")
- self.DPlaylist.configure(background="#d9d9d9")
- self.DPlaylist.configure(disabledforeground="#a3a3a3")
- self.DPlaylist.configure(foreground="#000000")
- self.DPlaylist.configure(highlightbackground="#d9d9d9")
- self.DPlaylist.configure(highlightcolor="black")
- self.DPlaylist.configure(pady="0")
- self.DPlaylist.configure(relief='groove')
- self.DPlaylist.configure(text='''Download Playlist''')
- self.DPlaylist.configure(command=popupmsg)
- self.OpnFoldr = tk.Button(top)
- self.OpnFoldr.place(relx=0.856, rely=0.125, height=34, width=77)
- self.OpnFoldr.configure(activebackground="#ececec")
- self.OpnFoldr.configure(activeforeground="#000000")
- self.OpnFoldr.configure(background="#d9d9d9")
- self.OpnFoldr.configure(disabledforeground="#a3a3a3")
- self.OpnFoldr.configure(foreground="#000000")
- self.OpnFoldr.configure(highlightbackground="#d9d9d9")
- self.OpnFoldr.configure(highlightcolor="black")
- self.OpnFoldr.configure(pady="0")
- self.OpnFoldr.configure(relief='groove')
- self.OpnFoldr.configure(text='''Open Folder''')
- self.OpnFoldr.configure(width=77)
- self.OpnFoldr.configure(command=OpenFolder)
- self.SaveTo = tk.Button(top)
- self.SaveTo.place(relx=0.856, rely=0.018, height=24, width=77)
- self.SaveTo.configure(activebackground="#ececec")
- self.SaveTo.configure(activeforeground="#000000")
- self.SaveTo.configure(background="#d9d9d9")
- self.SaveTo.configure(disabledforeground="#a3a3a3")
- self.SaveTo.configure(foreground="#000000")
- self.SaveTo.configure(highlightbackground="#d9d9d9")
- self.SaveTo.configure(highlightcolor="black")
- self.SaveTo.configure(pady="0")
- self.SaveTo.configure(relief='groove')
- self.SaveTo.configure(text='''Save to...''')
- self.SaveTo.configure(width=77)
- self.SaveTo.configure(command=FileDirec)
- # The following code is added to facilitate the Scrolled widgets specified.
- class AutoScroll(object):
- '''Configure the scrollbars for a widget.'''
- def __init__(self, master):
- # Rozen. Added the try-except clauses so that this class
- # could be used for scrolled entry widget for which vertical
- # scrolling is not supported. 5/7/14.
- try:
- vsb = ttk.Scrollbar(master, orient='vertical', command=self.yview)
- except:
- pass
- hsb = ttk.Scrollbar(master, orient='horizontal', command=self.xview)
- # self.configure(yscrollcommand=_autoscroll(vsb),
- # xscrollcommand=_autoscroll(hsb))
- try:
- self.configure(yscrollcommand=self._autoscroll(vsb))
- except:
- pass
- self.configure(xscrollcommand=self._autoscroll(hsb))
- self.grid(column=0, row=0, sticky='nsew')
- try:
- vsb.grid(column=1, row=0, sticky='ns')
- except:
- pass
- hsb.grid(column=0, row=1, sticky='ew')
- master.grid_columnconfigure(0, weight=1)
- master.grid_rowconfigure(0, weight=1)
- # Copy geometry methods of master (taken from ScrolledText.py)
- if py3:
- methods = tk.Pack.__dict__.keys() | tk.Grid.__dict__.keys() \
- | tk.Place.__dict__.keys()
- else:
- methods = tk.Pack.__dict__.keys() + tk.Grid.__dict__.keys() \
- + tk.Place.__dict__.keys()
- for meth in methods:
- if meth[0] != '_' and meth not in ('config', 'configure'):
- setattr(self, meth, getattr(master, meth))
- @staticmethod
- def _autoscroll(sbar):
- '''Hide and show scrollbar as needed.'''
- def wrapped(first, last):
- first, last = float(first), float(last)
- if first <= 0 and last >= 1:
- sbar.grid_remove()
- else:
- sbar.grid()
- sbar.set(first, last)
- return wrapped
- def __str__(self):
- return str(self.master)
- def _create_container(func):
- '''Creates a ttk Frame with a given master, and use this new frame to
- place the scrollbars and the widget.'''
- def wrapped(cls, master, **kw):
- container = ttk.Frame(master)
- container.bind('<Enter>', lambda e: _bound_to_mousewheel(e, container))
- container.bind('<Leave>', lambda e: _unbound_to_mousewheel(e, container))
- return func(cls, container, **kw)
- return wrapped
- class ScrolledListBox(AutoScroll, tk.Listbox):
- '''A standard Tkinter Text widget with scrollbars that will
- automatically show/hide as needed.'''
- @_create_container
- def __init__(self, master, **kw):
- tk.Listbox.__init__(self, master, **kw)
- AutoScroll.__init__(self, master)
- import platform
- def _bound_to_mousewheel(event, widget):
- child = widget.winfo_children()[0]
- if platform.system() == 'Windows' or platform.system() == 'Darwin':
- child.bind_all('<MouseWheel>', lambda e: _on_mousewheel(e, child))
- child.bind_all('<Shift-MouseWheel>', lambda e: _on_shiftmouse(e, child))
- else:
- child.bind_all('<Button-4>', lambda e: _on_mousewheel(e, child))
- child.bind_all('<Button-5>', lambda e: _on_mousewheel(e, child))
- child.bind_all('<Shift-Button-4>', lambda e: _on_shiftmouse(e, child))
- child.bind_all('<Shift-Button-5>', lambda e: _on_shiftmouse(e, child))
- def _unbound_to_mousewheel(event, widget):
- if platform.system() == 'Windows' or platform.system() == 'Darwin':
- widget.unbind_all('<MouseWheel>')
- widget.unbind_all('<Shift-MouseWheel>')
- else:
- widget.unbind_all('<Button-4>')
- widget.unbind_all('<Button-5>')
- widget.unbind_all('<Shift-Button-4>')
- widget.unbind_all('<Shift-Button-5>')
- def _on_mousewheel(event, widget):
- if platform.system() == 'Windows':
- widget.yview_scroll(-1 * int(event.delta / 120), 'units')
- elif platform.system() == 'Darwin':
- widget.yview_scroll(-1 * int(event.delta), 'units')
- else:
- if event.num == 4:
- widget.yview_scroll(-1, 'units')
- elif event.num == 5:
- widget.yview_scroll(1, 'units')
- def _on_shiftmouse(event, widget):
- if platform.system() == 'Windows':
- widget.xview_scroll(-1 * int(event.delta / 120), 'units')
- elif platform.system() == 'Darwin':
- widget.xview_scroll(-1 * int(event.delta), 'units')
- else:
- if event.num == 4:
- widget.xview_scroll(-1, 'units')
- elif event.num == 5:
- widget.xview_scroll(1, 'units')
- if __name__ == '__main__':
- vp_start_gui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement