2015-02-21 18:30:32 -08:00
|
|
|
"""A python app to (automatically) tag comic archives"""
|
2013-02-06 17:20:05 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Copyright 2012-2014 Anthony Beville
|
2013-02-06 17:20:05 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2013-02-06 17:20:05 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-06 17:20:05 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2013-02-06 17:20:05 -08:00
|
|
|
|
2018-01-14 07:41:27 -08:00
|
|
|
import os
|
2013-02-06 17:20:05 -08:00
|
|
|
import sys
|
|
|
|
import signal
|
|
|
|
import traceback
|
|
|
|
import platform
|
2018-01-14 07:41:27 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from .settings import ComicTaggerSettings
|
|
|
|
# Need to load setting before anything else
|
|
|
|
SETTINGS = ComicTaggerSettings()
|
2013-02-06 17:20:05 -08:00
|
|
|
|
|
|
|
try:
|
2015-02-12 14:57:46 -08:00
|
|
|
qt_available = True
|
2018-09-19 13:05:39 -07:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
|
|
from .taggerwindow import TaggerWindow
|
2013-02-06 17:20:05 -08:00
|
|
|
except ImportError as e:
|
2015-02-12 14:57:46 -08:00
|
|
|
qt_available = False
|
2015-02-13 15:08:07 -08:00
|
|
|
|
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from . import utils
|
|
|
|
from . import cli
|
|
|
|
from .options import Options
|
|
|
|
from .comicvinetalker import ComicVineTalker
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
def ctmain():
|
2015-02-12 14:57:46 -08:00
|
|
|
opts = Options()
|
|
|
|
opts.parseCmdLineArgs()
|
|
|
|
|
|
|
|
# manage the CV API key
|
|
|
|
if opts.cv_api_key:
|
2018-09-19 13:05:39 -07:00
|
|
|
if opts.cv_api_key != SETTINGS.cv_api_key:
|
|
|
|
SETTINGS.cv_api_key = opts.cv_api_key
|
|
|
|
SETTINGS.save()
|
2015-02-12 14:57:46 -08:00
|
|
|
if opts.only_set_key:
|
2015-02-13 15:08:07 -08:00
|
|
|
print("Key set")
|
2015-02-12 14:57:46 -08:00
|
|
|
return
|
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
ComicVineTalker.api_key = SETTINGS.cv_api_key
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
|
|
|
|
|
|
if not qt_available and not opts.no_gui:
|
|
|
|
opts.no_gui = True
|
2018-09-19 13:05:39 -07:00
|
|
|
print("PyQt5 is not available. ComicTagger is limited to command-line mode.", file=sys.stderr)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if opts.no_gui:
|
2018-09-19 13:05:39 -07:00
|
|
|
cli.cli_mode(opts, SETTINGS)
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2019-10-06 05:15:18 -07:00
|
|
|
os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'
|
2018-09-19 13:05:39 -07:00
|
|
|
app = QtWidgets.QApplication(sys.argv)
|
|
|
|
if platform.system() == "Darwin":
|
|
|
|
# Set the MacOS dock icon
|
|
|
|
app.setWindowIcon(
|
|
|
|
QtGui.QIcon(ComicTaggerSettings.getGraphic('app.png')))
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
# For pure python, tell windows that we're not python,
|
|
|
|
# so we can have our own taskbar icon
|
|
|
|
import ctypes
|
|
|
|
myappid = u'comictagger' # arbitrary string
|
|
|
|
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
|
2019-10-06 05:15:18 -07:00
|
|
|
# force close of console window
|
|
|
|
SWP_HIDEWINDOW = 0x0080
|
|
|
|
consoleWnd = ctypes.windll.kernel32.GetConsoleWindow()
|
|
|
|
if consoleWnd != 0:
|
|
|
|
ctypes.windll.user32.SetWindowPos(consoleWnd, None, 0, 0, 0, 0, SWP_HIDEWINDOW)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if platform.system() != "Linux":
|
2015-02-15 02:44:00 -08:00
|
|
|
img = QtGui.QPixmap(ComicTaggerSettings.getGraphic('tags.png'))
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
splash = QtWidgets.QSplashScreen(img)
|
2015-02-12 14:57:46 -08:00
|
|
|
splash.show()
|
|
|
|
splash.raise_()
|
|
|
|
app.processEvents()
|
|
|
|
|
|
|
|
try:
|
2018-09-19 13:05:39 -07:00
|
|
|
tagger_window = TaggerWindow(opts.file_list, SETTINGS, opts=opts)
|
|
|
|
tagger_window.setWindowIcon(
|
|
|
|
QtGui.QIcon(ComicTaggerSettings.getGraphic('app.png')))
|
2015-02-12 14:57:46 -08:00
|
|
|
tagger_window.show()
|
|
|
|
|
|
|
|
if platform.system() != "Linux":
|
2015-02-13 15:08:07 -08:00
|
|
|
splash.finish(tagger_window)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
sys.exit(app.exec_())
|
2015-02-13 15:08:07 -08:00
|
|
|
except Exception as e:
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QMessageBox.critical(
|
|
|
|
QtWidgets.QMainWindow(),
|
2015-02-15 03:55:04 -08:00
|
|
|
"Error",
|
|
|
|
"Unhandled exception in app:\n" +
|
|
|
|
traceback.format_exc())
|