class UnderControl(App): def build(self): self.gui_running = True self.actingAsServer = False self.actingAsClient = False self.firstServerSendCommPage = True self.screen_manager = ScreenManager() #adding the intro page of the app to the app screen manager self.introPage = IntroPage(self) self.add_new_page(self.introPage, "Intro") #adding the the initializing page to the app screen manager self.initializingPage = InitializingPage(self) self.add_new_page(self.initializingPage, "Initialize") return self.screen_manager def add_new_page(self, page, screen_name, on_enter_func=None): self.screen = Screen(name=screen_name) self.screen.add_widget(page) if on_enter_func != None: self.screen.bind(on_enter=on_enter_func) self.screen_manager.add_widget(self.screen) def on_stop(self): self.gui_running = False #acts to be taken on closing the app in case it was acting as a server if self.actingAsServer: #closing the server connections for client in self.server.connections: client["Socket"].close() #making a flase client to termainate the acceptance_thread of the app fakeClient = ClientReverseShell("localhost", self.server_port) fakeClient.send_data("") elif self.actingAsClient: self.MainApp.client.sock.close()
def build(self): # initialize logger #KL.start([DataMode.file, DataMode.communication]) #, "/sdcard/curiosity/", the_ip='127.0.0.1')#self.user_data_dir) KL.start([DataMode.file, DataMode.communication, DataMode.ros], self.user_data_dir) self.cg = CuriosityGame(self) self.cf = ConsentForm(self) self.cei2 = CEI2() self.qf = [] for p in range(0, len(self.cei2.page_dict)): self.qf.append(QuestionsForm(self, self.cei2.page_dict[p])) self.learn = Learning(self) self.lf = [LearningForm(self), LearningForm(self)] self.df = DetailsForm(self) self.ff = FinalForm(self) self.score = CuriosityScore(self.cg.game_duration, len(self.cg.items), self.user_data_dir) self.sm = ScreenManager() screen = Screen(name='consent') screen.add_widget(self.cf) self.sm.add_widget(screen) screen = Screen(name='thegame') screen.add_widget(self.cg.the_widget) self.sm.add_widget(screen) for kqf in range(0, len(self.qf)): screen = Screen(name="question"+str(kqf)) screen.add_widget(self.qf[kqf]) self.sm.add_widget(screen) screen = Screen(name="learning_0") screen.add_widget(self.lf[0]) screen.bind(on_pre_enter=self.learn.start) self.sm.add_widget(screen) screen = Screen(name="learning_1") screen.add_widget(self.lf[1]) self.sm.add_widget(screen) screen = Screen(name="details") screen.add_widget(self.df) self.sm.add_widget(screen) screen = Screen(name="final") screen.bind(on_enter=self.ff.start) screen.add_widget(self.ff) self.sm.add_widget(screen) self.start() return self.sm
def build(self): if not os.path.isdir(PROFILE_PICTURES_LOCATION): os.makedirs(PROFILE_PICTURES_LOCATION) state = State() sm = ScreenManager() create_screen = Screen(name="create_db_screen") create_screen.add_widget( CreateDBWidget(state=state, db_filename=DB_FILENAME)) sm.add_widget(create_screen) login_screen = Screen(name="login_screen") login_screen.add_widget( LoginWidget(state=state, sm=sm, db_filename=DB_FILENAME)) sm.add_widget(login_screen) roster_screen = Screen(name="roster_screen") roster_widget = RosterWidget(state=state, sm=sm) roster_screen.add_widget(roster_widget) roster_screen.bind(on_pre_enter=roster_widget.on_pre_enter) sm.add_widget(roster_screen) contact_add_screen = Screen(name="contact_add_screen") contact_add_screen.add_widget(ContactAddWidget(state=state, sm=sm)) sm.add_widget(contact_add_screen) contact_edit_screen = Screen(name="contact_edit_screen") contact_edit_screen.add_widget( ContactEditWidget(state=state, sm=sm, screen=contact_edit_screen)) sm.add_widget(contact_edit_screen) if os.path.isdir(DB_FILENAME): sm.current = "login_screen" else: sm.current = "create_db_screen" # # XXX: this is only for debug # state.set_backend( # Backend(db_location=DB_FILENAME, key=state.hash_pin("1234")) # ) # state.set_edited_contact("Alice") # sm.current = "contact_edit_screen" return sm
def screen(self, screen_manager, data_store): """ Return a screen instance containing all the necessary UI items that have been associated with the expected event handlers. :param kivy.uix.screenmanager.ScreenManager screen_manager: The UI stack of screens which controls which card is to be displayed. :param dict data_store: A dictionary containing application state. :return kivy.uix.screenmanager.Screen: A graphical representation of the card. """ # References to app related objects. self.screen_manager = screen_manager self.data_store = data_store # The Kivy Screen instance used to draw the UI. screen = Screen(name=self.title) # Bind event handlers to life-cycle events. screen.bind(on_enter=self._enter) screen.bind(on_pre_enter=self._pre_enter) screen.bind(on_pre_leave=self._leave) # The main layout that defines how UI elements are drawn. self.layout = BoxLayout(orientation="vertical") screen.add_widget(self.layout) # The sound player for this card. self.player = None # Text font size for the Screen instance. self.font_size = "{}sp".format(self.text_size) if self.form: self._draw_form() elif self.text: self._draw_text() else: # For padding purposes. self.layout.add_widget(Label(text=" ")) if self.sound: self.player = SoundLoader.load(self.sound) self.player.loop = self.sound_repeat if self.background: self.layout.bind(size=self._update_rect, pos=self._update_rect) with self.layout.canvas.before: if isinstance(self.background, tuple): Color(*self.background) self.rect = Rectangle(size=self.layout.size, pos=self.layout.pos) else: self.rect = Rectangle( source=self.background, size=self.layout.size, pos=self.layout.pos, ) if self.buttons: self._draw_buttons() return screen
class RootWidget(ScreenManager): def switch_screen(self): self.current = "list" self.dropdown.dismiss() def send_search(self, term, response_list) -> type(None): new_screen = "search" response_dict = search(term)['data'] if response_dict is None: return None else: response_list.append(response_dict) for item in response_list: item_view = ProductView(item) self.search_screen.add_widget(item_view) self.current = new_screen self.dropdown.dismiss() def __init__(self, **kwargs): # make sure we aren't overriding any important functionality super().__init__(**kwargs) self.screen1 = Screen(name="1") self.search_screen = Screen(name="search") self.list_screen = Screen(name="list") # Add widgets---------------------------------------------------------- with self.screen1.canvas.before: Color(0, 0, 0, 1) self.screen1.rect = Rectangle(size=self.screen1.size, pos=self.screen1.pos) def update_rect(instance, value): instance.rect.pos = instance.pos instance.rect.size = instance.size # listen to size and position changes self.screen1.bind(pos=update_rect, size=update_rect) # Add image ---------------------------------------------------- self.screen1.add_widget(Image(source='Phrijj.png', size_hint=(1, 1), pos_hint={ 'center_x': 0.5, 'center_y': 0.6 }), index=1) # -------------------------------------------------------------- # Add textinput ------------------------------------------------ self.textinput = TextInput(hint_text="Search for ingredients", multiline=False, size_hint_y=None, height=44, pos_hint={ 'center_x': 0.5, 'center_y': 0.95 }, opacity=1) # Add dropdown menu -------------------------------------------- self.dropdown = DropDown() self.dropdown.add_widget(self.textinput) # Add buttons to dropdown menu search_button = Button(color=(0, 0, 0, 1), background_color=(255, 255, 255, 255), text="Search", size_hint_y=None, height=44) self.search_response_list = [] search_button.bind(on_press=lambda widget: self.send_search( self.textinput.text, self.search_response_list)) self.dropdown.add_widget(search_button) show_button = Button(color=(0, 0, 0, 1), background_color=(255, 255, 255, 255), text="Show", size_hint_y=None, height=44) show_button.bind(on_press=lambda widget: self.switch_screen()) self.dropdown.add_widget(show_button) # -------------------------------------------------------------- # Add enter button --------------------------------------------- self.enter_button = Button( color=(0, 0, 0, 1), background_color=(255, 255, 255, 255), text="Start!", size_hint=(1, .2), pos_hint={ 'center_x': 0.5, 'center_y': 0.07 }, ) self.enter_button.bind(on_release=self.dropdown.open) self.screen1.add_widget(self.enter_button, index=0) self.add_widget(self.screen1) self.add_widget(self.list_screen) self.add_widget(self.search_screen)
def build(self): if (not self.is_desktop()): Config.set('postproc', 'retain_time', '10') Config.set('postproc', 'double_tap_time', '1') Config.set('postproc', 'triple_tap_time', '2') Config.set('graphics', 'fullscreen', 'auto') Config.write() ################################## platform = kivy.utils.platform() ################################## # Start screen ################################## start_screen = Screen(name='start') start_screen.bind(on_pre_enter=self.generate_start_screen) ################################## # Card screen ################################## card_layout = BoxLayout(orientation='vertical',size_hint=(1,.95)) card_widget = BoxLayout(size_hint=(1,.85)) card_buttons_widget = BoxLayout(size_hint=(1,.15)) self.card_label = Label(markup=True, pos=(0,0), font_name='img/ipag.ttf', font_size=64, halign="center", valign="top") self.card_label.bind(on_touch_down=self.on_card_press) card_widget.add_widget(self.card_label) again_btn = Button(markeup=True) again_btn.text = "again" again_btn.bind(on_press=self.process_card_btn) card_buttons_widget.add_widget(again_btn) soon_btn = Button(markeup=True) soon_btn.text = "soon" soon_btn.bind(on_press=self.process_card_btn) card_buttons_widget.add_widget(soon_btn) later_btn = Button(markeup=True) later_btn.text = "later" later_btn.bind(on_press=self.process_card_btn) card_buttons_widget.add_widget(later_btn) never_btn = Button(markeup=True) never_btn.text = "never" never_btn.bind(on_press=self.process_card_btn) card_buttons_widget.add_widget(never_btn) card_layout.add_widget(card_widget) card_layout.add_widget(card_buttons_widget) card_screen = Screen(name='main') card_screen.add_widget(card_layout) card_screen.bind(on_enter=self.card_refresh) ################################## # Settings screen ################################## settings_screen = SettingsScreen(name='settings') settings_screen.add_widget(self.generate_settings()) ################################## # No more cards screen ################################## no_more_layout = BoxLayout(size_hint=(1,1), orientation='vertical') no_more_label = Label(markup=True, pos=(0,0), font_name='img/ipag.ttf', size_hint=(1,.85), font_size=64, halign="center", text="No more cards to review.") no_more_layout.add_widget(no_more_label) no_more_btn_layout = BoxLayout(size_hint=(1,.15)) no_more_home_btn = Button(markup=True) no_more_home_btn.text = "Home" no_more_home_btn.bind(on_press=self.go_to_start_screen) no_more_btn_layout.add_widget(no_more_home_btn) no_more_exit_btn = Button(markup=True) no_more_exit_btn.text = "Done" no_more_exit_btn.bind(on_press=sys.exit) no_more_btn_layout.add_widget(no_more_exit_btn) no_more_layout.add_widget(no_more_btn_layout) no_more_screen = Screen(name='finished') no_more_screen.add_widget(no_more_layout) import_layout = BoxLayout(size_hint=(1,1), orientation='vertical') self.import_msg_label = Label(markup=True, pos=(0,0), font_name = 'img/ipag.ttf', size_hint=(1,.1), font_size=24, halign='left', text='Please select a .tsv file.') import_layout.add_widget(self.import_msg_label) #TODO P3: Can we increase text size? import_file_chooser = FileChooserListView(on_submit=self.import_list, path='/') import_file_chooser.bind(selection=self.import_list) import_layout.add_widget(import_file_chooser) import_cancel_button = Button(text="Cancel", on_press=self.go_to_start_screen, size_hint=(1,.15)) import_layout.add_widget(import_cancel_button) import_screen = Screen(name='import') import_screen.add_widget(import_layout) # Add screens # sm = ScreenManager(transition=SlideTransition()) sm = ScreenManager(transition=FadeTransition()) sm.add_widget(start_screen) sm.add_widget(card_screen) sm.add_widget(settings_screen) sm.add_widget(no_more_screen) sm.add_widget(import_screen) self.on_load(1) return sm