我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用kivy.core.window.Window.size()。
def unimage(self, params): self.unimages.append([]) if self.kivy: from kivy.uix.image import Image self.unimages[len(self.unimages) - 1] = Image( source= params[4], allow_stretch = True, size_hint = (None, None), size=(params[2] * self.xratio, params[3] * self.yratio), pos=(params[0] * self.xratio, params[1] * self.yratio)) self.root.add_widget(self.unimages[len(self.unimages) - 1]) else: import ui self.unimages[len(self.unimages) - 1] = (ui.ImageView (name = 'Image', frame = (params[0] * self.xratio, \ (600 - params[1] - params[3]) * self.yratio, \ params[2] * self.xratio, params[3] * self.yratio))) self.root.add_subview (self.unimages[len(self.unimages) - 1]) self.unimages[len(self.unimages) - 1].image = \ ui.Image.named(params[4])
def __init__(self, **kvargs): super(KDialog, self).__init__(**kvargs) self.orientation = "vertical" self.param = None # ???? ??? ?????? ?????? "??-???-??????". self.box_buttons_select = BoxLayout(orientation="horizontal", size_hint_y=None, height=40) self.scroll = ScrollView() self.box_content = GridLayout(cols=2, size_hint_y=None) self.box_content.bind(minimum_height=self.box_content.setter("height")) self.body = Popup(title_align=self.title_align, background=self.background_image, on_dismiss=self.dismiss_callback) # ??? ???? ?????????. with self.box_content.canvas: Color(0.16, 0.16, 0.16) self.canvas_for_box_content = \ Rectangle(pos=(5, 5), size=(self.box_content.width, self.box_content.height)) self.box_content.bind(size=self._update_canvas_size, pos=self._update_canvas_size) self.scroll.add_widget(self.box_content)
def add_text_to_label(self, text): # TODO: ????????? ??????? ??????????? ?? ?????????? ????????, # ????????? ? Label, ?????????? ??????? ????? ?????? ??? ????? ??? # ??????????? ???????... while text != "": _text = text[:3500] text = text[3500:] message_text = Label(text=_text, size_hint_y=None, markup=True) message_text.bind(size=lambda *args: self._update_label_size(args), on_ref_press=self.event_callback) self.box_content.add_widget(message_text) # else: # message_text = Label(text=text.decode("utf-8", "replace"), # size_hint_y=None, markup=True) # message_text.bind(size=lambda *args: self._update_label_size(args), # on_ref_press=self.event_callback) # self.box_content.add_widget(message_text)
def _update_canvas_size(self, instance, value): """?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; """ self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ?????? ???? Popup - ???? ?????????. self.body_message.height = self.canvas_for_box_content.size[1] + 150 if self.body_message.height > Window.size[1]: self.body_message.height = Window.size[1] - 10
def _update_canvas_size(self, instance, value): """?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; """ self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ?????? ???? Popup. self.body.height = self.canvas_for_box_content.size[1] + 70 self.body.width = int(Window.size[0] / self.size_hint_x) if self.body.height > Window.size[1]: self.body.height = Window.size[1] - 10
def uniframe(self, params): if self.kivy: from kivy.graphics import Color from kivy.graphics import Rectangle self.root.canvas.add(Color (params[4][0],params[4][1], \ params[4][2])) self.root.canvas.add(Rectangle(pos = (params[0] * self.xratio, \ params[1] * self.yratio), size = (params[2] * self.xratio, \ params[3] * self.yratio))) else: import ui self.uniframes.append([]) self.uniframes[len(self.uniframes) - 1] = \ ui.View(frame=(params[0] * self.xratio, \ (600 - params[1] - params[3]) * self.yratio, \ params[2] * self.xratio, params[3] * self.yratio)) self.uniframes[len(self.uniframes) - 1].background_color = \ (params[4][0],params[4][1], params[4][2],1.0) self.root.add_subview(self.uniframes[len(self.uniframes) - 1])
def _update_canvas_size(self, instance, value): '''?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; ''' self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ?????? ???? Popup. self.height = self.dp(self.canvas_for_box_content.size[1] + 70) self.width = self.dp(int(Window.size[0] // self.hint_x)) if self.height > Window.size[1]: self.height = self.dp(Window.size[1] - 10)
def _update_box_content_size(self, *args): if args != (): height = self.dp(args[0][1]) if height != 0 and height is not None and height != self.dp(150): if self.param == 'logpass': self.height = self.dp(210) elif self.param == 'text': self.height = self.dp(170) else: if self.param == 'query' and self.check: h = self.dp(190) else: h = self.dp(150) self.height = h if height < h else height else: if self.rst: self.height = self.dp(400) if self.height > Window.size[1]: self.height = self.dp(Window.size[1] - 10)
def __init__(self, client, **kwargs): self.client = client self.disp_size = [0, 0] self.child_size = Window.size self.canvas = RenderContext(use_parent_projection = True) with self.canvas: self.fbo = Fbo(size = Window.size, use_parent_projection = True) with self.fbo: ClearColor(0, 0, 0, 0) ClearBuffers() super(DisplaySource, self).__init__(**kwargs) self.texture = self.fbo.texture if self.client.config.get('outputs', 'shmsink') == 'yes': from .GStreamerOutput import GStreamerOutput self.shmsinkoutput = GStreamerOutput(self.texture) else: self.shmsinkoutput = False Window.bind(on_resize = self.resize)
def _resize(self, *args): to_size = list(Window.size) if self.disp_size[0] > 0: to_size[0] = self.disp_size[0] if self.disp_size[1] > 0: to_size[1] = self.disp_size[1] self.child_size = to_size self.size = to_size self.fbo.size = Window.size self.texture = self.fbo.texture if self.shmsinkoutput: self.shmsinkoutput.new_texture(self.texture) for w in reversed(self.children[:]): self.remove_widget(w) self.add_widget(w) for s in self.client.sections: s.recalc()
def update(self, dt): sample, self.sample = self.sample, None if sample is None: return try: buf = sample.get_buffer() result, mapinfo = buf.map(Gst.MapFlags.READ) addr = mapinfo.__hash__() c_mapinfo = _MapInfo.from_address(addr) sbuf = string_at(c_mapinfo.data, mapinfo.size) self.texture.blit_buffer(sbuf, colorfmt = 'rgb') finally: if mapinfo is not None: buf.unmap(mapinfo) self.image.canvas.ask_update()
def __init__(self,**kwargs): self.baseimg = os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','effects','enbar_noback.png')) self.hpimg = os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','effects','hbar.png')) self.mpimg = os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','effects','mpbar.png')) super(ZippyGame,self).__init__(**kwargs) tempscale = Window.height / 256. self.map = BaseMap(os.path.abspath(os.path.join(os.path.dirname('__file__'),'Maps','prototype1','16px-680x800-metal.tmx')), Window.size,tempscale) spawn = self.map.map.layers['start'].find('spawn')[0] self.zipmeter = ZipMeter() self.sprite = Player_Sprite((spawn.px,spawn.py),self.map) self.add_widget(self.map) self.map.add_widget(self.sprite) self.add_widget(self.zipmeter) Clock.schedule_interval(self.update, 1.0/60.0)
def consider_collide(self,pushx,pushy): """ method to recursively find the point on a straight line where a collision occurs with tile object containing collision properties (t,b,l,r : top, bottom, left, right) Updates an Rect instance value with the x,y location at the point of collision for later use. Uses recursion instead of iteration because endpoint is not known prior to calling the method. :param pushx: normalised vector describing the direction to move, already pre-computed by the touch angle plus the touch location :param pushy: normalised vector describing the direction to move, already pre-computed by the touch angle plus the touch location :return: always returns None """ self.plotrect = Rect((self.pos[0]+(self.width*.42))+pushx,(self.pos[1]+(self.height*.35))+pushy, self.size[0]*.16, self.size[1]*.29) numnum = len(self.map.map.layers['blocker'].collide(self.plotrect, 'blocker')) if numnum >= 1: return None pushx += self.movedir.x pushy += self.movedir.y self.consider_collide(pushx,pushy)
def _update_window_size(self, instance, value): '''?????????? ??? ????????? ??????? ?????? ??????????.''' if not self.rst: self.height = self.message.texture_size[1] if self.param == 'text' or self.param == 'query' and self.check: self.height = 170 elif self.param == 'logpass': self.height = 210 elif self.rst: self.height = self.message.height = 400 if self.height > Window.size[1]: self.height = Window.size[1] - 10 elif self.height < 150: self.height = 150
def __init__(self, **kwargs): kwargs.setdefault('do_rotation', False) kwargs.setdefault('do_scale', False) kwargs.setdefault('do_translation_x', False) kwargs.setdefault('do_translation_y', False) super(DistToCenterWidget, self).__init__(**kwargs) self.image = Image(source='data/reticules/distcenter/dist_to_center_reticule.png') self.image.size = self.image.texture_size self.add_widget(self.image) self.label = DistanceLabel() self.label.markup = True self.label.pos = self.image.width + dp(5), self.image.height / 2 - dp(8) self.add_widget(self.label) self.pos = Window.size[0] / 2 - self.image.width / 2, Window.size[1] / 2 - self.image.height / 2
def on_touch_down(self, touch): with self.canvas: if touch.x > self.x_bounds: self.out_of_bounds = True #print ('Touch down event out of bounds with x > %s \n' %(self.x_bounds)) pass elif touch.x < self.x_bounds: self.canvas.clear() d = 10 Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d,d)) touch.ud['line'] = Line(points=(touch.x, touch.y)) #self.vector_length(touch.ud['line']) self.x_initial = touch.x self.y_initial = touch.y self.out_of_bounds = False print ('This is the initial x value: %s, \nThis is the initial y value: %s \n\n' %(self.x_initial, self.y_initial))
def userInput(self, *args): # function to save user input and take output from algorithm name_of_file = 'algorithm_input'# USER INPUT FILENAME inputFileName = os.path.join(assetsdirectory, name_of_file+'.txt') #TOTAL PATH NAME with open(inputFileName, 'w') as f: # create file and write initial and final coordinate positions f.write('%f\t%f\t%f\t%f' % (drawUtility.x_initial, drawUtility.y_initial, drawUtility.x_final, drawUtility.y_final)) drawUtility.canvas.clear() particle = Particle(pos = (drawUtility.x_initial, drawUtility.y_initial), size = (10, 10)) # draw a particle at chosen initial position drawUtility.add_widget(particle) while os.path.isfile('algorithm_output.npy') == False: # search for output file sleep(1) print "Still no file" else: print "File found!" #x,y = np.load('algorithm_output.npy') # load in algorithm output #xs = np.split(x, len(x)/200, 0); ys = np.split(y, len(y)/200, 0) # split x and y arrays into manageable chunks for animation x = np.load('mylistx.npy'); xs = np.split(x, len(x)/200, 0) # test data y = np.load('mylisty.npy'); ys = np.split(y, len(y)/200, 0) self.animate(xs, ys, 0, particle) # call animation function with output data
def userInput(self, *args): # function to save user input and take output from algorithm name_of_file = 'algorithm_input'# USER INPUT FILENAME inputFileName = os.path.join(assetsdirectory, name_of_file+'.txt') #TOTAL PATH NAME with open(inputFileName, 'w') as f: # create file and write initial and final coordinate positions f.write('%f\t%f\t%f\t%f' % (drawUtility.x_initial, drawUtility.y_initial, drawUtility.x_final, drawUtility.y_final)) drawUtility.canvas.clear() particle = Particle(pos = (drawUtility.x_initial, drawUtility.y_initial), size = (10, 10)) # draw a particle at chosen initial position drawUtility.add_widget(particle) while os.path.isfile('algorithm_output.npy') == False: # search for output file sleep(1) print ("Still no file") else: #x = np.load('mylistx.npy'); xs = np.split(x, len(x)/200, 0) # test data #y = np.load('mylisty.npy'); ys = np.split(y, len(y)/200, 0) print ("File found!") x,y = np.load('algorithm_output.npy') # load in algorithm output xs = np.split(x, len(x)/200, 0); ys = np.split(y, len(y)/200, 0) # split x and y arrays into manageable chunks for animation #self.animate(xs, ys, 0, particle) # call animation function with output data
def userInput(self, *args): # function to save user input and take output from algorithm name_of_file = 'algorithm_input'# USER INPUT FILENAME inputFileName = os.path.join(assetsdirectory, name_of_file+'.txt') #TOTAL PATH NAME with open(inputFileName, 'w') as f: # create file and write initial and final coordinate positions f.write('%f\t%f\t%f\t%f' % (drawUtility.x_initial, drawUtility.y_initial, drawUtility.x_final, drawUtility.y_final)) drawUtility.canvas.clear() particle = Particle(pos = (drawUtility.x_initial, drawUtility.y_initial), size = (10, 10)) # draw a particle at chosen initial position drawUtility.add_widget(particle) while os.path.isfile('algorithm_output.npy') == False: # search for output file sleep(1) print ("Still no file") else: x = np.load('mylistx.npy'); xs = np.split(x, len(x)/200, 0) # test data y = np.load('mylisty.npy'); ys = np.split(y, len(y)/200, 0) print ("File found!") #x,y = np.load('algorithm_output.npy') # load in algorithm output #xs = np.split(x, len(x)/200, 0); ys = np.split(y, len(y)/200, 0) # split x and y arrays into manageable chunks for animation self.animate(xs, ys, 0, particle) # call animation function with output data
def on_config_change(self, config, section, key, value): """?????????? ??? ?????? ?????? ?? ?????? ???????? ?????????.""" def select_callback(*args): file_manager.body.dismiss() self.downloadfolder[1] = file_manager.select_folder config.set("General", "downloadkey", "1") config.set("General", "downloadfolder", str(self.downloadfolder)) config.write() # TODO: ???????? ???????? ??????? ?? ???? ? ????????? ???????????. if key == "downloadkey" and int(value): # "????????? ????????" file_manager = \ FileChooser(select_callback=select_callback, filter="folder", title=core.string_lang_select_folder, background_image=self.core.theme_decorator_window, auto_dismiss=False, size=(.85, .9),) elif key == "downloadkey" and not int(value): self.downloadfolder[1] = "" config.set("General", "downloadkey", "0") config.set("General", "downloadfolder", str(self.downloadfolder)) config.write() elif key == "checkattachtoforum": # "???????? ????? ??????" self.checkattachtoforum = int(value) elif key == "progresstextsize": # "???????? ??????? ??????" self.window_text_size = int(value) elif key == "edittheme": # "?????? ??????? ????????????? ????" self.edit_pallete_theme()
def _update_canvas_size(self, instance, value): """?????????? ??? ????????? ??????? ?????? ??????????. type instance: instance <kivy.uix.gridlayout.GridLayout object'>; type value: list; param value: ??????? ?????? instance; """ self.canvas_for_box_content.pos = instance.pos self.canvas_for_box_content.size = instance.size # ????????? ??????? ???? Popup - ???? ?????????. if self.param in ["text", "tel", "address", "mail", "password", "datetime", "number"]: plus_height = 170 elif self.param == "logpass": plus_height = 200 else: plus_height = 120 self.body.height = self.canvas_for_box_content.size[1] + plus_height self.body.width = int(Window.size[0] / self.size_hint_x) if self.body.height > Window.size[1]: self.body.height = Window.size[1] - 10 if self.rst: self.message.height = self.body.height / 1.33
def unilabel(self, params): self.unilabels.append([]) if self.kivy: from kivy.uix.label import Label self.unilabels[len(self.unilabels) - 1] = Label(pos = \ (params[0] * self.xratio, params[1] * self.yratio), \ size_hint=(1.0,1.0), halign="left", \ valign="bottom", text = params[4]) self.unilabels[len(self.unilabels) - 1].font_size = 17.5 * \ self.yratio self.unilabels[len(self.unilabels) - 1].bind(size= \ self.unilabels[len(self.unilabels) - 1].setter('text_size')) self.root.add_widget(self.unilabels[len(self.unilabels) - 1]) else: import ui self.unilabels[len(self.unilabels) - 1] = ui.Label(frame= \ (params[0] * self.xratio, (600 - params[1] - params[3]) * \ self.yratio, params[2] * self.xratio, params[3] * self.yratio)) self.unilabels[len(self.unilabels) - 1].text = params[4] self.unilabels[len(self.unilabels) - 1].text_color = 'white' self.unilabels[len(self.unilabels) - 1].alignment = \ ALIGN_LEFT = True self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * \ self.xratio) self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
def unilabel(self, params): self.unilabels.append([]) if self.kivy: from kivy.uix.label import Label self.unilabels[len(self.unilabels) - 1] = Label(pos = \ (params[0] * self.xratio, params[1] * self.yratio), \ size_hint=(1.0,1.0), halign="left", \ valign="bottom", text = params[4]) self.unilabels[len(self.unilabels) - 1].font_size = 17.5 * \ self.yratio self.unilabels[len(self.unilabels) - 1].bind(size= \ self.unilabels[len(self.unilabels) - 1].setter('text_size')) self.root.add_widget(self.unilabels[len(self.unilabels) - 1]) else: import ui self.unilabels[len(self.unilabels) - 1] = ui.Label(frame= \ (params[0] * self.xratio, (600 - params[1] - params[3]) * \ self.yratio, params[2] * self.xratio, params[3] * self.yratio)) self.unilabels[len(self.unilabels) - 1].text = params[4] self.unilabels[len(self.unilabels) - 1].text_color = 'white' self.unilabels[len(self.unilabels) - 1].alignment = \ ui.ALIGN_LEFT self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * \ self.yratio) self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
def __init__(self, **kwargs): super(ThemeManager, self).__init__(**kwargs) self.rec_shadow = Atlas('{}rec_shadow.atlas'.format(images_path)) self.rec_st_shadow = Atlas('{}rec_st_shadow.atlas'.format(images_path)) self.quad_shadow = Atlas('{}quad_shadow.atlas'.format(images_path)) self.round_shadow = Atlas('{}round_shadow.atlas'.format(images_path)) Clock.schedule_once(lambda x: self.on_theme_style(0, self.theme_style)) self._determine_device_orientation(None, Window.size) Window.bind(size=self._determine_device_orientation)
def build(self): from kivy.core.window import Window Window.size = (540, 720) # self.theme_cls.theme_style = 'Dark' return Builder.load_string(""" #:import Toolbar kivymd.toolbar.Toolbar BoxLayout: orientation:'vertical' Toolbar: id: toolbar title: 'Page title' background_color: app.theme_cls.primary_color left_action_items: [['menu', lambda x: '']] right_action_items: [['search', lambda x: ''],['more-vert',lambda x:'']] MDTabbedPanel: id: tab_mgr tab_display_mode:'icons' MDTab: name: 'music' text: "Music" # Why are these not set!!! icon: "playlist-audio" MDLabel: font_style: 'Body1' theme_text_color: 'Primary' text: "Here is my music list :)" halign: 'center' MDTab: name: 'movies' text: 'Movies' icon: "movie" MDLabel: font_style: 'Body1' theme_text_color: 'Primary' text: "Show movies here :)" halign: 'center' """)
def small_error_warn(x): if dp(x) <= dp(80): if MDBottomNavigationErrorCache.last_size_warning != x: MDBottomNavigationErrorCache.last_size_warning = x Logger.warning("MDBottomNavigation: {}dp is less than the minimum size of 80dp for a " "MDBottomNavigationItem. We must now expand to 168dp.".format(x)) # Did you come here to find out what the bug is? # The bug is that on startup, this function returning dp(80) breaks the way it displays until you resize # I don't know why, this may or may not get fixed in the future return dp(168)
def __init__(self, *args, **kwargs): super(GStreamerAction, self).__init__(*args, **kwargs) self.settings = self.combine_settings(self.settings, self.client.minion.get('settings'), self.action.get('settings')) self.fade_length = self.settings.get('media_fade') self.input_pipeline = self.settings.get('camera_pipeline') try: self.resolution = ( int(self.settings.get('camera_width')), int(self.settings.get('camera_height')) ) except ValueError: self.resolution = Window.size self.texture = Texture.create(size = self.resolution, colorfmt = 'rgb') self.texture.flip_vertical() self.image = Image(texture = self.texture) if self.settings.get('media_preserve_aspect') == 'no': self.image.keep_ratio = False self.image.opacity = 0 caps = 'video/x-raw,format=RGB,width={},height={}'.format(*self.resolution) pl = '{} ! videoconvert ! videoscale ! appsink name=appsink emit-signals=True caps={}' self.pipeline = Gst.parse_launch(pl.format(self.input_pipeline, caps)) self.appsink = self.pipeline.get_by_name('appsink') self.appsink.connect('new-sample', self.new_sample) self.pipeline.set_state(Gst.State.READY)
def set_scale(self): if self.manager.current_screen.ids.get('scalar'): scale_amount = Window.size[0] / 233 print('scaling factor', scale_amount) animation = Animation(scale=scale_amount, duration=.2) scalar = self.manager.current_screen.ids.scalar # TODO - when we resize the screen, we want to focus on the map's focus target coordinates in the Scalar scalar.center = scalar.parent.center self.current_instance.map.recenter(*Window.size) animation.start(scalar)
def aggro_check(self, size): aggro_range = self.map.tile_width * size offset = (self.map.tile_width * (size / 2)) collided = [] for player in self.player_characters: rect = Rect(player.x - offset, player.y - offset, aggro_range, aggro_range) collided += [e for e in self.entities if rect.intersect(Rect(*e.pos + e.size)) and e.data.type == 'enemy'] return collided
def __init__(self, *args, **kwargs): self.mplevelmodifier = 0 self.hplevelmodifier = 0 self.width, self.height = Window.size self.scale = self.height / 256. # 21 tile size * 12 self.origlevels = self.hplevel = self.mplevel = self.scale * 57 # Len of the HP/MP bar super(ZipMeter, self).__init__(*args, **kwargs)
def __init__(self): self.width, self.height = Window.size self.scale = self.height / 256. # 21 tile size * 12
def __init__(self,pos,mapz): super(Player_Sprite,self).__init__(pos=pos,size=(195,164)) # (pos=pos, size=(192,81),*kwargs) self.mov_images = Atlas(os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','movement','animatlas.atlas'))) self.atk_images = Atlas(os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','attack','atk.atlas'))) self.spe_images = Atlas(os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','special','specatlas.atlas'))) self.wall_images = Atlas(os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','special','wall_anim','wall.atlas'))) self.animage = Atlas(os.path.abspath(os.path.join(os.path.dirname('__file__'),'animation','effects','arrow.atlas'))) self.map = mapz self.texture = self.mov_images['walk_2_right'] self.moving_right = False self.resting = False self.moving_left = False self.movyval = 0 self.suspended = 0 self.jumping = False self.animlen = 0 self.animduration = .08 self.prevdir = 'right' self.atkcounter = 0 self.touching = False self.perma_x = self.map.map.view_w / 2 self.perma_y = self.map.map.view_y / 2 self.skew_x_touch, self.skew_y_touch = 0,0 self.zipping = False self.sticking = False self.coldir = 'n' self.bearing = 90
def __init__(self, **kvargs): super(KDialog, self).__init__(**kvargs) self.param = None self.rst = None self.input_dialog_double = None # ???? ??? ?????? 'Yes, No, Cancel'. self.box_buttons_select = BoxLayout( size_hint_y=None, height=self.dp(40), spacing=5 ) self.ids.box_content.bind( size=self._update_window_size, pos=self._update_window_size )
def log(args, n, p, c): if n == "Nickname.." or n == "": p = Popup(title='Login Error', content=Label(text="Digite seu apelido!", color=(1,0,0,1)),size_hint=(.6, .2)) p.open() elif p == "Password.." or p == "": p = Popup(title='Login Error', content=Label(text="Digite sua senha!", color=(1,0,0,1)),size_hint=(.6, .2)) p.open() else: name = addslashes(n) pswd = addslashes(p) sql = "select * from users where nickname ='"+name+"' and passwd='"+pswd+"'" enc = cur.execute(sql) if enc: if c: try: _name = open(".saved/.name.txt", "w") _name.write(name) _name.close() _pass = open(".saved/.pass.txt", "w") _pass.write(pswd) _pass.close() os.system("attrib +h .saved/") except: print("Error in saving..") sm.current = 'space' Window.size=(1366, 768) else: p = Popup(title='Login Error', content=Label(text="Usuario "+n+" nao encontrado!"),size_hint=(.6, .2)) p.open()
def build(self): self.icon = 'img/icon.ico' # Window Settings Window.fullscreen = False Window.size = (820, 580) Window.clearcolor = (.6,.6,.6,.4) return sm
def __init__(self, **kwargs): super(ReticuleCalib, self).__init__(**kwargs) self.image = Image(source='data/reticules/calibration/reticule_calib_lock.png') self.image.size = self.image.texture_size self.add_widget(self.image) self.x_value = TextInput() self.x_value.background_color = (1, 1, 1, 0.7) self.add_widget(self.x_value) # TODO : petit souci de design. Le positionnement du réticule de calib se fait par set du center du widget. Or, # si on étend sa taille au delà de celle de l'image du réticule, le positionnement ne sera pas bon. self.size = self.image.texture_size
def draw_tile(self, proxy): if proxy.image.texture: self.map_layer.add( Rectangle(pos=proxy.pos, size=proxy.size, texture=proxy.image.texture, group=proxy.zoom))
def draw_tiles(self, tile_list): for tile in tile_list: image_id = tile.get_id() if self.tileCache.add_tile(tile.zoom, image_id): image = self.map.get_tile(tile.zoom, tile.x, tile.y) if image is None: continue image.create_property("pos", tile.pos) image.create_property("size", tile.size) image.create_property("zoom", str(int(tile.zoom))) image.bind(on_load=self.draw_tile) # if image.loaded: # only useful when Loader actually caches images # image.dispatch("on_load")
def get_dist_to_center(self): """ :return: The distance in meters between the last known position and the position represented by the middle of the screen. If no distance can be calculated, it returns -1. """ if self.map is None: return -1 try: merc_x, merc_y = self.map.map_coord_to_map_projection(*self.to_local(Window.size[0]/2, Window.size[1]/2)) except ZeroDivisionError: return -1 lat, lon = Map.to_geographic(merc_x, merc_y) lat_last, lon_last = self.last_pos_wgs84 dist = Map.distance(lat_last, lon_last, lat, lon) return dist
def redraw(self): self.canvas.clear() with self.canvas: Color(*COL_FG) total_ticks = int(self.total_axis_space/self.space_btw_marks) for i in range(total_ticks): if i % 5 == 0: # Long Mark mark = self.mark_length else: # Short Mark mark = self.mark_length / 2 Line(points=[self.fwidth - mark, i * self.space_btw_marks, self.fwidth, i * self.space_btw_marks, self.fwidth, (i + 1) * self.space_btw_marks]) i = int(self.total_axis_space/self.space_btw_marks) Line(points=[self.fwidth - self.mark_length, i * self.space_btw_marks, self.fwidth, i * self.space_btw_marks]) for i in range(int(total_ticks / 5) + 1): label = CoreLabel() label.text = "{:.1f}".format(0.1 * i) label.refresh() label_texture = label.texture texture_size = list(label_texture.size) Rectangle(texture=label_texture, size=[s * 0.9 for s in texture_size], pos=(0, i * 5 *self.space_btw_marks - 2))
def set_window_size(self, size, hide=False): Window.size = size if hide: Window.hide()
def _load_window_pos_size(self, *args): self.set_window_pos(self.last_pos) self.set_window_size(self.last_size) Clock.schedule_interval(self._update_window_pos, 0.2) self.root.bind(size=self._update_window_size)