@@ -51,7 +51,6 @@ def elements(self):
5151 self .NbTabs .pack (fill = 'both' , expand = True )
5252
5353 #Footer
54-
5554 tk .Frame (self , height = 5 ).pack ()
5655
5756 self .footer = tk .Frame (self , relief = 'groove' , borderwidth = 1 , height = 25 )
@@ -112,10 +111,10 @@ def GeneralTabElements(self):
112111 self .OpenFileEntry = tk .Entry (self .OpenFileFrame )
113112 self .OpenFileEntry .pack (side = 'left' , fill = 'x' , padx = padx , expand = True )
114113
115- self .BrowseFileButton = FlexButton (self .OpenFileFrame , text = "Browse" , command = lambda : self .OnBrowseFile () )
114+ self .BrowseFileButton = ttk . Button (self .OpenFileFrame , text = "Browse" , command = lambda : self .OnBrowseFile () )
116115 self .BrowseFileButton .pack (side = 'left' , padx = padx , pady = pady )
117116
118- self .OpenFileButton = FlexButton (self .OpenFileFrame , text = "Open" , command = lambda : self .OnOpenFile ('' , True ) )
117+ self .OpenFileButton = ttk . Button (self .OpenFileFrame , text = "Open" , command = lambda : self .OnOpenFile ('' , True ) )
119118 self .OpenFileButton .pack (side = 'left' , padx = padx , pady = pady )
120119
121120 lfp = 10
@@ -124,14 +123,14 @@ def GeneralTabElements(self):
124123 self .FileMetaFrame = tk .LabelFrame (self .GeneralTab , text = "Metadata" )
125124 self .FileMetaFrame .grid (row = 1 , column = 0 , padx = lfp , pady = lfp , sticky = 'nsew' )
126125
127- self .FileMetaMess = FlexMessage (self .FileMetaFrame , text = "No flie was found." )
126+ self .FileMetaMess = tk . Message (self .FileMetaFrame , text = "No flie was found." )
128127 self .FileMetaMess .pack (fill = 'both' , expand = True , padx = padx , pady = padx )
129128
130129 #More infomation frame
131130 self .FileInfoFrame = tk .LabelFrame (self .GeneralTab , text = "Infomations" )
132131 self .FileInfoFrame .grid (row = 1 , column = 1 , padx = lfp , pady = lfp , sticky = 'nsew' )
133132
134- self .FileInfoMess = FlexMessage (self .FileInfoFrame , text = "No flie was found." )
133+ self .FileInfoMess = tk . Message (self .FileInfoFrame , text = "No flie was found." )
135134 self .FileInfoMess .pack (fill = 'both' , expand = True , padx = padx , pady = pady )
136135
137136 def ToolsTabElements (self ):
@@ -142,36 +141,35 @@ def ToolsTabElements(self):
142141 self .FlipToolFrame = tk .LabelFrame (self .ToolsTab , text = "Flipping" )
143142 self .FlipToolFrame .grid (row = 0 , column = 0 , sticky = 'nsew' , padx = fpadx , pady = fpady )
144143
145- self .FlipToolMess = FlexMessage (self .FlipToolFrame , anchor = 'w' , text = "Flip the note sequence horizontally (by tick), vertically (by layer) or both: " )
144+ self .FlipToolMess = tk . Message (self .FlipToolFrame , anchor = 'w' , text = "Flip the note sequence horizontally (by tick), vertically (by layer) or both: " )
146145 self .FlipToolMess .pack (fill = 'both' , expand = True , padx = padx , pady = pady )
147146
148147 self .var .tool .flip .vertical = tk .IntVar ()
149- self .FilpToolCheckV = FlexCheckbutton (self .FlipToolFrame , text = "Vertically" , variable = self .var .tool .flip .vertical , multiline = False )
148+ self .FilpToolCheckV = tk . Checkbutton (self .FlipToolFrame , text = "Vertically" , variable = self .var .tool .flip .vertical )
150149 self .FilpToolCheckV .pack (side = 'left' , padx = padx , pady = pady )
151150
152151 self .var .tool .flip .horizontal = tk .IntVar ()
153- self .FilpToolCheckH = FlexCheckbutton (self .FlipToolFrame , text = "Horizontally" , variable = self .var .tool .flip .horizontal , multiline = False )
152+ self .FilpToolCheckH = tk . Checkbutton (self .FlipToolFrame , text = "Horizontally" , variable = self .var .tool .flip .horizontal )
154153 self .FilpToolCheckH .pack (side = 'left' , padx = padx , pady = pady )
155154
156155 #Instrument tool
157156 self .InstToolFrame = tk .LabelFrame (self .ToolsTab , text = "Note's instrument" )
158157 self .InstToolFrame .grid (row = 0 , column = 1 , sticky = 'nsew' , padx = fpadx , pady = fpady )
159158
160- self .InstToolMess = FlexMessage (self .InstToolFrame , anchor = 'w' , text = "Change all note's instrument to:" )
159+ self .InstToolMess = tk . Message (self .InstToolFrame , anchor = 'w' , text = "Change all note's instrument to:" )
161160 self .InstToolMess .pack (fill = 'both' , expand = True , padx = padx , pady = pady )
162161
163162 self .var .tool .inst = ["Harp (piano)" ,"Double Bass" ,"Bass Drum" ,"Snare Drum" ,"Click" ,"Guitar" ,"Flute" ,"Bell" ,"Chime" ,"Xylophone" ]
164163 self .var .tool .inst .opt = ["(not applied)" ] + self .var .tool .inst + ["Random" ]
165164 self .InstToolCombox = ttk .Combobox (self .InstToolFrame , state = 'readonly' , values = self .var .tool .inst .opt ._ )
166- self .InstToolCombox .bind ("<Return>" , lambda e : self .InstToolCombox .event_generate ('<Down>' ))
167165 self .InstToolCombox .current (0 )
168166 self .InstToolCombox .pack (side = 'left' , fill = 'both' ,expand = True , padx = padx , pady = pady )
169167
170168 #Reduce tool
171169 self .ReduceToolFrame = tk .LabelFrame (self .ToolsTab , text = "Reducing" )
172170 self .ReduceToolFrame .grid (row = 1 , column = 0 , sticky = 'nsew' , padx = fpadx , pady = fpady )
173171
174- self .ReduceToolMess = FlexMessage (self .ReduceToolFrame , anchor = 'w' , text = "Delete as many note as possible to reduce file size." )
172+ self .ReduceToolMess = tk . Message (self .ReduceToolFrame , anchor = 'w' , text = "Delete as many note as possible to reduce file size." )
175173 self .ReduceToolMess .pack (fill = 'both' , expand = True , padx = padx , pady = pady )
176174
177175 self .var .tool .reduce .opt1 = tk .IntVar ()
@@ -190,7 +188,7 @@ def ToolsTabElements(self):
190188 self .CompactToolFrame = tk .LabelFrame (self .ToolsTab , text = "Compacting" )
191189 self .CompactToolFrame .grid (row = 1 , column = 1 , sticky = 'nsew' , padx = fpadx , pady = fpady )
192190
193- self .CompactToolMess = FlexMessage (self .CompactToolFrame , anchor = 'w' , text = "Remove spaces between notes vertically (by layer) and group them by instruments." )
191+ self .CompactToolMess = tk . Message (self .CompactToolFrame , anchor = 'w' , text = "Remove spaces between notes vertically (by layer) and group them by instruments." )
194192 self .CompactToolMess .pack (fill = 'both' , expand = True , padx = padx , pady = pady )
195193
196194 self .var .tool .compact = tk .IntVar ()
@@ -203,7 +201,7 @@ def ToolsTabElements(self):
203201 self .CompactToolChkOpt1 .pack (padx = padx * 5 , pady = pady )
204202
205203 #'Apply' botton
206- self .ToolsTabButton = FlexButton (self .ToolsTab , text = "Apply" , state = 'disabled' , command = self .OnApplyTool )
204+ self .ToolsTabButton = ttk . Button (self .ToolsTab , text = "Apply" , state = 'disabled' , command = self .OnApplyTool )
207205 self .ToolsTabButton .grid (row = 2 , column = 1 , sticky = 'se' , padx = fpadx , pady = fpady )
208206
209207 def footerElements (self ):
@@ -221,10 +219,16 @@ def footerElements(self):
221219 #self.progressbar.stop()
222220
223221 def WindowBind (self ):
224- #Buttons
225- self .master .bind ('<Escape>' , lambda _ : self .parent .destroy ())
226- self .master .bind ('<Control-o>' , lambda _ : self .OnBrowseFile (True ))
227- self .master .bind ('<Control-s>' , self .OnSaveFile )
222+ #Keys
223+ self .parent .bind ('<Escape>' , lambda _ : self .parent .destroy ())
224+ self .parent .bind ('<Control-o>' , lambda _ : self .OnBrowseFile (True ))
225+ self .parent .bind ('<Control-s>' , self .OnSaveFile )
226+ #Bind class
227+ self .bind_class ("Message" ,"<Configure>" , lambda e : e .widget .configure (width = e .width - 10 ))
228+ self .bind_class ("TButton" , "<Return>" , lambda e : e .widget .invoke ())
229+ self .bind_class ("Checkbutton" , "<Return>" , lambda e : e .widget .toggle ())
230+ self .bind_class ("Checkbutton" , "<Return>" , lambda e : e .widget .invoke ())
231+ self .bind_class ("TCombobox" , "<Return>" , lambda e : e .widget .event_generate ('<Down>' ))
228232
229233 def OnBrowseFile (self , doOpen = False ):
230234 types = [('Note Block Studio file' , '*.nbs' ), ('All files' , '*' )]
@@ -379,10 +383,10 @@ def __init__(self, parent):
379383 logo = tk .Label (self , text = "NBSTool" , font = ("Arial" , 44 ))
380384 logo .pack (padx = 30 , pady = 10 )
381385
382- description = FlexMessage (self , text = "A tool to work with .nbs (Note Block Studio) files.\n Author: IoeCmcomc\n Version: 0,1" , justify = 'center' )
386+ description = tk . Message (self , text = "A tool to work with .nbs (Note Block Studio) files.\n Author: IoeCmcomc\n Version: 0,1" , justify = 'center' )
383387 description .pack (fill = 'both' , expand = False , padx = 10 , pady = 10 )
384388
385- githubLink = FlexButton (self , text = 'GitHub' , command = lambda : webbrowser .open ("https://github.com/IoeCmcomc/NBSTool" ,new = True ))
389+ githubLink = ttk . Button (self , text = 'GitHub' , command = lambda : webbrowser .open ("https://github.com/IoeCmcomc/NBSTool" ,new = True ))
386390 githubLink .pack (padx = 10 , pady = 10 )
387391
388392 self .lift ()
@@ -403,16 +407,6 @@ def Alarm(self, event):
403407 self .focus_force ()
404408 self .bell ()
405409
406- class FlexMessage (tk .Message ):
407- def __init__ (self , * args , ** kwargs ):
408- tk .Message .__init__ (self , * args , ** kwargs )
409- self .bind ("<Configure>" , lambda e : self .configure (width = e .width - 10 ))
410-
411- class FlexButton (ttk .Button ):
412- def __init__ (self , * args , ** kwargs ):
413- ttk .Button .__init__ (self , * args , ** kwargs )
414- self .bind ("<Return>" , lambda e : self .invoke ())
415-
416410class FlexCheckbutton (tk .Checkbutton ):
417411 def __init__ (self , * args , ** kwargs ):
418412 okwargs = dict (kwargs )
@@ -438,8 +432,6 @@ def __init__(self, *args, **kwargs):
438432
439433 if self .multiline :
440434 self .bind ("<Configure>" , lambda event : self .configure (width = event .width - 10 , justify = self .justify , anchor = self .anchor , wraplength = event .width - 20 , text = self .text + ' ' * 999 ) )
441- self .bind ("<Return>" , lambda _ : self .toggle ())
442- self .bind ("<Return>" , lambda _ : self .invoke ())
443435
444436def WindowGeo (obj , parent , width , height , mwidth = None , mheight = None ):
445437 ScreenWidth = root .winfo_screenwidth ()
@@ -482,7 +474,7 @@ def compactNotes(data, sepInst=1, groupPerc=0):
482474 c += 1
483475 if note ['tick' ] == PrevNote ['tick' ]:
484476 LocalLayer += 1
485- Inner Layer = max (InnerLayer , LocalLayer )
477+ InnerLayer = max (InnerLayer , LocalLayer )
486478 note ['layer' ] = LocalLayer + OuterLayer
487479 else :
488480 LocalLayer = 0
0 commit comments