def jog(self, axis, mult): self.selected = None if 'x' in axis or 'y' in axis: step = 0 for f in ToggleButtonBehavior.get_widgets('xystep'): if f.state == 'down': step = float(f.text) break conf.plugin._printer.jog({axis: step*mult}) if 'z' in axis: step = 0 for f in ToggleButtonBehavior.get_widgets('zstep'): if f.state == 'down': step = float(f.text) break conf.plugin._printer.jog({axis: step*mult}) if 'e' in axis: step = 0 for f in ToggleButtonBehavior.get_widgets('estep'): if f.state == 'down': step = float(f.text) break conf.plugin._printer.extrude(step*mult)
def _do_press(self): ''' 何も押されていない状態で設定が解除されるのを防ぐためToggleButtonの関数を継承して変更する Source code for kivy.uix.behaviors.button https://kivy.org/docs/_modules/kivy/uix/behaviors/button.html ''' if self.state == 'normal': # ボタンを押されてない場合は状態を変更する ToggleButtonBehavior._do_press(self)
def __init__(self, client, topic, light_type, pos, **kwargs): self._pos = pos self._light_type = light_type MQTTButtonBehaviour.__init__(self, client=client, topic=topic) ToggleButtonBehavior.__init__(self, **kwargs) Widget.__init__( self, pos=(self._pos[0] - self._light_type['radius'], self._pos[1] - self._light_type['radius']), size=(self._light_type['radius'] * 2, self._light_type['radius'] * 2), **kwargs ) self.draw() self.bind(state=self.draw)
def get_tab_from_group(filename): all_tabs = ToggleButtonBehavior.get_widgets('__tabed_btn__') if all_tabs: for tab in all_tabs: if tab.filename == filename: return tab break
def refreshData(self): #self.remove_widget(self.starImage) self.remove_widget(self.statsLabel) self.remove_widget(self.resetButton) connection = sqlite3.connect("dashboard.db") cursor = connection.cursor() cursor.execute("SELECT * FROM stars ORDER BY stars DESC") statsText = "" for row in cursor: member = str(row[0]) stars = str(row[1]) statsText += '[b]' + member + '[/b]' + ": " + stars + " " connection.close() self.add_widget(self.resetButton) #self.add_widget(self.starImage) self.statsLabel.text = statsText self.add_widget(self.statsLabel) memberButtons = ToggleButtonBehavior.get_widgets('members') for m in memberButtons: m.state = 'normal'
def commit(self): """ commit data""" problems = set() # find out the categories for num in range(8): button_group = ToggleButtonBehavior.get_widgets(str(num + 1)) for button in button_group: if button.state == "down": problems.add(("Problem {}".format(num + 1), button.text)) # create connection cnx = create_connection() cnx.database = self.parent_widget.database_name cursor = cnx.cursor() # push data query = """delete from Problems_{} where day={} ;""".format(self.parent_widget.category, self.parent_widget.round) cursor.execute(query) insert_problems(cursor, self.parent_widget.category, self.parent_widget.round, problems) # commit and exit cnx.commit() cnx.close() # exit popup and reload parent self.popup.dismiss() self.parent_widget.load()
def __init__(self, **kwargs): super(FavoritesBox, self).__init__(**kwargs) self.stations = RadioStations() playlist = App.get_running_app().config.get('General', 'playlist') # Select the corresponding toggle button pltb = ToggleButtonBehavior.get_widgets('playlist') for tb in pltb: tb.state = 'down' if tb.text == playlist else 'normal' del pltb self.change_playlist(playlist) self.favListStart = set() self.favListNow = set() for station in self.stations.favorites: self.favListStart.add(station['name']) self.favListNow.add(station['name']) self.favListStationsList.adapter.bind( on_selection_change=self.change_selection) # Set up the draggable scrollbar scrlv = self.favListStationsList.container.parent # The ListView's ScrollView scrls = self.favListStationsSlider scrlv.bind(scroll_y=partial(self.scroll_slider, scrls)) scrls.bind(value=partial(self.scroll_list, scrlv))
def change_scroll_y(self, txt, scroll): if self._do_cursor_scroll: lines_lenght = len(txt._lines) line_pos = txt.cursor_row + 1 norm_y = float(line_pos) / lines_lenght scroll.scroll_y = abs(norm_y - 1) if line_pos == 1: scroll.scroll_y = 1 # scroll scroll numbers line_num = txt.cursor_row + 1 children = self.ids.numbering.children[::-1] if children: child = children[line_num - 1] self.ids.number_scroll.scroll_to(child, dp(5)) Clock.schedule_once(lambda dt: setattr(child, 'state', 'down')) def toggle(chd): if chd != child: chd.state = 'normal' map(lambda child: toggle, ToggleButtonBehavior.get_widgets(child.group))
def change_screen(self, tab, state): if state == 'down': self.code_manager.current = tab.filename checked_list = list(filter(lambda child: child != tab, ToggleButtonBehavior.get_widgets(tab.group))) for child in checked_list: if child != tab: child.state='normal'
def mode_btn_ctrl(self, text): w_list = ToggleButtonBehavior.get_widgets("sel_model") for w in w_list: if w.text == text: w.state = "down" else: w.state = "normal"
def set_instrument(self, *args): _list = ToggleButtonBehavior.get_widgets('x') from utils.instrument import selected_instr for each in _list: if (each.text == selected_instr.capitalize()): each.active = True else: each.active = False
def set_time_option(self): global time_option for tggle in ToggleButtonBehavior.get_widgets('1'): if tggle.state == "down": if tggle.text == "6-10": time_option = True else: time_option = False
def add_soldiers(self, sldr_name): soldiers_list.append(sldr_name) soldiers_time[sldr_name] = 9 for tggle in ToggleButtonBehavior.get_widgets('period'): if tggle.state == "down": soldiers_pzm[sldr_name] = int(tggle.text) else: soldiers_pzm[sldr_name] = 1
def on_state(self, widget, value): #print(widget.tooltip_text,value) if value == "down": self.active = True _list = ToggleButtonBehavior.get_widgets('x') for each in _list: if each is not widget: each.active = False del _list
def record_who_scored(self): t = ToggleButtonBehavior.get_widgets('team') s = ToggleButtonBehavior.get_widgets('scorer') _team_who_scored = None _tws_name = None _person_who_scored = None time_of_goal = self.time_of_goal minutes = datetime.strptime(time_of_goal, '%H:%M:%S.%f') minutes = int( math.ceil((minutes - datetime(1900, 1, 1)).seconds / 60.0)) for _t in t: if _t.state == 'down': _team_who_scored = _t.text _tws_name = _t.name for _s in s: if _s.state == 'down': _person_who_scored = _s.text if _team_who_scored and _person_who_scored: if _tws_name == 'home': self._home += 1 else: self._away += 1 if _tws_name == 'home': self._h_scorers.append('%s (%s)' % (_person_who_scored, minutes)) else: self._a_scorers.append('%s (%s)' % (_person_who_scored, minutes)) self._goals.append( (_team_who_scored, _person_who_scored, time_of_goal), ) self.current = 'manager_screen' self._update = True print self._goals else: popup = Popup(title='Missing Info', content=Label(text='!'), size_hint=(None, None), size=(self.width * 0.5, self.height * 0.5)) popup.open()
def get_selected_index(self): # gets the index of the button which is presently selected # returns -1 if no button is selected widgets = ToggleButtonBehavior.get_widgets('storage') index = -1 for idx in range(len(widgets)): widget = widgets[idx] if widget.state == "down": index = idx return index
def _do_press(self): """ To handle button pressure on right sided panel """ super(ImageSelectButton, self)._do_press() buttons = ToggleButtonBehavior.get_widgets("images") for button in buttons: if self != button: button.state = "normal" button.is_select = False button.change_color()
def _do_press(self): """To handle button pressure on right sided panel.""" buttons = ToggleButtonBehavior.get_widgets('images') for button in buttons: if self != button: button.state = 'normal' button.is_select = False else: button.state = 'down' button.is_select = True button.change_color()
def on_pre_enter(self): if self.code_field: self.code_field.code_input.focus = True Window.bind(on_key_down=self.keyboard_down) tab = get_tab_from_group(self.name) if tab: Clock.schedule_once(lambda dt: setattr(tab, 'state', 'down')) checked_list = list( filter(lambda child: child != tab, ToggleButtonBehavior.get_widgets(tab.group))) Clock.schedule_once(lambda dt: map( lambda child: setattr(child, 'state', 'normal'), checked_list))
def load_game(self, *args): game_name = None for game in ToggleButtonBehavior.get_widgets("g"): if game.state == "down": game_name = game.text if game_name != None: global gameCtrl if gameCtrl != None: del gameCtrl gameCtrl = Game() gameCtrl.load_game(str(format(game_name))) self.manager.current = "board_setup"
def on_state(self, widget, value): if value == "down": self.active = True _list = ToggleButtonBehavior.get_widgets('x') for each in _list: if each is not widget: each.active = False each.color = [.7, .7, .7, .5] del _list name = widget.text.lower() import utils.instrument as ut ut.selected_instr = name st = "selected_instr = '{}'".format(name) with open('utils/instrument.py', 'w') as file: file.write(st)
def build(self): self.sm = ScreenManager() Config.set('graphics', 'width', '375') Config.set('graphics', 'height', '667') Clock.schedule_interval(self.update_time, 1) self.state = 1 self.storynum = 0 self.money = 900 self.processions_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.busy = 0 self.doing_treasure = 0 self.doing_exchange = 0 self.need_money = 0 self.choosing_product = 0 All = ToggleButtonBehavior.get_widgets('p_line') for i in All: i.state = 'normal' return self.sm
def on_state(self, widget, value): #l = ["Piano", "Guitar", "Violin", "Xylophone", "Drums"] if value == "down": self.active = True _list = ToggleButtonBehavior.get_widgets('m') for each in _list: if each is not widget: each.active = False each.color = theme.get_color( self.theme_cls.theme_style, "SelectorNormalColor") # [.1, .1, .1, .3] del _list name = widget.text.lower() import utils.selected_instrument as ut ut.selected_instr = name st = "selected_instr = '{}'\ncamera_indx = {}\nmanual_instr = {}".format( name, ut.camera_indx, ut.manual_instr) with open('utils/selected_instrument.py', 'w') as file: file.write(st)
def build(self): self.sm = ScreenManager() Config.set('graphics', 'width', '375') Config.set('graphics', 'height', '667') Clock.schedule_interval(self.update_time, 1) self.username = '' ### start setting self.money = 900 ### start setting self.storystate = '00000000000000000000000000000000000' ### start setting self.processions_list = [] self.product_list = [] self.url_image = [] self.state = 1 self.storynum = 0 self.busy = 0 self.linename = 'p' self.doing_create = 0 # to create new id self.doing_loginout = 0 # to log in without internet, which is in 'Login' screen self.doing_treasure = 0 # to use key to open the treasure, which is in 'Home' screen self.doing_exchange = 0 # to press the products icon to exchange with coins, which is in 'Home' screen self.doing_network = 0 # to enter shoppping mall but without internet, which is in 'Home' screen self.doing_homeloading = 0 # to wait for connecting, which is in 'Home' screen self.doing_loginloading = 0 #to wait for connecting, which is in 'Login' screen self.doing_shoploading = 0 #to wait for connecting, which is in 'P_coin_exchange' screen self.start_counting = 0 # to dealing with loading self.seconds = 0 #to dealing with loading self.product_id = 0 All = ToggleButtonBehavior.get_widgets('all_line') for i in All: i.state = 'normal' return self.sm
def _doneCallback(self, *args): connection = sqlite3.connect("dashboard.db") cursor = connection.cursor() member = '' memberButtons = ToggleButtonBehavior.get_widgets('members') for m in memberButtons: if m.state == 'down': member = m.text break sql = "UPDATE stars SET stars=(SELECT stars FROM stars WHERE member='" + member + "') + " + str( self.stars) + " WHERE member = '" + member + "'" print("SQL: " + sql) cursor.execute(sql) connection.commit() connection.close() self._root.refreshData() self.dismiss()
def _newAppointmentCallback(self, *args): appointment = self._appointmentTitleInput.text appointmentTime = self._datetimePicker.get_datetime() connection = sqlite3.connect("dashboard.db") cursor = connection.cursor() date = str(appointmentTime.strftime("%Y-%m-%d")) # 2018-05-15 time = str(appointmentTime.strftime("%H:%M")) # 16:00 member = 'Fiete' memberButtons = ToggleButtonBehavior.get_widgets('members') for m in memberButtons: if m.state == 'down': member = m.text break sql = "INSERT INTO Appointment(appdate, apptime, apptext, member) VALUES(date('"+str(date)+"'), time('"+str(time)+"'), '" + appointment + "', '" + member + "')" print("SQL: " + sql) cursor.execute(sql) connection.commit() connection.close() self._root.refreshData() self.dismiss()
def active_profile(self): # Get the active profile for i, w in enumerate(ToggleButtonBehavior.get_widgets('profile')): if w.state == 'down': return i
def update(self): """ callback function after save changes button pressed. Store the new data in the DB :return: void """ ########################################################## ## INPUT CHECK ########################################################## if self.chunk.text == '' or self.score.text == '' or not self.is_number(self.score.text): popup = Popup(title='Alert!!', content=Label(text="Incomplete data, please re-check!"), size_hint=(None, None), size=(400, 200)) popup.open() return if self.counter == 0: # no meaning for that chunk popup = Popup(title='Alert!!', content=Label(text="No meaning for this chunk\nInsert at least one!"), size_hint=(None, None), size=(400, 200)) popup.open() return self.meaning = [] chosen_mean = '' for bl in self.layout_meaning.children: for idx, elem in enumerate(bl.children): if idx == 0: continue #the first children is the ADD new button #parse all rows mean = elem.children[4].text url = elem.children[3].text dis = elem.children[2].active approved = elem.children[1].active chosen = elem.children[0].active if mean == '': popup = Popup(title='Alert!!', content=Label(text="Empty meaning not allowed!"), size_hint=(None, None), size=(400, 200)) popup.open() return self.meaning.append(dict(found=mean, url=url, dis=dis, approved=approved, chosen=chosen)) ## check at least 1 approved count_approved = 0 for x in self.meaning: print x if x['approved'] is True: count_approved += 1 if count_approved == 0: popup = Popup(title='Alert!!', content=Label(text="At least insert one approved meaning!"), size_hint=(None, None), size=(400, 200)) popup.open() return chosen_table = 0 l = ToggleButtonBehavior.get_widgets('table') for toggle in l: if toggle.state == 'down': if toggle.text == '[b]Approved[/b]': chosen_table = 1 elif toggle.text == '[b]Unapproved[/b]': chosen_table = 2 del l print 'chunk: ', self.chunk.text print 'rows: ', self.meaning print 'category: ', self.category.text print 'chosen table: ', chosen_table print 'score: ', self.score.text print 'old_chunk: ', self.app.root.current_chunk print 'old_found: ', self.rows_kl ########################################################## ## DATA DUMP ########################################################## ##delete section (no update because I can have multiple meanings) for row in self.rows_kl: print 'dentro elimina kl' self.db.del_row_kl(chunk=str(self.app.root.current_chunk), found=row.found) self.db.del_chunk_ud(userid=self.app.root.userID, senderid=self.app.root.senderID, chunk=self.rows_ud[0].chunk) ##insert section for row in self.meaning: print row if row['approved']: print 'pre inserimento DB KL' self.db.insert_single_kl(chunk=self.chunk.text, found=row['found'], category=self.category.text, url=row['url'], dis=row['dis'], ngram=len(self.chunk.text.split(" "))) if row['chosen']: print 'pre inserimento DB UD' self.db.insert_single_ud( userid=self.app.root.userID, senderid=self.app.root.senderID, chunk=self.chunk.text, found=row['found'], score=int(self.score.text), status=chosen_table) ########################################################## ## END ########################################################## self.app.root.carousel.load_slide(self.app.root.approved)
def split(self): chosen_split = 0 chunks = [] ######################################################## ## GETTING SPLIT ORDER ######################################################## l = ToggleButtonBehavior.get_widgets('split') for toggle in l: if toggle.state == 'down': chosen_split = int(toggle.id) break del l if chosen_split == 1 or chosen_split == 4: chunks = self.splitted elif chosen_split == 2: chunks.append(self.splitted[0]) chunks.append(str(self.splitted[1] + " " + self.splitted[2])) elif chosen_split == 3: chunks.append(str(self.splitted[0] + " " + self.splitted[1])) chunks.append(self.splitted[2]) print 'chunks: ', chunks ######################################################## ## UPDATE UD AND KL ######################################################## ##loop splitted chunks for x in chunks: ##UPDATE UD ## in the case the chunk is already present, the trigger will update the value ## default table is UNDEFINED self.db.insert_single_ud( self.app.root.userID, self.app.root.senderID, x, self.rows_ud[0].found, 2, self.rows_ud[0].score) ## need to loop on each KL result for y in self.rows_kl: n = x.split(" ") ##UPDATE KL (use insert or ignore) self.db.insert_single_kl( chunk=x, found=y.found, category=y.category, url=y.url, dis=y.disambiguation_url, ngram=len(n)) ##REMOVE OLD LINE IN KL for z in self.rows_kl: self.db.del_row_kl(chunk=self.chunk, found=z.found) ##REMOVE OLD LINE IN UD self.db.del_chunk_ud(self.app.root.userID, self.app.root.senderID, self.chunk) ######################################################## ## CLOSE POPUP ######################################################## self.dismiss()
def _do_press(self): #We can only press the button if the state is normal if self.state == "normal": ToggleButtonBehavior._do_press(self)
def update(self, dt): self.files = conf.plugin._file_manager.list_files() if self.first: self.ids.file_list.bind(minimum_height=self.ids.file_list.setter('height')) self.first = False if self.files != self.oldFiles: self.ids.file_list.clear_widgets() for i in self.files['local']: date = self.files['local'][i]['date'] btn = FileView('files', self.files['local'][i]['name'], date, size_hint_y=None, height=60) children = self.ids.file_list.children if len(children) > 0: if date <= int(children[0].date): self.ids.file_list.add_widget(btn, index=0) elif date > int(children[len(children)-1].date): self.ids.file_list.add_widget(btn, index=len(children)) else: for w in range(len(children)): w = w if date <= int(children[w-1].date) and date >= int(children[w].date): self.ids.file_list.add_widget(btn, index = w-1) break else: self.ids.file_list.add_widget(btn) self.oldFiles = self.files self.selected = None for f in ToggleButtonBehavior.get_widgets('files'): if f.state == 'down': self.selected = f break if self.selected == None or not self.selected.title in self.files['local'].keys(): self.title = "No File" self.date = 0 self.etime.title = "" self.etime.time = "" self.ids.print_button.disabled = True self.ids.load_button.disabled = True self.ids.delete_button.disabled = True else: file = self.files['local'][self.selected.title] self.title = f.title self.date = f.date if('analysis' in file.keys()): etime = file['analysis']['estimatedPrintTime'] if not etime == None: m, s = divmod(int(etime), 60) h, m = divmod(m, 60) else: h, m, s = 0, 0, 0 self.etime.title = "Estimated" self.etime.time = str("%02d:%02d:%02d" % (h, m, s)) filament = file['analysis']['filament'] if(self.selected != self.oldSelected): self.filaBox.clear_widgets() if len(filament) == 1 and conf.plugin._printer.get_current_connection()[3]['extruder']['count'] == 1: fila_widget = FilamentLabel() fila_widget.title = "Usage:" fila_widget.name = 'tool0' self.filaBox.add_widget(fila_widget) else: for i in range(len(filament)): fila_widget = FilamentLabel() fila_widget.title = "Tool " + str(i) + " Usage:" fila_widget.name = 'tool' + str(i) self.filaBox.add_widget(fila_widget) self.oldSelected = self.selected for i in self.filaBox.children: if isinstance(i, FilamentLabel): i.update(filament) if conf.plugin._printer.is_printing() or conf.plugin._printer.is_closed_or_error(): self.ids.print_button.disabled = True else: self.ids.print_button.disabled = False if conf.plugin._printer.get_current_job()['file']['name'] == f.title or conf.plugin._printer.is_printing() or conf.plugin._printer.is_closed_or_error(): self.ids.load_button.disabled = True else: self.ids.load_button.disabled = False self.ids.delete_button.disabled = False
def add_option(self): btns = [x for x in ToggleButtonBehavior.get_widgets('options') if x.state == 'down'] if len(btns) > 0: self.add_filter(btns[0], self.ids.textinput.text) self.ids.textinput.text = ''
def update(self, dt): self.files = conf.plugin._file_manager.list_files() if self.first: self.ids.file_list.bind( minimum_height=self.ids.file_list.setter('height')) self.first = False if self.files != self.oldFiles: self.ids.file_list.clear_widgets() for i in self.files['local']: date = self.files['local'][i]['date'] btn = FileView('files', self.files['local'][i]['name'], date, size_hint_y=None, height=60) children = self.ids.file_list.children if len(children) > 0: if date <= int(children[0].date): self.ids.file_list.add_widget(btn, index=0) elif date > int(children[len(children) - 1].date): self.ids.file_list.add_widget(btn, index=len(children)) else: for w in range(len(children)): w = w if date <= int( children[w - 1].date) and date >= int( children[w].date): self.ids.file_list.add_widget(btn, index=w - 1) break else: self.ids.file_list.add_widget(btn) self.oldFiles = self.files self.selected = None for f in ToggleButtonBehavior.get_widgets('files'): if f.state == 'down': self.selected = f break if self.selected == None or not self.selected.title in self.files[ 'local'].keys(): self.title = "No File" self.date = 0 self.etime.title = "" self.etime.time = "" self.ids.print_button.disabled = True self.ids.load_button.disabled = True self.ids.delete_button.disabled = True else: file = self.files['local'][self.selected.title] self.title = f.title self.date = f.date if ('analysis' in file.keys()): etime = file['analysis']['estimatedPrintTime'] if not etime == None: m, s = divmod(int(etime), 60) h, m = divmod(m, 60) else: h, m, s = 0, 0, 0 self.etime.title = "Estimated" self.etime.time = str("%02d:%02d:%02d" % (h, m, s)) filament = file['analysis']['filament'] if (self.selected != self.oldSelected): self.filaBox.clear_widgets() if len( filament ) == 1 and conf.plugin._printer.get_current_connection( )[3]['extruder']['count'] == 1: fila_widget = FilamentLabel() fila_widget.title = "Usage:" fila_widget.name = 'tool0' self.filaBox.add_widget(fila_widget) else: for i in range(len(filament)): fila_widget = FilamentLabel() fila_widget.title = "Tool " + str(i) + " Usage:" fila_widget.name = 'tool' + str(i) self.filaBox.add_widget(fila_widget) self.oldSelected = self.selected for i in self.filaBox.children: if isinstance(i, FilamentLabel): i.update(filament) if conf.plugin._printer.is_printing( ) or conf.plugin._printer.is_closed_or_error(): self.ids.print_button.disabled = True else: self.ids.print_button.disabled = False if conf.plugin._printer.get_current_job( )['file']['name'] == f.title or conf.plugin._printer.is_printing( ) or conf.plugin._printer.is_closed_or_error(): self.ids.load_button.disabled = True else: self.ids.load_button.disabled = False self.ids.delete_button.disabled = False
def save_data(self, instance): """ callback function called after "SAVE" button pressed need to check consistency of inserted data and if it's all OK dump new data :param instance: :return: """ ############################################################################## ## DATA CHECK AND EXTRACTION ############################################################################## if self.new_chunk.text == "": # no meaning for that chunk popup = Popup(title='Alert!!', content=Label(text="Chunk Empty! Please fill chunk"), size_hint=(0.5, 0.3), font_size='38sp') popup.open() return if self.counter == 0: # no meaning for that chunk popup = Popup(title='Alert!!', content=Label(text="No meaning for this chunk\nInsert at least one!"), size_hint=(0.5, 0.3), font_size='38sp') popup.open() return meanings = [] for bl in self.bl_found.children: #parse all meanings inserted chosen = bl.children[1].children[0].active approved = bl.children[1].children[1].active dis = bl.children[1].children[2].active url = bl.children[1].children[3].text found = bl.children[1].children[4].text if found == '': popup = Popup(title='Alert!!', content=Label(text="Empty found label not allowed!"), size_hint=(0.5, 0.3), font_size='38sp') popup.open() return if chosen is True and approved is False: popup = Popup(title='Alert!!', content=Label(text="A meaning can't be chosen if not approved!"), size_hint=(0.5, 0.3), font_size='38sp') popup.open() return dis_int = 0 if dis: dis_int = 1 if approved: meanings.append([found, url, dis_int, chosen]) chosen_table = 0 l = ToggleButtonBehavior.get_widgets('table') for toggle in l: if toggle.state == 'down': if toggle.text == 'Approved': chosen_table = 1 elif toggle.text == 'Unapproved': chosen_table = 2 del l ############################################################################## ## SAVE DATA ############################################################################## rows = self.db.existchunk_kl(self.new_chunk.text) # no control of chunk already present because I use INSERT OR REPLACE for x in meanings: ngram = len(self.new_chunk.text.split(" ")) self.db.insert_single_kl(chunk=self.new_chunk.text, found=x[0], category=self.new_category.text, url=x[1], dis=int(x[2]), ngram=ngram) if x[3] is True: #case CHOSEN, need to add it to the UD self.db.insert_single_ud(userid=self.app.root.userID, senderid=self.app.root.senderID, chunk=self.new_chunk.text, found=x[0], status=chosen_table, score=1) ############################################################################## self.app.root.carousel.load_slide(self.app.root.approved)
def _do_press(self): if self.state == 'normal': ToggleButtonBehavior._do_press(self)
def success_login(self, request, results): self.seconds = 0 self.start_counting = 0 self.remove_busy(0) if(results['success'] == True): self.doing_loginout = 0 self.sm.current = 'Home' ### read in state ### self.username = self.root.ids.username.text self.storystate = results['stories'] self.money = int(results['points']) self.root.ids.username_label.text += str(self.username) self.root.ids.username_label_y.text += str(self.username) self.root.ids.username_label_h.text += str(self.username) ### write into file ### f = open('user.txt','w') ### username f.write(self.username) f.close() f = open('storystate.txt', 'w') ### storystate and money f.write(self.storystate + '\n' + str(self.money)) f.close() self.processions_list = [] ### processions list f = open('processions_list.txt', 'w') for i in range(len(results['boughtitems'])): self.processions_list.append({'item_name': results['boughtitems'][i]['item_name'], 'item_quantity': results['boughtitems'][i]['item_quantity']}) f.write(str(results['boughtitems'][i]['item_name']) + ' ' + str(results['boughtitems'][i]['item_quantity']) + '\n') f.close() ### story states have to been processed All = ToggleButtonBehavior.get_widgets('all_line') for i in All: i.background_normal = 'gray_dot.png' i.state = 'normal' for i in range(35): if(self.storystate[i] == '1'): digit = chr(ord('0') + int((i + 1) / 10)) + chr(ord('0') + int((i + 1) % 10)) self.root.ids["all_line_" + digit].background_normal = 'cyan_dot.png' return else: self.busy = 1 ### self.doing_loginout = 1 ### self.image_loginout =Image(color = get_color_from_hex('#FFFFFF'), opacity = 0.8, size = (.75 * self.root.width, .72* self.root.height), pos = (.125 * self.root.width, .15 * self.root.height)) self.button = Button(size = (.3 * self.root.width, .06 * self.root.height), size_hint = (None, None), background_normal = 'yes.png', background_down = 'yes.png', pos = (.35 * self.root.width, .18 * self.root.height)) self.button.bind(on_press = self.remove_busy) self.box = BoxLayout(size = (.6 * self.root.width, .5 * self.root.height), size_hint = (None, None), pos = (.2 * self.root.width, .3 * self.root.height), orientation = 'vertical', spacing = .1 * self.root.height , padding = .1 * self.root.width) self.loginout_text = Label(font_name = chinese_ch, halign = 'center', font_size = 100, color = get_color_from_hex('#000000'), markup = True, text_size = (self.box.width, None), text = results['messages']) self.box.add_widget(self.loginout_text) self.root.ids.id_login.add_widget(self.image_loginout) self.root.ids.id_login.add_widget(self.button) self.root.ids.id_login.add_widget(self.box) return