1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/desktop/__init__.py Mon Dec 03 00:37:15 2007 +0000
1.3 @@ -0,0 +1,276 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Simple desktop integration for Python. This module provides desktop environment
1.8 +detection and resource opening support for a selection of common and
1.9 +standardised desktop environments.
1.10 +
1.11 +Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.12 +
1.13 +This library is free software; you can redistribute it and/or
1.14 +modify it under the terms of the GNU Lesser General Public
1.15 +License as published by the Free Software Foundation; either
1.16 +version 2.1 of the License, or (at your option) any later version.
1.17 +
1.18 +This library is distributed in the hope that it will be useful,
1.19 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.21 +Lesser General Public License for more details.
1.22 +
1.23 +You should have received a copy of the GNU Lesser General Public
1.24 +License along with this library; if not, write to the Free Software
1.25 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.26 +
1.27 +--------
1.28 +
1.29 +Desktop Detection
1.30 +-----------------
1.31 +
1.32 +To detect a specific desktop environment, use the get_desktop function.
1.33 +To detect whether the desktop environment is standardised (according to the
1.34 +proposed DESKTOP_LAUNCH standard), use the is_standard function.
1.35 +
1.36 +Opening URLs
1.37 +------------
1.38 +
1.39 +To open a URL in the current desktop environment, relying on the automatic
1.40 +detection of that environment, use the desktop.open function as follows:
1.41 +
1.42 +desktop.open("http://www.python.org")
1.43 +
1.44 +To override the detected desktop, specify the desktop parameter to the open
1.45 +function as follows:
1.46 +
1.47 +desktop.open("http://www.python.org", "KDE") # Insists on KDE
1.48 +desktop.open("http://www.python.org", "GNOME") # Insists on GNOME
1.49 +
1.50 +Without overriding using the desktop parameter, the open function will attempt
1.51 +to use the "standard" desktop opening mechanism which is controlled by the
1.52 +DESKTOP_LAUNCH environment variable as described below.
1.53 +
1.54 +The DESKTOP_LAUNCH Environment Variable
1.55 +---------------------------------------
1.56 +
1.57 +The DESKTOP_LAUNCH environment variable must be shell-quoted where appropriate,
1.58 +as shown in some of the following examples:
1.59 +
1.60 +DESKTOP_LAUNCH="kdialog --msgbox" Should present any opened URLs in
1.61 + their entirety in a KDE message box.
1.62 + (Command "kdialog" plus parameter.)
1.63 +DESKTOP_LAUNCH="my\ opener" Should run the "my opener" program to
1.64 + open URLs.
1.65 + (Command "my opener", no parameters.)
1.66 +DESKTOP_LAUNCH="my\ opener --url" Should run the "my opener" program to
1.67 + open URLs.
1.68 + (Command "my opener" plus parameter.)
1.69 +
1.70 +Details of the DESKTOP_LAUNCH environment variable convention can be found here:
1.71 +http://lists.freedesktop.org/archives/xdg/2004-August/004489.html
1.72 +"""
1.73 +
1.74 +__version__ = "0.3"
1.75 +
1.76 +import os
1.77 +import sys
1.78 +
1.79 +# Provide suitable process creation functions.
1.80 +
1.81 +try:
1.82 + import subprocess
1.83 + def _run(cmd, shell, wait):
1.84 + opener = subprocess.Popen(cmd, shell=shell)
1.85 + if wait: opener.wait()
1.86 + return opener.pid
1.87 +
1.88 + def _readfrom(cmd, shell):
1.89 + opener = subprocess.Popen(cmd, shell=shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
1.90 + opener.stdin.close()
1.91 + return opener.stdout.read()
1.92 +
1.93 + def _status(cmd, shell):
1.94 + opener = subprocess.Popen(cmd, shell=shell)
1.95 + opener.wait()
1.96 + return opener.returncode == 0
1.97 +
1.98 +except ImportError:
1.99 + import popen2
1.100 + def _run(cmd, shell, wait):
1.101 + opener = popen2.Popen3(cmd)
1.102 + if wait: opener.wait()
1.103 + return opener.pid
1.104 +
1.105 + def _readfrom(cmd, shell):
1.106 + opener = popen2.Popen3(cmd)
1.107 + opener.tochild.close()
1.108 + opener.childerr.close()
1.109 + return opener.fromchild.read()
1.110 +
1.111 + def _status(cmd, shell):
1.112 + opener = popen2.Popen3(cmd)
1.113 + opener.wait()
1.114 + return opener.poll() == 0
1.115 +
1.116 +import commands
1.117 +
1.118 +# Private functions.
1.119 +
1.120 +def _get_x11_vars():
1.121 +
1.122 + "Return suitable environment definitions for X11."
1.123 +
1.124 + if not os.environ.get("DISPLAY", "").strip():
1.125 + return "DISPLAY=:0.0 "
1.126 + else:
1.127 + return ""
1.128 +
1.129 +def _is_xfce():
1.130 +
1.131 + "Return whether XFCE is in use."
1.132 +
1.133 + # XFCE detection involves testing the output of a program.
1.134 +
1.135 + try:
1.136 + return _readfrom(_get_x11_vars() + "xprop -root _DT_SAVE_MODE", shell=1).strip().endswith(' = "xfce4"')
1.137 + except OSError:
1.138 + return 0
1.139 +
1.140 +def _is_x11():
1.141 +
1.142 + "Return whether the X Window System is in use."
1.143 +
1.144 + return os.environ.has_key("DISPLAY")
1.145 +
1.146 +# Introspection functions.
1.147 +
1.148 +def get_desktop():
1.149 +
1.150 + """
1.151 + Detect the current desktop environment, returning the name of the
1.152 + environment. If no environment could be detected, None is returned.
1.153 + """
1.154 +
1.155 + if os.environ.has_key("KDE_FULL_SESSION") or \
1.156 + os.environ.has_key("KDE_MULTIHEAD"):
1.157 + return "KDE"
1.158 + elif os.environ.has_key("GNOME_DESKTOP_SESSION_ID") or \
1.159 + os.environ.has_key("GNOME_KEYRING_SOCKET"):
1.160 + return "GNOME"
1.161 + elif sys.platform == "darwin":
1.162 + return "Mac OS X"
1.163 + elif hasattr(os, "startfile"):
1.164 + return "Windows"
1.165 + elif _is_xfce():
1.166 + return "XFCE"
1.167 +
1.168 + # KDE, GNOME and XFCE run on X11, so we have to test for X11 last.
1.169 +
1.170 + if _is_x11():
1.171 + return "X11"
1.172 + else:
1.173 + return None
1.174 +
1.175 +def use_desktop(desktop):
1.176 +
1.177 + """
1.178 + Decide which desktop should be used, based on the detected desktop and a
1.179 + supplied 'desktop' argument (which may be None). Return an identifier
1.180 + indicating the desktop type as being either "standard" or one of the results
1.181 + from the 'get_desktop' function.
1.182 + """
1.183 +
1.184 + # Attempt to detect a desktop environment.
1.185 +
1.186 + detected = get_desktop()
1.187 +
1.188 + # Start with desktops whose existence can be easily tested.
1.189 +
1.190 + if (desktop is None or desktop == "standard") and is_standard():
1.191 + return "standard"
1.192 + elif (desktop is None or desktop == "Windows") and detected == "Windows":
1.193 + return "Windows"
1.194 +
1.195 + # Test for desktops where the overriding is not verified.
1.196 +
1.197 + elif (desktop or detected) == "KDE":
1.198 + return "KDE"
1.199 + elif (desktop or detected) == "GNOME":
1.200 + return "GNOME"
1.201 + elif (desktop or detected) == "XFCE":
1.202 + return "XFCE"
1.203 + elif (desktop or detected) == "Mac OS X":
1.204 + return "Mac OS X"
1.205 + elif (desktop or detected) == "X11":
1.206 + return "X11"
1.207 + else:
1.208 + return None
1.209 +
1.210 +def is_standard():
1.211 +
1.212 + """
1.213 + Return whether the current desktop supports standardised application
1.214 + launching.
1.215 + """
1.216 +
1.217 + return os.environ.has_key("DESKTOP_LAUNCH")
1.218 +
1.219 +# Activity functions.
1.220 +
1.221 +def open(url, desktop=None, wait=0):
1.222 +
1.223 + """
1.224 + Open the 'url' in the current desktop's preferred file browser. If the
1.225 + optional 'desktop' parameter is specified then attempt to use that
1.226 + particular desktop environment's mechanisms to open the 'url' instead of
1.227 + guessing or detecting which environment is being used.
1.228 +
1.229 + Suggested values for 'desktop' are "standard", "KDE", "GNOME", "XFCE",
1.230 + "Mac OS X", "Windows" where "standard" employs a DESKTOP_LAUNCH environment
1.231 + variable to open the specified 'url'. DESKTOP_LAUNCH should be a command,
1.232 + possibly followed by arguments, and must have any special characters
1.233 + shell-escaped.
1.234 +
1.235 + The process identifier of the "opener" (ie. viewer, editor, browser or
1.236 + program) associated with the 'url' is returned by this function. If the
1.237 + process identifier cannot be determined, None is returned.
1.238 +
1.239 + An optional 'wait' parameter is also available for advanced usage and, if
1.240 + 'wait' is set to a true value, this function will wait for the launching
1.241 + mechanism to complete before returning (as opposed to immediately returning
1.242 + as is the default behaviour).
1.243 + """
1.244 +
1.245 + # Decide on the desktop environment in use.
1.246 +
1.247 + desktop_in_use = use_desktop(desktop)
1.248 +
1.249 + if desktop_in_use == "standard":
1.250 + arg = "".join([os.environ["DESKTOP_LAUNCH"], commands.mkarg(url)])
1.251 + return _run(arg, 1, wait)
1.252 +
1.253 + elif desktop_in_use == "Windows":
1.254 + # NOTE: This returns None in current implementations.
1.255 + return os.startfile(url)
1.256 +
1.257 + elif desktop_in_use == "KDE":
1.258 + cmd = ["kfmclient", "exec", url]
1.259 +
1.260 + elif desktop_in_use == "GNOME":
1.261 + cmd = ["gnome-open", url]
1.262 +
1.263 + elif desktop_in_use == "XFCE":
1.264 + cmd = ["exo-open", url]
1.265 +
1.266 + elif desktop_in_use == "Mac OS X":
1.267 + cmd = ["open", url]
1.268 +
1.269 + elif desktop_in_use == "X11" and os.environ.has_key("BROWSER"):
1.270 + cmd = [os.environ["BROWSER"], url]
1.271 +
1.272 + # Finish with an error where no suitable desktop was identified.
1.273 +
1.274 + else:
1.275 + raise OSError, "Desktop '%s' not supported (neither DESKTOP_LAUNCH nor os.startfile could be used)" % desktop_in_use
1.276 +
1.277 + return _run(cmd, 0, wait)
1.278 +
1.279 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/desktop/dialog.py Mon Dec 03 00:37:15 2007 +0000
2.3 @@ -0,0 +1,422 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +Simple desktop dialogue box support for Python.
2.8 +
2.9 +Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
2.10 +
2.11 +This library is free software; you can redistribute it and/or
2.12 +modify it under the terms of the GNU Lesser General Public
2.13 +License as published by the Free Software Foundation; either
2.14 +version 2.1 of the License, or (at your option) any later version.
2.15 +
2.16 +This library is distributed in the hope that it will be useful,
2.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
2.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2.19 +Lesser General Public License for more details.
2.20 +
2.21 +You should have received a copy of the GNU Lesser General Public
2.22 +License along with this library; if not, write to the Free Software
2.23 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2.24 +
2.25 +--------
2.26 +
2.27 +Opening Dialogue Boxes (Dialogs)
2.28 +--------------------------------
2.29 +
2.30 +To open a dialogue box (dialog) in the current desktop environment, relying on
2.31 +the automatic detection of that environment, use the appropriate dialogue box
2.32 +class:
2.33 +
2.34 +question = desktop.dialog.Question("Are you sure?")
2.35 +question.open()
2.36 +
2.37 +To override the detected desktop, specify the desktop parameter to the open
2.38 +function as follows:
2.39 +
2.40 +question.open("KDE") # Insists on KDE
2.41 +question.open("GNOME") # Insists on GNOME
2.42 +
2.43 +The dialogue box options are documented in each class's docstring.
2.44 +"""
2.45 +
2.46 +from desktop import use_desktop, _run, _readfrom, _status
2.47 +
2.48 +# Dialogue parameter classes.
2.49 +
2.50 +class String:
2.51 +
2.52 + "A generic parameter."
2.53 +
2.54 + def __init__(self, name):
2.55 + self.name = name
2.56 +
2.57 + def convert(self, value, program):
2.58 + return [value or ""]
2.59 +
2.60 +class Strings(String):
2.61 +
2.62 + "Multiple string parameters."
2.63 +
2.64 + def convert(self, value, program):
2.65 + return value or []
2.66 +
2.67 +class StringKeyword:
2.68 +
2.69 + "A keyword parameter."
2.70 +
2.71 + def __init__(self, keyword, name):
2.72 + self.keyword = keyword
2.73 + self.name = name
2.74 +
2.75 + def convert(self, value, program):
2.76 + return [self.keyword + "=" + (value or "")]
2.77 +
2.78 +class StringKeywords:
2.79 +
2.80 + "Multiple keyword parameters."
2.81 +
2.82 + def __init__(self, keyword, name):
2.83 + self.keyword = keyword
2.84 + self.name = name
2.85 +
2.86 + def convert(self, value, program):
2.87 + l = []
2.88 + for v in value or []:
2.89 + l.append(self.keyword + "=" + v)
2.90 + return l
2.91 +
2.92 +class Integer(String):
2.93 +
2.94 + "An integer parameter."
2.95 +
2.96 + defaults = {
2.97 + "width" : 40,
2.98 + "height" : 15,
2.99 + "list_height" : 10
2.100 + }
2.101 +
2.102 + def convert(self, value, program):
2.103 + if value is None:
2.104 + value = self.defaults[self.name]
2.105 + return [str(int(value))]
2.106 +
2.107 +class IntegerKeyword(Integer):
2.108 +
2.109 + "An integer keyword parameter."
2.110 +
2.111 + def __init__(self, keyword, name):
2.112 + self.keyword = keyword
2.113 + self.name = name
2.114 +
2.115 + def convert(self, value, program):
2.116 + if value is None:
2.117 + value = self.defaults[self.name]
2.118 + return [self.keyword + "=" + str(int(value))]
2.119 +
2.120 +class Boolean(String):
2.121 +
2.122 + "A boolean parameter."
2.123 +
2.124 + values = {
2.125 + "kdialog" : ["off", "on"],
2.126 + "zenity" : ["FALSE", "TRUE"],
2.127 + "Xdialog" : ["off", "on"]
2.128 + }
2.129 +
2.130 + def convert(self, value, program):
2.131 + values = self.values[program]
2.132 + if value:
2.133 + return [values[1]]
2.134 + else:
2.135 + return [values[0]]
2.136 +
2.137 +class MenuItemList(String):
2.138 +
2.139 + "A menu item list parameter."
2.140 +
2.141 + def convert(self, value, program):
2.142 + l = []
2.143 + for v in value:
2.144 + l.append(v.value)
2.145 + l.append(v.text)
2.146 + return l
2.147 +
2.148 +class ListItemList(String):
2.149 +
2.150 + "A menu item list parameter."
2.151 +
2.152 + def convert(self, value, program):
2.153 + l = []
2.154 + for v in value:
2.155 + l.append(v.value)
2.156 + l.append(v.text)
2.157 + boolean = Boolean(None)
2.158 + l.append(boolean.convert(v.status, program))
2.159 + return l
2.160 +
2.161 +# Dialogue argument values.
2.162 +
2.163 +class MenuItem:
2.164 + def __init__(self, value, text):
2.165 + self.value = value
2.166 + self.text = text
2.167 +
2.168 +class ListItem(MenuItem):
2.169 + def __init__(self, value, text, status):
2.170 + MenuItem.__init__(self, value, text)
2.171 + self.status = status
2.172 +
2.173 +# Dialogue classes.
2.174 +
2.175 +class Dialogue:
2.176 +
2.177 + commands = {
2.178 + "KDE" : "kdialog",
2.179 + "GNOME" : "zenity",
2.180 + "X11" : "Xdialog"
2.181 + }
2.182 +
2.183 + def open(self, desktop=None):
2.184 +
2.185 + """
2.186 + Open a dialogue box (dialog) using a program appropriate to the desktop
2.187 + environment in use.
2.188 +
2.189 + If the optional 'desktop' parameter is specified then attempt to use that
2.190 + particular desktop environment's mechanisms to open the dialog instead of
2.191 + guessing or detecting which environment is being used.
2.192 +
2.193 + Suggested values for 'desktop' are "standard", "KDE", "GNOME", "Mac OS X",
2.194 + "Windows".
2.195 +
2.196 + The result of the dialogue interaction may be a string indicating user
2.197 + input (for input, password, menu, radiolist, pulldown), a list of strings
2.198 + indicating selections of one or more items (for checklist), or a value
2.199 + indicating true or false (for question).
2.200 + """
2.201 +
2.202 + # Decide on the desktop environment in use.
2.203 +
2.204 + desktop_in_use = use_desktop(desktop)
2.205 +
2.206 + # Get the program.
2.207 +
2.208 + try:
2.209 + program = self.commands[desktop_in_use]
2.210 + except KeyError:
2.211 + raise OSError, "Desktop '%s' not supported (no known dialogue box command could be suggested)" % desktop_in_use
2.212 +
2.213 + handler, options = self.info[program]
2.214 +
2.215 + cmd = [program]
2.216 + for option in options:
2.217 + if isinstance(option, str):
2.218 + cmd.append(option)
2.219 + else:
2.220 + value = getattr(self, option.name, None)
2.221 + cmd += option.convert(value, program)
2.222 +
2.223 + print cmd
2.224 + return handler(cmd, 0)
2.225 +
2.226 +class Simple(Dialogue):
2.227 + def __init__(self, text, width=None, height=None):
2.228 + self.text = text
2.229 + self.width = width
2.230 + self.height = height
2.231 +
2.232 +class Question(Simple):
2.233 +
2.234 + """
2.235 + A dialogue asking a question and showing response buttons.
2.236 + Options: text, width (in characters), height (in characters)
2.237 + """
2.238 +
2.239 + name = "question"
2.240 + info = {
2.241 + "kdialog" : (_status, ["--yesno", String("text")]),
2.242 + "zenity" : (_status, ["--question", StringKeyword("--text", "text")]),
2.243 + "Xdialog" : (_status, ["--stdout", "--yesno", String("text"), Integer("height"), Integer("width")]),
2.244 + }
2.245 +
2.246 +class Warning(Simple):
2.247 +
2.248 + """
2.249 + A dialogue asking a question and showing response buttons.
2.250 + Options: text, width (in characters), height (in characters)
2.251 + """
2.252 +
2.253 + name = "warning"
2.254 + info = {
2.255 + "kdialog" : (_status, ["--warningyesno", String("text")]),
2.256 + "zenity" : (_status, ["--warning", StringKeyword("--text", "text")]),
2.257 + "Xdialog" : (_status, ["--stdout", "--yesno", String("text"), Integer("height"), Integer("width")]),
2.258 + }
2.259 +
2.260 +class Message(Simple):
2.261 +
2.262 + """
2.263 + A message dialogue.
2.264 + Options: text, width (in characters), height (in characters)
2.265 + """
2.266 +
2.267 + name = "message"
2.268 + info = {
2.269 + "kdialog" : (_status, ["--msgbox", String("text")]),
2.270 + "zenity" : (_status, ["--info", StringKeyword("--text", "text")]),
2.271 + "Xdialog" : (_status, ["--stdout", "--msgbox", String("text"), Integer("height"), Integer("width")]),
2.272 + }
2.273 +
2.274 +class Error(Simple):
2.275 +
2.276 + """
2.277 + An error dialogue.
2.278 + Options: text, width (in characters), height (in characters)
2.279 + """
2.280 +
2.281 + name = "error"
2.282 + info = {
2.283 + "kdialog" : (_status, ["--error", String("text")]),
2.284 + "zenity" : (_status, ["--error", StringKeyword("--text", "text")]),
2.285 + "Xdialog" : (_status, ["--stdout", "--msgbox", String("text"), Integer("height"), Integer("width")]),
2.286 + }
2.287 +
2.288 +class Menu(Simple):
2.289 +
2.290 + """
2.291 + A menu of options, one of which being selectable.
2.292 + Options: text, width (in characters), height (in characters),
2.293 + list_height (in items), items (MenuItem objects)
2.294 + """
2.295 +
2.296 + name = "menu"
2.297 + info = {
2.298 + "kdialog" : (_readfrom, ["--menu", String("text"), MenuItemList("items")]),
2.299 + "zenity" : (_readfrom, ["--list", StringKeyword("--text", "text"), StringKeywords("--column", "titles"),
2.300 + MenuItemList("items")]
2.301 + ),
2.302 + "Xdialog" : (_readfrom, ["--stdout", "--menubox",
2.303 + String("text"), Integer("height"), Integer("width"), Integer("list_height"), MenuItemList("items")]
2.304 + ),
2.305 + }
2.306 +
2.307 + def __init__(self, text, titles, items, width=None, height=None, list_height=None):
2.308 + Simple.__init__(self, text, width, height)
2.309 + self.titles = titles
2.310 + self.items = items
2.311 + self.list_height = list_height
2.312 +
2.313 +class RadioList(Menu):
2.314 +
2.315 + """
2.316 + A list of radio buttons, one of which being selectable.
2.317 + Options: text, width (in characters), height (in characters),
2.318 + list_height (in items), items (ListItem objects), titles
2.319 + """
2.320 +
2.321 + name = "radiolist"
2.322 + info = {
2.323 + "kdialog" : (_readfrom, ["--radiolist", String("text"), ListItemList("items")]),
2.324 + "zenity" : (_readfrom,
2.325 + ["--list", "--radiolist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"),
2.326 + ListItemList("items")]
2.327 + ),
2.328 + "Xdialog" : (_readfrom, ["--stdout", "--radiolist",
2.329 + String("text"), Integer("height"), Integer("width"), Integer("list_height"), ListItemList("items")]
2.330 + ),
2.331 + }
2.332 +
2.333 +class CheckList(Menu):
2.334 +
2.335 + """
2.336 + A list of checkboxes, many being selectable.
2.337 + Options: text, width (in characters), height (in characters),
2.338 + list_height (in items), items (ListItem objects), titles
2.339 + """
2.340 +
2.341 + name = "checklist"
2.342 + info = {
2.343 + "kdialog" : (_readfrom, ["--checklist", String("text"), ListItemList("items")]),
2.344 + "zenity" : (_readfrom,
2.345 + ["--list", "--checklist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"),
2.346 + ListItemList("items")]
2.347 + ),
2.348 + "Xdialog" : (_readfrom, ["--stdout", "--checklist",
2.349 + String("text"), Integer("height"), Integer("width"), Integer("list_height"), ListItemList("items")]
2.350 + ),
2.351 + }
2.352 +
2.353 +class Pulldown(Menu):
2.354 +
2.355 + """
2.356 + A pull-down menu of options, one of which being selectable.
2.357 + Options: text, width (in characters), height (in characters),
2.358 + entries (list of values)
2.359 + """
2.360 +
2.361 + name = "pulldown"
2.362 + info = {
2.363 + "kdialog" : (_readfrom, ["--combobox", String("text"), Strings("items")]),
2.364 + "zenity" : (_readfrom, ["--list", "--radiolist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"),
2.365 + Strings("items")]
2.366 + ),
2.367 + "Xdialog" : (_readfrom, ["--stdout", "--combobox", String("text"), Integer("height"), Integer("width"), Strings("items")]),
2.368 + }
2.369 +
2.370 +class Input(Simple):
2.371 +
2.372 + """
2.373 + An input dialogue, consisting of an input field.
2.374 + Options: text, width (in characters), height (in characters),
2.375 + input
2.376 + """
2.377 +
2.378 + name = "input"
2.379 + info = {
2.380 + "kdialog" : (_readfrom, ["--inputbox", String("text"), String("data")]),
2.381 + "zenity" : (_readfrom, ["--entry", StringKeyword("--text", "text"), StringKeyword("--entry-text", "data")]),
2.382 + "Xdialog" : (_readfrom, ["--stdout", "--inputbox", String("text"), Integer("height"), Integer("width"), String("data")]),
2.383 + }
2.384 +
2.385 + def __init__(self, text, data, width=None, height=None):
2.386 + Simple.__init__(self, text, width, height)
2.387 + self.data = data
2.388 +
2.389 +class Password(Input):
2.390 +
2.391 + """
2.392 + A password dialogue, consisting of a password entry field.
2.393 + Options: text, width (in characters), height (in characters),
2.394 + input
2.395 + """
2.396 +
2.397 + name = "password"
2.398 + info = {
2.399 + "kdialog" : (_readfrom, ["--password", String("text")]),
2.400 + "zenity" : (_readfrom, ["--password", StringKeyword("--text", "text"), "--hide-text"]),
2.401 + "Xdialog" : (_readfrom, ["--stdout", "--password", "--inputbox", String("text"), Integer("height"), Integer("width")]),
2.402 + }
2.403 +
2.404 +class TextFile(Simple):
2.405 +
2.406 + """
2.407 + A text file input box.
2.408 + Options: text, width (in characters), height (in characters),
2.409 + filename
2.410 + """
2.411 +
2.412 + name = "textfile"
2.413 + info = {
2.414 + "kdialog" : (_readfrom, ["--textbox", String("filename"), String("width"), String("height")]),
2.415 + "zenity" : (_readfrom, ["--textbox", StringKeyword("--filename", "filename"), IntegerKeyword("--width", "width"),
2.416 + IntegerKeyword("--height", "height")]
2.417 + ),
2.418 + "Xdialog" : (_readfrom, ["--stdout", "--textbox", String("text"), Integer("height"), Integer("width")]),
2.419 + }
2.420 +
2.421 + def __init__(self, text, filename, width=None, height=None):
2.422 + Simple.__init__(self, text, width, height)
2.423 + self.filename = filename
2.424 +
2.425 +# vim: tabstop=4 expandtab shiftwidth=4