From 11253f23b86c49b791a77ece1c5504fad7345544 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 26 Jul 2018 10:22:02 +0530 Subject: [PATCH] More work on lambda slots --- src/calibre/gui2/actions/add.py | 16 +++++++++------- src/calibre/gui2/gestures.py | 7 +++---- src/calibre/gui2/jobs.py | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index d602f311b2..0eae6277a0 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -65,10 +65,12 @@ class AddAction(InterfaceAction): 'e-book file is a different book)')).triggered.connect( self.add_recursive_multiple) arm = self.add_archive_menu = self.add_menu.addMenu(_('Add multiple books from archive (ZIP/RAR)')) - self.create_menu_action(arm, 'recursive-single-archive', _( - 'One book per directory in the archive')).triggered.connect(partial(self.add_archive, True)) - self.create_menu_action(arm, 'recursive-multiple-archive', _( - 'Multiple books per directory in the archive')).triggered.connect(partial(self.add_archive, False)) + connect_lambda(self.create_menu_action( + arm, 'recursive-single-archive', _('One book per directory in the archive')).triggered, + self, lambda self: self.add_archive(True)) + connect_lambda(self.create_menu_action( + arm, 'recursive-multiple-archive', _('Multiple books per directory in the archive')).triggered, + self, lambda self: self.add_archive(False)) self.add_menu.addSeparator() ma('add-empty', _('Add empty book (Book entry with no formats)'), shortcut='Shift+Ctrl+E').triggered.connect(self.add_empty) @@ -79,9 +81,9 @@ class AddAction(InterfaceAction): arm = self.add_archive_menu = self.add_menu.addMenu(_('Add an empty file to selected book records')) from calibre.ebooks.oeb.polish.create import valid_empty_formats for fmt in sorted(valid_empty_formats): - self.create_menu_action(arm, 'add-empty-' + fmt, - _('Add empty {}').format(fmt.upper())).triggered.connect( - partial(self.add_empty_format, fmt)) + connect_lambda(self.create_menu_action( + arm, 'add-empty-' + fmt, _('Add empty {}').format(fmt.upper())).triggered, + self, lambda self: self.add_empty_format(fmt)) self.add_menu.addSeparator() ma('add-config', _('Control the adding of books'), triggered=self.add_config) diff --git a/src/calibre/gui2/gestures.py b/src/calibre/gui2/gestures.py index 7c2d6cb8ab..81afadbbd8 100644 --- a/src/calibre/gui2/gestures.py +++ b/src/calibre/gui2/gestures.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals import sys, os -from functools import partial from PyQt5.Qt import ( QApplication, QEvent, QMouseEvent, QObject, QPointF, QScroller, Qt, QTouchDevice, @@ -156,9 +155,9 @@ class GestureManager(QObject): self.state = State() self.state.tapped.connect(self.handle_tap, type=Qt.QueuedConnection) # has to be queued otherwise QApplication.keyboardModifiers() does not work self.state.flicking.connect(self.handle_flicking) - self.state.tap_hold_started.connect(partial(self.handle_tap_hold, 'start')) - self.state.tap_hold_updated.connect(partial(self.handle_tap_hold, 'update')) - self.state.tap_hold_finished.connect(partial(self.handle_tap_hold, 'end')) + connect_lambda(self.state.tap_hold_started, self, lambda self, tp: self.handle_tap_hold('start', tp)) + connect_lambda(self.state.tap_hold_updated, self, lambda self, tp: self.handle_tap_hold('update', tp)) + connect_lambda(self.state.tap_hold_finished, self, lambda self, tp: self.handle_tap_hold('end', tp)) self.evmap = {QEvent.TouchBegin: 'start', QEvent.TouchUpdate: 'update', QEvent.TouchEnd: 'end'} self.last_tap_at = 0 if touch_supported: diff --git a/src/calibre/gui2/jobs.py b/src/calibre/gui2/jobs.py index b4bd9e74e0..b266c28b72 100644 --- a/src/calibre/gui2/jobs.py +++ b/src/calibre/gui2/jobs.py @@ -623,8 +623,7 @@ class JobsDialog(QDialog, Ui_JobsDialog): self.search.initialize('jobs_search_history', help_text=_('Search for a job by name')) self.search.search.connect(self.find) - self.search_button.clicked.connect(lambda : - self.find(self.search.current_text)) + connect_lambda(self.search_button.clicked, self, lambda self: self.find(self.search.current_text)) self.restore_state() def restore_state(self):