def disconnect_popup(self): popup = Popup(title='Choisissez un premier sommet', size_hint=(0.9, 0.9), auto_dismiss=False) bl = BoxLayout(orientation='vertical') confirm_button = Button(text="Confirmer") confirm_button.disabled = True list_adapter1 = ListAdapter(data=[ str(i + 1) + "- " + self.g.get_sommets()[i].nom for i in range(len(self.g.get_sommets())) ], cls=ListItemButton, sorted_keys=[]) list_adapter1.bind( on_selection_change=lambda a: self.selection_change_disco( list_adapter1, 0, confirm_button)) list_view1 = ListView(adapter=list_adapter1) bl.add_widget(list_view1) confirm_button.bind(on_press=lambda a: self.disconnect_popup2(popup)) cancel_button = Button(text="Annuler") cancel_button.bind(on_press=lambda a: popup.dismiss()) bl.add_widget(confirm_button) bl.add_widget(cancel_button) popup.content = bl popup.open()
def p_degree(self, popup): popup.dismiss() popup = Popup(title='Sommets par degre', size_hint=(0.9, 0.9), auto_dismiss=False) bl = BoxLayout(orientation='vertical') list_adapter1 = ListAdapter(data=[ str(i + 1) + "- " + self.g.get_sommets_by_degree()[i].nom for i in range(len(self.g.get_sommets())) ], cls=ListItemButton, sorted_keys=[]) list_adapter1.bind(on_selection_change=lambda a: self.selected( list_adapter1, "degre")) list_view1 = ListView(adapter=list_adapter1) bl.add_widget(list_view1) cancel_button = Button(text="Fermer") cancel_button.bind(on_press=lambda a: popup.dismiss()) bl.add_widget(cancel_button) popup.content = bl popup.open()
def connect_popup(self): popup = Popup(title='Connecter deux sommets', size_hint=(0.9, 0.9), auto_dismiss=False) bl = BoxLayout(orientation='vertical') confirm_button = Button(text="Confirmer") confirm_button.disabled = True gl_inputs = GridLayout(cols=2) gl_inputs.add_widget(Label(text="Sommet 1")) gl_inputs.add_widget(Label(text="Sommet 2")) list_adapter1 = ListAdapter(data=[ str(i + 1) + "- " + self.g.get_sommets()[i].nom for i in range(len(self.g.get_sommets())) ], cls=ListItemButton, sorted_keys=[]) list_adapter1.bind(on_selection_change=lambda a: self.selection_change( list_adapter1, 0, list_adapter2, confirm_button)) list_view1 = ListView(adapter=list_adapter1) gl_inputs.add_widget(list_view1) list_adapter2 = ListAdapter(data=[ str(i + 1) + "- " + self.g.get_sommets()[i].nom for i in range(len(self.g.get_sommets())) ], cls=ListItemButton, sorted_keys=[]) list_adapter2.bind(on_selection_change=lambda a: self.selection_change( list_adapter2, 1, list_adapter1, confirm_button)) list_view2 = ListView(adapter=list_adapter2) gl_inputs.add_widget(list_view2) bl.add_widget(gl_inputs) confirm_button.bind(on_press=lambda a: self.connect(popup)) cancel_button = Button(text="Annuler") cancel_button.bind(on_press=lambda a: popup.dismiss()) bl.add_widget(confirm_button) bl.add_widget(cancel_button) popup.content = bl popup.open()
class MainView(BoxLayout): def __init__(self, **kwargs): kwargs['cols'] = 2 super(MainView, self).__init__(**kwargs) # def build(self): # global store project_store = JsonStore('projectlist.json') self.list_adapter = ListAdapter(data=[("Project " + r + ' ' + project_store[r]['profile']['projecttitle']) for r in project_store.keys()], cls=ListItemButton, sorted_keys=[]) self.list_adapter.bind(on_selection_change=self.callback) list_view = ListView(adapter=self.list_adapter) self.add_widget(list_view) def callback(self, instance): global PROJECT p_num= instance.selection[0].text.split(' ')[1] PROJECT = p_num print p_num print 'project' return PROJECT
def aff_list_succ(self): popup = Popup(title='Liste de successeurs', size_hint=(0.9, 0.9), auto_dismiss=False) bl = BoxLayout(orientation="vertical") list_adapter1 = ListAdapter(data=[ str(i + 1) + "- " + self.g.get_sommets()[i].__repr__() for i in range(len(self.g.get_sommets())) ], cls=ListItemButton, sorted_keys=[]) list_adapter1.bind(on_selection_change=lambda a: self.selected( list_adapter1, "no_filter")) list_view1 = ListView(adapter=list_adapter1) bl.add_widget(list_view1) bt = Button(text="Fermer") bt.bind(on_press=lambda a: popup.dismiss()) bl.add_widget(bt) popup.content = bl popup.open()
class MainView(BoxLayout): def __init__(self, **kwargs): kwargs['cols'] = 2 super(MainView, self).__init__(**kwargs) self.orientation = 'vertical' self.list_adapter = ListAdapter(data=["Item #{0}".format(i) for i in range(10)], cls=ListItemButton, sorted_keys=[]) self.list_adapter.bind(on_selection_change=self.selection_change) list_view = ListView(adapter=self.list_adapter) self.add_widget(list_view) self.add_widget(Button(text="select random item", on_press=self.callback)) def callback(self, instance): index = randint(0, 9) self.change_from_code = True if not self.list_adapter.get_view(index).is_selected: self.list_adapter.get_view(index).trigger_action(duration=0) self.change_from_code = False def selection_change(self, adapter, *args): if self.change_from_code: print("selection change from code") else: print("selection changed by click")
class MainView(GridLayout): def __init__(self, **kwargs): kwargs['cols'] = 2 super(MainView, self).__init__(**kwargs) self.orientation = 'vertical' self.network = Network() listUser = self.network.getAllUsers() self.myListAdapter = ListAdapter(data=[str(listUser[i]) for i in range(len(listUser))], cls=ListItemButton, selection_mode='single', sorted_keys=[]) self.myListAdapter.bind(on_selection_change=self.selectionChange) myListView = ListView(adapter=self.myListAdapter) self.add_widget(myListView) self.layout = BoxLayout(orientation='vertical') lbl = Label(text = 'SELECT USER FROM LIST') btn1 = Button(text='Friends', background_color = (0.988, 0.53, 0.70, 1.0)) btn1.bind(on_press=self.clickFriends) btn2 = Button(text='Friends of friends', background_color = (0.988, 0.53, 0.70, 1.0)) btn2.bind(on_press=self.clickFriendsOfFriends) btn3 = Button(text='Suggested friend', background_color = (0.988, 0.53, 0.70, 1.0)) btn3.bind(on_press=self.clickSuggestedFriends) self.layout.add_widget(lbl) self.layout.add_widget(btn1) self.layout.add_widget(btn2) self.layout.add_widget(btn3) people = "" self.add_widget(self.layout) def selectionChange(self, adapter, *args): if (adapter.selection): self.layout.disabled = False self.people = str(adapter.selection[0].text) def clickFriends(self, adapter): listUser1 = self.network.getFriends(self.people) lvAdapter = SimpleListAdapter(data=[str(listUser1[i]) for i in range(len(listUser1))],cls=Label) lv = ListView(adapter=lvAdapter) myTitle = str(self.people) myTitle += "\nFriends: "; popup = Popup(title=myTitle, content=lv, size_hint = (None, None), size=(400,400)) popup.open() def clickFriendsOfFriends(self, adapter): listUser1 = self.network.getFriendOfFriends(self.people) lvAdapter = SimpleListAdapter(data=[str(listUser1[i]) for i in range(len(listUser1))],cls=Label) lv = ListView(adapter=lvAdapter) myTitle = str(self.people) myTitle += "\nFriends of Friends: "; popup = Popup(title=myTitle, content=lv, size_hint = (None, None), size=(400,400)) popup.open() def clickSuggestedFriends(self, adapter): listUser1 = self.network.getSuggestedFriend(self.people) lvAdapter = SimpleListAdapter(data=[str(listUser1[i]) for i in range(len(listUser1))],cls=Label) lv = ListView(adapter=lvAdapter) myTitle = str(self.people) myTitle += "\nSuggested Friends: "; popup = Popup(title=myTitle, content=lv, size_hint = (None, None), size=(400,400)) popup.open()