gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnumed-devel] If you are online - passing a string array to subrout


From: Horst Herb
Subject: Re: [Gnumed-devel] If you are online - passing a string array to subroutine
Date: Wed, 12 Jun 2002 21:23:58 +1000

On Wed, 12 Jun 2002 19:33, richard terry wrote:

> Now I need to genericize it (if that is a word). I want to be able to
> pass down to it an array of text "label1,label2...labeln", and then
> construct the grid sizer with n columns (instead of 6 here), and jsut
> create n number of wxStaticText labels and add the correct label to it.
> so I can use the routine for all the prompts in all sections.

Instead of passing an array, I would choose a dictionary for more 
flexibility (but you can pass an array in the same fashion):

class EditPromptsAllergies(wxPanel):
    def __init__(self,parent,id=-1, labels={}):
        # labels is now an empty dictionary by default
        wxPanel.__init__(self, parent, id ...)
        self.SetLabels(labels)
       self.sizer = wxGridSizer(6, 1, 2, 2)  # rows, cols, hgap, vgap
       ...
    def SetLabels(self, labels):
          lbl_date = wxStaticText(self,-1,labels["date"] ...
          lbl_something = wxStaticText(self, -1, labels["something"]
          ...

####### calling part here ###############

#create a dictionary with a few key:value pairs
labels = {"date":"01.02.2003", "name":"Willy Wonka"}
#add a key value pair
labels["something"] = "something else"
# remember that python is quite dynamic regarding data types!
labels["three"] = 3
labels[4] = "four"
labels["some array"] = [1,2,3,4,5]

#create a panel instance and pass the labels dictionary as parameter
AllergyPanel = EditPromptsAllergies(myparent, -1. labels)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]