Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[29a0f3]: inst / zenity_entry.m Maximize Restore History

Download this file

zenity_entry.m    120 lines (110 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
## Copyright (C) 2006 Sřren Hauberg <soren@hauberg.org>
## Copyright (C) 2010, 2012 Carnë Draug <carandraug+dev@gmail.com>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{entry}, @var{status}] =} zenity_entry (@var{text}, @var{parameter1}, @var{value1}, @dots{})
## Displays a text entry dialog using Zenity.
##
## The variable @var{text} sets the dialog text and is the only mandatory
## argument.
##
## @var{entry} is a string with the text from the entry field and @var{status}
## is a scalar with the exit code. @var{status} will have a value of @code{0} if
## @option{OK} is pressed; @code{1} if @option{Close} is pressed or the window
## functions are used to close it; or @code{5} if timeout has been reached.
##
## Note that unless @option{OK} is used to close the window, @var{entry} will be
## an empty string, despite whatever text was in the entry field.
##
## All @var{parameters} are optional, but if given, may require a corresponding
## @var{value}. All possible parameters are:
##
## @table @samp
## @item entry
## Sets the default text in the entry field. Requires a string as value.
##
## @item title
## Sets the title of the window. Requires a string as value.
##
## @item password
## Hides the text in the text entry field. No value is required.
##
## @item width
## Sets the width of the dialog window. Requires a scalar as value.
##
## @item height
## Sets the height of the dialog window. Requires a scalar as value.
##
## @item icon
## Sets the icon of the window. Requires a string as value with the file path to
## an image, or one of the four stock icons:
##
## @table @samp
## @item error
## @item info
## @item question
## @item warning
## @end table
##
## @item timeout
## Sets the time in seconds after which the dialog is closed. Requires a scalar
## as value.
## @end table
##
## @strong{Note:} ultimately, the availability of some parameters is dependent
## on the user's system preferences and zenity version.
##
## @seealso{input, menu, kbhit, zenity_message, zenity_file_selection}
## @end deftypefn
function [out, status] = zenity_entry(text, varargin)
## Update figures so they are show before the dialog. To not be shown at this
## step, turn them off with 'figure(N, "visible", "off")
## This is similar to the functions input and pause
drawnow;
if (nargin < 1)
error ("'text' argument is not optional")
elseif (!ischar(text))
error ("'text' argument must be a string")
endif
text = sprintf("--text=\"%s\"", text);
options = zenity_options ("entry", varargin);
pre_cmd = sprintf("%s ", ...
text, ...
options.entry, ...
options.title, ...
options.password, ...
options.icon, ...
options.width, ...
options.height, ...
options.timeout);
cmd = sprintf("zenity --entry %s", pre_cmd);
[status, output] = system(cmd);
## Exit code -1 = An unexpected error has occurred
## Exit code 0 = The user has pressed either OK or Close.
## Exit code 1 = The user has either pressed Cancel, or used the window
## functions to close the dialog
## Exit code 5 = The dialog has been closed because the timeout has been reached
if (status == 0)
if (output(end) == "\n")
output = output(1:end-1);
endif
out = output;
elseif (status == 1 || status == 5)
out = "";
else
error("An unexpected error occurred with exit code '%i' and output '%s'",...
status, output);
endif
endfunction