FE 'tkGooie' Utilities

---

'SELECTORtools' group

---

tkDegreesMinSecConvertSelect

(an angle convert
and/or select utility)

(FE = Freedom Environment)

FE Home Page > FE Downloads Page > FE 'tkGooies' Description Page >

FE 'tkGooies' 'SELECTORtools' Page > This Page

INTRODUCTION to 'tkDegreesMinSecConvertSelect'

I have been reading various math and physics books (in 2015-2016), many of which deal with astronomy.

Occasionally, I see angles measured in degrees-minutes-seconds, and I sometimes wonder what the angle would be in decimal notation.

In 2013, I had written an 'tkAngleConvertSelect' utility for converting among 3 different ways of expressing an angle --- decimal-degrees, radians, and percents.

I decided that a nice little project would be to take that code as a basis for creating a Tk GUI for converting between decimal-degrees and degrees-minutes-seconds.

Like with the 'degrees-radians angle convert-select' utility, I would use Tk 'scale' widgets by which to select any of the 4 quantities --- decimal-degrees, integer-degrees, integer-minutes, and seconds.

Like with the 'degrees-radians angle convert-select' utility, I just needed to make sure that when any of the 4 'scale' variables changed, the other 3 variables were changed correspondingly.


THE GUI DESIGN

Following a coding pattern I started using around 2015, I laid out a 'text-sketch' of a proposed layout for the GUI.

In the below sketch of the GUI:

  SQUARE BRACKETS indicate a comment (not to be placed on the GUI).
  BRACES          indicate a Tk 'button' widget.
  A COLON         indicates that the text before the colon is on a 'label' widget.
  <----O---->     indicates a Tk 'scale' widget.
  UNDERSCORES     indicate a Tk 'entry' widget.
  CAPITAL-O       indicates a Tk 'radiobutton' widget.
  CAPITAL-X       indicates a Tk 'checkbutton' widget (if any).

The options available to the user are indicated by the following 'sketch' of the GUI:

 FRAMEnames
 VVVVVVVVVV
             ------------------------------------------------------------------------------------------
             tkDegreesMinSec - Converter/Selector
             [window title]
             ------------------------------------------------------------------------------------------

 .fRbuttons          {UseIt} {Cancel} {Help} Decimal-Degrees: 60.000  Degrees-Minutes-Seconds: 60 0 0

 .fRleft                                                      .fRright [the canvas is in this frame]

 .fRleft.fRsliders1  Decimal   0.000                360.000   |-------------------------------------|
                     Degrees:  <--------------O----------->   |                                     |
                                                              |   canvas to hold circle depicting   |
 .fRleft.fRsliders3  Integer   0                        360   |                                     |
                     Degrees:  <--------------O----------->   |   the current angle as a sector in  |
                                                              |                                     |
                     Integer   0                         60   |             the circle              |
                     Minutes:  <--------------O----------->   |                                     |
                                                              |                                     |
                     Integer   0                         60   |                                     |
                     Seconds:  <--------------O----------->   |-------------------------------------|

---

GUI components:

From the GUI 'sketch' above, it is seen that the GUI consists of about

   -  3 button widgets
   -  2 label widgets (followed by a couple of one-line text widgets)
   -  4 scale widgets
   -  1 canvas widget
   -  0 entry widgets
   -  0 radiobutton widgets
   -  0 checkbutton widgets
   -  0 listbox widgets


A SCREENSHOT

So I set to work converting the code of the degrees-radians converter-selector GUI to this proposed GUI, and I ended up with the GUI seen in the following image.

This image does not do justice to the immediacy of the changes. Whenever ONE of the 'sliders' is moved:

  • the other THREE sliders adjust accordingly

  • the angle depicted in the circle on the canvas is updated

  • the 2 text areas change to present the current angle in the two formats (decimal and degrees-minutes-seconds). The numbers in the two text areas are available for copy-paste into another window on the desktop, such as a text-editor window.


The 'Help' button on the GUI provides pretty complete and detailed help for using the GUI.


DESCRIPTION OF THE CODE

Below, I provide the Tk script code for this 'tkDegreesMinSec' convert-select utility.

I follow my usual 'canonical' structure for Tk code for this Tk script:



  0) Set general window & widget parms (win-name, win-position,
     win-color-scheme, fonts, widget-geometry-parms, win-size-control,
     text-array-for-labels-etc).

  1a) Define ALL frames (and sub-frames, if any).
  1b) Pack   ALL frames and sub-frames.

  2) Define & pack all widgets in the frames, frame by frame.
              Within each frame, define ALL the widgets.
              Then pack the widgets.

  3) Define keyboard and mouse/touchpad/touch-sensitive-screen action
     BINDINGS, if needed.

  4) Define PROCS, if needed.

  5) Additional GUI initialization (typically with one or more of
     the procs), if needed.


This Tk coding structure is discussed in more detail on the page A Canonical Structure for Tk Code --- and variations.

This structure makes it easy for me to find code sections --- while generating and testing a Tk script, and when looking for code snippets to include in other scripts (code re-use).

