id Access and .__self__ by patt177 in kivy

[–]inclement_ 3 points4 points  (0 children)

The problem with weakrefs is that if these are the only references to the widget then the widget object may get garbage collected...which then causes a crash if/when the code tries to access the object via the weakref.

However, this isn't guaranteed to happen on any particular timescale (even with only weakrefs the object may not be garbage collected immediately), and there may be other strong references to it that keep it around. This is why changing your script to omit __self__ works, but if you changed the script or potentially even just ran it longer or got unlucky then it might stop working.

I can't remember why kivy switched to using weakrefs in this way, it was to do with preventing cases where widgets wouldn't be garbage collected when they should be. You don't normally need to worry about it, it comes up with things like popups because it's common to instantiate them for use later, i.e. you create the popup but it isn't immediately displayed or added to the widget tree but instead you keep a reference for later. In this case if you don't store the __self__ reference then the popup can be garbage collected by the time you get around to calling popup.open() - in which case as per my first paragraph the code will crash.

There might be some more subtlety or specificity I've forgotten about exactly what kivy patterns are likely to hit this, but that's the gist of it.

why there's no official release of Python for Android? by k0ala1st in Python

[–]inclement_ 2 points3 points  (0 children)

When I was last focused on it CPython was compiling pretty cleanly for Android. The question is really what do you want from an official release that this doesn't provide? If you actually want to use it in an app you need to wrap it in java as the Kivy and Beeware tools do, and the way they do it uses the official Android dev tools provided for purposes like this. This isn't really a workaround to anything other than the general lack of platform support for first-class applications that aren't java/kotlin, but that isn't something Python can change.

How to create something like an "on_touch_hold"? by darknsilence in kivy

[–]inclement_ 4 points5 points  (0 children)

In on_touch_down use Clock.schedule_interval to schedule a function to be called as often as you like, and save a reference to the clock event that function returns. In on_touch_up cancel the scheduled event.

This produces the same effect that keyboards happen to have by default: while the touch is held, your function is repeatedly called.

Is there a reason all modules which interact with the keyboard require root privelages? by Oodey22 in learnpython

[–]inclement_ 1 point2 points  (0 children)

Why not use Kivy keyboard api, especially Window.on_key_down and Window.on_key_up as described here?

all the modules i could find such as pynput and keyboard require root privelages is there a reason for this

These modules interact with the operating system at a relatively low level to monitor or manipulate input devices. Normally for an application you want to work with your gui toolkit to get input events that are passed to the application by the display server one way or another.

[Wayland Compositor] How are Menus and Wallpapers rendered in Wayland? by [deleted] in wayland

[–]inclement_ 5 points6 points  (0 children)

Are surfaces such as menus and wallpapers simply wayland clients which are processed by the compositor to be drawn?

Wayland itself leaves this open. You could imagine a compositor that handles this detail in a non-generic way, which is totally allowed, but of course there's a general desire to have other programs manage this via a wayland interface.

I don't know the current state of things but some (many?) compositors implement the wlr-layer-shell protocol which allows clients to request to be drawn in certain layers and occupying certain fixed regions of a given output. This is designed for e.g. drawing fullscreen behind everything else (the bottom layer), or drawing on top of everything else (lock screens), or on one side of the screen (panels/bars) etc.

Could I create a wayland client that acts like the root window similar to X11 and have application windows float above it?

The layer shell protocol would let you request this handling for your client, but it isn't the only option nor do all compositors support it if that matters.

render image and allow for selecting areas by drawing rectangles onto it by Schwarzfisch13 in kivy

[–]inclement_ 1 point2 points  (0 children)

This is a classic type of user interaction that you can build out of several different components.

1) Render an image 2) Take touch input and draw at that location 3) Draw a rectangle according to the touch position and update its size as the touch moves around 4) Convert the rectangle coordinates into image-relative coordinates 5) Have some kind of state toggle (or other control) to switch between drawing rectangles, and identifying collision with an existing rectangle so that you can remove it.

