class HotPlaceWidget(Widget): is_screen = BooleanProperty(True) def __init__(self): super().__init__() self.origin_size = (1, 1) self.widget_layout = FloatLayout() #줌을 12에서 붐비는정도라는 의도에 걸맞게 zoom을 높여주기 -> ux 개선사항 self.map_view = MapView(zoom=14, lat=37.5606, lon=126.9790) # gps에서 현재위치 받아서 띄우기 self.cur_lat, self.cur_lon = 37.5606, 126.9790 self.marker_layer = MarkerMapLayer() self.map_view.add_layer(self.marker_layer) self.items_bind() def items_bind(self): self.widget_layout.clear_widgets() sql_connection = sqlite3.connect('Records/records.db') cursor = sql_connection.cursor() cursor.execute('select lat,lon,count from popularity') for (lat, lon, count) in cursor.fetchall(): if count < 3: self.map_view.add_marker(MapMarker( lat=lat, lon=lon, source='images/heart_yellow.png'), layer=self.marker_layer) elif 3 <= count < 7: self.map_view.add_marker(MapMarker( lat=lat, lon=lon, source='images/heart_green.png'), layer=self.marker_layer) else: self.map_view.add_marker(MapMarker( lat=lat, lon=lon, source='images/heart_red.png'), layer=self.marker_layer) sql_connection.close() self.widget_layout.add_widget(self.map_view) self.bind(is_screen=self.on_is_screen) def on_is_screen(self, instance, value): if value: self.items_bind() else: self.widget_layout.clear_widgets() def set_screen(self, value): self.is_screen = value
class total_item_class(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout2.add_widget(a) except: pass obj = itemslist() self.item = obj.get() string = 'Total number of records are : %s' % (len(self.item)) label1 = Label(text=string, font_size=35,color=[255,255, 255, 1], size_hint=(.20, .10), pos_hint={'x': .40, 'y': .70}) self.main_layout2.add_widget(label1) button1 = Button( text='Ok',background_color = (0, 255, 0, 0.7), size_hint=(.20,.08), pos_hint={'x': .45, 'y': .30} ) button1.bind(on_press=self.ok) self.main_layout2.add_widget(button1) return self.main_layout2 def ok(self, instance): self.main_layout2.clear_widgets() f = MainApp() f.run()
class MainApp(App): #create the application screens def build(self): data_dir = getattr( self, 'user_data_dir') #get a writable path to save our score self.store = JsonStore(join( data_dir, 'score.json')) # create a JsonScore file in the available location if (not self.store.exists('score') ): # if there is no file, we need to save the best score as 1 self.store.put('score', best=1) if platform( ) == 'android': # if we are on Android, we can initialize the ADs service revmob.start_session('54c247f420e1fb71091ad44a') self.screens = {} # list of app screens self.screens['menu'] = MenuScreen( self ) #self the MainApp instance, so others objects can change the screen self.screens['game'] = GameScreen(self) self.root = FloatLayout() self.open_screen('menu') self.sound = SoundLoader.load( 'res/background.mp3') # open the background music # kivy support music loop, but it was not working on Android. I coded in a different way to fix it # but if fixed, we can just set the loop to True and call the play(), so it'll auto repeat # self.sound.loop = True It # was not working on android, so I wrote the following code: self.sound.play() # play the sound Clock.schedule_interval(self.check_sound, 1) #every second force the music to be playing return self.root # play the sound def check_sound(self, dt=None): self.sound.play() # when the app is minimized on Android def on_pause(self): self.sound.stop() # the stop the sound Clock.unschedule(self.check_sound) if platform() == 'android': #if on android, we load an ADs and show it revmob.show_popup() return True # when the app is resumed def on_resume(self): self.sound.play() # we start the music again Clock.schedule_interval(self.check_sound, 1) # show a new screen. def open_screen(self, name): self.root.clear_widgets() #remove the current screen self.root.add_widget(self.screens[name]) # add a new one self.screens[name].run() # call the run method from the desired screen
class donepopupclass(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout2.add_widget(a) except: pass label1 = Label(text='Done',font_size=60,color=[255,255, 255, 1], size_hint=(.20, .10), pos_hint={'x': .40, 'y': .70}) self.main_layout2.add_widget(label1) button1 = Button( text='Ok',background_color = (0, 255, 0, 0.7), size_hint=(.20, .08), pos_hint={'x': .35, 'y': .30} ) button1.bind(on_press=self.ok) self.main_layout2.add_widget(button1) return self.main_layout2 def ok(self, instance): self.main_layout2.clear_widgets() f = additem1() f.run()
class ScatterLayout(Scatter): '''RelativeLayout class, see module documentation for more information. ''' content = ObjectProperty() def __init__(self, **kw): self.content = FloatLayout() super(ScatterLayout, self).__init__(**kw) if self.content.size != self.size: self.content.size = self.size super(ScatterLayout, self).add_widget(self.content) self.bind(size=self.update_size) def update_size(self, instance, size): self.content.size = size def add_widget(self, *l): self.content.add_widget(*l) def remove_widget(self, *l): self.content.remove_widget(*l) def clear_widgets(self): self.content.clear_widgets()
def show_load_popup(self, *args): if os.path.exists(os.path.abspath('saves/')): file_chooser = FileChooserIconView(path="saves") elif os.path.exists(os.path.abspath('../saves')): file_chooser = FileChooserIconView(path="../saves") else: file_chooser = FileChooserIconView(path=".") load_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Load', size_hint=(.08, .05)) back_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Back', size_hint=(.08, .05), pos_hint={'center_x': .95, 'bottom_y': .05}) content = FloatLayout() content.clear_widgets() content.add_widget(file_chooser) content.add_widget(load_btn) content.add_widget(back_btn) popup = Popup(title="Load a file", content=content) load_callback = lambda load: self.load( file_chooser.path, file_chooser.selection, popup) load_btn.bind(on_release=load_callback) back_btn.bind(on_release=popup.dismiss) popup.open()
class ScatterLayout(Scatter): '''ScatterLayout class, see module documentation for more information. ''' content = ObjectProperty() def __init__(self, **kw): self.content = FloatLayout() super(ScatterLayout, self).__init__(**kw) if self.content.size != self.size: self.content.size = self.size super(ScatterLayout, self).add_widget(self.content) self.bind(size=self.update_size) def update_size(self, instance, size): self.content.size = size def add_widget(self, *l): self.content.add_widget(*l) def remove_widget(self, *l): self.content.remove_widget(*l) def clear_widgets(self): self.content.clear_widgets()
class total_item_class(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) obj = itemslist() self.item = obj.get() string = 'Total number of records are :\n-------------> %s' % (len( self.item)) label1 = Label(text=string, font_size=55, size_hint=(.20, .10), pos_hint={ 'x': .40, 'y': .70 }) self.main_layout2.add_widget(label1) button1 = Button(text='Ok', size_hint=(.15, .10), pos_hint={ 'x': .45, 'y': .30 }) button1.bind(on_press=self.ok) self.main_layout2.add_widget(button1) return self.main_layout2 def ok(self, instance): self.main_layout2.clear_widgets() f = MainFile.MainApp() f.run()
class Workflow: def __init__(self): self.root = FloatLayout() self.states = {} # XXX: stack is unused, as only one call_state is pending at a time self.stack = [] def add_state(self, step, name): self.states[name] = step def set_handler(self, handler): self.handler = handler def call_state(self, name, parameters=None): assert(len(self.stack) == 0) self.stack.append([name, parameters]) def return_state(self, parameters): self.handler(self, self.current_state, parameters) self.next_step() def start(self): assert(len(self.stack) > 0) self.next_step() return self.root def next_step(self): assert(len(self.stack) > 0) name, parameters = self.stack.pop() self.current_state = name step = self.states[name] widget = step.called_with(self, parameters) self.root.clear_widgets() self.root.add_widget(widget)
class KalServerApp(App): def build(self): print '# Create Controler' self.controler = KalControler.instance() self.controler.app = self print '# Start Kaleidoscope server at', (config.server_ip, config.server_port) self.server = KalServer(config.server_ip, config.server_port) Clock.schedule_interval(self.update_loop, 0) self.root = FloatLayout() self.screen_wait = KalServerScreenWait() self.root.add_widget(self.screen_wait) return self.root def update_loop(self, *l): asyncore.loop(timeout=0, count=10) KalControler.instance().tick_state_machine() def show(self, widget=None): self.root.clear_widgets() if widget: self.root.add_widget(widget) else: self.root.add_widget(self.screen_wait)
class donepopupclass(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) label1 = Label(text='Done', font_size='55', size_hint=(.20, .10), pos_hint={ 'x': .40, 'y': .70 }) self.main_layout2.add_widget(label1) button1 = Button(text='Ok', size_hint=(.35, .10), pos_hint={ 'x': .35, 'y': .30 }) button1.bind(on_press=self.ok) self.main_layout2.add_widget(button1) return self.main_layout2 def ok(self, instance): cam.CameraExample.pictaken = False cam.CameraExample.imagedata = "" self.main_layout2.clear_widgets() f = additem.additem1() f.run()
def show_load_popup(self, *args): if os.path.exists(os.path.abspath('saves/')): file_chooser = FileChooserIconView(path="saves") elif os.path.exists(os.path.abspath('../saves')): file_chooser = FileChooserIconView(path="../saves") else: file_chooser = FileChooserIconView(path=".") load_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Load', size_hint=(.08, .05)) back_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Back', size_hint=(.08, .05), pos_hint={ 'center_x': .95, 'bottom_y': .05 }) content = FloatLayout() content.clear_widgets() content.add_widget(file_chooser) content.add_widget(load_btn) content.add_widget(back_btn) popup = Popup(title="Load a file", content=content) load_callback = lambda load: self.load(file_chooser.path, file_chooser. selection, popup) load_btn.bind(on_release=load_callback) back_btn.bind(on_release=popup.dismiss) popup.open()
class Workflow: def __init__(self): self.root = FloatLayout() self.states = {} def add_state(self, step, name): self.states[name] = step def set_handler(self, handler): self.handler = handler def return_state(self, parameters): name, parameters = self.handler.send(parameters) self.next_step(name, parameters) def start(self): name, parameters = self.handler.send(None) self.next_step(name, parameters) return self.root def next_step(self, name, parameters): step = self.states[name] widget = step.called_with(self, parameters) self.root.clear_widgets() self.root.add_widget(widget)
class search_item_class(App): data = '' def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout2.add_widget(a) except: pass label1 = Label(text='item name',color=[255,255, 255, 1], size_hint=(.20, .10), pos_hint={'x': .2, 'y': .70}) self.main_layout2.add_widget(label1) self.textbox1 = TextInput( multiline=False, readonly=False, font_size=40, size_hint = (.35, .1), pos_hint={'x': .50, 'y': .70} ) self.main_layout2.add_widget(self.textbox1) button1 = Button( text='search',background_color = (0, 255, 0, 0.7), size_hint=(.20,.08), pos_hint={'x': .30, 'y': .30} ) button1.bind(on_press=self.search) self.main_layout2.add_widget(button1) button2 = Button( text='Back',background_color = (0, 255, 0, 0.7), size_hint=(.20,.08), pos_hint={'x': .55, 'y': .30} ) button2.bind(on_press=self.back) #self.objret = textbox(self.textbox1.text,self.textbox2.text) self.main_layout2.add_widget(button2) return self.main_layout2 def back(self,instance): self.main_layout2.clear_widgets() f=MainApp() f.run() def search(self, instance): search_item_class.data = self.textbox1.text self.main_layout2.clear_widgets() f=search_item_class1() f.run()
class MyApp(App): def cbf_test1(self, *args): self.screen.remove_widget(self.grid) self.current_sheet = Sheet(self.finished) self.screen.add_widget(self.current_sheet) def cbf_test2(self, *args): print "test 2" def cbf_test3(self, *args): print "test 3" def cbf_test4(self, *args): print "test 4" def build(self): self.screen = FloatLayout() self.grid = GridLayout(cols=2, spacing=24, padding=24) for s in [ "Cirkel, vierkant, hode en lage tonen", "Cirkel en vierkant.", "Vierkant", "Knoppenkast" ]: but = Button(text=s, font_size='24dp', size_hint=(0.4, 0.4), padding=(24, 24)) but.bind(on_press=self.cbf_test1) self.grid.add_widget(but) self.screen.add_widget(self.grid) return self.screen def finished(self, *args): print "from app finished" self.screen.clear_widgets() self.screen.add_widget(self.grid) events = self.current_sheet.eventbag.get_events() total = len(events) total_user_events = 0 total_fake_events = 0 total_user_events_hit = 0 total_fake_user_events_hit = 0 for e in events: if e.user_event: total_user_events += 1 if e.hit_user_event: total_user_events_hit += 1 if e.fake_user_event: total_fake_events += 1 if e.hit_fake_user_event: total_fake_user_events_hit += 1 print "Totaal user events", total_user_events, "waarvan", total_user_events_hit, "geraakt zijn" print "Totaal user events", total_fake_events, "waarvan", total_fake_user_events_hit, "geraakt zijn"
class Main(App): def __init__(self, **kwargs): super(Main, self).__init__(**kwargs) self.box = FloatLayout() def build(self): Story(self.box, experiment_setup.story_setup, self.restart_app) return self.box def restart_app(self): self.box.clear_widgets() self.build()
class search_item_class(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) self.item = search_item.search_item_class().data obj = words_filter(self.item) self.item = obj.output() obj2 = record_availability_checker(self.item) self.value = obj2.get() ############################################### in case of camera ####################################### '''img1 = obj2.get1() img2 = obj2.get2() img=img1+img2 ####################convert txt to img################ print(len(img)) fh = open("/root/try.jpg", "wb") fh.write(base64.standard_b64decode(img)) fh.close() ######################################## string = ' %s is at %s\n--------------------Check here---------------------' % (self.item,self.value) label1 = Label(text=string,font_size=40, size_hint=(.20, .10), pos_hint={'x': .40, 'y': .75}) self.main_layout2.add_widget(label1) img = Image(source='/root/try.jpg',size_hint=(.70, .70),pos_hint={'x': .20, 'y': .14}) self.main_layout2.add_widget(img)''' string = ' %s is at %s' % (self.item.strip(), self.value.strip()) label1 = Label(text=string, font_size=40, size_hint=(.20, .10), pos_hint={ 'x': .40, 'y': .75 }) self.main_layout2.add_widget(label1) button1 = Button(text='Ok', size_hint=(.15, .10), pos_hint={ 'x': .45, 'y': .10 }) button1.bind(on_press=self.ok) self.main_layout2.add_widget(button1) return self.main_layout2 def ok(self, instance): self.main_layout2.clear_widgets() f = search_item.search_item_class() f.run()
class Safhe3(Screen): def __init__(self , joyText,app,**kwargs): super(Safhe3, self).__init__(**kwargs) self.app = app self.joyText = joyText self.layout = FloatLayout(size=(3000, 3000)) with self.canvas: Rectangle(source = 'joystick.png', size = (Window.width,Window.height)) self.add_widget(self.layout) self.update() def update(self): self.layout.clear_widgets() self.nextpage = Button(text = "Previous page",size_hint= (None,None),size = (100,50),on_press = self.next ) self.layout.add_widget(self.nextpage) self.joyText2 = self.joyText.split("\n") self.joyText = self.joyText2[0] a = open("joystick/" + self.joyText.replace("\r",""),"r") self.p = a.readlines() print "man p hastam ",self.p Window.clearcolor = (0.3,0.6,0.7,0) print "salam baba golam" for looper in range (len(self.p)): q = self.p[looper].split(" ") print q,"hi" for x,y,x1,y1,t in [q]: print x,y,x1,y1 x = int(float(x)) y = int(float(y)) x1 = int(float(x1)) y1 = int(float(y1)) t = t.split("\n") t = t[0] thebuttons = Button(background_color =(0.3,0.9,1,0.9),size_hint= (None,None),size = (abs(x1 - x), abs(y1 - y)) ,pos=(x,y), border=(1,1,1,1), text = t , on_press=self.press , on_release = self.release ) print x1-x, y1-y self.layout.add_widget(thebuttons) a.close() def on_enter(self, *args): self.update() def next(self, btn): sm.current = "page3" def press(self,btn): self.app.connection.write(btn.text.replace("\n","").replace("\r","") + "$") def release(self, btn): self.app.connection.write(btn.text.replace("\n","").replace("\r","")+"#UP" + "$")
class PulseCalculatorApp(App): def build(self): self.screens = {} self.screens["menu"] = MainMenu(app=self) self.screens["bandwidth"] = BandwidthConversionScreen(app=self) self.screens["power"] = PowerConversionScreen(app=self) self.screens["nls"] = NLSScreen(app=self) self.root = FloatLayout() self.goto_screen("menu") def goto_screen(self, screen_name): self.root.clear_widgets() self.root.add_widget(self.screens[screen_name])
class MainApp(App): #create the application screens def build(self): data_dir = getattr(self, 'user_data_dir') #get a writable path to save our score self.store = JsonStore(join(data_dir, 'score.json')) # create a JsonScore file in the available location if(not self.store.exists('score')): # if there is no file, we need to save the best score as 1 self.store.put('score', best=1) if platform() == 'android': # if we are on Android, we can initialize the ADs service revmob.start_session('54c247f420e1fb71091ad44a') self.screens = {} # list of app screens self.screens['menu'] = MenuScreen(self) #self the MainApp instance, so others objects can change the screen self.screens['game'] = GameScreen(self) self.root = FloatLayout() self.open_screen('menu') self.sound = SoundLoader.load('res/background.mp3') # open the background music # kivy support music loop, but it was not working on Android. I coded in a different way to fix it # but if fixed, we can just set the loop to True and call the play(), so it'll auto repeat # self.sound.loop = True It # was not working on android, so I wrote the following code: self.sound.play() # play the sound Clock.schedule_interval(self.check_sound, 1) #every second force the music to be playing return self.root # play the sound def check_sound(self, dt = None): self.sound.play() # when the app is minimized on Android def on_pause(self): self.sound.stop() # the stop the sound Clock.unschedule(self.check_sound) if platform() == 'android': #if on android, we load an ADs and show it revmob.show_popup() return True # when the app is resumed def on_resume(self): self.sound.play() # we start the music again Clock.schedule_interval(self.check_sound, 1) # show a new screen. def open_screen(self, name): self.root.clear_widgets() #remove the current screen self.root.add_widget(self.screens[name]) # add a new one self.screens[name].run() # call the run method from the desired screen
class DrumPoserApp(App): def build(self): self.screens = {} self.screens["editor"] = EditorScreen(app=self) self.screens["teachme"] = TeachMeScreen(app=self) self.screens["menu"] = MainMenu(app=self) self.root = FloatLayout() self.goto_screen("menu") return self.root def goto_screen(self, screen_name): self.root.clear_widgets() self.root.add_widget(self.screens[screen_name]) if screen_name == 'editor': self.screens["editor"].init_editor()
class mypopup(App): def build(self): self.main_layout = FloatLayout(size=(50, 50)) label = Label(text='item is already present at', size_hint=(.15, .1), pos_hint={ 'x': .2, 'y': .70 }) self.main_layout.add_widget(label) button1 = Button(text='continue', pos=(20, 700), size_hint=(.15, .1), pos_hint={ 'x': .2, 'y': .30 }) button1.bind(on_press=self.on_button_press1) self.main_layout.add_widget(button1) button2 = Button(text='cancel', pos=(20, 700), size_hint=(.15, .1), pos_hint={ 'x': .50, 'y': .30 }) button2.bind(on_press=self.on_button_press2) self.main_layout.add_widget(button2) return self.main_layout def on_button_press1(self, instance): x = additem.additem1.textbox1 print('yash', x) y = additem.additem1.textbox2 print('tash', y) obj = recordoverride(x, y) print('done') self.main_layout.clear_widgets() f = additem.additem1() f.run() def on_button_press2(self, instance): self.main_layout.clear_widgets() f = additem.additem1() f.run()
class mypopup(App): def build(self): self.main_layout = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout.add_widget(a) except: pass ob = record_availability_checker(additem1.textbox1.strip()) label = Label(text=' %s is already present at %s' %(additem1.textbox1.strip(),ob.get()),color=[255,255, 255, 1],size_hint=(.15, .1), pos_hint={'x': .2, 'y': .70}) self.main_layout.add_widget(label) button1 = Button( text='continue',background_color = (0, 255, 0, 0.7), pos=(20, 700), size_hint=(.20,.08), pos_hint={'x': .2, 'y': .30} ) button1.bind(on_press=self.on_button_press1) self.main_layout.add_widget(button1) button2 = Button( text='cancel',background_color = (0, 255, 0, 0.7), pos=(20, 700), size_hint=(.20,.08), pos_hint={'x': .50, 'y': .30} ) button2.bind(on_press=self.on_button_press2) self.main_layout.add_widget(button2) return self.main_layout def on_button_press1(self, instance): x=additem1.textbox1 y=additem1.textbox2 obj = recordoverride(x,y) self.main_layout.clear_widgets() f = additem1() f.run() def on_button_press2(self, instance): self.main_layout.clear_widgets() f = additem1() f.run()
class spin(App): textbox1 = "" textbox2 = "" def build(self): obj = itemslist() self.items=obj.get() try: self.items.remove(None) except: pass print(obj.get()) self.main_layout2 = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout2.add_widget(a) except: pass self.spinner = Spinner( text='Click here',background_color = (0, 255, 0, 0.7), values=self.items, size_hint=(.20, .08), pos_hint={'x': .25, 'y': .80}) self.main_layout2.add_widget(self.spinner) button1 = Button( text='Back',background_color = (0, 255, 0, 0.7), size_hint=(.20,.08), pos_hint={'x': .55, 'y': .80} ) button1.bind(on_press=self.back) self.main_layout2.add_widget(button1) return self.main_layout2 def back(self, instance): self.main_layout2.clear_widgets() #time.sleep(.5) #pyautogui.click(50,50) f = MainApp() f.run()
class MainApp(App): def build(self): print("Main App") self.screens = {} # list of app screens self.screens['menu'] = MainMenu( self ) # self the MainApp instance, so others objects can change the screen self.screens['configure'] = Configuration_Window(self) self.root = FloatLayout() self.open_screen( 'menu') # Burası menu olmalı ama test için online yapıldı return self.root def open_screen(self, name): self.root.clear_widgets() self.root.add_widget(self.screens[name])
class MainApp(App): def build(self): self.screens = {} # list of app screens self.screens['menu'] = MainMenu( self ) # self the MainApp instance, so others objects can change the screen self.screens['configure'] = Configuration_Window(self) self.screens['password'] = Password_Window(self) self.root = FloatLayout() self.open_screen('menu') return self.root def open_screen(self, name): self.root.clear_widgets() self.root.add_widget(self.screens[name])
class MainApp(App): def build(self): self.request = "" self.url = "" self.response_text = "" self.screens = {} self.screens['menu'] = MenuScreen(self) self.root = FloatLayout() self.open_screen('menu') return self.root def open_screen(self,name): self.root.clear_widgets() self.root.add_widget(self.screens[name]) self.screens[name].run()
def show_save_popup(self, save_unit, *args): if os.path.exists(os.path.abspath('saves/')): file_chooser = FileChooserIconView(path="saves") elif os.path.exists(os.path.abspath('../saves')): file_chooser = FileChooserIconView(path="../saves") else: file_chooser = FileChooserIconView(path=".") text_input = TextInput(size_hint=(.20, .05), pos_hint={ 'center_x': .5, 'bottom_y': .05 }, multiline=False) save_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Save', size_hint=(.08, .05)) back_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Back', size_hint=(.08, .05), pos_hint={ 'center_x': .95, 'bottom_y': .05 }) content = FloatLayout() content.clear_widgets() content.add_widget(file_chooser) content.add_widget(save_btn) content.add_widget(text_input) content.add_widget(back_btn) popup = Popup(title="Save a file", content=content) serialize_callback = lambda save: self.save( file_chooser.path, text_input.text, save_unit, popup) text_input.bind(on_text_validate=serialize_callback) save_btn.bind(on_release=serialize_callback) back_btn.bind(on_release=popup.dismiss) popup.open()
class Game_layout(Widget): def __init__(self, **kwargs): super(Game_layout, self).__init__(**kwargs) self.finished = False self.levelBuilder = levelBuilder() self.nodeList = [] self.laserList = [] self.wallList = [] self.gameLayout = FloatLayout(size_hint=(None, None)) self.add_widget(self.gameLayout) def get_lists(self): return [self.nodeList, self.wallList, self.laserList] def set_lists(self, nodelist, walllist, laserlist): self.nodeList = nodelist self.laserList = laserlist self.wallList = walllist self.gameLayout.clear_widgets() self.loadLevel() def select_levels(self, parent): self.popup.dismiss() def select_main(self, parent): self.popup.dismiss() def levelHelper(self, parent): self.level = parent.text[parent.text.find("/"):parent.text.find(".")] self.loadLevel() def loadMenu(self, *arg): self.popup.open() def loadLevel(self): self.gameLayout.clear_widgets() for x in range(len(self.nodeList)): self.gameLayout.add_widget(self.nodeList[x]) for x in range(len(self.laserList)): self.gameLayout.add_widget(self.laserList[x]) for x in range(len(self.wallList)): self.gameLayout.add_widget(self.wallList[x])
class spin(App): textbox1 = "" textbox2 = "" def build(self): obj = itemslist() self.items=obj.get() try: self.items.remove(None) except: pass print(obj.get()) self.main_layout2 = FloatLayout(size=(50, 50)) self.spinner = Spinner( text='Click here', values=self.items, size_hint=(.15, .10), pos_hint={'x': .25, 'y': .30}) self.main_layout2.add_widget(self.spinner) button1 = Button( text='Back', size_hint=(.15, .10), pos_hint={'x': .55, 'y': .30} ) button1.bind(on_press=self.back) self.main_layout2.add_widget(button1) return self.main_layout2 def back(self, instance): self.main_layout2.clear_widgets() time.sleep(.5) pyautogui.click(50,50) f = MainFile.MainApp() f.run()
class GamesScreen(BasicScreen): def __init__(self, background_img, title, **kwargs): super(GamesScreen, self).__init__(name='GamesScreen', background_img=background_img, **kwargs) self.set_screen_info(game_title=title) def set_screen_info(self, game_title): self.main_layout = FloatLayout(id='GamesScreen', size_hint=(1, 1)) self.main_title = Label(id='GameTitle', text=str(game_title), font_size=30, pos_hint={'y': 0.9}, size_hint=(1, 0.1)) self.photo = Image(size_hint=(0.3, 0.3), pos_hint={'x': 0.1, 'y': 0.6}, source='logo.png') self.back_button = Button(id='BackButton', text='Back', font_size=15, size_hint=(0.1, 0.1), on_press=lambda a: App.get_running_app().root.switch_screen('ListGamesScreen')) self.main_layout.add_widget(self.main_title) self.main_layout.add_widget(self.photo) self.main_layout.add_widget(self.back_button) self.add_widget(self.main_layout) def refresh_screen(self, **kwargs): self.main_layout.clear_widgets() self.set_screen_info(**kwargs)
class CrappyBirdApp(App): def build(self): EventLoop.ensure_window() self.window = EventLoop.window self.root = FloatLayout() self.screens = {} self.screens['menu'] = MenuScreen(self) self.open_screen('menu') def open_screen(self,name): self.root.clear_widgets() self.root.add_widget(self.screens[name]) self.screens[name].run() def start(self): self.game = CrappyBirdGame(self) self.root.clear_widgets() self.root.add_widget(self.game) self.game.serve_bird() Clock.schedule_interval(self.game.update, 1.0 / 60.0) def special_start(self): self.special_game = SpecialGame(self) self.root.clear_widgets() self.root.add_widget(self.special_game) self.special_game.serve() Clock.schedule_interval(self.special_game.update, 1.0 / 60.0)
class search_item_class1(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout2.add_widget(a) except: pass self.item = search_item_class().data obj = words_filter(self.item) self.item = obj.output() obj2 = record_availability_checker(self.item) self.value = str(obj2.get()) string = '%s is at %s' % (self.item,self.value) label1 = Label(text=string,font_size=40,color=[255,255, 255, 1], size_hint=(.20, .10), pos_hint={'x': .40, 'y': .75}) self.main_layout2.add_widget(label1) button1 = Button( text='Ok',background_color = (0, 255, 0, 0.7), size_hint=(.20,.08), pos_hint={'x': .45, 'y': .10} ) button1.bind(on_press=self.ok) self.main_layout2.add_widget(button1) return self.main_layout2 def ok(self,instance): self.main_layout2.clear_widgets() f=search_item_class() f.run()
class Workflow: def __init__(self): self.root = FloatLayout() self.steps = [] self.step_index = -1 self.data = {} def add_step(self, step): step.register_workflow(self) self.steps.append(step) def widget(self): return self.root def storage(self): return self.data def start(self): assert(len(self.steps) > 0) self.next_step() def next_step(self): assert(self.step_index < len(self.steps)) self.step_index += 1 step = self.steps[self.step_index] step.workflow_init() self.root.clear_widgets() self.root.add_widget(step.widget()) def prev_step(self): assert(self.step_index > 0) self.step_index -= 1 step = self.steps[self.step_index] step.workflow_init() self.root.clear_widgets() self.root.add_widget(step.widget())
class Workflow: def __init__(self): self.root = FloatLayout() self.steps = [] self.data = {} def add_step(self, step): step.register_workflow(self) self.steps.append(step) def widget(self): return self.root def storage(self): return self.data def start(self): self.next_step() def next_step(self): step = self.steps.pop(0) self.root.clear_widgets() self.root.add_widget(step.widget())
def show_save_popup(self, save_unit, *args): if os.path.exists(os.path.abspath('saves/')): file_chooser = FileChooserIconView(path="saves") elif os.path.exists(os.path.abspath('../saves')): file_chooser = FileChooserIconView(path="../saves") else: file_chooser = FileChooserIconView(path=".") text_input = TextInput( size_hint=(.20, .05), pos_hint={'center_x': .5, 'bottom_y': .05}, multiline=False) save_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Save', size_hint=(.08, .05)) back_btn = Button(font_name='src/fonts/Enchanted_Land.otf', font_size=24, text='Back', size_hint=(.08, .05), pos_hint={'center_x': .95, 'bottom_y': .05}) content = FloatLayout() content.clear_widgets() content.add_widget(file_chooser) content.add_widget(save_btn) content.add_widget(text_input) content.add_widget(back_btn) popup = Popup(title="Save a file", content=content) serialize_callback = lambda save: self.save( file_chooser.path, text_input.text, save_unit, popup) text_input.bind(on_text_validate=serialize_callback) save_btn.bind(on_release=serialize_callback) back_btn.bind(on_release=popup.dismiss) popup.open()
class MyApp(App): def build(self): self.parent = FloatLayout() self.Menu(None) return self.parent def Menu(self, buton): self.parent.clear_widgets() try: self.video1.state = "stop" except: pass try: pass self.video2.state = "stop" except: pass self.layout1 = GridLayout(cols=2) self.layout1.spacing = 100 self.layout1.padding = 100 button1 = Button(text='Play video1', font_size=14) button1.bind(on_press=self.on_button_press1) self.layout1.add_widget(button1) #add button button2 = Button(text='Play video2', font_size=14) button2.bind(on_press=self.on_button_press2) self.layout1.add_widget(button2) self.parent.add_widget(self.layout1) return self.parent def on_button_press1(self, buton): self.parent.clear_widgets() self.layout2 = GridLayout(cols=2) menuBack = Button(text='Menu', font_size=14) menuBack.size_hint = (0.1, 0.1) menuBack.bind(on_press=self.Menu) self.layout2.add_widget(menuBack) self.video1 = VideoPlayer(source='softboy.avi', state='play') self.layout2.add_widget(self.video1) self.parent.add_widget(self.layout2) return self.parent def on_button_press2(self, buton): self.parent.clear_widgets() self.layout3 = GridLayout(cols=2) menuBack = Button(text='Menu', font_size=14) menuBack.size_hint = (0.1, 0.1) menuBack.bind(on_press=self.Menu) self.layout3.add_widget(menuBack) self.video2 = VideoPlayer(source='videoplayback.avi', state='play') self.layout3.add_widget(self.video2) self.parent.add_widget(self.layout3) return self.parent
class MyApp(App): def build(self): self.parent= FloatLayout() self.Menu(None) return self.parent def Menu(self, buton): self.parent.clear_widgets() try: self.video1.state="stop" except: pass try: pass self.video2.state="stop" except: pass self.layout1 =GridLayout(cols=2) self.layout1.spacing =100 self.layout1.padding =100 button1 = Button(text='Play video1', font_size=14) button1.bind(on_press=self.on_button_press1) self.layout1.add_widget(button1) #add button button2 = Button(text='Play video2', font_size=14) button2.bind(on_press=self.on_button_press2) self.layout1.add_widget(button2) self.parent.add_widget(self.layout1) return self.parent def on_button_press1(self,buton): self.parent.clear_widgets() self.layout2 =GridLayout(cols=2) menuBack = Button(text='Menu', font_size=14) menuBack.size_hint = (0.1,0.1) menuBack.bind(on_press=self.Menu) self.layout2.add_widget(menuBack) self.video1= VideoPlayer(source='softboy.avi', state='play') self.layout2.add_widget(self.video1) self.parent.add_widget(self.layout2) return self.parent def on_button_press2(self,buton): self.parent.clear_widgets() self.layout3 =GridLayout(cols=2) menuBack = Button(text='Menu', font_size=14) menuBack.size_hint = (0.1,0.1) menuBack.bind(on_press=self.Menu) self.layout3.add_widget(menuBack) self.video2= VideoPlayer(source='videoplayback.avi', state='play') self.layout3.add_widget(self.video2) self.parent.add_widget(self.layout3) return self.parent
class Screen(FloatLayout): def build(self): self.object1 = BoxLayout() return self.object1 def __init__(self, **kwargs): super(Screen, self).__init__(**kwargs) #Fundal image with self.canvas.before: self.fundal_image = Image(source = "E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/fundal.jpg") self.fundal_image.opacity = 0.7 self.add_widget(self.fundal_image) self.rect = Rectangle(size = self.size, pos = self.pos) self.bind(size = self._update_rect, pos = self._update_rect) self.layout = FloatLayout() self.layout.size_hint = (None, None) self.layout.size = (600, 500) self.layout.padding = 20 self.fundal_image.add_widget(self.layout) self.sound = SoundLoader.load("E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/JO_-_09_-_Fortitude.ogg") self.sound.play() self.sound.loop = True self.sound.volume = 0.5 self.Menu(None) def Menu(self, buton): self.layout.clear_widgets() self.button1 = Button(text = 'Carousel', bold = True, background_color =(0, 0, 1, 1)) self.button1.pos = (290, 380) self.button1.size_hint = (0.3, 0.1) self.layout.add_widget(self.button1) self.button2 = Button(text = 'Optiuni', bold = True, background_color =(0, 0, 1, 1)) self.button2.pos = (290, 280) self.button2.size_hint = (0.3, 0.1) self.layout.add_widget(self.button2) self.button3 = Button(text = 'About', bold = True, background_color =(0, 0, 1, 1)) self.button3.pos = (290, 180) self.button3.size_hint = (0.3, 0.1) self.layout.add_widget(self.button3) self.button4 = Button(text = 'Iesi', bold = True, background_color =(0, 0, 1, 1)) self.button4.pos = (290, 80) self.button4.size_hint = (0.3, 0.1) self.layout.add_widget(self.button4) self.button1.bind(on_press = self.Carousel) self.button2.bind(on_press = self.Options) self.button3.bind(on_press = self.About) self.button4.bind(on_press = self.Exit) def Carousel(self, buton): self.layout.clear_widgets() self.carousel = Carousel(direction = 'right') self.carousel.anim_move_duration = 1 self.carousel.loop = True self.carousel.size_hint = (0.7, 0.7) self.carousel.pos = (200, 120) self.layout.add_widget(self.carousel) self.image1 = Image(source = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature1.jpg') self.carousel.add_widget(self.image1) self.image2 = Image(source= 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature2.jpg') self.carousel.add_widget(self.image2) self.image3 = Image(source = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature3.jpg') self.carousel.add_widget(self.image3) self.image4 = Image(source = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature4.jpg') self.carousel.add_widget(self.image4) self.label = Label(text = 'This is the end of the list!', font_size = 30) self.carousel.add_widget(self.label) self.backbutton = Button(text = 'Back', bold = True, background_color = (0, 0, 1, 1)) self.backbutton.pos = (200, 100) self.backbutton.size_hint = (0.7, 0.1) self.layout.add_widget(self.backbutton) self.backbutton.bind(on_press = self.Menu) def Options(self, buton): self.layout.clear_widgets() self.switch = Switch(text = 'Music') self.switch.active = True self.switch.size_hint = (0.3, 0.2) self.switch.pos = (300, 360) self.layout.add_widget(self.switch) self.show_volume = Label(text = 'Volume = 50') self.layout.add_widget(self.show_volume) self.music_slide = Slider(min = 0, max = 100, value = 50) self.music_slide.step = 5 self.music_slide.size_hint = (0.3, 0.1) self.music_slide.pos = (300, 180) self.music_slide.orientation = 'horizontal' self.layout.add_widget(self.music_slide) self.button = Button(text = 'Back', bold = True, background_color = (0, 0, 1, 1)) self.button.pos = (300, 120) self.button.size_hint = (0.3, 0.1) self.button.opacity = 0.7 self.layout.add_widget(self.button) self.switch.bind(active = self.mute) self.music_slide.bind(value = self.volume_value) self.button.bind(on_press = self.Menu) def volume_value(self,x,y): self.show_volume.text = 'Volume ' + str(int(self.music_slide.value)) self.sound.volume = self.music_slide.value / 100 def mute(self,x,y): if (self.switch.active == False): self.music_slide.disabled = True self.sound.stop() else: self.music_slide.disabled = False self.music_slide.value = 0 self.sound.play() def About(self, buton): self.layout.clear_widgets() self.backbutton = Button(text = 'Back', background_color = (0, 0, 1, 1)) self.backbutton.size_hint = (1, 0.1) self.label = Label(text = 'Thanks InfoAcademy!', bold = True, font_size = 24) self.blayout = BoxLayout() self.blayout.orientation = 'vertical' self.blayout.padding = 40 self.blayout.add_widget(self.backbutton) self.blayout.add_widget(self.label) self.backbutton.bind(on_press = self.Menu) self.popup = Popup(background = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/fundal4_tema.jpg') self.popup.size_hint =(None, None) self.popup.size = (400, 400) self.popup.title = 'Who made this aplication?' self.popup.content = self.blayout self.popup.open() self.popup.bind(on_press = self.close_popup) self.backbutton.bind(on_press = self.close_popup) def close_popup(self, buton): self.popup.dismiss() def Exit(self, buton): sys.exit() def _update_rect(self, instance, value): self.rect.pos = instance.pos self.rect.size = instance.size
class CreateGroup(Popup): ## # Class Constructor: __init__ # --------------------------- # This method is called during creation of the CreateGroup class. # This function creates the layout for the popup as well as initializes all the # popup attributes. # # @params # (CreateGroup) self This instance of CreateGroup # (Various) **kwargs Arguments for constuction of internal Popup object ## def __init__(self, **kwargs): self.layout = FloatLayout(size=(Window.width, 200)) super(CreateGroup, self).__init__(title='Add Group', content=self.layout, size_hint=(None,None), size=(400,200), background=BKGD_DCHRC, pos_hint={"center_x":.5, 'top':.7}, auto_dismiss=False, **kwargs) ## # Class Method: draw_layout # ------------------------- # This method creates the entire layout for the create group popup by calling functions to create # the group name text box, create the users dropdown, and the add or cancel buttons # # @params # (CreateGroup) self This instance of CreateGroup ## def draw_layout(self): self.dropdown = DropDown(auto_width=False, width=180, max_height=180, on_dismiss=self.display_num_down) self.dropdown.main_button = HoverButton(text="Select Users", size=(180,30), size_hint=(None,None), pos_hint={"center_x":.5, 'top':.65}, button_down=DD_DCHRC[1], button_up=DD_DCHRC[0], on_release=self.display_label) self.group_name = TextInput(size_hint=(None, None), size=(250, 30), pos_hint={'center_x':.5, 'top':.91}, hint_text='Group Name', multiline=False) self.layout.add_widget(self.group_name) self.layout.add_widget(self.dropdown.main_button) self.add_group_dropdown() self.layout.add_widget(HoverButton(text="Add", button_down=BTN_DCHRC[1], button_up=BTN_DCHRC[0], font_size=14, size_hint=(None,None), size=(100,40), pos_hint={"center_x":.7, 'top':.35}, on_press=self.add_group)) self.layout.add_widget(HoverButton(text="Cancel", button_down=BTN_DCHRC[1], button_up=BTN_DCHRC[0], font_size=14, size_hint=(None,None), size=(100,40), pos_hint={"center_x":.3, 'top':.35}, on_press=self.dismiss)) ## # Class Method: open_popup # ------------------------ # This method is called to clear the widgets of the current popup layout and redraw the # layout according to the current situation. # # @params # (CreateGroup) self This instance of CreateGroup ## def open_popup(self): self.layout.clear_widgets() self.draw_layout() self.open() ## # Class Method: display_num_down # ------------------------------ # This method displays the number of users selected in the dropdown on the mainbutton # and creates all of the ToggleButtons for all of the users # # @params # (CreateGroup) self This instance of CreateGroup # (DropDown) instance This is the dropdown that calls this function on_dismiss ## def display_num_down(self, instance): num_down = 0 for user_panel in self.dropdown.container.children: for user in user_panel.children: if type(user) == ToggleButton: if user.state == 'down': num_down += 1 if num_down == 1: self.dropdown.main_button.text = str(num_down) + " User Selected" else: self.dropdown.main_button.text = str(num_down) + " Users Selected" for child in self.layout.children: if type(child) == Label and child.text == 'Priority': self.layout.remove_widget(child) ## # Class Method: display_label # --------------------------- # This method displays the label priority when the popup opens for clarification of the text boxes # in the ToggleButtons # # @params # (CreateGroup) self This instance of CreateGroup # (HoverButton) instance This is the main button for the dropdown ## def display_label(self, instance): self.dropdown.open(self.dropdown.main_button) self.layout.add_widget(Label(text="Priority", size_hint=(None,None), size = (40,20), font_size=9, pos_hint={'center_x':.7, 'top':.56})) ## # Class Method: add_group_dropdown # -------------------------------- # This method adds all of the ToggleButtons to the dropdown # # @params # (CreateGroup) self This instance of CreateGroup ## def add_group_dropdown(self): all_users = database.get_all_users() for user in all_users: user_tog = UserToggle(user) self.dropdown.add_widget(user_tog) ## # Class Method: add_group # ----------------------- # This method adds all of the selected users to a group with the name stored in the group name text input. # If no users are selected or no group name is provided, and error label appears to inform the end user # # @params # (CreateGroup) self This instance of CreateGroup # (HoverButton) instance The button pressed in order to call add_group ## def add_group(self, instance): if self.group_name.text == '': for child in self.layout.children: if type(child) == Label and child.text == "Please Insert a Group Name and Select Group Members": self.content.remove_widget(child) self.content.add_widget(Label(text="Please Insert a Group Name and Select Group Members", size_hint=(None,None), font_size=12, color=(1,0,0,1), pos_hint={'center_x':.5, 'top':1.8})) else: names_selected = False for user_panel in self.dropdown.container.children: for user in user_panel.children: if type(user) == ToggleButton and user.state == 'down': names_selected = True database.add_group_member(user.text, self.group_name.text, user_panel.priority_text.text) if not names_selected: for child in self.layout.children: if type(child) == Label and child.text == "Please Insert a Group Name and Select Group Members": self.content.remove_widget(child) self.content.add_widget(Label(text="Please Insert a Group Name and Select Group Members", size_hint=(None,None), font_size=12, color=(1,0,0,1), pos_hint={'center_x':.5, 'top':1.8})) else: self.dismiss() manager.menu.show_groups()
class MainApp(App): def build(self): ''''Initialisation de l'app (text et bouton)''' self.fenetre = FloatLayout() self.date = 'Aujourd\'hui' self.label_ville_depart = 'Ville de départ' #pour les test : 'Ville de départ !' en temp normal self.ville_depart = None #pour les test : None en temp normal self.arret_depart = None #pour les test : None en temp normal self.status_ville_depart = None #permet de gerer si c'est pour le bouton de depart ou d'arriver self.label_ville_arriver = 'Ville d\'arriver' #pour les test : 'Ville d\'arriver !' en temp normal self.ville_arriver = None #pour les test : None en temp normal self.arret_arriver = None #pour les test : None en temp normal self.init_list_adapter_alphabet() self.init_list_adapter_ville([]) self.init_list_adapter_arret([]) self.titre = Image(source='Images/le_sept.png', size_hint=(.6, .8), pos_hint={'x': 0.2, 'center_y': 0.80}) self.affichage_date = Label(text='[color=682279]'+self.date+'[/color]', markup= True, font_size= 35, pos_hint={'x': 0, 'center_y': 0.55}) self.bouton_changer_date = Button(text='[color=682279]Changer[/color]', font_size= 35, font_name= 'fonts/Soft Elegance.ttf', background_color=(1, 1, 1, 1), markup= True, size_hint=(.2, .07), pos_hint={'x': 0.25, 'center_y': 0.40}) self.bouton_valider_date = Button(text='[color=682279]Valider[/color]', font_size= 35, font_name= 'fonts/Soft Elegance.ttf', background_color=(1, 1, 1, 1), markup= True, size_hint=(.2, .07), pos_hint={'x': 0.55, 'center_y': 0.40}) self.bouton_changer_date.bind(on_press=self.pose_choix_ville_depart) self.bouton_valider_date.bind(on_press=self.pose_choix_ville_depart) self.fenetre.add_widget(self.titre) self.fenetre.add_widget(self.affichage_date) self.fenetre.add_widget(self.bouton_changer_date) self.fenetre.add_widget(self.bouton_valider_date) return self.fenetre def pose_choix_ville_depart(self, adapter): self.fenetre.clear_widgets() self.affichage_date = Label(text='[color=682279]'+self.date+'[/color]', markup= True, font_size= 35, pos_hint={'x': 0, 'center_y': 0.55}) self.init_bouton_label_ville_depart() self.init_bouton_retour(0.1, 0.1) self.bouton_retour.bind(on_press=self.retour_main) self.bouton_label_ville_depart.bind(on_press=self.afficher_alphabet) self.fenetre.add_widget(self.titre) self.fenetre.add_widget(self.bouton_retour) self.fenetre.add_widget(self.affichage_date) self.fenetre.add_widget(self.bouton_label_ville_depart) def pose_choix_ville_arriver(self): self.fenetre.clear_widgets() self.affichage_ville_depart = Label(text='[color=682279]'+self.label_ville_depart+'[/color]', markup= True, font_size= 35, pos_hint={'x': 0, 'center_y': 0.45}) self.init_bouton_label_ville_arriver() self.init_bouton_retour(0.1, 0.1) self.bouton_retour.bind(on_press=self.retour_main) self.bouton_label_ville_arriver.bind(on_press=self.afficher_alphabet) self.fenetre.add_widget(self.titre) self.fenetre.add_widget(self.bouton_retour) self.fenetre.add_widget(self.affichage_date) self.fenetre.add_widget(self.affichage_ville_depart) self.fenetre.add_widget(self.bouton_label_ville_arriver) def pose_recherche(self): self.fenetre.clear_widgets() self.affichage_ville_arriver = Label(text='[color=682279]'+self.label_ville_arriver+'[/color]', markup= True, font_size= 35, pos_hint={'x': 0, 'center_y': 0.35}) self.bouton_recherche = Button(text='[color=682279]Recherche[/color]', font_size=35, font_name= 'fonts/Soft Elegance.ttf', background_color=(1, 1, 1, 1), markup=True, size_hint=(.3, .07), pos_hint={'x': 0.35, 'center_y': 0.1}) self.init_bouton_retour(0.1, 0.1) self.bouton_retour.bind(on_press=self.retour_main) self.bouton_recherche.bind(on_press=self.recherche) self.fenetre.add_widget(self.titre) self.fenetre.add_widget(self.bouton_retour) self.fenetre.add_widget(self.affichage_date) self.fenetre.add_widget(self.bouton_recherche) self.fenetre.add_widget(self.affichage_ville_depart) self.fenetre.add_widget(self.affichage_ville_arriver) def init_list_adapter_alphabet(self): ''''Initialise les données de la liste de l'alphabet''' if self.status_ville_depart == None: self.list_adapter_alphabet = ListAdapter( data=gestion_bd.select_alphabet_ville_depart(), cls=ListItemButton, sorted_keys=[], selection_mode='multiple', ) else: self.list_adapter_alphabet = ListAdapter( data=gestion_bd.select_alphabet_ville_arriver(self.ville_depart), cls=ListItemButton, sorted_keys=[], selection_mode='multiple', ) def init_list_adapter_ville(self, donnee): '''Initialise les données de la liste des villes''' self.list_adapter_ville = ListAdapter( data=donnee, cls=ListItemButton, sorted_keys=[], selection_mode='multiple', ) def init_list_adapter_arret(self, donnee): '''Initialise les données de la liste des arrets''' self.list_adapter_arret = ListAdapter( data=donnee, cls=ListItemButton, sorted_keys=[], selection_mode='multiple', ) def init_bouton_label_ville_depart(self): '''Initialise le bouton ville de depart''' self.bouton_label_ville_depart = Button(text='[color=682279]'+self.label_ville_depart+'[/color]', font_size= 35, font_name= "fonts/Soft Elegance.ttf", background_color=(1, 1, 1, 1), markup= True, size_hint=(0.3,0.07), pos_hint={'x': 0.35, 'center_y': 0.4}) def init_bouton_label_ville_arriver(self): '''Initialise le bouton ville d'arriver''' self.bouton_label_ville_arriver = Button(text='[color=682279]'+self.label_ville_arriver+'[/color]', font_size=35, markup= True, font_name= "fonts/Soft Elegance.ttf", background_color=(1, 1, 1, 1), size_hint=(0.3,0.07), pos_hint={'x': 0.35, 'center_y': 0.25}) def afficher_alphabet(self, value): '''Affiche la liste de l'alphabet''' if self.status_ville_depart == None: self.list_adapter_alphabet.bind(on_selection_change=self.afficher_list_ville) self.list_view_alphabet = ListView(adapter=self.list_adapter_alphabet) self.fenetre.add_widget(self.list_view_alphabet) else: self.init_list_adapter_alphabet() self.list_adapter_alphabet.bind(on_selection_change=self.afficher_list_ville) self.list_view_alphabet = ListView(adapter=self.list_adapter_alphabet) self.fenetre.add_widget(self.list_view_alphabet) def afficher_list_ville(self, adapter): ''' Initialise la liste des villes, supprime la liste de l'alphabet et affiche la liste des villes ''' if self.status_ville_depart == None: for element in adapter.selection: index_element = element.index self.init_list_adapter_ville(gestion_bd.select_villes(str(adapter.data[index_element]))) self.fenetre.remove_widget(self.list_view_alphabet) self.list_adapter_ville.bind(on_selection_change=self.select_ville) self.list_view_ville = ListView(adapter=self.list_adapter_ville) self.fenetre.add_widget(self.list_view_ville) else: for element in adapter.selection: index_element = element.index self.init_list_adapter_ville(gestion_bd.select_seconde_villes(self.ville_depart, adapter.data[index_element])) self.fenetre.remove_widget(self.list_view_alphabet) self.list_adapter_ville.bind(on_selection_change=self.select_ville) self.list_view_ville = ListView(adapter=self.list_adapter_ville) self.fenetre.add_widget(self.list_view_ville) def select_ville(self, adapter): ''' Self.label_ville_depart devient le nom de la ville de départ Initialise la liste des arrets ''' if self.status_ville_depart == None: for element in adapter.selection: index_element = element.index self.label_ville_depart = adapter.data[index_element] self.ville_depart = adapter.data[index_element] self.status_ville_depart = 'ville' self.init_list_adapter_arret(gestion_bd.select_arrets(self.label_ville_depart)) self.select_arret() else: for element in adapter.selection: index_element = element.index self.label_ville_arriver = adapter.data[index_element] self.ville_arriver = adapter.data[index_element] self.init_list_adapter_arret(gestion_bd.select_arrets(self.label_ville_arriver)) self.select_arret() def select_arret(self): '''Supprime la listes des villes, affiche la liste des arrets''' if self.status_ville_depart == 'ville': self.fenetre.remove_widget(self.list_view_ville) self.list_adapter_arret.bind(on_selection_change=self.modif_bouton) self.list_view_arret = ListView(adapter=self.list_adapter_arret) self.fenetre.add_widget(self.list_view_arret) else: self.fenetre.remove_widget(self.list_view_ville) self.list_adapter_arret.bind(on_selection_change=self.modif_bouton) self.list_view_arret = ListView(adapter=self.list_adapter_arret) self.fenetre.add_widget(self.list_view_arret) def modif_bouton(self, adapter): '''Modifie les bouton depart ou arriver''' if self.status_ville_depart == 'ville': for element in adapter.selection: index_element = element.index self.label_ville_depart = "'"+self.label_ville_depart+", "+adapter.data[index_element]+"'" self.status_ville_depart = 'ville+arret' self.arret_depart = adapter.data[index_element] self.pose_choix_ville_arriver() else: for element in adapter.selection: index_element = element.index self.label_ville_arriver = "'"+self.label_ville_arriver+", "+adapter.data[index_element]+"'" self.arret_arriver = adapter.data[index_element] self.init_bouton_label_ville_arriver() self.pose_recherche() def retour_main(self, adapter): self.fenetre.clear_widgets() MainApp().run() def init_bouton_retour(self, pos_x, pos_y): '''Initialise le bouton de réinitialisation de l'app''' self.bouton_retour = Button(text='[color=682279]Retour[/color]', font_size= 35, font_name= "fonts/Soft Elegance.ttf", markup= True, size_hint=(0.2,0.07), pos_hint={'x': pos_x, 'center_y': pos_y}) def recherche(self, value): '''Le select général''' if self.label_ville_depart != 'Ville de départ !' and self.label_ville_arriver != 'Ville d\'arriver !': self.retour = gestion_bd.select_horaire(self.ville_depart, self.arret_depart, self.ville_arriver, self.arret_arriver) if self.retour[0] == False or self.retour == 'ERREUR': self.fenetre.clear_widgets() self.affichage_erreur = Label(text='[color=682279]Il n\'y a aucun bus ce jour ci.[/color]', markup= True, font_size= 35, pos_hint={'x': 0, 'center_y': 0.60}) self.init_bouton_retour(0.42, 0.4) self.bouton_retour.bind(on_press=self.retour_main) self.fenetre.add_widget(self.affichage_erreur) self.fenetre.add_widget(self.bouton_retour) else: self.afficher_resultat() def afficher_resultat(self): '''Vide la fenêtre et affiche les resultats''' self.fenetre.clear_widgets() self.affichage_ville_depart = Label(text='[color=682279]'+self.ville_depart+'[/color]', markup= True, font_size= 25, pos_hint={'x': -0.2, 'center_y': 0.90}) self.affichage_ville_arriver = Label(text='[color=682279]'+self.ville_arriver+'[/color]', markup= True, font_size= 25, pos_hint={'x': 0.2, 'center_y': 0.90}) self.affichage_arret_depart = Label(text='[color=682279]'+self.arret_depart+'[/color]', markup= True, font_size= 25, pos_hint={'x': -0.2, 'center_y': 0.83}) self.affichage_arret_arriver = Label(text='[color=682279]'+self.arret_arriver+'[/color]', markup= True, font_size= 25, pos_hint={'x': 0.2, 'center_y': 0.83}) self.affichage_date = Label(text='[color=682279]'+str(self.date)+'[/color]', markup= True, font_size= 25, pos_hint={'x': -0.38, 'center_y': 0.98}) '''Pour chaque horaire, l'affiche''' for ville in self.retour[1]: i = 1 for bus in self.retour[1][ville]: if ville == self.ville_depart: self.affichage_horaire_depart = Label(text='[color=682279]'+'Départ à '+self.retour[1][ville]['bus'+str(i)][1]+'[/color]', markup= True, font_size= 30, pos_hint={'x': -0.2, 'center_y': 0.70-i/16}) self.fenetre.add_widget(self.affichage_horaire_depart) i += 1 else: self.affichage_horaire_arriver = Label(text='[color=682279]'+'Arrivée à '+self.retour[1][ville]['bus'+str(i)][1]+'[/color]', markup= True, font_size= 30, pos_hint={'x': 0.2, 'center_y': 0.70-i/16}) self.fenetre.add_widget(self.affichage_horaire_arriver) i += 1 self.init_bouton_retour(0.42, 0.1) self.bouton_retour.bind(on_press=self.retour_main) self.fenetre.add_widget(self.bouton_retour) self.fenetre.add_widget(self.affichage_ville_depart) self.fenetre.add_widget(self.affichage_ville_arriver) self.fenetre.add_widget(self.affichage_arret_depart) self.fenetre.add_widget(self.affichage_arret_arriver) self.fenetre.add_widget(self.affichage_date)
class ChangePassword(Popup): ## # Class Constructor: __init__ # --------------------------- # This method is called during creation of the ChangePassword class. # This function creates the layout for the popup as well as initializes all the # popup attributes. # # @params # (ChangePassword) self This instance of ChangePassword # (Various) **kwargs Arguments for constuction of internal Popup object ## def __init__(self, **kwargs): self.layout = FloatLayout(size=(Window.width, 200)) super(ChangePassword, self).__init__(title='Change Password', content=self.layout, size_hint=(None, None), size=(400, 200), background=BKGD_DCHRC, pos_hint={ "center_x": .5, 'top': .7 }, auto_dismiss=False, **kwargs) ## # Class Method: draw_layout # ------------------------- # This method creates the entire layout for the change password popup including # both the password box and the verify password box. The function can also detect # if a user is selected or not and responds accordingly. # # @params # (ChangePassword) self This instance of ChangePassword ## def draw_layout(self): if manager.CURRENT_USER == None: self.layout.add_widget( Label(text="No user currently selected", pos_hint={ "center_x": .5, 'top': 1.25 })) self.layout.add_widget( HoverButton(text="Cancel", button_up=BTN_DCHRC[0], button_down=BTN_DCHRC[1], font_size=14, size_hint=(None, None), size=(100, 40), pos_hint={ "center_x": .5, 'top': .35 }, on_press=self.dismiss)) if manager.CURRENT_USER: self.new_passwd = TextInput(size_hint=(.8, None), size=(0, 30), write_tab=False, pos_hint={ 'center_x': .5, 'top': .878 }, password=True, hint_text='new password', multiline=False) self.verify_new_passwd = TextInput(size_hint=(.8, None), size=(0, 30), write_tab=False, pos_hint={ 'center_x': .5, 'top': .62 }, password=True, hint_text='verify new password', multiline=False) self.layout.add_widget(self.new_passwd) self.layout.add_widget(self.verify_new_passwd) self.layout.add_widget( HoverButton(text="Update", background_normal=BKGD_LCHRC, font_size=14, button_up=BTN_DCHRC[0], button_down=BTN_DCHRC[1], size_hint=(None, None), size=(100, 40), pos_hint={ "center_x": .65, 'top': .35 }, on_press=self.update_password)) self.layout.add_widget( HoverButton(text="Cancel", button_up=BTN_DCHRC[0], button_down=BTN_DCHRC[1], font_size=14, size_hint=(None, None), size=(100, 40), pos_hint={ "center_x": .35, 'top': .35 }, on_press=self.dismiss)) ## # Class Method: open_popup # ------------------------ # This method is called to clear the widgets of the current popup layout and redraw the # layout according to the current situation. # # @params # (ChangePassword) self This instance of ChangePassword ## def open_popup(self): self.layout.clear_widgets() self.draw_layout() self.open() ## # Class Method: update_password # ----------------------------- # This method checks the password and verify password text inputs to see if both passwords match. # In the case that no password is provided or the passwords do not match, the function provides an # error message to let the user know their mistake. In the case that they do match, the function updates # the database with the new password and closes the popup # # @params # (ChangePassword) self This instance of ChangePassword # (HoverButton) instance The button that is used to call the update_password function ## def update_password(self, instance): for child in self.layout.children: if child.text == "Please Insert a New Password" or\ child.text == "Passwords Did Not Match!": self.layout.remove_widget(child) if self.new_passwd.text == '' and self.verify_new_passwd.text == '': self.layout.add_widget( Label(text="Please Insert a New Password", color=(1, 0, 0, 1), font_size=11, pos_hint={ "center_x": .5, "top": 1.95 })) return elif self.new_passwd.text != self.verify_new_passwd.text: self.new_passwd.text = '' self.verify_new_passwd.text = '' self.layout.add_widget( Label(text="Passwords Did Not Match!", color=(1, 0, 0, 1), font_size=11, pos_hint={ "center_x": .5, "top": 1.95 })) return pw = database.Attribute("Crypt-Password", ":=", database.hash_passwd(self.new_passwd.text), 'radcheck') database.modify_user_attr(manager.CURRENT_USER, pw) self.dismiss() manager.menu.display_user_info(manager.CURRENT_USER)
class KYRScreen(Screen): spriteList = ListProperty() locationEvent = DictProperty() # all location-based events for the room, including room changes player = ObjectProperty() playerBoundary = ObjectProperty() isCurrent = BooleanProperty(False) playerLocation = ListProperty((500,70)) bg = StringProperty() fg = StringProperty(None) music = ObjectProperty(None) #startLocations = DictProperty() boundaries = ListProperty() items = ListProperty() def __init__(self, **kwargs): super(KYRScreen, self).__init__(**kwargs) self.field = FloatLayout() def on_isCurrent(self, instance, value): if value: self.turnOn() else: self.turnOff() def turnOn(self): print 'turning on {}'.format(self) self.buildPlayer(self.playerLocation) self.buildBoundaries() self.loadBackground() if self.fg != None: self.loadForeground() self.loadWidgets() def turnOff(self): print 'turning off {}'.format(self) #self.parent.playerLocation = self.playerLocation self.unloadWidgets() def buildBoundaries(self): for boundary in self.boundaries: self.field.add_widget(boundary) print 'building boundary: ', boundary def loadBackground(self): print 'loading bg', self.bg bg = CImage.load(self.bg, keep_data=True).texture with self.field.canvas.before: Rectangle(texture = bg, pos=(0,0), size=(1068,450)) def loadForeground(self): print 'loading fg', self.fg fg = AGSprite(source=self.fg, pos=(0,0), size=(1068,450)) self.field.add_widget(fg) def loadWidgets(self): self.add_widget(self.field) def unloadWidgets(self): ''' removes all widgets to prevent conflicts when re-instantiating screen ''' self.field.clear_widgets() self.remove_widget(self.field) def changePlayerImage(self, direction): # CURRENTLY REDUNDANT if direction == 'up': self.player.source = 'assets/art/Clyde_up.zip' elif direction == 'down': self.player.source = 'assets/art/Clyde_down.zip' elif direction == 'left': self.player.source = 'assets/art/Clyde_left.zip' elif direction == 'right': self.player.source = 'assets/art/Clyde_right.zip' def on_transition_state(self, instance, value): pass def buildPlayer(self, playerLocation): ''' loads player sprite onto screen ''' self.player = AGPlayer(source = 'assets/art/brandon-right.zip', size=(96,192)) #self.player.anim_delay = (-1) self.player.pos = playerLocation self.field.add_widget(self.player) def loadSprites(self): # REDUNDANT # look in sprite list for sprite in specific room, return sprite list for room directory = {'room number': 'sprite list'} sprites = directory['room number'] return sprites def buildSprites(self, sprites): # REDUNDANT for sprite in sprites: self.field.add_widget(sprite) self.spriteList.append(sprite)
class additem1(App): def build(self): self.main_layout2 = FloatLayout(size=(50, 50)) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout2.add_widget(a) except: pass label1 = Label(text='Enter name of the item', size_hint=(.50, .1),color=[255,255, 255, 1], pos_hint={'x': .25, 'y': .80}) self.main_layout2.add_widget(label1) self.textbox1 = TextInput( multiline=False, readonly=False, size_hint=(.50,.05), pos_hint={'x': .25, 'y': .77} ) self.main_layout2.add_widget(self.textbox1) label2 = Label(text='Enter name of the location', size_hint=(.50, .1),color=[255,255, 255, 1], pos_hint={'x': .25, 'y': .65}) self.main_layout2.add_widget(label2) self.textbox2 = TextInput( multiline=False, readonly=False, size_hint=(.50, .05), pos_hint={'x': .25, 'y': .62} ) self.main_layout2.add_widget(self.textbox2) button2 = Button( text='Submit',background_color = (0, 255, 0, 0.7), size_hint=(.20,.08), pos_hint={'x': .40, 'y': .30} ) button2.bind(on_press=self.submit) button3 = Button( text='Back',background_color = (0, 255, 0, 0.7), size_hint=(.20, .08), pos_hint={'x': .40, 'y': .17} ) button3.bind(on_press=self.back) self.main_layout2.add_widget(button3) # self.objret = textbox(self.textbox1.text,self.textbox2.text) self.main_layout2.add_widget(button2) return self.main_layout2 def back(self, instance): self.main_layout2.clear_widgets() f = MainApp() f.run() def submit(self, instance): ob = words_filter(self.textbox1.text) k = ob.output() obj = record_availability_checker(k) temp1 = obj.get() x = self.textbox1.text y = self.textbox2.text ob1 = words_filter(x) x = ob1.output() ob2 = words_filter(y) y = ob2.output() additem1.textbox1 = x additem1.textbox2 = y if temp1 == "": if x != "" and y != "": self.main_layout2.clear_widgets() obj2 = record_add(x, y) f = donepopupclass() f.run() else: self.main_layout2.clear_widgets() f = additem1() f.run() else: self.main_layout2.clear_widgets() f = mypopup() f.run()
class MainApp(App): def build(self): """'Initialisation de l'app (text et bouton)""" self.fenetre = FloatLayout() self.date = self.init_date() self.label_ville_depart = "Ville de départ !" # pour les test : 'Ville de départ !' en temp normal self.ville_depart = None # pour les test : None en temp normal self.arret_depart = None # pour les test : None en temp normal self.status_ville_depart = None # permet de gerer si c'est pour le bouton de depart ou d'arriver self.label_ville_arriver = "Ville d'arriver !" # pour les test : 'Ville d\'arriver !' en temp normal self.ville_arriver = None # pour les test : None en temp normal self.arret_arriver = None # pour les test : None en temp normal self.init_list_adapter_alphabet() self.init_list_adapter_ville([]) self.init_list_adapter_arret([]) self.titre = Image(source="Images/le_sept.png", size_hint=(0.6, 0.8), pos_hint={"x": 0.2, "center_y": 0.80}) self.bouton_date = Button( text="[color=682279]" + self.date + "[/color]", font_size_hint=1, font_name="fonts/Soft Elegance.ttf", markup=True, size_hint=(0.3, 0.05), pos_hint={"x": 0.35, "center_y": 0.6}, ) self.init_bouton_label_ville_depart() self.init_bouton_label_ville_arriver() self.bouton_recherche = Button( text="[color=682279]Recherche[/color]", font_size_hint=1, font_name="fonts/Soft Elegance.ttf", markup=True, size_hint=(0.3, 0.05), pos_hint={"x": 0.35, "center_y": 0.2}, ) self.bouton_label_ville_depart.bind(on_press=self.afficher_alphabet) self.bouton_label_ville_arriver.bind(on_press=self.afficher_alphabet) self.bouton_recherche.bind(on_press=self.recherche) self.fenetre.add_widget(self.titre) self.fenetre.add_widget(self.bouton_date) self.fenetre.add_widget(self.bouton_label_ville_depart) self.fenetre.add_widget(self.bouton_label_ville_arriver) self.fenetre.add_widget(self.bouton_recherche) return self.fenetre def init_date(self): """Initialise la date""" objet_date = datetime.now() if len(str(objet_date.month)) == 1: mois = "0" + str(objet_date.month) else: mois = str(objet_date.month) date = str(objet_date.day) + "/" + mois + "/" + str(objet_date.year) return date def init_list_adapter_alphabet(self): """'Initialise les données de la liste de l'alphabet""" self.list_adapter_alphabet = ListAdapter( data=[ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ], cls=ListItemButton, sorted_keys=[], selection_mode="multiple", ) def init_list_adapter_ville(self, donnee): """Initialise les données de la liste des villes""" self.list_adapter_ville = ListAdapter( data=donnee, cls=ListItemButton, sorted_keys=[], selection_mode="multiple" ) def init_list_adapter_arret(self, donnee): """Initialise les données de la liste des arrets""" self.list_adapter_arret = ListAdapter( data=donnee, cls=ListItemButton, sorted_keys=[], selection_mode="multiple" ) def init_bouton_label_ville_depart(self): """Initialise le bouton ville de depart""" self.bouton_label_ville_depart = Button( text="[color=682279]" + self.label_ville_depart + "[/color]", font_size_hint=0.5, markup=True, font_name="fonts/Soft Elegance.ttf", size_hint=(0.3, 0.05), pos_hint={"x": 0.35, "center_y": 0.5}, ) def init_bouton_label_ville_arriver(self): """Initialise le bouton ville d'arriver""" self.bouton_label_ville_arriver = Button( text="[color=682279]" + self.label_ville_arriver + "[/color]", font_size_hint=0.5, markup=True, font_name="fonts/Soft Elegance.ttf", size_hint=(0.3, 0.05), pos_hint={"x": 0.35, "center_y": 0.4}, ) def afficher_alphabet(self, value): """Affiche la liste de l'alphabet""" if self.status_ville_depart == None: self.list_adapter_alphabet.bind(on_selection_change=self.afficher_list_ville) self.list_view_alphabet = ListView(adapter=self.list_adapter_alphabet) self.fenetre.add_widget(self.list_view_alphabet) else: self.init_list_adapter_alphabet() self.list_adapter_alphabet.bind(on_selection_change=self.afficher_list_ville) self.list_view_alphabet = ListView(adapter=self.list_adapter_alphabet) self.fenetre.add_widget(self.list_view_alphabet) def afficher_list_ville(self, adapter): """ Initialise la liste des villes, supprime la liste de l'alphabet et affiche la liste des villes """ if self.status_ville_depart == None: for element in adapter.selection: index_element = element.index self.init_list_adapter_ville(gestion_bd.select_villes(str(adapter.data[index_element]))) self.fenetre.remove_widget(self.list_view_alphabet) self.list_adapter_ville.bind(on_selection_change=self.select_ville) self.list_view_ville = ListView(adapter=self.list_adapter_ville) self.fenetre.add_widget(self.list_view_ville) else: for element in adapter.selection: index_element = element.index self.init_list_adapter_ville( gestion_bd.select_seconde_villes(self.label_ville_depart, adapter.data[index_element]) ) self.fenetre.remove_widget(self.list_view_alphabet) self.list_adapter_ville.bind(on_selection_change=self.select_ville) self.list_view_ville = ListView(adapter=self.list_adapter_ville) self.fenetre.add_widget(self.list_view_ville) def select_ville(self, adapter): """ Self.label_ville_depart devient le nom de la ville de départ Initialise la liste des arrets """ if self.status_ville_depart == None: for element in adapter.selection: index_element = element.index self.label_ville_depart = adapter.data[index_element] self.ville_depart = adapter.data[index_element] self.status_ville_depart = "ville" self.init_list_adapter_arret(gestion_bd.select_arrets(self.label_ville_depart)) self.select_arret() else: for element in adapter.selection: index_element = element.index self.label_ville_arriver = adapter.data[index_element] self.ville_arriver = adapter.data[index_element] self.init_list_adapter_arret(gestion_bd.select_arrets(self.label_ville_arriver)) self.select_arret() def select_arret(self): """Supprime la listes des villes, affiche la liste des arrets""" if self.status_ville_depart == "ville": self.fenetre.remove_widget(self.list_view_ville) self.list_adapter_arret.bind(on_selection_change=self.modif_bouton) self.list_view_arret = ListView(adapter=self.list_adapter_arret) self.fenetre.add_widget(self.list_view_arret) else: self.fenetre.remove_widget(self.list_view_ville) self.list_adapter_arret.bind(on_selection_change=self.modif_bouton) self.list_view_arret = ListView(adapter=self.list_adapter_arret) self.fenetre.add_widget(self.list_view_arret) def modif_bouton(self, adapter): """Modifie les bouton depart ou arriver""" if self.status_ville_depart == "ville": for element in adapter.selection: index_element = element.index self.label_ville_depart = "'" + self.label_ville_depart + ", " + adapter.data[index_element] + "'" self.status_ville_depart = "ville+arret" self.arret_depart = adapter.data[index_element] self.fenetre.remove_widget(self.list_view_arret) self.fenetre.remove_widget(self.bouton_label_ville_depart) self.init_bouton_label_ville_depart() self.fenetre.add_widget(self.bouton_label_ville_depart) else: for element in adapter.selection: index_element = element.index self.label_ville_arriver = "'" + self.label_ville_arriver + ", " + adapter.data[index_element] + "'" self.arret_arriver = adapter.data[index_element] self.fenetre.remove_widget(self.list_view_arret) self.fenetre.remove_widget(self.bouton_label_ville_arriver) self.init_bouton_label_ville_arriver() self.fenetre.add_widget(self.bouton_label_ville_arriver) def recherche(self, value): """Le select général""" if self.label_ville_depart != "Ville de départ !" and self.label_ville_arriver != "Ville d'arriver !": self.retour = gestion_bd.select_horaire( self.ville_depart, self.arret_depart, self.ville_arriver, self.arret_arriver ) self.afficher_resultat() def afficher_resultat(self): """Vide la fenêtre et affiche les resultats""" self.fenetre.clear_widgets() self.affichage_ville_depart = Label( text="[color=682279]" + self.ville_depart + "[/color]", markup=True, font_size=25, pos_hint={"x": -0.2, "center_y": 0.90}, ) self.affichage_ville_arriver = Label( text="[color=682279]" + self.ville_arriver + "[/color]", markup=True, font_size=25, pos_hint={"x": 0.2, "center_y": 0.90}, ) self.affichage_arret_depart = Label( text="[color=682279]" + self.arret_depart + "[/color]", markup=True, font_size=25, pos_hint={"x": -0.2, "center_y": 0.83}, ) self.affichage_arret_arriver = Label( text="[color=682279]" + self.arret_arriver + "[/color]", markup=True, font_size=25, pos_hint={"x": 0.2, "center_y": 0.83}, ) self.affichage_date = Label( text="[color=682279]" + str(self.date) + "[/color]", markup=True, font_size=25, pos_hint={"x": -0.38, "center_y": 0.98}, ) """Pour chaque horaire, l'affiche""" for ville in self.retour: i = 1 for bus in self.retour[ville]: if ville == self.ville_depart: self.affichage_horaire_depart = Label( text="[color=682279]Départ à " + self.retour[ville]["bus" + str(i)][1] + "[/color]", markup=True, font_size=30, pos_hint={"x": -0.2, "center_y": 0.70 - (i / 16)}, ) self.fenetre.add_widget(self.affichage_horaire_depart) i += 1 else: self.affichage_horaire_arriver = Label( text="[color=682279]Arrivée à " + self.retour[ville]["bus" + str(i)][1] + "[/color]", markup=True, font_size=30, pos_hint={"x": 0.2, "center_y": 0.70 - (i / 16)}, ) self.fenetre.add_widget(self.affichage_horaire_arriver) i += 1 self.fenetre.add_widget(self.affichage_ville_depart) self.fenetre.add_widget(self.affichage_ville_arriver) self.fenetre.add_widget(self.affichage_arret_depart) self.fenetre.add_widget(self.affichage_arret_arriver) self.fenetre.add_widget(self.affichage_date)
class Transmut(App): def build(self): self.ether = [] self.universe = [] self.data_path = os.path.realpath(os.path.dirname(sys.argv[0])) + os.sep + "Data" + os.sep self.load_ether() #self.test() #self.solution() self.root = FloatLayout() self.screen_menu = Menu(app=self) self.screen_splash = Splash(app=self) sound_intro = SoundLoader.load(filename= self.data_path + '42286__erh__f-eh-angelic-3.ogg') self.sound_find = SoundLoader.load(filename= self.data_path + '30342__junggle__waterdrop25.ogg') sound_intro.play() self.show('splash') def show(self, *args): name = args[0] screen = getattr(self, 'screen_%s' % name) self.root.clear_widgets() self.root.add_widget(screen) def new_game(self): self.elements_found = ['Air', 'Earth', 'Fire', 'Water'] self.game() def restore_game(self): try: g = open(self.data_path + 'savegame', 'rb') self.elements_found = pickle.load(g) g.close() self.game() except: self.new_game() def game(self): self.root.clear_widgets() a = AnchorLayout() i = Image(source = 'Data/space.jpg', allow_stretch = True, keep_ratio = False) a.add_widget(i) g1 = GridLayout(size_hint = (1,1), cols = 2, rows = 1) a.add_widget(g1) s = ScrollView(size_hint = (.25, 1), do_scroll_x = False, size_hint_y = None) g1.add_widget(s) self.g2 = GridLayout(size_hint = (1, None), height = len(self.elements_found)*35, cols = 1, spacing = 2) s.add_widget(self.g2) self.l = Label(text="0/"+str(len(self.ether)+4), size_hint = (None, None), height = 35) self.g2.add_widget(self.l) for e in self.elements_found: self.update_elements_menu(e) self.root.add_widget(a) def update_elements_menu(self,e): b = Button(size_hint = (None, None), height = 30, text = e) b.bind(on_press = partial(self.add_element_to_universe,e)) self.g2.add_widget(b) self.g2.height = len(self.elements_found)*30 self.l.text = "%d / %d" % (len(self.elements_found), len(self.ether)+4) def add_element_to_universe(self,*args): e = args[0] if len(self.universe) > 0: #let's roll a = 2*math.pi/len(self.universe) c = 0 r = 150 + 100*len(self.universe)/10 for x in self.universe: A = Animation( center_x = Window.center[0] + math.cos(c*a)*r, center_y = Window.center[1] + math.sin(c*a)*r, transition = 'out_back', duration = 1 ) c = c + 1 A.start(x) f = Element(text = e, center=Window.center) f.bind(on_touch_up=partial(self.check_position,f)) self.universe.append(f) self.root.add_widget(f) def check_position(self,*args): f = args[1] if f in self.universe and (f.x <0.1*Window.width or f.x>0.9*Window.width or f.y<0.1*Window.height or f.y>0.9*Window.height): self.universe.remove(f) self.root.remove_widget(f) return 1 for e in self.universe: if e == f: continue if f.collide_widget(e): b = self.transmute(e.text,f.text) if b: self.sound_find.play() self.universe.remove(e) self.universe.remove(f) self.root.remove_widget(e) self.root.remove_widget(f) self.add_element_to_universe(b) if b not in self.elements_found: self.elements_found.append(b) output = open(self.data_path + 'savegame', 'wb') pickle.dump(self.elements_found, output) output.close() self.update_elements_menu(b) return 1 def load_ether(self): f = open(self.data_path + "ether.dat", 'r') c = 0 for line in f: c = c + 1 if re.match("#",line): continue a = re.match("(\d+)\s+(.*?)\s+\=\s+(.*?)\s+\+\s+(.*?)\s+",line) if a != None: self.ether.append( [int(a.group(1)), a.group(2), a.group(3), a.group(4)] ) else: print "Error building ether [%d] " % c def transmute(self, item1, item2): for formula in self.ether: if (formula[2] == item1 and formula[3] == item2) or (formula[3] == item1 and formula[2] == item2): return formula[1] return None def test(self): print "%d %s = %s + %s" %(self.ether[5][0], self.ether[5][1], self.ether[5][2], self.ether[5][3]) print "transmute Storm & Snow => %s" % self.transmute('Storm','Snow') print "transmute Bread & Snow => %s" % self.transmute('Bread','Snow') # doesn't work def solution(self): s = ['Air', 'Earth', 'Fire', 'Water'] count = 4 def solution_rec(e,l): for x in l: n = self.transmute(e,x) if n and n not in s: #count = count + 1; print "%s + %s = %s" %(e,x,n) l.append(n) solution_rec(n,l) for e in s: solution_rec(e,s)
class Safhe2(Screen): def __init__(self, **kwargs): super(Safhe2, self).__init__(**kwargs) self.nameZ = "joystick1" with self.canvas: Rectangle(source = 'joystick.png', size = (Window.width,Window.height)) self.layout = FloatLayout(size=(300, 300)) self.key = [] self.button1 = [] self.location = [] self.tolocation = [] self.x = 0 self.draw_button() self.add_widget(self.layout) self.drawing = "true" def clear_button(self,bt): self.key = [] self.layout.clear_widgets() self.draw_button() self.button1 = [] self.location = [] self.tolocation = [] def undo(self,bt): i = 0 if len(self.location)!=0: del self.location [-1] del self.key [-1] self.layout.clear_widgets() self.draw_button() for x,y,x1,y1 in self.location: i = i+1 thebuttons = Button(background_color =(0.3,0.9,1,0.9),size_hint= (None,None),size = (x1 - x, y1 - y),pos=(x,y), border=(1,1,1,1), text = str(self.key[i-1])) self.layout.add_widget(thebuttons) def draw_button(self): self.nextpage = Button(text = "Previous page",size_hint= (None,None),size = ("75pt","25pt"),on_press = self.next ) self.save = Button(text = "Save",size_hint= (None,None),pos = ("75pt","0pt"),size = ("75pt","25pt"),on_press = self.saving ) self.clearbutton = Button(text = "Clear",size_hint= (None,None),pos = ("150pt","0pt"),size = ("75pt","25pt"),on_press = self.clear_button ) self.Undo = Button(text = "Undo",size_hint= (None,None),pos = ("225pt","0pt"),size = ("75pt","25pt"),on_press = self.undo ) self.layout.add_widget(self.clearbutton) self.layout.add_widget(self.Undo) self.layout.add_widget(self.save) self.layout.add_widget(self.nextpage) def next(self, btn): self.draw_button() sm.current = "page3" def saving(self, btn): q = ButtonNamePopUp(self) q.open() def saved(self): self.location.append(100,300,200,300) def clear(self): i = 0 self.layout.clear_widgets() self.draw_button() self.location.append(self.tolocation) #print self.tolocation, self.location #main buuton for x,y,x1,y1 in self.location: # print "rastin" i = i + 1 # print "salam aghaye x1 va x","1",x1,"0",x # print "salam aghaye y1 va y","1",y1,"0",y thebuttons = Button(background_color =(0.3,0.9,1,0.9),size_hint= (None,None),size = (x1 - x, y1 - y) ,pos=(x,y), border=(1,1,1,1), text = str(self.key[i-1])) self.layout.add_widget(thebuttons) self.tolocation = [] self.button1 = [] def on_touch_down(self, touch): super(Safhe2, self).on_touch_down(touch) q = [] q.append(touch.x) q.append(touch.y) # check if its in one of the buttons in self.location x, y = touch.x, touch.y cntr = 0 if x>100 and x<200 and y>0 and y<50: self.drawing = "saving" print "saving" for x1,y1,x2,y2 in self.location: if (x1<=x<=x2 or x2<=x<=x1) and (y1<=y<=y2 or y2<=y<=y1): self.drawing = "options" self.clicked_button_id = cntr print "Sajad sedasho kam kon ye zarre, ye zarre az ye zarre bishtar" cntr += 1 if not( (touch.x<200 and touch.x>100 and touch.y<50 and touch.y>0) or (touch.x<100 and touch.x>0 and touch.y<50 and touch.y>0) or (touch.x<300 and touch.x>200 and touch.y<50 and touch.y>0) or (touch.x<400 and touch.x>300 and touch.y<50 and touch.y>0)): self.button1.append(touch.x) self.button1.append(touch.y) self.tolocation.append(touch.x) self.tolocation.append(touch.y) def on_touch_move(self, touch): super(Safhe2, self).on_touch_move(touch) if self.drawing != "true": return if not( (touch.x<200 and touch.x>100 and touch.y<50 and touch.y>0) or (touch.x<100 and touch.x>0 and touch.y<50 and touch.y>0) or (touch.x<300 and touch.x>200 and touch.y<50 and touch.y>0) or (touch.x<400 and touch.x>300 and touch.y<50 and touch.y>0)): self.layout.clear_widgets() for x,y,x1,y1 in self.location: thebuttons = Button(background_color =(0,0.8,0.8,0.4),size_hint= (None,None),size = (x1 - x, y1 - y),pos=(x,y), border=(1,1,1,1)) self.layout.add_widget(thebuttons) self.draw_button() self.button1.append(touch.x) self.button1.append(touch.y) button = Button(background_color =(0,0.8,0.8,0.4),size_hint= (None,None),size = (self.button1[2] - self.button1[0], self.button1[3] - self.button1[1]) , pos_hint={'x':self.button1[0]/Window.width , 'y':self.button1[1]/Window.height}, border=(1,1,1,1)) self.layout.add_widget(button) del self.button1[-1] del self.button1[-1] def on_touch_up(self, touch): super(Safhe2, self).on_touch_up(touch) if self.drawing == "options": q = ButtonOptionsPopUp(self) q.open() return if not( (touch.x<200 and touch.x>100 and touch.y<50 and touch.y>0) or (touch.x<100 and touch.x>0 and touch.y<50 and touch.y>0) or (touch.x<300 and touch.x>200 and touch.y<50 and touch.y>0) or (touch.x<400 and touch.x>300 and touch.y<50 and touch.y>0)): self.key.append(-1) del self.button1[-1] del self.button1[-1] self.tolocation.append(touch.x) self.tolocation.append(touch.y) self.clear() #print self.location print self.key if self.drawing == "toBeTrueSoon": print "Salam" self.drawing = "true" self.undo(None)
class KurveApp(App): def build(self): #game = KurveGame() self.root = FloatLayout() #android audio. Comment next 2 lines to use on android self.sound = SoundLoader.load(filename = 'assets/song.mp3') self.sound.play() loadscreen = Image(source='assets/intro.png') x,y = 1280,736 start = Button(text = "PLAY! ",font_size = 30,pos = (x-x*3/8,y/10),size=(x/4,y/8)) help1 = Button(text = "Help",font_size = 20,pos = (x/8,y/10),size=(x/8,y/8)) start.bind(on_press = self.startgame) help1.bind(on_press = self.loadhelp) loadscreen.add_widget(start) loadscreen.add_widget(help1) self.root.add_widget(loadscreen) return self.root def loadhelp(self,obj): app = self x,y = 1280,736 self.root.clear_widgets() helpimg = Image(source = 'assets/help.jpg') back = Button(text = "Got it. Lets Play!",font_size = 25,pos = (x-x*3/8,y/10),size=(x/4,y/8)) helpimg.add_widget(back) self.root.add_widget(helpimg) def backfn(obj): self.startgame(app) back.bind(on_press = backfn) return self.root def startgame(self,obj): self.root.clear_widgets() game = KurveGame() x = game.width y = game.top leftbtn = Button(text = "left",pos = (0,y-y/6),size=(x/12,y/6)) rightbtn = Button(text = "right",pos = (0,0),size=(x/12,y/6)) leftbtn2 = Button(text="left",pos = (x-x/12,0),size=(x/12,y/6)) rightbtn2 = Button(text = "right",pos = (x-x/12,y-y/6),size=(x/12,y/6)) game.add_widget(leftbtn) game.add_widget(rightbtn) game.add_widget(leftbtn2) game.add_widget(rightbtn2) game.begin(self,self.root) Clock.schedule_interval(game.update,1.0/15.0) def turn_left(obj): game.snake1.velocity = Vector(*game.snake1.velocity).rotate(90) def turn_right(obj): game.snake1.velocity = Vector(*game.snake1.velocity).rotate(270) def turn_left2(obj): game.snake2.velocity = Vector(*game.snake2.velocity).rotate(90) def turn_right2(obj): game.snake2.velocity = Vector(*game.snake2.velocity).rotate(270) leftbtn.bind(on_press = turn_left) rightbtn.bind(on_release = turn_right) leftbtn2.bind(on_press = turn_left2) rightbtn2.bind(on_release = turn_right2) self.root.add_widget(game) return self.root
class MainApp(App): def build(self): print('os getcwd'+os.getcwd()) try: wb = openpyxl.load_workbook("datafile.xlsx") except: wb = openpyxl.Workbook() w = wb.create_sheet("Sheet1") wb.save(filename='datafile.xlsx') self.main_layout = FloatLayout(size=(50, 50)) button1 = Button( text='Add Item' ,background_color=(0,255,0,0.7) , pos=(20, 700), size_hint=(.50, .1), pos_hint={'x': .25, 'y': .85} ) try: Window.clearcolor = (1, 1, 1, 1) a = Image(source='ar1.png',size=(1200,900)) self.main_layout.add_widget(a) except: pass button1.bind(on_press=self.on_button_press1) self.main_layout.add_widget(button1) button2 = Button( text='Search Item', background_color = (0, 255, 0, 0.7), pos=(20, 700), size_hint=(.50, .1), pos_hint={'x': .25, 'y': .65} ) button2.bind(on_press=self.on_button_press2) self.main_layout.add_widget(button2) button3 = Button( text='All Items', pos=(20, 700),background_color = (0, 255, 0, 0.7), size_hint=(.50, .1), pos_hint={'x': .25, 'y': .45} ) button3.bind(on_press=self.on_button_press3) self.main_layout.add_widget(button3) button4 = Button( text='Total Items', pos=(20, 700),background_color = (0, 255, 0, 0.7), size_hint=(.50, .1), pos_hint={'x': .25, 'y': .25} ) button5 = Button( text='Delete Item', pos=(20, 700),background_color = (0, 255, 0, 0.7), size_hint=(.50, .1), pos_hint={'x': .25, 'y': .05} ) button4.bind(on_press=self.on_button_press4) self.main_layout.add_widget(button4) button5.bind(on_press=self.on_button_press5) self.main_layout.add_widget(button5) return self.main_layout def on_button_press1(self, instance): self.main_layout.clear_widgets() app1 = additem1() app1.run() print('hi') def on_button_press2(self, instance): self.main_layout.clear_widgets() f = search_item_class() f.run() def on_button_press3(self, instance): self.main_layout.clear_widgets() f = spin() f.run() def on_button_press4(self, instance): self.main_layout.clear_widgets() f = total_item_class() f.run() def on_button_press5(self, instance): self.main_layout.clear_widgets() f = delete_item_class() f.run()
class TwistedClientApp(App): ''' ''' connection = None user_os = None user = None labelmsg = "" chat_online_details = "" haha = [] y=0 notify_events = [] available_users = [] def build(self): root = self.initialise_setup() self.start_thread() return root def initialise_setup(self): '''variable initialisation''' self.layout = FloatLayout(size=(800,800)) self.Mainlabel = Label(text="SharePy",color=(0.6,0.7,0.2,1),font_size="65sp",pos=(280,450),size_hint=(.3,.3)) self.layout.add_widget(self.Mainlabel) self.cont_but = Button(text="Cont...",background_color=(0.2,0.3,0.88,1),pos=(700,30),size_hint=(.12,.1)) self.layout.add_widget(self.cont_but) self.INFO = Label(size_hint=(.3,.3),pos=(230,300),color=(0.6,0.3,0.1,1),font_size="21dp") self.INFO2 = Label(size_hint=(.3,.3),pos=(230,150),color=(0.3,0.3,0.7,1),font_size="21dp") self.INFO.text = "SharePy is a project based on File Sharing.\nIts a project developed in Kivy using Python.\n\nBasic Features include:\n " self.INFO2.text = self.INFO2.text + "\n-> Zero Configuration\n-> File Transfering\n-> File Syncing\n-> File Searching\n-> Notification Broadcasting on File Events\n-> ChatBot for communication between Clients\n-> File Listing" self.INFO3 = Label(text="Members:\nVarun Malhotra\nMayank Bhola\nHarsh Bhatia",color=(0.7,0.1,0.1,1),pos=(150,40),size_hint=(0.2,0.2),font_size="21dp") self.layout.add_widget(self.INFO) self.layout.add_widget(self.INFO2) self.layout.add_widget(self.INFO3) self.anim_info2 = Animation(x=80,y=150, opacity=0.4, d=0.4,t ='in_quad') +\ Animation(x=230,y=150, opacity=1, d=0.5) self.anim_info2.start(self.INFO2) self.anim_info3 = Animation(x=80,y=20, opacity=0.4, d=0.6,t ='in_quad') +\ Animation(x=150,y=20, opacity=1, d=0.8) self.anim_info3.start(self.INFO3) self.cont_but.bind(on_press=self.setup_gui) return self.layout def setup_gui(self,object): ''' The layout for the app goes here ''' global user user = getpass.getuser() global user_os user_os = platform.system() self.Mainlabel = Label(text="SharePy",color=(0.6,0.7,0.2,1),font_size="65sp",pos=(280,450),size_hint=(.3,.3)) self.label = TextInput(hint_text='Connecting...\n',size_hint=(.68,.5),pos=(20,120),readonly=True,focus=True) self.dir_loc = TextInput(hint_text='Your root directory is: ',size_hint=(.68,.07),pos=(20,430),readonly=True,background_color=(192,192,192,0.3),foreground_color=(255,255,255,1)) self.button =Button(text="Start Client",size_hint=(.2,.2),background_color=(0.7,0.2,0.3,1),pos=(50,100)) self.ctexthost = TextInput(text="localhost",hint_text="Enter host",size_hint=(.2,.1),pos=(-150,350),multiline=False,background_color=(0.4,0.5,1,0.9),foreground_color=(255,255,255,1)) self.ctextport = TextInput(text="8000",hint_text="Enter port",size_hint=(.2,.1),pos=(-150,250),multiline=False,background_color=(0.4,0.5,1,.9),foreground_color=(255,255,255,1)) self.button1 = ToggleButton(text="Search a File",size_hint=(.2,.2),pos=(10,500),group="file_share",font_size='18sp') self.button2 = ToggleButton(text="Get a File",size_hint=(.2,.2),pos=(210,500),group="file_share",font_size="18sp") self.button3 = Button(text="Search a File",size_hint=(.17,.15),pos=(20,520),background_color=(0.5,0.7,1,1),font_size="18sp") self.button4 = Button(text="List Directory",size_hint=(.17,.15),pos=(150,520),background_color=(0.4,1,0.3,1),font_size="18sp") self.button4.bind(on_press=self.opentextinput) self.closeclient = Button(text="Close Client",pos=(425,520),size_hint=(0.17,0.15),background_color=(0.8,0.3,0.1,1),font_size="18sp") self.closeclient.bind(on_press=self.CloseClient) self.notify_ground = TextInput(text="I notify events",pos=(600,0),background_color=(0.7,0.5,0.9,1),size_hint=(.3,1),readonly=True,scroll_y=10) self.chat_ground = TextInput(text="CHAT BOX",pos=(600,0),background_color=(0.7,0.5,0.9,1),size_hint=(.3,1),readonly=True,scroll_y=10) self.chatbox = Button(text="Chat Box",pos=(563,520),size_hint=(0.17,0.15),background_color=(0.3,0.3,0.7,1),font_size="18sp") self.chatbox.bind(on_press=self.chathistory) self.reponame = TextInput(text="Hellosnp",hint_text="Enter RepoName",pos=(200,300),size_hint=(0.5,0.1),multiline=False,focus=True) self.button.bind(on_press=self.connect_to_server) self.label_info = TextInput(text="Hi i'm a alebe;",pos=(0,610),background_color=(0.7,0,0,1),size_hint=(1,.2),readonly=True) self.notify_but = Button(text="Recent events",size_hint=(.17,.15),pos=(290,520),background_color=(0.8,0.2,0.3,1),font_size="18sp") self.notify_but.bind(on_press=self.recent_act) self.cancel_event = Button(text="Close",size_hint=(0.27,0.06),pos=(600,0),background_color=(255,0,0,0.6)) self.cancel_chat = Button(text="Close",size_hint=(0.27,0.06),pos=(600,0),background_color=(255,0,0,0.6)) self.repolabel = Label(text="Create your own Repository/New Folder by providing the name below",pos=(210,320),size_hint=(0.5,0.5),color=(0.6,0.3,0.1,1),font_size="20dp") self.update = Button(text="Update",background_color=(0.3,0.3,0.9,1),size_hint=(.25,.1),pos=(600,550)) self.fetching_server() return self.layout def fetching_server(self): ''' Start server on desired port''' self.layout.clear_widgets() self.layout.add_widget(self.button) self.layout.add_widget(self.Mainlabel) self.layout.add_widget(self.ctexthost) self.layout.add_widget(self.ctextport) self.anim_host = Animation(x=280,y=550, opacity=0.4, d=0.2,t ='in_quad') +\ Animation(x=280,y=450, opacity=1, d=0.2) self.anim_host.start(self.Mainlabel) self.anim_host = Animation(x=0,y=350, opacity=0.4, d=0.5,t ='in_quad') +\ Animation(x=50,y=350, opacity=1, d=0.6) self.anim_host.start(self.ctexthost) self.anim_port = Animation(x=0,y=250, opacity=0.4, d=0.5,t ='in_quad') +\ Animation(x=50,y=250, opacity=1, d=0.6) self.anim_port.start(self.ctextport) self.anim_startbut = Animation(x=0,y=100, opacity=0.4, d=0.5,t ='in_quad') +\ Animation(x=50,y=100, opacity=1, d=0.6) self.anim_startbut.start(self.button) def repo_creation(self): ''' creation of repo to work in''' self.layout.clear_widgets() self.layout.add_widget(self.repolabel) self.layout.add_widget(self.reponame) self.reponame.bind(on_text_validate=self.building_utilities) return self.layout def building_utilities(self, *args): ''' providing the services to the client''' root_dirname = self.reponame.text if not os.path.exists(root_dirname): os.makedirs(root_dirname) os.chdir(root_dirname) self.dir_loc.text = os.getcwd() self.layout.clear_widgets() self.layout.add_widget(self.button3) self.layout.add_widget(self.button4) self.layout.add_widget(self.closeclient) self.layout.add_widget(self.notify_but) self.layout.add_widget(self.chatbox) self.layout.add_widget(self.label) self.layout.add_widget(self.dir_loc) self.layout.add_widget(self.label_info) self.anim_host = Animation(x=20,y=520, opacity=0.4, d=0.5,t ='in_quad') +\ Animation(x=20,y=480, opacity=1, d=0.6) self.anim_host.start(self.button3) self.anim_port = Animation(x=155,y=520, opacity=0.1, d=0.5,t ='in_quad') +\ Animation(x=155,y=480, opacity=1, d=0.6) self.anim_port.start(self.button4) self.anim_button = Animation(x=290,y=520, opacity=0.1, d=0.5,t ='in_quad') +\ Animation(x=290,y=480, opacity=1, d=0.6) self.anim_button.start(self.notify_but) self.anim_close = Animation(x=425,y=520, opacity=0.1, d=0.5,t ='in_quad') +\ Animation(x=425,y=480, opacity=1, d=0.6) self.anim_close.start(self.closeclient) self.anim_chat = Animation(x=563,y=520, opacity=0.1, d=0.5,t ='in_quad') +\ Animation(x=563,y=480, opacity=1, d=0.6) self.anim_chat.start(self.chatbox) return self.layout def connect_to_server(self,*args): ''' connection establishing (handshaking)''' if((self.ctextport.text).isdigit()): self.conn = reactor.connectTCP(str(self.ctexthost.text), int(self.ctextport.text), EchoFactory(self)) self.label.text = "Connecting...\n" else: self.label.text = "Not Connected...\nPlease enter valid port" def on_connection(self, connection): ''' on successful establishment with server''' self.print_message("Connected Succesfully!") self.connection = connection self.repo_creation() def send_message(self,connection): ''' client demands resources ''' msg = self.textbox.text if msg and self.connection: msg = "2$#" + user + "@" + user_os + ": " + msg self.connection.write(str(msg)) self.textbox.text = "" def print_message(self, msg): ''' the processed output client gets on demanding resources ''' copr = msg.split("$#")[0] if copr.isdigit(): if (int(copr)==2): self.label.text = msg.split("$#")[1] + "\n" #print msg.split("$#")[1] elif (int(copr)==8): self.sendarea.text = self.sendarea.text + msg.split("8$#")[1] + "\n" print "recveived msg - " + (msg.split("8$#")[1]).split("##")[1] + " from ip add" + (msg.split("8$#")[1]).split("##")[0] elif (int(copr)==4): msg = msg.split("$#")[1] g = msg.split(": <")[1] o = g.split(": ")[0] if o=="FileMovedEvent": d = g.split(": src_path=")[1] e = d.split(", ")[0] f = d.split(", ")[1] f1 = f.split(">")[0] msg = "A file at\n" + e + "\nis moved to\n" + f1 else: of = g.split(": ")[1] print o f = g.split("src_path=")[1] f1 = f.split(">")[0] msg = "A file at\n" + f1 + "\n is " + o self.layout.remove_widget(self.label_info) self.layout.add_widget(self.label_info) self.label_info.text = str(msg) self.anim = Animation(x=0,y=550, opacity=0, d=1, t='in_back') +\ Animation(x=0,y=480, d=1, opacity=0.8) +\ Animation(x=0,y=480, d=4,opacity=1) +\ Animation(x=0,y=650, opacity=0, d=2) self.anim.start(self.label_info) self.notify_events.append(str(msg)) elif (int(copr)==5): msg = msg.split("$#")[1] msg = msg.split(',') self.chat_ground.text = " " self.haha = [0]*30 self.y = 0 for on in range (0,len(msg)-1): self.haha[on] = Button(text=str(msg[on]),background_color=(0,1,0,1),pos=(600,515-self.y),size_hint=(0.25,0.07)) self.layout.add_widget(self.haha[on]) self.haha[on].bind(on_press= partial(self.open_chat_for,msg[on])) self.y=self.y+45 self.layout.add_widget(self.update) return self.layout else: self.label.text = msg + "\n" def opentextinput(self, *args): ''' for sending a message to server or searching for ''' self.textbox = TextInput(size_hint=(.9,.1),pos=(0,0), multiline=False,focus=True) self.textbox.bind(on_text_validate=self.send_message) self.closebutton = Button(text="Close",size_hint=(.1,.1),pos=(720,0),background_color=(255,0,0,1)) self.closebutton.bind(on_press=self.close_input_editor) self.layout.add_widget(self.textbox) self.layout.add_widget(self.closebutton) def close_input_editor(self, *args): ''' closing the requester -- textbox ''' self.layout.remove_widget(self.closebutton) self.layout.remove_widget(self.textbox) def CloseClient(self, *args): ''' client wants to disconnect with the server ''' self.conn.disconnect() self.layout.clear_widgets() #os.chdir(cd..) self.repo_creation() path = os.path.dirname(os.getcwd()) os.chdir(path) #output = subprocess.Popen(["cd.."],stdout=subprocess.PIPE).communicate()[0] print os.getcwd() return self.layout def chathistory(self, *args): ''' maintaining conversational history ''' self.layout.remove_widget(self.chatbox) self.layout.clear_widgets() self.sendarea = Label(text=" ",size_hint=(.2,.2),pos=(80,400),font_size="19dp",color=(0.7,0.5,0.6,1)) self.layout.add_widget(self.sendarea) self.update.bind(on_press=self.cancel_chat_box) self.layout.add_widget(self.chat_ground) self.backbutton = Button(text="Back <-",background_color=(1,0.1,0.1,1),size_hint=(.11,.1),pos=(30,500),font_size="20dp") self.layout.add_widget(self.backbutton) self.backbutton.bind(on_press=self.building_utilities) #self.layout.add_widget(self.cancel_chat) #self.cancel_chat.bind(on_press=self.cancel_chat_box) self.chat_online_details = "5$#" + user + "@" + user_os + ": " + "Ready to chat" #print self.chat_online_details self.connection.write(str(self.chat_online_details)) #return self.layout def stimulate_on_repo_changes(self): ''' checking for any file events in the current repo ''' while True: #self.logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(message)s',datefmt='%Y-%m-%d %H:%M:%S') self.path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd() self.event_handler = ChangeHandler(self) self.observer = Observer() self.observer.schedule(self.event_handler, self.path, recursive=True) self.observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: self.observer.stop() self.observer.join() def start_thread(self): t = Thread(target=self.stimulate_on_repo_changes) t.start() def notify(self,textevent): textevent1 = "4$#" + user + "@" + user_os + ": " + str(textevent) #textevent = "4$#" + textevent self.connection.write(str(textevent1)) return self.layout def dismiss_popup(instance): return False def recent_act(self, textevent): self.layout.remove_widget(self.notify_but) self.layout.add_widget(self.notify_ground) self.anim_ground = Animation(x=700,y=0, opacity=0.3, d=0.2,t ='in_quad') +\ Animation(x=600,y=0, opacity=1, d=0.2) self.anim_ground.start(self.notify_ground) self.layout.add_widget(self.cancel_event) self.cancel_event.bind(on_press=self.cancel_event_window) self.notify_ground.text = "" for l in self.notify_events: self.notify_ground.text = self.notify_ground.text + str(l) + '\n' return self.layout def cancel_event_window(self,*args): self.layout.remove_widget(self.notify_ground) self.layout.remove_widget(self.cancel_event) self.layout.add_widget(self.notify_but) return self.layout def cancel_chat_box(self,args): self.layout.clear_widgets() self.chathistory() return self.layout def open_chat_for(self,ipadd,args): self.chat_lid = TextInput(hint_text="Send msg",pos=(100,50),size_hint=(.6,.1),multiline=False,focus=True) self.layout.add_widget(self.chat_lid) self.chat_lid.bind(on_text_validate=partial(self.send_to_ip,ipadd)) def send_to_ip(self,ipadd,args): print "send msg - '" + self.chat_lid.text +"' to ip address - "+ipadd self.connection.write("8$#"+str(ipadd)+"##"+str(self.chat_lid.text)) self.chat_lid.text = "" self.chat_lid.focus = True
class HandlerFlowControl: def __init__(self): self.root = FloatLayout() self.state = HandlerStateAskNames(self) self.state.start() def askNamesStart(self): # XXX: note we are using state to keep our local variables, otherwise there could be only one copy self.state.names = [] layout = BoxLayout(orientation='vertical') text_input = TextInput(font_size=100, size_hint_y=None, height=150) accept_button = Button(text='Accept name') accept_button.bind(on_release=lambda x: self.state.nameEntered(text_input.text)) layout.add_widget(text_input) layout.add_widget(accept_button) self.root.clear_widgets() self.root.add_widget(layout) def askNamesEnd(self): self.state = HandlerStateShowNames(self) self.state.start() def askNamesNameEntered(self, name): if len(name) > 3: self.state.names.append(name) if len(self.state.names) == 3: self.state = HandlerStateShowNames(self) self.state.start(self.state.names) else: # XXX: should be another state popup = Popup(title='Invalid name', content=Label(text='It should have more than 3 characters, press "Esc" to continue'), size=(200,200)) popup.open() def showNamesStart(self, names): layout = BoxLayout(orientation='vertical') # Screen 1 to 2 communication for n in names: label = Label(text=n) layout.add_widget(label) inner_layout = BoxLayout(orientation='horizontal') button_next = Button(text='Next screen') button_prev = Button(text='Prev screen') inner_layout.add_widget(button_next) inner_layout.add_widget(button_prev) button_next.bind(on_press=lambda x: self.state.next()) button_prev.bind(on_press=lambda x: self.state.prev()) layout.add_widget(inner_layout) self.root.clear_widgets() self.root.add_widget(layout) def showNamesEnd(self): pass def showNamesPressPrev(self): self.my_names = [] self.state = HandlerStateAskNames(self) self.state.start() def showNamesPressNext(self): self.state = HandlerStatePromptForExit(self) self.state.start() def promptForExitStart(self): button = Button(text='Click to exit') button.bind(on_press=lambda x: exit()) self.root.clear_widgets() self.root.add_widget(button) def promptForExitQuit(self): pass