I call your attention to step-zero. One new thing that I have started doing around 2014 is using a text-array for text in labels, buttons, and other widgets in the GUI. This can make it easier for people to internationalize my scripts. I will be using a text-array like this in most of my scripts in the future.


Experimenting with the GUI

As in all my scripts that use the 'pack' geometry manager (which is all of my 100-plus scripts, so far), I provide the four main pack parameters --- '-side', '-anchor', '-fill', '-expand' --- on all of the 'pack' commands for the frames and widgets.

That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window.

In this particular GUI, like for the 'degrees-radians converter-selector' GUI on which it was based, I have chosen to make the window stay at the same size that it takes when it is initially 'packed'.

However, one could comment the statement

   wm resizable . 0 0

and activate the statement

   wm minsize . $minWinWidthPx $minWinHeightPx

and the statements that set the min-width and min-height values.

If you want to make the window resizable, you can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various frames and widgets --- to get the widget behavior that you want --- and adjust the calculations for drawing the circle and filled-angle, if necessary.

---

Additional experimentation: You might want to change the fonts used for the various GUI widgets. For example, you could change '-weight' from 'bold' to 'normal' --- or '-slant' from 'roman' to 'italic'. Or change font families.

In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing.

I use variables to set geometry parameters of widgets --- parameters such as border-widths and padding. And I have included the '-relief' parameter on the definitions of frames and widgets. Feel free to experiment with those 'appearance' parameters as well.


Some features in the code

There are plenty of comments in the code, to describe what most of the code-sections are doing.

You can look at the top of the PROCS section of the code to see a list of the procs used in this script, along with brief descriptions of how they are called and what they do.

Here is a quick view of how each of the procs are 'triggered'.

   'angle_update'         - called via button1-release bindings on the
                            4 scale widgets --- and
                            called in the 'Additional GUI Initialization'
                            section at the bottom of this script.

   'draw_circle'          - called in the 'Additional GUI Initialization'
                            section at the bottom of this script.

   'redraw_angle'         - called by the 'angle_update' proc

   'put_vars'             - called by the 'UseIt' button

   'popup_msg_var_scroll' - called by the 'Help' button


It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this.

Without the comments, potential young Tcler's might be tempted to return to their iPhones and iPads and iPods --- to watch videos of semi-nude people looking miserable (and getting on each other's nerves) trying to survive on the edge of an insect-infested jungle with essentially no initial shelter, tools, or conveniences.


THE CODE

Here is a link to CODE for the script 'tkDegreesMinSecConvertSelect.tk'.

With your web browser, you can 'right-click' on this link --- and in the menu that pops up, select an item like 'Save Link Target As ...' --- to save this file to your local computer.

Then you can rename the file to remove the '.txt' suffix. Make sure that you have execute permission set on the file --- in order to execute the script.


SOME POTENTIAL ENHANCEMENTS:

One enhancement that I have considered is to change the 'seconds' scale widget to allow for fractional seconds, instead of limiting 'seconds' to integer values.

Other than that possible enhancement, I do not have any plans for further enhancements for this GUI, but a 'ColorMe' button could be added to this GUI --- like I did for a font-selector GUI whose code is at a wiki.tcl.tk page titled "YAFSG - Yet Another Font Selector GUI" and in a 'tkPointerSettings' GUI whose code I contributed at the wiki.tcl.tk page titled "tkPointerSettings - a Tk GUI 'wrapper' for the 'xinput' command". (There are also pages on this site that present those two Tk utilities.)

With a 'ColorMe' button, the user could easily use a color selector, like the one whose code is available at A non-obfuscated color selector GUI, to change the color of this tkDegreesMinSec-Convert-Select GUI.

Instead of supplying a 'ColorMe' button to do that, I simply point out that the user can change the RGB values for the 'tk_setPalette' statement near the top of this code.


IN CONCLUSION

Once in a while, I see questions in forums like 'how can i make several scale widgets move in unison?'. Well, here is some code that answers that particular question --- in detail, with a full example --- not a 'snippet'.

I sometimes wonder how many lines of code it would have taken in C or C++ with a widgets-library like Qt or Gtk or wxWidgets to do something like getting scale widgets to move in unison.

But I don't wonder for long. Back to Tcl-Tk. Much, much simpler.

Bottom of the page for tkDegreesMinSecConvertSelect --- a utility in the FE 'tkGooies' system, in the 'SELECTORtools' group.

To return to a previously visited web page location, click on the
Back button of your web browser a sufficient number of times.
OR, use the History-list option of your web browser.
OR ...

< Go to Top of Page, above. >
< Go to FE 'tkGooies' 'SELECTORtools' Page >
< Go to FE 'tkGooies' Description page >
< Go to FE Home page. >

This FE web page was created 2016 Mar 11.
Page was changed 2016 Mar 28. (Added a comment to the Potential Enhancements section.)

If I ever post a copy of this code on the Tcler's Wiki site (wiki.tcl.tk) ---
as a backup and alternative to this page, I plan to put a link to that page here.