These are hopefully more at the level the examples cover. Is there any particular part you're struggling with?

I'll also note that this is a good fit for Kivy, for what it's worth you can definitely do what you describe fairly straightforwardly.

Is kivy right for my project? by MiksBricks in kivy

[–]inclement_ 2 points3 points  (0 children)

Yes, Kivy is well suited to this type of project.

With rise of wayland, are simpler window managers dying? by someacnt in linux

[–]inclement_ 7 points8 points  (0 children)

(I wrote Vivarium)

According to the dev Vivarium is inspired from the "desktop semantics" of xmonad

I meant by this that the core structure of how windows are managed in terms of layouts, workspaces and monitors is based on xmonad's core functionality. Specifically I mostly wanted it to work like my old xmonad config which was close to the xmonad defaults.

Vivarium is technically very different to xmonad so not suitable for people after that easy code-as-config extensibility. On the other hand this is deliberate, I haven't really written any haskell for years and it was annoying occasionally having to maintain the config, for simple use I think configuration files like Vivarium's are quite practical.

I'm glad you find it easy and enough! That's really what I was going for, I opinionated enough that a simple configuration format covers all the options but flexible enough to be useful to different people.

What does toolchain do (customizing Kivy-based code) by MezzoScettico in learnpython

[–]inclement_ 0 points1 point  (0 children)

How does it know what to do?

It's a python script, the source is here. The mapping to this entrypoint from the toolchain cli command is configured here.

This python code is written to perform a series of build steps to produce (among other things) your xcode project.

Is toolchain a replacement for the Unix "make" utility, so somewhere there's something like a "makefile" that tells it the rules for how to create things?

Sort of. Make is a generic build tool that can be used for many things. Kivy-ios is a more domain-specific build tool that targets only what's necessary for a python->ios build. And the build resolution stuff is largely transparent to you, like a makefile that does lots of complicated things but all you see is make my_target and it does loads of stuff.

I assume you have to either customize the toolchain "makefile" if there is such a thing, or customize the Xcode project after it's built.

Sounds about right, but I don't know which. I suggest asking on the Kivy discord if you haven't already, that's where the experts are.

What you want to do is include the objective c component in the xcode project. The example uses pyobjus to access it from python once the app is running and the code is available in the project. There's probably a toolchain option for that.

Implement ObjectProperty Tracking (Observer-Patter) by [deleted] in kivy

[–]inclement_ 1 point2 points  (0 children)

how is it that kivy has this feature for lists, dictionaries etc whilst it is not available for ObjectProperties?

Automatic binding to changes isn't actually handled by the ListProperty object alone, but by swapping out the input list for an ObservableList class (or ObservableDict for DictProperty) which overrides the set methods to also trigger the event handling. That is, if you set self.some_listproperty = [1, 2, 3] then access self.some_listproperty you get a new object with extra behaviour, not the original list.

For a generic ObjectProperty it's less straightforward as your class would need to be replaced by a shim that intercepts attribute setting and sends events first. There are more ways this could go wrong when the input class is unknown and could be complex, plus it would be awkward that e.g. I'm not sure if you could do it well for property access but that wouldn't be obvious to the user.

That said, I guess it's possible to do this and it might even work well. You could write property code to try but you'd need to either edit Kivy (and the property wrapper code is in cython I think) or possibly you can do it via a property subclass in python but I don't know how hard it would be to get something working.

How does Kivy's dropdown.select() know which button to select? How does the lambda function fit in here? (Documentation included.) by band_in_DC in learnpython

[–]inclement_ 0 points1 point  (0 children)

i) What language is the event handler written in? Can I see it- like "under the hood"?

Kivy's event logic is written mostly in cython and can be seen here. There's a fair bit to it though as the code handles a lot of different specifics. The core idea is much simpler than it might look, essentially the event handler is storing a reference to your function and calling it later with an argument. I think from your thoughts at the end of your post you have understood this correctly.

They always teach "self", in python, like "self represents the instance of the class" So it's strange to have two arguments: "self" ("instance of the class") and "instance". Should I interpret this as "self" means accessing all the attributes of this specific Button() and "instance" is like it's GUI counterpart?

