Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
Added a main loading bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sklyvan committed Nov 23, 2021
1 parent 715863e commit 93c35e3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
7 changes: 7 additions & 0 deletions res/GUI/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QProgressBar" name="mainProgressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# Graphic User Interface variables.
REPOSITORY_URL = "https://github.com/Sklyvan/ScrapingUPF"
README_URL = "https://github.com/Sklyvan/ScrapingUPF/blob/main/README.md"
APP_LOGO = "../res/GUI/AppLogo.png"
APP_LOGO = "../res/GUI/AppLogo.png"
21 changes: 21 additions & 0 deletions src/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def addGeneratedEvents(MyCalendar, subjectsBlocks, calendarID, subjectsColors, l
return True

def RunApplication(deleteMode=False, replaceMode=True):
global loadingStatus
loadingStatus = 0
"""
This function is the main function of the application,
it's going to read the configuration file, then it's going to generate the events.
Expand All @@ -135,32 +137,43 @@ def RunApplication(deleteMode=False, replaceMode=True):
:param replaceMode: If this is true, the function will replace the events in the Google Calendar.
:return: True in case of success, False in case of error.
"""
yield loadingStatus

# Checking the Python version, in this case we're going to use Python 3.8 or higher, since I'm using the Walrus Operator.
if sys.version_info.major < PYTHON_VERSION['Major'] or (sys.version_info.major >= PYTHON_VERSION['Major'] and sys.version_info.minor < PYTHON_VERSION['Minor']):
addLogInformation(f"You're using Python {sys.version_info.major}.{sys.version_info.minor}, required version is 3.8 or bigger.")
return False
loadingStatus += 3
yield loadingStatus

# Checking if the configuration file exists, if it exists, we're going to read it.
if os.path.isfile(CONFIG_FILE):
userPreferences = getUserPreferences(CONFIG_FILE)
else:
addLogInformation(f"UserPreferences.ini not found at {CONFIG_FILE}.")
return False
loadingStatus += 12
yield loadingStatus

if isUsingEspaiAulaFilePath(userPreferences): # If the user is using the automatic mode, we're going to read the HTML file with user data.
espaiAulaFile = HTML_LocalFile(getEspaiAulaFilePath(userPreferences), DECODE_HTML_FILE)
fromGroups, fromSubjects, userSubjectsGroups, pGroups, sGroups = extractSubjectsPreferencesFromFile(espaiAulaFile)
else: # If the user is using the manual mode, we're going to read the user groups and subjects from the user preferences file.
fromGroups, fromSubjects, userSubjectsGroups, pGroups, sGroups = extractSubjectsPreferences(userPreferences)
loadingStatus += 15
yield loadingStatus

subjectsColors = dict(zip(fromSubjects, [str(x%GOOGLE_CALENDAR_API_MAX_COLORS+1) for x in range(len(fromSubjects))])) # Generating a dictionary[subjectCode] = assignedColor
loadingStatus += 5
yield loadingStatus

# Extracting the time information.
basicInformation, timeRange = extractRequestInformation(userPreferences)
DATA = generateData(fromSubjects, fromGroups, basicInformation)
fromDate = int(time.mktime(datetime.datetime.strptime(timeRange[0], "%d/%m/%Y").timetuple()))
toDate = int(time.mktime(datetime.datetime.strptime(timeRange[1], "%d/%m/%Y").timetuple()))
loadingStatus += 25
yield loadingStatus

"""
At this point, we have all the user data and we checked if it's correct.
Expand All @@ -173,11 +186,17 @@ def RunApplication(deleteMode=False, replaceMode=True):
addLogInformation(f"Using {len(subjectsBlocks)} subjects blocks.")
else:
addLogInformation("No subjects blocks have been downloaded, closing program.")
return False
else:
addLogInformation("Something went wrong generating blocks, closing program.")
return False
loadingStatus += 15
yield loadingStatus

MyCalendar = Calendar()
calendarID = getCalendarID(userPreferences)
loadingStatus += 5
yield loadingStatus

# Now, with all the information downloaded, we're going to work with Google Calendar API.
if replaceMode: # In this case, we're deleting all the events in the calendar and then adding the new ones.
Expand All @@ -190,4 +209,6 @@ def RunApplication(deleteMode=False, replaceMode=True):
addGeneratedEvents(MyCalendar, subjectsBlocks, calendarID, subjectsColors)

addLogInformation("Everything has been done successfully.")
loadingStatus += 20
yield loadingStatus
return True
21 changes: 17 additions & 4 deletions src/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def setupUi(self, MainWindowDesign, QtApplication):
self.transferButton.setObjectName("transferButton")
self.verticalLayout.addWidget(self.transferButton)
self.gridLayout_3.addWidget(self.endBox, 2, 0, 1, 1)
self.mainProgressBar = QtWidgets.QProgressBar(self.mainWindow)
self.mainProgressBar.setProperty("value", 0)
self.mainProgressBar.setObjectName("mainProgressBar")
self.gridLayout_3.addWidget(self.mainProgressBar, 3, 0, 1, 1)
MainWindowDesign.setCentralWidget(self.mainWindow)
self.menuBar = QtWidgets.QMenuBar(MainWindowDesign)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 594, 22))
Expand Down Expand Up @@ -275,8 +279,6 @@ def setupUi(self, MainWindowDesign, QtApplication):
self.actionManual.triggered.connect(self.openManual)
self.actionAgradecimientos.triggered.connect(self.runInformationWindow)

self.threads = {}

def retranslateUi(self, MainWindowDesign):
_translate = QtCore.QCoreApplication.translate
MainWindowDesign.setWindowTitle(_translate("MainWindowDesign", "ScrapingUPF"))
Expand Down Expand Up @@ -333,6 +335,8 @@ def runOnInit(self):
self.endDateEdit.setDate(QtCore.QDate.fromString(timeRange[1], 'dd/MM/yyyy'))
if isUsingEspaiAulaFilePath(userPreferences): self.filePathText.setText(getEspaiAulaFilePath(userPreferences))

self.mainProgressBar.setValue(0)

def clickSaveButton(self):
planEstudio = self.planEstudioText.text()
idiomaPais = self.idiomaPaisText.text()
Expand Down Expand Up @@ -370,18 +374,27 @@ def clickUseFileButton(self):
def clickRemoveSubjectsButton(self): # Remove subjects from Google Calendar
fromDate, toDate = self.startDateEdit.text(), self.endDateEdit.text()
insertTimeRange(CONFIG_FILE, fromDate, toDate)
RunApplication(deleteMode=True)
mainLoop = True
applicationIterator = RunApplication(deleteMode=True)
while mainLoop:
try: self.updateMainLoadingBar(next(applicationIterator))
except StopIteration: mainLoop = False

def clickAddSubjectsButton(self): # Add subjects to Google Calendar
fromDate, toDate = self.startDateEdit.text(), self.endDateEdit.text()
insertTimeRange(CONFIG_FILE, fromDate, toDate)
RunApplication()
mainLoop = True
applicationIterator = RunApplication()
while mainLoop:
try: self.updateMainLoadingBar(next(applicationIterator))
except StopIteration: mainLoop = False

def clickVerificationButton(self):
for i in range(checkEspaiAulaFileIntegrity(self.filePathText.text())):
self.progressBar.setValue(i+1)

def clickClearSubjectsButton(self): clearSubjectsPreferences(CONFIG_FILE)
def updateMainLoadingBar(self, toValue): self.mainProgressBar.setValue(toValue)

def runInformationWindow(self): print("Not implemented.")

Expand Down
4 changes: 4 additions & 0 deletions src/MainWindowNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def setupUi(self, MainWindowDesign):
self.transferButton.setObjectName("transferButton")
self.verticalLayout.addWidget(self.transferButton)
self.gridLayout_3.addWidget(self.endBox, 2, 0, 1, 1)
self.mainProgressBar = QtWidgets.QProgressBar(self.mainWindow)
self.mainProgressBar.setProperty("value", 0)
self.mainProgressBar.setObjectName("mainProgressBar")
self.gridLayout_3.addWidget(self.mainProgressBar, 3, 0, 1, 1)
MainWindowDesign.setCentralWidget(self.mainWindow)
self.menuBar = QtWidgets.QMenuBar(MainWindowDesign)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 594, 22))
Expand Down

0 comments on commit 93c35e3

Please sign in to comment.