-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCEApp.py
80 lines (63 loc) · 2.62 KB
/
PCEApp.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
#!/usr/bin/env python
# Copyright (C) 2014 Chaserhkj
# This file is licensed under the MIT license
# For more details, see COPYRIGHT
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QUrl
import PCEModels
import PCEDataMgr
import os,sys
import json,time
class PCEApp(object):
def __init__(self, app):
self._engine = QQmlApplicationEngine()
self._context = self._engine.rootContext()
self._mgr = PCEDataMgr.DataMgr()
self._repoM = PCEModels.RepoModel([])
self._cateM = PCEModels.CateModel([])
self._emojiM = PCEModels.EmojiModel([])
self._cb = app.clipboard()
self._context.setContextProperty("reposModel", self._repoM)
self._context.setContextProperty("cateModel", self._cateM)
self._context.setContextProperty("emojisModel", self._emojiM)
self._engine.load(QUrl.fromLocalFile("interface.qml"))
self._rootObj = self._engine.rootObjects()[0]
self._rootObj.cateClicked.connect(self.updateEmoji)
self._rootObj.emojiActivated.connect(self.copyEmoji)
self._rootObj.addRepoRequested.connect(self.addRepo)
self._rootObj.delRepoRequested.connect(self.delRepo)
self._rootObj.aboutToClose.connect(self.saveAndCleanUp)
self._seletedCate = -1
self._config = os.path.join(os.environ["HOME"],".PCE.json")
if os.path.exists(self._config):
with open(self._config) as f:
repoList = json.load(f)
for i in repoList:
self.addRepo(QUrl.fromLocalFile(i))
def show(self):
self._rootObj.show()
def updateEmoji(self, row):
self._seletedCate = row
self._emojiM.setEmojis(self._mgr.emojis[row])
def copyEmoji(self, row):
self._cb.setText(self._mgr.emojis[self._seletedCate][row]["emoticon"])
self._rootObj.deselectEmoji()
time.sleep(0.5) # This sounds like a hack, may have more elegant methods
self._rootObj.minimize()
def addRepo(self, url):
self._mgr.addFile(url.toLocalFile())
self._repoM.setRepos(self._mgr.repos)
self._cateM.setCates(self._mgr.names)
def delRepo(self, row):
self._mgr.delRepo(row)
self._repoM.setRepos(self._mgr.repos)
self._cateM.setCates(self._mgr.names)
def saveAndCleanUp(self):
with open(self._config, "w") as f:
json.dump([i[1] for i in self._mgr.repos], f, indent = 4)
if __name__=="__main__":
app = QGuiApplication(sys.argv)
PCE = PCEApp(app)
PCE.show()
sys.exit(app.exec_())