forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 13
/
qad_shortcuts.py
98 lines (77 loc) · 3.9 KB
/
qad_shortcuts.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
classe per la gestione delle scorciatoie
-------------------
begin : 2020-04-23
copyright : iiiii
email : hhhhh
developers : bbbbb aaaaa ggggg
***************************************************************************/
/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import QKeySequence
from qgis.gui import QgsGui
import string
#===============================================================================
# QadShortcuts class
#===============================================================================
class QadShortcuts():
def __init__(self):
self.sManager = QgsGui.shortcutsManager()
self.objList = [] # lista di coppie (shortcut KeySequence) o (action KeySequence)
def __del__(self):
self.registerForPrintable()
del self.objList[:] # svuoto la lista
def registerForPrintableAndQadFKeys(self):
# setta una lista di shortcut e una di action
for item in self.objList:
self.sManager.setObjectKeySequence(item[0], item[1].toString())
return
def unregisterForPrintableAndQadFKeys(self):
# rimuove gli shortcut e le action relative ai caratteri stampabili
# e li memorizza in 2 liste interne: una per gi shortcut ed una per le action che sono state rimosse
del self.objList[:] # svuoto la lista
s = string.printable
for i in range(0, len(s)):
seq = QKeySequence(s[i])
obj = self.sManager.objectForSequence(seq)
if obj is not None:
self.objList.append([obj, seq])
self.sManager.setObjectKeySequence(obj, QKeySequence().toString()) # lo annulla
# rimuove gli shortcut e le action relative ai caratteri F2, F3, F8, F12, ESC
seq = QKeySequence(Qt.Key_F2)
obj = self.sManager.objectForSequence(seq)
if obj is not None:
self.objList.append([obj, seq])
self.sManager.setObjectKeySequence(obj, QKeySequence().toString()) # lo annulla
seq = QKeySequence(Qt.Key_F3)
obj = self.sManager.objectForSequence(seq)
if obj is not None:
self.objList.append([obj, seq])
self.sManager.setObjectKeySequence(obj, QKeySequence().toString()) # lo annulla
seq = QKeySequence(Qt.Key_F8)
obj = self.sManager.objectForSequence(seq)
if obj is not None:
self.objList.append([obj, seq])
self.sManager.setObjectKeySequence(obj, QKeySequence().toString()) # lo annulla
seq = QKeySequence(Qt.Key_F12)
obj = self.sManager.objectForSequence(seq)
if obj is not None:
self.objList.append([obj, seq])
self.sManager.setObjectKeySequence(obj, QKeySequence().toString()) # lo annulla
seq = QKeySequence(Qt.Key_Escape)
obj = self.sManager.objectForSequence(seq)
if obj is not None:
self.objList.append([obj, seq])
self.sManager.setObjectKeySequence(obj, QKeySequence().toString()) # lo annulla
return