UI-Dialog

 view release on metacpan or  search on metacpan

lib/UI/Dialog/Backend/XDialog.pm  view on Meta::CPAN

  $self->{'test_mode_result'} = '';

	#: Dynamic path discovery...
	my $CFG_PATH = $cfg->{'PATH'};
	if ($CFG_PATH) {
		if (ref($CFG_PATH) eq "ARRAY") {
      $self->{'PATHS'} = $CFG_PATH;
    }
		elsif ($CFG_PATH =~ m!:!) {
      $self->{'PATHS'} = [ split(/:/,$CFG_PATH) ];
    }
		elsif (-d $CFG_PATH) {
      $self->{'PATHS'} = [ $CFG_PATH ];
    }
	}
  elsif ($ENV{'PATH'}) {
    $self->{'PATHS'} = [ split(/:/,$ENV{'PATH'}) ];
  }
	else {
    $self->{'PATHS'} = '';
  }

  $self->{'_opts'}->{'debug'} = $cfg->{'debug'} || undef();

	$self->{'_opts'}->{'literal'} = $cfg->{'literal'} || 0;

  $self->{'_opts'}->{'XDIALOG_HIGH_DIALOG_COMPAT'} = 1
    unless not $cfg->{'XDIALOG_HIGH_DIALOG_COMPAT'};

  $self->{'_opts'}->{'callbacks'} = $cfg->{'callbacks'} || undef();
  #  --wmclass <name>
  $self->{'_opts'}->{'wmclass'} = $cfg->{'wmclass'} || undef();
  #  --rc-file <gtkrc filename>
  $self->{'_opts'}->{'rcfile'} = $cfg->{'rcfile'} || undef();
  #  --backtitle <backtitle>
  $self->{'_opts'}->{'backtitle'} = $cfg->{'backtitle'} || undef();
  #  --title <title>
  $self->{'_opts'}->{'title'} = $cfg->{'title'} || undef();
  #  --allow-close | --no-close
  $self->{'_opts'}->{'allowclose'} = $cfg->{'allowclose'} || 0;
  $self->{'_opts'}->{'noclose'} = $cfg->{'noclose'} || 0;
  #  --screen-center | --under-mouse | --auto-placement
  $self->{'_opts'}->{'screencenter'} = $cfg->{'screencenter'} || 0;
  $self->{'_opts'}->{'undermouse'} = $cfg->{'undermouse'} || 0;
  $self->{'_opts'}->{'autoplacement'} = $cfg->{'autoplacement'} || 0;
  #  --center | --right | --left | --fill
  $self->{'_opts'}->{'center'} = $cfg->{'center'} || 0;
  $self->{'_opts'}->{'right'} = $cfg->{'right'} || 0;
  $self->{'_opts'}->{'left'} = $cfg->{'left'} || 0;
  $self->{'_opts'}->{'fill'} = $cfg->{'fill'} || 0;
  #  --no-wrap | --wrap
  $self->{'_opts'}->{'nowrap'} = $cfg->{'nowrap'} || 0;
  $self->{'_opts'}->{'wrap'} = $cfg->{'wrap'} || 0;
  #  --cr-wrap | --no-cr-wrap
  $self->{'_opts'}->{'crwrap'} = $cfg->{'crwrap'} || 0;
  $self->{'_opts'}->{'nocrwrap'} = $cfg->{'nocrwrap'} || 0;
  #  --buttons-style default|icon|text
  $self->{'_opts'}->{'buttonsstyle'} = $cfg->{'buttonsstyle'} || 'default';
  #  --fixed-font (tailbox, textbox, and editbox)
  $self->{'_opts'}->{'fixedfont'} = $cfg->{'fixedfont'} || 0;
  #  --editable (combobox)
  $self->{'_opts'}->{'editable'} = $cfg->{'editable'} || 0;
  #  --time-stamp | --date-stamp (logbox)
  $self->{'_opts'}->{'timestamp'} = $cfg->{'timestamp'} || 0;
  $self->{'_opts'}->{'datestamp'} = $cfg->{'datestamp'} || 0;
  #  --reverse (logbox)
  $self->{'_opts'}->{'reverse'} = $cfg->{'reverse'} || 0;
  #  --keep-colors (logbox)
  $self->{'_opts'}->{'keepcolors'} = $cfg->{'keepcolours'} || $cfg->{'keepcolors'} || 0;
  #  --interval <timeout> (input(s) boxes, combo box, range(s) boxes, spin(s) boxes, list boxes, menu box, treeview, calendar, timebox)
  $self->{'_opts'}->{'interval'} = $cfg->{'interval'} || 0;
  #  --no-tags (menubox, checklist and radiolist)
  $self->{'_opts'}->{'notags'} = $cfg->{'notags'} || 0;
  #  --item-help (menubox, checklist, radiolist, buildlist and treeview)
  $self->{'_opts'}->{'itemhelp'} = $cfg->{'itemhelp'} || 0;
  #  --default-item <tag> (menubox)
  $self->{'_opts'}->{'defaultitem'} = $cfg->{'defaultitem'} || undef();
  #  --icon <xpm filename> (textbox, editbox, tailbox, logbox, fselect and dselect)
  $self->{'_opts'}->{'icon'} = $cfg->{'icon'} || undef();
  #  --no-ok (tailbox and logbox)
  $self->{'_opts'}->{'nook'} = $cfg->{'nook'} || 0;
  #  --no-cancel (infobox, gauge and progress)
  $self->{'_opts'}->{'nocancel'} = $cfg->{'nocancel'} || 0;
  #  --no-buttons (textbox, tailbox, logbox, infobox  fselect and dselect)
  $self->{'_opts'}->{'nobuttons'} = $cfg->{'nobuttons'} || 0;
  #  --default-no !(wizard)
  $self->{'_opts'}->{'defaultno'} = $cfg->{'defaultno'} || 0;
  #  --wizard !(msgbox, infobox, gauge and progress)
  $self->{'_opts'}->{'wizard'} = $cfg->{'wizard'} || 0;
  #  --help <help> (infobox, gauge and progress)
  $self->{'_opts'}->{'help'} = $cfg->{'help'} || undef();
  #  --print <printer> (textbox, editbox and tailbox)
  $self->{'_opts'}->{'print'} = $cfg->{'print'} || undef();
  #  --check <label> !(infobox, gauge and progress)
  $self->{'_opts'}->{'check'} = $cfg->{'check'} || undef();
  #  --ok-label <label> !(wizard)
  $self->{'_opts'}->{'oklabel'} = $cfg->{'oklabel'} || undef();
  #  --cancel-label <label> !(wizard)
  $self->{'_opts'}->{'cancellabel'} = $cfg->{'cancellabel'} || undef();
  #  --beep | --beep-after (all)
  $self->{'_opts'}->{'beepbin'} = $cfg->{'beepbin'} || $self->_find_bin('beep') || '/usr/bin/beep';
  $self->{'_opts'}->{'beepbefore'} = $cfg->{'beepbefore'} || 0;
  $self->{'_opts'}->{'beepafter'} = $cfg->{'beepafter'} || 0;
  #  --begin <Yorg> <Xorg> (all)
  $self->{'_opts'}->{'begin'} = $cfg->{'begin'} || undef(); #: 'begin' => [$y,$x]
  #  --ignore-eof (infobox and gauge)
  $self->{'_opts'}->{'ignoreeof'} = $cfg->{'ignoreeof'} || 0;
  #  --smooth (tailbox and logbox)
  $self->{'_opts'}->{'smooth'} = $cfg->{'smooth'} || 0;

  #: \/we handle these internally\/
  #  --stderr | --stdout
  #  --separator <character> | --separate-output
  #: ^^we handle these internally^^

  $self->{'_opts'}->{'bin'} ||= $self->_find_bin('Xdialog');
  unless (-x $self->{'_opts'}->{'bin'}) {
		croak("the Xdialog binary could not be found.");
  }

  #: to determin upper limits use:

lib/UI/Dialog/Backend/XDialog.pm  view on Meta::CPAN


  $args->{'ok-label'} ||= $args->{'oklabel'} || 0;
  $fmt = $self->append_format_check
    ( $args, $fmt, "ok-label",
      '--ok-label '.shell_quote($args->{'ok-label'})
    );

  $args->{'cancel-label'} ||= $args->{'cancellabel'} || 0;
  $fmt = $self->append_format_check
    ( $args, $fmt, "cancel-label",
      '--cancel-label '.shell_quote($args->{'cancel-label'})
    );

  if (exists $args->{'begin'}) {
    my $begin = $args->{'begin'};
    if (ref($begin) eq "ARRAY") {
      $fmt = $self->append_format($fmt,'--begin '.$begin->[0].' '.$begin->[1]);
    }
  }

  return $fmt;
}

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: State Methods (override inherited)
#:

#: report on the state of the last widget.
sub state {
  my $self = shift();
  my $rv = $self->rv() || 0;
  $self->_debug((join(" | ",(caller())))." > state() > is: ".($rv||'NULL'),2);
  if ($rv == 1 or $rv == 129) {
		return("CANCEL");
  }
  elsif ($rv == 2) {
		return("HELP");
  }
  elsif ($rv == 3) {
		return("PREVIOUS");
  }
  elsif ($rv == 254) {
		return("ERROR");
  }
  elsif ($rv == 255) {
		return("ESC");
  }
  elsif (not $rv or $rv =~ /^null$/i) {
		return("OK");
  }
  else {
		return("UNKNOWN(".$rv.")");
  }
}


