diff --git a/.gitignore b/.gitignore index fff4177..78aeefe 100644 --- a/.gitignore +++ b/.gitignore @@ -330,4 +330,12 @@ ASALocalRun/ .mfractor/ ## Ignore .nbs files. -*.nbs \ No newline at end of file +*.nbs + +## Ignore other files/folders. +*.ico +*.spec +*.bat +version.* +build/ +dist/ \ No newline at end of file diff --git a/main.py b/main.py index c2e9acd..3554039 100644 --- a/main.py +++ b/main.py @@ -1,30 +1,32 @@ import sys, operator, webbrowser -from time import sleep -from random import randrange +import tkinter as tk +import tkinter.ttk as ttk -#from tkinter import * -from tkinter import Tk, Menu, Frame, LabelFrame, Button, Label, Message, \ -Checkbutton, Entry, Text, IntVar, StringVar, messagebox, END, Toplevel -from tkinter.ttk import Button, Style, Notebook, Progressbar, Combobox from tkinter.filedialog import askopenfilename, asksaveasfilename from tkinter.scrolledtext import ScrolledText +from time import sleep +from random import randrange +from pprint import pprint + from attr import Attr from nbsio import opennbs, writenbs #sys.stdout = open('main_log.txt', 'w') -class MainWindow(Frame): +class MainWindow(tk.Frame): def __init__(self, parent): - Frame.__init__(self, parent) + tk.Frame.__init__(self, parent) self.parent = parent self.properties() self.elements() self.WindowBind() self.UpdateVar(True) + self.update() self.pack(fill='both', expand=True) - WindowGeo(self.parent, self.parent, width=800, height=500) + self.update() + WindowGeo(self.parent, self.parent, 800, 500, 600, 500) def properties(self): self.filePath = None @@ -35,61 +37,65 @@ def properties(self): def elements(self): self.parent.title("NBS Tool") - self.style = Style() + self.style = ttk.Style() self.style.theme_use("default") #Menu bar - self.menuBar = Menu(self) + self.menuBar = tk.Menu(self) self.parent.config(menu=self.menuBar) self.menus() #Tabs - self.NbTabs = Notebook(self, padding=(0, 10, 0, 10)) + self.NbTabs = ttk.Notebook(self) self.tabs() - self.NbTabs.pack(expand=True, fill='both') + self.NbTabs.pack(fill='both', expand=True) #Footer - self.footer = Frame(self, relief='groove', borderwidth=1, height=30) + tk.Frame(self, height=5).pack() + + self.footer = tk.Frame(self, relief='groove', borderwidth=1, height=25) + self.footer.pack_propagate(False) self.footer.pack(fill='x') - self.footerElements() def menus(self): # 'File' menu - self.fileMenu = Menu(self.menuBar, tearoff=False) + self.fileMenu = tk.Menu(self.menuBar, tearoff=False) self.menuBar.add_cascade(label="File", menu=self.fileMenu) - self.fileMenu.add_command(label="Open", command = lambda: self.OnBrowseFile(True)) - self.fileMenu.add_command(label="Save", command=self.OnSaveFile) - self.fileMenu.add_command(label="Save as new file", command = lambda: self.OnSaveFile(True)) + self.fileMenu.add_command(label="Open", accelerator="Ctrl+O", command = lambda: self.OnBrowseFile(True)) + self.fileMenu.add_command(label="Save", accelerator="Ctrl+S", command=self.OnSaveFile) + self.fileMenu.add_command(label="Save as new file", accelerator="Ctrl+Shift+S", command = lambda: self.OnSaveFile(True)) + self.fileMenu.add_separator() + self.fileMenu.add_command(label="Quit", accelerator="Esc", command=self.parent.destroy) - self.helpMenu = Menu(self.menuBar, tearoff=False) + self.helpMenu = tk.Menu(self.menuBar, tearoff=False) self.menuBar.add_cascade(label="Help", menu=self.helpMenu) self.helpMenu.add_command(label="About", command=lambda: AboutWindow(self)) def tabs(self): #"General" tab - self.GeneralTab = Frame(self.NbTabs) + self.GeneralTab = tk.Frame(self.NbTabs) - self.GeneralTab.rowconfigure(0, pad=3) - self.GeneralTab.rowconfigure(1, pad=3, weight=1) + self.GeneralTab.rowconfigure(0) + self.GeneralTab.rowconfigure(1, weight=1) - self.GeneralTab.columnconfigure(0, pad=3, weight=1, uniform='a') - self.GeneralTab.columnconfigure(1, pad=3, weight=1, uniform='a') + self.GeneralTab.columnconfigure(0, weight=1, uniform='a') + self.GeneralTab.columnconfigure(1, weight=1, uniform='a') self.GeneralTabElements() self.NbTabs.add(self.GeneralTab, text="General") #"Tools" tab - self.ToolsTab = Frame(self.NbTabs) + self.ToolsTab = tk.Frame(self.NbTabs) - self.ToolsTab.rowconfigure(0, pad=3, weight=1, uniform='b') - self.ToolsTab.rowconfigure(1, pad=3, weight=1, uniform='b') - self.ToolsTab.rowconfigure(2, pad=3) + self.ToolsTab.rowconfigure(0, weight=1, uniform='b') + self.ToolsTab.rowconfigure(1, weight=1, uniform='b') + self.ToolsTab.rowconfigure(2) - self.ToolsTab.columnconfigure(0, pad=3, weight=1, uniform='b') - self.ToolsTab.columnconfigure(1, pad=3, weight=1, uniform='b') + self.ToolsTab.columnconfigure(0, weight=1, uniform='b') + self.ToolsTab.columnconfigure(1, weight=1, uniform='b') self.ToolsTabElements() self.NbTabs.add(self.ToolsTab, text="Tools") @@ -98,37 +104,35 @@ def GeneralTabElements(self): padx, pady = 5, 5 #"Open file" frame - self.OpenFileFrame = Frame(self.GeneralTab, relief='ridge', borderwidth=1) + self.OpenFileFrame = tk.Frame(self.GeneralTab, relief='ridge', borderwidth=1) self.OpenFileFrame.grid(row=0, columnspan=2, sticky='ew') - self.OpenFileLabel = Label(self.OpenFileFrame, text="Open file:", anchor='w', width=8) + self.OpenFileLabel = tk.Label(self.OpenFileFrame, text="Open file:", anchor='w', width=8) self.OpenFileLabel.pack(side='left', padx=padx, pady=pady) - self.OpenFileEntry = Entry(self.OpenFileFrame) + self.OpenFileEntry = tk.Entry(self.OpenFileFrame) self.OpenFileEntry.pack(side='left', fill='x', padx=padx, expand=True) - self.BrowseFileButton = Button(self.OpenFileFrame, text="Browse", command = lambda: self.OnBrowseFile() ) + self.BrowseFileButton = ttk.Button(self.OpenFileFrame, text="Browse", command = lambda: self.OnBrowseFile() ) self.BrowseFileButton.pack(side='left', padx=padx, pady=pady) - self.OpenFileButton = Button(self.OpenFileFrame, text="Open", command = lambda: self.OnOpenFile('', True) ) + self.OpenFileButton = ttk.Button(self.OpenFileFrame, text="Open", command = lambda: self.OnOpenFile('', True) ) self.OpenFileButton.pack(side='left', padx=padx, pady=pady) lfp = 10 #File metadata frame - self.FileMetaFrame = LabelFrame(self.GeneralTab, text="Metadata") + self.FileMetaFrame = tk.LabelFrame(self.GeneralTab, text="Metadata") self.FileMetaFrame.grid(row=1, column=0, padx=lfp, pady=lfp, sticky='nsew') - self.FileMetaMess = Message(self.FileMetaFrame, text="No flie was found.") - self.FileMetaMess.bind("", lambda e: self.FileMetaMess.configure(width=e.width-10)) + self.FileMetaMess = tk.Message(self.FileMetaFrame, text="No flie was found.") self.FileMetaMess.pack(fill='both', expand=True, padx=padx, pady=padx) #More infomation frame - self.FileInfoFrame = LabelFrame(self.GeneralTab, text="Infomations") + self.FileInfoFrame = tk.LabelFrame(self.GeneralTab, text="Infomations") self.FileInfoFrame.grid(row=1, column=1, padx=lfp, pady=lfp, sticky='nsew') - self.FileInfoMess = Message(self.FileInfoFrame, text="No flie was found.") - self.FileInfoMess.bind("", lambda e: self.FileInfoMess.configure(width=e.width-10)) + self.FileInfoMess = tk.Message(self.FileInfoFrame, text="No flie was found.") self.FileInfoMess.pack(fill='both', expand=True, padx=padx, pady=pady) def ToolsTabElements(self): @@ -136,83 +140,115 @@ def ToolsTabElements(self): padx, pady = 5, 0 #Flip tool - self.FlipToolFrame = LabelFrame(self.ToolsTab, text="Flipping") + self.FlipToolFrame = tk.LabelFrame(self.ToolsTab, text="Flipping") self.FlipToolFrame.grid(row=0, column=0, sticky='nsew', padx=fpadx, pady=fpady) - self.FlipToolMess = Message(self.FlipToolFrame, anchor='w', text="Flip the note sequence horizontally (by tick), vertically (by layer) or both: ") - self.FlipToolMess.bind("", lambda e: self.FlipToolMess.configure(width=e.width-10)) + self.FlipToolMess = tk.Message(self.FlipToolFrame, anchor='w', text="Flip the note sequence horizontally (by tick), vertically (by layer) or both: ") self.FlipToolMess.pack(fill='both', expand=True, padx=padx, pady=pady) - self.var.tool.flip.vertical = IntVar() - self.FilpToolCheckV = Checkbutton(self.FlipToolFrame, text="Vertically", variable=self.var.tool.flip.vertical) + self.var.tool.flip.vertical = tk.IntVar() + self.FilpToolCheckV = tk.Checkbutton(self.FlipToolFrame, text="Vertically", variable=self.var.tool.flip.vertical) self.FilpToolCheckV.pack(side='left', padx=padx, pady=pady) - self.var.tool.flip.horizontal = IntVar() - self.FilpToolCheckH = Checkbutton(self.FlipToolFrame, text="Horizontally", variable=self.var.tool.flip.horizontal) + self.var.tool.flip.horizontal = tk.IntVar() + self.FilpToolCheckH = tk.Checkbutton(self.FlipToolFrame, text="Horizontally", variable=self.var.tool.flip.horizontal) self.FilpToolCheckH.pack(side='left', padx=padx, pady=pady) #Instrument tool - self.InstToolFrame = LabelFrame(self.ToolsTab, text="Note's instrument") + self.InstToolFrame = tk.LabelFrame(self.ToolsTab, text="Note's instrument") self.InstToolFrame.grid(row=0, column=1, sticky='nsew', padx=fpadx, pady=fpady) - self.InstToolMess = Message(self.InstToolFrame, anchor='w', text="Change all note's instrument to:") - self.InstToolMess.bind("", lambda e: self.InstToolMess.configure(width=e.width-10)) + self.InstToolMess = tk.Message(self.InstToolFrame, anchor='w', text="Change all note's instrument to:") self.InstToolMess.pack(fill='both', expand=True, padx=padx, pady=pady) self.var.tool.inst = ["Harp (piano)" ,"Double Bass" ,"Bass Drum" ,"Snare Drum" ,"Click" ,"Guitar" ,"Flute" ,"Bell" ,"Chime" ,"Xylophone"] self.var.tool.inst.opt = ["(not applied)"] + self.var.tool.inst + ["Random"] - self.InstToolCombox = Combobox(self.InstToolFrame, state='readonly', values=self.var.tool.inst.opt._) + self.InstToolCombox = ttk.Combobox(self.InstToolFrame, state='readonly', values=self.var.tool.inst.opt._) self.InstToolCombox.current(0) self.InstToolCombox.pack(side='left', fill='both' ,expand=True, padx=padx, pady=pady) + #Reduce tool + self.ReduceToolFrame = tk.LabelFrame(self.ToolsTab, text="Reducing") + self.ReduceToolFrame.grid(row=1, column=0, sticky='nsew', padx=fpadx, pady=fpady) + + self.ReduceToolMess = tk.Message(self.ReduceToolFrame, anchor='w', text="Delete as many note as possible to reduce file size.") + self.ReduceToolMess.pack(fill='both', expand=True, padx=padx, pady=pady) + + self.var.tool.reduce.opt1 = tk.IntVar() + self.CompactToolChkOpt1 = FlexCheckbutton(self.ReduceToolFrame, text="Delete duplicate notes", variable=self.var.tool.reduce.opt1, anchor='w') + self.CompactToolChkOpt1.pack(padx=padx, pady=pady) + + self.var.tool.reduce.opt2 = tk.IntVar() + self.CompactToolChkOpt2 = FlexCheckbutton(self.ReduceToolFrame, text=" In every tick, delete all notes except the first note", variable=self.var.tool.reduce.opt2, anchor='w') + self.CompactToolChkOpt2.pack(padx=padx, pady=pady) + + self.var.tool.reduce.opt3 = tk.IntVar() + self.CompactToolChkOpt3 = FlexCheckbutton(self.ReduceToolFrame, text=" In every tick, delete all notes except the last note", variable=self.var.tool.reduce.opt3, anchor='w') + self.CompactToolChkOpt3.pack(padx=padx, pady=(pady, 10)) + #Compact tool - self.CompactToolFrame = LabelFrame(self.ToolsTab, text="Compacting") - self.CompactToolFrame.grid(row=1, column=0, sticky='nsew', padx=fpadx, pady=fpady) + self.CompactToolFrame = tk.LabelFrame(self.ToolsTab, text="Compacting") + self.CompactToolFrame.grid(row=1, column=1, sticky='nsew', padx=fpadx, pady=fpady) - self.CompactToolMess = Message(self.CompactToolFrame, anchor='w', text="Remove spaces between notes vertically (by layer) and group them by instruments.") - self.CompactToolMess.bind("", lambda e: self.CompactToolMess.configure(width=e.width-10)) + self.CompactToolMess = tk.Message(self.CompactToolFrame, anchor='w', text="Remove spaces between notes vertically (by layer) and group them by instruments.") self.CompactToolMess.pack(fill='both', expand=True, padx=padx, pady=pady) - self.var.tool.compact = IntVar() - self.CompactToolCheck = Checkbutton(self.CompactToolFrame, text="Compact notes"+" "*40, variable=self.var.tool.compact, command=self.toggleCompactToolOpt) - self.CompactToolCheck.pack(anchor='w', padx=padx, pady=pady) + self.var.tool.compact = tk.IntVar() + self.CompactToolCheck = FlexCheckbutton(self.CompactToolFrame, text="Compact notes", variable=self.var.tool.compact, command=self.toggleCompactToolOpt, anchor='w') + self.CompactToolCheck.pack(padx=padx, pady=pady) - self.var.tool.compact.opt1 = IntVar() - self.CompactToolOpt1 = Checkbutton(self.CompactToolFrame, text="Automatic separate notes by instruments (remain some spaces)", variable=self.var.tool.compact.opt1, state='disabled', justify='left') - self.CompactToolOpt1.bind("", lambda e: self.CompactToolOpt1.configure(wraplength=e.width-20)) - self.CompactToolOpt1.select() - #print(dir(self.CompactToolOpt1)) - self.CompactToolOpt1.pack(anchor='w', padx=padx*5, pady=pady) + self.var.tool.compact.opt1 = tk.IntVar() + self.CompactToolChkOpt1 = FlexCheckbutton(self.CompactToolFrame, text="Automatic separate notes by instruments (remain some spaces)", variable=self.var.tool.compact.opt1, state='disabled', anchor='w') + self.CompactToolChkOpt1.select() + self.CompactToolChkOpt1.pack(padx=padx*5, pady=pady) #'Apply' botton - self.ToolsTabButton = Button(self.ToolsTab, text="Apply", state='disabled', command = self.OnApplyTool ) + self.ToolsTabButton = ttk.Button(self.ToolsTab, text="Apply", state='disabled', command = self.OnApplyTool ) self.ToolsTabButton.grid(row=2, column=1, sticky='se', padx=fpadx, pady=fpady) - def RawTabElements(self): - self.txt = ScrolledText(self.RawTab) - self.txt.pack(side='left', fill='both', expand=1, padx=10, pady=10) - def footerElements(self): - self.footerLabel = Label(self.footer, text="Footer") + self.footerLabel = tk.Label(self.footer, text="Footer") self.footerLabel.pack(side='left', fill='x') self.var.footerLabel = 0 - self.progressbar = Progressbar(self.footer,orient="horizontal",length=300,mode="determinate") #self.progressbar.pack(side='right') + self.sizegrip = ttk.Sizegrip(self.footer) + self.sizegrip.pack(side='right') + + self.progressbar = ttk.Progressbar(self.footer, orient="horizontal", length=300 ,mode="determinate") self.progressbar["value"] = 0 self.progressbar["maximum"] = 100 #self.progressbar.start() #self.progressbar.stop() def WindowBind(self): - #Buttons - self.master.bind('', lambda _: self.parent.destroy()) - self.master.bind('', lambda _: self.OnBrowseFile(True)) - self.master.bind('', self.OnSaveFile) + #Keys + self.parent.bind('', lambda _: self.parent.destroy()) + self.parent.bind('', lambda _: self.OnBrowseFile(True)) + self.parent.bind('', self.OnSaveFile) + self.parent.bind('', lambda _: self.OnSaveFile(True)) + self.parent.bind('', lambda _: self.OnSaveFile(True)) + #Bind class + self.bind_class("Message" ,"", lambda e: e.widget.configure(width=e.width-10)) + self.bind_class("TButton", "", lambda e: e.widget.invoke()) + self.bind_class("Checkbutton", "", lambda e: e.widget.toggle()) + self.bind_class("Checkbutton", "", lambda e: e.widget.invoke()) + self.bind_class("TCombobox", "", lambda e: e.widget.event_generate('')) + self.bind_class("Entry" ,"", self.popupmenus) + def popupmenus(self, event): + w = event.widget + self.popupMenu = tk.Menu(self, tearoff=False) + self.popupMenu.add_command(label="Select all", accelerator="Ctrl+A", command=lambda: w.event_generate("")) + self.popupMenu.add_separator() + self.popupMenu.add_command(label="Cut", accelerator="Ctrl+X", command=lambda: w.event_generate("")) + self.popupMenu.add_command(label="Copy", accelerator="Ctrl+C", command=lambda: w.event_generate("")) + self.popupMenu.add_command(label="Paste", accelerator="Ctrl+V", command=lambda: w.event_generate("")) + self.popupMenu.tk.call("tk_popup", self.popupMenu, event.x_root, event.y_root) + def OnBrowseFile(self, doOpen=False): types = [('Note Block Studio file', '*.nbs'), ('All files', '*')] filename = askopenfilename(filetypes = types) - self.OpenFileEntry.delete(0,END) + self.OpenFileEntry.delete(0,'end') self.OpenFileEntry.insert(0, filename) if doOpen: self.OnOpenFile(filename, None) @@ -255,27 +291,50 @@ def OnSaveFile(self, saveAsNewFile=False): def toggleCompactToolOpt(self, id=1): if id >= 1: - self.CompactToolOpt1["state"] = "disable" if self.var.tool.compact.get() == 0 else "normal" + self.CompactToolChkOpt1["state"] = "disable" if self.var.tool.compact.get() == 0 else "normal" def OnApplyTool(self): + self.ToolsTabButton['state'] = 'disabled' self.UpdateProgBar(0) data = self.inputFileData - self.UpdateProgBar(20) - applied = flipNotes(data, self.var.tool.flip.vertical.get(), self.var.tool.flip.horizontal.get()) - self.UpdateProgBar(40) + ticklen = data['headers']['length'] + layerlen = data['maxLayer'] instOpti = self.InstToolCombox.current() - if instOpti > 0: - for note in applied['notes']: + self.UpdateProgBar(30) + for i, note in enumerate(data['notes']): + #Flip + if bool(self.var.tool.flip.horizontal.get()): note['tick'] = ticklen - note['tick'] + if bool(self.var.tool.flip.vertical.get()): note['layer'] = layerlen - note['layer'] + + #Instrument change + if instOpti > 0: note['inst'] = randrange(len(self.var.tool.inst)) if instOpti > len(self.var.tool.inst) else instOpti-1 - self.UpdateProgBar(60) - if self.var.tool.compact.get() == 1: applied = compactNotes(applied, self.var.tool.compact.opt1.get(), groupPerc=0) + self.UpdateProgBar(50) + #Reduce + if bool(self.var.tool.reduce.opt2.get()) and bool(self.var.tool.reduce.opt3.get()): + data['notes'] = [note for i, note in enumerate(data['notes']) if note == data['notes'][-1] or note['tick'] != data['notes'][i-1]['tick'] or note['tick'] != data['notes'][i+1]['tick']] + elif bool(self.var.tool.reduce.opt2.get()): + data['notes'] = [note for i, note in enumerate(data['notes']) if note['tick'] != data['notes'][i-1]['tick']] + elif bool(self.var.tool.reduce.opt3.get()): + data['notes'] = [data['notes'][i-1] for i, note in enumerate(data['notes']) if note['tick'] != data['notes'][i-1]['tick']] + self.UpdateProgBar(60) + if bool(self.var.tool.reduce.opt1.get()): + data['notes'] = sorted(data['notes'], key = operator.itemgetter('tick', 'inst', 'key', 'layer') ) + data['notes'] = [note for i, note in enumerate(data['notes']) if note['tick'] != data['notes'][i-1]['tick'] or note['inst'] != data['notes'][i-1]['inst'] or note['key'] != data['notes'][i-1]['key']] + data['notes'] = sorted(data['notes'], key = operator.itemgetter('tick', 'layer') ) + + self.UpdateProgBar(70) + #Compact + if bool(self.var.tool.compact.get()): data = compactNotes(data, self.var.tool.compact.opt1.get(), groupPerc=0) self.UpdateProgBar(80) - applied['notes'] = sorted(applied['notes'], key = operator.itemgetter('tick', 'layer') ) - - self.inputFileData = applied + #Sort notes + data['notes'] = sorted(data['notes'], key = operator.itemgetter('tick', 'layer') ) + self.UpdateProgBar(90) + self.inputFileData = data self.UpdateProgBar(100) self.RaiseFooter('Applied') self.UpdateProgBar(-1) + self.ToolsTabButton['state'] = 'normal' def UpdateVar(self, repeat=False): #print("Started updating….") @@ -329,21 +388,20 @@ def RaiseFooter(self, text='', color='green', hid=False): self.footerLabel.pack_forget() self.footerLabel.update() -class AboutWindow(Toplevel): +class AboutWindow(tk.Toplevel): def __init__(self, parent): - Toplevel.__init__(self) + tk.Toplevel.__init__(self) self.parent = parent self.alarmTime = 0 self.title("About this application...") - logo = Label(self, text="NBSTool", font=("Arial", 44)) + logo = tk.Label(self, text="NBSTool", font=("Arial", 44)) logo.pack(padx=30, pady=10) - description = Message(self, text="A tool to work with .nbs (Note Block Studio) files.\nAuthor: IoeCmcomc\nVersion: 0,1", justify='center') - description.bind("", lambda e: description.configure(width=e.width-10)) + description = tk.Message(self, text="A tool to work with .nbs (Note Block Studio) files.\nAuthor: IoeCmcomc\nVersion: 0,25", justify='center') description.pack(fill='both', expand=False, padx=10, pady=10) - githubLink = Button(self, text='GitHub', command= lambda: webbrowser.open("https://github.com/IoeCmcomc/NBSTool",new=True)) + githubLink = ttk.Button(self, text='GitHub', command= lambda: webbrowser.open("https://github.com/IoeCmcomc/NBSTool",new=True)) githubLink.pack(padx=10, pady=10) self.lift() @@ -357,34 +415,52 @@ def __init__(self, parent): self.bind("", self.Alarm) self.bind('', lambda _: self.destroy()) - WindowGeo(self, parent, 400, 250, dialog=True) + WindowGeo(self, parent, 400, 250) def Alarm(self, event): print(dir(event)) self.focus_force() self.bell() +class FlexCheckbutton(tk.Checkbutton): + def __init__(self, *args, **kwargs): + okwargs = dict(kwargs) + if 'multiline' in kwargs: + self.multiline = kwargs['multiline'] + del okwargs['multiline'] + else: + self.multiline = True -def WindowGeo(obj, parent, width, height, dialog=False): + tk.Checkbutton.__init__(self, *args, **okwargs) - #print(parent.winfo_screenwidth(), parent.winfo_screenheight()) + self.text = kwargs['text'] + if 'anchor' in kwargs: + self.anchor = kwargs['anchor'] + else: + self.anchor = 'w' + self['anchor'] = self.anchor + + if 'justify' in kwargs: + self.justify = kwargs['justify'] + else: self.justify = 'left' + self['justify'] = self.justify + + if self.multiline: + self.bind("", lambda event: self.configure(width=event.width-10, justify=self.justify, anchor=self.anchor, wraplength=event.width-20, text=self.text+' '*999) ) +def WindowGeo(obj, parent, width, height, mwidth=None, mheight=None): ScreenWidth = root.winfo_screenwidth() ScreenHeight = root.winfo_screenheight() WindowWidth = width or obj.winfo_reqwidth() WindowHeight = height or obj.winfo_reqheight() - #print(WindowWidth, WindowHeight) - WinPosX = int(ScreenWidth / 2 - WindowWidth / 2) WinPosY = int(ScreenHeight / 2.3 - WindowHeight / 2) - #print(WinPosX, WinPosY) - obj.geometry("{}x{}+{}+{}".format(WindowWidth, WindowHeight, WinPosX, WinPosY)) obj.update() - obj.minsize(obj.winfo_width(), obj.winfo_height()) + obj.minsize(mwidth or obj.winfo_width(), mheight or obj.winfo_height()) def flipNotes(data, vertically=0, horizontally=0): vertically, horizontally = bool(vertically), bool(horizontally) @@ -407,35 +483,35 @@ def compactNotes(data, sepInst=1, groupPerc=0): #print('Instrument: {}'.format(inst)) InnerLayer = LocalLayer = c = 0 #print('OuterLayer: {}; Innerlayer: {}; LocalLayer: {}; c: {}'.format(OuterLayer, InnerLayer, LocalLayer, c)) - lastNote = {'layer':-1, 'tick':-1} + PrevNote = {'layer':-1, 'tick':-1} for note in r['notes']: if note['inst'] == inst: c += 1 - if note['tick'] == lastNote['tick']: + if note['tick'] == PrevNote['tick']: LocalLayer += 1 InnerLayer = max(InnerLayer, LocalLayer) note['layer'] = LocalLayer + OuterLayer else: LocalLayer = 0 note['layer'] = LocalLayer + OuterLayer - lastNote = note + PrevNote = note #print('OuterLayer: {}; Innerlayer: {}; LocalLayer: {}; c: {}'.format(OuterLayer, InnerLayer, LocalLayer, c)) OuterLayer += InnerLayer + 1 #print('OuterLayer: {}; Innerlayer: {}; LocalLayer: {}; c: {}'.format(OuterLayer, InnerLayer, LocalLayer, c)) else: - lastNote = {'layer':-1, 'tick':-1} + PrevNote = {'layer':-1, 'tick':-1} layer = 0 for note in r['notes']: - if note['tick'] == lastNote['tick']: + if note['tick'] == PrevNote['tick']: layer += 1 note['layer'] = layer else: layer = 0 note['layer'] = layer - lastNote = note + PrevNote = note return r -root = Tk() +root = tk.Tk() app = MainWindow(root) root.mainloop() diff --git a/nbsio.py b/nbsio.py index a62a145..b7464dd 100644 --- a/nbsio.py +++ b/nbsio.py @@ -243,21 +243,4 @@ def writenbs(filename, data): if __name__ == "__main__": import sys - opennbs(sys.argv[1], sys.argv[2]) - ''' - a = opennbs('Chạy ngay đi – Sơn Tùng M-TP.nbs') - b = opennbs('Chạy ngay đi – Sơn Tùng M-TP.nbssaved.nbs') - #b = opennbs('Bước chân thần kỳ – OPlus.nbs') - - for i in range(10): - print('='*40) - pprint(a['notes'][i]) - pprint(b['notes'][i]) - print('='*40) - print('note {0} in a = note {0} in b: {1}'.format(i, a['notes'][i] == b['notes'][i])) - - print('='*40) - #print(a['headers'] == b['headers']) - #print(a['notes'] == b['notes']) - print(a == b) - ''' \ No newline at end of file + opennbs(sys.argv[1], sys.argv[2]) \ No newline at end of file