Skip to content

Instantly share code, notes, and snippets.

@Alan-FGR
Created August 1, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alan-FGR/31561af2ececfefc12c3 to your computer and use it in GitHub Desktop.
Save Alan-FGR/31561af2ececfefc12c3 to your computer and use it in GitHub Desktop.
__author__ = 'Alan'
__version__ = '0.1'
import kivy
kivy.require("1.0.0")
from kivy.app import Builder
from kivy.app import App
from kivy.clock import Clock
mybutstr = """
#:import win kivy.core.window
Button:
size_hint: None,None
size: '65dp','35dp'
center_y: win.Window.height*0.5
center_x: win.Window.width*0.5
text: 'test'
"""
class MyApp(App):
def build(self, **kwargs):
self.mybut = Builder.load_string(mybutstr)
Clock.schedule_interval(self.resizeBut,0.1)
return self.mybut
def resizeBut(self, *args):
self.mybut.height = self.mybut.height+10
MyApp().run()
@Alan-FGR
Copy link
Author

Alan-FGR commented Aug 1, 2015

<daboum> hello
<daboum> I'm getting weird behavior in the kv file
<daboum> For one Wiget I've added two Images
<daboum> but each image has a different Window.height
<daboum> so when I do <Image>: center_y: Window.height for both I get different position for each images
<daboum> can anybody explain why?
<daboum> in fact is there anyone online?
<daboum> please anyone?
* samiux (~samiux@unaffiliated/samiux) has left ("Leaving")
<nine_9> daboum: are the images the same size?
<daboum> not really
<daboum> but their center isn't on the same level
<daboum> when it should be clearly
<daboum> right?
<nine_9> yes
<nine_9> although i never 'set' the center_y like that
<daboum> what could possibly be the problem?
<nine_9> no idea, are the images in a layout?
<daboum> no 
<nine_9> perhaps you could try setting the y pos minus the self.height*.5
<nine_9> or perhaps you could paste an sscce
<daboum> minus what?
<daboum> and whats an sscce :p
<nine_9> center_y is just half the height i think, so you could do pos: some_x, se
<nine_9> wait
<nine_9> pos: some_x, some_y-(self.height*.5)
<nine_9> sscce = short self-contained correct example
<nine_9> minimal reproducible script
<daboum> well the problem is that on my computer screen it looks fine when moving to my phone it gets out of hand
<daboum> despite the fact that I'm using dp.dp
<daboum> which I believe should be just dp
<daboum> but in kv that causes an error
* Bawbzzz (blank@cable-24-135-240-64.dynamic.sbb.rs) has joined
* zoj has quit (Ping timeout: 246 seconds)
<nine_9> what error?
<daboum> I've solved part of the problem
<daboum> or maybe all of it
<nine_9> '10dp' or dp(10) shouldn't cause problems are are the proper way to use dps
<daboum> nine_9: the error is dp module is not callable
<daboum> well it does
<daboum> I have to use dp.dp(10)
<nine_9> in kv?
<daboum> yes
<nine_9> something is very weird... are you using the development version?
<daboum> as for why the center is different its because I'm doing height: 60 dp after doing center_y: Window.height
<daboum> probably not
<daboum> its been a while since I've updated
<daboum> but I"m not going to update now :p
<daboum> which is the version now?
<nine_9> yeah, it's worth a try
<nine_9> 1.9.0
<nine_9> the stable
<daboum> well I have 1.8
<daboum> 1.8.0
<nine_9> but the development version is quite stable it seems
<nine_9> although i personally don't use it
<nine_9> i'm using 1.9.0 and never experienced any problem like that
<daboum> did you understand what happened though with the center y?
<nine_9> nope
<daboum> okay wait 
<daboum> http://pastebin.com/mVma0Phg
<daboum> how werid is that
<daboum> nine_9: 
<daboum> ^^
<daboum> tell me when you read the file
<nine_9> that's expected, because the bottom one doesn't know the size at that time, so it reverts to the default one (100,100)
<nine_9> it uses the size to calc the center_x and y
<nine_9> of the Image that is
<daboum> I think  thats a bug
<daboum> when its resized it should keep the same center
<daboum> thats the logical thing to happen
<daboum> even if it is expected
<daboum> well I mean I prefer like how I am saying
<nine_9> nope, that's not a bug, center_y uses the height to know where is the center of the widget, so you have to set the height you want before using it
<daboum> well I know but it could be made to be more intuitive
<nine_9> but yeah, when it resizes i think it should keep 'update' the height that's used to calc center_y
<nine_9> so i don't know, lemme try in 1.9.0
<daboum> yes 
<daboum> oh 
<daboum> okay
<daboum> it would be cool if they fixed it
* kvuser2 has quit (Quit: Page closed)
<sapienTech> is it possible to give a kivy Image object a PIL image object instead of a filename? I would like to take an image from file, use PIL to get a thumbnail and pass that thumbnail into the kivy image object
<sapienTech> is the only way to save the thumnail file, and then have kivy Image load it from file?
<sapienTech> it seems kivy.core.image can take in an image object, but can kivy.uix.image?
<nine_9> daboum: it's very buggy :P
<daboum> why whats happening nine_9 ?
<nine_9> i've tried with a button, and it won't stay in place :)
<daboum> oh thats not so good :/
<daboum> sapienTech: I'm researching now
* Guest10910 (~Jorge@186.177.2.148) has joined
<nine_9> wait, i think that's because i forgot to use size_hint :P
<daboum> oh nine_9 :)
<sapienTech> daboum: thanks!
<sapienTech> i can create a test app if there if you guys don't know off hand/don't know
<sapienTech> sorry mouseslip
<nine_9> i'm doing an sscce
<sapienTech> i can create a test app too if you guys don't know off-hand
<kovak> you can load a core image, and then set the widget Image.texture to the core image.texture
<nine_9> https://gist.github.com/Alan-FGR/31561af2ececfefc12c3
<nine_9> the button won't be auto-centered
<daboum> was it the size hint thing?
<nine_9> size_hint would work
<nine_9> center_y doesn't bind stuff it seems
<nine_9> it just do some math and that's all

@Alan-FGR
Copy link
Author

Alan-FGR commented Aug 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment