beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.35k stars 671 forks source link

Allow widgets to be added to canvas #2513

Open strandlife opened 6 months ago

strandlife commented 6 months ago

What is the problem or limitation you are having?

For a non-linear graphic editor, I need to add normal widgets to the canvas. In the Qt program, widgets in the canvas have more possibilities. Like clicking and moving. But canvas special widgets either don't have these facilities or we didn't find them... editors_nla_tracks_example

Describe the solution you'd like

context.append(Button , Box, ....)

Describe alternatives you've considered

Rect.on_press = .....

Additional context

No response

freakboy3742 commented 6 months ago

Thanks for the suggestion. This could be very difficult to achieve - especially the layout, as it's not clear how widget sizing would work in a canvas context. However, I can see how it could be useful (if nothing else, it would be one way to achieve a GUI layout editor).

strandlife commented 6 months ago

Is it possible to implement the following codes?

context.rect.on_press = press
def press(widget, w, h):
       # widget return  rect . no canvas
       bt_w = w
       bt_h = h

Is it possible to move the widgets with the mouse? In Qt this can be done by simply enabling a simple feature. Will the feature (adding widgets to the canvas) be added to the program in the future?

freakboy3742 commented 6 months ago

Give that you can't add a widget to a canvas, I'm not sure why you'd be able to move them on a canvas...

As for whether this feature will be added in the future? Maybe.

Toga is an Open Source project, so it entirely depends on someone submitting a PR that implements the feature. I can't control anyone else's TODO list; but I can tell you it's not high on my own TODO list at the moment. It might be a higher priority for me in the future. If this is a high priority feature for someone else, then they are free to submit a PR, and someone from the project (possibly myself) will review that PR.

strandlife commented 6 months ago

Our English is not good. It was difficult for us to write these messages... Anyway, thanks for your reply.

To make an interactive graphic environment, is there another solution in the Toga library?

strandlife commented 6 months ago

What do you mean by PR?

freakboy3742 commented 6 months ago

A PR is a Pull Request - the mechanism by which you contribute to an open source project on Github. You can see the current list of open Toga pull requests here. These are features that core developers, and other community members have proposed for inclusion in Toga.

As for other options for building an interactive graphic environment - I can't offer any better options at present.

strandlife commented 6 months ago

self.view.context.append(bt) error: AttributeError: 'Button' object has no attribute '_draw'

I need to see how to solve the above problem? I think I should request that they implement the _draw function for these widgets.

freakboy3742 commented 6 months ago

I'm afraid I don't have any insight for you here. _draw() is the API that is used to render canvas drawing objects in a given context; however, I strongly suspect that won't be the mechanism that you need to use to add a widget to a canvas, because a widget isn't a 2D drawable. As I noted in my original comment - this will be a very difficult feature to achieve.