mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GUI: Editable combo box with most common character encodings instead of fully free form text entry. This still allows users to specify encodings that are not part of the common list.
This commit is contained in:
parent
6056da01a7
commit
38a82b049d
@ -191,7 +191,9 @@ class Widget(QWidget):
|
|||||||
if not val: val = ''
|
if not val: val = ''
|
||||||
getattr(g, 'setPlainText', g.setText)(val)
|
getattr(g, 'setPlainText', g.setText)(val)
|
||||||
getattr(g, 'setCursorPosition', lambda x: x)(0)
|
getattr(g, 'setCursorPosition', lambda x: x)(0)
|
||||||
elif isinstance(g, QComboBox) and val:
|
elif isinstance(g, QComboBox):
|
||||||
|
if not val:
|
||||||
|
val = ''
|
||||||
idx = g.findText(val, Qt.MatchFixedString)
|
idx = g.findText(val, Qt.MatchFixedString)
|
||||||
if idx < 0:
|
if idx < 0:
|
||||||
g.addItem(val)
|
g.addItem(val)
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
<iconset>
|
||||||
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -122,14 +122,8 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Input character &encoding:</string>
|
<string>Input character &encoding:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
|
||||||
<cstring>opt_input_encoding</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1" colspan="3">
|
|
||||||
<widget class="QLineEdit" name="opt_input_encoding"/>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0" colspan="2">
|
<item row="6" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_remove_paragraph_spacing">
|
<widget class="QCheckBox" name="opt_remove_paragraph_spacing">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -244,8 +238,22 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="1" colspan="3">
|
||||||
|
<widget class="EncodingComboBox" name="opt_input_encoding">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>EncodingComboBox</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>widgets.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../../../resources/images.qrc"/>
|
<include location="../../../../resources/images.qrc"/>
|
||||||
<include location="../../../../resources/images.qrc"/>
|
<include location="../../../../resources/images.qrc"/>
|
||||||
|
@ -55,10 +55,21 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="opt_output_encoding"/>
|
<widget class="EncodingComboBox" name="opt_output_encoding">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>EncodingComboBox</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>widgets.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="3" column="0">
|
<item row="4" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -27,32 +27,47 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QCheckBox" name="opt_inline_toc">
|
<widget class="QCheckBox" name="opt_inline_toc">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Inline TOC</string>
|
<string>&Inline TOC</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QCheckBox" name="opt_full_image_depth">
|
<widget class="QCheckBox" name="opt_full_image_depth">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Do not reduce image size and depth</string>
|
<string>Do not reduce image size and depth</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Output Encoding:</string>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Output Encoding:</string>
|
||||||
</item>
|
</property>
|
||||||
<item row="0" column="1">
|
</widget>
|
||||||
<widget class="QLineEdit" name="opt_output_encoding"/>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="EncodingComboBox" name="opt_output_encoding">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>EncodingComboBox</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>widgets.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -96,10 +96,21 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QLineEdit" name="opt_output_encoding"/>
|
<widget class="EncodingComboBox" name="opt_output_encoding">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>EncodingComboBox</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>widgets.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -616,6 +616,32 @@ class ComboBoxWithHelp(QComboBox):
|
|||||||
QComboBox.hidePopup(self)
|
QComboBox.hidePopup(self)
|
||||||
self.set_state()
|
self.set_state()
|
||||||
|
|
||||||
|
|
||||||
|
class EncodingComboBox(QComboBox):
|
||||||
|
'''
|
||||||
|
A combobox that holds text encodings support
|
||||||
|
by Python. This is only populated with the most
|
||||||
|
common and standard encodings. There is no good
|
||||||
|
way to programatically list all supported encodings
|
||||||
|
using encodings.aliases.aliases.keys(). It
|
||||||
|
will not work.
|
||||||
|
'''
|
||||||
|
|
||||||
|
ENCODINGS = ['', 'ascii', 'big5', 'cp1250', 'cp1251', 'cp1252', 'cp1253',
|
||||||
|
'cp1254', 'cp1255', 'cp1256', 'euc_jp', 'euc_kr', 'gb2312', 'gb18030',
|
||||||
|
'hz', 'iso2022_jp', 'iso2022_kr', 'iso8859_5', 'latin_1', 'shift_jis',
|
||||||
|
'utf_8',
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QComboBox.__init__(self, parent)
|
||||||
|
self.setEditable(True)
|
||||||
|
self.setLineEdit(EnLineEdit(self))
|
||||||
|
|
||||||
|
for item in self.ENCODINGS:
|
||||||
|
self.addItem(item)
|
||||||
|
|
||||||
|
|
||||||
class PythonHighlighter(QSyntaxHighlighter):
|
class PythonHighlighter(QSyntaxHighlighter):
|
||||||
|
|
||||||
Rules = []
|
Rules = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user