class Register(FloatLayout): def __init__(self, **kwargs): super(MasterClient.Register, self).__init__(**kwargs) # Background image self.background = Image() self.background.source = ("interface/Register/register.png") # Next button self.next_button = Button() self.next_button.size = (25, 25) self.next_button.pos = (360, 645) self.next_button.background_color = (1.0, 1.0, 1.0, 0.01) self.next_button.on_press = self.dismiss_Register # TextInput field self.username = TextInput() self.username.size = (240, 29) self.username.pos = (113, 545) self.username.font_name = "interface/Montserrat-Medium.ttf" self.username.font_size = 14 self.username.cursor_color = [0.31, 0.49, 0.63, 1.0] self.username.background_color = (1.0, 1.0, 1.0, 0) self.background.add_widget(self.next_button) self.background.add_widget(self.username) self.add_widget(self.background) def dismiss_Register(self): global my_username my_username = str(self.username.text) self.clear_widgets() # Para a GUI para que a execução de conexão possa continuar App.get_running_app().stop()
class Chat(Screen): def __init__(self, ms, **kwargs): super(MasterClient.Chat, self).__init__(**kwargs) self.ms = ms self.layout = FloatLayout() # Background image self.background = Image() self.background.source = ("interface/Chat/chat_bars.png") # Back button self.back_button = Button() self.back_button.size = (25, 25) self.back_button.pos = (20, 645) self.back_button.background_color = (1.0, 1.0, 1.0, 0.5) self.back_button.on_press = self.back_home # Contact status self.contact_status = Image() self.contact_status.source = ("interface/online.png") self.contact_status.size = (18, 18) self.contact_status.pos = (360, 652) self.background.add_widget(self.back_button) self.background.add_widget(self.contact_status) self.layout.add_widget(self.background) self.add_widget(self.layout) def back_home(self): App.get_running_app().sm.current = "home"
def build(self): f=FloatLayout() b=Button(text="enter", font_size=30) i=Image(source="enter.jpg") f.add_widget(i) i.add_widget(b) return f
def loadScores(self, obj): app = self self.clear_widgets() helpimg = Image(source = 'assets/help.jpg') back = Button(text = "BACK",font_size = 25) helpimg.add_widget(back) self.add_widget(helpimg) def backfn(obj): self.__init__() back.bind(on_press = backfn) return self
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 loadScores(self, obj): #app = self self.clear_widgets() helpimg = Image(source='assets/help.jpg') back = Button(text="BACK", font_size=25) helpimg.add_widget(back) self.add_widget(helpimg) def backfn(obj): self.__init__() back.bind(on_press=backfn) return self
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
class CustomLayout(FloatLayout): def __init__(self, **kwargs): # make sure we aren't overriding any important functionality super(CustomLayout, self).__init__(**kwargs) self.imag1 = Image(source="fundal.jpg") self.imag1.opacity = 0.5 self.add_widget(self.imag1) self.but1 = Button(text="Butonul 1", bold=True, background_color=(0, 0, 1, 1)) self.but1.pos = (350, 300) self.but1.size_hint = (1, 0.05) self.but1.opacity = 0.5 self.imag1.add_widget(self.but1) self.but2 = Button(text="Butonul 2", bold=True, background_color=(0, 0, 1, 1)) self.but2.pos = (350, 200) self.imag1.add_widget(self.but2) self.but3 = Button(text="Butonul 3", bold=True, background_color=(0, 0, 1, 1)) self.but3.pos = (350, 100) self.but3.size_hint = (0.3, 0.05) self.imag1.add_widget(self.but3)
class AddContact(Screen): def __init__(self, ms, home_screen, **kwargs): super(MasterClient.AddContact, self).__init__(**kwargs) self.ms = ms self.home_screen = home_screen self.layout = FloatLayout() # Background image self.background = Image() self.background.source = ("interface/AddContact/add_contact.png") # Next button self.next_button = Button() self.next_button.size = (25, 25) self.next_button.pos = (360, 645) self.next_button.background_color = (1.0, 1.0, 1.0, 0.5) self.next_button.on_press = self.add_contact # TextInput field self.contact_username = TextInput() self.contact_username.size = (240, 28) self.contact_username.pos = (113, 545) self.contact_username.font_name = "interface/Montserrat-Medium.ttf" self.contact_username.font_size = 14 self.contact_username.cursor_color = [0.31, 0.49, 0.63, 1.0] self.contact_username.background_color = (1.0, 1.0, 1.0, 0) self.background.add_widget(self.next_button) self.background.add_widget(self.contact_username) self.layout.add_widget(self.background) self.add_widget(self.layout) def add_contact(self): new_contact_added = str(self.contact_username.text) self.ms.add_contact(new_contact_added) App.get_running_app().sm.current = "home"
def ElementCard(fetch, size): name = Cards.Text("name", fetch[1]) type = Cards.Text("type", fetch[3]) text = Cards.Text("text", fetch[5]) # don't ask... if size != 1: posX = size * 1.65 posX3 = size * 1.7 posY1 = size * 1.295 posY2 = size * 1.322 posY3 = size * 17 posXE = size * 1.79 posYE = size * 1.25 else: posX = 1 posX3 = 1 posY1 = 1 posY2 = 1 posY3 = 1 posXE = 1 posYE = 1 border = Image(source="ElementCard.png", size_hint=(1 * size, 1 * size), allow_stretch=True) border.add_widget( Image(source=str(fetch[3] + ".png"), size=(45 * size, 45 * size), pos=(228 * posXE, 465 * posYE), allow_stretch=True)) border.add_widget( Image(texture=name, pos=(278 * posX, 392 * posY1), size=(220 * size, 220 * size), allow_stretch=True)) border.add_widget( Image(texture=type, pos=(278 * posX, 363 * posY2), size=(220 * size, 220 * size), allow_stretch=True)) border.add_widget( Image(texture=text, pos=(255 * posX3, 8 * posY3), size=(290 * size, 290 * size), allow_stretch=True)) return border
class DisplayLayout(FloatLayout): def __init__(self, **kwargs): self.anotations = annotationRegister self.current = self.anotations["Landmark"] super(DisplayLayout, self).__init__(**kwargs) self.newImage = Image() self.add_widget(self.newImage) def changeImg(self, src): if src: self.newImage.source = src # self.newImage.arrayImg = cv2.cvtColor(cv2.imread(src), cv2.COLOR_BGR2RGB) self.newImage.arrayImg = cv2.imread(src) def changeAnnotationType(self, anot): self.current.update_widgets(list(self.newImage.children)) self.current = self.anotations[anot] new_children = self.current.widgets self.newImage.clear_widgets() for child in new_children: self.newImage.add_widget(child) def addAnnotation(self, annotationParent, *args, **kwargs): self.current.addAnnotation(annotationParent, *args, **kwargs) self.current.update_widgets(list(annotationParent.children)) def saveAnnotations(self, imgName, annotationParent): return self.current.saveAnnotations(imgName, annotationParent) def annotationSuicideModeToggle(self, annotationParent, *args, **kwargs): for anoType in self.anotations: for anotation in self.anotations[anoType].widgets: anotation.suicideModeToggle()
class CustomLayout(FloatLayout): def __init__(self, **kwargs): # make sure we aren't overriding any important functionality super(CustomLayout, self).__init__(**kwargs) self.imag1 = Image(source="fundal.jpg") self.imag1.opacity = 0.5 self.add_widget(self.imag1) self.but1 =Button(text = "Butonul 1",bold =True, background_color = (0,0,1,1)) self.but1.pos = (350,300) self.but1.size_hint = (1,0.05) self.but1.opacity = 0.5 self.imag1.add_widget(self.but1) self.but2 =Button(text = "Butonul 2",bold =True, background_color = (0,0,1,1)) self.but2.pos = (350,200) self.imag1.add_widget(self.but2) self.but3 =Button(text = "Butonul 3",bold =True, background_color = (0,0,1,1)) self.but3.pos = (350,100) self.but3.size_hint = (0.3,0.05) self.imag1.add_widget(self.but3)
class SettingPos(SettingString): '''Implementation of a string setting on top of a :class:`SettingItem`. It is visualized with a :class:`~kivy.uix.label.Label` widget that, when clicked, will open a :class:`~kivy.uix.popup.Popup` with a :class:`~kivy.uix.textinput.Textinput` so the user can enter a custom value. ''' popup = ObjectProperty(None, allownone=True) '''(internal) Used to store the current popup when it's shown. :attr:`popup` is an :class:`~kivy.properties.ObjectProperty` and defaults to None. ''' # position = ObjectProperty(None) '''(internal) Used to store the current textinput from the popup and to listen for changes. :attr:`textinput` is an :class:`~kivy.properties.ObjectProperty` and defaults to None. ''' pic = StringProperty() position = StringProperty('50*50') def __init__(self, **kwargs): super(SettingPos, self).__init__(**kwargs) self.img = Image(source=self.pic) def on_panel(self, instance, value): if value is None: return self.bind(on_release=self._create_popup) def _dismiss(self, *largs): if self.popup: self.popup.dismiss() self.popup = None def _register(self, instance, touch): if self.img.collide_point(*touch.pos): # self.position = '*'.join([str(p) for p in touch.pos]) # print(touch) # print(self.img.pos) # print(self.img.size) # print(Window.size) x, y = self.img.to_widget(touch.pos[0], touch.pos[1], True) x = x - self.img.pos[0] - 20.0 y = y + 68.0 # print('%s * %s' % (x, y)) self.position = str(x) + '*' + str(y) def _validate(self, instance): value = self.position self.value = value # print(self.value) self._dismiss() def _create_popup(self, instance): # create popup layout content = BoxLayout(orientation='vertical', spacing='5dp') # popup_width = min(0.95 * Window.width, dp(500)) self.popup = popup = Popup( title=self.title, content=content) pos = [float(c) for c in self.value.split('*')] scat = ScatterCross(size=(20, 20), size_hint=(None, None), pos=pos) scat.bind(on_touch_up=self._register) self.img.add_widget(scat) content.add_widget(self.img) content.add_widget(SettingSpacer()) # 2 buttons are created for accept or cancel the current value btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp') btn = Button(text='Ok') btn.bind(on_release=self._validate) btnlayout.add_widget(btn) btn = Button(text='Cancel') btn.bind(on_release=self._dismiss) btnlayout.add_widget(btn) content.add_widget(btnlayout) # all done, open the popup ! popup.open()
class MainScreen(AppScreen, BoxLayout): __background = None # type: Widget __time = None # type: Label __date = None # type: Label def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.__background = Image() self.__background.color = [1, 1, 1, 1] self.add_widget(self.__background) self.__time = Label() self.__time.text = "12:00" self.__time.font_size = 200 self.__time.pos = (337, 225) self.__time.color = [0, 0, 0, 1] self.__background.add_widget(self.__time) self.__date = Label() self.__date.text = "Sat 13.02.2016" self.__date.font_size = 50 self.__date.pos = (337, 100) self.__date.color = [0, 0, 0, 1] self.__background.add_widget(self.__date) TimeManager.instance.register_time_listener(self.__timemanager_timechanged) TimeManager.instance.register_date_listener(self.__timemanager_datechanged) def _on_resize(self): pass def update_time(self, hours: int, minutes: int): string = "" if hours < 10: string += "0" string += str(hours) + ":" if minutes < 10: string += "0" string += str(minutes) self.__time.text = string def update_date(self, weekday: str, day: int, month: int, year: int): self.__date.text = weekday + " " + str(day) + "." + str(month) + "." + str(year) def on_set(self): pass def on_unset(self): pass def __timemanager_timechanged(self, hours: int = None, minutes: int = None, seconds: int = None): self.update_time(hours, minutes) def __timemanager_datechanged(self, year: int = None, month: int = None, day: int = None, weekday: int = None): wd = "" if weekday == 0: wd = "Mon" elif weekday == 1: wd = "Tue" elif weekday == 2: wd = "Wed" elif weekday == 3: wd = "Thu" elif weekday == 4: wd = "Fri" elif weekday == 5: wd = "Sat" elif weekday == 6: wd = "Sun" self.update_date(wd, day, month, year)
class CoatiraneAdventures(App): title = f'Coatirane Adventures - {GAME_VERSION}' def __init__(self, *args, **kwargs): Window.bind(on_resize=self.on_resize) Window.bind(on_request_close=self.close_window) Window.bind(on_memorywarning=self.on_memory_warning) self._keyboard = None self._keycode = None self._bind_keyboard() # Builder.load_file('Game.kv') self._size = Window.size self.ratios = None self._background = None self._loader = None self._screen_manager = None self._popup_manager = PopupManager() self.use_kivy_settings = False self.width, self.height = self._size self.x, self.y = 0, 0 self._end_screen = 'town_main' self._content = GameContent(PROGRAM_TYPE) Refs.gc = self._content Refs.gp = self._popup_manager Refs.log = self.log Refs.app = self self.settings_cls = Settings self._keyboard_bindings = {'on_key_up': [], 'on_key_down': []} super().__init__(**kwargs) self.initialized = False def _bind_keyboard(self): self.log('The keyboard has been bound!') self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self._keyboard.bind(on_key_up=self._on_keyboard_up) def _keyboard_closed(self): self.log('The keyboard has been closed!') self._keyboard.unbind(on_key_down=self._on_keyboard_down) self._keyboard.unbind(on_key_up=self._on_keyboard_up) self._keyboard = None def map_key_name(self, code): if code == '': return key_name = None if code in ('w', 'up'): key_name = 'move_up' elif code in ('a', 'left'): key_name = 'move_left' elif code in ('s', 'down'): key_name = 'move_down' elif code in ('d', 'right'): key_name = 'move_right' elif code in ('m', ): key_name = 'map' elif code in ('o', ): key_name = 'options' elif code in ('i', ): key_name = 'inventory' elif code in ('esc', ): key_name = 'pause' elif code in ('q', ): key_name = 'secondary_action_1' elif code in ('e', ): key_name = 'secondary_action_2' elif code in ('f', ): key_name = 'primary_action' elif code in ('f12', ): key_name = 'screenshot' return key_name def take_screenshot(self): path = expanduser( '~/Saved Games/Coatirane Adventures/screenshots/').replace( '\\', '/') if not exists(path): mkdir(path) Window.screenshot( f'{path}Coatirane Adventures - {datetime.now().strftime("%d-%m-%Y %H-%M-%S")}.png' ) def _on_keyboard_down(self, keyboard, keycode, text, modifiers): if self._keycode != keycode: self._keycode = keycode Refs.log(f'Key was pressed - {keycode}') key_name = self.map_key_name(keycode[1]) if key_name is not None: if key_name == 'screenshot': self.take_screenshot() else: for callback in self._keyboard_bindings['on_key_down']: callback(keyboard, key_name, text, modifiers) def _on_keyboard_up(self, keyboard, keycode): self._keycode = None key_name = self.map_key_name(keycode[1]) if key_name == 'screenshot' or key_name is None: return for callback in self._keyboard_bindings['on_key_up']: callback(keyboard, key_name) def bind_keyboard(self, **kwargs): self.log(f'Add binding for master keyboard') for key, callback in kwargs.items(): self._keyboard_bindings[key].append(callback) def unbind_keyboard(self, **kwargs): self.log(f'Remove binding for master keyboard') for key, callback in kwargs.items(): self._keyboard_bindings[key].remove(callback) def log(self, message, level='info', tag='CoatiraneAdventures'): Logger.log({ 'info': 20, 'warn': 30, 'debug': 10, 'error': 40 }[level], f"{tag}: {message}") def to_window(self, x, y): return x, y def build(self): self.log('loading the starting game window') self._background = Image(source="game_bounds.png", allow_stretch=True) self.log('creating background loader') self._loader = CALoader(PROGRAM_TYPE) self._loader.load_base_values() self._loader.size = self._size self.ratios = self._loader.load_ratios() # self.background.add_widget(self.loader) self._screen_manager = Root(self) Refs.gs = self._screen_manager self._screen_manager.size = self._size self._background.add_widget(self._screen_manager) return self._background def start_loading(self, save_slot, finish_screen): self.log('Starting background loader') self._background.add_widget(self._loader) self._screen_manager.opacity = 0 self._end_screen = finish_screen Refs.gc.set_save_slot(save_slot) Clock.schedule_once(lambda dt: self._loader.load_game(save_slot), 0) def finished_loading(self): self.log('Finished Loading') self._background.remove_widget(self._loader) self._screen_manager.display_screen(self._end_screen, True, False) self._screen_manager.opacity = 1 def reset_loader(self): self._loader.reset() def get_manager(self): return self._screen_manager # def add_manager(self, manager): # self._screen_manager = manager # manager.size = self.width, self.height # # def set_manager(self): # self._background.add_widget(self._screen_manager) def allow_sleep(self): Window.allow_screensaver = True def deny_sleep(self): Window.deny_screensaver = True def close_window(self, *args): self.log('Save Game') self.log('Closing the window') if platform == 'win': Window.close() def on_memory_warning(self): self.log('received memory warning') # The game may or may not return from a pause. def on_pause(self): self.log('game paused') if platform == 'win': return True else: return True def exit_game(self): self.stop() def on_resize(self, *args): Clock.unschedule(self.fix_size) Clock.schedule_once(self.fix_size, .25) def get_content(self): return self._content def make_windowed(self): Window.fullscreen = 0 Window.borderless = 0 w, h = int(Config.get('graphics', 'width')), int(Config.get('graphics', 'height')) sw, sh = int(Config.get('graphics', 'screen_width')), int( Config.get('graphics', 'screen_height')) if w == sw and h == sh: w, h = int(w * 2 / 3), int(h * 2 / 3) l, t = int(sw / 2 - w / 2), int(sh / 2 - h / 2) Window.left = l Window.top = t Config.set('graphics', 'width', int(w)) Config.set('graphics', 'height', int(h)) Config.set('graphics', 'left', l) Config.set('graphics', 'top', t) Config.write() Window.size = w, h self.log(f'Window size is {w}x{h}') self.width, self.height = w, h def make_fake_fullscreen(self): Window.fullscreen = 0 Window.borderless = 1 Window.pos = 0, 0 Window.left = 0 Window.top = 0 width, height = int(Config.get('graphics', 'screen_width')), int( Config.get('graphics', 'screen_height')) Config.set('graphics', 'width', width) Config.set('graphics', 'height', height) Config.set('graphics', 'left', 0) Config.set('graphics', 'top', 0) Config.write() Window.size = width, height self.width, self.height = width, height def fix_size(self, *args): if self._size == Window.size: return self._size = Window.size self._background.size = Window.size offset = self._background.width / 2 - self._background.norm_image_size[ 0] / 2, self._background.height / 2 - self._background.norm_image_size[ 1] / 2 if self._loader: self._loader.size = self._background.norm_image_size self._loader.pos = offset #if self.initialized: self._screen_manager.size = self._background.norm_image_size self._screen_manager.pos = offset def get_dkey(self, key, x=None, y=None, z=None, w=None, t=None, u=None): # This is to get a ratio. All ratios will be designed at res 1706 x 960 # This function will get the ratios for 1x and scale them up or down if needed dict_key, v = key.split(' ') d = self.ratios for k in dict_key.split('.'): d = d.get(k) if v == 'p_h': # print(d['p_h']) values = d['p_h'] for key in values.keys(): if not isinstance(values[key], float) and not isinstance( values[key], int): values[key] = eval(values[key].format(x=x, y=y, z=z, w=w, t=t, u=u)) return values elif v == 's' or v == 'p': return eval(d[v + '_x'].format(x=x, y=y, z=z, w=w, t=t, u=u)), eval(d[v + '_y'].format(x=x, y=y, z=z, w=w, t=t, u=u)) else: return eval(d[v].format(x=x, y=y, z=z, w=w, t=t, u=u))
class View(App): WINDOW_WIDTH = 800 WINDOW_HEIGHT = 600 def __init__(self, controller, **kwargs): self.controller = controller super(View, self).__init__(**kwargs) def build(self): self.dni = True self.startPicker = None self.endPicker = None self.cosine = False self.path = None self.fileName = None self.progressPopupDescription = None print "Building Main Window" layout = BoxLayout(orientation='vertical') topBarLayout = BoxLayout(orientation='horizontal') mapWidget = self._generateMap() topBarLayout.add_widget(mapWidget) layout.add_widget(topBarLayout) self.label = Label(text="Use the pin above to select a latitude and longitude.") self.progressBar= ProgressBar(max=1) bottomLeftBox = BoxLayout(orientation='vertical') bottomLeftBox.add_widget(self.label) # bottomLeftBox.add_widget(self.progressBar) bottomLeftBox.add_widget(self._generateExportButton()) bottomLeftBox.add_widget(self._generateExportGHIButton()) # bottomLeftBox.add_widget(self._generateHeatmapButton()) # bottomLeftBox.add_widget(self._generateRunSimulationButton()) self.bottomBarLayout = BoxLayout(size_hint=(1,0.5)) self.bottomBarLayout.add_widget(bottomLeftBox) self.bottomBarLayout.add_widget(self._generateDatetimePicker()) layout.add_widget(self.bottomBarLayout) return layout def updateProgressBar(self, progress): if self.progressBar is not None: self.progressBar.value = progress if self.progressPopupDescription is not None: self.progressPopupDescription.text = "Generating ("+str(round(progress * 1000)/10.0) + " %)" def _generateDatetimePicker(self): layout = BoxLayout(orientation='vertical') startDatetime = self.controller.getSolarStartDatetime() endDatetime = startDatetime + datetime.timedelta(days=7) #create new datetime objects because we need timezone-naive versions for the datetimepicker class. startDatetime = datetime.datetime(year=startDatetime.year, month=startDatetime.month, day=startDatetime.day, hour=startDatetime.hour, minute=startDatetime.minute, tzinfo=None) endDatetime = datetime.datetime(year=endDatetime.year, month = endDatetime.month, day = endDatetime.day, hour = endDatetime.hour, minute=endDatetime.minute, tzinfo = None) self.startPicker = FlexiDatetimePicker(density=3, initialDatetime= startDatetime) self.endPicker = FlexiDatetimePicker(density = 3, initialDatetime = endDatetime) startLabel = Label(text="Choose Start Date") endLabel = Label(text="Choose End Date") layout.add_widget(startLabel) layout.add_widget(self.startPicker) layout.add_widget(endLabel) layout.add_widget(self.endPicker) return layout def displayErrorMessage(self,message="default"): print "Building Popup" button = Button(text="Close") label = Label(text=message) layout= BoxLayout(orientation='vertical') layout.add_widget(label) layout.add_widget(button) popup = Popup(title="Error",content=layout,size_hint=(None, None), size=(400, 400)) button.bind(on_press=lambda widget:popup.dismiss()) popup.open() print "Popup Opened." def _on_checkbox_active(self,checkbox, value): if value: self.cosine = True else: self.cosine = False def _displayHeatmapGenerationPopup(self, press): print "Building Heatmap Generation Box" self.progressPopupDescription = Label(text = "Generating Heatmaps can take a long time. \nAre you sure you want to do this?") self.heatmapButton = Button(text="Generate") self.heatmapButton.bind(on_press=self._generateHeatmap) checkbox = CheckBox() checkbox.bind(active=self._on_checkbox_active) cancelButton = Button(text="Cancel") layout = BoxLayout(orientation='vertical') layout.add_widget(self.progressPopupDescription) layout.add_widget(self.heatmapButton) layout.add_widget(checkbox) layout.add_widget(cancelButton) layout.add_widget(self.progressBar) popup = Popup(title="Heatmap", content = layout, size_hint=(None, None), size = (400,400)) cancelButton.bind(on_press = lambda widget:self._cancelHeatmapGeneration(popup)) popup.open() self.heatmapPopup = popup print "Heatmap Generation Box Generated" def _generateHeatmap(self, touch): startDate = self.startPicker.getSelectedDatetime() endDate = self.endPicker.getSelectedDatetime() self.controller.beginGeneratingHeatmapData(startDate, endDate, cosine = self.cosine) if self.heatmapButton is not None and self.heatmapPopup is not None and self.progressPopupDescription is not None: self.heatmapPopup.content.remove_widget(self.heatmapButton) self.heatmapButton = None self.progressPopupDescription.text = "Generating Heatmap..." def _cancelHeatmapGeneration(self, popup): popup.dismiss() popup.clear_widgets() self.progressBar.parent = None self.progressBar.value = 0 self.heatmapPopup = None self.heatmapButton = None self.progressPopupDescription = None self.controller.cancelHeatmapGeneration() def _generateMap(self): layout = RelativeLayout() self.mapImg=Image(source='resources/images/map.png',allow_stretch = True, keep_ratio = False) self.mapPin = MapPin( parent=self.mapImg,view = self,allow_stretch = False, source='resources/images/pin.png', size=(20,34)) self.mapImg.add_widget(self.mapPin) layout.add_widget(self.mapImg) print "Scheduling." # Clock.schedule_interval(self._updateMapImg, 2) Clock.schedule_interval(self._timeseriesGenerated, 2) return layout def _imageLoaded(self, proxyImage): if proxyImage.image.texture: self.mapImg.texture = proxyImage.image.texture def _timeseriesGenerated(self, timeInterval): finished = self.controller.saveTimeseriesIfDataGenerated() if finished: self._dismissPopup() def _generateExportButton(self): exportButton = Button(text='Export DNI as CSV') exportButton.bind(on_press = self._getSavePath) return exportButton def _generateExportGHIButton(self): exportButton = Button(text='Export GHI as CSV') exportButton.bind(on_press = self._getGHISavePath) return exportButton def _generateRunSimulationButton(self): simButton = Button(text="Run Simulation") simButton.bind(on_press=self._chooseSimulation) return simButton def _chooseSimulation(self, press): info = Label(text="Please select a simulation from the following options.") solarMarketButton = Button(text="Solar w/ Market Prices") solarPPAButton = Button(text="Solar w/ PPA") solarPPAButton.bind(on_press=self._solarPPASimOptions) solarPortfolioButton = Button(text="Solar with Contract Portfolio") batteryMarketButton = Button(text="Batteries with Market Trading Only") batteryPortfolioButton = Button(text="Batteries with Contract Portfolio") layout = BoxLayout(orientation="vertical") layout.add_widget(info) layout.add_widget(solarMarketButton) layout.add_widget(solarPPAButton) layout.add_widget(solarPortfolioButton) layout.add_widget(batteryMarketButton) layout.add_widget(batteryPortfolioButton) self.simulationPopup = Popup(title="Run Simulation", content=layout, size_hint=(0.9, 0.9)) self.simulationPopup.open() def _solarPPASimOptions(self, press): if self.simulationPopup is not None: self.simulationPopup.title = "Solar Plant with PPA Simulation" contents = self.simulationPopup.content contents.clear_widgets() location = Label(text="Location = Lat: "+str(round(self.getSelectedLatitude() * 1000)/1000.0)+" Lon: "+str(round(self.getSelectedLongitude() * 1000)/1000.0)) contents.add_widget(location) startDate = Label(text="Start Date: "+str(self.startPicker.getSelectedDatetime())) contents.add_widget(startDate) endDate = Label(text="End Date: "+str(self.endPicker.getSelectedDatetime())) contents.add_widget(endDate) sizeMWLabel=Label(text="Enter Plant Nameplate Capacity (MW):") contents.add_widget(sizeMWLabel) self.sizeMWInput = TextInput(text='1', multiline=False) contents.add_widget(self.sizeMWInput) runSimButton = Button(text="Run Simulation") runSimButton.bind(on_press=self._runSolarPPASim) contents.add_widget(runSimButton) def _runSolarPPASim(self, press): if self.sizeMWInput is not None: namePlateMW = float(self.sizeMWInput.text) startDate = self.startPicker.getSelectedDatetime() endDate = self.endPicker.getSelectedDatetime() lat = self.getSelectedLatitude() lon = self.getSelectedLongitude() state = "nsw" data = self.controller.runSolarPPASimulation(state, startDate, endDate, lat, lon, namePlateMW) self._displaySolarSimulationResults(data) def _displaySolarSimulationResults(self, data): self.simulationPopup.title = "Results" self.simulationPopup.content.clear_widgets() def _generateHeatmapButton(self): heatmapButton = Button(text="Generate Heatmap") heatmapButton.bind(on_press=self._displayHeatmapGenerationPopup) return heatmapButton def getDatabasePath(self): # return "/Volumes/SOLAR/data.hdf5" return "./test.hdf5" def getFolderPath(self): return "./testFiles" def displayImage(image): image.show() def changeXY(self,x,y): labelText = "Current Location - Lat : "+str(round(1000*x)/1000.0) + " Long:" + str(round(1000*y)/1000.0) self.label.text = labelText def _getSavePath(self, touch): self.dni = True if self.controller.checkDatesValid(self.getSelectedStartDate(), self.getSelectedEndDate()): saveDialog = SaveDialog(save=self._save, cancel=self._dismissPopup) self._popup = Popup(title="Save file", content=saveDialog, size_hint=(0.9, 0.9)) self._popup.open() else: self.displayErrorMessage("Selected start and end dates not valid.") def _getGHISavePath(self, touch): self.dni = False if self.controller.checkDatesValid(self.getSelectedStartDate(), self.getSelectedEndDate()): saveDialog = SaveDialog(save=self._save, cancel=self._dismissPopup) self._popup = Popup(title="Save file", content=saveDialog, size_hint=(0.9, 0.9)) self._popup.open() else: self.displayErrorMessage("Selected start and end dates not valid.") def _showProgressPopup(self): content = BoxLayout(orientation = 'vertical') self.progressPopupDescription= Label(text = "0 %") content.add_widget(self.progressPopupDescription) content.add_widget(self.progressBar) self._popup = Popup(title="Progress:", content = content, size_hint=(0.5,0.5), auto_dismiss=False) self._popup.open() def _dismissPopup(self): try: self.progressBar= ProgressBar(max=1) self._popup.clear_widgets() self._popup.dismiss() except AttributeError: print "No popup to close!" def _save(self, path, fileName): pattern = ".*\/.*" # regex = re.compile(pattern) if re.match(pattern, fileName): #If we find the filename is a directory, do nothing. path = fileName else: #otherwise join path and filename. path = path + "/"+ fileName self._dismissPopup() print "Popup dismissed" self._showProgressPopup() self.controller.exportTimeseries(path, self.dni) def getSelectedStartDate(self): if self.startPicker: return self.startPicker.getSelectedDatetime() else: return self.controller.getSolarStartDatetime() def getSelectedEndDate(self): if self.endPicker: return self.endPicker.getSelectedDatetime() else: return self.controller.getSolarEndDatetime() def getSelectedLatitude(self): return self.mapPin.getLatLong()[0] def getSelectedLongitude(self): return self.mapPin.getLatLong()[1] def reportWriteFinished(self): self._dismissPopup()
class RLMapWidget(RelativeLayout, Listener): """ Game map widget. Mostly is busy displaying character widgets and such. Assumes that its parent has the following attributes: self.parent.boombox a dict of SoundLoader instances with correct sounds """ # A list of events that should be ignored by the animation system # 'queue_exhausted' is not included here as self.process_game_event() processes it separately non_animated = {'log_updated', 'inventory_updated', 'hp_changed', 'ammo_changed'} def __init__(self, map=None, **kwargs): super(RLMapWidget, self).__init__(**kwargs) # Connecting to map, factories and other objects this class should know about self.tile_factory = TileWidgetFactory() self.map = map self.size = [self.map.size[0]*32, self.map.size[1]*32] # Adding LayerWidgets for every layer of the map self.layer_widgets = {} for layer in self.map.layers: self.layer_widgets.update({layer: LayerWidget(layer=layer, parent=self)}) self.add_widget(self.layer_widgets[layer]) # This is set to True during animation to avoid mistakes self.animating = False # Queue of GameEvents to be animated self.animation_queue = [] # A temporary widget slot for stuff like explosions, spell effects and such self.overlay_widget = None # Debugging Dijkstra map view if DISPLAY_DIJKSTRA_MAP: self.dijkstra_widget = None # self.dijkstra_widget = DijkstraWidget(parent=self) # self.add_widget(self.dijkstra_widget) self.counter = 0 ######################################################### # # Stuff related to animation # ########################################################## def process_game_event(self, event): """ Process a GameEvent passed by queue :param event: GameEvent :return: """ if event.event_type == 'queue_exhausted': # Shoot animations only after the entire event batch for the turn has arrived # Better to avoid multiple methods messing with self.animation_queue simultaneously self.animate_game_event() # Ignore non-animatable events else: self.animation_queue.append(event) def animate_game_event(self, widget=None, anim_duration=0.2): """ Process a single event from self.animation_queue Read the event and perform the correct actions on widgets (such as update text of log window, create and launch animation, maybe make some sound). The event is removed from self.map.game_events. After the actions required are performed, the method calls itself again, either recursively, or, in case of animations, via Animation's on_complete argument. The recursion is broken when event queue is empty. :return: """ if widget and widget.parent and widget.height == 0: # If the widget was given zero size, this means it should be removed # This entire affair is kinda inefficient and should be rebuilt later widget.parent.remove_widget(widget) if not self.animation_queue == []: event = self.animation_queue.pop(0) if event.event_type == 'moved': final = self.get_screen_pos(event.actor.location, center=True) if final[0] < event.actor.widget.pos[0] and event.actor.widget.direction == 'right'\ or final[0] > event.actor.widget.pos[0] and event.actor.widget.direction == 'left': event.actor.widget.flip() a = Animation(center=final, duration=anim_duration) a.bind(on_start=lambda x, y: self.remember_anim(), on_complete=lambda x, y: self.animate_game_event(widget=y)) a.start(event.actor.widget) elif event.event_type == 'attacked': current = self.get_screen_pos(event.actor.location, center=True) target = self.get_screen_pos(event.location, center=True) if target[0] > current[0] and event.actor.widget.direction == 'left' or\ target[0] < current[0] and event.actor.widget.direction == 'right': event.actor.widget.flip() a = Animation(center_x=current[0]+int((target[0]-current[0])/2), center_y=current[1]+int((target[1]-current[1])/2), duration=anim_duration/2) a += Animation(center_x=current[0], center_y=current[1], duration=anim_duration/2) a.bind(on_start=lambda x, y: self.remember_anim(), on_complete=lambda x, y: self.animate_game_event(widget=y)) a.start(event.actor.widget) self.parent.boombox['attacked'].seek(0) self.parent.boombox['attacked'].play() elif event.event_type == 'was_destroyed': if not event.actor.widget: # If actor is None, that means it was destroyed right after spawning, not getting a # widget. Similar case is covered under 'dropped', see there for example. The check is # different here, because in 'dropped' item is taken from map, where it's None by the time # this method runs. Here, on the other hand, Item object exists (in GameEvent), but has # no widget (and is not placed on map, but that's irrelevant). self.animate_game_event() return a = Animation(size=(0, 0), duration=anim_duration) a.bind(on_start=lambda x, y: self.remember_anim(), on_complete=lambda x, y: self.animate_game_event(widget=y)) a.start(event.actor.widget) elif event.event_type == 'picked_up': # It's assumed that newly added item will be the last in player inventory self.layer_widgets['items'].remove_widget(self.map.actors[0].inventory[-1].widget) self.animate_game_event() elif event.event_type == 'dropped': item = self.map.get_item(location=event.location, layer='items') if not item: # Item could've been destroyed right after being drop, ie it didn't get a widget. Skip. # It's rather likely if someone was killed by landmine, dropped an item and had this item # destroyed in the same explosion self.animate_game_event() return if not item.widget: self.tile_factory.create_widget(item) item.widget.center = self.get_screen_pos(event.location, center=True) self.layer_widgets['items'].add_widget(item.widget) self.animate_game_event() elif event.event_type == 'actor_spawned': if not event.actor.widget: self.tile_factory.create_widget(event.actor) event.actor.widget.center = self.get_screen_pos(event.location, center=True) self.layer_widgets['actors'].add_widget(event.actor.widget) self.animate_game_event() elif event.event_type == 'construction_spawned': if not event.actor.widget: self.tile_factory.create_widget(event.actor) event.actor.widget.center = self.get_screen_pos(event.location, center=True) self.layer_widgets['constructions'].add_widget(event.actor.widget) self.animate_game_event() elif event.event_type == 'exploded': loc = self.get_screen_pos(event.location) loc = (loc[0]+16, loc[1]+16) self.overlay_widget = Image(source='Explosion.png', size=(0, 0), size_hint=(None, None), pos=loc) a = Animation(size=(96, 96), pos=(loc[0]-32, loc[1]-32), duration=0.3) a += Animation(size=(0, 0), pos=loc, duration=0.3) a.bind(on_start=lambda x, y: self.remember_anim(), on_complete=lambda x, y: self.animate_game_event(widget=y)) self.add_widget(self.overlay_widget) self.parent.boombox['exploded'].seek(0) self.parent.boombox['exploded'].play() a.start(self.overlay_widget) elif event.event_type == 'rocket_shot': self.overlay_widget = RelativeLayout(center=self.get_screen_pos(event.actor.location, center=True), size=(64,64), size_hint=(None, None)) i = Image(source='Rocket.png', size=(32, 32), size_hint=(None, None)) self.overlay_widget.add_widget(i) self.overlay_widget.canvas.before.add(Translate(x=16, y=16)) a = degrees(atan2(event.actor.location[1]-event.location[1], event.actor.location[0]-event.location[0])) # if abs(a) >= 90: # self.overlay_widget.center_y += 64 self.overlay_widget.canvas.before.add(Rotate(angle=a+90, axis=(0, 0, 1), origin=i.center)) a = Animation(center=self.get_screen_pos(event.location, center=True), duration=anim_duration) a += Animation(size=(0, 0), duration=0) a.bind(on_start=lambda x, y: self.remember_anim(), on_complete=lambda x, y: self.animate_game_event(widget=y)) self.add_widget(self.overlay_widget) a.start(self.overlay_widget) elif event.event_type == 'shot': self.overlay_widget = Image(source='Shot.png', size=(32, 32), size_hint=(None, None), pos=self.get_screen_pos(event.actor.location)) a = Animation(pos=self.get_screen_pos(event.location), duration=anim_duration) a += Animation(size=(0, 0), duration=0) a.bind(on_start=lambda x, y: self.remember_anim(), on_complete=lambda x, y: self.animate_game_event(widget=y)) self.add_widget(self.overlay_widget) self.parent.boombox['shot'].seek(0) self.parent.boombox['shot'].play() a.start(self.overlay_widget) elif event.event_type in self.non_animated: self.parent.process_nonmap_event(event) self.animate_game_event() else: # Reactivating keyboard after finishing animation self.animating = False # Might as well be time to redraw the Dijkstra widget if DISPLAY_DIJKSTRA_MAP: if self.dijkstra_widget: self.remove_widget(self.dijkstra_widget) # else: # self.map.dijkstras['PC'].rebuild_self() self.dijkstra_widget = DijkstraWidget(parent=self) self.add_widget(self.dijkstra_widget) def remember_anim(self): ''' This is a separate method because lambdas cannot into assignment, and animation queue depends on lambdas not to be evaluated prematurely. :return: ''' self.animating = True def get_screen_pos(self, location, parent=False, center=False): """ Return screen coordinates (in pixels) for a given location. Unless window parameter is set to true, returns coordinates relative to self :param location: int tuple :param parent: bool If true, return parent coordinates. :param center: bool. If True, return coordinates for tile center, otherwise return bottom-left corner :return: int tuple """ r = [location[0]*32, location[1]*32] if center: r[0] += 16 r[1] += 16 if not parent: return r else: return self.to_parent(r[0], r[1]) def update_rect(self, pos, size): self.rect.pos = self.pos self.rect.size = self.size
class CustomLayout(FloatLayout): def __init__(self, **kwargs): # suprascrierea initului vechi din modul super(CustomLayout, self).__init__(**kwargs) # var muzica_activa este o definita in acest namespace pt a avea efect in dezactivarea_volumului self.muzica_activa = 0 # obiectul layout0 este de tipul FloatLayout() self.layout0 = FloatLayout() # setam atributul source al obiect imag1 self.imag1 = Image(source="fundal.jpg") # adaugam fundalul ca si widget self.add_widget(self.imag1) # setam atributele layout0 self.layout0.size = (600, 500) self.layout0.size_hint = (None, None) self.layout0.padding = 200 self.imag1.add_widget(self.layout0) # incarcam widgetul SoundLoader si atributele sale self.sound = SoundLoader.load('And_So_YouCode Rap_Tarzi.wav') self.sound.play() self.sound.loop = True self.sound.volume = 0.5 # anulam functionalitatile cu care vine metoda self.Menu(None) def Menu(self, Buton): # am curatat layoutul self.layout0.clear_widgets() # creare but1 si atributelor sale self.but1 = Button(text="Carusel", bold=True, background_color=(0, 0, 1, 1)) self.but1.pos = (300, 380) self.but1.size_hint = (0.3, 0.1) self.but1.opacity = 0.7 #adaugarea ca si widget a but1 pe layout0 self.layout0.add_widget(self.but1) # creare but2 si atributelor sale self.but2 = Button(text="Optiuni", bold=True, background_color=(0, 0, 1, 1)) self.but2.pos = (300, 300) self.but2.size_hint = (0.3, 0.1) self.but2.opacity = 0.7 self.layout0.add_widget(self.but2) # creare but3 si atributelor sale self.but3 = Button(text="About", bold=True, background_color=(0, 0, 1, 1)) self.but3.pos = (300, 220) self.but3.size_hint = (0.3, 0.1) self.but3.opacity = 0.7 self.layout0.add_widget(self.but3) # creare but4 si atributelor sale self.but4 = Button(text="Iesi", bold=True, background_color=(0, 0, 1, 1)) self.but4.pos = (300, 140) self.but4.size_hint = (0.3, 0.1) self.but4.opacity = 0.7 self.layout0.add_widget(self.but4) # se leaga evenimentele de apasare a butoanelor de metodele de mai jos self.but1.bind(on_press=self.CatreCarusel) self.but2.bind(on_press=self.Optiuni) self.but3.bind(on_press=self.About) self.but4.bind(on_press=self.Iesi) def CatreCarusel(self, Buton): # am curatat layoutul self.layout0.clear_widgets() # am adaptat programul din clasa folosind obiecte dar nu merge # setam directia in care vom misca cu mouse-ul imaginile self.carousel = Carousel(direction='right') # setam viteza de miscare self.carousel.anim_move_duration = 1 self.carousel.loop = True self.carousel.size_hint = (0.7, 0.7) self.carousel.pos = (200, 120) self.carousel.add_widget(self.layout0) self.image1 = Image(source="nature1.jpg") self.carousel.add_widget(self.image1) self.image2 = Image(source="nature2.jpg") self.carousel.add_widget(self.image2) self.image3 = Image(source="nature3.jpg") self.carousel.add_widget(self.image3) self.image1 = Image(source="nature4.jpg") self.carousel.add_widget(self.image4) self.eticheta_final = Label(text="Am ajuns la finalul listei!", font_size=30) self.carousel.add_widget(self.eticheta_final) # cream widgetul inapoiButon self.inapoiButon = Button(text="Inapoi", bold=True, background_color=(0, 0, 1, 1)) self.inapoiButon.pos = (200, 100) self.inapoiButon.size_hint = (0.7, 0.1) self.inapoiButon.opacity = 0.7 self.layout0.add_widget(self.inapoiButon) #legam apasarea butonului de intoarcerea la meniul principal self.inapoiButon.bind(on_press=self.Menu) def Optiuni(self, Buton): self.layout0.clear_widgets() # Cream un widget Switch si atributele sale self.switch1 = Switch(text="muzica") self.switch1.active = True self.switch1.size_hint = (0.3, 0.2) self.switch1.pos = (300, 360) self.layout0.add_widget(self.switch1) # leaga Switch-ul de metoda dezactiveaza_volum self.switch1.bind(active=self.dezactiveaza_volum) # cream un widget Label si atributele sale # textul de pe acesta urmand sa se schimbe odata cu volumul self.arata_volum = Label(text="volum: 50") self.arata_volum.size_hint = (0.3, 0.1) self.arata_volum.pos = (300, 260) self.layout0.add_widget(self.arata_volum) # cream un widget Slider si atributele sale # nu am urmat exact indicatiile din cerinta pt. a crea atributele # am incercercat sa fac fereastra sa semene cu poza self.slide_muzica = Slider(min=0, max=100, value=50) self.slide_muzica.step = 5 self.slide_muzica.pos = (300, 100) self.slide_muzica.size_hint = (0.3, 0.5) self.slide_muzica.orientation = "horizontal" self.layout0.add_widget(self.slide_muzica) # leaga Slider-ul de metoda valoare_volum self.slide_muzica.bind(value=self.valoare_volum) # crearea widgetu-lui inapoiButon si atributelor sale self.inapoiButon = Button(text="Inapoi", bold=True, background_color=(0, 0, 1, 1)) self.inapoiButon.pos = (300, 120) self.inapoiButon.size_hint = (0.3, 0.1) self.inapoiButon.opacity = 0.7 self.layout0.add_widget(self.inapoiButon) # legam apasarea butonului de intoarcerea la meniul principal self.inapoiButon.bind(on_press=self.Menu) def Iesi(self, Buton): # Apelam sys.exit() sys.exit() def valoare_volum(self, x, y): # modificam Labelul arata_volum aratand valoarea integer a slide-ului self.arata_volum.text = "volum: " + str(int(self.slide_muzica.value)) self.sound.volume = self.slide_muzica.value / 100 def dezactiveaza_volum(self, x, y): if (self.muzica_activa % 2 == 0): # slide-ul este dezactivat self.slide_muzica.disabled = True # stocam valoarea slidu-lui intr-o var temporara self.slide_muzica.value_temp = int(self.slide_muzica.value) # setam valorea volumului la 0 self.slide_muzica.value = 0 else: # facem slide-ul iar available self.slide_muzica.disabled = False # reluam volumul melodiei din variabila temporara self.slide_muzica.value = int(self.slide_muzica.value_temp) self.sound.play() # folosim aceasta variabila pt. a contoriza switch-ul self.muzica_activa += 1 def About(self, Buton): # crearea widgetu-lui inchide si atributelor sale self.inchide = Button(text="Inapoi", background_color=(0, 0, 1, 1)) self.inchide.pos = (300, 120) self.inchide.size_hint = (1, 0.1) # legam apasarea butonului de intoarcerea la meniul principal self.inchide.bind(on_press=self.inchide_popup) # cream Label self.eticheta = Label(text="Multumiri InfoAcademy", bold=True, font_size=24) self.layout1 = BoxLayout() self.layout1.orientation = "vertical" self.layout1.padding = 40 self.layout1.add_widget(self.eticheta) self.layout1.add_widget(self.inchide) self.popup = Popup() self.popup.background = "fundal4_tema.jpg" self.popup.size_hint = (None, None) self.popup.size = (400, 400) self.popup.title = 'Cine a creat aplicatia?' self.popup.content = self.layout1 self.popup.open() def inchide_popup(self, Buton): self.popup.dismiss()
class Juego(Screen): def __init__(self, **Kwargs): super(Juego, self).__init__(**Kwargs) self.orientation = "vertical" S = Image(source='imagenes/juego.jpeg', allow_stretch=True) self.add_widget(S) #añade la imagen al widget self.option = "" self.botones = [] self.my_box1 = FloatLayout(size=(300, 300)) labelTitle = Label(text='[color=000000] CENTINELA [/color]', markup=True, font_size="70dp", font_name="Times", size_hint=(0.3, 0.3), pos=(120, 450)) labelChat = Label(text='[color=000000] CHAT [/color]', markup=True, font_size="50dp", font_name="Times", size_hint=(0.3, 0.3), pos=(500, 450)) SP1 = Image(source='imagenes/moneda.png', size_hint=(0.2, 0.1), pos=(30, 370)) SP2 = Image(source='imagenes/moneda.png', size_hint=(0.2, 0.1), pos=(150, 370)) SP3 = Image(source='imagenes/moneda.png', size_hint=(0.2, 0.1), pos=(270, 370)) labelPunto1 = Label(text='[color=000000] ' + varg.getPuntos1() + '[/color]', markup=True, font_size="30dp", font_name="Times", size_hint=(0.3, 0.3), pos=(55, 350)) labelPunto2 = Label(text='[color=000000] ' + varg.getPuntos2() + '[/color]', markup=True, font_size="30dp", font_name="Times", size_hint=(0.3, 0.3), pos=(175, 350)) labelPunto3 = Label(text='[color=000000] ' + varg.getPuntos3() + '[/color]', markup=True, font_size="30dp", font_name="Times", size_hint=(0.3, 0.3), pos=(295, 350)) #Acción de iniciar self.btnIniciar = Button(text="INICIAR", font_size=85, size_hint=(0.5, 0.5), background_color=[0, 166, 0, 38], pos=(100, 30)) self.btnIniciar.bind(on_press=self.iniciar) #Acción de atacar self.btnAtacar = Button(text="Atacar", font_size=24, size_hint=(0.1, 0.1), background_color=[0, 1, 0.6, 0.8], pos=(100, 10)) self.btnAtacar.bind(on_press=self.changerA) #Acción de sumar self.btnSumar = Button(text="Sumar", font_size=24, size_hint=(0.1, 0.1), background_color=[0, 1, 0.6, 0.8], pos=(200, 10)) self.btnSumar.bind(on_press=self.changer) #Acción de Robar self.btnRobar = Button(text="Robar", font_size=24, size_hint=(0.1, 0.1), background_color=[0, 1, 0.6, 0.8], pos=(300, 10)) self.btnRobar.bind(on_press=self.changerR) self.labelPunto = Label(text='[color=000000] ' + varg.getPuntos() + '[/color]', markup=True, font_size="30dp", font_name="Times", size_hint=(0.3, 0.3), pos=(375, -10)) self.puntosImg = Image(source='imagenes/moneda.png', size_hint=(0.2, 0.1), pos=(350, 10)) #Chat self.messageInput = TextInput(size_hint=(0.2, 0.1), pos=(550, 10)) #Boton para enviar mensaje btn = Button(text="Enviar", font_size=24, size_hint=(0.1, 0.1), background_color=[0, 1, 0.6, 0.8], pos=(720, 10)) btn.bind(on_press=self.sendMessage) self.my_box1.add_widget(labelTitle) self.my_box1.add_widget(labelChat) self.my_box1.add_widget(self.messageInput) self.my_box1.add_widget(SP1) self.my_box1.add_widget(SP2) self.my_box1.add_widget(SP3) self.puntosImg.add_widget(self.labelPunto) self.puntosImg.add_widget(labelPunto1) self.puntosImg.add_widget(labelPunto2) self.puntosImg.add_widget(labelPunto3) self.my_box1.add_widget(btn) self.my_box1.add_widget(self.btnAtacar) self.my_box1.add_widget(self.btnRobar) self.my_box1.add_widget(self.btnSumar) self.my_box1.add_widget(self.puntosImg) self.my_box1.add_widget(self.btnIniciar) self.add_widget(self.my_box1) def sendMessage(self, btn): requestmsg = varg.getplayer_name() + " chat " + self.messageInput.text print(requestmsg) self.my_box1.remove_widget(self.messageInput) self.my_box1.add_widget(self.messageInput) s.sendall(requestmsg.encode()) def escucharTurno(self): while (varg.getturno() != varg.getplayer_name()): time.sleep(1) s.sendall(b'turno') data = s.recv(1024).decode() varg.setturno(data) print(data) print(varg.getturno()) self.my_box1.remove_widget(self.labelTurno) self.labelTurno = Label(text='[color=165B03] Es turno de: ' + varg.getprimerTurno() + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(120, 380)) self.my_box1.add_widget(self.labelTurno) self.my_box1.remove_widget(self.labelTurno) self.labelTurno = Label(text='[color=165B03] Es turno de: ' + varg.getprimerTurno() + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(120, 380)) self.my_box1.add_widget(self.labelTurno) def jugada(self, btn): print("boton", btn.text) if (self.option == "S"): print(varg.getnameTurno()) requestS = "S " + btn.text + " " + varg.getnameTurno() print(requestS) s.sendall(requestS.encode()) data = s.recv(1024).decode() print(requestS) print("respuesta de suma:", data) varg.setPuntos(data) # TODO: ACTUALIZAR LABEL DE PUNTOS self.puntosImg.remove_widget(self.labelPunto) self.labelPunto = Label(text='[color=000000] ' + varg.getPuntos() + '[/color]', markup=True, font_size="30dp", font_name="Times", size_hint=(0.3, 0.3), pos=(375, -10)) self.puntosImg.add_widget(self.labelPunto) print("antes de las cartas") misCartasAct = varg.getmisCartas() index = misCartasAct.index(btn.text) newarray = [] for carta in misCartasAct: if (index != misCartasAct.index(carta)): newarray.append(carta) varg.setmisCartas(newarray) print("mis cartas", varg.getmisCartas()) #self.escucharTurno() elif (self.option == "A"): namePlayer = self.Jugador.text orden = varg.getorden() indeP = orden.index(namePlayer) if (indeP == 0): elPlayer = "p1" elif (indeP == 1): elPlayer = "p2" elif (indeP == 2): elPlayer = "p3" elif (indeP == 3): elPlayer = "p4" requestA = "S" + " -" + btn.text + " " + elPlayer print(requestA) s.sendall(requestA.encode()) misCartas = varg.getmisCartas() index = misCartas.index(btn.text) newarray = [] for carta in misCartas: if (index != misCartas.index(carta)): newarray.append(carta) varg.setmisCartas(newarray) elif (self.option == "R"): requestS = "R" print("antes del for") for a in self.botones: self.my_box1.remove_widget(a) self.my_box1.add_widget(self.btnAtacar) self.my_box1.add_widget(self.btnRobar) self.my_box1.add_widget(self.btnSumar) def generarCartas(self, cartas): x = 30 y = 100 cont = 0 for a in cartas: self.btnC = Button(text=a, font_size=24, size_hint=(0.05, 0.08), background_color=[0, 1, 0.6, 0.8], pos=(x, y)) self.btnC.bind(on_press=self.jugada) self.my_box1.add_widget(self.btnC) self.botones.append(self.btnC) cont = cont + 1 if (cont < 7): x = x + 50 elif (cont == 7): y = 50 x = 30 else: x = x + 50 def threaded_msg(self): while True: time.sleep(1) data = s.recv(1024).decode() print(data) def iniciar(self, btn): self.my_box1.remove_widget(self.btnIniciar) jugadores = varg.getjugadores() labelPin = Label(text='[color=165B03] Estas en la sala: ' + varg.getnum() + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(120, 400)) self.labelTurno = Label(text='[color=165B03] Es turno de: ' + varg.getprimerTurno() + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(120, 380)) labelP1 = Label(text='[color=165B03] ' + jugadores[0] + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(-20, 270)) labelP2 = Label(text='[color=165B03] ' + jugadores[1] + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(110, 270)) labelP3 = Label(text='[color=165B03] ' + jugadores[2] + '[/color]', markup=True, font_size="20dp", font_name="Times", size_hint=(0.3, 0.3), pos=(220, 270)) self.my_box1.add_widget(labelPin) self.my_box1.add_widget(self.labelTurno) self.my_box1.add_widget(labelP1) self.my_box1.add_widget(labelP2) self.my_box1.add_widget(labelP3) #start_new_thread(self.threaded_msg, ()) def cartas(self): if (self.option == "A" or self.option == "R"): self.my_box1.remove_widget(self.btnCon) self.my_box1.remove_widget(self.Jugador) self.my_box1.remove_widget(self.labelJ) if (self.option == "A"): self.generarCartas(varg.getmisCartas()) elif (self.option == "R"): self.generarCartas([ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" ]) elif (self.option == "S"): self.generarCartas(varg.getmisCartas()) def changerAR(self): #Cambiar de pantalla self.my_box1.remove_widget(self.btnAtacar) self.my_box1.remove_widget(self.btnRobar) self.my_box1.remove_widget(self.btnSumar) self.labelJ = Label(text='[color=165B03] Jugador: [/color]', markup=True, font_size="30dp", font_name="Times", size_hint=(0.3, 0.3), pos=(10, 10)) self.my_box1.add_widget(self.labelJ) self.Jugador = TextInput(size_hint=(0.2, 0.1), pos=(40, 10)) self.btnCon = Button(text="continuar", font_size=24, size_hint=(0.17, 0.1), background_color=[0, 1, 0.6, 0.8], pos=(210, 15)) self.btnCon.bind(on_press=self.change) self.my_box1.add_widget(self.btnCon) self.my_box1.add_widget(self.Jugador) def changerA(self, btn): self.option = "A" self.changerAR() def changerR(self, btn): self.option = "R" self.changerAR() def change(self, btn): self.cartas() def changer(self, btn): #Cambiar de pantalla self.option = "S" self.my_box1.remove_widget(self.btnAtacar) self.my_box1.remove_widget(self.btnRobar) self.my_box1.remove_widget(self.btnSumar) self.cartas()
def CellPopup(gear, screen, character, main, button): fL = FloatLayout() name = Cards.Text("name", gear.name) type = Cards.Text("type", gear.type) text = Cards.Text("text", gear.definition) border = Image(source="GearCard.png", size_hint=(.85, .85), pos_hint={ "center_x": .5, "y": .13 }, allow_stretch=True) border.add_widget( Image(texture=name, pos=(295, 388), size=(220, 220), allow_stretch=True)) border.add_widget( Image(texture=type, pos=(295, 363), size=(220, 220), allow_stretch=True)) border.add_widget( Image(texture=text, pos=(278, 80), size=(250, 250), allow_stretch=True)) b4 = Button(size_hint=(.4, .1), pos_hint={ "center_x": .27, "y": .012 }, text="Discard") fL.add_widget(border) fL.add_widget(b4) popup = Popup(title='Card Viewer', content=fL, size_hint=(None, None), size=(410, 580)) b2 = Button(name="item", text=str(gear.quality), size_hint=(.05, .02), color=(0, 0, 0, 1), pos_hint={ "center_x": .81, "y": .195 }, background_color=(0, 0, 0, 0)) b5 = Button(size_hint=(.4, .1), pos_hint={ "center_x": .73, "y": .012 }, text="Use") fL.add_widget(b2) fL.add_widget(b5) qlt = gear.quality b2.bind(on_release=partial(Screens.WeaponPlusMinus, qlt, gear)) b5.bind(on_release=partial(UsePopup, gear, screen, popup, character, main)) b4.bind( on_release=partial(DiscardPopup, gear, screen, popup, character, main)) if screen.name == "confirm": b4.disabled = True b5.disabled = True popup.open()
class SpecialImage(AnchorLayout, ButtonBehavior, MouseOver): background_color = ListProperty([1, 1, 1, 1]) # so I can set this if I want to when instantiating SpecialImage file_path = StringProperty("No path") file_name = StringProperty("No name") def __init__(self, direntry, **kwargs): super().__init__(**kwargs) self.anchor_x = "center" self.anchor_y = "center" if direntry != None: # should change to isinstance(direntry) self.file_path = direntry.path self.file_name = direntry.name self.file_description = "Extra wide Laminate plank" self.hover = False self.selected = False self.size_hint_x = None self.width = 82 self.size_hint_y = None self.a_texture = get_texture() self.text_color = almost_black self.boxlayout = BoxLayout(orientation = "vertical", size_hint = (None, 1)) self.add_widget(self.boxlayout) self.bind(size = self.update_boxlayout) ### inside boxlayout start ### self.space_0 = Widget(size_hint = (1, None), height = '0dp') self.boxlayout.add_widget(self.space_0) self.a_image = Image(size_hint = (1, None), source = self.file_path, allow_stretch = True) # do I need a function here that sets height self.boxlayout.add_widget(self.a_image) self.hover_widget = Widget() self.a_image.add_widget(self.hover_widget) self.a_image.bind(size = self.update_image_height) self.space_1 = Widget(size_hint = (1, None), height = '2dp') self.boxlayout.add_widget(self.space_1) self.title = Label(size_hint = (1, None), height = '27dp', text = self.file_name, halign = "center", valign = "top", color = self.text_color, font_size = '14dp', bold = True) # this could be one pixel lower (i.e. adjust height of this and above). Waiting to see what their text font is like i.e. the d's and l's stick out by one, but (all?) capitals are fine self.boxlayout.add_widget(self.title) self.space_2 = Widget(size_hint = (1, None), height = '1dp') self.boxlayout.add_widget(self.space_2) self.description = Label(size_hint = (1, None), height = 0, text = self.file_description, halign = "left", valign = "top", color = self.text_color, font_size = '13dp') # keeping this one pixels, otherwise it doesn't work #self.boxlayout.add_widget(self.description) # IMPORTANT. TO ADD DESCRIPTION BACK, UNCOMMENT THE ABOVE LINE, AND SET HEIGHT OF SELF.DESRCRIPTION TO SOMETHING (I THINK IT WAS 40PIXELS BEFORE) #self.space_3 = Widget(size_hint = (1, 1)) # takes up remaining space #self.boxlayout.add_widget(self.space_3) self.bind(size = self.update_text_textboxes) ### inside boxlayout end ## self.bind(size = self.update_height) self.draw_main(self, (1, 1, 1, 1)) # I need to kno how to access background color property and put it here self.draw_hover() self.bind(pos = self.update_rectangles, size = self.update_rectangles, height = self.update_rectangles) self.bind(background_color = self.draw_main) ### animations start ### self.animation_on_hover_image = Animation(opacity = 1, duration = 0.1, transition = "in_out_expo") self.animation_on_hover_text = Animation(color = rich_blue, duration = 0.1, transition = "in_out_expo") self.animation_on_hover_background = Animation(background_color = (1, 1, 1, 1), duration = 0.1, transition = "in_out_expo") self.animation_on_exit_image = Animation(opacity = 0, duration = 0.1, transition = "in_out_expo") self.animation_on_exit_text = Animation(color = self.text_color, duration = 0.1, transition = "in_out_expo") self.animation_on_exit_background = Animation(background_color = self.background_color, duration = 0.1, transition = "in_out_expo") self.animation_selected_image = Animation(background_color = rich_blue, duration = 0.1, transition = "in_out_expo") self.animation_deselected_image = Animation(background_color = self.background_color, duration = 0.1, transition = "in_out_expo") # I need to know how to access background color property and put it here self.animation_test_1 = Animation(color = (1, 1, 1, 1), duration = 0.1, transition = "in_out_expo") self.animation_test_2 = Animation(color = (1, 1, 1, 1), duration = 0.1, transition = "in_out_expo") self.animation_test_3 = Animation(color = almost_black, duration = 0.1, transition = "in_out_expo") ### animations end ### def draw_main(self, self_again, background_color): # no idea how to get around this self_again nonsense #Logger.critical("triggered") self.canvas.before.clear() with self.canvas.before: Color(*background_color) self.rectangle = Rectangle(pos = self.pos, size = self.size) def draw_hover(self): with self.hover_widget.canvas.after: self.hover_widget.canvas.opacity = 0 self.hover_rectangle = Rectangle(texture=self.a_texture) # (not setting size and pos, because I can leave that to update_rectangles, which won't have the correct answer til the first hover anyway) def update_rectangles(self, *args): # I could merge all these "update" things self.rectangle.pos = self.pos self.rectangle.size = self.size self.hover_rectangle.pos = self.a_image.pos self.hover_rectangle.size = self.a_image.size def update_text_textboxes(self, *args): self.title.text_size = [self.boxlayout.width, self.title.height] # If this doesn't work, do self.title.parent.width self.description.text_size = [self.boxlayout.width, self.description.height] def update_image_height(self, *args): self.a_image.height = (self.a_image.width / self.a_image.texture_size[0]) * self.a_image.texture_size[1] # whatever the aspect ratio needs to be, alternatively, I could do a image manager thing def update_height(self, *args): self.height = self.space_0.height + ((self.boxlayout.width / self.a_image.texture_size[0]) * self.a_image.texture_size[1]) + self.space_1.height + self.title.height + self.space_2.height + self.description.height+ 5 # I need to replace self.boxlayout.width with the image height, if we can know it... def update_boxlayout(self, *args): self.boxlayout.width = 64 def on_hover(self): #Window.set_system_cursor("hand") #this may need to be handled in filebrowser since on_exit and on_hover will always be simultaneously called. EDIT 21-02-2020, this could be done so that filebrowser sets to arrow IF NOT in specialimage if self.selected == False: self.hover = True #self.parent.parent.parent.hover_count += 1 not fool proof self.update_rectangles() self.animation_on_hover_image.start(self.hover_widget.canvas) self.animation_on_hover_text.start(self.title) self.animation_on_hover_background.start(self) def on_exit(self): self.hover = False #self.parent.parent.parent.hover_count -= 1 not foo lproof #Window.set_system_cursor("arrow") if self.selected == False: self.animation_on_exit_image.start(self.hover_widget.canvas) self.animation_on_exit_text.start(self.title) self.animation_on_exit_background.start(self) def on_press(self): # must have file browser as parent to work, I could always make a clause if I wanted to make specialimage work fine outside of filebrowser self.parent.parent.parent.set_selected(self) # let this decide if set_selected should be called #self.set_selected() def set_selected(self): self.selected = True self.animation_selected_image.start(self) self.animation_test_1.start(self.title) self.animation_test_2.start(self.description) self.animation_on_exit_image.start(self.hover_widget.canvas) ### NEW Window.set_system_cursor("arrow") # a quick thing def set_deselected(self): """ foolproof is that on_exit can include self.animation_test_3, and this just play on_exit(). and call the onexit animations "text_default" "description_default", "description hover", "description pressed" etc. """ self.selected = False self.animation_on_exit_image.start(self.hover_widget.canvas) self.animation_on_exit_text.start(self.title) self.animation_on_exit_background.start(self) # deselected (background) animation is now redundant? self.animation_test_3.start(self.description)
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 CivMapScreen(BoxLayout): def __init__(self, **kwargs): super(CivMapScreen, self).__init__(**kwargs) self.pos = (0, 0) self.nations = [] self.ms = MapScatter(pos_hint={'x': 0, 'y': 0}) self.add_widget(self.ms) self.im = Image(source='civ_board.png', allow_stretch=True, keep_ratio=False, opacity=1.0) self.ms.add_widget(self.im) self.fl = FloatLayout(size=self.im.size, pos_hint={'x': 0, 'y': 0}) self.ms.bind(size=self.fl.setter('size')) self.im.add_widget(self.fl) self.bind(size=self.im.setter('size')) self.sm = ScreenManager(pos_hint={ 'x': 1660 / 4058.0, 'y': 3 / 2910.0 }, size_hint=((3367 - 1660) / 4058.0, (2907 - 2105) / 2910.0)) self.fl.add_widget(self.sm) self.st = StockPanel(pos_hint={'x': 0, 'y': 0}, size_hint=(1, 1)) self.st.ccc_btn.bind(on_press=self.change_screen) self.sm.bind(size=self.st.lab.setter('size')) screen = Screen(name="Stock and Treasury", pos_hint={ 'x': 0, 'y': 0 }, size_hint=(1, 1)) screen.add_widget(self.st) self.sm.add_widget(screen) self.ccc = CivCardCreditsPanel(pos_hint={ 'x': 0, 'y': 0 }, size_hint=(1, 1)) self.ccc.st_btn.bind(on_press=self.change_screen) screen = Screen(name='Civ Card Credits', pos_hint={ 'x': 0, 'y': 0 }, size_hint=(1, 1)) screen.add_widget(self.ccc) self.sm.add_widget(screen) def change_screen(self, instance, *args): if instance == self.st.ccc_btn: self.sm.current = 'Civ Card Credits' elif instance == self.ccc.st_btn: self.sm.current = 'Stock and Treasury' for obj in [self, self.sm, self.st, self.st.lab]: print(obj, obj.pos, obj.pos_hint, obj.size, obj.size_hint) def add_spotter(self, spotter): print(f'Adding {spotter} to {self.fl}') self.fl.add_widget(spotter)