Right way to call a function from mouse callback

397 views
Skip to first unread message

Gibranlp

unread,
Oct 3, 2021, 1:45:30 PM10/3/21
to qtile-dev
What is the right implementation of mouse callback on functions?

I have already imported qtile

from libqtile import qtile

I have a working function, called by key shortcut that works fine, but hen i use mouse callbacks i just dont know how to make it work.

foo();

I have tried this so far on mouse callbacks

- mouse_callbacks={'Button1':qtile.cmd_spawn(foo)}

which gives the error:

AttributeError: 'NoneType' object has no attribute 'cmd_spawn'

I have also tried

- mouse_callbacks={'Button1':qtile.function(foo)}

and  i get the error:

 mouse_callbacks={'Button1':qtile.function(set_rand_wallpaper)},
AttributeError: 'NoneType' object has no attribute 'function'

I have tryed with lazy object which i know now that are not callable,

mouse_callbacks={'Button1':lazy.function(foo)}

Can anyone point me in the right direction?

thanks



el Paraguayo

unread,
Oct 3, 2021, 1:49:16 PM10/3/21
to qtil...@googlegroups.com
Writing it like that means you're binding the result of `qtile.cmd_spawn(foo)` to the button.

You can do it like this:
mouse_callbacks={'Button1': lambda: qtile.function(foo)}

--
You received this message because you are subscribed to the Google Groups "qtile-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qtile-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qtile-dev/51ae9659-875a-426c-8a84-1a21aa565781n%40googlegroups.com.

el Paraguayo

unread,
Oct 3, 2021, 1:51:04 PM10/3/21
to qtil...@googlegroups.com
Hit send too soon. Meant to say:
mouse_callbacks={'Button1': lambda: qtile.cmd_spawn(foo)}

I do wonder if we should allow mouse callbacks to take lazy objects too...

Gibranlp

unread,
Oct 3, 2021, 1:55:04 PM10/3/21
to qtile-dev
When using lambda:

mouse_callbacks={'Button1':lambda: qtile.cmd_spawn(foo)}

The function is just never called

Gibranlp

unread,
Oct 3, 2021, 2:08:33 PM10/3/21
to qtile-dev
I got it working now:

mouse_callbacks={'Button1':lambda: qtile.cmd_function(foo)},

the cmd_function is to be called. now it works.

Thanks



On Sunday, October 3, 2021 at 12:45:30 PM UTC-5 Gibranlp wrote:

elParaguayo

unread,
Oct 3, 2021, 2:12:57 PM10/3/21
to qtile-dev
Sorry. Missed the part in your first message where you said foo was a function. 

Glad you got it working.

Reply all
Reply to author
Forward
0 new messages