Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Dialog programming: (I)what lists can be passed (II)How to put quotes

From   "James Hassell" <>
Subject   Re: st: Dialog programming: (I)what lists can be passed (II)How to put quotes
Date   Tue, 14 Nov 2006 12:13:11 -0600

David Elliott wrote:

>Thanks to James Hassell, I have made significant progress in my dialog
>programming.  However, I am not clear on what can and cannot be done
>in a "heavyweight i-action," it being very much a trial and error
>undertaking.  Once can change labels and hide/disable controls.  Using
>James's example above once can populate lists in the PREINIT stage of
>dialog creation.  What I would like to do is populate a second list
>following user selection of a variable.  That list would be populated
>with the results of a levelsof.  I have tried to extend James's
>example with a second ado, but I don't seem to be able to change the
>contents of a list class once the dialog box has been created.  Am I
>correct in thinking that once a dialog box has been initialized that
>the only changes that can be made are to the interaction with the
>controls themselves, not to the *contents* of the controls?
>I see a way around this by creating a new dialog box to create and do
>the picking of levels.  This would be similar in function to the ifin
>expression builder dialog.  Am I correct in assuming that this would
>be a viable alternative?  Are there any caveats?
>Many thanks.  Although I have thoroughly read the dialog and class
>sections, it is not always obvious how to use them to accomplish
>specific tasks.

Heavyweight i-action's can be used to do many things. Heavyweight means
that the dialog program calls out to Stata's ado engine to perform some
task. That task might be typical ado programming, class system programming
which interacts with a dialog box, or both. For your purposes you will need
an ado program that does both. All objects (controls or properties) that 
belong to a dialog have built-in member programs. These member programs
are documented in -help dialog_programming-. These member programs can be 
called in dialog programs or scripts (the typical way), or externally by 
through the class system using the fully qualified object name and member 
	.mydialog_dlg.myStringProperty.setstring "somestring"

Most dialog controls have the following member programs...
	hide, show, disable, enable, and setposition.

Some controls allow you to set their label and value using the 
setlabel and setvalue member programs respectively. Unfortunately there
is not a built-in member program for the COMBOBOX or LISTBOX controls which
would allow for managing its contents.  There are implementation details 
which are preventing us from providing such functionally at this time. 
However, all is not lost.  There is a utility that is part of Stata 9 that
will help David do just what he wants. dynamic_list_control.class is a 
helper routine for some of the -irf graph- commands that was built for 
managing LISTBOXes and COMBOXBOXes from ado code. I have written an 
example which I believe does what David has requested...

/////////////////////// BEGIN d1.dlg //////////////////////////
*!  VERSION 1.0.0  14nov2006


POSITION . . 400 300
OK ok1,	label("OK")
CANCEL	can1, label("Cancel")
SUBMIT	sub1, label("Submit")
RESET	res1

	create BOOLEAN isLoading
	/* Set true when dialog is loading to block events that
	 * might be triggered by the initial populating of the
	 * variable combobox.
	program initialize

	program getLevels

DIALOG main, label("Test COMBOBOX control as varlist")
  TEXT     tx_var	10	10	100	.,	///
	label("Variable:") right		
  COMBOBOX cb_var	+105	@	240	.,	///
  	dropdownlist contents(variables) 		///
  	onselchange(program getLevels)

  TEXT     tx_level	10	50	100	.,	///
	label("Levels:") right
  LISTBOX  lb_level	+105	@	100	.,	///

LIST variables
	// intentionally empty
	// this list will be populated by d1_work.ado

LIST levels
	// intentionally empty
	// this list will be populated by d1_work.ado

PROGRAM initialize
	put "d1_work Init"
	stata hidden

PROGRAM getLevels
	if main.cb_var & ! isLoading {
		put "d1_work GetLevels " main.cb_var
		stata hidden
/////////////////////// END d1.dlg //////////////////////////

////////////////// BEGIN d1_work.ado ////////////////////////
program d1_work
	version 9
	gettoken subcmd 0 : 0
	`subcmd' `0'

program Init
	syntax [varlist]

	unab varlist : `varlist'
	if "`varlist'" != "" {
	foreach v of local varlist {
		capture confirm numeric variable  `v'
		if ! _rc {
			.d1_dlg.variables.Arrpush "`v'"

program GetLevels
	syntax [varlist]
	quietly levelsof `varlist'
	local levels `r(levels)'
	capture {
		/* dynamic_list_control is a helper class
		 * for managing dynamic list conrols.
		.dlist = , 	///
			dialogname(d1) controlname(main.lb_level)
		.dlist.setList, newlist(`levels')
	capture classutil drop .dlist
/////////////////// END d1_work.ado /////////////////////////

-- James
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index