-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathLoadQSSDialog.py
149 lines (131 loc) · 5.43 KB
/
LoadQSSDialog.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-
"""
/***************************************************************************
LoadQSS
A QGIS plugin
Configure look and feel
-------------------
begin : 2015-04-29
copyright : (C) 2015 All4Gis.
email : franka1986 at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* 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 *
# any later version. *
* *
***************************************************************************/
"""
# Import the PyQt and QGIS libraries
from .AboutQSSDialog import AboutQSSDialog
from LoadQSS.gui.generated.Load_QSS import Ui_LoadQSSDialog
from LoadQSS.utils.utils import *
from qgis.PyQt.QtCore import Qt
from qgis.gui import *
import os
try:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
except ImportError:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# try:
# from pydevd import *
# except ImportError:
# None
class LoadQSSDialog(QDialog, Ui_LoadQSSDialog):
def __init__(self, iface):
QDialog.__init__(self)
self.setupUi(self)
self.iface = iface
self.lastOpenedFile = None
self.app = QApplication.instance()
self.listStyles.addItems(getStyleList())
self.currentItem = None
# Copy style to examples plugin folder
def to_exmples_folder(self, folder, stylesheet):
return os.path.join(self.plugin_dir, "examples", folder, stylesheet)
# About
def About(self):
self.About = AboutQSSDialog(self.iface)
self.About.setWindowFlags(Qt.Window | Qt.WindowCloseButtonHint)
self.About.exec_()
# Selected row
def SelectRow(self, checked):
if checked:
self.Delete_btn.setEnabled(True)
self.Activate_btn.setEnabled(True)
self.currentItem = checked
self.ApplyStyle(preview=True)
else:
self.Delete_btn.setEnabled(False)
self.Activate_btn.setEnabled(False)
self.currentItem = None
# Add new qss
def AddStyle(self):
self.filename, _ = QFileDialog.getOpenFileName(self, "Open qss",
self.lastOpenedFile,
"*.qss")
if self.filename:
flags = Qt.WindowSystemMenuHint | Qt.WindowTitleHint
text, ok = QInputDialog.getText(self, 'Style Name',
'Enter name for Style:',
flags=flags)
if ok:
if text == "":
self.iface.messageBar().clearWidgets()
self.iface.messageBar().pushMessage("Error: ",
"Enter theme name.",
level=QgsMessageBar.CRITICAL,
duration=3)
return
# Add to list
self.listStyles.addItem(text)
# TODO :Copy style to examples folder
AddNewStyle(text, self.filename)
return
# Remove style in list
def DeleteStyle(self):
try:
if(self.currentItem.text() == getPreview()):
if (self.currentItem.text() == getActivated()):
ret = QMessageBox.question(self, 'Delete Style : '
+ self.currentItem.text(),
'The style you are about to remove is your active style.\n' +
'The default Qgis style will be set.\n' +
'Are you sure you want to remove it?',
QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if ret == QMessageBox.Yes:
self.ResetStyle()
if ret == QMessageBox.No:
return
else:
activateStyle(getActivated(), self.iface)
except Exception:
None
self.listStyles.takeItem(self.listStyles.currentRow())
delStyle(self.currentItem.text())
self.Delete_btn.setEnabled(False)
self.Activate_btn.setEnabled(False)
self.currentItem = None
return
# Apply style
def ApplyStyle(self, preview=False):
try:
activateStyle(self.currentItem.text(), self.iface, preview)
except Exception:
None
return
# Restores style
def ResetStyle(self):
self.app.setStyleSheet("")
setActivated("")
return
# Close dialog
def closeEvent(self, evt):
activateStyle(getActivated(), self.iface, close=True)
return