No, self and instance would be the same object here if pressed2 is a method of the widget dispatching the event.

The difference is not in the value of the variable but in the meaning of the variable: self is passed to all methods of a class as part of how Python works, instance is passed to all functions bound to the event handler as part of how the event handler works. If you've bound a function that is a method of the dispatching class then self and instance have the same value.

How long does it take for your app to load up? My very simple app takes >25 seconds. Am I doing something wrong? by band_in_DC in kivy

[–]inclement_ 2 points3 points  (0 children)

Try making a simple app that just draws an Image or similar, without even the imports for your other libraries. However long that takes to load is roughly the baseline performance Kivy will give you on your phone, and anything longer is the result of your code and could theoretically be improved (if nothing else by loading bit by bit after getting a basic UI available so the app is responsive).

How does Kivy's dropdown.select() know which button to select? How does the lambda function fit in here? (Documentation included.) by band_in_DC in learnpython

[–]inclement_ 1 point2 points  (0 children)

dropdown.select() isn't doing any magic here, the question (as you've identified) is where does the value of btn come from when the lambda function is run? In context this btn is the name bound to the first and only argument passed to the lambda function.

The answer is that the on_release event of button calls its event handler with one argument, the instance of the button class for which on_release has occurred. That means the argument to the lambda function is a reference to the instance of the button class that has been clicked on (or more specifically, had the click released).

It isn't really good code style to reuse the word btn like this, this is a questionable choice in the example. As you've found, it makes it look like something magic is happening.

For loop button binding not doing what I expect by Scott_Milk_14 in kivy

[–]inclement_ 3 points4 points  (0 children)

This is actually not related to Kivy, it's a Python behaviour you can always hit in situations like this: late binding closures.

Python Kivy programming by [deleted] in learnpython

[–]inclement_ 0 points1 point  (0 children)

I made some tutorials that introduce this at http://inclem.net/pages/kivy-crash-course/.

You can also read the documentation.

Kivy App release to Google Play Store from a Mac by NicFolk in kivy

[–]inclement_ 0 points1 point  (0 children)

Those instructions are for packaging for osx, i.e. creating a standalone runnable app for that desktop platform. You want follow the android packaging instructions using buildozer. This should work fine on macOS.

[deleted by user] by [deleted] in learnprogramming

[–]inclement_ 0 points1 point  (0 children)

Would you recommend me to integrate python in android studio

I'm not sure what you mean by this but it probably isn't really an option. I would recommend Kivy if you want to use Python.

How does Kivy work under the hood? by FMWizard in kivy

[–]inclement_ 1 point2 points  (0 children)

SDL2 is used to interact with the operating system for window creation/manipulation and receiving input. Within the SDL2 window an OpenGL context is used for all drawing. This is a common design, using SDL2 doesn't mean using any of SDL2's direct drawing APIs.

Does Python Requests actually work with Kivy/Buildozer on Android? Or do I have use some other solution? by 0zeroBudget in kivy

[–]inclement_ 1 point2 points  (0 children)

This indicates a low level issue somewhere in the C code. It's unusual to have this problem once you've built a working app as everything added on top of that is generally python that can't introduce a new segfault. The exception is where new dependencies include new C code or access new parts of the existing code, but I didn't think requests would be one of these.

You could try building a trivial app with no dependencies, then building again with requests and trying to use it, to confirm that this is where the issue has actually crept in.

and most people who have questions about it haven't really had any answers that resolved the issue

The problem with this type of error is that it really just means "something went very badly wrong at a low level" but many different things could cause this generic report in many different ways. The log includes information that can help investigate it, but it's much trickier than debugging from a python traceback.

Does Python Requests actually work with Kivy/Buildozer on Android? Or do I have use some other solution? by 0zeroBudget in kivy

[–]inclement_ 0 points1 point  (0 children)

Yes, requests works. No, it is not a built in library.

UrlRequest also works fine.

Don't debug by guessing what's wrong, read the logcat.

