-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.py
83 lines (69 loc) · 2.62 KB
/
Application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (C) 2018--2019 Philip Belemezov.
# All Rights Reserved.
#
# This file is part of Subtitles.
#
# Subtitles is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Subtitles is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Subtitles. If not, see <https://www.gnu.org/licenses/>.
import sys
from os import path
from enum import Enum
from PyQt5.Qt import (
QApplication, QStandardPaths, QSettings
)
from log import logger
class Application(QApplication):
class ResourceType(Enum):
IMAGE = 1
TEXT = 2
_resourceMap = {
ResourceType.IMAGE: {
'extensions': ['.png'],
}
}
def __init__(self, args):
super().__init__(args)
# self.setOrganizationName("philipbel")
self.setOrganizationDomain("philipbel.github.io")
self.setApplicationName("Subtitles")
if sys.platform == 'win32':
QSettings.setDefaultFormat(QSettings.IniFormat)
self._resourcePaths = self._initResourcePaths()
def _initResourcePaths(self):
resourcePaths = []
resourcePaths.append(path.dirname(__file__))
resourcePaths.extend(QStandardPaths.standardLocations(
QStandardPaths.AppLocalDataLocation))
# For when we're running from the dev tree
resourcePaths.append(path.abspath(path.curdir))
resourcePaths.append(path.join(path.abspath(path.curdir), 'resources'))
resourcePaths.append(path.join(path.abspath(path.curdir), 'doc'))
return resourcePaths
def findResource(self, resource, resourceType=None):
if resourceType:
extensions = Application._resourceMap[resourceType]['extensions']
else:
extensions = ['']
for p in self._resourcePaths:
for ext in extensions:
resourcePath = path.join(p, resource + ext)
if path.exists(resourcePath):
return resourcePath
logger.warn("Unable to locate resource '{}' of type '{}'".format(
resource, resourceType
))
return None
@staticmethod
def instance():
assert(isinstance(QApplication.instance(), Application))
return QApplication.instance()