-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_grid_layout.py
137 lines (116 loc) · 5.63 KB
/
main_grid_layout.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QVBoxLayout, QLineEdit, QPushButton, QApplication, QDialog, QInputDialog, \
QComboBox, QMessageBox, QTreeWidget, QTreeWidgetItem, QTableWidget, QTableWidgetItem
from PyQt5.Qt import Qt
import qlib
import qlib as qc
import sqlite_crud
import parameters as gl
import stdio
class MainGridConfig(QDialog):
def __init__(self, parent = None):
super(MainGridConfig, self).__init__(parent)
self.toto = False
self.setWindowTitle('Configurar Grelha')
self.setWindowIcon(QIcon('./img/columns.png'))
masterLayout = QVBoxLayout(self)
self.textEdit = QLineEdit()
self.conditionsCbx = QComboBox()
self.configGrid = QTableWidget(self)
self.configGrid.setSelectionBehavior(QTableWidget.SelectRows)
self.configGrid.setSelectionMode(QTableWidget.SingleSelection)
self.configGrid.setEditTriggers(QTableWidget.NoEditTriggers)
self.configGrid.verticalHeader().setDefaultSectionSize(20)
self.configGrid.setAlternatingRowColors(True)
self.configGrid.verticalHeader().setVisible(False)
self.configGrid.setStyleSheet("alternate-background-color: #d2e5ff;")
# addBtn = QPushButton('Adiciona')
# addBtn.clicked.connect(self.add_click)
# deleteBtn = QPushButton('Apaga')
# deleteBtn.clicked.connect(self.delete_click)
# renameBtn = QPushButton('Renomeia')
# renameBtn.clicked.connect(self.rename_click)
saveBtn = QPushButton('Guarda')
self.fix_size(saveBtn, size= 80)
saveBtn.clicked.connect(self.save_click)
exitBtn = QPushButton('Sair')
self.fix_size(exitBtn)
exitBtn.clicked.connect(self.exit_click)
masterLayout.addLayout(qc.addHLayout([saveBtn, exitBtn, True]))
masterLayout.addWidget(self.configGrid)
self.update_grid()
def fix_size(self, widget_control, size = 50):
widget_control.setMaximumWidth(size)
widget_control.setMinimumWidth(size)
def update_grid(self):
self.configGrid.setColumnCount(3)
self.configGrid.setHorizontalHeaderLabels(['Visivel','Coluna','Tamanho'])
self.configGrid.setRowCount(len(gl.GRID_COL_NAMES))
for n in range(0,len(gl.GRID_COL_NAMES)):
self.configGrid.setCellWidget(n, 0, qlib.checkBoxGrid())
if gl.GRID_COLUMN_SIZES[n][1] > 0 :
self.configGrid.cellWidget(n,0) .layout().itemAt(1).widget().setChecked(True)
else:
self.configGrid.cellWidget(n,0) .layout().itemAt(1).widget().setChecked(False)
item = QTableWidgetItem()
item.setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter)
item.setText(gl.GRID_COL_NAMES[n])
self.configGrid.setItem(n, 1, item)
item = QTableWidgetItem()
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
item.setText(str(gl.GRID_COLUMN_SIZES[n][1]))
self.configGrid.setItem(n, 2, item)
self.configGrid.resizeColumnsToContents()
self.configGrid.setColumnWidth(2,0)
def add_click(self):
text, flag = QInputDialog.getText(None, "Adiciona Estado Fisico:", "", QLineEdit.Normal,'')
if flag and not text == '':
# if not dbmain.find_duplicate('conditions', 'condition_name', text):
sql = 'INSERT into conditions (condition_name) VALUES (?);'
sqlite_crud.execute_query(sql, (text,))
self.update_grid()
self.textEdit.clear()
# else:
# void = QMessageBox.warning(None, "Erro", 'Estado Fisico Duplicado',
# QMessageBox.StandardButtons(QMessageBox.Close), QMessageBox.Close)
def delete_click(self):
sqlite_crud.execute_query('delete from conditions where condition_name=?', (self.conditionsList.currentItem().text(0), ))
self.update_grid()
def rename_click(self):
text, flag = QInputDialog.getText(None, "Altera nome do Estado Fisico:", "", QLineEdit.Normal,'')
if flag and not text == '':
sqlite_crud.execute_query('UPDATE conditions set condition_name=? WHERE condition_name=?',
(text,self.conditionsList.currentItem().text(0)))
self.update_grid()
def save_click(self):
gl.GRID_COLUMN_SIZES = []
for n in range(0,len(gl.GRID_COL_NAMES)):
if self.configGrid.cellWidget(n, 0).layout().itemAt(1).widget().isChecked(): # .isChecked(): # foi ticado
if int(self.configGrid.item(n, 2).text()) == 0:
gl.GRID_COLUMN_SIZES.append((n,40))
else:
gl.GRID_COLUMN_SIZES.append((n, int(self.configGrid.item(n, 2).text())))
else:
gl.GRID_COLUMN_SIZES.append((n,0))
sqlite_crud.save_parameters('GRID_COLUMN_SIZES', str(gl.GRID_COLUMN_SIZES))
sqlite_crud.load_parameters()
self.toto = True
self.close()
def exit_click(self):
self.toto = False
self.close()
def main():
gl.db_params = stdio.read_config_file('gabo.ini')
gl.conn_string = "host=" + gl.db_params['db_host'] + ' port=' + gl.db_params['db_port'] + ' dbname=' + gl.db_params[
'db_database'] + \
' user=' + gl.db_params['db_user'] + ' password=' + gl.db_params['db_password']
sqlite_crud.load_parameters()
app = QApplication(sys.argv)
form = MainGridConfig()
form.show()
app.exec_()
if __name__ == '__main__':
main()