<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
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. <br>
<br>
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. <br>
<br>
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. <br>
<br>
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. <br>
<br>
Sentinel_GUI is the main loop. Its constructor features the setting of
user variables for the GUI components, dialogs, sliders, etc. A snipet
is:<br>
<br>
=======start GUI=============<br>
class Sentuser_GUI:<br>
<br>
def Frame1( self, master,**argv):<br>
...<br>
self.gray_scale = True<br>
self.post_event_stack = False<br>
self.post_event_format = "Tiff 2"<br>
self.show_real_time = False<br>
# Site settings<br>
self.lat = 40.00<br>
self.long = 120.00<br>
=========end GUI===========<br>
For example, gray_scale relates to a button on the
DisplaySettingsDialog.<br>
<br>
DisplaySettings gets kicked off in the <b>body</b> of this class
("GUI"),
as:<br>
self.settingsMenu.add_command(label="Schedule, Site, and
Operation...", command=self.DisplaySettings)<br>
<br>
In DisplaySettings, we get into control variables that apparently
will be shared with DisplaySettingsDialogs. <br>
=========start OS===========<br>
def DisplaySettings(self):<br>
print "OSett self = ", self, "type =", type(self)
<<---debug code<br>
sdict = {} <<-------- local sdict<br>
sdict[ "ok" ] = False <<---- ok<br>
sdict[ "color" ] = 2<br>
if self.gray_scale:<br>
sdict[ "color"] = 1<br>
... more sdict ...<br>
dialog = DisplaySettingsDialog( self.master, sdict )<br>
print "dialog self = ", dialog, "type =", type(dialog)<br>
self.Focus()<br>
if not dialog.sdict["ok"]: <<----ok<br>
return<br>
if dialog.colorVar.get() == 1:<br>
self.gray_scale = True<br>
else:<br>
self.gray_scale = False<br>
..<br>
<br>
==========end OS==========<br>
<br>
A snipet of, DisplaySettingsDialog (OSD):<br>
<br>
===========start OSD========<br>
class DisplaySettingsDialog(tkSimpleDialog.Dialog):<br>
<br>
def __init__(self, parent, sdict):<br>
self.sdict = sdict <<-------<br>
print "Set OSDiag sdict"<br>
tkSimpleDialog.Dialog.__init__(self, parent)<br>
<br>
def <b>body</b>(self,master):<br>
self.title("Display Settings")<br>
<br>
print "body from OSDialog, self =", self, "type =", type(self)<br>
self.colorVar = IntVar()
<<--- control variables<br>
Radiobutton( master, text="Gray Scale",<br>
value=1, variable=self.colorVar).grid(row=0,
sticky=W)<br>
Radiobutton( master, text="Pseudo Color",<br>
value=2, variable=self.colorVar).grid(row=1,
sticky=W)<br>
self.colorVar.set( self.sdict["color"] )
<<------<br>
...<br>
Label( master, text="Start Time: ").grid(row=6, sticky=W)<br>
self.enableVar = StringVar()<br>
Entry(master, width=10,
textvariable=self.enableVar).grid(row=6, column=1)<br>
self.enableVar.set( "%s" % self.sdict["enable_time"] )<br>
<br>
return entry<br>
<br>
def <b>apply</b>(self):<br>
self.sdict["ok"] = True <<------ ok<br>
<br>
============end OS===============<br>
<br>
======= Skeletal List of Classes and def's=============<br>
class DisplaySettingsDialog(tkSimpleDialog.Dialog): <<-----<br>
def __init__(self, parent, sdict):<br>
def body(self,master):<br>
def apply(self):<br>
class BoxSettingsDialog(tkSimpleDialog.Dialog):<br>
def __init__(self, parent, sdict):<br>
def body(self,master):<br>
def apply(self):<br>
class SetDecoderDialog(tkSimpleDialog.Dialog):<br>
def __init__(self, parent, gui):<br>
def body(self,master):<br>
def apply(self):<br>
class Sentuser_GUI: <<-----<br>
def Frame1( self, master,**argv):<br>
def __init__(self, master):<br>
def Focus( self ):<br>
def LogMessage( self, msg ):<br>
def DestroyLogWindow(self,event=None):<br>
def ShowHistogram(self):<br>
def DisplaySettings(self): <font color="#3333ff">
<<-----</font><br>
...<br>
def SaveConfigFile(self): <br>
def PrintConfigData():<br>
def OpenConfigFile(self):<br>
... (~50 more def's at this level)<br>
==========end of skeletal==========<br>
<br>
<br>
============main loop=======<br>
def Process(): <<----- (with mainloop code)<br>
root = Tk()<br>
app = Sentuser_GUI(root)<br>
root.mainloop()<br>
===========end main loop=====<br>
<br>
<big><b>Screen image</b></big><br>
<br>
<img src="cid:part1.07030307.03070304@sbcglobal.net" alt=""><br>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html;" http-equiv="Content-Type">
<title>Signature.html</title>
<pre class="moz-signature" cols="76"> Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
<font color="#330099"> </font>
</pre>
<div style="margin-left: 40px;">
<div style="margin-left: 80px;"><b>The Richard Feynman Problem-Solving
Algorithm:</b><br>
<b> (1) write down the problem;</b><br>
<b> (2) think very hard;</b><br>
<b> (3) write down the answer.</b><b><b
style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace;"></span></b></b><br>
</div>
<b><b style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace;"></span></b></b></div>
<pre class="moz-signature" cols="76"><b><b
style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace; color: rgb(153, 51, 153);"></span></b></b><b
style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace; color: rgb(153, 51, 153);"></span></b><span
style="color: rgb(153, 51, 153);"></span><span
style="color: rgb(153, 51, 153);">
</span><span style="color: rgb(153, 51, 153);"></span><b
style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace;"></span></b><span
style="color: rgb(204, 51, 204);"></span> Web Page: <<a
class="moz-txt-link-abbreviated"
href="http://www.speckledwithstars.net/">www.speckledwithstars.net/</a>></pre>
</div>
</body>
</html>