class GalleryButton(MDFloatingActionButton): """A FAB which opens the gallery.""" path_selected_callback = ObjectProperty(lambda: None) def __init__(self, **kwargs): """Initializes the gallery button""" super(GalleryButton, self).__init__(**kwargs) self.manager_open = False self.manager = None def on_release(self): """Function called when the button is released.""" self.file_manager_open() def file_manager_open(self): """Opens the file manager window""" if not self.manager: self.manager = ModalView(size_hint=(1, 1), auto_dismiss=False) self.file_manager = MDFileManager(exit_manager=self.exit_manager, select_path=self.select_path) # Monkey patch file selection so that history is not erased def select_dir_or_file(path): """Called by tap on the name of the directory or file.""" if os.path.isfile(path): self.file_manager.select_path(path) return self.file_manager.current_path = path self.file_manager.show(path) self.file_manager.select_dir_or_file = select_dir_or_file self.manager.add_widget(self.file_manager) self.file_manager.show('/') # output manager to the screen self.manager_open = True self.manager.open() def select_path(self, path): """ It will be called when you click on the file name or the catalog selection button. :type path: str; :param path: path to the selected directory or file; """ self.path_selected_callback(path) self.exit_manager() toast(path) def exit_manager(self, *args): """Called when the user reaches the root of the directory tree.""" self.manager.dismiss() self.manager_open = False
def on_status(self, instance, new_value): status = new_value # updates the status property with new value # Sum each row, column and diagonal. # Could be shorter, but let’s be extra # clear what’s going on sums = [ sum(status[0:3]), sum(status[3:6]), sum(status[6:9]), # rows sum(status[0::3]), sum(status[1::3]), sum(status[2::3]), # columns sum(status[0::4]), sum(status[2:7:2]) # diagonals ] winner = None if 3 in sums: winner = 'Kolečka vítězí!' elif -3 in sums: winner = 'Křížky vítězí!' elif 0 not in status: winner = 'Remíza ... nikdo nezvítězil!' if winner: popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text=winner, font_size=50) popup.add_widget(victory_label) popup.bind(on_dismiss=self.reset) popup.open()
def card(content, title=None, background_color=None, size=(.7, .5)): '''Вывод диалоговых окон с кастомным контентом.''' if not background_color: background_color = [1.0, 0, 0, 1] card = MDCard(size_hint=(1, 1), padding=5) #, background_color=background_color) if title: box = BoxLayout(orientation='vertical', padding=dp(8)) box.add_widget( MDLabel(text=title, theme_text_color='Secondary', font_style="Title", size_hint_y=None, height=dp(36))) box.add_widget(MDSeparator(height=dp(1))) box.add_widget(content) card.add_widget(box) else: card.add_widget(content) dialog = ModalView(size_hint=size, background_color=[0, 0, 0, .2]) dialog.add_widget(card) dialog.open() return dialog
def button_pressed(self, button): colours = {-1: (1, 0, 0, 1), 1: (0, 1, 0, 1)} # (r, g, b, a) row, column = button.coords if button.pressed == 1: button.text = {-1: Finish.surrounded(row, column), 1: 'X'}[self.status[row][column]] button.background_color = colours[self.status[row][column]] print ('{} button clicked!'.format(button.coords)) button.pressed = 0 if Finish.board[row][column] == 1: self.treasuresfound = self.treasuresfound + 1 if self.treasuresfound == 9: popup = ModalView(size_hint=(0.75, 0.5)) endlabel = Button(text="You won !", font_size=50) endlabel.background_color = (0, 1, 0, 1) popup.add_widget(endlabel) popup.bind(on_dismiss=self.reset) popup.open() else: self.attempts = self.attempts - 1 if self.attempts == 0: popup = ModalView(size_hint=(0.75, 0.5)) endlabel = Button(text="Try again", font_size=50) popup.add_widget(endlabel) popup.bind(on_dismiss=self.reset) popup.open()
def pokazDodanieObiektu(self, *args): view = ModalView(size_hint=(None, None), size=(640, 480)) box = BoxLayout(orientation="vertical", spacing=10) scrollView = ScrollView(bar_margin=10, bar_color=[1, 1, 1, 1]) viewWrapper = GridLayout(cols=2, row_default_height=40, size_hint_y=None, padding=[-20, 20, 20, 20]) viewWrapper.bind(minimum_height=viewWrapper.setter('height')) listaTextBoxow = [] for i in range(len(self.sharedInstance.data.temp)): l = Label(text=self.sharedInstance.data.temp[i], halign="left", width=50) #textPlaceHolder = 'Tutaj wpisz wartosc dla {0}'.format(self.sharedInstance.data.temp[i]) #textPlaceHolder,multiline=False, ) textinput = TextInput(multiline=False, text="0", focus=True) listaTextBoxow.append(textinput) viewWrapper.add_widget(l) viewWrapper.add_widget(textinput) #background_color=[51/255.0, 181.0/255, 229/255.0,1] scrollView.add_widget(viewWrapper) box.add_widget(scrollView) box.add_widget( Button(text='Dodaj', font_size=14, on_press=partial(self.dodajObiekt, view, listaTextBoxow), size_hint=(1, .1))) view.add_widget(box) view.open() return view
def helpView(self): """ Show Help/Guides modal (show when help button pressed) """ widgets = FloatLayout( size_hint=(None, None), size=(300, 300), background_color=parse_color("#FF9933"), ) sizer = NumericProperty(30) main = ModalView( title_color=parse_color("#FF9933"), title_size=(25), seperator_height=("9dp"), separator_color=parse_color("#FF9933"), #background_color=parse_color("#FF9933"), size_hint=(None, None), size=(400, 620), content=Image(source="coreEngine/Images/about.png"), ) white_bar = Image(source="coreEngine/Images/whitebar.png", pos=(123, 123), size=(400, 400)) logo = Image(source="coreEngine/Images/about.png") main.add_widget(logo, 1) main.open()
def Load(self): """ Load from the Disk Button > Load() """ from functools import partial from kivy.uix import filechooser from kivy.uix.filechooser import FileChooserListView, FileChooserIconView main = ModalView(size_hint=(.8,.8)) # everything on this Modal is 80% BL = BoxLayout(portrait="vertical") FLV = FileChooserListView(path="coreEngine/Saved",) def cTexloader(instance): Selected = FLV.selection Selected_Attr = Selected LStoString = str(Selected_Attr[0]) self.Loader_NoErr(ctexSaved=LStoString,fixedPath=LStoString) Load_Btn = Button(text="Load this File") Load_Btn.bind(on_press=cTexloader) main.add_widget(BL) BL.add_widget(FLV) BL.add_widget(Load_Btn) main.open()
def Load(self): """ Load from the Disk Button > Load() """ from functools import partial from kivy.uix import filechooser from kivy.uix.filechooser import FileChooserListView, FileChooserIconView main = ModalView(size_hint=(.8, .8)) # everything on this Modal is 80% BL = BoxLayout(portrait="vertical") FLV = FileChooserListView(path="coreEngine/Saved", ) def cTexloader(instance): Selected = FLV.selection Selected_Attr = Selected LStoString = str(Selected_Attr[0]) self.Loader_NoErr(ctexSaved=LStoString, fixedPath=LStoString) Load_Btn = Button(text="Load this File") Load_Btn.bind(on_press=cTexloader) main.add_widget(BL) BL.add_widget(FLV) BL.add_widget(Load_Btn) main.open()
def on_status(self, instance, new_value): status = new_value sums = [ sum(status[0:3]), sum(status[3:6]), sum(status[6:9]), sum(status[0::3]), sum(status[1::3]), sum(status[2::3]), sum(status[::4]), sum(status[2:-2:2]) ] winner = None if 3 in sums: winner = "Os win!" elif -3 in sums: winner = "Xs win!" elif 0 not in self.status: winner = "Draw!" if winner: popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text=winner, font_size=50) popup.add_widget(victory_label) popup.bind(on_dismiss=self.reset) popup.open()
def reset(self, *args): self.status = [0 for _ in range(9)] for child in self.children: child.text = '' child.background_color = (1, 1, 1, 1) self.current_player = 1 winner = None if -3 in sums: winner = 'Выиграли крестики' elif 3 in sums: winner = 'Выиграли нолики' elif 0 not in self.status: winner = 'Ничья' if winner: popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text=winner, font_size=50) popup.add_widget(victory_label) popup.bind(on_dismiss=self.reset) popup.open() for row in range(3): for column in range(3): grid_entry = GridEntry(coords=(row, column)) grid_entry.bind(on_release=self.button_pressed) self.add_widget(grid_entry)
def on_status(self, instance, new_value): status = new_value # Sum each row, col and diag # Could be shorter, but let's be extra # clear what's going on sums = [#rows sum(status[0:3]), #columns sum(status[3:6]), sum(status[6:9]), sum(status[0::3]), #diagonals sum(status[1::3]), sum(status[2::3]), sum(status[::4]), sum(status[2:-2:2])] # Sums can only be +-3 if one player # filled the whole line winner = '' if 3 in sums: winner = '{} win!'.format('Nitya') elif -3 in sums: winner = '{} win!'.format('Pranav') elif 0 not in self.status: #Grid full winner = 'Draw...Nobody wins!' if winner: popup = ModalView(size_hint = (0.75 , 0.5 )) victory_label = Label(text = winner, font_size = 50) popup.add_widget(victory_label) popup.bind(on_dismiss = self.reset) popup.open()
def save_new(self, *args): print("SAVE_NEW") print("path", path) # function to get text from text boxes servers = open(path +"\\" + 'server.json') try: ServerDict = json.load(servers) except ValueError: ServerDict = {} servers.close() grid = self.children[0] temp_list = [i.text for i in grid.children[4:0:-1]] # part of list becasue BoxLayout must be excluded # now need to check if all inputs have text nonBlock = True for item in temp_list: if len(item) < 1: nonBlock = False if nonBlock == True: if temp_list[0] in ServerDict.keys(): p = ModalView(size_hint=(0.7, 0.1)) p.add_widget(Label(text="Wybierz inna nazwe.")) p.open() else: # here stuff will be saved ServerDict[temp_list[0]] = {"address":temp_list[1], "login":temp_list[2], "passw":temp_list[3]} servers = open(path+"\\"+'server.json', 'w') json.dump(ServerDict, servers) servers.close() self.dismiss() else: p = ModalView(size_hint=(0.7, 0.1)) p.add_widget(Label(text="Błędne dane. Sprawdź i popraw...")) p.open()
def show_loading_popup(max=1): popup_window = ModalView(size_hint=(0.2, 0.1), auto_dismiss=False) popup_layout = LoadingPopup(popup_window, max) popup_window.add_widget(popup_layout) popup_window.open() return popup_layout
def callback(instance): from pages import leaveReq leaveReq.Data.append([user, id, department]) view = ModalView(size_hint=(0.5, 0.75), background_color=(0, 0, 0, 0.6)) view.add_widget(leaveReq.LeaveLayout()) view.open()
def show_question_popup(question, condition_function): popup_window = ModalView(size_hint=(0.3, 0.3), auto_dismiss=False) popup_layout = YesNoPopup(popup_window, condition_function, question) popup_window.add_widget(popup_layout) popup_window.open() return popup_window
def buildRuleView(rule, *args): main_layout = FloatLayout() header = Label(text=rule.getName(), pos_hint={ 'center_x': .5, 'top': 1 }, size_hint=(.2, .1), font_size="30sp", bold=True, color=rgba('#0a5e00')) body = WrappedLabel(text=rule.getText(), font_size="20sp", pos_hint={ 'center_x': .5, 'center_y': .5 }, size_hint=(.9, .9)) main_layout.add_widget(header) main_layout.add_widget(body) rule_view = ModalView(size_hint=(.92, .98), background="Resources/262626.png", background_color=rgba('#0a5e00')) rule_view.add_widget(main_layout) rule_view.open()
def GameOverNote(self,survivaltime): popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text="Game Over\n" + "%0.2f"%survivaltime + " sec", font_size=50) popup.add_widget(victory_label) popup.bind(on_dismiss=game.reset) popup.bind(on_press=popup.dismiss) popup.open()
def _on_keyboard_up(self, keyboard, keycode): key_str = keycode[1] if not funcs.check_possibility_to_move(self.game_field_matrix): popup = ModalView(size_hint=(None, None), size=(200, 50), background_color=(1, .7, .2, .4)) popup.add_widget( Button(text='You LOSE!', font_size='25sp', background_color=(1, .7, .2, 1))) popup.open() keyboard.release() state, updated_field = funcs.process_game_step(self.game_field_matrix, key_str) if state != funcs.WRONG_USER_INPUT: self.game_field_matrix = updated_field self.generate_random_number() updated_field = funcs.to_one_dim(self.game_field_matrix)[::-1] for index in range(len(updated_field)): self.children[index].text = str(updated_field[index]) if self.look_for_game_win_state and state == funcs.GAME_WON: self.look_for_game_win_state = False popup = ModalView(size_hint=(None, None), size=(200, 50), background_color=(1, .7, .2, .4)) popup.add_widget( Button(text='You WON!', font_size='25sp', background_color=(1, .7, .2, 1))) popup.open() return True
def helpView(self): """ Show Help/Guides modal (show when help button pressed) """ widgets = FloatLayout(size_hint=(None,None), size=(300,300), background_color=parse_color("#FF9933"),) sizer = NumericProperty(30) main = ModalView(title_color=parse_color("#FF9933"), title_size=(25), seperator_height=("9dp"), separator_color=parse_color("#FF9933"), #background_color=parse_color("#FF9933"), size_hint=(None,None), size=(400,620), content = Image(source="coreEngine/Images/about.png"), ) white_bar = Image(source="coreEngine/Images/whitebar.png", pos=(123,123), size=(400,400)) logo = Image(source="coreEngine/Images/about.png") main.add_widget(logo, 1) main.open()
class HomeScreen(Screen): def workout_options(self): layout = BoxLayout(orientation='vertical') blank_btn = Button(text='Start Blank', size_hint=[.8, 1], pos_hint={'x': .1}, on_release=self.new_workout) template_btn = Button(text='Start from Template', size_hint=[.8, 1], pos_hint={'x': .1}) previous_btn = Button(text='Copy from Previous', size_hint=[.8, 1], pos_hint={'x': .1}) layout.add_widget(blank_btn) layout.add_widget(template_btn) layout.add_widget(previous_btn) self.popup = ModalView(content=layout, size_hint=[1, .5], pos_hint={'top': .5}) self.popup.add_widget(layout) self.popup.open() def new_workout(self, instance): self.popup.dismiss() self.manager.current = 'workout'
def button_pressed(self, button): player = {1: 'X', -1: 'O'} colours = {1: (0, 1, 0, 1), -1: (1, 0, 0, 1)} x, y, z, w = button.coords already_played = self.board[x, y, z, w] != 0 if not already_played: self.board[x, y, z, w] = self.current_player button.text = player[self.current_player] button.background_color = colours[self.current_player] winner = None if check_win(move = button.coords, player = self.current_player, \ moves = self.move_list[self.current_player], \ board = self.board): winner = '{0} wins!'.format(player[self.current_player]) elif 0 not in self.board: winner = 'Draw... nobody wins!' if winner: popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text=winner, font_size=50) popup.add_widget(victory_label) popup.bind(on_dismiss=self.reset) popup.open() else: self.current_player *= -1
def on_status(self, instance, new_value): status = new_value # Sum each row, column and diagonal. # Could be shorter, but let's be extra # clear what’s going on sums = [sum(status[0:3]), # rows sum(status[3:6]), sum(status[6:9]), sum(status[0::3]), # columns sum(status[1::3]), sum(status[2::3]), sum(status[::4]), # diagonals sum(status[2:-2:2])] # Sums can only be +-3 if one player # filled the whole line winner = None if -3 in sums: winner = 'Крестик Выиграл!' elif 3 in sums: winner = 'Нолик Выиграл!' elif 0 not in self.status: winner = 'Ничья....!' if winner: popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text=winner, font_size=50) popup.add_widget(victory_label) popup.bind(on_dismiss=self.reset) popup.open()
def on_status(self, instance, new_value): status = new_value sums = [ sum(status[0:3]), sum(status[3:6]), sum(status[6:9]), sum(status[0::3]), sum(status[1::3]), sum(status[2::3]), sum(status[::4]), sum(status[2:-2:2]) ] resultado = None if -3 in sums: resultado = 'O Joogador 02 (X) ganhou!' elif 3 in sums: resultado = 'O Jogador 01 (O) ganhou!' elif 0 not in self.status: resultado = "Velhou!" if resultado: popup = ModalView(size_hint=(0.75, 0.5)) labelResultado = Label(text=resultado, font_size=50) popup.add_widget(labelResultado) popup.bind(on_dismiss=self.reset) popup.open()
class StudentGridLayout(GridLayout): records = '' show = False def __init__(self, **kwargs): super().__init__() self.cols = 2 self.app = AssessmentApp() def load_student_data(self, dt, records): num = 0 for record in records: for data in record: self.add_widget(Label(text=str(dt[num]))) self.add_widget(Button(text=str(data), size_hint=(.2, .2))) num += 1 print(num) self.add_widget(TextInput()) self.add_widget(Button(text='edit')) self._popup = ModalView(size_hint=(.5, .5)) self._popup.add_widget( self) #Popup(content=self,title='Student data',size_hint=(.7,.7)) self._popup.open() self._popup.bind( on_dismiss=lambda *x: self._popup.remove_widget(self) ) #self._popup.bind(on_dismiss=self._popup.remove_widget(self.children)
def on_press_bt_selected_two_equal_periods(self): popup = ModalView(size_hint=(None,None)) popup.add_widget(Label(text=lang['Selected_two_equal_periods'],size_hint=(None,None),height=30, width=300)) popup.height = 40 popup.width = 300 popup.open() print('selected two equal periods')
def permTime(self): global opDetail #p = leaveData.grant_perm(detail) view = ModalView(size_hint=(0.25, 0.25), background_color=(0, 0, 0, 0.6)) view.add_widget(userSettings.Permission(opDetail)) view.open()
def on_status(self, instance, new_value): status = new_value # Sum each row, col and diag # Could be shorter, but let's be extra # clear what's going on sums = [#rows sum(status[0:3]), #columns sum(status[3:6]), sum(status[6:9]), sum(status[0::3]), #diagonals sum(status[1::3]), sum(status[2::3]), sum(status[::4]), sum(status[2:-2:2])] # Sums can only be +-3 if one player # filled the whole line winner = '' if 3 in sums: winner = '{} win!'.format('O') elif -3 in sums: winner = '{} win!'.format('X') elif 0 not in self.status: #Grid full winner = 'Draw...Nobody wins!' if winner: popup = ModalView(size_hint = (0.75 , 0.5 )) victory_label = Label(text = winner, font_size = 50) popup.add_widget(victory_label) popup.bind(on_dismiss = self.reset) popup.open()
def on_start(self): """ Sets the main window's size, opens airports database connection, decides to render the login window based on the saved settings, and initializes the data manager once the application starts. :return: None """ # Config.set('graphics', 'width', '1050') # Config.set('graphics', 'height', '800') # Config.write() Window.clearcolor = (0, 0, 0, 1) Window.size = (1200, 800) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) db_path = os.path.join(BASE_DIR, "..", "DATA", "global_airports.db") self.airports_connection = sqlite3.connect(db_path) self.airports_cursor = self.airports_connection.cursor() db_path = os.path.join(BASE_DIR, "..", "DATA", "AIRCRAFT_COLLISION_FORECAST_SYSTEM.db") settings_connection = sqlite3.connect(db_path) settings_cursor = settings_connection.cursor() query = f"SELECT STATE FROM SETTINGS WHERE NAME = 'SHOW LOGIN WINDOW'" settings_cursor.execute(query) result = settings_cursor.fetchall() settings_connection.close() if result[0][0] == '1': login_window = ModalView(size_hint=(0.5, 0.5), auto_dismiss=False) login_window.add_widget(LoginView(login_window)) login_window.open() else: self.data_manager = DataManager(airport_id_index=2, airplane_id_index=0) Thread(target=self.data_manager.load_airports).start()
def decode(self): # img = input("Enter image name(with extension) :") img = self.ids.pathLabel.text # Must let PIL know that its a JPEG file, currently using JPG # Just need to use the same if statement as before image = Image.open(img, 'r') data = '' imgdata = iter(image.getdata()) while (True): pixels = [ value for value in imgdata.__next__()[:3] + imgdata.__next__()[:3] + imgdata.__next__()[:3] ] # string of binary data binstr = '' for i in pixels[:8]: if (i % 2 == 0): binstr += '0' else: binstr += '1' data += chr(int(binstr, 2)) if (pixels[-1] % 2 != 0): dmessage = ModalView(size_hint=(None, None), size=(400, 400)) message_label = Label(text="Message:\n\n" + data, text_size=(dmessage.width - 50, None)) dmessage.add_widget(message_label) dmessage.open() return data
def encode(self): # img = input("Enter image name(with extension): ") img = self.ids.pathLabel.text image = Image.open(img, 'r') # data = input("Enter data to be encoded : ") data = self.ids.messageInput.text if (len(data) == 0): raise ValueError('Data is empty') newimg = image.copy() self.encode_enc(newimg, data) # new_img_name = input("Enter the name of new image(with extension): ") # Sets the encoded image to the original image path new_img_name = img # Saves the image newimg.save(new_img_name, self.check_file_type(new_img_name)) message = ModalView(size_hint=(None, None), size=(400, 400)) messageLabel = Label(text="Message Encoded to:\n" + img, text_size=(message.width - 50, None)) message.add_widget(messageLabel) message.open() print('done')
def choose_color(self): view = ModalView() clrpr = ColorPicker() view.add_widget(clrpr) view.open() def on_color(instance, value): self.color_picked = value clrpr.bind(color=on_color)
def launchSimpleModal(text): view = ModalView(size_hint=(0.4, 0.2)) content = SimpleModal(text=text) view.add_widget(content) # bind the on_press event of the button to the dismiss function content.bind(on_press=view.dismiss) # open the view view.open()
def open_settings_window(): """ Opens the settings window. :return: None """ settings_window = ModalView(size_hint=(0.5, 0.5), auto_dismiss=False) settings_window.add_widget(SettingsView(settings_window)) settings_window.open()
def complete(self, *args): source = 'resources/circuit_complete.png' texture = Image(source=source) height = dp((texture.texture_size[1] * self.width) / texture.texture_size[0]) complete_popup = ModalView(size_hint=(1, None), height=height, background=source, background_color=[0, 0, 0, .35], auto_dismiss=False, pos_hint={'center_y': .65}) complete_popup.open() Clock.schedule_once(lambda dt: self.back_home(popup=complete_popup), 7)
class UploadMainWidget(BoxLayout): def __init__(self, **kwargs): super().__init__(**kwargs) self.files = [] self.files_boxs = [] self.uploading = False def upload_files(self): if len(self.files) > 0: for pos, file in enumerate(self.files): self.files[pos] = {f"name": file, "status": "None"} self.service = App.get_running_app().root.drive self.drive = DriveManager(self.service, files=self.files) self.drive.func = "upload" self.drive.start() self.vrf = Clock.schedule_interval(self.check_upload, .1) else: modal = ModalView(size_hint=(None, None), width=300, height=50) modal.add_widget(Label(text="Seleciione arqivos para upload")) modal.open() def check_upload(self, event): for pos, file in enumerate(self.drive.files): self.files_boxs[pos].ids.status.text = file["status"] if not self.drive.proccessing: self.files = [] self.files_boxs = [] self.vrf.cancel() def openfilechooser(self): self.modal = ModalView(size_hint=(.8, .8)) self.modal.padding = 5 self.file_widget = BoxLayout(size_hint=(.8, .9)) self.file_widget.orientation = "vertical" self.filec = FileChooserView() self.file_widget.add_widget(self.filec) self.modal.add_widget(self.file_widget) self.boxbtn = BoxLayout(size_hint=(.8, .1)) self.addbtn = Button(text="Adicionar") self.addbtn.on_press = self.selectfiles self.cancelbtn = Button(text="Terminar ou cancelar") self.cancelbtn.on_press = self.closefilechooser self.boxbtn.add_widget(self.addbtn) self.boxbtn.add_widget(self.cancelbtn) self.file_widget.add_widget(self.boxbtn) self.modal.open() def closefilechooser(self): self.modal.dismiss() def selectfiles(self): self.filec.on_submit()
def showLoading(self,txt="Loading ..."): cnt=BoxLayout() lbl=Label(text=txt) mdl=ModalView(size_hint=(0.9,0.3),auto_dismiss=False) cnt.add_widget(lbl) mdl.add_widget(cnt) mdl.open() self.loader=mdl self.setAnimation(self.loader)
def showGraph (self): if self.goals: show = ModalView (size_hint = (1, 1)) close = Factory.ImageButton (size_hint = (1, 1)) close.children[0].source = "graph/" + os.listdir ("graph")[self.current] close.children[0].size_hint = (1, 1) close.bind (on_press = show.dismiss) show.add_widget (close) show.open()
def on_game_over(self, *args): # print 'entrou no dispatch do game over', args view = ModalView(size_hint=(None, None), size=(600, 400)) label = Label(text='Game Over\nPlayer %s Ganhou!!' % (args[0]), font_size=50, halign="center", valign='middle') view.add_widget(label) view.open()
def on_touch_down(self, touch): if self.collide_point(touch.pos[0], touch.pos[1]): content = Rozpoziomowany() view = ModalView(size_hint=(None, None), size=(400, 400), auto_dismiss=False) view.add_widget(content) btn = content.ids['przejscie'] btn2 = content.ids['menu'] btn.bind(on_press=view.dismiss) btn2.bind(on_press=view.dismiss) view.open()
def on_preferences(self, *args): settings_view = SettingsWithNoMenu() base_dir = self._settings.base_dir settings_view.add_json_panel('Dashboard Preferences', self._settings.userPrefs.config, os.path.join(base_dir, 'resource', 'settings', 'dashboard_settings.json')) popup = ModalView(size_hint=DashboardView._POPUP_SIZE_HINT) popup.add_widget(settings_view) popup.bind(on_dismiss=self._popup_dismissed) popup.open() self._popup = popup
def info_popup(self, msg, callback): def done(): view.dismiss() Clock.schedule_once(lambda dt: callback(), 0.25) view = ModalView(size_hint=(None, None), size=(dp(600), dp(200))) msg = FieldLabel(halign='center', text=msg) view.add_widget(msg) view.open() Clock.schedule_once(lambda dt: done(), 2.0)
def set_language(self, language): language_map = {"English": "en_US", "简体中文": "zh_CN"} self.parent.configer.lang = language_map.get(language, "en_US") self.parent.configer.save_config() # show popup hint view = ModalView(size_hint=(None, None), size=(0, 0)) view.add_widget( Label(text=_("This will take effect next time you start"), font_size=30)) view.open()
def queryTableNames(n, callback): view = ModalView(size_hint=(None, None), size=(400, 200), background_color=(0, 0, 0, .6), auto_dismiss=True) def save_and_close(x): view.dismiss() callback(x) view.add_widget(QueryTableNamesWidget(n_tables=3, callback=save_and_close)) view.open() print self.table_names return self.table_names
def check_board(self): values = [[self.get_value(row, col) for col in range(9)] for row in range(9)] if solver.check_board(values): win = ModalView(size_hint=(None, None), size=(300, 100)) win.add_widget(Label(text='Congratualtions', font_size=20)) win.open() else: loss = ModalView(size_hint=(None, None), size=(300, 100)) loss.add_widget(Label(text='You have some mistakes', font_size=20)) loss.open()
def on_pre_enter(self): for child in self.ids.grid.children: child.background_color = [1, 1, 1, 1] def my_callback(dt): view.dismiss() view = ModalView(size=(100, 100)) view.background = 'img.jpg' view.open() Clock.schedule_once(my_callback, 5)
def set_language(self, language): language_map = { "English": "en_US", "简体中文": "zh_CN" } self.parent.configer.lang = language_map.get(language, "en_US") self.parent.configer.save_config() # show popup hint view = ModalView(size_hint=(None, None), size=(0, 0)) view.add_widget(Label(text=_("This will take effect next time you start"), font_size=30)) view.open()
def on_press_bt_selected_two_equal_periods(self): popup = ModalView(size_hint=(None, None)) popup.add_widget( Label(text=lang['Selected_two_equal_periods'], size_hint=(None, None), height=30, width=300)) popup.height = 40 popup.width = 300 popup.open() print('selected two equal periods')
class ButtonTreeItem(Button): def __init__(self, num, outward, **kwargs): super(ButtonTreeItem, self).__init__(**kwargs) self.size = (20, window_height/btnHeightRate) # 20 isn't change anything self.size_hint_y = None self.num = num self.context = False self.outward = outward def on_touch_down(self, touch): if self.collide_point(*touch.pos): self.create_clock() return super(ButtonTreeItem, self).on_touch_down(touch) def on_touch_up(self, touch): if self.collide_point(*touch.pos): self.delete_clock() if self.context : self.context = False return True return super(ButtonTreeItem, self).on_touch_up(touch) def create_clock(self, *args): Clock.schedule_once(self.openContextMenu, timeOut_forContextMenu) def delete_clock(self, *args): Clock.unschedule(self.openContextMenu) def openContextMenu(self, *args): self.context = True self.contextMenu = ModalView(size_hint=(0.5, 0.5)) self.contextMenu.bind(on_dismiss=self.outward.showTree()) contextLayout = BoxLayout( padding = 10, spacing = 10, pos_hint = {'center_x': 0.5, 'center_y': 0.5}, size_hint = (0.7, 0.8), orientation = 'vertical') contextLayout.add_widget(Label(text=self.text)) btnDelete = Button(text='delete') btnDelete.bind(on_press=self.delete) contextLayout.add_widget(btnDelete) close = Button(text='close') close.bind(on_release=self.contextMenu.dismiss) contextLayout.add_widget(close) self.contextMenu.add_widget(contextLayout) self.contextMenu.open() def delete(self, *args): tree.curItem().remove(self.num) self.contextMenu.dismiss() self.outward.showTree()
def modal_insert(self): lbl1 = Label(text='ID', id="lbl") lbl2 = Label(text='Nome', id="lbl") lbl3 = Label(text='Preco', id="lbl") lbl4 = Label(text='IVA', id="lbl") txt1 = TextInput(text='000', id="txtinp") txt2 = TextInput(text='Product Name', id="txtinp") txt3 = TextInput(text='123.45', id="txtinp") txt4 = TextInput(text='23', id="txtinp") insertion_grid = GridLayout(cols=2) insertion_grid.add_widget(lbl1) insertion_grid.add_widget(txt1) insertion_grid.add_widget(lbl2) insertion_grid.add_widget(txt2) insertion_grid.add_widget(lbl3) insertion_grid.add_widget(txt3) insertion_grid.add_widget(lbl4) insertion_grid.add_widget(txt4) # create content and assign to the view content = Button(text='Close me!') modal_layout = BoxLayout(orientation="vertical") modal_layout.add_widget(insertion_grid) def insert_def(self): input_list = [] for text_inputs in reversed(self.parent.children[2].children): if text_inputs.id == "txtinp": input_list.append(text_inputs.text) print input_list grid.add_row(input_list, body_alignment, col_size, self) # print view # view.dismiss insert_btn = Button(text="Insert", on_press=insert_def) modal_layout.add_widget(insert_btn) modal_layout.add_widget(content) view = ModalView(auto_dismiss=False) view.add_widget(modal_layout) # bind the on_press event of the button to the dismiss function content.bind(on_press=view.dismiss) insert_btn.bind(on_release=view.dismiss) view.open()
def on_back(self): # game still running, ask for user confirmation if self.state == 'running': SoundManager.play(Trigger.GAME_PAUSE) view = ModalView(size_hint=(None, None), size=(600, 400), auto_dismiss=False) content = Factory.STModalView(title='Spiel abbrechen', text='Das Spiel ist noch nicht beendet.\nWirklich abbrechen?', cb_yes=self.cancel_match, cb_no=self.resume_match) view.add_widget(content) view.open() # game not running anymore elif self.state in ['finished', 'submitting', 'submit_failed']: view = ModalView(size_hint=(None, None), size=(600, 400), auto_dismiss=False) content = Factory.STModalView(title='Spiel abbrechen', text='Das Ergebnis wurde noch nicht hochgeladen.\nWirklich abbrechen?', cb_yes=self.cancel_match) view.add_widget(content) view.open() else: self.manager.current = 'lounge'
def on_preferences(self, *args): """ Display the dashboard preferences view """ settings_view = DashboardPreferences(self._settings, self._dashboard_factory) def popup_dismissed(*args): self._notify_preference_listeners() screens = settings_view.get_selected_screens() screens = self._filter_dashboard_screens(screens) self._settings.userPrefs.set_dashboard_screens(screens) self._update_screens(screens) popup = ModalView(size_hint=DashboardView._POPUP_SIZE_HINT) popup.add_widget(settings_view) popup.bind(on_dismiss=popup_dismissed) popup.open()
def show_modal(self, dt): modal = ModalView(size_hint=(0.5, 0.3), auto_dismiss=False) modalBox = BoxLayout(orientation="vertical", spacing=5, padding=10) txt = TextInput(hint_text="Takma ad giriniz...", size_hint=(1, None), height=50) modalBox.add_widget(txt) modalBtn = Button(text="Tamam", size_hint=(1, None), height=50) def setNick(instance): self.setted = True self.nick = txt.text modal.dismiss() self.root.opacity = 1 self.connect_to_server() modalBtn.bind(on_release=setNick) modalBox.add_widget(modalBtn) modal.add_widget(modalBox) modal.open()
def on_heatmap_options(self): def popup_dismissed(response): self._update_heatmap_preferences() settings_view = SettingsWithNoMenu() base_dir = self._settings.base_dir settings_view.add_json_panel('Heatmap Settings', self._settings.userPrefs.config, os.path.join(base_dir, 'autosportlabs', 'racecapture', 'views', 'dashboard', 'heatmap_settings.json')) popup = ModalView(size_hint=HeatmapView._POPUP_SIZE_HINT) popup.add_widget(settings_view) popup.bind(on_dismiss=popup_dismissed) popup.open()
def on_status(self, instance,status): status=self.status #sum each row, column and diagonal sums=[sum(status[0:3]),sum(status[3:6]),sum(status[6:9]), #rows sum(status[0::3]),sum(status[1::3]),sum(status[2::3]), #cols sum(status[0::4]),sum(status[2:-2:2])] # diagonals winner=None if 3 in sums: print(self.status) winner='Player 1 (O) wins!\n Would you like to play again?' elif -3 in sums: print(self.status) winner='Player 2 (X) wins!\n Would you like to play again?' elif 0 not in self.status: #grid full print(self.status) winner='Draw! \n Would you like to play again?' if winner: # create a button float=FloatLayout(size_hint=(0.5,0.5)) y_button=Button(text="Y",font_size=20,pos_hint={'x':0.4, 'center_y': 0.5},size_hint=(None,None)) n_button=Button(text="N",font_size=20,pos_hint={'x':0.6, 'center_y': 0.5},size_hint=(None,None)) float.add_widget(y_button) float.add_widget(n_button) popup=ModalView(size_hint=(0.5,0.5)) victory_label=Label(text=winner,pos_hint={'x': 0.3, 'center_y':0.7},size_hint=(None,None)) float.add_widget(victory_label) popup.add_widget(float) if y_button: self.reset popup.bind(on_dismiss=self.reset) popup.open()
def choose(self, button): from HoneyApp import HoneyApp def get_date_diff_string(): timestamp_diff = (datetime.datetime.fromtimestamp(self.current_images[self.IMAGE_TYPE_LEFT]['timestamp']) - datetime.datetime.fromtimestamp(self.current_images[self.IMAGE_TYPE_RIGHT]['timestamp'])) return str(abs(timestamp_diff.days)) + ' дней' if button.type == self.IMAGE_TYPE_LEFT: image_chosen_timestamp = self.current_images[self.IMAGE_TYPE_LEFT]['timestamp'] image_another_timestamp = self.current_images[self.IMAGE_TYPE_RIGHT]['timestamp'] else: image_chosen_timestamp = self.current_images[self.IMAGE_TYPE_RIGHT]['timestamp'] image_another_timestamp = self.current_images[self.IMAGE_TYPE_LEFT]['timestamp'] if image_chosen_timestamp < image_another_timestamp: status = True else: status = False modal = ModalView(size_hint=(None, None), size=(400, 200)) if status: modal.bind(on_dismiss=self.renew_images) modal_data = random.choice(HoneyApp.success) else: modal_data = random.choice(HoneyApp.error) layout = GridLayout(cols=1, rows=2, on_touch_down=modal.dismiss) text = '[size=18][b]{text}[/b][/size]\n' \ '[size=11]Эта фотография была сделана: [b]{image_date_chosen}[/b]\n' \ 'Дата второй фотографии: [b]{image_date_another}[/b]\n' \ 'Разница - [b]{date_diff}[/b][/size]'.\ format(text=modal_data['text'], image_date_chosen=datetime.datetime.fromtimestamp(image_chosen_timestamp).strftime('%d.%m.%Y %H:%M'), image_date_another=datetime.datetime.fromtimestamp(image_another_timestamp).strftime('%d.%m.%Y %H:%M'), date_diff=get_date_diff_string()) layout.add_widget(Label(text=text, markup=True)) layout.add_widget(Image(source=modal_data['filename'])) modal.add_widget(layout) modal.open()
def on_status(self, instance, new_value): status = new_value sums = [sum(status[0:3]), sum(status[3:6]), sum(status[6:9]), sum(status[0::3]), sum(status[1::3]), sum(status[2::3]), sum(status[::4]), sum(status[2:-2:2])] winner = None if 3 in sums: winner = "Os win!" elif -3 in sums: winner = "Xs win!" elif 0 not in self.status: winner = "Draw!" if winner: popup = ModalView(size_hint=(0.75, 0.5)) victory_label = Label(text=winner, font_size = 50) popup.add_widget(victory_label) popup.bind(on_dismiss = self.reset) popup.open()
def go(self,screen): if screen=="about": cnt=BoxLayout(padding=0,spacing=0) lbl=Label(text=" [size=20]pyPuzzle Game[/size]\n\nSimple fun memory game\n\n" "Match simple jelly images\n\nEnter your scores.\n\n" "www.yahyakesenek.com @2016",markup=True) cnt.add_widget(lbl) modal=ModalView(size_hint=(0.7,0.5),background_color=get_color_from_hex("#ff7373")) modal.add_widget(cnt) modal.open() modal.x=self.root.x-modal.width-10 anim=Animation(center_x=self.root.center_x,center_y=self.root.center_y,d=2,t="out_expo") anim.start(modal) return if screen=="settings": cnt=BoxLayout() lbl=Label(text="Set Sound Volume :") sld=Slider(max=100,min=0,value=25) sld.bind(value=self.value_change) cnt.add_widget(lbl);cnt.add_widget(sld) modal=ModalView(size_hint=(0.8,0.2),background_color=get_color_from_hex("#ff7373")) modal.add_widget(cnt) modal.open() modal.x=self.root.x+modal.width+10 anim=Animation(center_x=self.root.center_x,center_y=self.root.center_y,d=2,t="out_expo") anim.start(modal) self.sld=sld return if screen=="exit": cnt=BoxLayout(size_hint=(0.8,0.5),padding=4,spacing=5) lbl=Label(text="[size=35][color=#ae5a41]Quit?[/color][/size]",markup=True) btnyes=Button(text="Yes") btnno=Button(text="No") modal=ModalView(size_hint=(0.8,0.2)) def quit(inst): exit() def cancel(inst): if modal: modal.dismiss() if self.root.current=="game_screen": self.root.current_screen.newGame() btnyes.bind(on_release=quit) btnno.bind(on_release=cancel) cnt.add_widget(lbl) cnt.add_widget(btnyes) cnt.add_widget(btnno) modal.add_widget(cnt) modal.open() return if screen=="end_screen": self.level=1 self.root.current=screen if self.root.current=="main_screen": if self.snd.state=="stop": self.snd.play() else: self.snd.stop()
def posted(self,inst,data): import json from time import strptime,strftime,time res=json.loads(data.decode()) if not isinstance(data,dict) else data scores=res["scores"] modal=ModalView(size_hint=(0.8,0.65)) scrl=ScrollView(size_hint=(0.9,0.9),spacing=2) cnt=BoxLayout(orientation="vertical",size_hint=(1,None),height=50) mb=BoxLayout() lbl=Label(text="[color=#aef4f3]Name[/color]",markup=True) mb.add_widget(lbl) lbl=Label(text="[color=#aef4f3]Score[/color] ",markup=True) mb.add_widget(lbl) lbl=Label(text="[color=#aef4f3]Date[/color] ",markup=True) mb.add_widget(lbl) cnt.add_widget(mb) for score in scores: bx=BoxLayout() with bx.canvas.before: Color(get_color_from_hex("#abc")) lbl=Label(text=score["ad"]) bx.add_widget(lbl) lbl=Label(text=score["puan"]) bx.add_widget(lbl) tms=strptime(score["zaman"],"%Y-%m-%d %H:%M:%S") lbl=Label(text=str(tms.tm_mday)+"."+str(tms.tm_mon)+"."+str(tms.tm_year)) bx.add_widget(lbl) cnt.add_widget(bx) cnt.height=len(scores)*50 scrl.add_widget(cnt) modal.add_widget(scrl) if self.loader: self.loader.dismiss() modal.open() self.setAnimation(modal,once=True)
def countDown(self,dt): self.total -=dt if self.total<=0: Clock.unschedule(self.countDown) if self.game.root.get_current=="end_screen": self.game.root.current="main_screen" tmo=SoundLoader.load("sounds/time_over.ogg") tmo.volume=self.vol tmo.play() cnt=BoxLayout(orientation="vertical",size_hint=(.9,0.7),pos_hint={"center_x":0.5,"center_y":0.5}) modal=ModalView(size_hint=(0.5,0.5),auto_dismiss=False,pos_hint={"center_x":0.5,"center_y":0.5}) lbl=Label(text="[color=#aef4f3]Time Out![/color]",markup=True,size_hint=(1,None),height=30) btnplay=Button(text="Replay",size_hint=(1,None),height=50) btnquit=Button(text="Quit",size_hint=(1,None),height=50) def replay(inst): if modal: modal.dismiss() self.newGame() def quit(inst): if modal: modal.dismiss() self.game.go("exit") btnplay.bind(on_release=replay) btnquit.bind(on_release=quit) cnt.add_widget(lbl) cnt.add_widget(btnplay) cnt.add_widget(btnquit) modal.add_widget(cnt) modal.open() return min,sec=divmod(self.total,60) min=int(min) sec=int(sec) self.game.timer=str(min)+":"+str(sec)