11import threading
22import time
3+ import tkinter
4+ from tkinter import filedialog
35
46import Algorithms .Sorting as Sorting
57import pygame
68
79import UI .Wrapper as Wrapper
810from UI .Arrays import Array
911
10- import tkinter
11- from tkinter import filedialog
12-
1312''' This should only have code concerning the UI duh
1413 Specifically the display of screens, and functions for input (button presses)
1514 Everything here should just to be to display stuff and inputs
@@ -237,6 +236,18 @@ def update(self):
237236
238237 def on_reset (self ):
239238 self .window .event .set ()
239+ self .set_sorting_thread (None )
240+
241+ def set_sorting_thread (self , thread ):
242+ if self .sorting_thread is not None :
243+ self .window .event .set ()
244+ self .sorting_thread .join ()
245+ self .window .event .clear ()
246+ self .sorting_thread = thread
247+
248+ def sort_done (self ):
249+ self .sorting_thread = None
250+ self .window .event .set ()
240251
241252 def display_sorting (self , screen_group , options_screen_group , slide_in = True ):
242253 self .scroll_bar = []
@@ -258,26 +269,15 @@ def display_sorting(self, screen_group, options_screen_group, slide_in = True):
258269
259270 screen_group .add (Wrapper .Text (Wrapper .DefaultText .text ("Sorting" , Wrapper .FontSizes .TITLE_SIZE ), (self .window .window .get_size ()[0 ]/ 2 , self .TITLE_Y ), self .window , slide_in ))
260271 screen_group .add (Wrapper .Background ((self .MARGIN_X + self .SORTING_WIDTH / 2 , self .SORTING_Y ), (self .SORTING_WIDTH , self .SORTING_HEIGHT ), Wrapper .Colors .SMALL_BACKGROUND_COLOR , self .window , None , False ))
261-
262- def set_sorting_thread (thread ):
263- if self .sorting_thread is not None :
264- self .window .event .set ()
265- self .sorting_thread .join ()
266- self .window .event .clear ()
267- self .sorting_thread = thread
268-
269- def sort_done ():
270- self .sorting_thread = None
271- self .window .event .set ()
272272
273273 self .sorting_thread = None
274274
275275 buttons = []
276276 resets = []
277277 def bind_function (sort_input ):
278278 def func ():
279- sort_algo = Wrapper .sequential_functions (Wrapper .add_args_to_func (sort_input .sort , self .array , self .window .event , self .aux_array ), sort_done )
280- set_sorting_thread (threading .Thread (target = sort_algo ))
279+ sort_algo = Wrapper .sequential_functions (Wrapper .add_args_to_func (sort_input .sort , self .array , self .window .event , self .aux_array ), self . sort_done )
280+ self . set_sorting_thread (threading .Thread (target = sort_algo ))
281281 return self .sorting_thread .start ()
282282 func .__name__ = sort_input .name
283283 return func
0 commit comments