Title: Signature.html
I'm looking at some Tkinter GUI code that I did not write. I've about completed work to add a read/write a configuration file of data of values the users have access to. I'm somewhat familiar with the techniques of OOP from prior use of many years ago with Java, C++, and XWindow. However, I have a question about some usage within the code, before I go further. The four or five  classes, functions of interest to me are shown below as snipets. A skeletal list of all defs and classes is included.  All of this code is taken to the program prior to my adding new functionality. The main loop code is thrown in for reference.

To go further into modifying one of the main dialogs, I probably need to understand how sdict (set dictionary??), a dictionary, which contains the names of configuration variables,  is used here.  Its use looks related to the Sentinel_GUI class, which  initially  sets the GUI global values. For example,  self.gray_scale = True, holds the current state of two buttons that give a choice between color and gray for an image that is displayed. I have something of a grasp about the use of control variables used here, but they may be wrapped up in sdict usage. Note the sdict creation in DisplaySettings vs DisplaySettingsDialog. As a side interest, the code uses sdict["ok"] (True/False). I think this entry has something to do with whether any variable in the dialog has changed when the user clicks OK. For kicks, I'm throwing in an image of the dialog, which possibly may not get posted with this message, if not denied. See bottom.

The question here is how is sdict being used here in terms of its need within the GUI?  Probably if I had written the program from scratch, I would have made all these variables global to Sentinel_GUI.

Here's a list of relevant  classes and def's below (=Classes and def's=) in the order they appear in the py code, with relevant items marked by <<-----. Note the Process code at the end. Sentinel_GUI, Display SettingsDialog, DisplaySettings and SaveConfigFile are the key players. 

Sentinel_GUI is the main loop. Its constructor features the setting of user variables for the GUI components, dialogs, sliders, etc. A snipet is:

=======start GUI=============
class Sentuser_GUI:

    def Frame1( self, master,**argv):
        ...
        self.gray_scale = True
        self.post_event_stack = False
        self.post_event_format = "Tiff 2"
        self.show_real_time = False
        # Site settings
        self.lat = 40.00
        self.long = 120.00
=========end GUI===========
For example, gray_scale relates to a button on the DisplaySettingsDialog.

DisplaySettings gets kicked off in the body of this class ("GUI"), as:
        self.settingsMenu.add_command(label="Schedule, Site, and Operation...", command=self.DisplaySettings)

In DisplaySettings, we get into control variables that apparently will be shared with DisplaySettingsDialogs.
=========start OS===========
    def DisplaySettings(self):
        print "OSett self = ", self, "type =", type(self) <<---debug code
        sdict = {}                       <<-------- local sdict
        sdict[ "ok" ] = False            <<---- ok
        sdict[ "color" ] = 2
        if self.gray_scale:
            sdict[ "color"] = 1
... more sdict ...
        dialog = DisplaySettingsDialog( self.master, sdict )
        print "dialog self = ", dialog, "type =", type(dialog)
        self.Focus()
        if not dialog.sdict["ok"]:              <<----ok
            return
        if dialog.colorVar.get() == 1:
            self.gray_scale = True
        else:
            self.gray_scale = False
            ..

==========end OS==========

A snipet of, DisplaySettingsDialog (OSD):

===========start OSD========
class DisplaySettingsDialog(tkSimpleDialog.Dialog):

    def __init__(self, parent, sdict):
        self.sdict = sdict               <<-------
        print "Set OSDiag sdict"
        tkSimpleDialog.Dialog.__init__(self, parent)
       
    def body(self,master):
        self.title("Display Settings")

        print "body from OSDialog, self =", self, "type =", type(self)
        self.colorVar = IntVar()                                <<--- control variables
        Radiobutton( master, text="Gray Scale",
                     value=1, variable=self.colorVar).grid(row=0, sticky=W)
        Radiobutton( master, text="Pseudo Color",
                     value=2, variable=self.colorVar).grid(row=1, sticky=W)
        self.colorVar.set( self.sdict["color"] )            <<------
       ...
        Label( master, text="Start Time: ").grid(row=6, sticky=W)
        self.enableVar = StringVar()
        Entry(master, width=10, textvariable=self.enableVar).grid(row=6, column=1)
        self.enableVar.set( "%s" % self.sdict["enable_time"] )

        return entry

    def apply(self):
        self.sdict["ok"] = True       <<------ ok

============end OS===============

======= Skeletal List of Classes and def's=============
class DisplaySettingsDialog(tkSimpleDialog.Dialog): <<-----
    def __init__(self, parent, sdict):
    def body(self,master):
    def apply(self):
class BoxSettingsDialog(tkSimpleDialog.Dialog):
    def __init__(self, parent, sdict):
    def body(self,master):
    def apply(self):
class SetDecoderDialog(tkSimpleDialog.Dialog):
    def __init__(self, parent, gui):
    def body(self,master):
    def apply(self):
class Sentuser_GUI: <<-----
    def Frame1( self, master,**argv):
    def __init__(self, master):
    def Focus( self ):
    def LogMessage( self, msg ):
    def DestroyLogWindow(self,event=None):
    def ShowHistogram(self):
    def DisplaySettings(self):     <<-----
...
    def SaveConfigFile(self):
        def PrintConfigData():
    def OpenConfigFile(self):
    ... (~50 more def's at this level)
==========end of skeletal==========


============main loop=======
def Process():  <<----- (with mainloop code)
    root = Tk()
    app = Sentuser_GUI(root)
    root.mainloop()
===========end main loop=====

Screen image



--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
            
The Richard Feynman Problem-Solving Algorithm:
  (1) write down the problem;
  (2) think very hard;
  (3) write down the answer.

                    Web Page: <www.speckledwithstars.net/>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to