#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Public Methods
#:

#  --combobox    <text> <height> <width> <item1> ... <itemN>
#:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#: display a dropdown list that's editable
sub combobox {
  my $self = shift();
  my $caller = (caller(1))[3] || 'main';
  $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller;
  if ($_[0] && $_[0] eq 'caller') {
    shift(); $caller = shift();
  }
  my $args = $self->_pre($caller,@_);

  my $fmt = $self->prepare_format($args);
  $fmt = $self->append_format_base($args,$fmt);
  $fmt = $self->append_format($fmt,'--separate-output --combobox {{text}} {{height}} {{width}} {{list}}');
  my $command = $self->prepare_command
    ( $args, $fmt,
      text => $self->make_kvt($args,$args->{'text'}),
    );

  my ($rv,$selected) = $self->command_string($command);
  $self->_post($args);
  return($rv ? $selected : 0);
}


#  --rangebox    <text> <height> <width> <min value> <max value> [<default value>]
#:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#: display a slider bar with a preset range.
sub rangebox {
  my $self = shift();
  my $caller = (caller(1))[3] || 'main';
  $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller;
  if ($_[0] && $_[0] eq 'caller') {
    shift(); $caller = shift();
  }
  my $args = $self->_pre($caller,@_);

  my $fmt = $self->prepare_format($args);
  $fmt = $self->append_format_base($args,$fmt);
  $fmt = $self->append_format($fmt,'--rangebox {{text}} {{height}} {{width}} {{min}} {{max}} {{def}}');
  my $command = $self->prepare_command
    ( $args, $fmt,
      text => $self->make_kvt($args,$args->{'text'}),
      min => $self->make_kvl($args,($args->{'min'}||'0')),
      max => $self->make_kvl($args,($args->{'max'}||'100')),
      def => $self->make_kvl($args,($args->{'def'}||'0')),
    );

  my ($rv,$selected) = $self->command_string($command);
  $self->_post($args);
  return($rv ? $selected : 0);
}

#  --2rangesbox  <text> <height> <width> <label1> <min1> <max1> <def1> <label2> <min2> <max2> <def2>
#:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#: display two slider bars with preset ranges and labels
sub rangesbox2 {
  my $self = shift();
  my $caller = (caller(1))[3] || 'main';
  $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller;
  if ($_[0] && $_[0] eq 'caller') {
    shift(); $caller = shift();
  }
  my $args = $self->_pre($caller,@_);

  my $fmt = $self->prepare_format($args);
  $fmt = $self->append_format_base($args,$fmt);
  $fmt = $self->append_format($fmt,'--separate-output --2rangesbox {{text}} {{height}} {{width}}');
  $fmt = $self->append_format($fmt,'{{label1}} {{min1}} {{max1}} {{def1}}');
  $fmt = $self->append_format($fmt,'{{label2}} {{min2}} {{max2}} {{def2}}');
  my $command = $self->prepare_command
    ( $args, $fmt,
      text => $self->make_kvt($args,$args->{'text'}),
      label1 => $self->make_kvl($args,($args->{'label1'}||'')),



( run in 1.605 second using v1.01-cache-2.11-cpan-2398b32b56e )