Logo Search packages:      
Sourcecode: pythoncard version File versions  Download package

def customDialogs::PreferencesDialog::buildPrefsResource (   self,
  title,
  preferences 
)

This builds a string containing a resource description as you find in a .rsrc files

Definition at line 287 of file customDialogs.py.

00287                                                     :
        """This builds a string containing a resource description as you find in a .rsrc files"""
        
        location = 15
        height = 80
        prefsResString = ""

        # dynamically build each of the preference choices.
        for preference in preferences:
            escapedDefaultPref = preference[3]
            if preference[4] != 2 and preference[4] != 6 and preference[4] != 7:
                escapedDefaultPref = escapedDefaultPref.replace("'", "\\'")
            
            prefsResString = prefsResString + \
                             "{'type':'StaticText', 'name':'lab" + preference[0] + "', " + \
                             "'position':(45, %d), "  % (location) + \
                             "'text':'" + preference[1].replace("'", "\\'") + "'}," + \
                             "{'type':'Button', 'name':'btn" + preference[0] + "', " + \
                             "'position':(15, %d), 'size':(18,-1),"  % (location-3) + \
                             "'label':'?','command':'printHelpString'},"

            # prefernce needs a text box for normal string.
            if preference[4] == 1:    # 1
                prefsResString = prefsResString + \
                                 "{'type':'TextField', 'name':'" + preference[0] + "', " + \
                                 "'size':(200,-1), 'position':(220, %d), "  % (location-3) + \
                                 "'text':'" + escapedDefaultPref + "'},"

            # text box, but for a number
            elif preference[4] == 2 or preference[4] == 6:  # was 4
                prefsResString = prefsResString + \
                                 "{'type':'TextField', 'name':'" + preference[0] + "', " + \
                                 "'size':(200,-1), 'position':(220, %d), "  % (location-3) + \
                                 "'text':'%s'}," % escapedDefaultPref
            # password field
            elif preference[4] == 3:  # 3
                prefsResString = prefsResString + \
                                 "{'type':'PasswordField', 'name':'" + preference[0] + "', " + \
                                 "'size':(200,-1), 'position':(220, %d), "  % (location-3) + \
                                 "'text':'" + preference[3] + "'},"

            # "Yes"/"No" choice box
            elif preference[4] == 4:  # was 2  - I changed the order so it made more sense.
                prefsResString = prefsResString + \
                                 "{'type':'Choice', 'name':'" + preference[0] + "', " + \
                                 "'size':(80,-1), 'position':(220, %d), "  % (location-3) + \
                                 "'items':['Yes','No'],'stringSelection':'" + escapedDefaultPref + "'},"
                
            # Custom choice box
            elif preference[4] == 5:  #
                prefsResString = prefsResString + \
                                 "{'type':'Choice', 'name':'" + preference[0] + "', " + \
                                 "'size':(80,-1), 'position':(220, %d), "  % (location-3) + \
                                 "'items':["
                for item in preference[5]:
                    prefsResString = prefsResString + "'%s'," % item
                prefsResString = prefsResString + "], 'stringSelection':'" + escapedDefaultPref + "'},"

            # Font preference
            elif preference[4] == 7:  
                prefsResString = prefsResString + \
                                 "{'type':'Button', 'name':'" + preference[0] + "', " + \
                                 "'size':(60,-1), 'label':'Choose','position':(220, %d), "  % (location-3) + \
                                 "'command':'fontChoose'},"
                
                
            location = location + 35
            height = height + 35
        
        
        # construct the resource string.
        dlgRSRC = "{'type':'CustomDialog','name':'dlgPrefs'," + \
                  " 'title':'" + title + "','position':(100,50),'size':(440, %d),\n\n'components': [" % height
        
        dlgRSRC = dlgRSRC + prefsResString

        dlgRSRC = dlgRSRC + \
                  "{'type':'Button', 'name':'btnOK', 'position':(15, %d), "  % (height - 55) + \
                  "'label':'OK', 'id':5100, 'default':1, 'toolTip':'Update Preferences'}," + \
                  "{'type':'Button', 'name':'btnCancel', 'position':(115, %d)," % (height - 55) + \
                  "'label':'Cancel', 'id':5101, 'toolTip':'Discard Preferences Changes' } " + \
                  " ] } "

        # eval the resource string, pass it to Resource() and return it.
        return resource.Resource( eval(dlgRSRC) )
    

    def on_fontChoose_command(self, event):


Generated by  Doxygen 1.6.0   Back to index