Welcome, guest | Sign In | My Account | Store | Cart

Before discovering http://quizlet.com/, the following program was developed for running custom quizzes to help with studying for college courses. The program is not very advanced, but it works reasonably well for what it was designed to do. If the program were developed further, it would need greater capabilities than it currently has and would require a secondary system for actually creating the quizzes (currently, they are hand-typed). Quiz Me could be a starting point for anyone who wishes to actually write a program such as this and inspire others to write much better programs than what this recipe currently offers.

The Pipe and _Method classes presented here are for providing optional thread support to the tkinter GUI library. Oftentimes, it can be inconvenient to play with threads and GUI libraries simultaneously, and most GUI libraries require GUI specific operations to be performed within a certain thread. The classes below are for wrapping the root of the application so that method calls can be executed at a later time within whatever thread they are supposed to be executed in. This program was used as a test platform of the concept though it did not see any of its expected use: threading is not used in this application.

Python, 34 lines
 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
#####################
# source/exe_queue.py
#####################

import queue

################################################################################

class Pipe:

    def __init__(self, obj):
        self.__obj = obj
        self.__queue = queue.Queue()

    def __getattr__(self, name):
        method = _Method(self.__queue, name)
        setattr(self, name, method)
        return method

    def update(self):
        while not self.__queue.empty():
            name, args, kwargs = self.__queue.get()
            getattr(self.__obj, name)(*args, **kwargs)

################################################################################

class _Method:

    def __init__(self, queue, name):
        self.__queue = queue
        self.__name = name

    def __call__(self, *args, **kwargs):
        self.__queue.put((self.__name, args, kwargs))