def btnSort_clicked(self): ''' transit to a new state and control sort process states -1 → 0 → 1 ↖ ↙ 2 -1 → 0 choose algorithm 0 → 1 sort 1 → 2 cancel 2 → 0 new sort ''' dprint('FUNCTION: btnSort_clicked') # ready to start -> running if self.app_state == 0: self.sort_button_status(1) self.thread_update() globals.RET_FLAG = False self.sorter.start() # running -> finished elif self.app_state == 1: globals.RET_FLAG = True self.sort_button_status(2) # finished -> ready to start elif self.app_state == 2: self.scene.clear() self.columns_setup() self.sort_button_status(0) else: print('app state not found') sys.exit(1)
def sort_button_status(self, state): ''' transit to a new state and set labels and button ''' dprint('FUNCTION: sort_button_status') dprint('\tstate {} → {}'.format(self.app_state, state)) style = '' btn_text = '' if state == 0: self.ui.spinColAmount.setEnabled(True) self.ui.spinDelay.setEnabled(True) self.ui.listAlgorithms.setEnabled(True) btn_text = 'sort' style = 'background-color: rgba(255,0,68,255); color: #fff' elif state == 1: self.ui.spinColAmount.setEnabled(False) self.ui.spinDelay.setEnabled(False) self.ui.listAlgorithms.setEnabled(False) btn_text = 'cancel' style = 'background-color: #000; color: #fff' elif state == 2: btn_text = 'new sort' style = 'background-color: rgba(85,0,255,255); color: #fff' self.app_state = state self.ui.btnSort.setText(btn_text) self.ui.btnSort.setStyleSheet(style)
def spinDelay_changed(self): '''re render the sorter(thread)''' dprint('FUNCTION: spinDelay_changed') if self.app_state == 0: dprint('\tdelay {} → {}'.format(self.sort_delay, self.ui.spinDelay.value())) self.sort_delay = self.ui.spinDelay.value()
def spinAmount_changed(self): '''re render the scene''' dprint('FUNCTION: spinAmount_changed') if self.app_state == 0: dprint('\tamount {} → {}'.format(self.col_amount, self.ui.spinColAmount.value())) self.col_amount = self.ui.spinColAmount.value() self.columns_setup()
def list_clicked(self, item): dprint('FUNCTION: list_clicked') dprint('\ttext: {}'.format(item.text())) dprint('\tapp_state = {}'.format(self.app_state)) # enter ready state when first clicked if self.app_state == -1: self.ui.btnSort.setEnabled(True) self.ui.spinColAmount.setEnabled(True) self.ui.spinDelay.setEnabled(True) self.app_state = 0 self.sort_button_status(self.app_state) # render labSortWith's text if self.app_state == 0: text = item.text() dprint('\talgorithm {} → {}'.format(self.algorithm_key, self.algorithm_list[text])) self.algorithm_key = self.algorithm_list[text] self.ui.labSortWith.setText(text)