1# -*- coding: utf-8 -*-
2
3"""
4***************************************************************************
5    FixedTablePanel.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
28
29from processing.gui.FixedTableDialog import FixedTableDialog
30
31pluginPath = os.path.split(os.path.dirname(__file__))[0]
32
33with warnings.catch_warnings():
34    warnings.filterwarnings("ignore", category=DeprecationWarning)
35    WIDGET, BASE = uic.loadUiType(
36        os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
37
38
39class FixedTablePanel(BASE, WIDGET):
40
41    def __init__(self, param, parent=None):
42        super(FixedTablePanel, self).__init__(parent)
43        self.setupUi(self)
44
45        self.leText.setEnabled(False)
46
47        self.param = param
48
49        # NOTE - table IS squashed to 1-dimensional!
50        self.table = []
51        for row in range(param.numberRows()):
52            for col in range(len(param.headers())):
53                self.table.append('0')
54
55        self.leText.setText(
56            self.tr('Fixed table {0}x{1}').format(param.numberRows(), len(param.headers())))
57
58        self.btnSelect.clicked.connect(self.showFixedTableDialog)
59
60    def updateSummaryText(self):
61        self.leText.setText(self.tr('Fixed table {0}x{1}').format(
62            len(self.table) // len(self.param.headers()), len(self.param.headers())))
63
64    def setValue(self, value):
65        self.table = value
66        self.updateSummaryText()
67
68    def showFixedTableDialog(self):
69        dlg = FixedTableDialog(self.param, self.table)
70        dlg.exec_()
71        if dlg.rettable is not None:
72            self.setValue(dlg.rettable)
73        dlg.deleteLater()
74