-
Notifications
You must be signed in to change notification settings - Fork 70
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
No 'label' or 'icon' property when defined in custom class #253
Comments
I have no idea about this code (CC @TingPing do you happen to have some more clue here?). |
Adding a function to |
@RossComputerGuy I tried to do what the LGI documentation says and it didn't work. However, there is still another way to do this, by doing it just as it is done in C: local lgi = require('lgi')
local Gtk = lgi.Gtk
local GObject = lgi.GObject
local Expidus = lgi.package('Expidus')
Expidus:class('AppButton', Gtk.FlowBoxChild)
function Expidus.AppButton:_class_init(klass)
function klass:set_property(id, value, pspec)
if id == 1 then
self.priv.label = value:get_string()
elseif id == 2 then
self.priv.icon = value:get_string()
else
GObject.OBJECT_WARN_INVALID_PROPERTY_ID(self, id, pspec)
end
end
function klass:get_property(id, value, pspec)
if id == 1 then
value:set_string(self.priv.label)
elseif id == 2 then
value:set_string(self.priv.icon)
else
GObject.OBJECT_WARN_INVALID_PROPERTY_ID(self, id, pspec)
end
end
klass:install_property(1, GObject.ParamSpecString(
"label", "Label", "Application label", "App",
{ 'READWRITE', 'CONSTRUCT' }
)
)
klass:install_property(2, GObject.ParamSpecString(
"icon", "Icon", "Application icon", "app-icon-unknown",
{ 'READWRITE', 'CONSTRUCT' }
)
)
end
local btn = Expidus.AppButton{
label = "ExpBtn",
icon = "go-home-symbolic"
}
print(btn.label, btn.icon)
-- Default values:
print(Expidus.AppButton().label)
print(Expidus.AppButton().icon) Note that with this method it is mandatory to assign the functions |
Please, close this if no activity or is solved |
@M1que4s but we need it fixed |
@RossComputerGuy I left an answer with a solution to the problem above |
This sounds more like a temporary fix until this issue is fixed. |
@RossComputerGuy The way in which properties are created with LGI is specific to the library. On the other hand, the way I have done it is the way it is done according to GObject, that is, more C-style. I wouldn't say it's a temporary solution |
Well the way it is documented should work because its documented as a feature. |
@RossComputerGuy Here you can see how subclassing is done with GObject in C: https://developer.gnome.org/SubclassGObject/ |
Yes, you are right. However, I'm honestly not sure why it doesn't work |
@RossComputerGuy Anyway, I hope my comment was helpful |
My custom class: https://github.com/ExpidusOS/shell/blob/master/share/expidus-shell/expidus/widgets/app-button.lua
Code that calls my class: https://github.com/ExpidusOS/shell/blob/master/share/expidus-shell/expidus/launcher.lua
Result:
Note that I've reduced the calling code down so I don't have the entire file pasted.
The text was updated successfully, but these errors were encountered: