Get rid of another .ui file

This commit is contained in:
Kovid Goyal 2016-06-19 19:20:41 +05:30
parent e4b77688bc
commit 86216f0092
2 changed files with 152 additions and 493 deletions

View File

@ -11,13 +11,16 @@ from datetime import timedelta
import calendar, textwrap import calendar, textwrap
from collections import OrderedDict from collections import OrderedDict
from PyQt5.Qt import (QDialog, Qt, QTime, QObject, QMenu, QHBoxLayout, from PyQt5.Qt import (
QAction, QIcon, QMutex, QTimer, pyqtSignal, QWidget, QGridLayout, QDialog, Qt, QTime, QObject, QMenu, QHBoxLayout, QAction, QIcon, QMutex,
QCheckBox, QTimeEdit, QLabel, QLineEdit, QDoubleSpinBox, QSize, QTimer, pyqtSignal, QWidget, QGridLayout, QCheckBox, QTimeEdit, QLabel,
QTreeView, QSizePolicy) QLineEdit, QDoubleSpinBox, QSize, QTreeView, QSizePolicy, QToolButton,
QScrollArea, QFrame, QVBoxLayout, QTabWidget, QSpacerItem, QGroupBox,
QRadioButton, QStackedWidget, QSpinBox, QPushButton, QDialogButtonBox
)
from calibre.gui2.dialogs.scheduler_ui import Ui_Dialog
from calibre.gui2 import config as gconf, error_dialog, gprefs from calibre.gui2 import config as gconf, error_dialog, gprefs
from calibre.gui2.search_box import SearchBox2
from calibre.web.feeds.recipes.model import RecipeModel from calibre.web.feeds.recipes.model import RecipeModel
from calibre.ptempfile import PersistentTemporaryFile from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.date import utcnow from calibre.utils.date import utcnow
@ -44,6 +47,7 @@ class RecipesView(QTreeView):
QTreeView.currentChanged(self, current, previous) QTreeView.currentChanged(self, current, previous)
self.parent().current_changed(current, previous) self.parent().current_changed(current, previous)
# Time/date widgets {{{
class Base(QWidget): class Base(QWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
@ -192,9 +196,10 @@ class EveryXDays(Base):
def schedule(self): def schedule(self):
schedule = self.interval.value() schedule = self.interval.value()
return 'interval', schedule return 'interval', schedule
# }}}
class SchedulerDialog(QDialog, Ui_Dialog): class SchedulerDialog(QDialog):
SCHEDULE_TYPES = OrderedDict([ SCHEDULE_TYPES = OrderedDict([
('days_of_week', DaysOfWeek), ('days_of_week', DaysOfWeek),
@ -206,52 +211,160 @@ class SchedulerDialog(QDialog, Ui_Dialog):
def __init__(self, recipe_model, parent=None): def __init__(self, recipe_model, parent=None):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.setupUi(self) self.commit_on_change = True
self.previous_urn = None
self.setWindowIcon(QIcon(I('scheduler.png')))
self.setWindowTitle(_("Schedule news download"))
self.l = l = QGridLayout(self)
# Left panel
self.h = h = QHBoxLayout()
l.addLayout(h, 0, 0, 1, 1)
self.search = s = SearchBox2(self)
self.search.initialize('scheduler_search_history')
self.search.setMinimumContentsLength(15)
self.go_button = b = QToolButton(self)
b.setText(_("Go"))
b.clicked.connect(self.search.do_search)
self.clear_search_button = cb = QToolButton(self)
self.clear_search_button.clicked.connect(self.search.clear_clicked)
cb.setIcon(QIcon(I('clear_left.png')))
h.addWidget(s), h.addWidget(b), h.addWidget(cb)
self.recipes = RecipesView(self)
l.addWidget(self.recipes, 1, 0, 1, 1)
self.recipe_model = recipe_model self.recipe_model = recipe_model
self.recipe_model.do_refresh() self.recipe_model.do_refresh()
self.count_label.setText( self.recipes.setModel(self.recipe_model)
# NOTE: Number of news sources self.recipes.setFocus(Qt.OtherFocusReason)
_('%s news sources') % self.recipe_model.showing_count) self.count_label = la = QLabel(_('%s news sources') % self.recipe_model.showing_count)
la.setAlignment(Qt.AlignCenter)
l.addWidget(la, 2, 0, 1, 1)
self.search.search.connect(self.recipe_model.search)
self.recipe_model.searched.connect(self.search.search_done, type=Qt.QueuedConnection)
self.recipe_model.searched.connect(self.search_done)
# Right Panel
self.scroll_area = sa = QScrollArea(self)
self.l.addWidget(sa, 0, 1, 2, 1)
sa.setFrameShape(QFrame.NoFrame)
sa.setWidgetResizable(True)
self.scroll_area_contents = sac = QWidget(self)
sa.setWidget(sac)
sac.v = v = QVBoxLayout(sac)
v.setContentsMargins(0, 0, 0, 0)
self.detail_box = QTabWidget(self)
self.detail_box.setVisible(False)
self.detail_box.setCurrentIndex(0)
v.addWidget(self.detail_box)
v.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
# First Tab (scheduling)
self.tab = QWidget()
self.detail_box.addTab(self.tab, _("&Schedule"))
self.tab.v = vt = QVBoxLayout(self.tab)
vt.setContentsMargins(0, 0, 0, 0)
self.blurb = la = QLabel('blurb')
la.setWordWrap(True), la.setOpenExternalLinks(True)
vt.addWidget(la)
vt.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
self.frame = f = QFrame(self.tab)
vt.addWidget(f)
f.setFrameShape(f.StyledPanel)
f.setFrameShadow(f.Raised)
f.v = vf = QVBoxLayout(f)
self.schedule = s = QCheckBox(_("&Schedule for download:"), f)
self.schedule.stateChanged[int].connect(self.toggle_schedule_info)
vf.addWidget(s)
f.h = h = QHBoxLayout()
vf.addLayout(h)
self.days_of_week = QRadioButton(_("&Days of week"), f)
self.days_of_month = QRadioButton(_("Da&ys of month"), f)
self.every_x_days = QRadioButton(_("Every &x days"), f)
self.days_of_week.setChecked(True)
h.addWidget(self.days_of_week), h.addWidget(self.days_of_month), h.addWidget(self.every_x_days)
self.schedule_stack = ss = QStackedWidget(f)
self.schedule_widgets = [] self.schedule_widgets = []
for key in reversed(self.SCHEDULE_TYPES): for key in reversed(self.SCHEDULE_TYPES):
self.schedule_widgets.insert(0, self.SCHEDULE_TYPES[key](self)) self.schedule_widgets.insert(0, self.SCHEDULE_TYPES[key](self))
self.schedule_stack.insertWidget(0, self.schedule_widgets[0]) self.schedule_stack.insertWidget(0, self.schedule_widgets[0])
vf.addWidget(ss)
self.search.initialize('scheduler_search_history') self.last_downloaded = la = QLabel(f)
self.search.setMinimumContentsLength(15) la.setWordWrap(True)
self.search.search.connect(self.recipe_model.search) vf.addWidget(la)
self.recipe_model.searched.connect(self.search.search_done, vt.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
type=Qt.QueuedConnection) self.account = acc = QGroupBox(self.tab)
self.recipe_model.searched.connect(self.search_done) acc.setTitle(_("&Account"))
self.recipes = RecipesView(self) vt.addWidget(acc)
self.gridLayout.addWidget(self.recipes, 1, 0, 1, 1) acc.g = g = QGridLayout(acc)
self.recipes.setFocus(Qt.OtherFocusReason) acc.unla = la = QLabel(_("&Username:"))
self.commit_on_change = True self.username = un = QLineEdit(self)
self.previous_urn = None la.setBuddy(un)
g.addWidget(la), g.addWidget(un, 0, 1)
self.recipes.setModel(self.recipe_model) acc.pwla = la = QLabel(_("&Password:"))
self.detail_box.setVisible(False) self.password = pw = QLineEdit(self)
self.download_button = self.buttonBox.addButton(_('&Download now'), pw.setEchoMode(QLineEdit.Password), la.setBuddy(pw)
self.buttonBox.ActionRole) g.addWidget(la), g.addWidget(pw, 1, 1)
self.download_button.setIcon(QIcon(I('arrow-down.png'))) self.show_password = spw = QCheckBox(_("&Show password"), self.account)
self.download_button.setVisible(False) spw.stateChanged[int].connect(self.set_pw_echo_mode)
g.addWidget(spw, 2, 0, 1, 2)
self.rla = la = QLabel(_("For the scheduling to work, you must leave calibre running."))
vt.addWidget(la)
for b, c in self.SCHEDULE_TYPES.iteritems(): for b, c in self.SCHEDULE_TYPES.iteritems():
b = getattr(self, b) b = getattr(self, b)
b.toggled.connect(self.schedule_type_selected) b.toggled.connect(self.schedule_type_selected)
b.setToolTip(textwrap.dedent(c.HELP)) b.setToolTip(textwrap.dedent(c.HELP))
self.days_of_week.setChecked(True)
self.schedule.stateChanged[int].connect(self.toggle_schedule_info) # Second tab (advanced settings)
self.show_password.stateChanged[int].connect(self.set_pw_echo_mode) self.tab2 = t2 = QWidget()
self.download_button.clicked.connect(self.download_clicked) self.detail_box.addTab(self.tab2, _("&Advanced"))
self.download_all_button.clicked.connect( self.tab2.g = g = QGridLayout(t2)
self.download_all_clicked) g.setContentsMargins(0, 0, 0, 0)
self.add_title_tag = tt = QCheckBox(_("Add &title as tag"), t2)
g.addWidget(tt, 0, 0, 1, 2)
t2.la = la = QLabel(_("&Extra tags:"))
self.custom_tags = ct = QLineEdit(self)
la.setBuddy(ct)
g.addWidget(la), g.addWidget(ct, 1, 1)
t2.la2 = la = QLabel(_("&Keep at most:"))
la.setToolTip(_("Maximum number of copies (issues) of this recipe to keep. Set to 0 to keep all (disable)."))
self.keep_issues = ki = QSpinBox(t2)
tt.toggled['bool'].connect(self.keep_issues.setEnabled)
ki.setMaximum(100000), la.setBuddy(ki)
ki.setToolTip(_(
"<p>When set, this option will cause calibre to keep, at most, the specified number of issues"
" of this periodical. Every time a new issue is downloaded, the oldest one is deleted, if the"
" total is larger than this number.\n<p>Note that this feature only works if you have the"
" option to add the title as tag checked, above.\n<p>Also, the setting for deleting periodicals"
" older than a number of days, below, takes priority over this setting."))
ki.setSpecialValueText(_("all issues")), ki.setSuffix(_(" issues"))
g.addWidget(la), g.addWidget(ki, 2, 1)
si = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
g.addItem(si, 3, 1, 1, 1)
self.old_news.setValue(gconf['oldest_news']) # Bottom area
self.hb = h = QHBoxLayout()
self.go_button.clicked.connect(self.search.do_search) self.l.addLayout(h, 2, 1, 1, 1)
self.clear_search_button.clicked.connect(self.search.clear_clicked) self.labt = la = QLabel(_("Delete downloaded &news older than:"))
self.old_news = on = QSpinBox(self)
on.setToolTip(_(
"<p>Delete downloaded news older than the specified number of days. Set to zero to disable.\n"
"<p>You can also control the maximum number of issues of a specific periodical that are kept"
" by clicking the Advanced tab for that periodical above."))
on.setSpecialValueText(_("never delete")), on.setSuffix(_(" days"))
on.setMaximum(1000), la.setBuddy(on)
on.setValue(gconf['oldest_news'])
h.addWidget(la), h.addWidget(on)
self.download_all_button = b = QPushButton(QIcon(I('news.png')), _("Download &all scheduled"), self)
b.setToolTip(_("Download all scheduled news sources at once"))
b.clicked.connect(self.download_all_clicked)
self.l.addWidget(b, 3, 0, 1, 1)
self.bb = bb = QDialogButtonBox(QDialogButtonBox.Save, self)
bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
self.download_button = b = bb.addButton(_('&Download now'), bb.ActionRole)
b.setIcon(QIcon(I('arrow-down.png'))), b.setVisible(False)
b.clicked.connect(self.download_clicked)
self.l.addWidget(bb, 3, 1, 1, 1)
geom = gprefs.get('scheduler_dialog_geometry') geom = gprefs.get('scheduler_dialog_geometry')
if geom is not None: if geom is not None:

View File

@ -1,454 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>792</width>
<height>575</height>
</rect>
</property>
<property name="windowTitle">
<string>Schedule news download</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/scheduler.png</normaloff>:/images/scheduler.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="SearchBox2" name="search"/>
</item>
<item>
<widget class="QToolButton" name="go_button">
<property name="text">
<string>Go</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="clear_search_button">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/clear_left.png</normaloff>:/images/clear_left.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1" rowspan="2">
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>581</width>
<height>444</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="detail_box">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>&amp;Schedule</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="blurb">
<property name="text">
<string>blurb</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="schedule">
<property name="text">
<string>&amp;Schedule for download:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="days_of_week">
<property name="text">
<string>&amp;Days of week</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="days_of_month">
<property name="text">
<string>Da&amp;ys of month</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="every_x_days">
<property name="text">
<string>Every &amp;x days</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="schedule_stack"/>
</item>
<item>
<widget class="QLabel" name="last_downloaded">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="account">
<property name="title">
<string>&amp;Account</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QLineEdit" name="username"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Username:</string>
</property>
<property name="buddy">
<cstring>username</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>&amp;Password:</string>
</property>
<property name="buddy">
<cstring>password</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="show_password">
<property name="text">
<string>&amp;Show password</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>For the scheduling to work, you must leave calibre running.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>&amp;Advanced</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="add_title_tag">
<property name="text">
<string>Add &amp;title as tag</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>&amp;Extra tags:</string>
</property>
<property name="buddy">
<cstring>custom_tags</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_6">
<property name="toolTip">
<string>Maximum number of copies (issues) of this recipe to keep. Set to 0 to keep all (disable).</string>
</property>
<property name="text">
<string>&amp;Keep at most:</string>
</property>
<property name="buddy">
<cstring>keep_issues</cstring>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="keep_issues">
<property name="toolTip">
<string>&lt;p&gt;When set, this option will cause calibre to keep, at most, the specified number of issues of this periodical. Every time a new issue is downloaded, the oldest one is deleted, if the total is larger than this number.
&lt;p&gt;Note that this feature only works if you have the option to add the title as tag checked, above.
&lt;p&gt;Also, the setting for deleting periodicals older than a number of days, below, takes priority over this setting.</string>
</property>
<property name="specialValueText">
<string>all issues</string>
</property>
<property name="suffix">
<string> issues</string>
</property>
<property name="maximum">
<number>100000</number>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="custom_tags"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="count_label">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Delete downloaded &amp;news older than:</string>
</property>
<property name="buddy">
<cstring>old_news</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="old_news">
<property name="toolTip">
<string>&lt;p&gt;Delete downloaded news older than the specified number of days. Set to zero to disable.
&lt;p&gt;You can also control the maximum number of issues of a specific periodical that are kept by clicking the Advanced tab for that periodical above.</string>
</property>
<property name="specialValueText">
<string>never delete</string>
</property>
<property name="suffix">
<string> days</string>
</property>
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="download_all_button">
<property name="toolTip">
<string>Download all scheduled news sources at once</string>
</property>
<property name="text">
<string>Download &amp;all scheduled</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/news.png</normaloff>:/images/news.png</iconset>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SearchBox2</class>
<extends>QComboBox</extends>
<header>calibre/gui2/search_box.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../../resources/images.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>762</x>
<y>570</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>762</x>
<y>570</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>add_title_tag</sender>
<signal>toggled(bool)</signal>
<receiver>keep_issues</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>508</x>
<y>42</y>
</hint>
<hint type="destinationlabel">
<x>577</x>
<y>108</y>
</hint>
</hints>
</connection>
</connections>
</ui>