~lrcshow-x/lrcshow-x/2-series

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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Filename: preferenceShortcut.py
 
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class preferenceShortcut(QWidget):
	
	def __init__(self, shortcutsValue):
		QWidget.__init__(self)
		
		mainLayout = QVBoxLayout(None)
		mainLayout.setContentsMargins(5, 10, 0, 0)
		
		layout1 = QHBoxLayout(None)
		layout1.setContentsMargins(0, 0, 200, 0)
		self.setShortcut = QPushButton(QIcon('./icon/configure.png'), _('Set shortcut...'), self)
		self.setShortcut.setEnabled(False)
		self.setDefault = QPushButton(QIcon('./icon/undo.png'), _('Back to default'), self)
		layout1.addWidget(self.setShortcut)
		layout1.addWidget(self.setDefault)
		
		shortcutDescribe = [_('Switch to fullscreen mode'), _('Switch to OSD mode'), _('Switch to normal mode'), _('Switch to horizontal mode'), _('Lrceditor: insert a time-tag'), _('Lrceditor: delete the last time-tag'), _('Open the lrc editor'), _('Save offset'), _('Delay the lrc 0.2 second'), _('Advance the lrc 0.2 second'), _('Show the fast setting bar'), _('Reload the current lrc')]
		
		self.shortcutsValue = shortcutsValue
		
		self.itemNum = len(shortcutDescribe)
		self.table = QTableWidget(self.itemNum, 2, self)
		self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        	self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
		self.table.setSelectionMode(QAbstractItemView.SingleSelection)
		self.table.setColumnWidth(0, 300)
		self.table.setColumnWidth(1, 80)
		title = QStringList()<<_('Description')<<_('Shortcuts')
		self.table.setHorizontalHeaderLabels(title)
		for i in range(self.itemNum):
			self.table.setItem(i, 0, QTableWidgetItem(shortcutDescribe[i], 0))
			self.table.setItem(i, 1, QTableWidgetItem(self.shortcutsValue[i], 0))
		
		mainLayout.addWidget(self.table)
		mainLayout.addLayout(layout1)
		self.setLayout(mainLayout)
		
		self.connect(self.table, SIGNAL("cellClicked(int,int)"), self.activeSet)
		self.connect(self.setShortcut, SIGNAL("clicked()"), self.changeShortcut)
		self.connect(self.table, SIGNAL("cellDoubleClicked(int,int)"), self.changeShortcut)
		self.connect(self.setDefault, SIGNAL("clicked()"), self.defaultAction)
		
	def defaultAction(self):
		self.shortcutsValue = ['F', 'O', 'Esc', 'H', 'F5', 'F6', 'E', 'S', '-', '+', 'I', 'R']
		for i in range(self.itemNum):
			self.table.setItem(i, 1, QTableWidgetItem(self.shortcutsValue[i], 0))
	
	def activeSet(self,row,col):
		if(not self.setShortcut.isEnabled()):
			self.setShortcut.setEnabled(True)
	
	def changeShortcut(self):
		row = self.table.currentRow()
		editorBox = shortcutBox()
		editorBox.editorBox.setText(self.table.item(row, 1).text())
		result = editorBox.exec_()
		if(result == QDialog.Accepted):
			tmpList = []
			for i in range(self.itemNum):
				if(i == row):
					pass
				else:
					tmpList.append(self.table.item(i, 1).text())
			if(editorBox.editorBox.text() in tmpList):
				a = QMessageBox(QMessageBox.Information,  _('Shortcuts conflict'), _('The operation was canceled'))
				okButton = QPushButton(QIcon('./icon/ok.png'),  _('Ok'))
				a.addButton(okButton, QMessageBox.YesRole)
				a.exec_()
			else:
				self.table.setItem(row, 1, QTableWidgetItem(editorBox.editorBox.text(), 0))
				for i in range(self.itemNum):
					self.shortcutsValue[i] = str(self.table.item(i, 1).text())

class shortcutBox(QDialog):
	
	def __init__(self, parent = None, *args):
		QDialog.__init__(self, parent)
		self.setWindowTitle(_('Capturing Shortcut'))
		mainLayout = QVBoxLayout(None)
		layout1 = QHBoxLayout(None)
		self.ok = QPushButton(QIcon('./icon/ok.png'), _('Ok'), self)
		self.cancel = QPushButton(QIcon('./icon/cancel.png'), _('Cancel'), self)
		self.clear = QPushButton(QIcon('./icon/del_tags.png'), _('Clear'), self)
		layout1.addWidget(self.ok)
		layout1.addWidget(self.clear)
		layout1.addWidget(self.cancel)
		self.comment = QLabel(_('Single Key allowed'), self)
		self.editorBox = QLineEdit(self)
		self.editorBox.setReadOnly(True)
		self.editorBox.setFocus()
		mainLayout.addWidget(self.comment)
		mainLayout.addWidget(self.editorBox)
		mainLayout.addLayout(layout1)
		self.setLayout(mainLayout)
		
		self.connect(self.ok,SIGNAL("clicked()"),self,SLOT("accept()"))
		self.connect(self.cancel,SIGNAL("clicked()"),self,SLOT("reject()"))
		self.connect(self.clear,SIGNAL("clicked()"),self.editorBox,SLOT("clear()"))
	
	def keyPressEvent(self,ev):
		self.editorBox.setText(QKeySequence(ev.key()).toString())