SmartMirror’s Documentation¶
-
class
calendarapi.
CalendarApiWrapper
[source]¶ Google Calendar API wrapper for performing asynchronous calls.
-
call_calendar_api
(service)[source]¶ Starts asynchronous api call.
Only one request can be processed at the same time for each instance of CalendarApiWrapper. To obtain results get_upcoming_events() has to be called.
Parameters: service – googleapiclient discovery’s service object built for calendar v3 api with which the call will be made. Returns: 0 if api was successfully called or 1 if api call is already processing Raises: ValueError
– if impossible behaviour occurred.
-
get_upcoming_events
()[source]¶ Checks availability and returns api call results.
Returns: -1 if api’s function was not called, 0 if api call finished and returned results or 1 if api call is being processed. upcoming_events: list of upcoming events.
events_colours: dictionary containing calendar’s colours data.
-
-
calendarapi.
calendar_api_call
(input_queue, output_queue)[source]¶ Callback function calling calendar api for upcoming events.
Input should be added to the queue before this callback starts execution.
Parameters: - input_queue – queue for passing input. This function expects to get googleapiclient discovery’s service object from this queue.
- output_queue – queue for passing call’s results. Results are returned as a single 2 element tuple. First element is a list of upcoming calendar events, the second one is a dict containing calendar’s color definitions.
Raises: ValueError
– if no arguments were passed through input queue.
-
class
calendarauth.
CalendarAuthenticator
[source]¶ Wrapper for asynchronous authentication with OAuth 2.0.
CalendarAuthenticator uses multiprocessing module to handle asynchronous google calendar api authentication with readonly permissions. Authentication is started by calling start_authentication() and resulting credentials can be collected via get_credentials(). Only one authentication can be performed at the same time for each instance of CalendarAuthenticator. During authentication process web browser is opened on google log in page through which user has to authenticate and confirm that he’s giving this application permissions to access calendar information.
-
cancel_authentication
()[source]¶ Stops the authentication process.
This function stops data collector process. Even if process was not running this function will attempt to join it.
Returns: -1 if authentication process wasn’t running or 0 if authentication was ongoing and successfully stopped.
-
get_credentials
()[source]¶ Return credentials and according return code.
This function checks whether user completed authentication and returns credentials.
Returns: -1 if authentication process was not started, 0 if authentication was completed or 1 if authentication is still ongoing. credentials: OAuth 2.0 credentials required to call calendar api.
-
start_authentication
()[source]¶ Starts authentication process.
Only one authentication can be performed at the same time for each instance of CalendarAuthenticator. To obtain credentials get_credentials() has to be called.
Returns: 0 if authentication process was successfully started or 1 if authentication process was already running.
-
-
calendarauth.
get_credentials
(output_queue)[source]¶ Executes authentication flow.
This function executes OAuth 2.0 authentication flow for installed applications. Local server is started and web browser opens with google authentication page.
Parameters: output_queue – queue through which credentials will be returned.
-
class
calendarloginpage.
CalendarLoginPage
(master, controller)[source]¶ Menu page for logging into google calendar.
CalendarLoginPage inherits from tkinter’s frame page. It’s purpose is to provide end user with interface to authenticate and authorize google calendar access.
-
class
clock.
Clock
(master, controller)[source]¶ Displays time and date.
Clock class inherits from tkinter’s Frame class and abstract Plugin class.
-
edit_mode
()[source]¶ Switches edit_mode on/off.
When switching edit mode on this function first makes mouse cursor visible when on top of this module and makes background highlight visible by changing it’s color to yellow, then appropriate event handlers are bind to left mouse button click (<Button-1>) and mouse motion with left mouse button pressed (<B1-Motion>) for every component.
When switching edit mode off cursor is first hidden, highlight made invisible by changing it’s color to black, then mouse input event handlers are unbound from all components.
-
-
facerecognition.
face_recognition
(running_flag, recognized_face)[source]¶ Performs face detection and recognition.
This function is supposed to be invoked as a callback for separate process.
Parameters: - running_flag – multiprocessing.Event flag controlling the while loop. When set to false this function will exit the loop and clean up before finishing.
- recognized_face – multiprocessing.Value(ctypes.c_int) variable for storing id of recognized face. This variable is set to -1 if face was not detected, 0 if face was detected but not recognized or id if face was detected and recognized.
Raises: ValueError
– if either camera was not detected or cascade file was not found.
-
class
facerecognizer.
FaceRecognizer
[source]¶ Manages asynchronous face detection and recognition.
This class hides multiprocessing mechanism details from the outside world.
-
class
greeter.
Greeter
(master, controller)[source]¶ Greeter module class.
Greeter class inherits from tkinter’s Frame class and abstract Plugin class. This modules displays greetings message when face is detected and recognized.
-
edit_mode
()[source]¶ Switches edit_mode on/off.
When switching edit mode on this function first makes mouse cursor visible while hovering on top of this module and makes background highlight visible by changing it’s color to yellow, then appropriate event handlers are bind to left mouse button click (<Button-1>) and mouse motion with left mouse button pressed (<B1-Motion>) for every component.
When switching edit mode off cursor is first hidden, highlight made invisible by changing it’s color to black, then mouse input event handlers are unbound from all components.
-
Application menu.
Menu class inherits from tkinter’s Frame class. It acts as a controller and container for all options pages.
Brings frame to the top and sends it <<FrameShown>> event.
Parameters: frame_key – dictionary key of frame that we want to show. Frame’s key is it’s class’ name.
Menu’s ‘base’ page.
StartPage inherit’s from tkinter’s frame class. It acts as a container of buttons used to navigate to different menu pages.
-
class
mirrordisplay.
MirrorDisplay
(master, controller)[source]¶ Creates and manages all information displaying modules.
MirrorDisplay class inherits from tkinter’s Frame class. It is a geometry master and controller for all frames stored inside. Each frame stored here has a role of displaying information to user. Once this frame is displayed application can be closed with Escape button.
Every frame stored directly in MirrorDisplay should inherit from plugin abstract class thus implementing one specific public function: ‘edit_mode’. This function should enable user to change location of module using mouse input, concretely mouse motion with left mouse button pressed (<B1-Motion>). Yellow background highlight should be displayed around each frame in edit state.
-
class
plugin.
Plugin
[source]¶ Abstract class which frames stored in MirrorDisplay class should inherit from.
-
recognizertraining.
train_recognizer
(user_id)[source]¶ Loads training data from disk and trains face recognizer.
Parameters: user_id – integer to be used as a training label. This is the number that will be returned by recognizer. Raises: ValueError
– if yml file containing recognizer data was not found.
-
class
smartcalendar.
Calendar
(master, controller)[source]¶ Displays google calendar events when face is recognized.
This class inherits from tkinter’s Frame class and abstract Plugin class. Google Calendar API is used to source events. Calendar will be displayed only when known face is recognized and that person logged in to Google Calendar at startup.
-
edit_mode
()[source]¶ Switches edit_mode on/off.
When switching edit mode on this function first makes mouse cursor visible when on top of this module and makes background highlight visible by changing it’s color to yellow, then appropriate event handlers are bind to left mouse button click (<Button-1>) and mouse motion with left mouse button pressed (<B1-Motion>) for every component.
When switching edit mode off cursor is first hidden, highlight made invisible by changing it’s color to black, then mouse input event handlers are unbound from all components.
-
-
class
smartmirror.
SmartMirror
[source]¶ Main window of the application.
SmartMirror inherits from tkinter’s Tk class. It manages ‘main’ frames and provides public functions needed to control the application from within these frames. Once start_smartmirror() is called application has to be closed using Escape key.
-
class
trainingdata.
TrainingData
[source]¶ Asynchronously collects training data for face recognizer.
TrainingData uses multiprocessing module to asynchronously collect data meant for training of opencv’s face recognition algorithms. Mentioned data is in the form of grayscale pictures containing only facial region. Only one ‘collector’ can be run at the same time.
-
trainingdata.
collect_data
(running_flag)[source]¶ Collects data for face recognizer training.
This function uses haar cascade face detection algorithm to snap 30 grayscale photos of user’s face, cropped to contain only facial region and saves them to disk. Photos formatted this way are ready to be used to train opencv’s face recognition algorithms.
Parameters: running_flag – flag for stopping this function early. Function is running while this flag is set. Type multiprocessing.Event is assumed. Raises: ValueError
– if either camera was not detected or cascade file was not found.
-
class
trainrecognizerpage.
TrainRecognizerPage
(master, controller)[source]¶ Menu page with face recognition training interface.
TrainRecognizerPage inherits from tkinter’s frame page. It stores all widgets inside a grid geometry manager and implements functions bind to these widgets. It’s purpose is to provide end user with interface to collect training data and train face recognition module with his/hers face.
-
class
weather.
Weather
(master, controller)[source]¶ Weather module class.
Weather class inherits from tkinter’s Frame class and abstract Plugin class. This module displays weather conditions as an icon and current temperature in Fahrenheit or Celsius scale depending on user’s preference.
Ipinfo api is used for finding current location and weather underground api is used for polling weather information.
-
edit_mode
()[source]¶ Switches edit_mode on/off.
When switching edit mode on this function first makes mouse cursor visible when on top of this module and makes background highlight visible by changing it’s color to yellow, then appropriate event handlers are bind to left mouse button click (<Button-1>) and mouse motion with left mouse button pressed (<B1-Motion>) for every component.
When switching edit mode off cursor is first hidden, highlight made invisible by changing it’s color to black, then mouse input event handlers are unbound from all components.
-
-
class
weatherapi.
WeatherApiWrapper
[source]¶ Wunderground api wrapper for performing asynchronous requests.
WeatherApiWrapper uses multiprocessing module to handle asynchronous wunderground api requests. Request can be started by calling call_weather_api() and response converted to json file can be collected with get_weather(). Only one request can be processed at the same time for each instance of WeatherApiWrapper.
-
call_weather_api
(country, region)[source]¶ Starts asynchronous api request.
Only one request can be processed at the same time for each instance of WeatherApiWrapper. To obtain results get_weather() has to be called.
Parameters: - country – country of interest. Either abbreviation or full english name.
- region – region of interest e.g city/province.
Returns: 0 if weather api request was successfully made or 1 if api request is already processing.
Raises: ValueError
– If impossible behaviour occurred.
-
get_weather
()[source]¶ Return request results and according return code.
Returns: - returncode – -1 if no request was made with call_weather_api
- function, 0 if weather information was successfully returned or 1 if api request is still being processed.
- weather_json: json file containing weather information for
- requested region or None (see returncode = -1 or 1).
-
-
weatherapi.
weather_api_request
(input_queue, output_queue)[source]¶ Callback function performing weather information requests.
Parameters: - input_queue – queue for passing city and region arguments for api request. These arguments should be passed in one tuple.
- output_queue – queue for passing request results.
Raises: ValueError
– if no arguments were passed through the input queue.