-
Notifications
You must be signed in to change notification settings - Fork 3
/
editor.py
executable file
·130 lines (88 loc) · 3.64 KB
/
editor.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess, sys
from PyQt4 import QtGui, QtCore
PROGRAM_NAME = "getLyrics editor"
class infoLabel(QtGui.QLabel):
def __init__(self, *args):
super(infoLabel, self).__init__(*args)
self.setOpenExternalLinks(False)
self.linkActivated.connect(self.googleSearch)
def googleSearch(self, url):
url = unicode(url.toUtf8(), sys.getfilesystemencoding())
subprocess.Popen(["kioclient", "exec", url], stdout = open('/dev/null', 'w'), stderr = subprocess.STDOUT)
class lyricsEditor(QtGui.QWidget):
textChanged = False
def __init__(self, lyrics, info):
super(lyricsEditor, self).__init__()
self.initUI(lyrics, info)
def initUI(self, lyrics = "", info = ""):
self.hlButtons = QtGui.QHBoxLayout()
self.hlButtons.addStretch()
if info != "":
url = " ".join(info.split())
url = "http://www.google.com/search?q=%s&ie=UTF-8&oe=UTF-8" % info.replace('"', "%22").replace("'", "%27").replace("&", "%26").replace("?", "%3F")
info = "<a href=\'%s\'>%s</a>" % (url, info)
self.lblInfo = infoLabel(info, self)
self.lblInfo.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
self.btnSave = QtGui.QPushButton("&Save", self)
self.btnSave.setEnabled(False)
self.btnSave.clicked.connect(self.saveFile)
self.btnSave.resize(self.btnSave.sizeHint())
self.hlButtons.addWidget(self.btnSave)
self.btnQuit = QtGui.QPushButton('&Quit', self)
self.btnQuit.clicked.connect(self.close)
self.btnQuit.resize(self.btnQuit.sizeHint())
self.btnQuit.setAutoDefault(True)
self.hlButtons.addWidget(self.btnQuit)
self.tdText = QtGui.QTextEdit(self)
self.tdText.setAcceptRichText(False)
self.tdText.setPlainText(lyrics)
self.tdText.textChanged.connect(self.textChangedSlot)
self.mainLayout = QtGui.QVBoxLayout(self)
self.setLayout(self.mainLayout)
if info != "":
self.mainLayout.addWidget(self.lblInfo)
self.mainLayout.addWidget(self.tdText)
self.mainLayout.addLayout(self.hlButtons)
#self.sizeHint = QtCore.QSize(500, 600)
self.resize(500, 600)
#self.setGeometry(300, 300, 250, 150)
self.setWindowTitle(PROGRAM_NAME)
self.show()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.close()
def textChangedSlot(self):
self.textChanged = True
self.btnSave.setEnabled(True)
def closeEvent(self, event):
if self.textChanged:
reply = QtGui.QMessageBox.question(self, PROGRAM_NAME + ' - Message',
"Your are about to loose all your changes.\n\nAre you sure to quit?", QtGui.QMessageBox.Yes |
QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
event.accept()
else:
event.ignore()
else:
event.accept()
def saveFile(self, event):
print self.tdText.toPlainText().toUtf8()
self.textChanged = False
self.close()
def main():
lyrics = info = ""
try:
lyrics = unicode(sys.argv[1].strip(), sys.getfilesystemencoding())
except:
pass
try:
info = unicode(sys.argv[2].strip(), sys.getfilesystemencoding())
except:
pass
app = QtGui.QApplication(sys.argv)
ex = lyricsEditor(lyrics, info)
sys.exit(app.exec_())
if __name__ == '__main__':
main()