rename globals to globalVars

to prevent to redifine an builtin function
This commit is contained in:
Bastian Schroll 2016-10-03 11:56:27 +02:00
parent e8e870849d
commit f8fcda94b6
30 changed files with 115 additions and 115 deletions

View file

@ -36,7 +36,7 @@ import json # for data
from threading import Thread
import pygame
import globals
import globalData
try:
#

View file

@ -14,27 +14,27 @@ alarmMonitor - displayServices
#
def autoTurnOffDisplay():
"""
Asynchronous function to turn of the display backlight
Asynchronous function to turn of the display backlight
@requires: globals.showDisplay - status of backlight
@requires: globals.enableDisplayUntil - given timestamp to turn off backlight
@requires: globals.running - service runs as long as this is True
In case of an exception the function set globals.abort to True.
This will terminate the main program.
@return: nothing
@exception: SystemExit exception in case of an error
"""
import sys
import time
import logging
import ConfigParser
import globals
import globalData
logging.debug("autoTurnOffDisplay-thread started")
try:
# Running will be set to False if main program is shutting down
while globals.running == True:
@ -59,12 +59,12 @@ def autoTurnOffDisplay():
#
# Only works as an asynchronous thread
# will call "exit(0)" when function is finished
#
#
def eventHandler():
"""
Asynchronous function to handle pygames events
in particular the touchscreen events
@requires: globals.showDisplay - status of backlight
@requires: globals.enableDisplayUntil - timestamp to turn off backlight
@requires: globals.running - service runs as long as this is True
@ -72,7 +72,7 @@ def eventHandler():
In case of an exception the function set globals.abort to True.
This will terminate the main program.
@return: nothing
@exception: SystemExit exception in case of an error
"""
@ -81,10 +81,10 @@ def eventHandler():
import logging
import ConfigParser
import pygame
import globals
import globalData
logging.debug("eventHandler-thread started")
try:
clock = pygame.time.Clock()
@ -93,13 +93,13 @@ def eventHandler():
# This limits the while loop to a max of 2 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(2)
# current time for this loop:
curtime = int(time.time())
for event in pygame.event.get():
# event-handler for QUIT
if event.type == pygame.QUIT:
if event.type == pygame.QUIT:
globals.running = False
# if touchscreen pressed
@ -109,7 +109,7 @@ def eventHandler():
# touching the screen will stop alarmSound in every case
pygame.mixer.stop()
# touching the dark display will turn it on for n sec
if globals.showDisplay == False:
logging.info("turn ON display")
@ -136,7 +136,7 @@ def eventHandler():
globals.navigation = "alarmPage"
## end if showDisplay
## end if event MOUSEBUTTONDOWN
## end for event
## end for event
except:
logging.error("unknown error in eventHandler-thread")
logging.debug("unknown error in eventHandler-thread", exc_info=True)
@ -146,8 +146,8 @@ def eventHandler():
finally:
logging.debug("exit eventHandler-thread")
exit(0)
#
# Only works as an asynchronous thread
# will call "exit(0)" when function is finished
@ -155,21 +155,21 @@ def eventHandler():
def displayPainter():
"""
Asynchronous function to build the display content
@requires: globals.showDisplay - status of backlight
@requires: globals.enableDisplayUntil - given timestamp when backlight will turned off
@requires: globals.running - service runs as long as this is True
@requires: globals.data - data of the last alarm
@requires: globals.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs)
@requires: globals.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs)
@requires: configuration has to be set in the config.ini
In case of an exception the function set globals.abort to True.
This will terminate the main program.
@return: nothing
@exception: SystemExit exception in case of an error
"""
import sys
import time
import logging
@ -178,10 +178,10 @@ def displayPainter():
import pygame
from wrapline import wrapline
from roundrects import round_rect
import globals
import globalData
logging.debug("displayPainter-thread called")
try:
# use GPIO pin numbering convention
GPIO.setmode(GPIO.BCM)
@ -197,41 +197,41 @@ def displayPainter():
# disable mouse cursor
pygame.mouse.set_visible(False)
#define fonts
fontHeader = pygame.font.Font(None, 30)
fontHeader.set_bold(True)
fontHeader.set_underline(True)
fontTime = pygame.font.Font(None, 15)
fontRIC = pygame.font.Font(None, 30)
fontRIC.set_bold(True)
fontMsg = pygame.font.Font(None, 20)
fontHistory = pygame.font.Font(None, 15)
fontStatus = pygame.font.Font(None, 20)
fontStatus.set_bold(True)
fontStatusContent = pygame.font.Font(None, 20)
fontButton = pygame.font.Font(None, 20)
clock = pygame.time.Clock()
# Build Lists out of config-entries
functionCharTestAlarm = [x.strip() for x in globals.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
logging.debug("displayPainter-thread started")
# Running will be set to False if main program is shutting down
while globals.running == True:
# This limits the while loop to a max of 2 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(2)
# current time for this loop:
curtime = int(time.time())
if globals.showDisplay == True:
# Enable LCD display
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.HIGH)
@ -246,7 +246,7 @@ def displayPainter():
(width, height) = fontHeader.size("Alarm-Monitor")
x = (int(globals.config.getint("Display","displayWidth")) - width)/2
screen.blit(header, (x, 20))
# show time of last alarm
if globals.lastAlarm > 0:
try:
@ -270,7 +270,7 @@ def displayPainter():
logging.debug("unknown error in lastAlarm", exc_info=True)
pass
## end if globals.lastAlarm > 0
# show remaining time before display will be turned off:
restZeit = globals.enableDisplayUntil - curtime +1
zeit = fontTime.render(str(restZeit), 1, pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")))
@ -286,9 +286,9 @@ def displayPainter():
y = 50
for data in reversed(globals.alarmHistory):
# Layout:
# Date Description
# Date Description
# Time Msg
# Prepare date/time block
dateString = time.strftime("%d.%m.%y", time.localtime(data['timestamp']))
timeString = time.strftime("%H:%M:%S", time.localtime(data['timestamp']))
@ -297,7 +297,7 @@ def displayPainter():
else:
(shifting, height) = fontHistory.size(timeString)
shifting += 5
# get colour
if data['functionChar'] in functionCharTestAlarm:
colour = globals.config.get("AlarmMonitor","colourYellow")
@ -317,7 +317,7 @@ def displayPainter():
y += height
except KeyError:
pass
# Paint Msg
try:
textLines = wrapline(data['msg'].replace("*", " * "), fontHistory, (globals.config.getint("Display","displayWidth") - shifting - 40))
@ -327,16 +327,16 @@ def displayPainter():
y += height
except KeyError:
pass
# line spacing for next dataset
y += 2
## end for globals.alarmHistory
except KeyError:
pass
## end if globals.navigation == "historyPage"
elif globals.navigation == "statusPage":
(width, height) = fontStatusContent.size("Anzahl Test-Alarme:")
y = 70
@ -347,7 +347,7 @@ def displayPainter():
screen.blit(title, (20, y))
screen.blit(content, (20 +x, y))
y += height + 10
# Last Alarm
title = fontStatusContent.render("Letzte Nachricht:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
if globals.lastAlarm > 0:
@ -371,19 +371,19 @@ def displayPainter():
screen.blit(title, (20, y))
screen.blit(content, (20 +x, y))
y += height + 10
# Number of DAU-Msgs
title = fontStatusContent.render("Anzahl DAU-Tests:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
content = fontStatusContent.render(str(globals.countKeepAlive), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
screen.blit(title, (20, y))
screen.blit(content, (20 +x, y))
y += height + 10
## end if globals.navigation == "statusPage"
else:
y = 50
# Paint Date/Time
try:
dateTimeString = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.data['timestamp']))
@ -394,7 +394,7 @@ def displayPainter():
y += height + 10
except KeyError:
pass
# Paint Description
try:
textLines = wrapline(globals.data['description'], fontRIC, (globals.config.getint("Display","displayWidth") - 40))
@ -405,7 +405,7 @@ def displayPainter():
y += height + 5
except KeyError:
pass
# Paint Msg
try:
y += 10
@ -418,19 +418,19 @@ def displayPainter():
except KeyError:
pass
## end if default navigation
# paint navigation buttons
buttonWidth = 80
buttonHeight = 25
buttonY = globals.config.getint("Display","displayHeight") - buttonHeight - 2
round_rect(screen, ( 20, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
buttonText = fontButton.render("Verlauf", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
(width, height) = fontButton.size("Verlauf")
textX = 20 + (buttonWidth - width)/2
textY = buttonY + (buttonHeight - height)/2
screen.blit(buttonText, (textX, textY))
round_rect(screen, (120, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
buttonText = fontButton.render("Status", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
(width, height) = fontButton.size("Status")
@ -444,12 +444,12 @@ def displayPainter():
textX = 220 + (buttonWidth - width)/2
textY = buttonY + (buttonHeight - height)/2
screen.blit(buttonText, (textX, textY))
## end if globals.showDisplay == True
else:
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
# Update display...
pygame.display.update()
## end while globals.running == True
@ -465,4 +465,4 @@ def displayPainter():
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
GPIO.cleanup()
pygame.quit()
exit(0)
exit(0)

View file

@ -1,35 +1,35 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
# configparser (Configparser)
config = 0
# control-params (Boolean)
running = True
showDisplay = False
abort = False
# color of display-boarder
screenBackground = ""
# navigation = ""
navigation = "alarmPage"
# enable display until (Timestamp)
enableDisplayUntil = 0
# data-structure (Dict)
data = {}
# last alarm shown (Timestamp)
lastAlarm = 0
# alarm history (List)
alarmHistory = []
# statusPage
startTime = 0
countAlarm = 0
countTestAlarm = 0
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
# configparser (Configparser)
config = 0
# control-params (Boolean)
running = True
showDisplay = False
abort = False
# color of display-boarder
screenBackground = ""
# navigation = ""
navigation = "alarmPage"
# enable display until (Timestamp)
enableDisplayUntil = 0
# data-structure (Dict)
data = {}
# last alarm shown (Timestamp)
lastAlarm = 0
# alarm history (List)
alarmHistory = []
# statusPage
startTime = 0
countAlarm = 0
countTestAlarm = 0
countKeepAlive = 0