-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
229 lines (193 loc) · 8.19 KB
/
Copy pathgui.py
File metadata and controls
229 lines (193 loc) · 8.19 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
import sys
import time
import os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import join_fires
import merge_incendios
import procesar_incendios_grilla
import fire_phenology
class QProgBar(QProgressBar):
value = 0
@pyqtSlot()
def increaseValue(progressBar):
progressBar.setValue(progressBar.value)
progressBar.value = progressBar.value+1
class GUI:
def __init__(self):
QApplication.setStyle(QStyleFactory.create('CleanLooks'))
# Create an PyQT4 application object.
self.a = QApplication(sys.argv)
# The QWidget widget is the base class of all user interface objects in PyQt4.
self.window = QWidget()
# Set window size.
self.window.resize(640/2,480/4)
# Set window title
self.window.setWindowTitle("Detección de eventos de incendio")
self.macrolayout = QVBoxLayout(self.window)
self.addIntroBlock()
self.addFirstStageBlock()
self.addSecondStageBlock()
self.addThirdStageBlock()
self.addFourthStageBlock()
def addIntroBlock(self):
label = QLabel("Detectar eventos de incendio")
label.setAlignment(Qt.AlignCenter)
self.macrolayout.addWidget(label)
def addFirstStageBlock(self):
# First stage: join_fires.py
topgridlayout = QGridLayout()
self.macrolayout.addLayout(topgridlayout)
textbox = QLineEdit()
textbox.setPlaceholderText("archivo csv")
def openFileDialog():
filename = QFileDialog.getOpenFileName(
self.window,
'Abrir CSV',
os.getcwd()
)
textbox.setText(filename)
btn = QPushButton('Cargar archivo de entrada')
btn.clicked.connect(openFileDialog)
btn.resize(btn.sizeHint())
btn.move(100, 80)
topgridlayout.addWidget(textbox,0,0)
topgridlayout.addWidget(btn, 0,1)
firstStageLayout = QGridLayout()
self.macrolayout.addLayout(firstStageLayout)
formato_fecha_label = QLabel("Formato de la fecha")
formato_fecha_box = QLineEdit()
formato_fecha_box.setPlaceholderText("%d (dia) %m (mes) %Y (año)")
formato_fecha_ayuda = QLabel("e.g. %d/%m/%Y")
firstStageLayout.addWidget(formato_fecha_label, 2,0)
firstStageLayout.addWidget(formato_fecha_box, 2,1)
firstStageLayout.addWidget(formato_fecha_ayuda, 2,2)
separador_label = QLabel("Separador:")
separador_radio_1 = QRadioButton(";")
separador_radio_2 = QRadioButton(",")
separador_radio_group = QButtonGroup()
separador_radio_group.addButton(separador_radio_1,1)
separador_radio_group.addButton(separador_radio_2,2)
separador_radio_group.setExclusive(False)
firstStageLayout.addWidget(separador_label,3,0)
firstStageLayout.addWidget(separador_radio_1,3,1)
firstStageLayout.addWidget(separador_radio_2,3,2)
pdecimal_label = QLabel("Punto decimal:")
pdecimal_radio_1 = QRadioButton(",")
pdecimal_radio_2 = QRadioButton(".")
pdecimal_radio_group = QButtonGroup()
pdecimal_radio_group.addButton(pdecimal_radio_1,1)
pdecimal_radio_group.addButton(pdecimal_radio_2,2)
pdecimal_radio_group.setExclusive(True)
firstStageLayout.addWidget(pdecimal_label,4,0)
firstStageLayout.addWidget(pdecimal_radio_1,4,1)
firstStageLayout.addWidget(pdecimal_radio_2,4,2)
bar = QProgBar()
self.bar_inserted = False
def procesar_join_fires():
if not self.bar_inserted:
self.macrolayout.insertWidget(3,bar)
self.bar_inserted = True
bar.setValue(0)
print(pdecimal_radio_group.checkedId())
print(separador_radio_group.checkedId())
def actualizar_barra(porc):
bar.setValue(porc)
self.a.processEvents()
print("Archivo entrada = " + textbox.text())
print("Formato de fecha = " + formato_fecha_box.text())
pdecimal = "."
if pdecimal_radio_group.checkedId() == 1:
pdecimal = ","
separador = ","
if separador_radio_group.checkedId() == 1:
separador = ";"
print("pdecimal = " + pdecimal + " sep = " + separador)
join_fires.SEPARADOR = separador
join_fires.PUNTO_DECIMAL = pdecimal
join_fires.FORMATO_FECHA = formato_fecha_box.text()
app = join_fires.Difusion(actualizar_barra)
app.cargar_de_archivo(textbox.text())
app.correr()
app.guardar_en_archivo(join_fires.ARCHIVO_SALIDA)
del(app)
procesar_1 = QPushButton('Procesar')
procesar_1.clicked.connect(procesar_join_fires)
firstStageLayout.addWidget(procesar_1, 5,0)
self.macrolayout.addSpacing(10)
def addSecondStageBlock(self):
secondStageLayout = QGridLayout()
self.macrolayout.addLayout(secondStageLayout)
def procesar_agrupar():
# It may look like it should be 5, but after a bar
# is inserted in the first stage it shuold be 6.
self.macrolayout.insertWidget(6, QLabel("Agrupando.."))
merge_incendios.merge_incendios()
self.macrolayout.insertWidget(7, QLabel("OK!"))
secondStageTitle = QLabel("Agrupar focos de incendio")
secondStageTitle.setAlignment(Qt.AlignCenter)
secondStageFileOut = QLabel(
"Archivo de salida:"
+ os.getcwd() + "/" + merge_incendios.DEFAULT_FILENAME_OUT
)
secondStageFileOut.setAlignment(Qt.AlignLeft)
secondStageButton = QPushButton("Procesar")
secondStageButton.clicked.connect(procesar_agrupar)
secondStageLayout.addWidget(secondStageTitle)
secondStageLayout.addWidget(secondStageFileOut)
secondStageLayout.addWidget(secondStageButton)
def addThirdStageBlock(self):
thirdStageLayout = QGridLayout()
self.macrolayout.addLayout(thirdStageLayout)
bar = QProgBar()
self.grid_bar_inserted = False
def procesar_asignar_celdas():
if not self.grid_bar_inserted:
self.macrolayout.insertWidget(9, bar)
bar.setValue(0)
def actualizar_barra(porc):
bar.setValue(porc)
self.a.processEvents()
procesar_incendios_grilla.asignar_grilla(actualizar_barra)
thirdStageTitle = QLabel("Asignar celdas de grillas")
thirdStageTitle.setAlignment(Qt.AlignCenter)
thirdStageFileOut = QLabel(
"Archivo de salida:"
+ os.getcwd() + "/"+procesar_incendios_grilla.AR_CSV_OUT
)
thirdStageFileOut.setAlignment(Qt.AlignLeft)
thirdStageButton = QPushButton("Procesar")
thirdStageButton.clicked.connect(procesar_asignar_celdas)
thirdStageLayout.addWidget(thirdStageTitle)
thirdStageLayout.addWidget(thirdStageFileOut)
thirdStageLayout.addWidget(thirdStageButton)
def addFourthStageBlock(self):
fourthStageLayout = QGridLayout()
self.macrolayout.addLayout(fourthStageLayout)
def procesar_phenology():
self.macrolayout.addWidget(QLabel("Analizando.."))
fire_phenology.analizar_fenologia()
self.macrolayout.addWidget(QLabel("OK!"))
fourthStageTitle = QLabel("Analizar fenologia")
fourthStageTitle.setAlignment(Qt.AlignCenter)
fourthStageFileOut = QLabel(
"Archivo de salida:"
+ os.getcwd() + "/"+fire_phenology.AR_OUT_ANUAL + "\n y "
+ os.getcwd() + "/"+fire_phenology.AR_OUT_MENSUAL
)
fourthStageFileOut.setAlignment(Qt.AlignLeft)
fourthStageButton = QPushButton("Procesar")
fourthStageButton.clicked.connect(procesar_phenology)
fourthStageLayout.addWidget(fourthStageTitle)
fourthStageLayout.addWidget(fourthStageFileOut)
fourthStageLayout.addWidget(fourthStageButton)
def run(self):
self.window.show()
sys.exit(self.a.exec_())
g = GUI()
g.run()
# Parte 2
# Show window