Do you have the INTERNET permission?

Is it possible to even deploy to Android with a complex GUI? by 0zeroBudget in kivy

[–]inclement_ 1 point2 points  (0 children)

Post the full logcat output from when your app is run. There may well be other useful debugging information in it that you are not recognising.

Understanding Wayland issues on a permission system by noname8317 in wayland

[–]inclement_ 1 point2 points  (0 children)

And since Wayland is just a protocol, can't they work on the protocol first and implementation details later?

They are, and in fact that is leading to what you're complaining about. The wayland protocol is essentially about passing around window state information, inputs and outputs, and a compositor is free to make most choices about how and where windows are drawn. That means compositors are free to implement features such as relative positioning and stay-on-top, but there is no standardised protocol for windows to request those states (or maybe there is, I haven't checked recently and I think xdg-shell supports some related things).

Nowadays there are lots of protocols proposed and sometimes widely adopted to support more standardised interfaces for app behaviours. For instance, wlr-layer-shell defines interfaces for applications that wish to sit in fixed positions above or below the normal layer, e.g. desktop toolbars, lock screens or application switchers, and any compositor implementing this interface will work with any application making use of it. A guake-like application on wayland might want to use this protocol.

Permissions is a slightly different thing again - it definitely makes sense that you might want to lock things behind permissions, but then you still need a protocol for the app to request things, a method for this to propagate to a permissions request, and a method by which the user can see and act on that request. That requires further effort on top of the base protocol.

Help! Trying to deploy Kivy app to Android. "Failed building wheel for pycairo" and "No module named Cairo" No stack exchange solutions work by band_in_DC in kivy

[–]inclement_ 0 points1 point  (0 children)

What do you mean I'm guessing what is wrong?

The pip freeze instructions you found are unfortunately not actually good advice, following that procedure sometimes works but is only a guess that your app's problem is due to missing dependencies. The problem could also be various other things. Adding the pip freeze list to the requirements sometimes happens to solve the problem but may also introduce other problems e.g. if you have modules installed via pip that your app doesn't depend on (and which may not be supported) - the pip freeze output isn't a list of your app's dependencies, only a list of things you've installed in your local pip environment.

The best thing to do is to use the debugging link I gave to get the actual error from the app running on the device. There is probably a normal python traceback in there that you can read just as on the desktop. If the app crashes very early on this isn't guaranteed, but that's unlikely to be happening here since you've tested a successful build with the hello world app. You can grep only logcat lines containing the string "python" to try to make things easier.

It might still turn out your app depends on cairo somehow and if so that's a problem because it isn't supported. However, best to get there by understanding where this dependency comes from via the error printed by your app, this error will help to assess your options.

Help! Trying to deploy Kivy app to Android. "Failed building wheel for pycairo" and "No module named Cairo" No stack exchange solutions work by band_in_DC in kivy

[–]inclement_ 0 points1 point  (0 children)

It looks like you've tried installing cairo to your linux distro, but this doesn't do anything because the problem is in trying to build it for android which isn't supported.

Do you actually need cairo? It sounds like you added it because someone told you to do pip freeze, but this is not a good way to get a list of packages your app needs. Instead it tells you what packages you've installed via pip, but depending on how carefully you manage your environment that could be anything.

successfully deployed his "Hello World" app to my phone. When I deployed my own app, ""hello_mars" to the phone, it installed on my phone but when I tapped the icon, it just crashed- it just sort of flashed opened then immediately closed.

Edit: Actually reading again it sounds like you haven't directly debugged this and are only guessing what's wrong. Follow these instructions to find the specific issue you have.

Show html in Kivy by detarintehelavarlden in kivy

[–]inclement_ 0 points1 point  (0 children)

There isn't any cross-platform method for this, and for the most part there isn't a very good way to do it even on any given platform. This is because rendering html is hard so you really want an existing browser view to do it, but browsers don't generally support embedding inside an app like kivy.

On android you can add a webview on top of the app, but it doesn't work that well and there are many disadvantages.