def __init__(self, card: Card, aspect_ratio: float = 24 / 37, path: Optional[str] = None, **kwargs): """ Instantiates a new CardWidget. :param card: The card value to associate to this widget. :param aspect_ratio: The aspect ratio that will be enforced. :param path: The path to the folder containing the card images. :param kwargs: Parameters to be forwarded to the base class' constructor. """ super().__init__(**kwargs) self._card = card self._path = path or GameOptions().cards_path self._visible = True self._grayed_out = False self._touch_down_pos: Optional[Tuple[int, int]] = None self._shadow_image = _get_drop_shadow_filename(self._path) self._shadow_enabled = _SHADOW_STRENGTH self.auto_bring_to_front = True image = Image(source=_get_card_filename(card, self._path)) image.keep_ratio = False image.allow_stretch = True self.fbind("size", image.setter("size")) self.add_widget(image) self._ratio = aspect_ratio self.width = self.height * self._ratio self.size_hint = None, None self.register_event_type("on_double_tap") self.register_event_type("on_card_moved") self._check_aspect_ratio = True # noinspection PyUnreachableCode if __debug__: self.fbind("size", self._assert_aspect_ratio)
def main(): sm = ScreenManager() screenshare = Screen(name="screenshare") sm.switch_to(screenshare) boxl = BoxLayout(orientation='vertical') data = BytesIO() canvas_img = Im.new('RGB', (1920, 1080), color=(0, 0, 0)) canvas_img.save(data, format='png') data.seek(0) kimg = KiImage(data, ext='png') img = Image() img.texture = kimg.texture img.allow_strech = True img.keep_ratio = True btn = Button(text='start', pos_hint={'x': 0, 'y': 0}, size_hint=(0.1, 0.1)) sock = socket.socket() host = '127.0.0.1' port = 8000 def retreive(*a): rwh = sock.recv(50).decode() rwh = eval(rwh) print(rwh) repeat = rwh[0] width = rwh[1] height = rwh[2] print(repeat) b = bytearray() flag = 0 for i in range(repeat): im = sock.recv(1024) b.extend(im) flag = flag + 1 print(flag, len(b)) z = Im.frombytes('RGB', (width, height), bytes(b)) data.seek(0) z.save(data, format='png') data.seek(0) kimg = KiImage(data, ext='png') img.texture = kimg.texture #img.source(z) def startret(*a): print('hello') sock.connect((host, port)) Clock.schedule_interval(retreive, 1.0 / 20) boxl.add_widget(img) boxl.add_widget(btn) btn.bind(on_press=startret) screenshare.add_widget(boxl) return sm
def build(self): main_layout = BoxLayout(padding=(10, 0), orientation="vertical") wimg = Image(source='s.png') wimg.allow_stretch = True wimg.keep_ratio = False wimg.size_hint_x = 1 wimg.size_hint_y = 0.2 scroll_container = BoxLayout(orientation="vertical", size_hint=(1, 0.90)) self.layout = BoxLayout(padding=(15, 10), orientation="vertical", spacing=50, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) colors = [red, green, blue, purple] root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height * 0.70)) root.add_widget(self.layout) bottom_layout = BoxLayout(padding=10, orientation="horizontal", size_hint=(1, 0.1)) self.textinput = TextInput(hint_text="Say something ", background_color=random.choice(colors), size_hint=(0.8, 1)) btn3 = Button(text="Send", background_color=random.choice(colors), size_hint=(0.2, 1)) btn3.bind(on_press=self.sent) bottom_layout.add_widget(self.textinput) bottom_layout.add_widget(btn3) scroll_container.add_widget(root) main_layout.add_widget(wimg) main_layout.add_widget(scroll_container) main_layout.add_widget(bottom_layout) Window.bind(on_key_down=self.on_key_down) btn = Label(padding=(0, 0), text="Bot> " + random.choice(ice_breakers), color=(1, 0, 1, 1), size_hint=(1.0, 1.0), halign="left", valign="middle") btn.bind(size=btn.setter('text_size')) self.layout.add_widget(btn) return main_layout
def showPicture(self, *args): self.clear_widgets() i1 = Image() i1.keep_ratio = True i1.source = 'simplekivy3.gif' self.add_widget(i1) b1 = Button() b1.size_hint_y = 0.1 b1.background_color = (1, 0, 0, 1) b1.text = '< -- Back' self.add_widget(b1) b1.bind(on_press=self.showMenu)
def resimleriEkle(self, dosyalar): self.root.ids.karinca.clear_widgets() for dosya in dosyalar: if os.path.isfile(dosya): if imghdr.what(dosya): resim=Image(source=dosya) resim.allow_stretch=True resim.keep_ratio=False self.root.ids.karinca.add_widget(resim) if self.root.ids.karinca.slides: self.root.ids.slyat_dugme.disabled=False else: self.root.ids.slyat_dugme.disabled=True
def resimleriEkle(self, dosyalar): self.root.ids.karinca.clear_widgets() for dosya in dosyalar: if os.path.isfile(dosya): if imghdr.what(dosya): resim = Image(source=dosya) resim.allow_stretch = True resim.keep_ratio = False self.root.ids.karinca.add_widget(resim) if self.root.ids.karinca.slides: self.root.ids.slyat_dugme.disabled = False else: self.root.ids.slyat_dugme.disabled = True
def placeWorldItems(self): for each in requiredItems: x = Image(source=self.resource_path('artAssets/{}.png'.format(each))) x.allow_stretch = True x.keep_ratio = True x.size_hint = (.03,.03) if(allWorldItems[each] in lightWorldLocations): x.pos_hint = {'center_x':lightWorldLocations[allWorldItems[each]][0],'center_y':lightWorldLocations[allWorldItems[each]][1]} x.text = '{}:{}'.format(each, allWorldItems[each]) x.reload() self.ids.lightScatter.add_widget(x,0) elif(allWorldItems[each] in darkWorldLocations): x.pos_hint = {'center_x':darkWorldLocations[allWorldItems[each]][0],'center_y':darkWorldLocations[allWorldItems[each]][1]} x.reload() self.ids.darkScatter.add_widget(x,0) else: pass
def conn(self, dt): try: post getnode except: from uuid import getnode from requests import post try: ip = str(getnode()) url = "http://10.0.0.109:5000/register" json = {"user_ip": ip, "user_resoluction": "1280x299"} headers = {"Content-Type": "application/json"} response = post( url=url, json=json, headers=headers, verify=True) # envia token + json ignorando SSl(certificado) self.text = str(response.json()) except: print("timeout") try: Clock except: from kivy.clock import Clock Clock.schedule_once(self.conn, 6) else: '''main_layout_title = Label(text="Fight Battle", font_name="source/font/mv-boli.ttf", color=(0, 0, 0, 1), size_hint=(0.23, 0.3), font_size=sp(82 * Window.size[1] / 600)) main_layout_title.pos_hint = {"x": 0.523 - (main_layout_title.size_hint_x / 2), "y": 0.653}''' main_layout_btn_jogar_image = Image( source="source/img/bg_botao.jpg", size_hint=(.255, .109), allow_stretch=True, keep_ratio=False) main_layout_btn_opcoes_image = Image( source="source/img/bg_btn_opcoes.jpg", size_hint=(.255, .109), allow_stretch=True, keep_ratio=False) main_btn_jogar = Button(text="jogar", opacity=0.0, size_hint=(.255, .109), on_press=main.jogar) main_layout_btn_jogar_image.pos_hint = main_btn_jogar.pos_hint = { "x": 0.522 - float(main_btn_jogar.size_hint_x / 2), "y": 0.415 } main_btn_opcao = Button(text="opções", opacity=0.0, size_hint=(.255, .109), on_press=main.opcoes) main_layout_btn_opcoes_image.pos_hint = main_btn_opcao.pos_hint = { "x": 0.522 - float(main_btn_opcao.size_hint_x / 2), "y": 0.29 } main_image = Image(source="source/img/tela_bg.jpg") main_image.allow_stretch = True main_image.keep_ratio = False main_layout = FloatLayout() main_layout.add_widget(main_image) main_layout.add_widget(main_layout_btn_jogar_image) main_layout.add_widget(main_layout_btn_opcoes_image) main_layout.add_widget(main_btn_jogar) main_layout.add_widget(main_btn_opcao) #main_layout.add_widget(main_layout_title) main.add_widget(main_layout) screen_manager.current = "main"