trackma 0.6__py3.5.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +19 -0
- EGG-INFO/SOURCES.txt +37 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/entry_points.txt +8 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +10 -0
- EGG-INFO/top_level.txt +1 -0
- trackma/__init__.py +0 -0
- trackma/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/__pycache__/accounts.cpython-35.pyc +0 -0
- trackma/__pycache__/data.cpython-35.pyc +0 -0
- trackma/__pycache__/engine.cpython-35.pyc +0 -0
- trackma/__pycache__/messenger.cpython-35.pyc +0 -0
- trackma/__pycache__/tracker.cpython-35.pyc +0 -0
- trackma/__pycache__/utils.cpython-35.pyc +0 -0
- trackma/accounts.py +145 -0
- trackma/data/anilist.jpg +0 -0
- trackma/data/hb.jpg +0 -0
- trackma/data/icon.png +0 -0
- trackma/data/mal.jpg +0 -0
- trackma/data/melative.jpg +0 -0
- trackma/data/shikimori.jpg +0 -0
- trackma/data/vndb.jpg +0 -0
- trackma/data.py +597 -0
- trackma/engine.py +818 -0
- trackma/extras/AnimeInfoExtractor.py +308 -0
- trackma/extras/__init__.py +1 -0
- trackma/extras/__pycache__/AnimeInfoExtractor.cpython-35.pyc +0 -0
- trackma/extras/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/extras/__pycache__/plex.cpython-35.pyc +0 -0
- trackma/extras/plex.py +101 -0
- trackma/lib/__init__.py +0 -0
- trackma/lib/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/lib.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libanilist.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libhb.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libmal.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libmelative.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libshikimori.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libvndb.cpython-35.pyc +0 -0
- trackma/lib/lib.py +162 -0
- trackma/lib/libanilist.py +406 -0
- trackma/lib/libhb.py +237 -0
- trackma/lib/libmal.py +707 -0
- trackma/lib/libmelative.py +204 -0
- trackma/lib/libshikimori.py +340 -0
- trackma/lib/libvndb.py +375 -0
- trackma/messenger.py +42 -0
- trackma/tracker.py +390 -0
- trackma/ui/__init__.py +0 -0
- trackma/ui/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/cli.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/curses.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/gtkui.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/qtui.cpython-35.pyc +0 -0
- trackma/ui/cli.py +835 -0
- trackma/ui/curses.py +1061 -0
- trackma/ui/gtkui.py +2647 -0
- trackma/ui/qtui.py +3046 -0
- trackma/utils.py +379 -0
trackma/ui/qtui.py
ADDED
|
@@ -0,0 +1,3046 @@
|
|
|
1
|
+
# This file is part of Trackma.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
pyqt_version = 0
|
|
21
|
+
try_pyqt5 = True # TODO: Make this a program argument or something
|
|
22
|
+
|
|
23
|
+
if try_pyqt5:
|
|
24
|
+
try:
|
|
25
|
+
from PyQt5 import QtGui, QtCore
|
|
26
|
+
from PyQt5.QtGui import QIcon, QPalette
|
|
27
|
+
from PyQt5.QtWidgets import (QApplication, QMainWindow, QFormLayout,
|
|
28
|
+
QGridLayout, QHBoxLayout, QVBoxLayout,
|
|
29
|
+
QAbstractItemView, QHeaderView, QListWidget,
|
|
30
|
+
QListWidgetItem, QTabWidget, QTableWidget,
|
|
31
|
+
QTableWidgetItem, QFrame, QScrollArea,
|
|
32
|
+
QStackedWidget, QWidget, QCheckBox, QComboBox,
|
|
33
|
+
QDoubleSpinBox, QGroupBox, QLineEdit,
|
|
34
|
+
QPushButton, QRadioButton, QSpinBox,
|
|
35
|
+
QStyleOptionButton, QToolButton, QProgressBar,
|
|
36
|
+
QDialog, QColorDialog, QDialogButtonBox,
|
|
37
|
+
QFileDialog, QInputDialog, QMessageBox,
|
|
38
|
+
QAction, QActionGroup, QLabel, QMenu, QStyle,
|
|
39
|
+
QSystemTrayIcon, QStyleOptionProgressBar)
|
|
40
|
+
pyqt_version = 5
|
|
41
|
+
except ImportError:
|
|
42
|
+
print("Couldn't import Qt5 dependencies. Make sure you "
|
|
43
|
+
"installed the PyQt5 package.")
|
|
44
|
+
#sys.exit(-1)
|
|
45
|
+
if pyqt_version is 0:
|
|
46
|
+
try:
|
|
47
|
+
import sip
|
|
48
|
+
sip.setapi('QVariant', 2)
|
|
49
|
+
from PyQt4 import QtGui, QtCore
|
|
50
|
+
from PyQt4.QtGui import (QApplication, QMainWindow,
|
|
51
|
+
QFormLayout, QGridLayout, QHBoxLayout, QVBoxLayout,
|
|
52
|
+
QAbstractItemView, QHeaderView,
|
|
53
|
+
QListWidget, QListWidgetItem, QTabWidget, QTableWidget, QTableWidgetItem,
|
|
54
|
+
QFrame, QScrollArea, QStackedWidget,
|
|
55
|
+
QWidget, QCheckBox, QComboBox, QDoubleSpinBox, QGroupBox, QLineEdit,
|
|
56
|
+
QPushButton, QRadioButton, QSpinBox, QStyleOptionButton, QToolButton,
|
|
57
|
+
QProgressBar,
|
|
58
|
+
QDialog, QColorDialog, QDialogButtonBox, QFileDialog, QInputDialog, QMessageBox,
|
|
59
|
+
QAction, QActionGroup, QLabel, QMenu, QStyle,
|
|
60
|
+
QSystemTrayIcon, QIcon, QPalette)
|
|
61
|
+
from PyQt4.QtGui import QStyleOptionProgressBarV2 as QStyleOptionProgressBar
|
|
62
|
+
pyqt_version = 4
|
|
63
|
+
except ImportError:
|
|
64
|
+
print("Couldn't import Qt dependencies. Make sure you "
|
|
65
|
+
"installed the PyQt4 package.")
|
|
66
|
+
sys.exit(-1)
|
|
67
|
+
|
|
68
|
+
import os
|
|
69
|
+
import urllib.request
|
|
70
|
+
import base64
|
|
71
|
+
from io import BytesIO
|
|
72
|
+
|
|
73
|
+
from trackma.engine import Engine
|
|
74
|
+
from trackma.accounts import AccountManager
|
|
75
|
+
from trackma import messenger
|
|
76
|
+
from trackma import utils
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
from PIL import Image
|
|
80
|
+
imaging_available = True
|
|
81
|
+
except ImportError:
|
|
82
|
+
try:
|
|
83
|
+
import Image
|
|
84
|
+
imaging_available = True
|
|
85
|
+
except ImportError:
|
|
86
|
+
print("Warning: PIL or Pillow isn't available. Preview images will be disabled.")
|
|
87
|
+
imaging_available = False
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
import dateutil.parser
|
|
91
|
+
import dateutil.tz
|
|
92
|
+
import datetime
|
|
93
|
+
dateutil_available = True
|
|
94
|
+
except ImportError:
|
|
95
|
+
print("Warning: DateUtil is unavailable. Next episode countdown will be disabled.")
|
|
96
|
+
dateutil_available = False
|
|
97
|
+
|
|
98
|
+
class Trackma(QMainWindow):
|
|
99
|
+
"""
|
|
100
|
+
Main GUI class
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
config = None
|
|
104
|
+
tray = None
|
|
105
|
+
accountman = None
|
|
106
|
+
worker = None
|
|
107
|
+
image_worker = None
|
|
108
|
+
started = False
|
|
109
|
+
selected_show_id = None
|
|
110
|
+
show_lists = None
|
|
111
|
+
finish = False
|
|
112
|
+
was_maximized = False
|
|
113
|
+
|
|
114
|
+
def __init__(self):
|
|
115
|
+
QMainWindow.__init__(self, None)
|
|
116
|
+
|
|
117
|
+
# Load QT specific configuration
|
|
118
|
+
self.configfile = utils.get_root_filename('ui-qt.json')
|
|
119
|
+
self.config = utils.parse_config(self.configfile, utils.qt_defaults)
|
|
120
|
+
self.api_configfile = utils.get_root_filename('ui-qt.0.json')
|
|
121
|
+
self.api_config = {}
|
|
122
|
+
|
|
123
|
+
# Build UI
|
|
124
|
+
QApplication.setWindowIcon(QIcon(utils.datadir + '/data/icon.png'))
|
|
125
|
+
self.setWindowTitle('Trackma-qt')
|
|
126
|
+
|
|
127
|
+
self.accountman = AccountManager()
|
|
128
|
+
self.accountman_widget = AccountDialog(None, self.accountman)
|
|
129
|
+
self.accountman_widget.selected.connect(self.accountman_selected)
|
|
130
|
+
|
|
131
|
+
# Go directly into the application if a default account is set
|
|
132
|
+
# Open the selection dialog otherwise
|
|
133
|
+
default = self.accountman.get_default()
|
|
134
|
+
if default:
|
|
135
|
+
self.start(default)
|
|
136
|
+
else:
|
|
137
|
+
self.accountman_widget.show()
|
|
138
|
+
|
|
139
|
+
def accountman_selected(self, account_num, remember):
|
|
140
|
+
account = self.accountman.get_account(account_num)
|
|
141
|
+
|
|
142
|
+
if remember:
|
|
143
|
+
self.accountman.set_default(account_num)
|
|
144
|
+
else:
|
|
145
|
+
self.accountman.set_default(None)
|
|
146
|
+
|
|
147
|
+
if self.started:
|
|
148
|
+
self.reload(account)
|
|
149
|
+
else:
|
|
150
|
+
self.start(account)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def start(self, account):
|
|
154
|
+
"""
|
|
155
|
+
Start engine and everything
|
|
156
|
+
|
|
157
|
+
"""
|
|
158
|
+
# Workers
|
|
159
|
+
self.worker = Engine_Worker(account)
|
|
160
|
+
self.account = account
|
|
161
|
+
|
|
162
|
+
# Timers
|
|
163
|
+
self.image_timer = QtCore.QTimer()
|
|
164
|
+
self.image_timer.setInterval(500)
|
|
165
|
+
self.image_timer.setSingleShot(True)
|
|
166
|
+
self.image_timer.timeout.connect(self.s_download_image)
|
|
167
|
+
|
|
168
|
+
self.busy_timer = QtCore.QTimer()
|
|
169
|
+
self.busy_timer.setInterval(100)
|
|
170
|
+
self.busy_timer.setSingleShot(True)
|
|
171
|
+
self.busy_timer.timeout.connect(self.s_busy)
|
|
172
|
+
|
|
173
|
+
# Build menus
|
|
174
|
+
action_play_next = QAction(getIcon('media-playback-start'), 'Play &Next', self)
|
|
175
|
+
action_play_next.setStatusTip('Play the next unwatched episode.')
|
|
176
|
+
action_play_next.setShortcut('Ctrl+N')
|
|
177
|
+
action_play_next.triggered.connect(lambda: self.s_play(True))
|
|
178
|
+
action_play_dialog = QAction('Play Episode...', self)
|
|
179
|
+
action_play_dialog.setStatusTip('Select an episode to play.')
|
|
180
|
+
action_play_dialog.triggered.connect(self.s_play_number)
|
|
181
|
+
action_details = QAction('Show &details...', self)
|
|
182
|
+
action_details.setStatusTip('Show detailed information about the selected show.')
|
|
183
|
+
action_details.triggered.connect(self.s_show_details)
|
|
184
|
+
action_altname = QAction('Change &alternate name...', self)
|
|
185
|
+
action_altname.setStatusTip('Set an alternate title for the tracker.')
|
|
186
|
+
action_altname.triggered.connect(self.s_altname)
|
|
187
|
+
action_play_random = QAction('Play &random show', self)
|
|
188
|
+
action_play_random.setStatusTip('Pick a random show with a new episode and play it.')
|
|
189
|
+
action_play_random.setShortcut('Ctrl+R')
|
|
190
|
+
action_play_random.triggered.connect(self.s_play_random)
|
|
191
|
+
action_add = QAction(getIcon('edit-find'), 'Search/Add from Remote', self)
|
|
192
|
+
action_add.setShortcut('Ctrl+A')
|
|
193
|
+
action_add.triggered.connect(self.s_add)
|
|
194
|
+
action_delete = QAction(getIcon('edit-delete'), '&Delete', self)
|
|
195
|
+
action_delete.setStatusTip('Remove this show from your list.')
|
|
196
|
+
action_delete.triggered.connect(self.s_delete)
|
|
197
|
+
action_quit = QAction(getIcon('application-exit'), '&Quit', self)
|
|
198
|
+
action_quit.setShortcut('Ctrl+Q')
|
|
199
|
+
action_quit.setStatusTip('Exit Trackma.')
|
|
200
|
+
action_quit.triggered.connect(self._exit)
|
|
201
|
+
|
|
202
|
+
action_sync = QAction('&Sync', self)
|
|
203
|
+
action_sync.setStatusTip('Send changes and then retrieve remote list')
|
|
204
|
+
action_sync.setShortcut('Ctrl+S')
|
|
205
|
+
action_sync.triggered.connect(lambda: self.s_send(True))
|
|
206
|
+
action_send = QAction('S&end changes', self)
|
|
207
|
+
action_send.setShortcut('Ctrl+E')
|
|
208
|
+
action_send.setStatusTip('Upload any changes made to the list immediately.')
|
|
209
|
+
action_send.triggered.connect(self.s_send)
|
|
210
|
+
action_retrieve = QAction('Re&download list', self)
|
|
211
|
+
action_retrieve.setShortcut('Ctrl+D')
|
|
212
|
+
action_retrieve.setStatusTip('Discard any changes made to the list and re-download it.')
|
|
213
|
+
action_retrieve.triggered.connect(self.s_retrieve)
|
|
214
|
+
action_scan_library = QAction('Rescan &Library', self)
|
|
215
|
+
action_scan_library.triggered.connect(self.s_scan_library)
|
|
216
|
+
|
|
217
|
+
action_reload = QAction('Switch &Account', self)
|
|
218
|
+
action_reload.setStatusTip('Switch to a different account.')
|
|
219
|
+
action_reload.triggered.connect(self.s_switch_account)
|
|
220
|
+
action_settings = QAction('&Settings...', self)
|
|
221
|
+
action_settings.triggered.connect(self.s_settings)
|
|
222
|
+
|
|
223
|
+
action_about = QAction(getIcon('help-about'), 'About...', self)
|
|
224
|
+
action_about.triggered.connect(self.s_about)
|
|
225
|
+
action_about_qt = QAction('About Qt...', self)
|
|
226
|
+
action_about_qt.triggered.connect(self.s_about_qt)
|
|
227
|
+
|
|
228
|
+
menubar = self.menuBar()
|
|
229
|
+
self.menu_show = menubar.addMenu('&Show')
|
|
230
|
+
self.menu_show.addAction(action_play_next)
|
|
231
|
+
self.menu_show.addAction(action_play_dialog)
|
|
232
|
+
self.menu_show.addAction(action_details)
|
|
233
|
+
self.menu_show.addAction(action_altname)
|
|
234
|
+
self.menu_show.addSeparator()
|
|
235
|
+
self.menu_show.addAction(action_play_random)
|
|
236
|
+
self.menu_show.addSeparator()
|
|
237
|
+
self.menu_show.addAction(action_add)
|
|
238
|
+
self.menu_show.addAction(action_delete)
|
|
239
|
+
self.menu_show.addSeparator()
|
|
240
|
+
self.menu_show.addAction(action_quit)
|
|
241
|
+
|
|
242
|
+
self.menu_play = QMenu('Play')
|
|
243
|
+
|
|
244
|
+
# Context menu for right click on list item
|
|
245
|
+
self.menu_show_context = QMenu()
|
|
246
|
+
#self.menu_show_context.addAction(action_play_next)
|
|
247
|
+
#self.menu_show_context.addAction(action_play_dialog)
|
|
248
|
+
self.menu_show_context.addMenu(self.menu_play)
|
|
249
|
+
self.menu_show_context.addAction(action_details)
|
|
250
|
+
self.menu_show_context.addAction(action_altname)
|
|
251
|
+
self.menu_show_context.addSeparator()
|
|
252
|
+
self.menu_show_context.addAction(action_delete)
|
|
253
|
+
|
|
254
|
+
# Context menu for right click on list header
|
|
255
|
+
self.menu_columns = QMenu()
|
|
256
|
+
self.available_columns = ['ID', 'Title', 'Progress', 'Score',
|
|
257
|
+
'Percent', 'Next Episode', 'Start date', 'End date',
|
|
258
|
+
'My start', 'My finish', 'Tags']
|
|
259
|
+
self.column_keys = {'id': 0,
|
|
260
|
+
'title': 1,
|
|
261
|
+
'progress': 2,
|
|
262
|
+
'score': 3,
|
|
263
|
+
'percent': 4,
|
|
264
|
+
'next_ep': 5,
|
|
265
|
+
'date_start': 6,
|
|
266
|
+
'date_end': 7,
|
|
267
|
+
'my_start': 8,
|
|
268
|
+
'my_end': 9,
|
|
269
|
+
'tag': 10}
|
|
270
|
+
|
|
271
|
+
self.menu_columns_group = QActionGroup(self, exclusive=False)
|
|
272
|
+
self.menu_columns_group.triggered.connect(self.s_toggle_column)
|
|
273
|
+
|
|
274
|
+
self.api_configfile = utils.get_root_filename('ui-qt.%s.json' % account['api'])
|
|
275
|
+
self.api_config = utils.parse_config(self.api_configfile, utils.qt_per_api_defaults)
|
|
276
|
+
if self.config['columns_per_api']:
|
|
277
|
+
self.config['visible_columns'] = self.api_config['visible_columns']
|
|
278
|
+
self.config['columns_state'] = self.api_config['columns_state']
|
|
279
|
+
|
|
280
|
+
for column_name in self.available_columns:
|
|
281
|
+
action = QAction(column_name, self, checkable=True)
|
|
282
|
+
if column_name in self.config['visible_columns']:
|
|
283
|
+
action.setChecked(True)
|
|
284
|
+
|
|
285
|
+
self.menu_columns_group.addAction(action)
|
|
286
|
+
self.menu_columns.addAction(action)
|
|
287
|
+
|
|
288
|
+
# Make icons for viewed episodes
|
|
289
|
+
rect = QtCore.QSize(16,16)
|
|
290
|
+
buffer = QtGui.QPixmap(rect)
|
|
291
|
+
ep_icon_states = {'all': QStyle.State_On,
|
|
292
|
+
'part': QStyle.State_NoChange,
|
|
293
|
+
'none': QStyle.State_Off}
|
|
294
|
+
self.ep_icons = {}
|
|
295
|
+
for key, state in ep_icon_states.items():
|
|
296
|
+
buffer.fill(QtCore.Qt.transparent)
|
|
297
|
+
painter = QtGui.QPainter(buffer)
|
|
298
|
+
opt = QStyleOptionButton()
|
|
299
|
+
opt.state = state
|
|
300
|
+
self.style().drawPrimitive(QStyle.PE_IndicatorMenuCheckMark, opt, painter)
|
|
301
|
+
self.ep_icons[key] = QIcon(buffer)
|
|
302
|
+
painter.end()
|
|
303
|
+
|
|
304
|
+
menu_list = menubar.addMenu('&List')
|
|
305
|
+
menu_list.addAction(action_sync)
|
|
306
|
+
menu_list.addSeparator()
|
|
307
|
+
menu_list.addAction(action_send)
|
|
308
|
+
menu_list.addAction(action_retrieve)
|
|
309
|
+
menu_list.addSeparator()
|
|
310
|
+
menu_list.addAction(action_scan_library)
|
|
311
|
+
self.menu_mediatype = menubar.addMenu('&Mediatype')
|
|
312
|
+
self.mediatype_actiongroup = QActionGroup(self, exclusive=True)
|
|
313
|
+
self.mediatype_actiongroup.triggered.connect(self.s_mediatype)
|
|
314
|
+
menu_options = menubar.addMenu('&Options')
|
|
315
|
+
menu_options.addAction(action_reload)
|
|
316
|
+
menu_options.addSeparator()
|
|
317
|
+
menu_options.addAction(action_settings)
|
|
318
|
+
menu_help = menubar.addMenu('&Help')
|
|
319
|
+
menu_help.addAction(action_about)
|
|
320
|
+
menu_help.addAction(action_about_qt)
|
|
321
|
+
|
|
322
|
+
# Build layout
|
|
323
|
+
main_layout = QVBoxLayout()
|
|
324
|
+
top_hbox = QHBoxLayout()
|
|
325
|
+
main_hbox = QHBoxLayout()
|
|
326
|
+
self.list_box = QVBoxLayout()
|
|
327
|
+
filter_bar_box_layout = QHBoxLayout()
|
|
328
|
+
self.filter_bar_box = QWidget()
|
|
329
|
+
left_box = QFormLayout()
|
|
330
|
+
small_btns_hbox = QHBoxLayout()
|
|
331
|
+
|
|
332
|
+
self.show_title = QLabel('Trackma-qt')
|
|
333
|
+
show_title_font = QtGui.QFont()
|
|
334
|
+
show_title_font.setBold(True)
|
|
335
|
+
show_title_font.setPointSize(12)
|
|
336
|
+
self.show_title.setFont(show_title_font)
|
|
337
|
+
|
|
338
|
+
self.api_icon = QLabel('icon')
|
|
339
|
+
self.api_user = QLabel('user')
|
|
340
|
+
|
|
341
|
+
top_hbox.addWidget(self.show_title, 1)
|
|
342
|
+
top_hbox.addWidget(self.api_icon)
|
|
343
|
+
top_hbox.addWidget(self.api_user)
|
|
344
|
+
|
|
345
|
+
self.notebook = QTabWidget()
|
|
346
|
+
self.notebook.currentChanged.connect(self.s_tab_changed)
|
|
347
|
+
self.show_filter = QLineEdit()
|
|
348
|
+
self.show_filter.textChanged.connect(self.s_filter_changed)
|
|
349
|
+
filter_tooltip = ("General Search: All fields (columns) of each show will be matched against the search term."
|
|
350
|
+
"\nAdvanced Searching: A field can be specified by using its key followed by a colon"
|
|
351
|
+
" e.g. 'title:My_Show date_start:2016'."
|
|
352
|
+
"\n Any field may be specified multiple times to match terms in any order e.g. 'tag:Battle+Shounen tag:Ecchi'. "
|
|
353
|
+
"\n + and _ are replaced with spaces when searching specific fields."
|
|
354
|
+
"\n If colon is used after something that is not a column key, it will treat it as a general term."
|
|
355
|
+
"\n ALL terms not attached to a field will be combined into a single general search term"
|
|
356
|
+
"\n - 'My date_end:2016 Show' will match shows that have 'My Show' in any field and 2016 in the End Date field."
|
|
357
|
+
"\n Available field keys are: ")
|
|
358
|
+
colkeys = ', '.join(sorted(self.column_keys.keys()))
|
|
359
|
+
self.show_filter.setToolTip(filter_tooltip + colkeys + '.')
|
|
360
|
+
self.show_filter_invert = QCheckBox()
|
|
361
|
+
self.show_filter_invert.stateChanged.connect(self.s_filter_changed)
|
|
362
|
+
self.show_filter_casesens = QCheckBox()
|
|
363
|
+
self.show_filter_casesens.stateChanged.connect(self.s_filter_changed)
|
|
364
|
+
|
|
365
|
+
self.setMinimumSize(740, 480)
|
|
366
|
+
if self.config['remember_geometry']:
|
|
367
|
+
self.setGeometry(self.config['last_x'], self.config['last_y'],
|
|
368
|
+
self.config['last_width'], self.config['last_height'])
|
|
369
|
+
|
|
370
|
+
self.show_image = QLabel('Trackma-qt')
|
|
371
|
+
self.show_image.setFixedHeight( 149 )
|
|
372
|
+
self.show_image.setFixedWidth( 100 )
|
|
373
|
+
self.show_image.setAlignment( QtCore.Qt.AlignCenter )
|
|
374
|
+
self.show_image.setStyleSheet("border: 1px solid #777;background-color:#999;text-align:center")
|
|
375
|
+
show_progress_label = QLabel('Progress')
|
|
376
|
+
self.show_progress = QSpinBox()
|
|
377
|
+
self.show_progress_bar = QProgressBar()
|
|
378
|
+
self.show_progress_btn = QPushButton('Update')
|
|
379
|
+
self.show_progress_btn.setToolTip('Set number of episodes watched to the value entered above')
|
|
380
|
+
self.show_progress_btn.clicked.connect(self.s_set_episode)
|
|
381
|
+
self.show_play_btn = QToolButton()
|
|
382
|
+
self.show_play_btn.setIcon(getIcon('media-playback-start'))
|
|
383
|
+
self.show_play_btn.setToolTip('Play the next unwatched episode\nHold to play other episodes')
|
|
384
|
+
self.show_play_btn.clicked.connect(lambda: self.s_play(True))
|
|
385
|
+
self.show_play_btn.setMenu(self.menu_play)
|
|
386
|
+
self.show_inc_btn = QToolButton()
|
|
387
|
+
self.show_inc_btn.setIcon(getIcon('list-add'))
|
|
388
|
+
self.show_inc_btn.setShortcut('Ctrl+Right')
|
|
389
|
+
self.show_inc_btn.setToolTip('Increment number of episodes watched')
|
|
390
|
+
self.show_inc_btn.clicked.connect(self.s_plus_episode)
|
|
391
|
+
self.show_dec_btn = QToolButton()
|
|
392
|
+
self.show_dec_btn.setIcon(getIcon('list-remove'))
|
|
393
|
+
self.show_dec_btn.clicked.connect(self.s_rem_episode)
|
|
394
|
+
self.show_dec_btn.setShortcut('Ctrl+Left')
|
|
395
|
+
self.show_dec_btn.setToolTip('Decrement number of episodes watched')
|
|
396
|
+
show_score_label = QLabel('Score')
|
|
397
|
+
self.show_score = QDoubleSpinBox()
|
|
398
|
+
self.show_score_btn = QPushButton('Set')
|
|
399
|
+
self.show_score_btn.setToolTip('Set score to the value entered above')
|
|
400
|
+
self.show_score_btn.clicked.connect(self.s_set_score)
|
|
401
|
+
self.show_tags_btn = QPushButton('Edit Tags...')
|
|
402
|
+
self.show_tags_btn.setToolTip('Open a dialog to edit your tags for this show')
|
|
403
|
+
self.show_tags_btn.clicked.connect(self.s_set_tags)
|
|
404
|
+
self.show_status = QComboBox()
|
|
405
|
+
self.show_status.setToolTip('Change your watching status of this show')
|
|
406
|
+
self.show_status.currentIndexChanged.connect(self.s_set_status)
|
|
407
|
+
|
|
408
|
+
small_btns_hbox.addWidget(self.show_dec_btn)
|
|
409
|
+
small_btns_hbox.addWidget(self.show_play_btn)
|
|
410
|
+
small_btns_hbox.addWidget(self.show_inc_btn)
|
|
411
|
+
small_btns_hbox.setAlignment( QtCore.Qt.AlignCenter )
|
|
412
|
+
|
|
413
|
+
left_box.addRow(self.show_image)
|
|
414
|
+
left_box.addRow(self.show_progress_bar)
|
|
415
|
+
left_box.addRow(small_btns_hbox)
|
|
416
|
+
left_box.addRow(show_progress_label, self.show_progress)
|
|
417
|
+
left_box.addRow(self.show_progress_btn)
|
|
418
|
+
left_box.addRow(show_score_label, self.show_score)
|
|
419
|
+
left_box.addRow(self.show_score_btn)
|
|
420
|
+
left_box.addRow(self.show_status)
|
|
421
|
+
left_box.addRow(self.show_tags_btn)
|
|
422
|
+
|
|
423
|
+
filter_bar_box_layout.addWidget(QLabel('Filter:'))
|
|
424
|
+
filter_bar_box_layout.addWidget(self.show_filter)
|
|
425
|
+
filter_bar_box_layout.addWidget(QLabel('Invert'))
|
|
426
|
+
filter_bar_box_layout.addWidget(self.show_filter_invert)
|
|
427
|
+
filter_bar_box_layout.addWidget(QLabel('Case Sensitive'))
|
|
428
|
+
filter_bar_box_layout.addWidget(self.show_filter_casesens)
|
|
429
|
+
self.filter_bar_box.setLayout(filter_bar_box_layout)
|
|
430
|
+
|
|
431
|
+
if self.config['filter_bar_position'] is FilterBar.PositionHidden:
|
|
432
|
+
self.list_box.addWidget(self.notebook)
|
|
433
|
+
self.filter_bar_box.hide()
|
|
434
|
+
elif self.config['filter_bar_position'] is FilterBar.PositionAboveLists:
|
|
435
|
+
self.list_box.addWidget(self.filter_bar_box)
|
|
436
|
+
self.list_box.addWidget(self.notebook)
|
|
437
|
+
elif self.config['filter_bar_position'] is FilterBar.PositionBelowLists:
|
|
438
|
+
self.list_box.addWidget(self.notebook)
|
|
439
|
+
self.list_box.addWidget(self.filter_bar_box)
|
|
440
|
+
|
|
441
|
+
main_hbox.addLayout(left_box)
|
|
442
|
+
main_hbox.addLayout(self.list_box, 1)
|
|
443
|
+
|
|
444
|
+
main_layout.addLayout(top_hbox)
|
|
445
|
+
main_layout.addLayout(main_hbox)
|
|
446
|
+
|
|
447
|
+
self.main_widget = QWidget(self)
|
|
448
|
+
self.main_widget.setLayout(main_layout)
|
|
449
|
+
self.setCentralWidget(self.main_widget)
|
|
450
|
+
|
|
451
|
+
# Statusbar
|
|
452
|
+
self.status_text = QLabel('Trackma-qt')
|
|
453
|
+
self.queue_text = QLabel('Unsynced items: N/A')
|
|
454
|
+
self.statusBar().addWidget(self.status_text, 1)
|
|
455
|
+
self.statusBar().addWidget(self.queue_text)
|
|
456
|
+
|
|
457
|
+
# Tray icon
|
|
458
|
+
tray_menu = QMenu(self)
|
|
459
|
+
action_hide = QAction('Show/Hide', self)
|
|
460
|
+
action_hide.triggered.connect(self.s_hide)
|
|
461
|
+
tray_menu.addAction(action_hide)
|
|
462
|
+
tray_menu.addAction(action_quit)
|
|
463
|
+
|
|
464
|
+
self.tray = QSystemTrayIcon(self.windowIcon())
|
|
465
|
+
self.tray.setContextMenu(tray_menu)
|
|
466
|
+
self.tray.activated.connect(self.s_tray_clicked)
|
|
467
|
+
self._tray()
|
|
468
|
+
|
|
469
|
+
# Connect worker signals
|
|
470
|
+
self.worker.changed_status.connect(self.status)
|
|
471
|
+
self.worker.raised_error.connect(self.error)
|
|
472
|
+
self.worker.raised_fatal.connect(self.fatal)
|
|
473
|
+
self.worker.changed_show.connect(self.ws_changed_show)
|
|
474
|
+
self.worker.changed_list.connect(self.ws_changed_list)
|
|
475
|
+
self.worker.changed_queue.connect(self.ws_changed_queue)
|
|
476
|
+
self.worker.playing_show.connect(self.ws_changed_show)
|
|
477
|
+
self.worker.prompt_for_update.connect(self.ws_prompt_update)
|
|
478
|
+
|
|
479
|
+
# Show main window
|
|
480
|
+
if not (self.config['show_tray'] and self.config['start_in_tray']):
|
|
481
|
+
self.show()
|
|
482
|
+
|
|
483
|
+
# Start loading engine
|
|
484
|
+
self.started = True
|
|
485
|
+
self._busy(False)
|
|
486
|
+
self.worker_call('start', self.r_engine_loaded)
|
|
487
|
+
|
|
488
|
+
def reload(self, account=None, mediatype=None):
|
|
489
|
+
if account:
|
|
490
|
+
self.account = account
|
|
491
|
+
|
|
492
|
+
self.api_configfile = utils.get_root_filename('ui-qt.%s.json' % self.account['api'])
|
|
493
|
+
self.api_config = utils.parse_config(self.api_configfile, utils.qt_per_api_defaults)
|
|
494
|
+
if self.config['columns_per_api']:
|
|
495
|
+
self.config['visible_columns'] = self.api_config['visible_columns']
|
|
496
|
+
self.menu_columns_group.setEnabled(False)
|
|
497
|
+
for action in self.menu_columns_group.actions():
|
|
498
|
+
action.setChecked(action.text() in self.config['visible_columns'])
|
|
499
|
+
self.menu_columns_group.setEnabled(True)
|
|
500
|
+
|
|
501
|
+
self.show()
|
|
502
|
+
self._busy(False)
|
|
503
|
+
self.worker_call('reload', self.r_engine_loaded, account, mediatype)
|
|
504
|
+
|
|
505
|
+
def closeEvent(self, event):
|
|
506
|
+
if not self.started or not self.worker.engine.loaded:
|
|
507
|
+
event.accept()
|
|
508
|
+
elif self.config['show_tray'] and self.config['close_to_tray']:
|
|
509
|
+
event.ignore()
|
|
510
|
+
self.s_hide()
|
|
511
|
+
else:
|
|
512
|
+
event.ignore()
|
|
513
|
+
self._exit()
|
|
514
|
+
|
|
515
|
+
def status(self, message):
|
|
516
|
+
self.status_text.setText(message)
|
|
517
|
+
print(message)
|
|
518
|
+
|
|
519
|
+
def error(self, msg):
|
|
520
|
+
self.status('Error: {}'.format(msg))
|
|
521
|
+
QMessageBox.critical(self, 'Error', str(msg), QMessageBox.Ok)
|
|
522
|
+
|
|
523
|
+
def fatal(self, msg):
|
|
524
|
+
QMessageBox.critical(self, 'Fatal Error', "Fatal Error! Reason:\n\n{0}".format(msg), QMessageBox.Ok)
|
|
525
|
+
self._busy()
|
|
526
|
+
self.finish = False
|
|
527
|
+
self.worker_call('unload', self.r_engine_unloaded)
|
|
528
|
+
|
|
529
|
+
def worker_call(self, function, ret_function, *args, **kwargs):
|
|
530
|
+
# Run worker in a thread
|
|
531
|
+
self.worker.set_function(function, ret_function, *args, **kwargs)
|
|
532
|
+
self.worker.start()
|
|
533
|
+
|
|
534
|
+
### GUI Functions
|
|
535
|
+
def _exit(self):
|
|
536
|
+
self._busy()
|
|
537
|
+
if self.config['remember_geometry']:
|
|
538
|
+
self._store_geometry()
|
|
539
|
+
if self.config['remember_columns']:
|
|
540
|
+
self._store_columnstate()
|
|
541
|
+
self.finish = True
|
|
542
|
+
self.worker_call('unload', self.r_engine_unloaded)
|
|
543
|
+
|
|
544
|
+
def _store_geometry(self):
|
|
545
|
+
self.config['last_x'] = self.x()
|
|
546
|
+
self.config['last_y'] = self.y()
|
|
547
|
+
self.config['last_width'] = self.width()
|
|
548
|
+
self.config['last_height'] = self.height()
|
|
549
|
+
utils.save_config(self.config, self.configfile)
|
|
550
|
+
|
|
551
|
+
def _store_columnstate(self):
|
|
552
|
+
self.config['columns_state'] = dict()
|
|
553
|
+
for status in self.statuses_nums:
|
|
554
|
+
state = self.show_lists[status].horizontalHeader().saveState()
|
|
555
|
+
self.config['columns_state'][status] = base64.b64encode(state).decode('ascii')
|
|
556
|
+
if self.config['columns_per_api']:
|
|
557
|
+
self.api_config['columns_state'] = self.config['columns_state']
|
|
558
|
+
utils.save_config(self.api_config, self.api_configfile)
|
|
559
|
+
else:
|
|
560
|
+
utils.save_config(self.config, self.configfile)
|
|
561
|
+
|
|
562
|
+
def _enable_widgets(self, enable):
|
|
563
|
+
self.notebook.setEnabled(enable)
|
|
564
|
+
self.menuBar().setEnabled(enable)
|
|
565
|
+
|
|
566
|
+
if self.selected_show_id:
|
|
567
|
+
self.show_progress_btn.setEnabled(enable)
|
|
568
|
+
self.show_score_btn.setEnabled(enable)
|
|
569
|
+
if 'can_tag' in self.mediainfo and self.mediainfo.get('can_tag'):
|
|
570
|
+
self.show_tags_btn.setEnabled(enable)
|
|
571
|
+
else:
|
|
572
|
+
self.show_tags_btn.setEnabled(False)
|
|
573
|
+
self.show_play_btn.setEnabled(enable)
|
|
574
|
+
self.show_inc_btn.setEnabled(enable)
|
|
575
|
+
self.show_dec_btn.setEnabled(enable)
|
|
576
|
+
self.show_status.setEnabled(enable)
|
|
577
|
+
|
|
578
|
+
def _update_queue_counter(self, queue):
|
|
579
|
+
self.queue_text.setText("Unsynced items: %d" % queue)
|
|
580
|
+
|
|
581
|
+
def _update_config(self):
|
|
582
|
+
self._tray()
|
|
583
|
+
self._filter_bar()
|
|
584
|
+
# TODO: Reload listviews?
|
|
585
|
+
|
|
586
|
+
def _tray(self):
|
|
587
|
+
if self.tray.isVisible() and not self.config['show_tray']:
|
|
588
|
+
self.tray.hide()
|
|
589
|
+
elif not self.tray.isVisible() and self.config['show_tray']:
|
|
590
|
+
self.tray.show()
|
|
591
|
+
if self.tray.isVisible():
|
|
592
|
+
if self.config['tray_api_icon']:
|
|
593
|
+
self.tray.setIcon( QIcon( utils.available_libs[self.account['api']][1] ) )
|
|
594
|
+
else:
|
|
595
|
+
self.tray.setIcon( self.windowIcon() )
|
|
596
|
+
|
|
597
|
+
def _filter_bar(self):
|
|
598
|
+
self.list_box.removeWidget(self.filter_bar_box)
|
|
599
|
+
self.list_box.removeWidget(self.notebook)
|
|
600
|
+
self.filter_bar_box.show()
|
|
601
|
+
if self.config['filter_bar_position'] is FilterBar.PositionHidden:
|
|
602
|
+
self.list_box.addWidget(self.notebook)
|
|
603
|
+
self.filter_bar_box.hide()
|
|
604
|
+
elif self.config['filter_bar_position'] is FilterBar.PositionAboveLists:
|
|
605
|
+
self.list_box.addWidget(self.filter_bar_box)
|
|
606
|
+
self.list_box.addWidget(self.notebook)
|
|
607
|
+
elif self.config['filter_bar_position'] is FilterBar.PositionBelowLists:
|
|
608
|
+
self.list_box.addWidget(self.notebook)
|
|
609
|
+
self.list_box.addWidget(self.filter_bar_box)
|
|
610
|
+
|
|
611
|
+
def _busy(self, wait=False):
|
|
612
|
+
if wait:
|
|
613
|
+
self.busy_timer.start()
|
|
614
|
+
else:
|
|
615
|
+
self._enable_widgets(False)
|
|
616
|
+
|
|
617
|
+
def _unbusy(self):
|
|
618
|
+
if self.busy_timer.isActive():
|
|
619
|
+
self.busy_timer.stop()
|
|
620
|
+
else:
|
|
621
|
+
self._enable_widgets(True)
|
|
622
|
+
|
|
623
|
+
def _rebuild_lists(self, showlist, altnames, library):
|
|
624
|
+
"""
|
|
625
|
+
Using a full showlist, rebuilds every QTreeView
|
|
626
|
+
|
|
627
|
+
"""
|
|
628
|
+
statuses_nums = self.worker.engine.mediainfo['statuses']
|
|
629
|
+
filtered_list = dict()
|
|
630
|
+
for status in statuses_nums:
|
|
631
|
+
filtered_list[status] = list()
|
|
632
|
+
|
|
633
|
+
for show in showlist:
|
|
634
|
+
filtered_list[show['my_status']].append(show)
|
|
635
|
+
|
|
636
|
+
for status in statuses_nums:
|
|
637
|
+
self._rebuild_list(status, filtered_list[status], altnames, library)
|
|
638
|
+
|
|
639
|
+
def _rebuild_list(self, status, showlist=None, altnames=None, library=None):
|
|
640
|
+
if not showlist:
|
|
641
|
+
showlist = self.worker.engine.filter_list(status)
|
|
642
|
+
if not altnames:
|
|
643
|
+
altnames = self.worker.engine.altnames()
|
|
644
|
+
if not library:
|
|
645
|
+
library = self.worker.engine.library()
|
|
646
|
+
|
|
647
|
+
widget = self.show_lists[status]
|
|
648
|
+
|
|
649
|
+
widget.clear()
|
|
650
|
+
widget.setSortingEnabled(False)
|
|
651
|
+
widget.setRowCount(len(showlist))
|
|
652
|
+
widget.setColumnCount(len(self.available_columns))
|
|
653
|
+
widget.setHorizontalHeaderLabels(self.available_columns)
|
|
654
|
+
|
|
655
|
+
# Hide invisible columns
|
|
656
|
+
for i, column in enumerate(self.available_columns):
|
|
657
|
+
if column not in self.config['visible_columns']:
|
|
658
|
+
widget.setColumnHidden(i, True)
|
|
659
|
+
|
|
660
|
+
if pyqt_version is 5:
|
|
661
|
+
widget.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
|
662
|
+
widget.horizontalHeader().setSectionResizeMode(2, QHeaderView.Fixed)
|
|
663
|
+
widget.horizontalHeader().setSectionResizeMode(3, QHeaderView.Fixed)
|
|
664
|
+
else:
|
|
665
|
+
widget.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)
|
|
666
|
+
widget.horizontalHeader().setResizeMode(2, QHeaderView.Fixed)
|
|
667
|
+
widget.horizontalHeader().setResizeMode(3, QHeaderView.Fixed)
|
|
668
|
+
|
|
669
|
+
widget.horizontalHeader().resizeSection(2, 70)
|
|
670
|
+
widget.horizontalHeader().resizeSection(3, 55)
|
|
671
|
+
widget.horizontalHeader().resizeSection(4, 100)
|
|
672
|
+
|
|
673
|
+
if self.config['remember_columns'] and str(status) in self.config['columns_state']:
|
|
674
|
+
state = QtCore.QByteArray(base64.b64decode(self.config['columns_state'][str(status)]))
|
|
675
|
+
widget.horizontalHeader().restoreState(state)
|
|
676
|
+
|
|
677
|
+
i = 0
|
|
678
|
+
|
|
679
|
+
if status == self.worker.engine.mediainfo['status_start']:
|
|
680
|
+
for show in showlist:
|
|
681
|
+
self._update_row( widget, i, show, altnames.get(show['id']), library.get(show['id']) )
|
|
682
|
+
i += 1
|
|
683
|
+
else:
|
|
684
|
+
for show in showlist:
|
|
685
|
+
self._update_row( widget, i, show, altnames.get(show['id']) )
|
|
686
|
+
i += 1
|
|
687
|
+
|
|
688
|
+
widget.setSortingEnabled(True)
|
|
689
|
+
widget.sortByColumn(1, QtCore.Qt.AscendingOrder)
|
|
690
|
+
|
|
691
|
+
# Update tab name with total
|
|
692
|
+
tab_index = self.statuses_nums.index(status)
|
|
693
|
+
tab_name = "%s (%d)" % (self.statuses_names[status], i)
|
|
694
|
+
self.notebook.setTabText(tab_index, tab_name)
|
|
695
|
+
|
|
696
|
+
def _update_row(self, widget, row, show, altname, library_episodes=None, is_playing=False):
|
|
697
|
+
color = self._get_color(is_playing, show, library_episodes)
|
|
698
|
+
|
|
699
|
+
title_str = show['title']
|
|
700
|
+
if altname:
|
|
701
|
+
title_str += " [%s]" % altname
|
|
702
|
+
progress_str = "%d / %d" % (show['my_progress'], show['total'])
|
|
703
|
+
percent_widget = EpisodeBar(self, self.config['colors'])
|
|
704
|
+
percent_widget.setRange(0, 100)
|
|
705
|
+
percent_widget.setBarStyle(self.config['episodebar_style'], self.config['episodebar_text'])
|
|
706
|
+
tooltip = "Watched: %d<br>" % show['my_progress']
|
|
707
|
+
|
|
708
|
+
if show['total'] > 0:
|
|
709
|
+
percent_widget.setMaximum(show['total'])
|
|
710
|
+
else:
|
|
711
|
+
percent_widget.setMaximum((int(show['my_progress']/12)+1)*12) # Round up to the next cour
|
|
712
|
+
percent_widget.setValue(show['my_progress'])
|
|
713
|
+
|
|
714
|
+
aired_eps = utils.estimate_aired_episodes(show)
|
|
715
|
+
if aired_eps:
|
|
716
|
+
percent_widget.setSubValue(aired_eps)
|
|
717
|
+
tooltip += "Aired (estimated): %d<br>" % aired_eps
|
|
718
|
+
|
|
719
|
+
if library_episodes:
|
|
720
|
+
eps = library_episodes.keys()
|
|
721
|
+
tooltip += "Latest available: %d<br>" % max(eps)
|
|
722
|
+
percent_widget.setEpisodes(eps)
|
|
723
|
+
|
|
724
|
+
tooltip += "Total: %d" % show['total']
|
|
725
|
+
percent_widget.setToolTip(tooltip)
|
|
726
|
+
percent = percent_widget.value() * 100 / percent_widget.maximum()
|
|
727
|
+
|
|
728
|
+
widget.setRowHeight(row, QtGui.QFontMetrics(widget.font()).height() + 2);
|
|
729
|
+
widget.setItem(row, 0, ShowItem( str(show['id']), color ))
|
|
730
|
+
widget.setItem(row, 1, ShowItem( title_str, color ))
|
|
731
|
+
widget.setItem(row, 2, ShowItemNum( show['my_progress'], progress_str, color ))
|
|
732
|
+
widget.setItem(row, 3, ShowItemNum( show['my_score'], str(show['my_score']), color ))
|
|
733
|
+
widget.setItem(row, 4, ShowItemNum( percent, str(percent), color ))
|
|
734
|
+
widget.setCellWidget(row, 4, percent_widget )
|
|
735
|
+
if 'date_next_ep' in self.mediainfo \
|
|
736
|
+
and self.mediainfo['date_next_ep'] \
|
|
737
|
+
and 'next_ep_time' in show \
|
|
738
|
+
and dateutil_available:
|
|
739
|
+
next_ep_dt = dateutil.parser.parse(show['next_ep_time'])
|
|
740
|
+
delta = next_ep_dt - datetime.datetime.now(dateutil.tz.tzutc())
|
|
741
|
+
widget.setItem(row, 5, ShowItem( "%i days, %02d hrs." % (delta.days, delta.seconds/3600), color, QtCore.Qt.AlignHCenter ))
|
|
742
|
+
else:
|
|
743
|
+
widget.setItem(row, 5, ShowItem( "-", color, QtCore.Qt.AlignHCenter ))
|
|
744
|
+
widget.setItem(row, 6, ShowItemDate( show['start_date'], color ))
|
|
745
|
+
widget.setItem(row, 7, ShowItemDate( show['end_date'], color ))
|
|
746
|
+
widget.setItem(row, 8, ShowItemDate( show['my_start_date'], color ))
|
|
747
|
+
widget.setItem(row, 9, ShowItemDate( show['my_finish_date'], color ))
|
|
748
|
+
try:
|
|
749
|
+
tag_str = show['my_tags']
|
|
750
|
+
if not tag_str:
|
|
751
|
+
tag_str = '-'
|
|
752
|
+
except:
|
|
753
|
+
tag_str = '-'
|
|
754
|
+
widget.setItem(row, 10, ShowItem( tag_str, color ))
|
|
755
|
+
|
|
756
|
+
def _get_color(self, is_playing, show, eps):
|
|
757
|
+
if is_playing:
|
|
758
|
+
return getColor(self.config['colors']['is_playing'])
|
|
759
|
+
elif show.get('queued'):
|
|
760
|
+
return getColor(self.config['colors']['is_queued'])
|
|
761
|
+
elif eps and max(eps) > show['my_progress']:
|
|
762
|
+
return getColor(self.config['colors']['new_episode'])
|
|
763
|
+
elif show['status'] == utils.STATUS_AIRING:
|
|
764
|
+
return getColor(self.config['colors']['is_airing'])
|
|
765
|
+
elif show['status'] == utils.STATUS_NOTYET:
|
|
766
|
+
return getColor(self.config['colors']['not_aired'])
|
|
767
|
+
else:
|
|
768
|
+
return None
|
|
769
|
+
|
|
770
|
+
def _get_row_from_showid(self, widget, showid):
|
|
771
|
+
# identify the row this show is in the table
|
|
772
|
+
for row in range(0, widget.rowCount()):
|
|
773
|
+
if widget.item(row, 0).text() == str(showid):
|
|
774
|
+
return row
|
|
775
|
+
|
|
776
|
+
return None
|
|
777
|
+
|
|
778
|
+
def _select_show(self, show):
|
|
779
|
+
if not show:
|
|
780
|
+
# Unselect any show
|
|
781
|
+
self.selected_show_id = None
|
|
782
|
+
|
|
783
|
+
self.show_title.setText('Trackma-qt')
|
|
784
|
+
self.show_image.setText('Trackma-qt')
|
|
785
|
+
self.show_progress.setValue(0)
|
|
786
|
+
self.show_score.setValue(0)
|
|
787
|
+
self.show_progress.setEnabled(False)
|
|
788
|
+
self.show_score.setEnabled(False)
|
|
789
|
+
self.show_progress_bar.setValue(0)
|
|
790
|
+
self.show_status.setEnabled(False)
|
|
791
|
+
self.show_progress_btn.setEnabled(False)
|
|
792
|
+
self.show_score_btn.setEnabled(False)
|
|
793
|
+
self.show_tags_btn.setEnabled(False)
|
|
794
|
+
self.show_play_btn.setEnabled(False)
|
|
795
|
+
self.show_inc_btn.setEnabled(False)
|
|
796
|
+
self.show_dec_btn.setEnabled(False)
|
|
797
|
+
return
|
|
798
|
+
|
|
799
|
+
# Block signals
|
|
800
|
+
self.show_status.blockSignals(True)
|
|
801
|
+
|
|
802
|
+
# Set proper ranges
|
|
803
|
+
if show['total']:
|
|
804
|
+
self.show_progress.setMaximum(show['total'])
|
|
805
|
+
self.show_progress_bar.setMaximum(show['total'])
|
|
806
|
+
# Regenerate Play Episode Menu
|
|
807
|
+
self.generate_episode_menus(self.menu_play, show['total'], show['my_progress'])
|
|
808
|
+
else:
|
|
809
|
+
self.show_progress.setMaximum(utils.estimate_aired_episodes(show))
|
|
810
|
+
self.generate_episode_menus(self.menu_play, utils.estimate_aired_episodes(show),show['my_progress'])
|
|
811
|
+
|
|
812
|
+
# Update information
|
|
813
|
+
self.show_title.setText(show['title'])
|
|
814
|
+
self.show_progress.setValue(show['my_progress'])
|
|
815
|
+
self.show_status.setCurrentIndex(self.statuses_nums.index(show['my_status']))
|
|
816
|
+
self.show_score.setValue(show['my_score'])
|
|
817
|
+
|
|
818
|
+
# Enable relevant buttons
|
|
819
|
+
self.show_progress.setEnabled(True)
|
|
820
|
+
self.show_score.setEnabled(True)
|
|
821
|
+
self.show_progress_btn.setEnabled(True)
|
|
822
|
+
self.show_score_btn.setEnabled(True)
|
|
823
|
+
if 'can_tag' in self.mediainfo and self.mediainfo.get('can_tag'):
|
|
824
|
+
self.show_tags_btn.setEnabled(True)
|
|
825
|
+
self.show_inc_btn.setEnabled(True)
|
|
826
|
+
self.show_dec_btn.setEnabled(True)
|
|
827
|
+
self.show_play_btn.setEnabled(True)
|
|
828
|
+
self.show_status.setEnabled(True)
|
|
829
|
+
|
|
830
|
+
# Download image or use cache
|
|
831
|
+
if show.get('image_thumb') or show.get('image'):
|
|
832
|
+
if self.image_worker is not None:
|
|
833
|
+
self.image_worker.cancel()
|
|
834
|
+
|
|
835
|
+
utils.make_dir('cache')
|
|
836
|
+
filename = utils.get_filename('cache', "%s_%s_%s.jpg" % (self.api_info['shortname'], self.api_info['mediatype'], show['id']))
|
|
837
|
+
|
|
838
|
+
if os.path.isfile(filename):
|
|
839
|
+
self.s_show_image(filename)
|
|
840
|
+
else:
|
|
841
|
+
if imaging_available:
|
|
842
|
+
self.show_image.setText('Waiting...')
|
|
843
|
+
self.image_timer.start()
|
|
844
|
+
else:
|
|
845
|
+
self.show_image.setText('Not available')
|
|
846
|
+
|
|
847
|
+
if show['total'] > 0:
|
|
848
|
+
self.show_progress_bar.setValue( show['my_progress'] )
|
|
849
|
+
else:
|
|
850
|
+
self.show_progress_bar.setValue( 0 )
|
|
851
|
+
|
|
852
|
+
# Make it global
|
|
853
|
+
self.selected_show_id = show['id']
|
|
854
|
+
|
|
855
|
+
# Unblock signals
|
|
856
|
+
self.show_status.blockSignals(False)
|
|
857
|
+
|
|
858
|
+
def _filter_check_row(self, table, row, expression, case_sensitive=False):
|
|
859
|
+
# Determine if a show matches a filter. True -> match -> do not hide
|
|
860
|
+
# Advanced search: Separate the expression into specific field terms, fail if any are not met
|
|
861
|
+
if ':' in expression:
|
|
862
|
+
exprs = expression.split(' ')
|
|
863
|
+
expr_list = []
|
|
864
|
+
for expr in exprs:
|
|
865
|
+
if ':' in expr:
|
|
866
|
+
expr_terms = expr.split(':',1)
|
|
867
|
+
if expr_terms[0] in self.column_keys:
|
|
868
|
+
col = self.column_keys[expr_terms[0]]
|
|
869
|
+
sub_expr = expr_terms[1].replace('_', ' ').replace('+', ' ')
|
|
870
|
+
item = table.item(row, col)
|
|
871
|
+
if case_sensitive:
|
|
872
|
+
if not sub_expr in item.text():
|
|
873
|
+
return False
|
|
874
|
+
else:
|
|
875
|
+
if not sub_expr.lower() in item.text().lower():
|
|
876
|
+
return False
|
|
877
|
+
else: # If it's not a field key, let it be a regular search term
|
|
878
|
+
expr_list.append(expr)
|
|
879
|
+
else:
|
|
880
|
+
expr_list.append(expr)
|
|
881
|
+
expression = ' '.join(expr_list)
|
|
882
|
+
|
|
883
|
+
# General case: if any fields match the remaining expression, success.
|
|
884
|
+
for col in range(table.columnCount()):
|
|
885
|
+
item = table.item(row, col)
|
|
886
|
+
itemtext = item.text()
|
|
887
|
+
if case_sensitive:
|
|
888
|
+
if expression in itemtext:
|
|
889
|
+
return True
|
|
890
|
+
else:
|
|
891
|
+
if expression.lower() in itemtext.lower():
|
|
892
|
+
return True
|
|
893
|
+
return False
|
|
894
|
+
|
|
895
|
+
def generate_episode_menus(self, menu, max_eps=1, watched_eps=0):
|
|
896
|
+
bp_top = 5 # No more than this many submenus/episodes in the root menu
|
|
897
|
+
bp_mid = 10 # No more than this many submenus in submenus
|
|
898
|
+
bp_btm = 13 # No more than this many episodes in the submenus
|
|
899
|
+
# The number of episodes where we ditch the submenus entirely since Qt doesn't deserve this abuse
|
|
900
|
+
breakpoint_no_menus = bp_top * bp_btm * bp_mid * bp_mid
|
|
901
|
+
|
|
902
|
+
menu.clear()
|
|
903
|
+
# Make basic actions
|
|
904
|
+
action_play_next = QAction(getIcon('media-skip-forward'), 'Play &Next Episode', self)
|
|
905
|
+
action_play_next.triggered.connect(lambda: self.s_play(True))
|
|
906
|
+
action_play_last = QAction(getIcon('view-refresh'), 'Play Last Watched Ep (#%d)' % watched_eps, self)
|
|
907
|
+
action_play_last.triggered.connect(lambda: self.s_play(False))
|
|
908
|
+
action_play_dialog = QAction('Play Episode...', self)
|
|
909
|
+
action_play_dialog.setStatusTip('Select an episode to play.')
|
|
910
|
+
action_play_dialog.triggered.connect(self.s_play_number)
|
|
911
|
+
|
|
912
|
+
menu.addAction(action_play_next)
|
|
913
|
+
menu.addAction(action_play_last)
|
|
914
|
+
|
|
915
|
+
if max_eps < 1 or max_eps > breakpoint_no_menus:
|
|
916
|
+
menu.addAction(action_play_dialog)
|
|
917
|
+
return menu
|
|
918
|
+
menu.addSeparator()
|
|
919
|
+
|
|
920
|
+
ep_actions = []
|
|
921
|
+
for ep in range(1, max_eps+1):
|
|
922
|
+
action = QAction('Ep. %d' % ep, self)
|
|
923
|
+
action.triggered.connect(self.s_play_ep_number(action, ep))
|
|
924
|
+
if ep <= watched_eps:
|
|
925
|
+
action.setIcon(self.ep_icons['all'])
|
|
926
|
+
else:
|
|
927
|
+
action.setIcon(self.ep_icons['none'])
|
|
928
|
+
ep_actions.append(action)
|
|
929
|
+
|
|
930
|
+
if max_eps <= bp_top:
|
|
931
|
+
# Just put the eps in the root menu
|
|
932
|
+
for action in ep_actions:
|
|
933
|
+
menu.addAction(action)
|
|
934
|
+
|
|
935
|
+
else:
|
|
936
|
+
# We need to go deeper. For now, put all the episodes into bottom-level submenus.
|
|
937
|
+
self.play_ep_submenus = [] # I don't like this scoping. If you find a way to transfer ownership of the submenu to the menu feel free to fix this.
|
|
938
|
+
current_actions = bp_btm + 1 # A bit hacky but avoids a special case for the first submenu
|
|
939
|
+
for action in ep_actions:
|
|
940
|
+
if current_actions >= bp_btm:
|
|
941
|
+
current_actions = 0
|
|
942
|
+
l = len(self.play_ep_submenus)
|
|
943
|
+
self.play_ep_submenus.append(QMenu('Episodes %d-%d:' % (l*bp_btm + 1, min((l+1)*bp_btm, max_eps))))
|
|
944
|
+
if watched_eps > min((l+1)*bp_btm, max_eps):
|
|
945
|
+
self.play_ep_submenus[-1].setIcon(self.ep_icons['all'])
|
|
946
|
+
elif watched_eps > l*bp_btm:
|
|
947
|
+
self.play_ep_submenus[-1].setIcon(self.ep_icons['part'])
|
|
948
|
+
else:
|
|
949
|
+
self.play_ep_submenus[-1].setIcon(self.ep_icons['none'])
|
|
950
|
+
self.play_ep_submenus[-1].addAction(action)
|
|
951
|
+
current_actions += 1
|
|
952
|
+
|
|
953
|
+
# Now to put the bottom level menus into other things
|
|
954
|
+
if len(self.play_ep_submenus) <= bp_top: # Straight into the root menu, easy!
|
|
955
|
+
for submenu in self.play_ep_submenus:
|
|
956
|
+
menu.addMenu(submenu)
|
|
957
|
+
else: # For now, put them into another level of submenus
|
|
958
|
+
self.play_ep_sub2menus = []
|
|
959
|
+
current_menus = bp_mid + 1
|
|
960
|
+
for s in self.play_ep_submenus:
|
|
961
|
+
if current_menus >= bp_mid:
|
|
962
|
+
current_menus = 0
|
|
963
|
+
l = len(self.play_ep_sub2menus)
|
|
964
|
+
self.play_ep_sub2menus.append(QMenu('Episodes %d-%d:' % (l*bp_btm*bp_mid + 1, min((l+1)*bp_btm*bp_mid, max_eps))))
|
|
965
|
+
self.play_ep_sub2menus[-1].addMenu(s)
|
|
966
|
+
if watched_eps > min((l+1)*bp_btm*bp_mid, max_eps):
|
|
967
|
+
self.play_ep_sub2menus[-1].setIcon(self.ep_icons['all'])
|
|
968
|
+
elif watched_eps > l*bp_btm*bp_mid:
|
|
969
|
+
self.play_ep_sub2menus[-1].setIcon(self.ep_icons['part'])
|
|
970
|
+
else:
|
|
971
|
+
self.play_ep_sub2menus[-1].setIcon(self.ep_icons['none'])
|
|
972
|
+
current_menus += 1
|
|
973
|
+
|
|
974
|
+
if len(self.play_ep_sub2menus) <= bp_top:
|
|
975
|
+
for submenu in self.play_ep_sub2menus:
|
|
976
|
+
menu.addMenu(submenu)
|
|
977
|
+
else:
|
|
978
|
+
# I seriously hope this additional level is not needed, but maybe someone will want to set smaller breakpoints.
|
|
979
|
+
self.play_ep_sub3menus = []
|
|
980
|
+
current_menus = bp_mid + 1
|
|
981
|
+
for s in self.play_ep_sub2menus:
|
|
982
|
+
if current_menus >= bp_mid:
|
|
983
|
+
current_menus = 0
|
|
984
|
+
l = len(self.play_ep_sub3menus)
|
|
985
|
+
self.play_ep_sub3menus.append(QMenu('Episodes %d-%d:' % (l*bp_btm*bp_mid*bp_mid + 1, min((l+1)*bp_btm*bp_mid*bp_mid, max_eps))))
|
|
986
|
+
self.play_ep_sub3menus[-1].addMenu(s)
|
|
987
|
+
if watched_eps > min((l+1)*bp_btm*bp_mid*bp_mid, max_eps):
|
|
988
|
+
self.play_ep_sub3menus[-1].setIcon(self.ep_icons['all'])
|
|
989
|
+
elif watched_eps > l*bp_btm*bp_mid*bp_mid:
|
|
990
|
+
self.play_ep_sub3menus[-1].setIcon(self.ep_icons['part'])
|
|
991
|
+
else:
|
|
992
|
+
self.play_ep_sub3menus[-1].setIcon(self.ep_icons['none'])
|
|
993
|
+
current_menus += 1
|
|
994
|
+
# No more levels, our sanity check earlier ensured that.
|
|
995
|
+
for submenu in self.play_ep_sub3menus:
|
|
996
|
+
menu.addMenu(submenu)
|
|
997
|
+
return menu
|
|
998
|
+
|
|
999
|
+
### Slots
|
|
1000
|
+
def s_hide(self):
|
|
1001
|
+
if self.isVisible():
|
|
1002
|
+
self.was_maximized = self.isMaximized()
|
|
1003
|
+
self.hide()
|
|
1004
|
+
else:
|
|
1005
|
+
self.setGeometry(self.geometry())
|
|
1006
|
+
if self.was_maximized:
|
|
1007
|
+
self.showMaximized()
|
|
1008
|
+
else:
|
|
1009
|
+
self.show()
|
|
1010
|
+
|
|
1011
|
+
def s_tray_clicked(self, reason):
|
|
1012
|
+
if reason == QSystemTrayIcon.Trigger:
|
|
1013
|
+
self.s_hide()
|
|
1014
|
+
|
|
1015
|
+
def s_busy(self):
|
|
1016
|
+
self._enable_widgets(False)
|
|
1017
|
+
|
|
1018
|
+
def s_show_selected(self, new, old=None):
|
|
1019
|
+
if new:
|
|
1020
|
+
index = new.row()
|
|
1021
|
+
selected_id = self.notebook.currentWidget().item( index, 0 ).text()
|
|
1022
|
+
|
|
1023
|
+
# Attempt to convert to int if possible
|
|
1024
|
+
try:
|
|
1025
|
+
selected_id = int(selected_id)
|
|
1026
|
+
except ValueError:
|
|
1027
|
+
selected_id = str(selected_id)
|
|
1028
|
+
|
|
1029
|
+
show = self.worker.engine.get_show_info(selected_id)
|
|
1030
|
+
self._select_show(show)
|
|
1031
|
+
else:
|
|
1032
|
+
self._select_show(None)
|
|
1033
|
+
|
|
1034
|
+
def s_download_image(self):
|
|
1035
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1036
|
+
self.show_image.setText('Downloading...')
|
|
1037
|
+
filename = utils.get_filename('cache', "%s_%s_%s.jpg" % (self.api_info['shortname'], self.api_info['mediatype'], show['id']))
|
|
1038
|
+
|
|
1039
|
+
self.image_worker = Image_Worker(show.get('image_thumb') or show['image'], filename, (100, 140))
|
|
1040
|
+
self.image_worker.finished.connect(self.s_show_image)
|
|
1041
|
+
self.image_worker.start()
|
|
1042
|
+
|
|
1043
|
+
def s_tab_changed(self):
|
|
1044
|
+
item = self.notebook.currentWidget().currentItem()
|
|
1045
|
+
if item:
|
|
1046
|
+
self.s_show_selected(item)
|
|
1047
|
+
self.s_filter_changed() # Refresh filter
|
|
1048
|
+
|
|
1049
|
+
def s_filter_changed(self):
|
|
1050
|
+
tabs = []
|
|
1051
|
+
if self.config['filter_global']:
|
|
1052
|
+
tabs = range(len(self.notebook))
|
|
1053
|
+
else:
|
|
1054
|
+
tabs = [self.notebook.currentIndex()]
|
|
1055
|
+
expr = self.show_filter.text()
|
|
1056
|
+
casesens = self.show_filter_casesens.isChecked()
|
|
1057
|
+
for tab_index in tabs:
|
|
1058
|
+
table = self.notebook.widget(tab_index)
|
|
1059
|
+
shown = 0
|
|
1060
|
+
total = 0
|
|
1061
|
+
for row in range(table.rowCount()):
|
|
1062
|
+
if not expr:
|
|
1063
|
+
table.setRowHidden(row, False)
|
|
1064
|
+
elif self.show_filter_invert.isChecked():
|
|
1065
|
+
table.setRowHidden(row, self._filter_check_row(table, row, expr, casesens))
|
|
1066
|
+
else:
|
|
1067
|
+
table.setRowHidden(row, not self._filter_check_row(table, row, expr, casesens))
|
|
1068
|
+
if not table.isRowHidden(row):
|
|
1069
|
+
shown += 1
|
|
1070
|
+
total += 1
|
|
1071
|
+
# Update tab name with matches out of total
|
|
1072
|
+
status = self.statuses_nums[tab_index]
|
|
1073
|
+
if expr:
|
|
1074
|
+
tab_name = "%s (%d/%d)" % (self.statuses_names[status], shown, total)
|
|
1075
|
+
else:
|
|
1076
|
+
tab_name = "%s (%d)" % (self.statuses_names[status], total) # Filter disabled
|
|
1077
|
+
self.notebook.setTabText(tab_index, tab_name)
|
|
1078
|
+
|
|
1079
|
+
def s_plus_episode(self):
|
|
1080
|
+
self._busy(True)
|
|
1081
|
+
self.worker_call('set_episode', self.r_generic, self.selected_show_id, self.show_progress.value()+1)
|
|
1082
|
+
|
|
1083
|
+
def s_rem_episode(self):
|
|
1084
|
+
if not self.show_progress.value() <= 0:
|
|
1085
|
+
self._busy(True)
|
|
1086
|
+
self.worker_call('set_episode', self.r_generic, self.selected_show_id, self.show_progress.value()-1)
|
|
1087
|
+
|
|
1088
|
+
def s_set_episode(self):
|
|
1089
|
+
self._busy(True)
|
|
1090
|
+
self.worker_call('set_episode', self.r_generic, self.selected_show_id, self.show_progress.value())
|
|
1091
|
+
|
|
1092
|
+
def s_set_score(self):
|
|
1093
|
+
self._busy(True)
|
|
1094
|
+
self.worker_call('set_score', self.r_generic, self.selected_show_id, self.show_score.value())
|
|
1095
|
+
|
|
1096
|
+
def s_set_status(self, index):
|
|
1097
|
+
if self.selected_show_id:
|
|
1098
|
+
self._busy(True)
|
|
1099
|
+
self.worker_call('set_status', self.r_generic, self.selected_show_id, self.statuses_nums[index])
|
|
1100
|
+
|
|
1101
|
+
def s_set_tags(self):
|
|
1102
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1103
|
+
if show['my_tags']:
|
|
1104
|
+
tags = show['my_tags']
|
|
1105
|
+
else:
|
|
1106
|
+
tags = ''
|
|
1107
|
+
tags, ok = QInputDialog.getText(self, 'Edit Tags',
|
|
1108
|
+
'Enter desired tags (comma separated)',
|
|
1109
|
+
text=tags)
|
|
1110
|
+
if ok:
|
|
1111
|
+
self.s_edit_tags(show, tags)
|
|
1112
|
+
|
|
1113
|
+
def s_edit_tags(self, show, tags):
|
|
1114
|
+
self._busy(True)
|
|
1115
|
+
self.worker_call('set_tags', self.r_generic, show['id'], tags)
|
|
1116
|
+
|
|
1117
|
+
def s_play(self, play_next, episode=0):
|
|
1118
|
+
if self.selected_show_id:
|
|
1119
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1120
|
+
|
|
1121
|
+
#episode = 0 # Engine plays next unwatched episode
|
|
1122
|
+
if not play_next and not episode:
|
|
1123
|
+
episode = self.show_progress.value()
|
|
1124
|
+
|
|
1125
|
+
self._busy(True)
|
|
1126
|
+
self.worker_call('play_episode', self.r_generic, show, episode)
|
|
1127
|
+
|
|
1128
|
+
def s_play_random(self):
|
|
1129
|
+
self._busy(True)
|
|
1130
|
+
self.worker_call('play_random', self.r_generic)
|
|
1131
|
+
|
|
1132
|
+
def s_play_number(self):
|
|
1133
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1134
|
+
ep_default = 1
|
|
1135
|
+
ep_min = 1
|
|
1136
|
+
ep_max = utils.estimate_aired_episodes(show)
|
|
1137
|
+
if ep_max is None:
|
|
1138
|
+
ep_max = max(show['total'],1)
|
|
1139
|
+
episode, ok = QInputDialog.getInt(self, 'Play Episode',
|
|
1140
|
+
'Enter an episode number of %s to play:' % show['title'],
|
|
1141
|
+
ep_default, ep_min, ep_max)
|
|
1142
|
+
if ok:
|
|
1143
|
+
self.s_play(False, episode)
|
|
1144
|
+
|
|
1145
|
+
def s_play_ep_number(self, action, number):
|
|
1146
|
+
return lambda: [action.setIcon(self.ep_icons['part']), self.s_play(False, number)]
|
|
1147
|
+
|
|
1148
|
+
def s_delete(self):
|
|
1149
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1150
|
+
reply = QMessageBox.question(self, 'Confirmation',
|
|
1151
|
+
'Are you sure you want to delete %s?' % show['title'],
|
|
1152
|
+
QMessageBox.Yes, QMessageBox.No)
|
|
1153
|
+
|
|
1154
|
+
if reply == QMessageBox.Yes:
|
|
1155
|
+
self.worker_call('delete_show', self.r_generic, show)
|
|
1156
|
+
|
|
1157
|
+
def s_scan_library(self):
|
|
1158
|
+
self._busy(True)
|
|
1159
|
+
self.worker_call('scan_library', self.r_library_scanned)
|
|
1160
|
+
|
|
1161
|
+
def s_altname(self):
|
|
1162
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1163
|
+
current_altname = self.worker.engine.altname(self.selected_show_id)
|
|
1164
|
+
|
|
1165
|
+
new_altname, ok = QInputDialog.getText(self, 'Alternative title',
|
|
1166
|
+
'Set the new alternative title for %s (blank to remove):' % show['title'],
|
|
1167
|
+
text=current_altname)
|
|
1168
|
+
|
|
1169
|
+
if ok:
|
|
1170
|
+
self.worker.engine.altname(self.selected_show_id, str(new_altname))
|
|
1171
|
+
self.ws_changed_show(show, altname=new_altname)
|
|
1172
|
+
|
|
1173
|
+
def s_retrieve(self):
|
|
1174
|
+
queue = self.worker.engine.get_queue()
|
|
1175
|
+
|
|
1176
|
+
if queue:
|
|
1177
|
+
reply = QMessageBox.question(self, 'Confirmation',
|
|
1178
|
+
'There are %d unsynced changes. Do you want to send them first? (Choosing No will discard them!)' % len(queue),
|
|
1179
|
+
QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel)
|
|
1180
|
+
|
|
1181
|
+
if reply == QMessageBox.Yes:
|
|
1182
|
+
self.s_send(True)
|
|
1183
|
+
elif reply == QMessageBox.No:
|
|
1184
|
+
self._busy(True)
|
|
1185
|
+
self.worker_call('list_download', self.r_list_retrieved)
|
|
1186
|
+
else:
|
|
1187
|
+
self._busy(True)
|
|
1188
|
+
self.worker_call('list_download', self.r_list_retrieved)
|
|
1189
|
+
|
|
1190
|
+
def s_send(self, retrieve=False):
|
|
1191
|
+
self._busy(True)
|
|
1192
|
+
if retrieve:
|
|
1193
|
+
self.worker_call('list_upload', self.s_retrieve)
|
|
1194
|
+
else:
|
|
1195
|
+
self.worker_call('list_upload', self.r_generic_ready)
|
|
1196
|
+
|
|
1197
|
+
def s_switch_account(self):
|
|
1198
|
+
self.accountman_widget.setModal(True)
|
|
1199
|
+
self.accountman_widget.show()
|
|
1200
|
+
|
|
1201
|
+
def s_show_image(self, filename):
|
|
1202
|
+
self.show_image.setPixmap( QtGui.QPixmap( filename ) )
|
|
1203
|
+
|
|
1204
|
+
def s_show_details(self):
|
|
1205
|
+
if not self.selected_show_id:
|
|
1206
|
+
return
|
|
1207
|
+
|
|
1208
|
+
show = self.worker.engine.get_show_info(self.selected_show_id)
|
|
1209
|
+
|
|
1210
|
+
self.detailswindow = DetailsDialog(None, self.worker, show)
|
|
1211
|
+
self.detailswindow.setModal(True)
|
|
1212
|
+
self.detailswindow.show()
|
|
1213
|
+
|
|
1214
|
+
def s_add(self):
|
|
1215
|
+
page = self.notebook.currentIndex()
|
|
1216
|
+
current_status = self.statuses_nums[page]
|
|
1217
|
+
|
|
1218
|
+
self.addwindow = AddDialog(None, self.worker, current_status)
|
|
1219
|
+
self.addwindow.setModal(True)
|
|
1220
|
+
self.addwindow.show()
|
|
1221
|
+
|
|
1222
|
+
def s_mediatype(self, action):
|
|
1223
|
+
index = action.data()
|
|
1224
|
+
mediatype = self.api_info['supported_mediatypes'][index]
|
|
1225
|
+
self.reload(None, mediatype)
|
|
1226
|
+
|
|
1227
|
+
def s_settings(self):
|
|
1228
|
+
dialog = SettingsDialog(None, self.worker, self.config, self.configfile)
|
|
1229
|
+
dialog.saved.connect(self._update_config)
|
|
1230
|
+
dialog.exec_()
|
|
1231
|
+
|
|
1232
|
+
def s_about(self):
|
|
1233
|
+
QMessageBox.about(self, 'About Trackma-qt %s' % utils.VERSION,
|
|
1234
|
+
'<p><b>About Trackma-qt %s</b></p><p>Trackma is an open source client for media tracking websites.</p>'
|
|
1235
|
+
'<p>This program is licensed under the GPLv3, for more information read COPYING file.</p>'
|
|
1236
|
+
'<p>Thanks to all contributors. To see all contributors see AUTHORS file.</p>'
|
|
1237
|
+
'<p>Copyright (C) z411 - Icon by shuuichi</p>'
|
|
1238
|
+
'<p><a href="http://github.com/z411/trackma">http://github.com/z411/trackma</a></p>' % utils.VERSION)
|
|
1239
|
+
|
|
1240
|
+
def s_about_qt(self):
|
|
1241
|
+
QMessageBox.aboutQt(self, 'About Qt')
|
|
1242
|
+
|
|
1243
|
+
def s_show_menu_columns(self, pos):
|
|
1244
|
+
globalPos = self.sender().mapToGlobal(pos)
|
|
1245
|
+
globalPos += QtCore.QPoint(3, 3)
|
|
1246
|
+
self.menu_columns.exec_(globalPos)
|
|
1247
|
+
|
|
1248
|
+
def s_toggle_column(self, w):
|
|
1249
|
+
(column_name, visible) = (w.text(), w.isChecked())
|
|
1250
|
+
index = self.available_columns.index(column_name)
|
|
1251
|
+
MIN_WIDTH = 30 # Width to restore columns to if too small to see
|
|
1252
|
+
|
|
1253
|
+
if visible:
|
|
1254
|
+
if column_name not in self.config['visible_columns']:
|
|
1255
|
+
self.config['visible_columns'].append(str(column_name))
|
|
1256
|
+
else:
|
|
1257
|
+
if column_name in self.config['visible_columns']:
|
|
1258
|
+
self.config['visible_columns'].remove(column_name)
|
|
1259
|
+
|
|
1260
|
+
utils.save_config(self.config, self.configfile)
|
|
1261
|
+
if self.config['columns_per_api']:
|
|
1262
|
+
self.api_config['visible_columns'] = self.config['visible_columns']
|
|
1263
|
+
utils.save_config(self.api_config, self.api_configfile)
|
|
1264
|
+
|
|
1265
|
+
for showlist in self.show_lists.values():
|
|
1266
|
+
showlist.setColumnHidden(index, not visible)
|
|
1267
|
+
if visible and showlist.columnWidth(index) < MIN_WIDTH:
|
|
1268
|
+
showlist.setColumnWidth(index, MIN_WIDTH)
|
|
1269
|
+
|
|
1270
|
+
### Worker slots
|
|
1271
|
+
def ws_changed_show(self, show, is_playing=False, episode=None, altname=None):
|
|
1272
|
+
if show:
|
|
1273
|
+
if not self.show_lists:
|
|
1274
|
+
return # Lists not built yet; can be safely avoided
|
|
1275
|
+
|
|
1276
|
+
widget = self.show_lists[show['my_status']]
|
|
1277
|
+
row = self._get_row_from_showid(widget, show['id'])
|
|
1278
|
+
|
|
1279
|
+
if row is None:
|
|
1280
|
+
return # Row not in list yet; can be safely avoided
|
|
1281
|
+
|
|
1282
|
+
library = self.worker.engine.library()
|
|
1283
|
+
|
|
1284
|
+
widget.setSortingEnabled(False)
|
|
1285
|
+
self._update_row(widget, row, show, altname, library.get(show['id']), is_playing)
|
|
1286
|
+
widget.setSortingEnabled(True)
|
|
1287
|
+
|
|
1288
|
+
if show['id'] == self.selected_show_id:
|
|
1289
|
+
self._select_show(show)
|
|
1290
|
+
|
|
1291
|
+
if is_playing and self.config['show_tray'] and self.config['notifications']:
|
|
1292
|
+
if episode == (show['my_progress'] + 1):
|
|
1293
|
+
delay = self.worker.engine.get_config('tracker_update_wait_s')
|
|
1294
|
+
self.tray.showMessage('Trackma Tracker', "Playing %s %s. Will update in %d seconds." % (show['title'], episode, delay))
|
|
1295
|
+
|
|
1296
|
+
def ws_changed_list(self, show, old_status=None):
|
|
1297
|
+
# Rebuild both new and old (if any) lists
|
|
1298
|
+
self._rebuild_list(show['my_status'])
|
|
1299
|
+
if old_status:
|
|
1300
|
+
self._rebuild_list(old_status)
|
|
1301
|
+
|
|
1302
|
+
# Set notebook to the new page
|
|
1303
|
+
self.notebook.setCurrentIndex( self.statuses_nums.index(show['my_status']) )
|
|
1304
|
+
# Refresh filter
|
|
1305
|
+
self.s_filter_changed()
|
|
1306
|
+
|
|
1307
|
+
def ws_changed_queue(self, queue):
|
|
1308
|
+
self._update_queue_counter(queue)
|
|
1309
|
+
|
|
1310
|
+
def ws_prompt_update(self, show, episode):
|
|
1311
|
+
reply = QMessageBox.question(self, 'Message',
|
|
1312
|
+
'Do you want to update %s to %d?' % (show['title'], episode),
|
|
1313
|
+
QMessageBox.Yes, QMessageBox.No)
|
|
1314
|
+
|
|
1315
|
+
if reply == QMessageBox.Yes:
|
|
1316
|
+
self.worker_call('set_episode', self.r_generic, show['id'], episode)
|
|
1317
|
+
|
|
1318
|
+
### Responses from the engine thread
|
|
1319
|
+
def r_generic(self):
|
|
1320
|
+
self._unbusy()
|
|
1321
|
+
|
|
1322
|
+
def r_generic_ready(self):
|
|
1323
|
+
self._unbusy()
|
|
1324
|
+
self.status('Ready.')
|
|
1325
|
+
|
|
1326
|
+
def r_engine_loaded(self, result):
|
|
1327
|
+
if result['success']:
|
|
1328
|
+
showlist = self.worker.engine.get_list()
|
|
1329
|
+
altnames = self.worker.engine.altnames()
|
|
1330
|
+
library = self.worker.engine.library()
|
|
1331
|
+
|
|
1332
|
+
self.notebook.blockSignals(True)
|
|
1333
|
+
self.show_status.blockSignals(True)
|
|
1334
|
+
|
|
1335
|
+
# Set globals
|
|
1336
|
+
self.notebook.clear()
|
|
1337
|
+
self.show_status.clear()
|
|
1338
|
+
self.show_lists = dict()
|
|
1339
|
+
|
|
1340
|
+
self.api_info = self.worker.engine.api_info
|
|
1341
|
+
self.mediainfo = self.worker.engine.mediainfo
|
|
1342
|
+
|
|
1343
|
+
self.statuses_nums = self.mediainfo['statuses']
|
|
1344
|
+
self.statuses_names = self.mediainfo['statuses_dict']
|
|
1345
|
+
|
|
1346
|
+
# Set allowed ranges (this should be reported by the engine later)
|
|
1347
|
+
decimal_places = 0
|
|
1348
|
+
if isinstance( self.mediainfo['score_step'], float ):
|
|
1349
|
+
decimal_places = len(str(self.mediainfo['score_step']).split('.')[1])
|
|
1350
|
+
|
|
1351
|
+
self.show_score.setRange(0, self.mediainfo['score_max'])
|
|
1352
|
+
self.show_score.setDecimals(decimal_places)
|
|
1353
|
+
self.show_score.setSingleStep(self.mediainfo['score_step'])
|
|
1354
|
+
|
|
1355
|
+
# Build notebook
|
|
1356
|
+
for status in self.statuses_nums:
|
|
1357
|
+
name = self.statuses_names[status]
|
|
1358
|
+
|
|
1359
|
+
self.show_lists[status] = ShowsTableWidget()
|
|
1360
|
+
self.show_lists[status].context_menu = self.menu_show_context
|
|
1361
|
+
self.show_lists[status].setSelectionMode(QAbstractItemView.SingleSelection)
|
|
1362
|
+
#self.show_lists[status].setFocusPolicy(QtCore.Qt.NoFocus)
|
|
1363
|
+
self.show_lists[status].setSelectionBehavior(QAbstractItemView.SelectRows)
|
|
1364
|
+
self.show_lists[status].setEditTriggers(QAbstractItemView.NoEditTriggers)
|
|
1365
|
+
self.show_lists[status].horizontalHeader().setHighlightSections(False)
|
|
1366
|
+
if pyqt_version is 5:
|
|
1367
|
+
self.show_lists[status].horizontalHeader().setSectionsMovable(True)
|
|
1368
|
+
else:
|
|
1369
|
+
self.show_lists[status].horizontalHeader().setMovable(True)
|
|
1370
|
+
self.show_lists[status].horizontalHeader().setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
|
1371
|
+
self.show_lists[status].horizontalHeader().customContextMenuRequested.connect(self.s_show_menu_columns)
|
|
1372
|
+
self.show_lists[status].verticalHeader().hide()
|
|
1373
|
+
self.show_lists[status].setGridStyle(QtCore.Qt.NoPen)
|
|
1374
|
+
self.show_lists[status].currentItemChanged.connect(self.s_show_selected)
|
|
1375
|
+
self.show_lists[status].doubleClicked.connect(self.s_show_details)
|
|
1376
|
+
|
|
1377
|
+
self.notebook.addTab(self.show_lists[status], name)
|
|
1378
|
+
self.show_status.addItem(name)
|
|
1379
|
+
|
|
1380
|
+
self.show_status.blockSignals(False)
|
|
1381
|
+
self.notebook.blockSignals(False)
|
|
1382
|
+
|
|
1383
|
+
# Build mediatype menu
|
|
1384
|
+
for action in self.mediatype_actiongroup.actions():
|
|
1385
|
+
self.mediatype_actiongroup.removeAction(action)
|
|
1386
|
+
|
|
1387
|
+
for n, mediatype in enumerate(self.api_info['supported_mediatypes']):
|
|
1388
|
+
action = QAction(mediatype, self, checkable=True)
|
|
1389
|
+
if mediatype == self.api_info['mediatype']:
|
|
1390
|
+
action.setChecked(True)
|
|
1391
|
+
else:
|
|
1392
|
+
action.setData(n)
|
|
1393
|
+
self.mediatype_actiongroup.addAction(action)
|
|
1394
|
+
self.menu_mediatype.addAction(action)
|
|
1395
|
+
|
|
1396
|
+
# Show API info
|
|
1397
|
+
self.api_icon.setPixmap( QtGui.QPixmap( utils.available_libs[self.account['api']][1] ) )
|
|
1398
|
+
if self.config['tray_api_icon']:
|
|
1399
|
+
self.tray.setIcon( QIcon( utils.available_libs[self.account['api']][1] ) )
|
|
1400
|
+
self.api_user.setText( self.worker.engine.get_userconfig('username') )
|
|
1401
|
+
self.setWindowTitle( "Trackma-qt %s [%s (%s)]" % (utils.VERSION, self.api_info['name'], self.api_info['mediatype']) )
|
|
1402
|
+
|
|
1403
|
+
# Rebuild lists
|
|
1404
|
+
self._rebuild_lists(showlist, altnames, library)
|
|
1405
|
+
|
|
1406
|
+
self.s_show_selected(None)
|
|
1407
|
+
self._update_queue_counter( len( self.worker.engine.get_queue() ) )
|
|
1408
|
+
|
|
1409
|
+
self.status('Ready.')
|
|
1410
|
+
|
|
1411
|
+
self._unbusy()
|
|
1412
|
+
|
|
1413
|
+
def r_list_retrieved(self, result):
|
|
1414
|
+
if result['success']:
|
|
1415
|
+
showlist = self.worker.engine.get_list()
|
|
1416
|
+
altnames = self.worker.engine.altnames()
|
|
1417
|
+
library = self.worker.engine.library()
|
|
1418
|
+
self._rebuild_lists(showlist, altnames, library)
|
|
1419
|
+
|
|
1420
|
+
self.status('Ready.')
|
|
1421
|
+
|
|
1422
|
+
self._unbusy()
|
|
1423
|
+
|
|
1424
|
+
def r_library_scanned(self, result):
|
|
1425
|
+
if result['success']:
|
|
1426
|
+
status = self.worker.engine.mediainfo['status_start']
|
|
1427
|
+
|
|
1428
|
+
showlist = self.worker.engine.filter_list(status)
|
|
1429
|
+
altnames = self.worker.engine.altnames()
|
|
1430
|
+
library = self.worker.engine.library()
|
|
1431
|
+
self._rebuild_list(status, showlist, altnames, library)
|
|
1432
|
+
|
|
1433
|
+
self.status('Ready.')
|
|
1434
|
+
|
|
1435
|
+
self._unbusy()
|
|
1436
|
+
|
|
1437
|
+
def r_engine_unloaded(self, result):
|
|
1438
|
+
if result['success']:
|
|
1439
|
+
self.close()
|
|
1440
|
+
if not self.finish:
|
|
1441
|
+
self.s_switch_account()
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
class DetailsDialog(QDialog):
|
|
1445
|
+
def __init__(self, parent, worker, show):
|
|
1446
|
+
QDialog.__init__(self, parent)
|
|
1447
|
+
self.setMinimumSize(530, 550)
|
|
1448
|
+
self.setWindowTitle('Details')
|
|
1449
|
+
self.worker = worker
|
|
1450
|
+
|
|
1451
|
+
main_layout = QVBoxLayout()
|
|
1452
|
+
details = DetailsWidget(self, worker)
|
|
1453
|
+
|
|
1454
|
+
bottom_buttons = QDialogButtonBox(QDialogButtonBox.Close)
|
|
1455
|
+
bottom_buttons.setCenterButtons(True)
|
|
1456
|
+
bottom_buttons.rejected.connect(self.close)
|
|
1457
|
+
|
|
1458
|
+
main_layout.addWidget(details)
|
|
1459
|
+
main_layout.addWidget(bottom_buttons)
|
|
1460
|
+
|
|
1461
|
+
self.setLayout(main_layout)
|
|
1462
|
+
details.load(show)
|
|
1463
|
+
|
|
1464
|
+
class DetailsWidget(QWidget):
|
|
1465
|
+
def __init__(self, parent, worker):
|
|
1466
|
+
self.worker = worker
|
|
1467
|
+
|
|
1468
|
+
QWidget.__init__(self, parent)
|
|
1469
|
+
|
|
1470
|
+
# Build layout
|
|
1471
|
+
main_layout = QVBoxLayout()
|
|
1472
|
+
main_layout.setContentsMargins(0, 0, 0, 0)
|
|
1473
|
+
|
|
1474
|
+
self.show_title = QLabel()
|
|
1475
|
+
show_title_font = QtGui.QFont()
|
|
1476
|
+
show_title_font.setBold(True)
|
|
1477
|
+
show_title_font.setPointSize(12)
|
|
1478
|
+
self.show_title.setAlignment( QtCore.Qt.AlignCenter )
|
|
1479
|
+
self.show_title.setFont(show_title_font)
|
|
1480
|
+
|
|
1481
|
+
info_area = QWidget()
|
|
1482
|
+
info_layout = QGridLayout()
|
|
1483
|
+
|
|
1484
|
+
self.show_image = QLabel()
|
|
1485
|
+
self.show_image.setAlignment( QtCore.Qt.AlignTop )
|
|
1486
|
+
self.show_info = QLabel()
|
|
1487
|
+
self.show_info.setWordWrap(True)
|
|
1488
|
+
self.show_info.setAlignment( QtCore.Qt.AlignTop )
|
|
1489
|
+
self.show_description = QLabel()
|
|
1490
|
+
self.show_description.setWordWrap(True)
|
|
1491
|
+
self.show_description.setAlignment( QtCore.Qt.AlignTop )
|
|
1492
|
+
|
|
1493
|
+
info_layout.addWidget( self.show_image, 0,0,1,1 )
|
|
1494
|
+
info_layout.addWidget( self.show_info, 1,0,1,1 )
|
|
1495
|
+
info_layout.addWidget( self.show_description, 0,1,2,1 )
|
|
1496
|
+
|
|
1497
|
+
info_area.setLayout(info_layout)
|
|
1498
|
+
|
|
1499
|
+
scroll_area = QScrollArea()
|
|
1500
|
+
scroll_area.setBackgroundRole(QPalette.Light)
|
|
1501
|
+
scroll_area.setWidgetResizable(True)
|
|
1502
|
+
scroll_area.setWidget(info_area)
|
|
1503
|
+
|
|
1504
|
+
main_layout.addWidget(self.show_title)
|
|
1505
|
+
main_layout.addWidget(scroll_area)
|
|
1506
|
+
|
|
1507
|
+
self.setLayout(main_layout)
|
|
1508
|
+
|
|
1509
|
+
def worker_call(self, function, ret_function, *args, **kwargs):
|
|
1510
|
+
# Run worker in a thread
|
|
1511
|
+
self.worker.set_function(function, ret_function, *args, **kwargs)
|
|
1512
|
+
self.worker.start()
|
|
1513
|
+
|
|
1514
|
+
def load(self, show):
|
|
1515
|
+
self.show_title.setText( "<a href=\"%s\">%s</a>" % (show['url'], show['title']) )
|
|
1516
|
+
self.show_title.setTextFormat(QtCore.Qt.RichText)
|
|
1517
|
+
self.show_title.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
|
1518
|
+
self.show_title.setOpenExternalLinks(True)
|
|
1519
|
+
|
|
1520
|
+
# Load show info
|
|
1521
|
+
self.show_info.setText('Wait...')
|
|
1522
|
+
self.worker_call('get_show_details', self.r_details_loaded, show)
|
|
1523
|
+
api_info = self.worker.engine.api_info
|
|
1524
|
+
|
|
1525
|
+
# Load show image
|
|
1526
|
+
filename = utils.get_filename('cache', "%s_%s_f_%s.jpg" % (api_info['shortname'], api_info['mediatype'], show['id']))
|
|
1527
|
+
|
|
1528
|
+
if os.path.isfile(filename):
|
|
1529
|
+
self.s_show_image(filename)
|
|
1530
|
+
else:
|
|
1531
|
+
self.show_image.setText('Downloading...')
|
|
1532
|
+
self.image_worker = Image_Worker(show['image'], filename)
|
|
1533
|
+
self.image_worker.finished.connect(self.s_show_image)
|
|
1534
|
+
self.image_worker.start()
|
|
1535
|
+
|
|
1536
|
+
def s_show_image(self, filename):
|
|
1537
|
+
self.show_image.setPixmap( QtGui.QPixmap( filename ) )
|
|
1538
|
+
|
|
1539
|
+
def r_details_loaded(self, result):
|
|
1540
|
+
if result['success']:
|
|
1541
|
+
details = result['details']
|
|
1542
|
+
|
|
1543
|
+
info_strings = []
|
|
1544
|
+
description_strings = []
|
|
1545
|
+
description_keys = {'Synopsis', 'English', 'Japanese', 'Synonyms'} # This might come down to personal preference
|
|
1546
|
+
list_keys = {'Genres'} # Anilist gives genres as a list, need a special case to fix formatting
|
|
1547
|
+
|
|
1548
|
+
for line in details['extra']:
|
|
1549
|
+
if line[0] and line[1]:
|
|
1550
|
+
if line[0] in description_keys:
|
|
1551
|
+
description_strings.append( "<h3>%s</h3><p>%s</p>" % (line[0], line[1]) )
|
|
1552
|
+
else:
|
|
1553
|
+
if line[0] in list_keys:
|
|
1554
|
+
description_strings.append( "<h3>%s</h3><p>%s</p>" % (line[0], ', '.join(line[1])) )
|
|
1555
|
+
elif len("%s" % line[1]) >= 17: # Avoid short tidbits taking up too much vertical space
|
|
1556
|
+
info_strings.append( "<h3>%s</h3><p>%s</p>" % (line[0], line[1]) )
|
|
1557
|
+
else:
|
|
1558
|
+
info_strings.append( "<p><b>%s:</b> %s</p>" % (line[0], line[1]) )
|
|
1559
|
+
|
|
1560
|
+
info_string = ''.join(info_strings)
|
|
1561
|
+
self.show_info.setText( info_string )
|
|
1562
|
+
description_string = ''.join(description_strings)
|
|
1563
|
+
self.show_description.setText( description_string )
|
|
1564
|
+
else:
|
|
1565
|
+
self.show_info.setText( 'There was an error while getting details.' )
|
|
1566
|
+
|
|
1567
|
+
class AddDialog(QDialog):
|
|
1568
|
+
worker = None
|
|
1569
|
+
selected_show = None
|
|
1570
|
+
|
|
1571
|
+
def __init__(self, parent, worker, current_status):
|
|
1572
|
+
QMainWindow.__init__(self, parent)
|
|
1573
|
+
self.setMinimumSize(700, 500)
|
|
1574
|
+
self.setWindowTitle('Search/Add from Remote')
|
|
1575
|
+
self.worker = worker
|
|
1576
|
+
self.current_status = current_status
|
|
1577
|
+
|
|
1578
|
+
layout = QGridLayout()
|
|
1579
|
+
|
|
1580
|
+
# Create top layout
|
|
1581
|
+
top_layout = QHBoxLayout()
|
|
1582
|
+
search_lbl = QLabel('Search terms:')
|
|
1583
|
+
self.search_txt = QLineEdit(self)
|
|
1584
|
+
self.search_txt.returnPressed.connect(self.s_search)
|
|
1585
|
+
self.search_txt.setFocus()
|
|
1586
|
+
self.search_btn = QPushButton('Search')
|
|
1587
|
+
self.search_btn.clicked.connect(self.s_search)
|
|
1588
|
+
top_layout.addWidget(search_lbl)
|
|
1589
|
+
top_layout.addWidget(self.search_txt)
|
|
1590
|
+
top_layout.addWidget(self.search_btn)
|
|
1591
|
+
|
|
1592
|
+
# Create table
|
|
1593
|
+
columns = ['Title', 'Type', 'Total']
|
|
1594
|
+
self.table = QTableWidget()
|
|
1595
|
+
self.table.setColumnCount(len(columns))
|
|
1596
|
+
self.table.setHorizontalHeaderLabels(columns)
|
|
1597
|
+
self.table.horizontalHeader().setHighlightSections(False)
|
|
1598
|
+
self.table.setSelectionMode(QAbstractItemView.SingleSelection)
|
|
1599
|
+
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
|
1600
|
+
self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
|
1601
|
+
self.table.verticalHeader().hide()
|
|
1602
|
+
self.table.setGridStyle(QtCore.Qt.NoPen)
|
|
1603
|
+
if pyqt_version is 5:
|
|
1604
|
+
self.table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
|
1605
|
+
else:
|
|
1606
|
+
self.table.horizontalHeader().setResizeMode(0, QHeaderView.Stretch)
|
|
1607
|
+
self.table.currentItemChanged.connect(self.s_show_selected)
|
|
1608
|
+
#self.table.doubleClicked.connect(self.s_show_details)
|
|
1609
|
+
|
|
1610
|
+
bottom_buttons = QDialogButtonBox(self)
|
|
1611
|
+
bottom_buttons.addButton("Cancel", QDialogButtonBox.RejectRole)
|
|
1612
|
+
self.select_btn = bottom_buttons.addButton("Add", QDialogButtonBox.AcceptRole)
|
|
1613
|
+
bottom_buttons.accepted.connect(self.s_add)
|
|
1614
|
+
bottom_buttons.rejected.connect(self.close)
|
|
1615
|
+
|
|
1616
|
+
# Info box
|
|
1617
|
+
self.details = DetailsWidget(self, worker)
|
|
1618
|
+
|
|
1619
|
+
# Finish layout
|
|
1620
|
+
layout.addLayout(top_layout, 0, 0, 1, 2)
|
|
1621
|
+
layout.addWidget(self.table, 1, 0, 1, 1)
|
|
1622
|
+
layout.addWidget(self.details, 1, 1, 1, 1)
|
|
1623
|
+
layout.addWidget(bottom_buttons, 2, 0, 1, 2)
|
|
1624
|
+
self.setLayout(layout)
|
|
1625
|
+
|
|
1626
|
+
def worker_call(self, function, ret_function, *args, **kwargs):
|
|
1627
|
+
# Run worker in a thread
|
|
1628
|
+
self.worker.set_function(function, ret_function, *args, **kwargs)
|
|
1629
|
+
self.worker.start()
|
|
1630
|
+
|
|
1631
|
+
def _enable_widgets(self, enable):
|
|
1632
|
+
self.search_btn.setEnabled(enable)
|
|
1633
|
+
self.table.setEnabled(enable)
|
|
1634
|
+
|
|
1635
|
+
# Slots
|
|
1636
|
+
def s_search(self):
|
|
1637
|
+
self.search_btn.setEnabled(False)
|
|
1638
|
+
self.select_btn.setEnabled(False)
|
|
1639
|
+
self.table.clearSelection()
|
|
1640
|
+
self.table.setEnabled(False)
|
|
1641
|
+
|
|
1642
|
+
self.worker_call('search', self.r_searched, self.search_txt.text())
|
|
1643
|
+
|
|
1644
|
+
def s_show_selected(self, new, old=None):
|
|
1645
|
+
if not new:
|
|
1646
|
+
return
|
|
1647
|
+
|
|
1648
|
+
index = new.row()
|
|
1649
|
+
self.selected_show = self.results[index]
|
|
1650
|
+
self.details.load(self.selected_show)
|
|
1651
|
+
self.select_btn.setEnabled(True)
|
|
1652
|
+
|
|
1653
|
+
def s_add(self):
|
|
1654
|
+
if self.selected_show:
|
|
1655
|
+
self.worker_call('add_show', self.r_added, self.selected_show, self.current_status)
|
|
1656
|
+
|
|
1657
|
+
# Worker responses
|
|
1658
|
+
def r_searched(self, result):
|
|
1659
|
+
if result['success']:
|
|
1660
|
+
self.search_btn.setEnabled(True)
|
|
1661
|
+
self.table.setEnabled(True)
|
|
1662
|
+
|
|
1663
|
+
self.results = result['results']
|
|
1664
|
+
|
|
1665
|
+
self.table.setRowCount(len(self.results))
|
|
1666
|
+
i = 0
|
|
1667
|
+
for res in self.results:
|
|
1668
|
+
self.table.setRowHeight(i, QtGui.QFontMetrics(self.table.font()).height() + 2);
|
|
1669
|
+
self.table.setItem(i, 0, ShowItem(res['title']))
|
|
1670
|
+
self.table.setItem(i, 1, ShowItem(res['type']))
|
|
1671
|
+
self.table.setItem(i, 2, ShowItem(str(res['total'])))
|
|
1672
|
+
|
|
1673
|
+
i += 1
|
|
1674
|
+
if self.table.currentRow() is 0: # Row number hasn't changed but the data probably has!
|
|
1675
|
+
self.s_show_selected(self.table.item(0,0))
|
|
1676
|
+
self.table.setCurrentItem(self.table.item(0,0))
|
|
1677
|
+
else:
|
|
1678
|
+
self.table.setRowCount(0)
|
|
1679
|
+
|
|
1680
|
+
self.search_btn.setEnabled(True)
|
|
1681
|
+
self.table.setEnabled(True)
|
|
1682
|
+
|
|
1683
|
+
def r_added(self, result):
|
|
1684
|
+
if result['success']:
|
|
1685
|
+
pass
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
class SettingsDialog(QDialog):
|
|
1689
|
+
worker = None
|
|
1690
|
+
config = None
|
|
1691
|
+
configfile = None
|
|
1692
|
+
|
|
1693
|
+
saved = QtCore.pyqtSignal()
|
|
1694
|
+
|
|
1695
|
+
def __init__(self, parent, worker, config, configfile):
|
|
1696
|
+
QDialog.__init__(self, parent)
|
|
1697
|
+
|
|
1698
|
+
self.worker = worker
|
|
1699
|
+
self.config = config
|
|
1700
|
+
self.configfile = configfile
|
|
1701
|
+
self.setStyleSheet("QGroupBox { font-weight: bold; } ")
|
|
1702
|
+
self.setWindowTitle('Settings')
|
|
1703
|
+
layout = QGridLayout()
|
|
1704
|
+
|
|
1705
|
+
# Categories
|
|
1706
|
+
self.category_list = QListWidget()
|
|
1707
|
+
category_media = QListWidgetItem(getIcon('media-playback-start'), 'Media', self.category_list)
|
|
1708
|
+
category_sync = QListWidgetItem(getIcon('view-refresh'), 'Sync', self.category_list)
|
|
1709
|
+
category_ui = QListWidgetItem(getIcon('window-new'), 'User Interface', self.category_list)
|
|
1710
|
+
category_theme = QListWidgetItem(getIcon('applications-graphics'), 'Theme', self.category_list)
|
|
1711
|
+
self.category_list.setSelectionMode(QAbstractItemView.SingleSelection)
|
|
1712
|
+
self.category_list.setCurrentRow(0)
|
|
1713
|
+
self.category_list.setMaximumWidth(self.category_list.sizeHintForColumn(0) + 15)
|
|
1714
|
+
self.category_list.setFocus()
|
|
1715
|
+
self.category_list.currentItemChanged.connect(self.s_switch_page)
|
|
1716
|
+
|
|
1717
|
+
# Media tab
|
|
1718
|
+
page_media = QWidget()
|
|
1719
|
+
page_media_layout = QVBoxLayout()
|
|
1720
|
+
page_media_layout.setAlignment(QtCore.Qt.AlignTop)
|
|
1721
|
+
|
|
1722
|
+
# Group: Media settings
|
|
1723
|
+
g_media = QGroupBox('Media settings')
|
|
1724
|
+
g_media.setFlat(True)
|
|
1725
|
+
g_media_layout = QFormLayout()
|
|
1726
|
+
self.tracker_enabled = QCheckBox()
|
|
1727
|
+
self.tracker_enabled.toggled.connect(self.tracker_type_change)
|
|
1728
|
+
self.tracker_type_local = QRadioButton('Local')
|
|
1729
|
+
self.tracker_type_local.toggled.connect(self.tracker_type_change)
|
|
1730
|
+
self.tracker_type_plex = QRadioButton('Plex media server')
|
|
1731
|
+
self.tracker_type_plex.toggled.connect(self.tracker_type_change)
|
|
1732
|
+
self.plex_host = QLineEdit()
|
|
1733
|
+
self.plex_port = QLineEdit()
|
|
1734
|
+
self.tracker_interval = QSpinBox()
|
|
1735
|
+
self.tracker_interval.setRange(5, 1000)
|
|
1736
|
+
self.tracker_interval.setMaximumWidth(60)
|
|
1737
|
+
self.tracker_process = QLineEdit()
|
|
1738
|
+
self.tracker_update_wait = QSpinBox()
|
|
1739
|
+
self.tracker_update_wait.setRange(0, 1000)
|
|
1740
|
+
self.tracker_update_wait.setMaximumWidth(60)
|
|
1741
|
+
self.tracker_update_close = QCheckBox()
|
|
1742
|
+
self.tracker_update_prompt = QCheckBox()
|
|
1743
|
+
|
|
1744
|
+
g_media_layout.addRow( 'Enable tracker', self.tracker_enabled )
|
|
1745
|
+
g_media_layout.addRow( self.tracker_type_local )
|
|
1746
|
+
g_media_layout.addRow( self.tracker_type_plex )
|
|
1747
|
+
g_media_layout.addRow( 'Tracker interval (seconds)', self.tracker_interval )
|
|
1748
|
+
g_media_layout.addRow( 'Process name (regex)', self.tracker_process )
|
|
1749
|
+
g_media_layout.addRow( 'Plex host', self.plex_host )
|
|
1750
|
+
g_media_layout.addRow( 'Plex port', self.plex_port )
|
|
1751
|
+
g_media_layout.addRow( 'Wait before updating (seconds)', self.tracker_update_wait )
|
|
1752
|
+
g_media_layout.addRow( 'Wait until the player is closed', self.tracker_update_close )
|
|
1753
|
+
g_media_layout.addRow( 'Ask before updating', self.tracker_update_prompt )
|
|
1754
|
+
|
|
1755
|
+
g_media.setLayout(g_media_layout)
|
|
1756
|
+
|
|
1757
|
+
# Group: Play Next
|
|
1758
|
+
g_playnext = QGroupBox('Play Next')
|
|
1759
|
+
g_playnext.setFlat(True)
|
|
1760
|
+
self.player = QLineEdit()
|
|
1761
|
+
self.player_browse = QPushButton('Browse...')
|
|
1762
|
+
self.player_browse.clicked.connect(self.s_player_browse)
|
|
1763
|
+
self.searchdir = QLineEdit()
|
|
1764
|
+
self.searchdir_browse = QPushButton('Browse...')
|
|
1765
|
+
self.searchdir_browse.clicked.connect(self.s_searchdir_browse)
|
|
1766
|
+
|
|
1767
|
+
g_playnext_layout = QGridLayout()
|
|
1768
|
+
g_playnext_layout.addWidget( QLabel('Player'), 0, 0, 1, 1)
|
|
1769
|
+
g_playnext_layout.addWidget( self.player, 0, 1, 1, 1)
|
|
1770
|
+
g_playnext_layout.addWidget( self.player_browse, 0, 2, 1, 1)
|
|
1771
|
+
g_playnext_layout.addWidget( QLabel('Media directory'), 1, 0, 1, 1)
|
|
1772
|
+
g_playnext_layout.addWidget( self.searchdir, 1, 1, 1, 1)
|
|
1773
|
+
g_playnext_layout.addWidget( self.searchdir_browse, 1, 2, 1, 1)
|
|
1774
|
+
|
|
1775
|
+
g_playnext.setLayout(g_playnext_layout)
|
|
1776
|
+
|
|
1777
|
+
# Media form
|
|
1778
|
+
page_media_layout.addWidget(g_media)
|
|
1779
|
+
page_media_layout.addWidget(g_playnext)
|
|
1780
|
+
page_media.setLayout(page_media_layout)
|
|
1781
|
+
|
|
1782
|
+
# Sync tab
|
|
1783
|
+
page_sync = QWidget()
|
|
1784
|
+
page_sync_layout = QVBoxLayout()
|
|
1785
|
+
page_sync_layout.setAlignment(QtCore.Qt.AlignTop)
|
|
1786
|
+
|
|
1787
|
+
# Group: Autoretrieve
|
|
1788
|
+
g_autoretrieve = QGroupBox('Autoretrieve')
|
|
1789
|
+
g_autoretrieve.setFlat(True)
|
|
1790
|
+
self.autoretrieve_off = QRadioButton('Disabled')
|
|
1791
|
+
self.autoretrieve_always = QRadioButton('Always at start')
|
|
1792
|
+
self.autoretrieve_days = QRadioButton('After n days')
|
|
1793
|
+
self.autoretrieve_days.toggled.connect(self.s_autoretrieve_days)
|
|
1794
|
+
self.autoretrieve_days_n = QSpinBox()
|
|
1795
|
+
self.autoretrieve_days_n.setRange(1, 100)
|
|
1796
|
+
g_autoretrieve_layout = QGridLayout()
|
|
1797
|
+
g_autoretrieve_layout.setColumnStretch(0, 1)
|
|
1798
|
+
g_autoretrieve_layout.addWidget(self.autoretrieve_off, 0, 0, 1, 1)
|
|
1799
|
+
g_autoretrieve_layout.addWidget(self.autoretrieve_always, 1, 0, 1, 1)
|
|
1800
|
+
g_autoretrieve_layout.addWidget(self.autoretrieve_days, 2, 0, 1, 1)
|
|
1801
|
+
g_autoretrieve_layout.addWidget(self.autoretrieve_days_n, 2, 1, 1, 1)
|
|
1802
|
+
g_autoretrieve.setLayout(g_autoretrieve_layout)
|
|
1803
|
+
|
|
1804
|
+
# Group: Autosend
|
|
1805
|
+
g_autosend = QGroupBox('Autosend')
|
|
1806
|
+
g_autosend.setFlat(True)
|
|
1807
|
+
self.autosend_off = QRadioButton('Disabled')
|
|
1808
|
+
self.autosend_always = QRadioButton('Immediately after every change')
|
|
1809
|
+
self.autosend_hours = QRadioButton('After n hours')
|
|
1810
|
+
self.autosend_hours.toggled.connect(self.s_autosend_hours)
|
|
1811
|
+
self.autosend_hours_n = QSpinBox()
|
|
1812
|
+
self.autosend_hours_n.setRange(1, 1000)
|
|
1813
|
+
self.autosend_size = QRadioButton('After the queue reaches n items')
|
|
1814
|
+
self.autosend_size.toggled.connect(self.s_autosend_size)
|
|
1815
|
+
self.autosend_size_n = QSpinBox()
|
|
1816
|
+
self.autosend_size_n.setRange(2, 20)
|
|
1817
|
+
self.autosend_at_exit = QCheckBox('At exit')
|
|
1818
|
+
g_autosend_layout = QGridLayout()
|
|
1819
|
+
g_autosend_layout.setColumnStretch(0, 1)
|
|
1820
|
+
g_autosend_layout.addWidget(self.autosend_off, 0, 0, 1, 1)
|
|
1821
|
+
g_autosend_layout.addWidget(self.autosend_always, 1, 0, 1, 1)
|
|
1822
|
+
g_autosend_layout.addWidget(self.autosend_hours, 2, 0, 1, 1)
|
|
1823
|
+
g_autosend_layout.addWidget(self.autosend_hours_n, 2, 1, 1, 1)
|
|
1824
|
+
g_autosend_layout.addWidget(self.autosend_size, 3, 0, 1, 1)
|
|
1825
|
+
g_autosend_layout.addWidget(self.autosend_size_n, 3, 1, 1, 1)
|
|
1826
|
+
g_autosend_layout.addWidget(self.autosend_at_exit, 4, 0, 1, 1)
|
|
1827
|
+
g_autosend.setLayout(g_autosend_layout)
|
|
1828
|
+
|
|
1829
|
+
# Group: Extra
|
|
1830
|
+
g_extra = QGroupBox('Additional options')
|
|
1831
|
+
g_extra.setFlat(True)
|
|
1832
|
+
self.auto_status_change = QCheckBox('Change status automatically')
|
|
1833
|
+
self.auto_status_change.toggled.connect(self.s_auto_status_change)
|
|
1834
|
+
self.auto_status_change_if_scored = QCheckBox('Change status automatically only if scored')
|
|
1835
|
+
self.auto_date_change = QCheckBox('Change start and finish dates automatically')
|
|
1836
|
+
g_extra_layout = QVBoxLayout()
|
|
1837
|
+
g_extra_layout.addWidget(self.auto_status_change)
|
|
1838
|
+
g_extra_layout.addWidget(self.auto_status_change_if_scored)
|
|
1839
|
+
g_extra_layout.addWidget(self.auto_date_change)
|
|
1840
|
+
g_extra.setLayout(g_extra_layout)
|
|
1841
|
+
|
|
1842
|
+
# Sync layout
|
|
1843
|
+
page_sync_layout.addWidget( g_autoretrieve )
|
|
1844
|
+
page_sync_layout.addWidget( g_autosend )
|
|
1845
|
+
page_sync_layout.addWidget( g_extra )
|
|
1846
|
+
page_sync.setLayout(page_sync_layout)
|
|
1847
|
+
|
|
1848
|
+
# UI tab
|
|
1849
|
+
page_ui = QWidget()
|
|
1850
|
+
page_ui_layout = QFormLayout()
|
|
1851
|
+
page_ui_layout.setAlignment(QtCore.Qt.AlignTop)
|
|
1852
|
+
|
|
1853
|
+
# Group: Icon
|
|
1854
|
+
g_icon = QGroupBox('Notification Icon')
|
|
1855
|
+
g_icon.setFlat(True)
|
|
1856
|
+
self.tray_icon = QCheckBox('Show tray icon')
|
|
1857
|
+
self.tray_icon.toggled.connect(self.s_tray_icon)
|
|
1858
|
+
self.close_to_tray = QCheckBox('Close to tray')
|
|
1859
|
+
self.start_in_tray = QCheckBox('Start minimized to tray')
|
|
1860
|
+
self.tray_api_icon = QCheckBox('Use API icon as tray icon')
|
|
1861
|
+
self.notifications = QCheckBox('Show notification when tracker detects new media')
|
|
1862
|
+
g_icon_layout = QVBoxLayout()
|
|
1863
|
+
g_icon_layout.addWidget(self.tray_icon)
|
|
1864
|
+
g_icon_layout.addWidget(self.close_to_tray)
|
|
1865
|
+
g_icon_layout.addWidget(self.start_in_tray)
|
|
1866
|
+
g_icon_layout.addWidget(self.tray_api_icon)
|
|
1867
|
+
g_icon_layout.addWidget(self.notifications)
|
|
1868
|
+
g_icon.setLayout(g_icon_layout)
|
|
1869
|
+
|
|
1870
|
+
# Group: Window
|
|
1871
|
+
g_window = QGroupBox('Window')
|
|
1872
|
+
g_window.setFlat(True)
|
|
1873
|
+
self.remember_geometry = QCheckBox('Remember window size and position')
|
|
1874
|
+
self.remember_columns = QCheckBox('Remember column layouts and widths')
|
|
1875
|
+
self.columns_per_api = QCheckBox('Use different visible columns per API')
|
|
1876
|
+
g_window_layout = QVBoxLayout()
|
|
1877
|
+
g_window_layout.addWidget(self.remember_geometry)
|
|
1878
|
+
g_window_layout.addWidget(self.remember_columns)
|
|
1879
|
+
g_window_layout.addWidget(self.columns_per_api)
|
|
1880
|
+
g_window.setLayout(g_window_layout)
|
|
1881
|
+
|
|
1882
|
+
# Group: Lists
|
|
1883
|
+
g_lists = QGroupBox('Lists')
|
|
1884
|
+
g_lists.setFlat(True)
|
|
1885
|
+
self.filter_bar_position = QComboBox()
|
|
1886
|
+
filter_bar_positions = [(FilterBar.PositionHidden, 'Hidden'),
|
|
1887
|
+
(FilterBar.PositionAboveLists, 'Above lists'),
|
|
1888
|
+
(FilterBar.PositionBelowLists, 'Below lists')]
|
|
1889
|
+
for (n,label) in filter_bar_positions:
|
|
1890
|
+
self.filter_bar_position.addItem(label, n)
|
|
1891
|
+
self.filter_global = QCheckBox('Update filter for all lists (slow)')
|
|
1892
|
+
g_lists_layout = QFormLayout()
|
|
1893
|
+
g_lists_layout.addRow('Filter bar position:',self.filter_bar_position)
|
|
1894
|
+
g_lists_layout.addRow(self.filter_global)
|
|
1895
|
+
g_lists.setLayout(g_lists_layout)
|
|
1896
|
+
|
|
1897
|
+
# UI layout
|
|
1898
|
+
page_ui_layout.addWidget(g_icon)
|
|
1899
|
+
page_ui_layout.addWidget(g_window)
|
|
1900
|
+
page_ui_layout.addWidget(g_lists)
|
|
1901
|
+
page_ui.setLayout(page_ui_layout)
|
|
1902
|
+
|
|
1903
|
+
# Theming tab
|
|
1904
|
+
page_theme = QWidget()
|
|
1905
|
+
page_theme_layout = QFormLayout()
|
|
1906
|
+
page_theme_layout.setAlignment(QtCore.Qt.AlignTop)
|
|
1907
|
+
|
|
1908
|
+
# Group: Episode Bar
|
|
1909
|
+
g_ep_bar = QGroupBox('Episode Bar')
|
|
1910
|
+
g_ep_bar.setFlat(True)
|
|
1911
|
+
self.ep_bar_style = QComboBox()
|
|
1912
|
+
ep_bar_styles = [(EpisodeBar.BarStyleBasic, 'Basic'),
|
|
1913
|
+
(EpisodeBar.BarStyle04, 'Trackma v0.4 Dual'),
|
|
1914
|
+
(EpisodeBar.BarStyleHybrid, 'Hybrid Dual')]
|
|
1915
|
+
for (n,label) in ep_bar_styles:
|
|
1916
|
+
self.ep_bar_style.addItem(label, n)
|
|
1917
|
+
self.ep_bar_style.currentIndexChanged.connect(self.s_ep_bar_style)
|
|
1918
|
+
self.ep_bar_text = QCheckBox('Show text label')
|
|
1919
|
+
g_ep_bar_layout = QFormLayout()
|
|
1920
|
+
g_ep_bar_layout.addRow('Style:', self.ep_bar_style)
|
|
1921
|
+
g_ep_bar_layout.addRow(self.ep_bar_text)
|
|
1922
|
+
g_ep_bar.setLayout(g_ep_bar_layout)
|
|
1923
|
+
|
|
1924
|
+
# Group: Colour scheme
|
|
1925
|
+
g_scheme = QGroupBox('Color Scheme')
|
|
1926
|
+
g_scheme.setFlat(True)
|
|
1927
|
+
col_tabs = [('rows', '&Row highlights'),
|
|
1928
|
+
('progress', '&Progress widget')]
|
|
1929
|
+
self.colors = {}
|
|
1930
|
+
self.colors['rows'] = [('is_playing', 'Playing'),
|
|
1931
|
+
('is_queued', 'Queued'),
|
|
1932
|
+
('new_episode', 'New Episode'),
|
|
1933
|
+
('is_airing', 'Airing'),
|
|
1934
|
+
('not_aired', 'Unaired')]
|
|
1935
|
+
self.colors['progress'] = [('progress_bg', 'Background'),
|
|
1936
|
+
('progress_fg', 'Watched bar'),
|
|
1937
|
+
('progress_sub_bg', 'Aired episodes'),
|
|
1938
|
+
('progress_sub_fg', 'Stored episodes'),
|
|
1939
|
+
('progress_complete', 'Complete')]
|
|
1940
|
+
self.color_buttons = []
|
|
1941
|
+
self.syscolor_buttons = []
|
|
1942
|
+
g_scheme_layout = QGridLayout()
|
|
1943
|
+
tw_scheme = QTabWidget()
|
|
1944
|
+
for (key,tab_title) in col_tabs:
|
|
1945
|
+
page = QFrame()
|
|
1946
|
+
page_layout = QGridLayout()
|
|
1947
|
+
col = 0
|
|
1948
|
+
for (key,label) in self.colors[key]: # Generate widgets from the keys and values
|
|
1949
|
+
self.color_buttons.append( QPushButton() )
|
|
1950
|
+
# self.color_buttons[-1].setStyleSheet('background-color: ' + getColor(self.config['colors'][key]).name())
|
|
1951
|
+
self.color_buttons[-1].setFocusPolicy(QtCore.Qt.NoFocus)
|
|
1952
|
+
self.color_buttons[-1].clicked.connect( self.s_color_picker(key,False) )
|
|
1953
|
+
self.syscolor_buttons.append( QPushButton('System Colors') )
|
|
1954
|
+
self.syscolor_buttons[-1].clicked.connect( self.s_color_picker(key,True) )
|
|
1955
|
+
page_layout.addWidget( QLabel(label), col, 0, 1, 1 )
|
|
1956
|
+
page_layout.addWidget( self.color_buttons[-1], col, 1, 1, 1 )
|
|
1957
|
+
page_layout.addWidget( self.syscolor_buttons[-1], col, 2, 1, 1 )
|
|
1958
|
+
col+=1
|
|
1959
|
+
page.setLayout(page_layout)
|
|
1960
|
+
tw_scheme.addTab(page,tab_title)
|
|
1961
|
+
g_scheme_layout.addWidget(tw_scheme)
|
|
1962
|
+
g_scheme.setLayout(g_scheme_layout)
|
|
1963
|
+
|
|
1964
|
+
# UI layout
|
|
1965
|
+
page_theme_layout.addWidget(g_ep_bar)
|
|
1966
|
+
page_theme_layout.addWidget(g_scheme)
|
|
1967
|
+
page_theme.setLayout(page_theme_layout)
|
|
1968
|
+
|
|
1969
|
+
# Content
|
|
1970
|
+
self.contents = QStackedWidget()
|
|
1971
|
+
self.contents.addWidget(page_media)
|
|
1972
|
+
self.contents.addWidget(page_sync)
|
|
1973
|
+
self.contents.addWidget(page_ui)
|
|
1974
|
+
self.contents.addWidget(page_theme)
|
|
1975
|
+
if pyqt_version is not 5:
|
|
1976
|
+
self.contents.layout().setMargin(0)
|
|
1977
|
+
|
|
1978
|
+
# Bottom buttons
|
|
1979
|
+
bottombox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Apply|QDialogButtonBox.Cancel)
|
|
1980
|
+
bottombox.accepted.connect(self.s_save)
|
|
1981
|
+
bottombox.button(QDialogButtonBox.Apply).clicked.connect(self._save)
|
|
1982
|
+
bottombox.rejected.connect(self.reject)
|
|
1983
|
+
|
|
1984
|
+
# Main layout finish
|
|
1985
|
+
layout.addWidget(self.category_list, 0, 0, 1, 1)
|
|
1986
|
+
layout.addWidget(self.contents, 0, 1, 1, 1)
|
|
1987
|
+
layout.addWidget(bottombox, 1, 0, 1, 2)
|
|
1988
|
+
layout.setColumnStretch(1, 1)
|
|
1989
|
+
|
|
1990
|
+
self._load()
|
|
1991
|
+
self.update_colors()
|
|
1992
|
+
|
|
1993
|
+
self.setLayout(layout)
|
|
1994
|
+
|
|
1995
|
+
def _load(self):
|
|
1996
|
+
engine = self.worker.engine
|
|
1997
|
+
tracker_type = engine.get_config('tracker_type')
|
|
1998
|
+
autoretrieve = engine.get_config('autoretrieve')
|
|
1999
|
+
autosend = engine.get_config('autosend')
|
|
2000
|
+
|
|
2001
|
+
self.tracker_enabled.setChecked(engine.get_config('tracker_enabled'))
|
|
2002
|
+
self.tracker_interval.setValue(engine.get_config('tracker_interval'))
|
|
2003
|
+
self.tracker_process.setText(engine.get_config('tracker_process'))
|
|
2004
|
+
self.tracker_update_wait.setValue(engine.get_config('tracker_update_wait_s'))
|
|
2005
|
+
self.tracker_update_close.setChecked(engine.get_config('tracker_update_close'))
|
|
2006
|
+
self.tracker_update_prompt.setChecked(engine.get_config('tracker_update_prompt'))
|
|
2007
|
+
|
|
2008
|
+
self.player.setText(engine.get_config('player'))
|
|
2009
|
+
self.searchdir.setText(engine.get_config('searchdir'))
|
|
2010
|
+
self.plex_host.setText(engine.get_config('plex_host'))
|
|
2011
|
+
self.plex_port.setText(engine.get_config('plex_port'))
|
|
2012
|
+
|
|
2013
|
+
if tracker_type == 'local':
|
|
2014
|
+
self.tracker_type_local.setChecked(True)
|
|
2015
|
+
self.plex_host.setEnabled(False)
|
|
2016
|
+
self.plex_port.setEnabled(False)
|
|
2017
|
+
elif tracker_type == 'plex':
|
|
2018
|
+
self.tracker_type_plex.setChecked(True)
|
|
2019
|
+
self.tracker_process.setEnabled(False)
|
|
2020
|
+
|
|
2021
|
+
if autoretrieve == 'always':
|
|
2022
|
+
self.autoretrieve_always.setChecked(True)
|
|
2023
|
+
elif autoretrieve == 'days':
|
|
2024
|
+
self.autoretrieve_days.setChecked(True)
|
|
2025
|
+
else:
|
|
2026
|
+
self.autoretrieve_off.setChecked(True)
|
|
2027
|
+
|
|
2028
|
+
self.autoretrieve_days_n.setValue(engine.get_config('autoretrieve_days'))
|
|
2029
|
+
|
|
2030
|
+
if autosend == 'always':
|
|
2031
|
+
self.autosend_always.setChecked(True)
|
|
2032
|
+
elif autosend == 'hours':
|
|
2033
|
+
self.autosend_hours.setChecked(True)
|
|
2034
|
+
elif autosend == 'size':
|
|
2035
|
+
self.autosend_size.setChecked(True)
|
|
2036
|
+
else:
|
|
2037
|
+
self.autosend_off.setChecked(True)
|
|
2038
|
+
|
|
2039
|
+
self.autosend_hours_n.setValue(engine.get_config('autosend_hours'))
|
|
2040
|
+
self.autosend_size_n.setValue(engine.get_config('autosend_size'))
|
|
2041
|
+
|
|
2042
|
+
self.autosend_at_exit.setChecked(engine.get_config('autosend_at_exit'))
|
|
2043
|
+
self.auto_status_change.setChecked(engine.get_config('auto_status_change'))
|
|
2044
|
+
self.auto_status_change_if_scored.setChecked(engine.get_config('auto_status_change_if_scored'))
|
|
2045
|
+
self.auto_date_change.setChecked(engine.get_config('auto_date_change'))
|
|
2046
|
+
|
|
2047
|
+
self.tray_icon.setChecked(self.config['show_tray'])
|
|
2048
|
+
self.close_to_tray.setChecked(self.config['close_to_tray'])
|
|
2049
|
+
self.start_in_tray.setChecked(self.config['start_in_tray'])
|
|
2050
|
+
self.tray_api_icon.setChecked(self.config['tray_api_icon'])
|
|
2051
|
+
self.notifications.setChecked(self.config['notifications'])
|
|
2052
|
+
self.remember_geometry.setChecked(self.config['remember_geometry'])
|
|
2053
|
+
self.remember_columns.setChecked(self.config['remember_columns'])
|
|
2054
|
+
self.columns_per_api.setChecked(self.config['columns_per_api'])
|
|
2055
|
+
self.filter_bar_position.setCurrentIndex(self.filter_bar_position.findData(self.config['filter_bar_position']))
|
|
2056
|
+
self.filter_global.setChecked(self.config['filter_global'])
|
|
2057
|
+
|
|
2058
|
+
self.ep_bar_style.setCurrentIndex(self.ep_bar_style.findData(self.config['episodebar_style']))
|
|
2059
|
+
self.ep_bar_text.setChecked(self.config['episodebar_text'])
|
|
2060
|
+
|
|
2061
|
+
self.autoretrieve_days_n.setEnabled(self.autoretrieve_days.isChecked())
|
|
2062
|
+
self.autosend_hours_n.setEnabled(self.autosend_hours.isChecked())
|
|
2063
|
+
self.autosend_size_n.setEnabled(self.autosend_size.isChecked())
|
|
2064
|
+
self.close_to_tray.setEnabled(self.tray_icon.isChecked())
|
|
2065
|
+
self.start_in_tray.setEnabled(self.tray_icon.isChecked())
|
|
2066
|
+
self.notifications.setEnabled(self.tray_icon.isChecked())
|
|
2067
|
+
|
|
2068
|
+
self.color_values = self.config['colors'].copy()
|
|
2069
|
+
|
|
2070
|
+
def _save(self):
|
|
2071
|
+
engine = self.worker.engine
|
|
2072
|
+
|
|
2073
|
+
engine.set_config('tracker_enabled', self.tracker_enabled.isChecked())
|
|
2074
|
+
engine.set_config('tracker_interval', self.tracker_interval.value())
|
|
2075
|
+
engine.set_config('tracker_process', str(self.tracker_process.text()))
|
|
2076
|
+
engine.set_config('tracker_update_wait_s', self.tracker_update_wait.value())
|
|
2077
|
+
engine.set_config('tracker_update_close', self.tracker_update_close.isChecked())
|
|
2078
|
+
engine.set_config('tracker_update_prompt', self.tracker_update_prompt.isChecked())
|
|
2079
|
+
|
|
2080
|
+
engine.set_config('player', self.player.text())
|
|
2081
|
+
engine.set_config('searchdir', self.searchdir.text())
|
|
2082
|
+
engine.set_config('plex_host', self.plex_host.text())
|
|
2083
|
+
engine.set_config('plex_port', self.plex_port.text())
|
|
2084
|
+
|
|
2085
|
+
if self.tracker_type_local.isChecked():
|
|
2086
|
+
engine.set_config('tracker_type', 'local')
|
|
2087
|
+
elif self.tracker_type_plex.isChecked():
|
|
2088
|
+
engine.set_config('tracker_type', 'plex')
|
|
2089
|
+
|
|
2090
|
+
if self.autoretrieve_always.isChecked():
|
|
2091
|
+
engine.set_config('autoretrieve', 'always')
|
|
2092
|
+
elif self.autoretrieve_days.isChecked():
|
|
2093
|
+
engine.set_config('autoretrieve', 'days')
|
|
2094
|
+
else:
|
|
2095
|
+
engine.set_config('autoretrieve', 'off')
|
|
2096
|
+
|
|
2097
|
+
engine.set_config('autoretrieve_days', self.autoretrieve_days_n.value())
|
|
2098
|
+
|
|
2099
|
+
if self.autosend_always.isChecked():
|
|
2100
|
+
engine.set_config('autosend', 'always')
|
|
2101
|
+
elif self.autosend_hours.isChecked():
|
|
2102
|
+
engine.set_config('autosend', 'hours')
|
|
2103
|
+
elif self.autosend_size.isChecked():
|
|
2104
|
+
engine.set_config('autosend', 'size')
|
|
2105
|
+
else:
|
|
2106
|
+
engine.set_config('autosend', 'off')
|
|
2107
|
+
|
|
2108
|
+
engine.set_config('autosend_hours', self.autosend_hours_n.value())
|
|
2109
|
+
engine.set_config('autosend_size', self.autosend_size_n.value())
|
|
2110
|
+
|
|
2111
|
+
engine.set_config('autosend_at_exit', self.autosend_at_exit.isChecked())
|
|
2112
|
+
engine.set_config('auto_status_change', self.auto_status_change.isChecked())
|
|
2113
|
+
engine.set_config('auto_status_change_if_scored', self.auto_status_change_if_scored.isChecked())
|
|
2114
|
+
engine.set_config('auto_date_change', self.auto_date_change.isChecked())
|
|
2115
|
+
|
|
2116
|
+
engine.save_config()
|
|
2117
|
+
|
|
2118
|
+
self.config['show_tray'] = self.tray_icon.isChecked()
|
|
2119
|
+
self.config['close_to_tray'] = self.close_to_tray.isChecked()
|
|
2120
|
+
self.config['start_in_tray'] = self.start_in_tray.isChecked()
|
|
2121
|
+
self.config['tray_api_icon'] = self.tray_api_icon.isChecked()
|
|
2122
|
+
self.config['notifications'] = self.notifications.isChecked()
|
|
2123
|
+
self.config['remember_geometry'] = self.remember_geometry.isChecked()
|
|
2124
|
+
self.config['remember_columns'] = self.remember_columns.isChecked()
|
|
2125
|
+
self.config['columns_per_api'] = self.columns_per_api.isChecked()
|
|
2126
|
+
self.config['filter_bar_position'] = self.filter_bar_position.itemData(self.filter_bar_position.currentIndex())
|
|
2127
|
+
self.config['filter_global'] = self.filter_global.isChecked()
|
|
2128
|
+
|
|
2129
|
+
self.config['episodebar_style'] = self.ep_bar_style.itemData(self.ep_bar_style.currentIndex())
|
|
2130
|
+
self.config['episodebar_text'] = self.ep_bar_text.isChecked()
|
|
2131
|
+
|
|
2132
|
+
self.config['colors'] = self.color_values
|
|
2133
|
+
|
|
2134
|
+
utils.save_config(self.config, self.configfile)
|
|
2135
|
+
|
|
2136
|
+
self.saved.emit()
|
|
2137
|
+
|
|
2138
|
+
def s_save(self):
|
|
2139
|
+
self._save()
|
|
2140
|
+
self.accept()
|
|
2141
|
+
|
|
2142
|
+
def tracker_type_change(self, checked):
|
|
2143
|
+
if self.tracker_enabled.isChecked():
|
|
2144
|
+
self.tracker_interval.setEnabled(True)
|
|
2145
|
+
self.tracker_update_wait.setEnabled(True)
|
|
2146
|
+
self.tracker_type_local.setEnabled(True)
|
|
2147
|
+
self.tracker_type_plex.setEnabled(True)
|
|
2148
|
+
if self.tracker_type_local.isChecked():
|
|
2149
|
+
self.tracker_process.setEnabled(True)
|
|
2150
|
+
self.plex_host.setEnabled(False)
|
|
2151
|
+
self.plex_port.setEnabled(False)
|
|
2152
|
+
elif self.tracker_type_plex.isChecked():
|
|
2153
|
+
self.plex_host.setEnabled(True)
|
|
2154
|
+
self.plex_port.setEnabled(True)
|
|
2155
|
+
self.tracker_process.setEnabled(False)
|
|
2156
|
+
else:
|
|
2157
|
+
self.tracker_type_local.setEnabled(False)
|
|
2158
|
+
self.tracker_type_plex.setEnabled(False)
|
|
2159
|
+
self.plex_host.setEnabled(False)
|
|
2160
|
+
self.plex_port.setEnabled(False)
|
|
2161
|
+
self.tracker_process.setEnabled(False)
|
|
2162
|
+
self.tracker_interval.setEnabled(False)
|
|
2163
|
+
self.tracker_update_wait.setEnabled(False)
|
|
2164
|
+
|
|
2165
|
+
def s_autoretrieve_days(self, checked):
|
|
2166
|
+
self.autoretrieve_days_n.setEnabled(checked)
|
|
2167
|
+
|
|
2168
|
+
def s_autosend_hours(self, checked):
|
|
2169
|
+
self.autosend_hours_n.setEnabled(checked)
|
|
2170
|
+
|
|
2171
|
+
def s_autosend_size(self, checked):
|
|
2172
|
+
self.autosend_size_n.setEnabled(checked)
|
|
2173
|
+
|
|
2174
|
+
def s_tray_icon(self, checked):
|
|
2175
|
+
self.close_to_tray.setEnabled(checked)
|
|
2176
|
+
self.start_in_tray.setEnabled(checked)
|
|
2177
|
+
self.tray_api_icon.setEnabled(checked)
|
|
2178
|
+
self.notifications.setEnabled(checked)
|
|
2179
|
+
|
|
2180
|
+
def s_ep_bar_style(self, index):
|
|
2181
|
+
if self.ep_bar_style.itemData(index) == EpisodeBar.BarStyle04:
|
|
2182
|
+
self.ep_bar_text.setEnabled(False)
|
|
2183
|
+
else:
|
|
2184
|
+
self.ep_bar_text.setEnabled(True)
|
|
2185
|
+
|
|
2186
|
+
def s_auto_status_change(self, checked):
|
|
2187
|
+
self.auto_status_change_if_scored.setEnabled(checked)
|
|
2188
|
+
|
|
2189
|
+
def s_player_browse(self):
|
|
2190
|
+
if pyqt_version is 5:
|
|
2191
|
+
self.player.setText( QFileDialog.getOpenFileName(caption='Choose player executable')[0] )
|
|
2192
|
+
else:
|
|
2193
|
+
self.player.setText( QFileDialog.getOpenFileName(caption='Choose player executable') )
|
|
2194
|
+
|
|
2195
|
+
def s_searchdir_browse(self):
|
|
2196
|
+
self.searchdir.setText( QFileDialog.getExistingDirectory(caption='Choose media directory') )
|
|
2197
|
+
|
|
2198
|
+
def s_switch_page(self, new, old):
|
|
2199
|
+
if not new:
|
|
2200
|
+
new = old
|
|
2201
|
+
|
|
2202
|
+
self.contents.setCurrentIndex( self.category_list.row( new ) )
|
|
2203
|
+
|
|
2204
|
+
def s_color_picker(self, key, system):
|
|
2205
|
+
return lambda: self.color_picker(key, system)
|
|
2206
|
+
|
|
2207
|
+
def color_picker(self, key, system):
|
|
2208
|
+
if system is True:
|
|
2209
|
+
current = self.color_values[key]
|
|
2210
|
+
result = ThemedColorPicker.do()
|
|
2211
|
+
if result is not None and result is not current:
|
|
2212
|
+
self.color_values[key] = result
|
|
2213
|
+
self.update_colors()
|
|
2214
|
+
else:
|
|
2215
|
+
current = getColor(self.color_values[key])
|
|
2216
|
+
result = QColorDialog.getColor(current)
|
|
2217
|
+
if result.isValid() and result is not current:
|
|
2218
|
+
self.color_values[key] = str(result.name())
|
|
2219
|
+
self.update_colors()
|
|
2220
|
+
|
|
2221
|
+
def update_colors(self):
|
|
2222
|
+
for ((key,label),color) in zip(self.colors['rows']+self.colors['progress'],self.color_buttons):
|
|
2223
|
+
color.setStyleSheet('background-color: ' + getColor(self.color_values[key]).name())
|
|
2224
|
+
|
|
2225
|
+
class ThemedColorPicker(QDialog):
|
|
2226
|
+
def __init__(self,parent=None,default=None):
|
|
2227
|
+
QDialog.__init__(self,parent)
|
|
2228
|
+
self.setWindowTitle('Select Color')
|
|
2229
|
+
layout = QVBoxLayout()
|
|
2230
|
+
colorbox = QGridLayout()
|
|
2231
|
+
self.colorString = default
|
|
2232
|
+
|
|
2233
|
+
self.groups = [0,1,2]
|
|
2234
|
+
self.roles = [1,2,3,4,5,11,12,16] # Only use background roles
|
|
2235
|
+
self.colors = []
|
|
2236
|
+
row = 0
|
|
2237
|
+
# Make colored buttons for selection
|
|
2238
|
+
for group in self.groups:
|
|
2239
|
+
col = 0
|
|
2240
|
+
for role in self.roles:
|
|
2241
|
+
self.colors.append( QPushButton() )
|
|
2242
|
+
self.colors[-1].setStyleSheet('background-color: ' + QtGui.QColor( QPalette().color(group, role) ).name() )
|
|
2243
|
+
self.colors[-1].setFocusPolicy(QtCore.Qt.NoFocus)
|
|
2244
|
+
self.colors[-1].clicked.connect( self.s_select(group,role) )
|
|
2245
|
+
colorbox.addWidget(self.colors[-1], row, col, 1, 1)
|
|
2246
|
+
col += 1
|
|
2247
|
+
row += 1
|
|
2248
|
+
bottombox = QDialogButtonBox()
|
|
2249
|
+
bottombox.addButton(QDialogButtonBox.Ok)
|
|
2250
|
+
bottombox.addButton(QDialogButtonBox.Cancel)
|
|
2251
|
+
bottombox.accepted.connect(self.accept)
|
|
2252
|
+
bottombox.rejected.connect(self.reject)
|
|
2253
|
+
layout.addLayout(colorbox)
|
|
2254
|
+
layout.addWidget(bottombox)
|
|
2255
|
+
self.setLayout(layout)
|
|
2256
|
+
|
|
2257
|
+
def s_select(self, group, role):
|
|
2258
|
+
return lambda: self.select(group, role)
|
|
2259
|
+
|
|
2260
|
+
def select(self, group, role):
|
|
2261
|
+
self.colorString = str(group) + ',' + str(role)
|
|
2262
|
+
|
|
2263
|
+
@staticmethod
|
|
2264
|
+
def do(parent=None, default=None):
|
|
2265
|
+
dialog = ThemedColorPicker(parent, default)
|
|
2266
|
+
result = dialog.exec_()
|
|
2267
|
+
|
|
2268
|
+
if result == QDialog.Accepted:
|
|
2269
|
+
return dialog.colorString
|
|
2270
|
+
else:
|
|
2271
|
+
return None
|
|
2272
|
+
|
|
2273
|
+
class AccountDialog(QDialog):
|
|
2274
|
+
selected = QtCore.pyqtSignal(int, bool)
|
|
2275
|
+
aborted = QtCore.pyqtSignal()
|
|
2276
|
+
|
|
2277
|
+
def __init__(self, parent, accountman):
|
|
2278
|
+
QDialog.__init__(self, parent)
|
|
2279
|
+
|
|
2280
|
+
self.accountman = accountman
|
|
2281
|
+
|
|
2282
|
+
layout = QVBoxLayout()
|
|
2283
|
+
|
|
2284
|
+
self.setWindowTitle('Select Account')
|
|
2285
|
+
|
|
2286
|
+
# Create list
|
|
2287
|
+
self.table = QTableWidget()
|
|
2288
|
+
self.table.horizontalHeader().setHighlightSections(False)
|
|
2289
|
+
self.table.setSelectionMode(QAbstractItemView.SingleSelection)
|
|
2290
|
+
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
|
2291
|
+
self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
|
2292
|
+
self.table.verticalHeader().hide()
|
|
2293
|
+
self.table.setGridStyle(QtCore.Qt.NoPen)
|
|
2294
|
+
self.table.doubleClicked.connect(self.select)
|
|
2295
|
+
|
|
2296
|
+
bottom_layout = QHBoxLayout()
|
|
2297
|
+
self.remember_chk = QCheckBox('Remember')
|
|
2298
|
+
if self.accountman.get_default() is not None:
|
|
2299
|
+
self.remember_chk.setChecked(True)
|
|
2300
|
+
cancel_btn = QPushButton('Cancel')
|
|
2301
|
+
cancel_btn.clicked.connect(self.cancel)
|
|
2302
|
+
add_btn = QPushButton('Add')
|
|
2303
|
+
add_btn.clicked.connect(self.add)
|
|
2304
|
+
self.edit_btns = QComboBox()
|
|
2305
|
+
self.edit_btns.blockSignals(True)
|
|
2306
|
+
self.edit_btns.addItem('Edit...')
|
|
2307
|
+
self.edit_btns.addItem('Update')
|
|
2308
|
+
self.edit_btns.addItem('Delete')
|
|
2309
|
+
self.edit_btns.addItem('Purge')
|
|
2310
|
+
self.edit_btns.setItemData( 1, 'Change the local password/PIN for this account', QtCore.Qt.ToolTipRole)
|
|
2311
|
+
self.edit_btns.setItemData( 2, 'Remove this account from Trackma', QtCore.Qt.ToolTipRole)
|
|
2312
|
+
self.edit_btns.setItemData( 3, 'Clear local DB for this account', QtCore.Qt.ToolTipRole)
|
|
2313
|
+
self.edit_btns.setCurrentIndex(0)
|
|
2314
|
+
self.edit_btns.blockSignals(False)
|
|
2315
|
+
self.edit_btns.activated.connect(self.s_edit)
|
|
2316
|
+
select_btn = QPushButton('Select')
|
|
2317
|
+
select_btn.clicked.connect(self.select)
|
|
2318
|
+
bottom_layout.addWidget(self.remember_chk) #, 1, QtCore.Qt.AlignRight)
|
|
2319
|
+
bottom_layout.addWidget(cancel_btn)
|
|
2320
|
+
bottom_layout.addWidget(add_btn)
|
|
2321
|
+
bottom_layout.addWidget(self.edit_btns)
|
|
2322
|
+
bottom_layout.addWidget(select_btn)
|
|
2323
|
+
|
|
2324
|
+
# Get icons
|
|
2325
|
+
self.icons = dict()
|
|
2326
|
+
for libname, lib in utils.available_libs.items():
|
|
2327
|
+
self.icons[libname] = QIcon(lib[1])
|
|
2328
|
+
|
|
2329
|
+
# Populate list
|
|
2330
|
+
self.rebuild()
|
|
2331
|
+
|
|
2332
|
+
# Finish layout
|
|
2333
|
+
layout.addWidget(self.table)
|
|
2334
|
+
layout.addLayout(bottom_layout)
|
|
2335
|
+
self.setLayout(layout)
|
|
2336
|
+
|
|
2337
|
+
def add(self):
|
|
2338
|
+
result = AccountAddDialog.do(icons=self.icons)
|
|
2339
|
+
if result:
|
|
2340
|
+
(username, password, api) = result
|
|
2341
|
+
self.accountman.add_account(username, password, api)
|
|
2342
|
+
self.rebuild()
|
|
2343
|
+
|
|
2344
|
+
def edit(self):
|
|
2345
|
+
self.edit_btns.blockSignals(True)
|
|
2346
|
+
self.edit_btns.setCurrentIndex(0)
|
|
2347
|
+
self.edit_btns.blockSignals(False)
|
|
2348
|
+
try:
|
|
2349
|
+
selected_account_num = self.table.selectedItems()[0].num
|
|
2350
|
+
acct = self.accountman.get_account(selected_account_num)
|
|
2351
|
+
result = AccountAddDialog.do(icons=self.icons,
|
|
2352
|
+
edit=True,
|
|
2353
|
+
username=acct['username'],
|
|
2354
|
+
password=acct['password'],
|
|
2355
|
+
api=acct['api'])
|
|
2356
|
+
if result:
|
|
2357
|
+
(username, password, api) = result
|
|
2358
|
+
self.accountman.edit_account(selected_account_num, username, password, api)
|
|
2359
|
+
self.rebuild()
|
|
2360
|
+
except IndexError:
|
|
2361
|
+
self._error("Please select an account.")
|
|
2362
|
+
|
|
2363
|
+
def delete(self):
|
|
2364
|
+
try:
|
|
2365
|
+
selected_account_num = self.table.selectedItems()[0].num
|
|
2366
|
+
reply = QMessageBox.question(self, 'Confirmation', 'Do you want to delete the selected account?', QMessageBox.Yes, QMessageBox.No)
|
|
2367
|
+
|
|
2368
|
+
if reply == QMessageBox.Yes:
|
|
2369
|
+
self.accountman.delete_account(selected_account_num)
|
|
2370
|
+
self.rebuild()
|
|
2371
|
+
except IndexError:
|
|
2372
|
+
self._error("Please select an account.")
|
|
2373
|
+
|
|
2374
|
+
def purge(self):
|
|
2375
|
+
try:
|
|
2376
|
+
selected_account_num = self.table.selectedItems()[0].num
|
|
2377
|
+
reply = QMessageBox.question(self, 'Confirmation', 'Do you want to purge the selected account\'s local data?', QMessageBox.Yes, QMessageBox.No)
|
|
2378
|
+
|
|
2379
|
+
if reply == QMessageBox.Yes:
|
|
2380
|
+
self.accountman.purge_account(selected_account_num)
|
|
2381
|
+
self.rebuild()
|
|
2382
|
+
except IndexError:
|
|
2383
|
+
self._error("Please select an account.")
|
|
2384
|
+
|
|
2385
|
+
def s_edit(self, index):
|
|
2386
|
+
if index is 1:
|
|
2387
|
+
self.edit()
|
|
2388
|
+
elif index is 2:
|
|
2389
|
+
self.delete()
|
|
2390
|
+
elif index is 3:
|
|
2391
|
+
self.purge()
|
|
2392
|
+
|
|
2393
|
+
def rebuild(self):
|
|
2394
|
+
self.table.clear()
|
|
2395
|
+
|
|
2396
|
+
columns = ['Username', 'Site']
|
|
2397
|
+
self.table.setColumnCount(len(columns))
|
|
2398
|
+
self.table.setHorizontalHeaderLabels(columns)
|
|
2399
|
+
self.table.setRowCount(len(self.accountman.accounts['accounts']))
|
|
2400
|
+
|
|
2401
|
+
accounts = self.accountman.get_accounts()
|
|
2402
|
+
i = 0
|
|
2403
|
+
for k, account in accounts:
|
|
2404
|
+
self.table.setRowHeight(i, QtGui.QFontMetrics(self.table.font()).height() + 2);
|
|
2405
|
+
self.table.setItem(i, 0, AccountItem(k, account['username']))
|
|
2406
|
+
self.table.setItem(i, 1, AccountItem(k, account['api'], self.icons[account['api']]))
|
|
2407
|
+
|
|
2408
|
+
i += 1
|
|
2409
|
+
|
|
2410
|
+
if pyqt_version is 5:
|
|
2411
|
+
self.table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
|
2412
|
+
else:
|
|
2413
|
+
self.table.horizontalHeader().setResizeMode(0, QHeaderView.Stretch)
|
|
2414
|
+
|
|
2415
|
+
def select(self, checked):
|
|
2416
|
+
try:
|
|
2417
|
+
selected_account_num = self.table.selectedItems()[0].num
|
|
2418
|
+
self.selected.emit(selected_account_num, self.remember_chk.isChecked())
|
|
2419
|
+
self.close()
|
|
2420
|
+
except IndexError:
|
|
2421
|
+
self._error("Please select an account.")
|
|
2422
|
+
|
|
2423
|
+
def cancel(self, checked):
|
|
2424
|
+
self.aborted.emit()
|
|
2425
|
+
self.close()
|
|
2426
|
+
|
|
2427
|
+
def _error(self, msg):
|
|
2428
|
+
QMessageBox.critical(self, 'Error', str(msg), QMessageBox.Ok)
|
|
2429
|
+
|
|
2430
|
+
class AccountItem(QTableWidgetItem):
|
|
2431
|
+
"""
|
|
2432
|
+
Regular item able to save account item
|
|
2433
|
+
|
|
2434
|
+
"""
|
|
2435
|
+
num = None
|
|
2436
|
+
|
|
2437
|
+
def __init__(self, num, text, icon=None):
|
|
2438
|
+
QTableWidgetItem.__init__(self, text)
|
|
2439
|
+
self.num = num
|
|
2440
|
+
if icon:
|
|
2441
|
+
self.setIcon( icon )
|
|
2442
|
+
|
|
2443
|
+
class ShowsTableWidget(QTableWidget):
|
|
2444
|
+
"""
|
|
2445
|
+
Regular table widget with context menu for show actions.
|
|
2446
|
+
|
|
2447
|
+
"""
|
|
2448
|
+
def __init__(self, parent = None):
|
|
2449
|
+
QTableWidget.__init__(self, parent)
|
|
2450
|
+
|
|
2451
|
+
def contextMenuEvent(self, event):
|
|
2452
|
+
action = self.context_menu.exec_(event.globalPos())
|
|
2453
|
+
|
|
2454
|
+
class ShowItem(QTableWidgetItem):
|
|
2455
|
+
"""
|
|
2456
|
+
Regular item able to show colors and alignment
|
|
2457
|
+
|
|
2458
|
+
"""
|
|
2459
|
+
|
|
2460
|
+
def __init__(self, text, color=None, alignment=None):
|
|
2461
|
+
QTableWidgetItem.__init__(self, text)
|
|
2462
|
+
if alignment:
|
|
2463
|
+
self.setTextAlignment( alignment )
|
|
2464
|
+
if color:
|
|
2465
|
+
self.setBackground( color )
|
|
2466
|
+
|
|
2467
|
+
class ShowItemNum(ShowItem):
|
|
2468
|
+
def __init__(self, num, text, color=None):
|
|
2469
|
+
ShowItem.__init__(self, text, color)
|
|
2470
|
+
self.setTextAlignment(QtCore.Qt.AlignHCenter)
|
|
2471
|
+
self.num = num
|
|
2472
|
+
|
|
2473
|
+
def __lt__(self, other):
|
|
2474
|
+
return self.num < other.num
|
|
2475
|
+
|
|
2476
|
+
class ShowItemDate(ShowItem):
|
|
2477
|
+
def __init__(self, date, color=None):
|
|
2478
|
+
if date:
|
|
2479
|
+
try:
|
|
2480
|
+
datestr = date.strftime("%Y-%m-%d")
|
|
2481
|
+
except ValueError:
|
|
2482
|
+
datestr = '?'
|
|
2483
|
+
else:
|
|
2484
|
+
datestr = '-'
|
|
2485
|
+
|
|
2486
|
+
self.date = date
|
|
2487
|
+
|
|
2488
|
+
ShowItem.__init__(self, datestr, color, QtCore.Qt.AlignHCenter)
|
|
2489
|
+
|
|
2490
|
+
def __lt__(self, other):
|
|
2491
|
+
if self.date and other.date:
|
|
2492
|
+
return self.date < other.date
|
|
2493
|
+
else:
|
|
2494
|
+
return True
|
|
2495
|
+
|
|
2496
|
+
class FilterBar():
|
|
2497
|
+
"""
|
|
2498
|
+
Constants relating to filter bar settings can live here.
|
|
2499
|
+
"""
|
|
2500
|
+
# Position
|
|
2501
|
+
PositionHidden = 0
|
|
2502
|
+
PositionAboveLists = 1
|
|
2503
|
+
PositionBelowLists = 2
|
|
2504
|
+
|
|
2505
|
+
class EpisodeBar(QProgressBar):
|
|
2506
|
+
"""
|
|
2507
|
+
Custom progress bar to show detailed information
|
|
2508
|
+
about episodes
|
|
2509
|
+
"""
|
|
2510
|
+
# Enum BarStyle
|
|
2511
|
+
BarStyleBasic = 0 # Basic native ProgressBar appearance
|
|
2512
|
+
BarStyle04 = 1 # Rectangular dual bar of Trackma v0.4
|
|
2513
|
+
BarStyleHybrid = 2 # Native ProgressBar with v0.4 library subbar overlaid
|
|
2514
|
+
|
|
2515
|
+
_subvalue = -1
|
|
2516
|
+
_episodes = []
|
|
2517
|
+
_subheight = 5
|
|
2518
|
+
_bar_style = BarStyle04
|
|
2519
|
+
_show_text = False
|
|
2520
|
+
|
|
2521
|
+
|
|
2522
|
+
def __init__(self, parent, colors):
|
|
2523
|
+
QProgressBar.__init__(self, parent)
|
|
2524
|
+
self.colors = colors
|
|
2525
|
+
|
|
2526
|
+
def paintEvent(self, event):
|
|
2527
|
+
rect = QtCore.QRect(0,0,self.width(), self.height())
|
|
2528
|
+
|
|
2529
|
+
if self._bar_style is self.BarStyleBasic:
|
|
2530
|
+
painter = QtGui.QPainter(self)
|
|
2531
|
+
prog_options = QStyleOptionProgressBar()
|
|
2532
|
+
prog_options.maximum = self.maximum()
|
|
2533
|
+
prog_options.progress = self.value()
|
|
2534
|
+
prog_options.rect = rect
|
|
2535
|
+
prog_options.text = '%d%%' % (self.value()*100/self.maximum())
|
|
2536
|
+
prog_options.textVisible = self._show_text
|
|
2537
|
+
self.style().drawControl(QStyle.CE_ProgressBar, prog_options, painter)
|
|
2538
|
+
|
|
2539
|
+
elif self._bar_style is self.BarStyle04:
|
|
2540
|
+
painter = QtGui.QPainter(self)
|
|
2541
|
+
painter.setBrush( getColor(self.colors['progress_bg']) )
|
|
2542
|
+
painter.setPen(QtCore.Qt.transparent)
|
|
2543
|
+
painter.drawRect( rect )
|
|
2544
|
+
self.paintSubValue(painter)
|
|
2545
|
+
if self.value() > 0:
|
|
2546
|
+
if self.value() >= self.maximum():
|
|
2547
|
+
painter.setBrush( getColor(self.colors['progress_complete']) )
|
|
2548
|
+
mid = self.width()
|
|
2549
|
+
else:
|
|
2550
|
+
painter.setBrush( getColor(self.colors['progress_fg']) )
|
|
2551
|
+
mid = int(self.width() / float(self.maximum()) * self.value())
|
|
2552
|
+
progressRect = QtCore.QRect(0, 0, mid, self.height())
|
|
2553
|
+
painter.drawRect(progressRect)
|
|
2554
|
+
self.paintEpisodes(painter)
|
|
2555
|
+
|
|
2556
|
+
elif self._bar_style is self.BarStyleHybrid:
|
|
2557
|
+
buffer = QtGui.QImage(self.width(), self.height(), QtGui.QImage.Format_ARGB32_Premultiplied)
|
|
2558
|
+
painter = QtGui.QPainter(buffer)
|
|
2559
|
+
painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source)
|
|
2560
|
+
painter.fillRect(rect, QtCore.Qt.transparent)
|
|
2561
|
+
painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)
|
|
2562
|
+
prog_options = QStyleOptionProgressBar()
|
|
2563
|
+
prog_options.maximum = self.maximum()
|
|
2564
|
+
prog_options.progress = self.value()
|
|
2565
|
+
prog_options.rect = rect
|
|
2566
|
+
prog_options.text = '%d%%' % (self.value()*100/self.maximum())
|
|
2567
|
+
self.style().drawControl(QStyle.CE_ProgressBar, prog_options, painter)
|
|
2568
|
+
painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceAtop)
|
|
2569
|
+
painter.setPen(QtCore.Qt.transparent)
|
|
2570
|
+
self.paintSubValue(painter)
|
|
2571
|
+
self.paintEpisodes(painter)
|
|
2572
|
+
painter = QtGui.QPainter(self)
|
|
2573
|
+
painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)
|
|
2574
|
+
painter.drawImage(rect, buffer)
|
|
2575
|
+
if self._show_text:
|
|
2576
|
+
self.style().drawControl(QStyle.CE_ProgressBarLabel, prog_options, painter)
|
|
2577
|
+
|
|
2578
|
+
def paintSubValue(self, painter):
|
|
2579
|
+
if self.subValue() > 0:
|
|
2580
|
+
painter.setBrush( getColor(self.colors['progress_sub_bg']) )
|
|
2581
|
+
mid = int(self.width() / float(self.maximum()) * self.subValue())
|
|
2582
|
+
progressRect = QtCore.QRect(0, self.height()-self._subheight, mid, self.height()-(self.height()-self._subheight))
|
|
2583
|
+
painter.drawRect(progressRect)
|
|
2584
|
+
|
|
2585
|
+
def paintEpisodes(self, painter):
|
|
2586
|
+
if self.episodes():
|
|
2587
|
+
for episode in self.episodes():
|
|
2588
|
+
painter.setBrush( getColor(self.colors['progress_sub_fg']) )
|
|
2589
|
+
if episode <= self.maximum():
|
|
2590
|
+
start = int(self.width() / float(self.maximum()) * (episode -1))
|
|
2591
|
+
finish = int(self.width() / float(self.maximum()) * episode)
|
|
2592
|
+
progressRect = QtCore.QRect(start, self.height()-self._subheight, finish-start, self.height()-(self.height()-self._subheight))
|
|
2593
|
+
painter.drawRect(progressRect)
|
|
2594
|
+
|
|
2595
|
+
def setSubValue(self, subvalue):
|
|
2596
|
+
if subvalue > self.maximum():
|
|
2597
|
+
self._subvalue = self.maximum()
|
|
2598
|
+
else:
|
|
2599
|
+
self._subvalue = subvalue
|
|
2600
|
+
|
|
2601
|
+
self.update()
|
|
2602
|
+
|
|
2603
|
+
def subValue(self):
|
|
2604
|
+
return self._subvalue
|
|
2605
|
+
|
|
2606
|
+
def setEpisodes(self, episodes):
|
|
2607
|
+
self._episodes = episodes
|
|
2608
|
+
self.update()
|
|
2609
|
+
|
|
2610
|
+
def episodes(self):
|
|
2611
|
+
return self._episodes
|
|
2612
|
+
|
|
2613
|
+
def setBarStyle(self, style, show_text):
|
|
2614
|
+
self._bar_style = style
|
|
2615
|
+
self._show_text = show_text
|
|
2616
|
+
|
|
2617
|
+
class AccountAddDialog(QDialog):
|
|
2618
|
+
def __init__(self, parent, icons, edit=False, username='', password='', api=''):
|
|
2619
|
+
QDialog.__init__(self, parent)
|
|
2620
|
+
self.edit = edit
|
|
2621
|
+
|
|
2622
|
+
# Build UI
|
|
2623
|
+
layout = QVBoxLayout()
|
|
2624
|
+
|
|
2625
|
+
formlayout = QFormLayout()
|
|
2626
|
+
self.lbl_username = QLabel('Username:')
|
|
2627
|
+
self.username = QLineEdit(username)
|
|
2628
|
+
|
|
2629
|
+
pin_layout = QHBoxLayout()
|
|
2630
|
+
self.lbl_password = QLabel('Password:')
|
|
2631
|
+
self.password = QLineEdit(password)
|
|
2632
|
+
self.api = QComboBox()
|
|
2633
|
+
self.api.currentIndexChanged.connect(self.s_refresh)
|
|
2634
|
+
self.api_auth = QLabel('Request PIN')
|
|
2635
|
+
self.api_auth.setTextFormat(QtCore.Qt.RichText)
|
|
2636
|
+
self.api_auth.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
|
2637
|
+
self.api_auth.setOpenExternalLinks(True)
|
|
2638
|
+
pin_layout.addWidget(self.password)
|
|
2639
|
+
pin_layout.addWidget(self.api_auth)
|
|
2640
|
+
|
|
2641
|
+
formlayout.addRow( QLabel('Site:'), self.api )
|
|
2642
|
+
formlayout.addRow( self.lbl_username, self.username )
|
|
2643
|
+
formlayout.addRow( self.lbl_password, pin_layout )
|
|
2644
|
+
|
|
2645
|
+
bottombox = QDialogButtonBox()
|
|
2646
|
+
bottombox.addButton(QDialogButtonBox.Save)
|
|
2647
|
+
bottombox.addButton(QDialogButtonBox.Cancel)
|
|
2648
|
+
bottombox.accepted.connect(self.validate)
|
|
2649
|
+
bottombox.rejected.connect(self.reject)
|
|
2650
|
+
|
|
2651
|
+
# Populate APIs
|
|
2652
|
+
for libname, lib in sorted(utils.available_libs.items()):
|
|
2653
|
+
self.api.addItem(icons[libname], lib[0], libname)
|
|
2654
|
+
|
|
2655
|
+
if self.edit:
|
|
2656
|
+
self.username.setEnabled(False)
|
|
2657
|
+
self.api.setCurrentIndex(self.api.findData(api, QtCore.Qt.UserRole))
|
|
2658
|
+
self.api.setEnabled(False)
|
|
2659
|
+
|
|
2660
|
+
# Finish layouts
|
|
2661
|
+
layout.addLayout(formlayout)
|
|
2662
|
+
layout.addWidget(bottombox)
|
|
2663
|
+
|
|
2664
|
+
self.setLayout(layout)
|
|
2665
|
+
|
|
2666
|
+
def validate(self):
|
|
2667
|
+
if len(self.username.text()) is 0:
|
|
2668
|
+
if len(self.password.text()) is 0:
|
|
2669
|
+
self._error('Please fill the credentials fields.')
|
|
2670
|
+
else:
|
|
2671
|
+
self._error('Please fill the username field.')
|
|
2672
|
+
elif len(self.password.text()) is 0:
|
|
2673
|
+
self._error('Please fill the password/PIN field.')
|
|
2674
|
+
else:
|
|
2675
|
+
self.accept()
|
|
2676
|
+
|
|
2677
|
+
def s_refresh(self, index):
|
|
2678
|
+
if not self.edit:
|
|
2679
|
+
self.username.setText("")
|
|
2680
|
+
self.password.setText("")
|
|
2681
|
+
|
|
2682
|
+
if pyqt_version is 5:
|
|
2683
|
+
apiname = self.api.itemData(index)
|
|
2684
|
+
else:
|
|
2685
|
+
apiname = str(self.api.itemData(index))
|
|
2686
|
+
api = utils.available_libs[apiname]
|
|
2687
|
+
if api[2] == utils.LOGIN_OAUTH:
|
|
2688
|
+
apiname = str(self.api.itemData(index))
|
|
2689
|
+
url = utils.available_libs[apiname][4]
|
|
2690
|
+
self.api_auth.setText( "<a href=\"{}\">Request PIN</a>".format(url) )
|
|
2691
|
+
self.api_auth.show()
|
|
2692
|
+
|
|
2693
|
+
self.lbl_username.setText('Name:')
|
|
2694
|
+
self.lbl_password.setText('PIN:')
|
|
2695
|
+
self.password.setEchoMode(QLineEdit.Normal)
|
|
2696
|
+
else:
|
|
2697
|
+
self.lbl_username.setText('Username:')
|
|
2698
|
+
self.lbl_password.setText('Password:')
|
|
2699
|
+
self.password.setEchoMode(QLineEdit.Password)
|
|
2700
|
+
self.api_auth.hide()
|
|
2701
|
+
|
|
2702
|
+
def _error(self, msg):
|
|
2703
|
+
QMessageBox.critical(self, 'Error', msg, QMessageBox.Ok)
|
|
2704
|
+
|
|
2705
|
+
@staticmethod
|
|
2706
|
+
def do(parent=None, icons=None, edit=False, username='', password='', api=''):
|
|
2707
|
+
dialog = AccountAddDialog(parent, icons, edit, username, password, api)
|
|
2708
|
+
result = dialog.exec_()
|
|
2709
|
+
|
|
2710
|
+
if result == QDialog.Accepted:
|
|
2711
|
+
currentIndex = dialog.api.currentIndex()
|
|
2712
|
+
return (
|
|
2713
|
+
str(dialog.username.text()),
|
|
2714
|
+
str(dialog.password.text()),
|
|
2715
|
+
str(dialog.api.itemData(currentIndex))
|
|
2716
|
+
)
|
|
2717
|
+
else:
|
|
2718
|
+
return None
|
|
2719
|
+
|
|
2720
|
+
class Image_Worker(QtCore.QThread):
|
|
2721
|
+
"""
|
|
2722
|
+
Image thread
|
|
2723
|
+
|
|
2724
|
+
Downloads an image and shrinks it if necessary.
|
|
2725
|
+
|
|
2726
|
+
"""
|
|
2727
|
+
cancelled = False
|
|
2728
|
+
finished = QtCore.pyqtSignal(str)
|
|
2729
|
+
|
|
2730
|
+
def __init__(self, remote, local, size=None):
|
|
2731
|
+
self.remote = remote
|
|
2732
|
+
self.local = local
|
|
2733
|
+
self.size = size
|
|
2734
|
+
super(Image_Worker, self).__init__()
|
|
2735
|
+
|
|
2736
|
+
def __del__(self):
|
|
2737
|
+
self.wait()
|
|
2738
|
+
|
|
2739
|
+
def run(self):
|
|
2740
|
+
self.cancelled = False
|
|
2741
|
+
|
|
2742
|
+
req = urllib.request.Request(self.remote)
|
|
2743
|
+
req.add_header("User-agent", "TrackmaImage/{}".format(utils.VERSION))
|
|
2744
|
+
img_file = BytesIO(urllib.request.urlopen(req).read())
|
|
2745
|
+
if self.size:
|
|
2746
|
+
im = Image.open(img_file)
|
|
2747
|
+
im.thumbnail((self.size[0], self.size[1]), Image.ANTIALIAS)
|
|
2748
|
+
im.save(self.local)
|
|
2749
|
+
else:
|
|
2750
|
+
with open(self.local, 'wb') as f:
|
|
2751
|
+
f.write(img_file.read())
|
|
2752
|
+
|
|
2753
|
+
if self.cancelled:
|
|
2754
|
+
return
|
|
2755
|
+
|
|
2756
|
+
self.finished.emit(self.local)
|
|
2757
|
+
|
|
2758
|
+
def cancel(self):
|
|
2759
|
+
self.cancelled = True
|
|
2760
|
+
|
|
2761
|
+
class Engine_Worker(QtCore.QThread):
|
|
2762
|
+
"""
|
|
2763
|
+
Worker thread
|
|
2764
|
+
|
|
2765
|
+
Contains the engine and manages every process in a separate thread.
|
|
2766
|
+
|
|
2767
|
+
"""
|
|
2768
|
+
engine = None
|
|
2769
|
+
function = None
|
|
2770
|
+
finished = QtCore.pyqtSignal(dict)
|
|
2771
|
+
|
|
2772
|
+
# Message handler signals
|
|
2773
|
+
changed_status = QtCore.pyqtSignal(str)
|
|
2774
|
+
raised_error = QtCore.pyqtSignal(str)
|
|
2775
|
+
raised_fatal = QtCore.pyqtSignal(str)
|
|
2776
|
+
|
|
2777
|
+
# Event handler signals
|
|
2778
|
+
changed_show = QtCore.pyqtSignal(dict)
|
|
2779
|
+
changed_list = QtCore.pyqtSignal(dict, object)
|
|
2780
|
+
changed_queue = QtCore.pyqtSignal(int)
|
|
2781
|
+
playing_show = QtCore.pyqtSignal(dict, bool, int)
|
|
2782
|
+
prompt_for_update = QtCore.pyqtSignal(dict, int)
|
|
2783
|
+
|
|
2784
|
+
def __init__(self, account):
|
|
2785
|
+
super(Engine_Worker, self).__init__()
|
|
2786
|
+
self.engine = Engine(account, self._messagehandler)
|
|
2787
|
+
self.engine.connect_signal('episode_changed', self._changed_show)
|
|
2788
|
+
self.engine.connect_signal('score_changed', self._changed_show)
|
|
2789
|
+
self.engine.connect_signal('tags_changed', self._changed_show)
|
|
2790
|
+
self.engine.connect_signal('status_changed', self._changed_list)
|
|
2791
|
+
self.engine.connect_signal('playing', self._playing_show)
|
|
2792
|
+
self.engine.connect_signal('show_added', self._changed_list)
|
|
2793
|
+
self.engine.connect_signal('show_deleted', self._changed_list)
|
|
2794
|
+
self.engine.connect_signal('show_synced', self._changed_show)
|
|
2795
|
+
self.engine.connect_signal('queue_changed', self._changed_queue)
|
|
2796
|
+
self.engine.connect_signal('prompt_for_update', self._prompt_for_update)
|
|
2797
|
+
|
|
2798
|
+
self.function_list = {
|
|
2799
|
+
'start': self._start,
|
|
2800
|
+
'reload': self._reload,
|
|
2801
|
+
'get_list': self._get_list,
|
|
2802
|
+
'set_episode': self._set_episode,
|
|
2803
|
+
'set_score': self._set_score,
|
|
2804
|
+
'set_status': self._set_status,
|
|
2805
|
+
'set_tags': self._set_tags,
|
|
2806
|
+
'play_episode': self._play_episode,
|
|
2807
|
+
'play_random': self._play_random,
|
|
2808
|
+
'list_download': self._list_download,
|
|
2809
|
+
'list_upload': self._list_upload,
|
|
2810
|
+
'get_show_details': self._get_show_details,
|
|
2811
|
+
'search': self._search,
|
|
2812
|
+
'add_show': self._add_show,
|
|
2813
|
+
'delete_show': self._delete_show,
|
|
2814
|
+
'unload': self._unload,
|
|
2815
|
+
'scan_library': self._scan_library,
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
def _messagehandler(self, classname, msgtype, msg):
|
|
2819
|
+
self.changed_status.emit("%s: %s" % (classname, msg))
|
|
2820
|
+
|
|
2821
|
+
def _error(self, msg):
|
|
2822
|
+
self.raised_error.emit(str(msg))
|
|
2823
|
+
|
|
2824
|
+
def _fatal(self, msg):
|
|
2825
|
+
self.raised_fatal.emit(str(msg))
|
|
2826
|
+
|
|
2827
|
+
def _changed_show(self, show, changes=None):
|
|
2828
|
+
self.changed_show.emit(show)
|
|
2829
|
+
|
|
2830
|
+
def _changed_list(self, show, old_status=None):
|
|
2831
|
+
self.changed_list.emit(show, old_status)
|
|
2832
|
+
|
|
2833
|
+
def _changed_queue(self, queue):
|
|
2834
|
+
self.changed_queue.emit(queue)
|
|
2835
|
+
|
|
2836
|
+
def _playing_show(self, show, is_playing, episode):
|
|
2837
|
+
self.playing_show.emit(show, is_playing, episode)
|
|
2838
|
+
|
|
2839
|
+
def _prompt_for_update(self, show, episode):
|
|
2840
|
+
self.prompt_for_update.emit(show, episode)
|
|
2841
|
+
|
|
2842
|
+
# Callable functions
|
|
2843
|
+
def _start(self):
|
|
2844
|
+
try:
|
|
2845
|
+
self.engine.start()
|
|
2846
|
+
except utils.TrackmaError as e:
|
|
2847
|
+
self._error(e)
|
|
2848
|
+
return {'success': False}
|
|
2849
|
+
|
|
2850
|
+
return {'success': True}
|
|
2851
|
+
|
|
2852
|
+
def _reload(self, account, mediatype):
|
|
2853
|
+
try:
|
|
2854
|
+
self.engine.reload(account, mediatype)
|
|
2855
|
+
except utils.TrackmaError as e:
|
|
2856
|
+
self._error(e)
|
|
2857
|
+
return {'success': False}
|
|
2858
|
+
|
|
2859
|
+
return {'success': True}
|
|
2860
|
+
|
|
2861
|
+
def _unload(self):
|
|
2862
|
+
try:
|
|
2863
|
+
self.engine.unload()
|
|
2864
|
+
except utils.TrackmaError as e:
|
|
2865
|
+
self._error(e)
|
|
2866
|
+
return {'success': False}
|
|
2867
|
+
|
|
2868
|
+
return {'success': True}
|
|
2869
|
+
|
|
2870
|
+
def _scan_library(self):
|
|
2871
|
+
try:
|
|
2872
|
+
self.engine.scan_library()
|
|
2873
|
+
except utils.TrackmaError as e:
|
|
2874
|
+
self._error(e)
|
|
2875
|
+
return {'success': False}
|
|
2876
|
+
|
|
2877
|
+
return {'success': True}
|
|
2878
|
+
|
|
2879
|
+
def _get_list(self):
|
|
2880
|
+
try:
|
|
2881
|
+
showlist = self.engine.get_list()
|
|
2882
|
+
altnames = self.engine.altnames()
|
|
2883
|
+
except utils.TrackmaError as e:
|
|
2884
|
+
self._error(e)
|
|
2885
|
+
return {'success': False}
|
|
2886
|
+
|
|
2887
|
+
return {'success': True, 'showlist': showlist, 'altnames': altnames}
|
|
2888
|
+
|
|
2889
|
+
def _set_episode(self, showid, episode):
|
|
2890
|
+
try:
|
|
2891
|
+
self.engine.set_episode(showid, episode)
|
|
2892
|
+
except utils.TrackmaError as e:
|
|
2893
|
+
self._error(e)
|
|
2894
|
+
return {'success': False}
|
|
2895
|
+
|
|
2896
|
+
return {'success': True}
|
|
2897
|
+
|
|
2898
|
+
def _set_score(self, showid, score):
|
|
2899
|
+
try:
|
|
2900
|
+
self.engine.set_score(showid, score)
|
|
2901
|
+
except utils.TrackmaError as e:
|
|
2902
|
+
self._error(e)
|
|
2903
|
+
return {'success': False}
|
|
2904
|
+
|
|
2905
|
+
return {'success': True}
|
|
2906
|
+
|
|
2907
|
+
def _set_status(self, showid, status):
|
|
2908
|
+
try:
|
|
2909
|
+
self.engine.set_status(showid, status)
|
|
2910
|
+
except utils.TrackmaError as e:
|
|
2911
|
+
self._error(e)
|
|
2912
|
+
return {'success': False}
|
|
2913
|
+
|
|
2914
|
+
return {'success': True}
|
|
2915
|
+
|
|
2916
|
+
def _set_tags(self, showid, tags):
|
|
2917
|
+
try:
|
|
2918
|
+
self.engine.set_tags(showid, tags)
|
|
2919
|
+
except utils.TrackmaError as e:
|
|
2920
|
+
self._error(e)
|
|
2921
|
+
return {'success': False}
|
|
2922
|
+
|
|
2923
|
+
return {'success': True}
|
|
2924
|
+
|
|
2925
|
+
def _play_episode(self, show, episode):
|
|
2926
|
+
try:
|
|
2927
|
+
played_ep = self.engine.play_episode(show, episode)
|
|
2928
|
+
except utils.TrackmaError as e:
|
|
2929
|
+
self._error(e)
|
|
2930
|
+
return {'success': False}
|
|
2931
|
+
|
|
2932
|
+
return {'success': True, 'show': show, 'played_ep': played_ep}
|
|
2933
|
+
|
|
2934
|
+
def _play_random(self):
|
|
2935
|
+
try:
|
|
2936
|
+
(show, ep) = self.engine.play_random()
|
|
2937
|
+
except utils.TrackmaError as e:
|
|
2938
|
+
self._error(e)
|
|
2939
|
+
return {'success': False}
|
|
2940
|
+
|
|
2941
|
+
return {'success': True, 'played_show': show, 'played_ep': ep}
|
|
2942
|
+
|
|
2943
|
+
def _list_download(self):
|
|
2944
|
+
try:
|
|
2945
|
+
self.engine.list_download()
|
|
2946
|
+
except utils.TrackmaError as e:
|
|
2947
|
+
self._error(e)
|
|
2948
|
+
return {'success': False}
|
|
2949
|
+
|
|
2950
|
+
return {'success': True}
|
|
2951
|
+
|
|
2952
|
+
def _list_upload(self):
|
|
2953
|
+
try:
|
|
2954
|
+
self.engine.list_upload()
|
|
2955
|
+
except utils.TrackmaError as e:
|
|
2956
|
+
self._error(e)
|
|
2957
|
+
return {'success': False}
|
|
2958
|
+
|
|
2959
|
+
return {'success': True}
|
|
2960
|
+
|
|
2961
|
+
def _get_show_details(self, show):
|
|
2962
|
+
try:
|
|
2963
|
+
details = self.engine.get_show_details(show)
|
|
2964
|
+
except utils.TrackmaError as e:
|
|
2965
|
+
self._error(e)
|
|
2966
|
+
return {'success': False}
|
|
2967
|
+
|
|
2968
|
+
return {'success': True, 'details': details}
|
|
2969
|
+
|
|
2970
|
+
def _search(self, terms):
|
|
2971
|
+
try:
|
|
2972
|
+
results = self.engine.search(terms)
|
|
2973
|
+
except utils.TrackmaError as e:
|
|
2974
|
+
self._error(e)
|
|
2975
|
+
return {'success': False}
|
|
2976
|
+
|
|
2977
|
+
return {'success': True, 'results': results}
|
|
2978
|
+
|
|
2979
|
+
def _add_show(self, show, status):
|
|
2980
|
+
try:
|
|
2981
|
+
results = self.engine.add_show(show, status)
|
|
2982
|
+
except utils.TrackmaError as e:
|
|
2983
|
+
self._error(e)
|
|
2984
|
+
return {'success': False}
|
|
2985
|
+
|
|
2986
|
+
return {'success': True}
|
|
2987
|
+
|
|
2988
|
+
def _delete_show(self, show):
|
|
2989
|
+
try:
|
|
2990
|
+
results = self.engine.delete_show(show)
|
|
2991
|
+
except utils.TrackmaError as e:
|
|
2992
|
+
self._error(e)
|
|
2993
|
+
return {'success': False}
|
|
2994
|
+
|
|
2995
|
+
return {'success': True}
|
|
2996
|
+
|
|
2997
|
+
def set_function(self, function, ret_function, *args, **kwargs):
|
|
2998
|
+
self.function = self.function_list[function]
|
|
2999
|
+
|
|
3000
|
+
try:
|
|
3001
|
+
self.finished.disconnect()
|
|
3002
|
+
except Exception:
|
|
3003
|
+
pass
|
|
3004
|
+
|
|
3005
|
+
if ret_function:
|
|
3006
|
+
self.finished.connect(ret_function)
|
|
3007
|
+
|
|
3008
|
+
self.args = args
|
|
3009
|
+
self.kwargs = kwargs
|
|
3010
|
+
|
|
3011
|
+
def __del__(self):
|
|
3012
|
+
self.wait()
|
|
3013
|
+
|
|
3014
|
+
def run(self):
|
|
3015
|
+
try:
|
|
3016
|
+
ret = self.function(*self.args,**self.kwargs)
|
|
3017
|
+
self.finished.emit(ret)
|
|
3018
|
+
except utils.TrackmaFatal as e:
|
|
3019
|
+
self._fatal(e)
|
|
3020
|
+
|
|
3021
|
+
def getIcon(icon_name):
|
|
3022
|
+
fallback = QIcon(utils.datadir + '/data/qtui/{}.png'.format(icon_name))
|
|
3023
|
+
return QIcon.fromTheme(icon_name, fallback)
|
|
3024
|
+
|
|
3025
|
+
def getColor(colorString):
|
|
3026
|
+
# Takes a color string in either #RRGGBB format or group,role format (using QPalette int values)
|
|
3027
|
+
if colorString[0] == "#":
|
|
3028
|
+
return QtGui.QColor(colorString)
|
|
3029
|
+
else:
|
|
3030
|
+
(group, role) = [int(i) for i in colorString.split(',')]
|
|
3031
|
+
if (0 <= group <= 2) and (0 <= role <= 19):
|
|
3032
|
+
return QtGui.QColor( QPalette().color(group, role) )
|
|
3033
|
+
else:
|
|
3034
|
+
# Failsafe - return black
|
|
3035
|
+
return QtGui.QColor()
|
|
3036
|
+
|
|
3037
|
+
def main():
|
|
3038
|
+
app = QApplication(sys.argv)
|
|
3039
|
+
try:
|
|
3040
|
+
mainwindow = Trackma()
|
|
3041
|
+
sys.exit(app.exec_())
|
|
3042
|
+
except utils.TrackmaFatal as e:
|
|
3043
|
+
QMessageBox.critical(None, 'Fatal Error', "{0}".format(e), QMessageBox.Ok)
|
|
3044
|
+
|
|
3045
|
+
if __name__ == '__main__':
|
|
3046
|
+
main()
|