paulb@46 | 1 | #!/usr/bin/env python |
paulb@46 | 2 | |
paulb@46 | 3 | """ |
paulb@46 | 4 | Simple desktop dialogue box support for Python. |
paulb@46 | 5 | |
paulb@51 | 6 | Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> |
paulb@46 | 7 | |
paulb@46 | 8 | This library is free software; you can redistribute it and/or |
paulb@46 | 9 | modify it under the terms of the GNU Lesser General Public |
paulb@46 | 10 | License as published by the Free Software Foundation; either |
paulb@46 | 11 | version 2.1 of the License, or (at your option) any later version. |
paulb@46 | 12 | |
paulb@46 | 13 | This library is distributed in the hope that it will be useful, |
paulb@46 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@46 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@46 | 16 | Lesser General Public License for more details. |
paulb@46 | 17 | |
paulb@46 | 18 | You should have received a copy of the GNU Lesser General Public |
paulb@46 | 19 | License along with this library; if not, write to the Free Software |
paulb@46 | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@46 | 21 | |
paulb@46 | 22 | -------- |
paulb@46 | 23 | |
paulb@46 | 24 | Opening Dialogue Boxes (Dialogs) |
paulb@46 | 25 | -------------------------------- |
paulb@46 | 26 | |
paulb@46 | 27 | To open a dialogue box (dialog) in the current desktop environment, relying on |
paulb@46 | 28 | the automatic detection of that environment, use the appropriate dialogue box |
paulb@46 | 29 | class: |
paulb@46 | 30 | |
paulb@46 | 31 | question = desktop.dialog.Question("Are you sure?") |
paulb@46 | 32 | question.open() |
paulb@46 | 33 | |
paulb@46 | 34 | To override the detected desktop, specify the desktop parameter to the open |
paulb@46 | 35 | function as follows: |
paulb@46 | 36 | |
paulb@46 | 37 | question.open("KDE") # Insists on KDE |
paulb@46 | 38 | question.open("GNOME") # Insists on GNOME |
paulb@46 | 39 | |
paulb@46 | 40 | The dialogue box options are documented in each class's docstring. |
paulb@51 | 41 | |
paulb@51 | 42 | Available dialogue box classes are listed in the desktop.dialog.available |
paulb@51 | 43 | attribute. |
paulb@46 | 44 | """ |
paulb@46 | 45 | |
paulb@46 | 46 | from desktop import use_desktop, _run, _readfrom, _status |
paulb@46 | 47 | |
paulb@49 | 48 | class _wrapper: |
paulb@49 | 49 | def __init__(self, handler): |
paulb@49 | 50 | self.handler = handler |
paulb@49 | 51 | |
paulb@49 | 52 | class _readvalue(_wrapper): |
paulb@49 | 53 | def __call__(self, cmd, shell): |
paulb@49 | 54 | return self.handler(cmd, shell).strip() |
paulb@49 | 55 | |
paulb@49 | 56 | class _readinput(_wrapper): |
paulb@49 | 57 | def __call__(self, cmd, shell): |
paulb@49 | 58 | return self.handler(cmd, shell)[:-1] |
paulb@49 | 59 | |
paulb@49 | 60 | class _readvalues_kdialog(_wrapper): |
paulb@49 | 61 | def __call__(self, cmd, shell): |
paulb@49 | 62 | result = self.handler(cmd, shell).strip().strip('"') |
paulb@49 | 63 | if result: |
paulb@49 | 64 | return result.split('" "') |
paulb@49 | 65 | else: |
paulb@49 | 66 | return [] |
paulb@49 | 67 | |
paulb@49 | 68 | class _readvalues_zenity(_wrapper): |
paulb@49 | 69 | def __call__(self, cmd, shell): |
paulb@49 | 70 | result = self.handler(cmd, shell).strip() |
paulb@49 | 71 | if result: |
paulb@49 | 72 | return result.split("|") |
paulb@49 | 73 | else: |
paulb@49 | 74 | return [] |
paulb@49 | 75 | |
paulb@49 | 76 | class _readvalues_Xdialog(_wrapper): |
paulb@49 | 77 | def __call__(self, cmd, shell): |
paulb@49 | 78 | result = self.handler(cmd, shell).strip() |
paulb@49 | 79 | if result: |
paulb@49 | 80 | return result.split("/") |
paulb@49 | 81 | else: |
paulb@49 | 82 | return [] |
paulb@49 | 83 | |
paulb@46 | 84 | # Dialogue parameter classes. |
paulb@46 | 85 | |
paulb@46 | 86 | class String: |
paulb@46 | 87 | |
paulb@46 | 88 | "A generic parameter." |
paulb@46 | 89 | |
paulb@46 | 90 | def __init__(self, name): |
paulb@46 | 91 | self.name = name |
paulb@46 | 92 | |
paulb@46 | 93 | def convert(self, value, program): |
paulb@46 | 94 | return [value or ""] |
paulb@46 | 95 | |
paulb@46 | 96 | class Strings(String): |
paulb@46 | 97 | |
paulb@46 | 98 | "Multiple string parameters." |
paulb@46 | 99 | |
paulb@46 | 100 | def convert(self, value, program): |
paulb@46 | 101 | return value or [] |
paulb@46 | 102 | |
paulb@49 | 103 | class StringPairs(String): |
paulb@49 | 104 | |
paulb@49 | 105 | "Multiple string parameters duplicated to make identifiers." |
paulb@49 | 106 | |
paulb@49 | 107 | def convert(self, value, program): |
paulb@49 | 108 | l = [] |
paulb@49 | 109 | for v in value: |
paulb@49 | 110 | l.append(v) |
paulb@49 | 111 | l.append(v) |
paulb@49 | 112 | return l |
paulb@49 | 113 | |
paulb@46 | 114 | class StringKeyword: |
paulb@46 | 115 | |
paulb@46 | 116 | "A keyword parameter." |
paulb@46 | 117 | |
paulb@46 | 118 | def __init__(self, keyword, name): |
paulb@46 | 119 | self.keyword = keyword |
paulb@46 | 120 | self.name = name |
paulb@46 | 121 | |
paulb@46 | 122 | def convert(self, value, program): |
paulb@46 | 123 | return [self.keyword + "=" + (value or "")] |
paulb@46 | 124 | |
paulb@46 | 125 | class StringKeywords: |
paulb@46 | 126 | |
paulb@46 | 127 | "Multiple keyword parameters." |
paulb@46 | 128 | |
paulb@46 | 129 | def __init__(self, keyword, name): |
paulb@46 | 130 | self.keyword = keyword |
paulb@46 | 131 | self.name = name |
paulb@46 | 132 | |
paulb@46 | 133 | def convert(self, value, program): |
paulb@46 | 134 | l = [] |
paulb@46 | 135 | for v in value or []: |
paulb@46 | 136 | l.append(self.keyword + "=" + v) |
paulb@46 | 137 | return l |
paulb@46 | 138 | |
paulb@46 | 139 | class Integer(String): |
paulb@46 | 140 | |
paulb@46 | 141 | "An integer parameter." |
paulb@46 | 142 | |
paulb@46 | 143 | defaults = { |
paulb@46 | 144 | "width" : 40, |
paulb@46 | 145 | "height" : 15, |
paulb@46 | 146 | "list_height" : 10 |
paulb@46 | 147 | } |
paulb@49 | 148 | scale = 8 |
paulb@49 | 149 | |
paulb@49 | 150 | def __init__(self, name, pixels=0): |
paulb@49 | 151 | String.__init__(self, name) |
paulb@49 | 152 | if pixels: |
paulb@49 | 153 | self.factor = self.scale |
paulb@49 | 154 | else: |
paulb@49 | 155 | self.factor = 1 |
paulb@46 | 156 | |
paulb@46 | 157 | def convert(self, value, program): |
paulb@46 | 158 | if value is None: |
paulb@46 | 159 | value = self.defaults[self.name] |
paulb@49 | 160 | return [str(int(value) * self.factor)] |
paulb@46 | 161 | |
paulb@46 | 162 | class IntegerKeyword(Integer): |
paulb@46 | 163 | |
paulb@46 | 164 | "An integer keyword parameter." |
paulb@46 | 165 | |
paulb@49 | 166 | def __init__(self, keyword, name, pixels=0): |
paulb@49 | 167 | Integer.__init__(self, name, pixels) |
paulb@46 | 168 | self.keyword = keyword |
paulb@46 | 169 | |
paulb@46 | 170 | def convert(self, value, program): |
paulb@46 | 171 | if value is None: |
paulb@46 | 172 | value = self.defaults[self.name] |
paulb@49 | 173 | return [self.keyword + "=" + str(int(value) * self.factor)] |
paulb@46 | 174 | |
paulb@46 | 175 | class Boolean(String): |
paulb@46 | 176 | |
paulb@46 | 177 | "A boolean parameter." |
paulb@46 | 178 | |
paulb@46 | 179 | values = { |
paulb@46 | 180 | "kdialog" : ["off", "on"], |
paulb@46 | 181 | "zenity" : ["FALSE", "TRUE"], |
paulb@46 | 182 | "Xdialog" : ["off", "on"] |
paulb@46 | 183 | } |
paulb@46 | 184 | |
paulb@46 | 185 | def convert(self, value, program): |
paulb@46 | 186 | values = self.values[program] |
paulb@46 | 187 | if value: |
paulb@46 | 188 | return [values[1]] |
paulb@46 | 189 | else: |
paulb@46 | 190 | return [values[0]] |
paulb@46 | 191 | |
paulb@46 | 192 | class MenuItemList(String): |
paulb@46 | 193 | |
paulb@46 | 194 | "A menu item list parameter." |
paulb@46 | 195 | |
paulb@46 | 196 | def convert(self, value, program): |
paulb@46 | 197 | l = [] |
paulb@46 | 198 | for v in value: |
paulb@46 | 199 | l.append(v.value) |
paulb@46 | 200 | l.append(v.text) |
paulb@46 | 201 | return l |
paulb@46 | 202 | |
paulb@46 | 203 | class ListItemList(String): |
paulb@46 | 204 | |
paulb@47 | 205 | "A radiolist/checklist item list parameter." |
paulb@47 | 206 | |
paulb@47 | 207 | def __init__(self, name, status_first=0): |
paulb@47 | 208 | String.__init__(self, name) |
paulb@47 | 209 | self.status_first = status_first |
paulb@46 | 210 | |
paulb@46 | 211 | def convert(self, value, program): |
paulb@46 | 212 | l = [] |
paulb@46 | 213 | for v in value: |
paulb@47 | 214 | boolean = Boolean(None) |
paulb@47 | 215 | status = boolean.convert(v.status, program) |
paulb@47 | 216 | if self.status_first: |
paulb@47 | 217 | l += status |
paulb@46 | 218 | l.append(v.value) |
paulb@46 | 219 | l.append(v.text) |
paulb@47 | 220 | if not self.status_first: |
paulb@47 | 221 | l += status |
paulb@46 | 222 | return l |
paulb@46 | 223 | |
paulb@46 | 224 | # Dialogue argument values. |
paulb@46 | 225 | |
paulb@46 | 226 | class MenuItem: |
paulb@47 | 227 | |
paulb@47 | 228 | "A menu item which can also be used with radiolists and checklists." |
paulb@47 | 229 | |
paulb@47 | 230 | def __init__(self, value, text, status=0): |
paulb@46 | 231 | self.value = value |
paulb@46 | 232 | self.text = text |
paulb@46 | 233 | self.status = status |
paulb@46 | 234 | |
paulb@46 | 235 | # Dialogue classes. |
paulb@46 | 236 | |
paulb@46 | 237 | class Dialogue: |
paulb@46 | 238 | |
paulb@46 | 239 | commands = { |
paulb@46 | 240 | "KDE" : "kdialog", |
paulb@46 | 241 | "GNOME" : "zenity", |
paulb@46 | 242 | "X11" : "Xdialog" |
paulb@46 | 243 | } |
paulb@46 | 244 | |
paulb@46 | 245 | def open(self, desktop=None): |
paulb@46 | 246 | |
paulb@46 | 247 | """ |
paulb@46 | 248 | Open a dialogue box (dialog) using a program appropriate to the desktop |
paulb@46 | 249 | environment in use. |
paulb@46 | 250 | |
paulb@46 | 251 | If the optional 'desktop' parameter is specified then attempt to use that |
paulb@46 | 252 | particular desktop environment's mechanisms to open the dialog instead of |
paulb@46 | 253 | guessing or detecting which environment is being used. |
paulb@46 | 254 | |
paulb@46 | 255 | Suggested values for 'desktop' are "standard", "KDE", "GNOME", "Mac OS X", |
paulb@46 | 256 | "Windows". |
paulb@46 | 257 | |
paulb@46 | 258 | The result of the dialogue interaction may be a string indicating user |
paulb@46 | 259 | input (for input, password, menu, radiolist, pulldown), a list of strings |
paulb@46 | 260 | indicating selections of one or more items (for checklist), or a value |
paulb@46 | 261 | indicating true or false (for question). |
paulb@46 | 262 | """ |
paulb@46 | 263 | |
paulb@46 | 264 | # Decide on the desktop environment in use. |
paulb@46 | 265 | |
paulb@46 | 266 | desktop_in_use = use_desktop(desktop) |
paulb@46 | 267 | |
paulb@46 | 268 | # Get the program. |
paulb@46 | 269 | |
paulb@46 | 270 | try: |
paulb@46 | 271 | program = self.commands[desktop_in_use] |
paulb@46 | 272 | except KeyError: |
paulb@46 | 273 | raise OSError, "Desktop '%s' not supported (no known dialogue box command could be suggested)" % desktop_in_use |
paulb@46 | 274 | |
paulb@46 | 275 | handler, options = self.info[program] |
paulb@46 | 276 | |
paulb@46 | 277 | cmd = [program] |
paulb@46 | 278 | for option in options: |
paulb@46 | 279 | if isinstance(option, str): |
paulb@46 | 280 | cmd.append(option) |
paulb@46 | 281 | else: |
paulb@46 | 282 | value = getattr(self, option.name, None) |
paulb@46 | 283 | cmd += option.convert(value, program) |
paulb@46 | 284 | |
paulb@46 | 285 | return handler(cmd, 0) |
paulb@46 | 286 | |
paulb@46 | 287 | class Simple(Dialogue): |
paulb@46 | 288 | def __init__(self, text, width=None, height=None): |
paulb@46 | 289 | self.text = text |
paulb@46 | 290 | self.width = width |
paulb@46 | 291 | self.height = height |
paulb@46 | 292 | |
paulb@46 | 293 | class Question(Simple): |
paulb@46 | 294 | |
paulb@46 | 295 | """ |
paulb@46 | 296 | A dialogue asking a question and showing response buttons. |
paulb@46 | 297 | Options: text, width (in characters), height (in characters) |
paulb@46 | 298 | """ |
paulb@46 | 299 | |
paulb@46 | 300 | name = "question" |
paulb@46 | 301 | info = { |
paulb@46 | 302 | "kdialog" : (_status, ["--yesno", String("text")]), |
paulb@46 | 303 | "zenity" : (_status, ["--question", StringKeyword("--text", "text")]), |
paulb@46 | 304 | "Xdialog" : (_status, ["--stdout", "--yesno", String("text"), Integer("height"), Integer("width")]), |
paulb@46 | 305 | } |
paulb@46 | 306 | |
paulb@46 | 307 | class Warning(Simple): |
paulb@46 | 308 | |
paulb@46 | 309 | """ |
paulb@46 | 310 | A dialogue asking a question and showing response buttons. |
paulb@46 | 311 | Options: text, width (in characters), height (in characters) |
paulb@46 | 312 | """ |
paulb@46 | 313 | |
paulb@46 | 314 | name = "warning" |
paulb@46 | 315 | info = { |
paulb@46 | 316 | "kdialog" : (_status, ["--warningyesno", String("text")]), |
paulb@46 | 317 | "zenity" : (_status, ["--warning", StringKeyword("--text", "text")]), |
paulb@46 | 318 | "Xdialog" : (_status, ["--stdout", "--yesno", String("text"), Integer("height"), Integer("width")]), |
paulb@46 | 319 | } |
paulb@46 | 320 | |
paulb@46 | 321 | class Message(Simple): |
paulb@46 | 322 | |
paulb@46 | 323 | """ |
paulb@46 | 324 | A message dialogue. |
paulb@46 | 325 | Options: text, width (in characters), height (in characters) |
paulb@46 | 326 | """ |
paulb@46 | 327 | |
paulb@46 | 328 | name = "message" |
paulb@46 | 329 | info = { |
paulb@46 | 330 | "kdialog" : (_status, ["--msgbox", String("text")]), |
paulb@46 | 331 | "zenity" : (_status, ["--info", StringKeyword("--text", "text")]), |
paulb@46 | 332 | "Xdialog" : (_status, ["--stdout", "--msgbox", String("text"), Integer("height"), Integer("width")]), |
paulb@46 | 333 | } |
paulb@46 | 334 | |
paulb@46 | 335 | class Error(Simple): |
paulb@46 | 336 | |
paulb@46 | 337 | """ |
paulb@46 | 338 | An error dialogue. |
paulb@46 | 339 | Options: text, width (in characters), height (in characters) |
paulb@46 | 340 | """ |
paulb@46 | 341 | |
paulb@46 | 342 | name = "error" |
paulb@46 | 343 | info = { |
paulb@46 | 344 | "kdialog" : (_status, ["--error", String("text")]), |
paulb@46 | 345 | "zenity" : (_status, ["--error", StringKeyword("--text", "text")]), |
paulb@46 | 346 | "Xdialog" : (_status, ["--stdout", "--msgbox", String("text"), Integer("height"), Integer("width")]), |
paulb@46 | 347 | } |
paulb@46 | 348 | |
paulb@46 | 349 | class Menu(Simple): |
paulb@46 | 350 | |
paulb@46 | 351 | """ |
paulb@46 | 352 | A menu of options, one of which being selectable. |
paulb@46 | 353 | Options: text, width (in characters), height (in characters), |
paulb@46 | 354 | list_height (in items), items (MenuItem objects) |
paulb@46 | 355 | """ |
paulb@46 | 356 | |
paulb@46 | 357 | name = "menu" |
paulb@46 | 358 | info = { |
paulb@49 | 359 | "kdialog" : (_readvalue(_readfrom), ["--menu", String("text"), MenuItemList("items")]), |
paulb@49 | 360 | "zenity" : (_readvalue(_readfrom), ["--list", StringKeyword("--text", "text"), StringKeywords("--column", "titles"), |
paulb@46 | 361 | MenuItemList("items")] |
paulb@46 | 362 | ), |
paulb@49 | 363 | "Xdialog" : (_readvalue(_readfrom), ["--stdout", "--menubox", |
paulb@46 | 364 | String("text"), Integer("height"), Integer("width"), Integer("list_height"), MenuItemList("items")] |
paulb@46 | 365 | ), |
paulb@46 | 366 | } |
paulb@47 | 367 | item = MenuItem |
paulb@49 | 368 | number_of_titles = 2 |
paulb@46 | 369 | |
paulb@47 | 370 | def __init__(self, text, titles, items=None, width=None, height=None, list_height=None): |
paulb@47 | 371 | |
paulb@47 | 372 | """ |
paulb@47 | 373 | Initialise a menu with the given heading 'text', column 'titles', and |
paulb@47 | 374 | optional 'items' (which may be added later), 'width' (in characters), |
paulb@47 | 375 | 'height' (in characters) and 'list_height' (in items). |
paulb@47 | 376 | """ |
paulb@47 | 377 | |
paulb@46 | 378 | Simple.__init__(self, text, width, height) |
paulb@49 | 379 | self.titles = ([""] * self.number_of_titles + titles)[-self.number_of_titles:] |
paulb@47 | 380 | self.items = items or [] |
paulb@46 | 381 | self.list_height = list_height |
paulb@46 | 382 | |
paulb@47 | 383 | def add(self, *args, **kw): |
paulb@47 | 384 | |
paulb@47 | 385 | """ |
paulb@47 | 386 | Add an item, passing the given arguments to the appropriate item class. |
paulb@47 | 387 | """ |
paulb@47 | 388 | |
paulb@47 | 389 | self.items.append(self.item(*args, **kw)) |
paulb@47 | 390 | |
paulb@46 | 391 | class RadioList(Menu): |
paulb@46 | 392 | |
paulb@46 | 393 | """ |
paulb@46 | 394 | A list of radio buttons, one of which being selectable. |
paulb@46 | 395 | Options: text, width (in characters), height (in characters), |
paulb@47 | 396 | list_height (in items), items (MenuItem objects), titles |
paulb@46 | 397 | """ |
paulb@46 | 398 | |
paulb@46 | 399 | name = "radiolist" |
paulb@46 | 400 | info = { |
paulb@49 | 401 | "kdialog" : (_readvalues_kdialog(_readfrom), ["--radiolist", String("text"), ListItemList("items")]), |
paulb@49 | 402 | "zenity" : (_readvalues_zenity(_readfrom), |
paulb@46 | 403 | ["--list", "--radiolist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"), |
paulb@47 | 404 | ListItemList("items", 1)] |
paulb@46 | 405 | ), |
paulb@49 | 406 | "Xdialog" : (_readvalues_Xdialog(_readfrom), ["--stdout", "--radiolist", |
paulb@46 | 407 | String("text"), Integer("height"), Integer("width"), Integer("list_height"), ListItemList("items")] |
paulb@46 | 408 | ), |
paulb@46 | 409 | } |
paulb@49 | 410 | number_of_titles = 3 |
paulb@46 | 411 | |
paulb@46 | 412 | class CheckList(Menu): |
paulb@46 | 413 | |
paulb@46 | 414 | """ |
paulb@46 | 415 | A list of checkboxes, many being selectable. |
paulb@46 | 416 | Options: text, width (in characters), height (in characters), |
paulb@47 | 417 | list_height (in items), items (MenuItem objects), titles |
paulb@46 | 418 | """ |
paulb@46 | 419 | |
paulb@46 | 420 | name = "checklist" |
paulb@46 | 421 | info = { |
paulb@49 | 422 | "kdialog" : (_readvalues_kdialog(_readfrom), ["--checklist", String("text"), ListItemList("items")]), |
paulb@49 | 423 | "zenity" : (_readvalues_zenity(_readfrom), |
paulb@46 | 424 | ["--list", "--checklist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"), |
paulb@47 | 425 | ListItemList("items", 1)] |
paulb@46 | 426 | ), |
paulb@49 | 427 | "Xdialog" : (_readvalues_Xdialog(_readfrom), ["--stdout", "--checklist", |
paulb@46 | 428 | String("text"), Integer("height"), Integer("width"), Integer("list_height"), ListItemList("items")] |
paulb@46 | 429 | ), |
paulb@46 | 430 | } |
paulb@49 | 431 | number_of_titles = 3 |
paulb@46 | 432 | |
paulb@46 | 433 | class Pulldown(Menu): |
paulb@46 | 434 | |
paulb@46 | 435 | """ |
paulb@46 | 436 | A pull-down menu of options, one of which being selectable. |
paulb@46 | 437 | Options: text, width (in characters), height (in characters), |
paulb@46 | 438 | entries (list of values) |
paulb@46 | 439 | """ |
paulb@46 | 440 | |
paulb@46 | 441 | name = "pulldown" |
paulb@46 | 442 | info = { |
paulb@49 | 443 | "kdialog" : (_readvalue(_readfrom), ["--combobox", String("text"), Strings("items")]), |
paulb@49 | 444 | "zenity" : (_readvalue(_readfrom), |
paulb@49 | 445 | ["--list", "--radiolist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"), |
paulb@49 | 446 | StringPairs("items")] |
paulb@46 | 447 | ), |
paulb@49 | 448 | "Xdialog" : (_readvalue(_readfrom), |
paulb@49 | 449 | ["--stdout", "--combobox", String("text"), Integer("height"), Integer("width"), Strings("items")]), |
paulb@46 | 450 | } |
paulb@49 | 451 | item = unicode |
paulb@49 | 452 | number_of_titles = 2 |
paulb@46 | 453 | |
paulb@46 | 454 | class Input(Simple): |
paulb@46 | 455 | |
paulb@46 | 456 | """ |
paulb@46 | 457 | An input dialogue, consisting of an input field. |
paulb@49 | 458 | Options: text, input, width (in characters), height (in characters) |
paulb@46 | 459 | """ |
paulb@46 | 460 | |
paulb@46 | 461 | name = "input" |
paulb@46 | 462 | info = { |
paulb@49 | 463 | "kdialog" : (_readinput(_readfrom), |
paulb@49 | 464 | ["--inputbox", String("text"), String("data")]), |
paulb@49 | 465 | "zenity" : (_readinput(_readfrom), |
paulb@49 | 466 | ["--entry", StringKeyword("--text", "text"), StringKeyword("--entry-text", "data")]), |
paulb@49 | 467 | "Xdialog" : (_readinput(_readfrom), |
paulb@49 | 468 | ["--stdout", "--inputbox", String("text"), Integer("height"), Integer("width"), String("data")]), |
paulb@46 | 469 | } |
paulb@46 | 470 | |
paulb@49 | 471 | def __init__(self, text, data="", width=None, height=None): |
paulb@46 | 472 | Simple.__init__(self, text, width, height) |
paulb@46 | 473 | self.data = data |
paulb@46 | 474 | |
paulb@46 | 475 | class Password(Input): |
paulb@46 | 476 | |
paulb@46 | 477 | """ |
paulb@46 | 478 | A password dialogue, consisting of a password entry field. |
paulb@49 | 479 | Options: text, width (in characters), height (in characters) |
paulb@46 | 480 | """ |
paulb@46 | 481 | |
paulb@46 | 482 | name = "password" |
paulb@46 | 483 | info = { |
paulb@49 | 484 | "kdialog" : (_readinput(_readfrom), |
paulb@49 | 485 | ["--password", String("text")]), |
paulb@49 | 486 | "zenity" : (_readinput(_readfrom), |
paulb@49 | 487 | ["--entry", StringKeyword("--text", "text"), "--hide-text"]), |
paulb@49 | 488 | "Xdialog" : (_readinput(_readfrom), |
paulb@49 | 489 | ["--stdout", "--password", "--inputbox", String("text"), Integer("height"), Integer("width")]), |
paulb@46 | 490 | } |
paulb@46 | 491 | |
paulb@46 | 492 | class TextFile(Simple): |
paulb@46 | 493 | |
paulb@46 | 494 | """ |
paulb@46 | 495 | A text file input box. |
paulb@49 | 496 | Options: filename, text, width (in characters), height (in characters) |
paulb@46 | 497 | """ |
paulb@46 | 498 | |
paulb@46 | 499 | name = "textfile" |
paulb@46 | 500 | info = { |
paulb@49 | 501 | "kdialog" : (_readfrom, ["--textbox", String("filename"), Integer("width", pixels=1), Integer("height", pixels=1)]), |
paulb@49 | 502 | "zenity" : (_readfrom, ["--text-info", StringKeyword("--filename", "filename"), IntegerKeyword("--width", "width", pixels=1), |
paulb@49 | 503 | IntegerKeyword("--height", "height", pixels=1)] |
paulb@46 | 504 | ), |
paulb@49 | 505 | "Xdialog" : (_readfrom, ["--stdout", "--textbox", String("filename"), Integer("height"), Integer("width")]), |
paulb@46 | 506 | } |
paulb@46 | 507 | |
paulb@49 | 508 | def __init__(self, filename, text="", width=None, height=None): |
paulb@46 | 509 | Simple.__init__(self, text, width, height) |
paulb@46 | 510 | self.filename = filename |
paulb@46 | 511 | |
paulb@47 | 512 | # Available dialogues. |
paulb@47 | 513 | |
paulb@47 | 514 | available = [Question, Warning, Message, Error, Menu, CheckList, RadioList, Input, Password, Pulldown, TextFile] |
paulb@47 | 515 | |
paulb@46 | 516 | # vim: tabstop=4 expandtab shiftwidth=4 |