1# -*- coding: utf-8 -*-
2
3"""
4***************************************************************************
5    RenderingStyleFilePanel.py
6    ---------------------
7    Date                 : August 2012
8    Copyright            : (C) 2012 by Victor Olaya
9    Email                : volayaf at gmail dot com
10***************************************************************************
11*                                                                         *
12*   This program is free software; you can redistribute it and/or modify  *
13*   it under the terms of the GNU General Public License as published by  *
14*   the Free Software Foundation; either version 2 of the License, or     *
15*   (at your option) any later version.                                   *
16*                                                                         *
17***************************************************************************
18"""
19
20__author__ = 'Victor Olaya'
21__date__ = 'August 2012'
22__copyright__ = '(C) 2012, Victor Olaya'
23
24import os
25import warnings
26
27from qgis.PyQt import uic
28from qgis.PyQt.QtWidgets import QFileDialog
29
30from processing.tools.system import isWindows
31
32pluginPath = os.path.split(os.path.dirname(__file__))[0]
33
34with warnings.catch_warnings():
35    warnings.filterwarnings("ignore", category=DeprecationWarning)
36    WIDGET, BASE = uic.loadUiType(
37        os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
38
39
40class RenderingStyleFilePanel(BASE, WIDGET):
41
42    def __init__(self):
43        super(RenderingStyleFilePanel, self).__init__(None)
44        self.setupUi(self)
45
46        self.btnSelect.clicked.connect(self.showSelectionDialog)
47
48    def showSelectionDialog(self):
49        filename, selected_filter = QFileDialog.getOpenFileName(self,
50                                                                self.tr('Select Style File'), '',
51                                                                self.tr('QGIS Layer Style File (*.qml *.QML)'))
52        if filename:
53            self.leText.setText(filename)
54
55    def setText(self, text):
56        self.leText.setText(text)
57
58    def getValue(self):
59        s = self.leText.text()
60        if isWindows():
61            s = s.replace('\\', '/')
62        return s
63