MTP: Add a way to get device info in the GUI easily

This commit is contained in:
Kovid Goyal 2012-09-24 10:25:55 +05:30
parent 50e9e1f768
commit c87508d20e
3 changed files with 49 additions and 5 deletions

View file

@ -196,6 +196,19 @@ def open(self, connected_device, library_uuid):
self.current_serial_num = snum
self.currently_connected_dev = connected_device
@synchronous
def device_debug_info(self):
ans = self.get_gui_name()
ans += '\nSerial number: %s'%self.current_serial_num
ans += '\nManufacturer: %s'%self.dev.manufacturer_name
ans += '\nModel: %s'%self.dev.model_name
ans += '\nids: %s'%(self.dev.ids,)
ans += '\nDevice version: %s'%self.dev.device_version
ans += '\nStorage:\n'
storage = sorted(self.dev.storage_info, key=operator.itemgetter('id'))
ans += pprint.pformat(storage)
return ans
@property
def filesystem_cache(self):
if self._filesystem_cache is None:

View file

@ -52,6 +52,7 @@ def __init__(self, *args, **kwargs):
self.start_thread = None
self._filesystem_cache = None
self.eject_dev_on_next_scan = False
self.current_device_data = {}
def startup(self):
self.start_thread = threading.current_thread()
@ -303,6 +304,11 @@ def open(self, connected_device, library_uuid):
_('Unknown MTP device'))
self.currently_connected_pnp_id = connected_device
self.current_serial_num = snum
self.current_device_data = devdata.copy()
def device_debug_info(self):
import pprint
return pprint.pformat(self.current_device_data)
@same_thread
def get_basic_device_information(self):

View file

@ -12,7 +12,8 @@
from PyQt4.Qt import (QWidget, QListWidgetItem, Qt, QToolButton, QLabel,
QTabWidget, QGridLayout, QListWidget, QIcon, QLineEdit, QVBoxLayout,
QPushButton, QGroupBox, QScrollArea, QHBoxLayout, QComboBox,
pyqtSignal, QSizePolicy, QDialog, QDialogButtonBox)
pyqtSignal, QSizePolicy, QDialog, QDialogButtonBox, QPlainTextEdit,
QApplication)
from calibre.ebooks import BOOK_EXTENSIONS
from calibre.gui2 import error_dialog
@ -372,15 +373,19 @@ def __init__(self, device, parent=None):
_('&Ignore the %s in calibre')%device.current_friendly_name,
self.base)
b.clicked.connect(self.ignore_device)
self.show_debug_button = bd = QPushButton(QIcon(I('debug.png')),
_('Show device information'))
bd.clicked.connect(self.show_debug_info)
l.addWidget(b, 0, 0, 1, 2)
l.addWidget(la, 1, 0, 1, 1)
l.addWidget(self.formats, 2, 0, 3, 1)
l.addWidget(self.formats, 2, 0, 4, 1)
l.addWidget(self.send_to, 2, 1, 1, 1)
l.addWidget(self.template, 3, 1, 1, 1)
l.setRowStretch(4, 10)
l.addWidget(r, 5, 0, 1, 2)
l.setRowStretch(5, 100)
l.addWidget(self.show_debug_button, 4, 1, 1, 1)
l.setRowStretch(5, 10)
l.addWidget(r, 6, 0, 1, 2)
l.setRowStretch(6, 100)
self.igntab = IgnoredDevices(self.device.prefs['history'],
self.device.prefs['blacklist'])
@ -388,6 +393,26 @@ def __init__(self, device, parent=None):
self.setCurrentIndex(1 if msg else 0)
def show_debug_info(self):
info = self.device.device_debug_info()
d = QDialog(self)
d.l = l = QVBoxLayout()
d.setLayout(l)
d.v = v = QPlainTextEdit()
d.setWindowTitle(self.device.get_gui_name())
v.setPlainText(info)
v.setMinimumWidth(400)
v.setMinimumHeight(350)
l.addWidget(v)
bb = d.bb = QDialogButtonBox(QDialogButtonBox.Close)
bb.accepted.connect(d.accept)
bb.rejected.connect(d.reject)
l.addWidget(bb)
bb.addButton(_('Copy to clipboard'), bb.ActionRole)
bb.clicked.connect(lambda :
QApplication.clipboard().setText(v.toPlainText()))
d.exec_()
def ignore_device(self):
self.igntab.ignore_device(self.device.current_serial_num)
self.base.b.setEnabled(False)