1.1 --- a/desktop/dialog.py Mon Dec 03 00:37:15 2007 +0000
1.2 +++ b/desktop/dialog.py Tue Dec 04 00:07:35 2007 +0000
1.3 @@ -144,27 +144,34 @@
1.4
1.5 class ListItemList(String):
1.6
1.7 - "A menu item list parameter."
1.8 + "A radiolist/checklist item list parameter."
1.9 +
1.10 + def __init__(self, name, status_first=0):
1.11 + String.__init__(self, name)
1.12 + self.status_first = status_first
1.13
1.14 def convert(self, value, program):
1.15 l = []
1.16 for v in value:
1.17 + boolean = Boolean(None)
1.18 + status = boolean.convert(v.status, program)
1.19 + if self.status_first:
1.20 + l += status
1.21 l.append(v.value)
1.22 l.append(v.text)
1.23 - boolean = Boolean(None)
1.24 - l.append(boolean.convert(v.status, program))
1.25 + if not self.status_first:
1.26 + l += status
1.27 return l
1.28
1.29 # Dialogue argument values.
1.30
1.31 class MenuItem:
1.32 - def __init__(self, value, text):
1.33 +
1.34 + "A menu item which can also be used with radiolists and checklists."
1.35 +
1.36 + def __init__(self, value, text, status=0):
1.37 self.value = value
1.38 self.text = text
1.39 -
1.40 -class ListItem(MenuItem):
1.41 - def __init__(self, value, text, status):
1.42 - MenuItem.__init__(self, value, text)
1.43 self.status = status
1.44
1.45 # Dialogue classes.
1.46 @@ -300,19 +307,35 @@
1.47 String("text"), Integer("height"), Integer("width"), Integer("list_height"), MenuItemList("items")]
1.48 ),
1.49 }
1.50 + item = MenuItem
1.51
1.52 - def __init__(self, text, titles, items, width=None, height=None, list_height=None):
1.53 + def __init__(self, text, titles, items=None, width=None, height=None, list_height=None):
1.54 +
1.55 + """
1.56 + Initialise a menu with the given heading 'text', column 'titles', and
1.57 + optional 'items' (which may be added later), 'width' (in characters),
1.58 + 'height' (in characters) and 'list_height' (in items).
1.59 + """
1.60 +
1.61 Simple.__init__(self, text, width, height)
1.62 self.titles = titles
1.63 - self.items = items
1.64 + self.items = items or []
1.65 self.list_height = list_height
1.66
1.67 + def add(self, *args, **kw):
1.68 +
1.69 + """
1.70 + Add an item, passing the given arguments to the appropriate item class.
1.71 + """
1.72 +
1.73 + self.items.append(self.item(*args, **kw))
1.74 +
1.75 class RadioList(Menu):
1.76
1.77 """
1.78 A list of radio buttons, one of which being selectable.
1.79 Options: text, width (in characters), height (in characters),
1.80 - list_height (in items), items (ListItem objects), titles
1.81 + list_height (in items), items (MenuItem objects), titles
1.82 """
1.83
1.84 name = "radiolist"
1.85 @@ -320,7 +343,7 @@
1.86 "kdialog" : (_readfrom, ["--radiolist", String("text"), ListItemList("items")]),
1.87 "zenity" : (_readfrom,
1.88 ["--list", "--radiolist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"),
1.89 - ListItemList("items")]
1.90 + ListItemList("items", 1)]
1.91 ),
1.92 "Xdialog" : (_readfrom, ["--stdout", "--radiolist",
1.93 String("text"), Integer("height"), Integer("width"), Integer("list_height"), ListItemList("items")]
1.94 @@ -332,7 +355,7 @@
1.95 """
1.96 A list of checkboxes, many being selectable.
1.97 Options: text, width (in characters), height (in characters),
1.98 - list_height (in items), items (ListItem objects), titles
1.99 + list_height (in items), items (MenuItem objects), titles
1.100 """
1.101
1.102 name = "checklist"
1.103 @@ -340,7 +363,7 @@
1.104 "kdialog" : (_readfrom, ["--checklist", String("text"), ListItemList("items")]),
1.105 "zenity" : (_readfrom,
1.106 ["--list", "--checklist", StringKeyword("--text", "text"), StringKeywords("--column", "titles"),
1.107 - ListItemList("items")]
1.108 + ListItemList("items", 1)]
1.109 ),
1.110 "Xdialog" : (_readfrom, ["--stdout", "--checklist",
1.111 String("text"), Integer("height"), Integer("width"), Integer("list_height"), ListItemList("items")]
1.112 @@ -419,4 +442,8 @@
1.113 Simple.__init__(self, text, width, height)
1.114 self.filename = filename
1.115
1.116 +# Available dialogues.
1.117 +
1.118 +available = [Question, Warning, Message, Error, Menu, CheckList, RadioList, Input, Password, Pulldown, TextFile]
1.119 +
1.120 # vim: tabstop=4 expandtab shiftwidth=4