mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Clean up widgets.py
This commit is contained in:
parent
10ec22ec12
commit
728e8483c9
@ -26,7 +26,7 @@ from calibre.gui2.dnd import (dnd_has_image, dnd_get_image, dnd_get_files,
|
|||||||
|
|
||||||
history = XMLConfig('history')
|
history = XMLConfig('history')
|
||||||
|
|
||||||
class ProgressIndicator(QWidget):
|
class ProgressIndicator(QWidget): # {{{
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QWidget.__init__(self, *args)
|
QWidget.__init__(self, *args)
|
||||||
@ -57,8 +57,9 @@ class ProgressIndicator(QWidget):
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
self.pi.stopAnimation()
|
self.pi.stopAnimation()
|
||||||
self.setVisible(False)
|
self.setVisible(False)
|
||||||
|
# }}}
|
||||||
|
|
||||||
class FilenamePattern(QWidget, Ui_Form):
|
class FilenamePattern(QWidget, Ui_Form): # {{{
|
||||||
|
|
||||||
changed_signal = pyqtSignal()
|
changed_signal = pyqtSignal()
|
||||||
|
|
||||||
@ -148,8 +149,9 @@ class FilenamePattern(QWidget, Ui_Form):
|
|||||||
|
|
||||||
return pat
|
return pat
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class FormatList(QListWidget):
|
class FormatList(QListWidget): # {{{
|
||||||
DROPABBLE_EXTENSIONS = BOOK_EXTENSIONS
|
DROPABBLE_EXTENSIONS = BOOK_EXTENSIONS
|
||||||
formats_dropped = pyqtSignal(object, object)
|
formats_dropped = pyqtSignal(object, object)
|
||||||
delete_format = pyqtSignal()
|
delete_format = pyqtSignal()
|
||||||
@ -188,6 +190,8 @@ class FormatList(QListWidget):
|
|||||||
else:
|
else:
|
||||||
return QListWidget.keyPressEvent(self, event)
|
return QListWidget.keyPressEvent(self, event)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class ImageDropMixin(object): # {{{
|
class ImageDropMixin(object): # {{{
|
||||||
'''
|
'''
|
||||||
Adds support for dropping images onto widgets and a context menu for
|
Adds support for dropping images onto widgets and a context menu for
|
||||||
@ -262,7 +266,7 @@ class ImageDropMixin(object): # {{{
|
|||||||
pixmap_to_data(pmap))
|
pixmap_to_data(pmap))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class ImageView(QWidget, ImageDropMixin):
|
class ImageView(QWidget, ImageDropMixin): # {{{
|
||||||
|
|
||||||
BORDER_WIDTH = 1
|
BORDER_WIDTH = 1
|
||||||
cover_changed = pyqtSignal(object)
|
cover_changed = pyqtSignal(object)
|
||||||
@ -314,8 +318,9 @@ class ImageView(QWidget, ImageDropMixin):
|
|||||||
p.drawRect(target)
|
p.drawRect(target)
|
||||||
#p.drawRect(self.rect())
|
#p.drawRect(self.rect())
|
||||||
p.end()
|
p.end()
|
||||||
|
# }}}
|
||||||
|
|
||||||
class CoverView(QGraphicsView, ImageDropMixin):
|
class CoverView(QGraphicsView, ImageDropMixin): # {{{
|
||||||
|
|
||||||
cover_changed = pyqtSignal(object)
|
cover_changed = pyqtSignal(object)
|
||||||
|
|
||||||
@ -333,7 +338,9 @@ class CoverView(QGraphicsView, ImageDropMixin):
|
|||||||
self.scene.addPixmap(pmap)
|
self.scene.addPixmap(pmap)
|
||||||
self.setScene(self.scene)
|
self.setScene(self.scene)
|
||||||
|
|
||||||
class FontFamilyModel(QAbstractListModel):
|
# }}}
|
||||||
|
|
||||||
|
class FontFamilyModel(QAbstractListModel): # {{{
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QAbstractListModel.__init__(self, *args)
|
QAbstractListModel.__init__(self, *args)
|
||||||
@ -371,7 +378,9 @@ class FontFamilyModel(QAbstractListModel):
|
|||||||
|
|
||||||
def index_of(self, family):
|
def index_of(self, family):
|
||||||
return self.families.index(family.strip())
|
return self.families.index(family.strip())
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# BasicList {{{
|
||||||
class BasicListItem(QListWidgetItem):
|
class BasicListItem(QListWidgetItem):
|
||||||
|
|
||||||
def __init__(self, text, user_data=None):
|
def __init__(self, text, user_data=None):
|
||||||
@ -404,9 +413,9 @@ class BasicList(QListWidget):
|
|||||||
def items(self):
|
def items(self):
|
||||||
for i in range(self.count()):
|
for i in range(self.count()):
|
||||||
yield self.item(i)
|
yield self.item(i)
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class LineEditECM(object): # {{{
|
||||||
class LineEditECM(object):
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Extend the context menu of a QLineEdit to include more actions.
|
Extend the context menu of a QLineEdit to include more actions.
|
||||||
@ -449,8 +458,9 @@ class LineEditECM(object):
|
|||||||
from calibre.utils.icu import capitalize
|
from calibre.utils.icu import capitalize
|
||||||
self.setText(capitalize(unicode(self.text())))
|
self.setText(capitalize(unicode(self.text())))
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class EnLineEdit(LineEditECM, QLineEdit):
|
class EnLineEdit(LineEditECM, QLineEdit): # {{{
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Enhanced QLineEdit.
|
Enhanced QLineEdit.
|
||||||
@ -459,9 +469,9 @@ class EnLineEdit(LineEditECM, QLineEdit):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class ItemsCompleter(QCompleter): # {{{
|
||||||
class ItemsCompleter(QCompleter):
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
A completer object that completes a list of tags. It is used in conjunction
|
A completer object that completes a list of tags. It is used in conjunction
|
||||||
@ -486,8 +496,9 @@ class ItemsCompleter(QCompleter):
|
|||||||
model = QStringListModel(items, self)
|
model = QStringListModel(items, self)
|
||||||
self.setModel(model)
|
self.setModel(model)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class CompleteLineEdit(EnLineEdit):
|
class CompleteLineEdit(EnLineEdit): # {{{
|
||||||
|
|
||||||
'''
|
'''
|
||||||
A QLineEdit that can complete parts of text separated by separator.
|
A QLineEdit that can complete parts of text separated by separator.
|
||||||
@ -550,8 +561,9 @@ class CompleteLineEdit(EnLineEdit):
|
|||||||
self.setText(complete_text_pat % (before_text[:cursor_pos - prefix_len], text, self.separator, after_text))
|
self.setText(complete_text_pat % (before_text[:cursor_pos - prefix_len], text, self.separator, after_text))
|
||||||
self.setCursorPosition(cursor_pos - prefix_len + len(text) + len_extra)
|
self.setCursorPosition(cursor_pos - prefix_len + len(text) + len_extra)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class EnComboBox(QComboBox):
|
class EnComboBox(QComboBox): # {{{
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Enhanced QComboBox.
|
Enhanced QComboBox.
|
||||||
@ -575,7 +587,9 @@ class EnComboBox(QComboBox):
|
|||||||
idx = 0
|
idx = 0
|
||||||
self.setCurrentIndex(idx)
|
self.setCurrentIndex(idx)
|
||||||
|
|
||||||
class CompleteComboBox(EnComboBox):
|
# }}}
|
||||||
|
|
||||||
|
class CompleteComboBox(EnComboBox): # {{{
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
EnComboBox.__init__(self, *args)
|
EnComboBox.__init__(self, *args)
|
||||||
@ -590,8 +604,9 @@ class CompleteComboBox(EnComboBox):
|
|||||||
def set_space_before_sep(self, space_before):
|
def set_space_before_sep(self, space_before):
|
||||||
self.lineEdit().set_space_before_sep(space_before)
|
self.lineEdit().set_space_before_sep(space_before)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class HistoryLineEdit(QComboBox):
|
class HistoryLineEdit(QComboBox): # {{{
|
||||||
|
|
||||||
lost_focus = pyqtSignal()
|
lost_focus = pyqtSignal()
|
||||||
|
|
||||||
@ -638,7 +653,9 @@ class HistoryLineEdit(QComboBox):
|
|||||||
QComboBox.focusOutEvent(self, e)
|
QComboBox.focusOutEvent(self, e)
|
||||||
self.lost_focus.emit()
|
self.lost_focus.emit()
|
||||||
|
|
||||||
class ComboBoxWithHelp(QComboBox):
|
# }}}
|
||||||
|
|
||||||
|
class ComboBoxWithHelp(QComboBox): # {{{
|
||||||
'''
|
'''
|
||||||
A combobox where item 0 is help text. CurrentText will return '' for item 0.
|
A combobox where item 0 is help text. CurrentText will return '' for item 0.
|
||||||
Be sure to always fetch the text with currentText. Don't use the signals
|
Be sure to always fetch the text with currentText. Don't use the signals
|
||||||
@ -685,8 +702,9 @@ class ComboBoxWithHelp(QComboBox):
|
|||||||
QComboBox.hidePopup(self)
|
QComboBox.hidePopup(self)
|
||||||
self.set_state()
|
self.set_state()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class EncodingComboBox(QComboBox):
|
class EncodingComboBox(QComboBox): # {{{
|
||||||
'''
|
'''
|
||||||
A combobox that holds text encodings support
|
A combobox that holds text encodings support
|
||||||
by Python. This is only populated with the most
|
by Python. This is only populated with the most
|
||||||
@ -709,8 +727,9 @@ class EncodingComboBox(QComboBox):
|
|||||||
for item in self.ENCODINGS:
|
for item in self.ENCODINGS:
|
||||||
self.addItem(item)
|
self.addItem(item)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class PythonHighlighter(QSyntaxHighlighter):
|
class PythonHighlighter(QSyntaxHighlighter): # {{{
|
||||||
|
|
||||||
Rules = []
|
Rules = []
|
||||||
Formats = {}
|
Formats = {}
|
||||||
@ -948,6 +967,9 @@ class PythonHighlighter(QSyntaxHighlighter):
|
|||||||
QSyntaxHighlighter.rehighlight(self)
|
QSyntaxHighlighter.rehighlight(self)
|
||||||
QApplication.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# Splitter {{{
|
||||||
class SplitterHandle(QSplitterHandle):
|
class SplitterHandle(QSplitterHandle):
|
||||||
|
|
||||||
double_clicked = pyqtSignal(object)
|
double_clicked = pyqtSignal(object)
|
||||||
@ -1179,4 +1201,5 @@ class Splitter(QSplitter):
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user