[Tutor] Shifts - first attempt at a GUI

mikalzet@libero.it mikalzet@libero.it
Sun, 7 Jul 2002 00:39:39 +0200 (CEST)


Well folks,

after quite a while away from the snake I've started fooling with it 
again, aiming at making (in time) a program which will earn me the 
lifelong gratitude of thousands of ER doctors out there besides getting 
things easier for me ...

This is my first shot at it, must say the Pmw are very interesting.
Under the signature you will find the code, comments welcome.
A few questions come to my mind ... I'm blurred by the hour of course
...

1) I see my final application having a button which, if pressed, creates 
the CreateScheduleTemplate window, would that be something like:

class MainApp:
	foo
	self.CreateSchema = Button(foo, ... , command = 
CreateScheduleTemplate() )
?

2) This way of doing it I have to insert shifts in the dictionary one by 
one; there should be a way of defining shifts for weekdays, saturdays and 
sundays and then automatically creating a dictionary entry for each single 
shift, any hints ? 

The idea of using a dictionary like this is that with a key
( e.g. surgical 06/07/2002 ) I obtain a list containing date and time of 
beginning and end of shift; this list can easily be enlarged by adding the 
name of the doctor who will cover it and become the data input of the 
final schedule printing function; the doctor to be added will be selected 
from a list of doctors which in some way will have to take into account a 
series of options (doc A doesn't work nights, B works parttime, C needs a 
day off for a congress, E has flower-arrangement classes on tuesday 
afternoons and so would rather not work then but will if really 
necessary and so forth). 

As I see it the dictionary will contain up to 15 keys per day, so a month 
of shifts requires 450 dictionary entries ... large enough to warrant a 
data base ? Or could pickling the data be enough ?

__
Michele Alzetta


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

#!/usr/bin/python

# Created in 2002/2003 ... (hopefully) 
# Michele Alzetta, mikalzet@libero.it
# an attempt at making a GUI program which will allow to create complex
# scheduling schemes for ER doctors - something like EPSCHED I imagine might be 
# (although I've never used it as it is far too expensive)

from Tkinter import *
import time
import Pmw

class CreateScheduleTemplate:
  
# Create the GUI interface which will eventually allow user to create the
# template for the shifts which must be covered in a schedule. 
# The shift template is being created as a dictionary, although of course it 
# will end up being pickled or saved in a file or in a database eventually

    def __init__(self, master):

        frame = Frame(master)
        frame.pack()

# Create an entry widget to allow giving each shift a name

        self._schematurni = {}
        self._InserisciNome = Pmw.EntryField(master,
                labelpos = 'w',
                label_text = 'Inserisci un nome univoco per questo turno:',
                validate = None,
                command = self.retrieve_schema)
        self._InserisciNome.pack()

# Create a date counter widget to select the shift date
        
        self._date = Pmw.Counter(master,
                labelpos = 'w',
                label_text = 'Date (4-digit year):',
                entryfield_value =
                        time.strftime('%d/%m/%Y', time.localtime()),
                entryfield_command = self.retrieve_schema,
                entryfield_validate = {'validator' : 'date', 'format' : 'dmy'},
                datatype = {'counter' : 'date', 'format' : 'dmy', 'yyyy' : 1})
        self._date.pack()

# Create two time counter widgets to select begin and end time for shift

        self._timebegin = Pmw.Counter(master,
                labelpos = 'w',
                label_text = 'Ora inizio:',
                entryfield_value =
                        time.strftime('%H:%M:%S', time.localtime()),
                entryfield_validate = {'validator' : 'time',
                        'min' : '00:00:00', 'max' : '23:59:59',
                        'minstrict' : 0, 'maxstrict' : 0},
                entryfield_command = self.retrieve_schema,
                datatype = {'counter' : 'time', 'time24' : 1},
                increment=60*60)
        self._timebegin.pack()

        self._timeend = Pmw.Counter(master,
                labelpos = 'w',
                label_text = 'Ora fine:',
                entryfield_value =
                        time.strftime('%H:%M:%S', time.localtime()),
                entryfield_validate = {'validator' : 'time',
                        'min' : '00:00:00', 'max' : '23:59:59',
                        'minstrict' : 0, 'maxstrict' : 0},
                entryfield_command = self.retrieve_schema,
                datatype = {'counter' : 'time', 'time24' : 1},
                increment=60*60)
        self._timeend.pack()

# Here I create two buttons: one to exit the program, one to insert the 
# selected data into the dictionary
# I also print the dictionary (for debugging purposes)

        self.get_schema = Button(frame, text="Inserisci", fg="red", command=self.retrieve_schema)
        self.get_schema.pack(side=LEFT)

        self.close_box = Button(frame, text="Quit", command='exit')
        self.close_box.pack(side=LEFT)

              
    def retrieve_schema(self):
        oraturno = [self._date.get(), self._timebegin.get(), self._timeend.get()]
        nometurno = self._InserisciNome.get() + ' ' + self._date.get()
        self._schematurni[nometurno] = oraturno
        print self._schematurni

if __name__ == '__main__':

    root = Tk()
    Pmw.initialise(root)
    app = CreateScheduleTemplate(root)
    root.mainloop()