-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: GTK::Simple::GladeApp #16
Conversation
Hi, I've just started poking around with GTK::Simple in order to implement a couple of things that I needed for something I have in mind. I think that there most definitely would be interest in this (despite the lack of discussion here,) unfortunately the PR has somewhat bit-rotted in the meantime: would it be possible for you to fix the merge conflicts, I'm quite happy to do so if you've already lost interest. I think once it merges cleanly, it would be nice to bring it into a branch on this repository so that it makes it easier for other people to work on. Anyway thanks a lot. |
I don't think generating methods to handle events is the right way to go. The key idea behind this module, when I first wrote it, was that events are delivered through supplies, which are vastly more composable. |
Yeah, I'm with you on that. A UI application is almost by definition reactive. I suspect that there is a little work to do to make it easier to implement all the signals with a supply to get the appropriate payload, but that will become apparent I'm sure. But I'm fully in favour of the general idea of getting the GtkBuilder stuff in :) |
Hey folks, thanks for taking interest. (I've been following jnthn's blog so I know he's been busy delivering goodies) Can you provide a sample of what GtkBuilder usage would be like with supplies? I take it you object to both |
* loads `$*PROGRAM`.glade * shows `mainWindow` * connects signals to `handle-signal(Str)`
(btw, i've rebased on latest master, but didn't get a chance to test to see if it still works, hopefully tonight as modules.perl6 is down now so I can't get my machine working :( ) |
Hi, A more elaborate and possibly preferable scheme might involve each widget object in the application having it's own supply for each signal, which is basically what the existing I'll have a play with this tomorrow to see what works best. |
…slobo-glade-app
Based on finanalyst#16 The actual end-state would be more like each "handler" having an individual supply, and that would be able to receive an actual Perl object.
Hi, I think that a possible way it could be represented is by having an attribute trait (something like class MyApp is GTK::Simple::GladeApp {
has Supply $.button-one-press is gtk-signal('onButton1Pressed');
} I'm just off out shopping now but will work this up when I get back :) |
Hi, Of course the elephant in the room here is that for all except the simplest button widgets you are going to want access to the object which the signal is for (to get its status or value or whatever,) as well as the other widgets in order to set their values. I think the way to go here is to declare the objects in a similar way as for the signals, retrieve them by id (with gtk_builder_get_object) and construct the appropriate Perl objects with that, the signals can then be associated with the objects. For this there needs to be constructor candidate for the widgets that accepts the GObject (and really we can make them GWidget because all of the ones that we care about will be.) Anyway any ideas welcome, as this is going to get quite complex quite qucikly :) |
A worthwhile exercise might be to try and implement all other |
For now we assume they are buttons :(
Right off the bat, in class MyApp is GTK::Simple::GladeApp {
has $.button;
has $.second;
};
my $app = MyApp.new;
$app.button.clicked.tap({ .sensitive = False; $app.second.sensitive = True });
$app.second.clicked.tap({ $app.exit; });
$app.run; |
(btw, I hope it's kosher to update original post as a summary of where we are at, let me know if you prefer different workflow) |
If you set a type constraint on the attributes then you can inspect that in your code and use that rather than hard coding ::Button. e.g: class MyApp is GTK::Simple::GladeApp {
has GTK::Simple::Button $.button;
has GTK::Simple::Button $.second;
}; Then in the module : $sig-attr.set_value(self, $sig-attr.type.new(gtk_widget => $gobject )); Obviously there should be some check on whether it's defined. Looking good 👍 |
Even worse than that, I can't figure out how to add |
Ah yes, that old not running the BUILD from a role gag :( |
Is there a cure other than adding a Also, was hoping to ask GObject about its type, to both require less typing, or also as an early check that .p6 and .glade agree about it, but having trouble finding anything in GTK docs... |
I've add #31 to cover off doing the first thing. The second thing is difficult if not impossible directly from NativeCall as it requires some macros defined on GObject and parts of the introspection infrastructure which would only be available in compiled C programs, and it would be nice to avoid building a helper in C to do this (if only to show case the power of NativeCall on its own) |
How about manually peeking into |
My assumption was that the classes would be generated from the xml anyway :) |
Oh you mean automatic construction of my $app = Gtk::Simple::GladeApp.new('hello.glade');
$app.button1.clicked.tap({...}); # Gtk::Simple::Button $.button1 from <object class='GtkButton' id='button1'>
$app.on-window-activate-focus.tap({...}); # Supply $.on-window-activate-focus from <window><signal name='activate-focus' handler='on-window-activate-focus'> |
No generate some module from the xml, that's what the other tools do |
So, is the following how you see an example glade app: MyApp.glade <?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<signal name="activate-focus" handler="on_window1_activate_focus" swapped="no"/>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button 1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
</child>
</object>
<object class="GtkWindow" id="window2">
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">button 2
</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
</child>
</object>
</interface> $ generate-pm.pl MyApp.glade
writing MyApp/Window1.pm
writing MyApp/Window2.pm MyApp/Window1.pm class MyApp::Window1 is GTK::Simple::Window {
has GTK::Simple::Button $.button1;
has Supply $.on_window1_activate_focus is gtk-signal('on_window1_activate_focus');
} Then manually do MyApp.pm class MyApp is GTK::Simple::GladeApp {
has MyApp::Window1 $window1;
has MyApp::Window2 $window2;
method run() {
$window1.show;
$window.$button1.clicked.tap({ $window2.show(); });
}
} How would updates to .glade happen - would we have ' #-- autogenerated section ' markers, or would one subclass the generated classes to extend them? A benefit of doing it all at runtime is that you could use a simple script when you need to introspect generated classes for say documentation purposes, but you don't have to keep regenerating .pm6 every time you adjust glade with new objects and signals of interest... method main($glade_filename) {
say GTK::Simple::GladeApp.new($glade_filename).perl
} |
On further thought, doing it at runtime would be hard to retain any IDE code completion, so scrap that bit. |
Note that one option you have in Perl 6 is to do the XML -> Class translation as part of a module's |
Neat! Is there a mechanism for invalidating the precompilation cache, given that it would depend on external file? |
Any update on this one? |
I've brought it up to date with master. Now I'm blocked on #31 - the best way to add Is there a way to add it to |
Well, there's a bit of everything in here: conflicts, requests for change... Do we want this? Do we need this? |
Depends on comment from the contributors. Though it looks like there hasn't been any work on it for almost 3 years. It looks useful, though. I say this with utter bias. |
Could you maybe try and rescue it? |
Hmmm... Yeah, I could give it a try, @JJ |
On 5/12/20 2:40 PM, Xliff wrote:
Hmmm...
Yeah, I could give it a try, @JJ <https://github.com/JJ>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#16 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABRTCQMQOZWS4Q3F5B76ISTRRE7SHANCNFSM4BRSZD5Q>.
I was wondering if there is much work involved. If it isn't much, just
to make it more complete, it would be ok. I am saying this because of my
work on the Gnome::* packages. It is far from finished so there is still
a lot to be done. But, thinking about adding support for Glade in
Gtk::Simple, there is an implementation in Gnome::Gtk3::Builder to load
XML from files, strings or from resources (GTK+ resources, that is).
Just a thought you might need...
Regards,
Marcel Timmerman
P.s. the Gnome::Gtk3::Glade package might become obsolete later because
of the improvement of the above mentioned class.
|
I'm removing this PR because it's old compared to other changes, so I wouldn't know how to untangle all the conflicts. |
This is an early code dump in order to gather comments. Idea is to use
GtkBuilder
to load Glade files and connect any widgets and signals in the said interface file to appropriate attributes and Supplies defined on the Perl class. E.g. the following does what you would expect:It's currently very simplistic and makes a lot of assumptions:
$*PROGRAM
.glade"mainWindow"
TODO:
gtk_builder_get_object()
based on attribute name) - hardcoded for::Buttons
GTK::Simple::App
, or maybe add glade loading toApp
and not have a separate class?