![]() |
#1 |
Member
![]() Posts: 18
Karma: 10
Join Date: Mar 2018
Device: Kindle
|
Button triggering automatically
I've just added a new button to my plug-in interface. For some reason, when I open the plug-in, that button's function fires off automatically. Here's my code for defining the button:
Code:
self.unshelve_TSBL1_button = QPushButton( 'Unshelve from TSBL 1', self) self.unshelve_TSBL1_button.clicked.connect(self.doUnshelve('status:TSBL1shelved')) self.l.addWidget(self.unshelve_TSBL1_button) Any ideas? |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,185
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
|
try this instead
Code:
from functools import partial self.unshelve_TSBL1_button = QPushButton( 'Unshelve from TSBL 1', self) self.unshelve_TSBL1_button.clicked.connect(partial(self.doUnshelve,'status:TSBL1shelved')) self.l.addWidget(self.unshelve_TSBL1_button) |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() Posts: 18
Karma: 10
Join Date: Mar 2018
Device: Kindle
|
That worked! Thanks so much!
If it's not a hassle, could I trouble you for a quick explanation? Or an explanation to read somewhere else? Thanks again! |
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,185
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
|
You are not supposed to call a function when connecting to a siganl, you just reference the function object and it will be called later when the signal is emitted. So when you do it as below (the wrong way), you are calling the function:
Code:
button.clicked.connect(myfunction()) Code:
button.clicked.connect(myfunction) But what if the function expects additional arguments? how to pass them without calling the function? Here is where the partial function comes into play, it takes the function and the args and makes new function like object that have the args built inside (sort of) it so that you do not need to supply them. Simply searching for "python partial" in google will give enough material for further explanation. |
![]() |
![]() |
![]() |
#5 |
Member
![]() Posts: 18
Karma: 10
Join Date: Mar 2018
Device: Kindle
|
Great, thanks. I really appreciate the time and explanation. I'll keep reading.
|
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
K5 Can a Kindle Touch battery die without triggering the "Critical Battery" error? | WaseemAlkurdi | Kindle Developer's Corner | 32 | 04-17-2021 05:37 AM |
Glo Triggering a library refresh automatically | anarcat | Kobo Developer's Corner | 58 | 10-08-2019 12:17 PM |
Note Case Triggering Auto-Sleep when Open | Ragamuffyn | Onyx Boox | 16 | 07-16-2018 05:32 PM |
[KT]Turn store button on search bar to browser button | aditya3098 | Kindle Developer's Corner | 74 | 05-19-2017 08:33 PM |
Phone triggering sleep mode-kobo glo HD | Alice98 | Kobo Reader | 4 | 03-05-2017 07:11 AM |