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
@@ -208,6 +207,18 @@ def update(self):
208207
209208 def on_reset (self ):
210209 self .window .event .set ()
210+ self .set_sorting_thread (None )
211+
212+ def set_sorting_thread (self , thread ):
213+ if self .sorting_thread is not None :
214+ self .window .event .set ()
215+ self .sorting_thread .join ()
216+ self .window .event .clear ()
217+ self .sorting_thread = thread
218+
219+ def sort_done (self ):
220+ self .sorting_thread = None
221+ self .window .event .set ()
211222
212223 def display_sorting (self , screen_group , options_screen_group , slide_in = True ):
213224 self .scroll_bar = []
@@ -229,26 +240,15 @@ def display_sorting(self, screen_group, options_screen_group, slide_in = True):
229240
230241 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 ))
231242 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 , False ))
232-
233- def set_sorting_thread (thread ):
234- if self .sorting_thread is not None :
235- self .window .event .set ()
236- self .sorting_thread .join ()
237- self .window .event .clear ()
238- self .sorting_thread = thread
239-
240- def sort_done ():
241- self .sorting_thread = None
242- self .window .event .set ()
243243
244244 self .sorting_thread = None
245245
246246 buttons = []
247247 resets = []
248248 def bind_function (sort_input ):
249249 def func ():
250- sort_algo = Wrapper .sequential_functions (Wrapper .add_args_to_func (sort_input .sort , self .array , self .window .event , self .aux_array ), sort_done )
251- set_sorting_thread (threading .Thread (target = sort_algo ))
250+ sort_algo = Wrapper .sequential_functions (Wrapper .add_args_to_func (sort_input .sort , self .array , self .window .event , self .aux_array ), self . sort_done )
251+ self . set_sorting_thread (threading .Thread (target = sort_algo ))
252252 return self .sorting_thread .start ()
253253 func .__name__ = sort_input .name
254254 return func
0 commit comments