I have the working code below running in a venv using python 3.7.6 what I want is when the Province combobox is changed have the stations combobox updated with that selected Provinces stations. How do I hook that event?
import sys
from PyQt6 import QtGui, QtCore
import bs4
from bs4 import BeautifulSoup
import requests
#import urllib3 as urllib # the lib that handles the url stuff
import urllib.request
provs = ['AB','BC','MB','NB','NL','NS','NT','NU','ON','PE','QC','SK','YT']
for prov in provs:
print(prov)
url = 'https://dd.weather.gc.ca/hydrometric/csv/' + prov + '/daily/' + prov + '_daily_hydrometric.csv'
print(url)
#https://dd.weather.gc.ca/hydrometric/doc/hydrometric_StationList.csv
def getStationsProv(provis):
data = urllib.request.urlopen('https://dd.weather.gc.ca/hydrometric/doc/hydrometric_StationList.csv') # it's a file like object and works just like a file
dataFiltered = []
for line in data: # files are iterable
#print(line.decode())
data = line.decode().split(",")
# dataFiltered.append("Station1")
if data[4] == provis :
arrayData = str(data[0]) + '-' + str(data[1]).replace('"','').replace(' ','_')
dataFiltered.append(arrayData)
# print(arrayData)
# print(dataFiltered)
# dataFiltered.append("Station2")
return dataFiltered
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import (
QApplication,
QCheckBox,
QComboBox,
QDateEdit,
QDateTimeEdit,
QDial,
QDoubleSpinBox,
QFontComboBox,
QLabel,
QLCDNumber,
QLineEdit,
QMainWindow,
QProgressBar,
QPushButton,
QRadioButton,
QSlider,
QSpinBox,
QTimeEdit,
QVBoxLayout,
QWidget,
)
# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
def getValue(self):
provIs = self.cbUser.itemData(self.qcb1.currentIndex()).toPyObject()
print(str(id_us))
def __init__(self):
super().__init__()
self.setWindowTitle("Env Canada hydrometric data")
self.setFixedWidth(500)
layout = QVBoxLayout()
label1 = QLabel("Select a province") #,
layout.addWidget(label1)
qcb1 = QComboBox() #,
qcb1.addItems(provs)
layout.addWidget(qcb1)
qcb2 = QComboBox()
df = getStationsProv(qcb1.currentText())
#df = getStationsProv('AB')
#print(df)
qcb2.addItems(df)
layout.addWidget(qcb2)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
Attached Files
