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)
python类size()的实例源码
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, **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 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):
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, **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 __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)