1
diff -ruN newt-0.51.6-old/newt.c newt-0.51.6/newt.c
2
--- newt-0.51.6-old/newt.c 2004-07-11 12:25:36 +0100
3
+++ newt-0.51.6/newt.c 2004-07-11 12:27:41 +0100
9
+ * @brief Refresh the screen
11
void newtRefresh(void) {
15
SLtt_set_cursor_visibility (cursorOn);
19
+ * @brief Return after suspension.
20
+ * @return 0 on success.
22
void newtResume(void) {
30
+ * @brief Resize the screen
31
+ * @param redraw - boolean - should we redraw the screen?
33
void newtResizeScreen(int redraw) {
34
SLtt_get_screen_size();
41
+ * @brief Initialize the newt library
42
+ * @return int - 0 for success, else < 0
45
char * MonoValue, * MonoEnv = "NEWT_MONO";
52
+ * @brief Closedown the newt library, tidying screen.
53
+ * @returns int , 0. (no errors reported)
55
int newtFinished(void) {
56
SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
63
+ * @brief Set the colors used.
64
+ * @param colors - newtColor struct used.
66
void newtSetColors(struct newtColors colors) {
67
if (!SLtt_Use_Ansi_Colors) {
74
+ * @brief Wait for a keystroke
76
void newtWaitForKey(void) {
84
+ * @brief Clear the keybuffer
86
void newtClearKeyBuffer(void) {
87
while (SLang_input_pending(1)) {
93
+ * Open a new window.
94
+ * @param left. unsigned int Size; _not_ including border
95
+ * @param top: unsigned int size, _not_ including border
96
+ * @param width unsigned int
97
+ * @param height unsigned int
98
+ * @param title - title string
99
+ * @return zero on success (currently no errors reported)
101
int newtOpenWindow(int left, int top, int width, int height,
102
const char * title) {
109
+ * @brief Draw a centered window.
110
+ * @param width - width in char cells
111
+ * @param height - no. of char cells.
112
+ * @param title - fixed title
113
+ * @returns 0. No errors reported
115
int newtCenteredWindow(int width, int height, const char * title) {
123
+ * @brief Remove the top window
125
void newtPopWindow(void) {
133
+ * @brief Delay for a specified number of usecs
134
+ * @param int - number of usecs to wait for.
136
void newtDelay(int usecs) {
139
diff -ruN newt-0.51.6-old/peanuts.py newt-0.51.6/peanuts.py
140
--- newt-0.51.6-old/peanuts.py 1999-07-13 16:40:07 +0100
141
+++ newt-0.51.6/peanuts.py 2004-07-11 12:25:36 +0100
145
+# Demo program to show use of python-newt module
149
screen = SnackScreen()
150
diff -ruN newt-0.51.6-old/snack.py newt-0.51.6/snack.py
151
--- newt-0.51.6-old/snack.py 2003-02-05 07:11:35 +0000
152
+++ newt-0.51.6/snack.py 2004-07-11 12:25:36 +0100
154
# The second section contains convenience classes that amalgamate
155
# the literal classes and make them more object-oriented.
158
+This module provides the NEWT Windowing toolkit API for Python
159
+This is a lightweight text-mode windowing library, based on slang.
167
+ - SingleRadioButton
187
+ - ListboxChoiceWindow
188
+ - ButtonChoiceWindow
196
snackArgs = {"append":-1}
199
+ """Base class for NEWT toolkit
204
+ - setCallback(self, obj, data = None) :
205
+ The callback for when object activated.
206
+ data is passed to obj.
208
def setCallback(self, obj, data = None):
210
self.w.setCallback(obj, data)
212
self.w.setCallback(obj)
218
class Button(Widget):
219
+ """Basic button class, takes button text as parameter
223
+ - Button(self, text): returns a button
225
def __init__(self, text):
226
- self.w = _snack.button(text)
227
+ self.w = _snack.button(text)
229
class CompactButton(Widget):
230
+ """Compact Button class (less frilly button decoration).
234
+ - CompactButton(self,text) : create button, with text.
236
def __init__(self, text):
237
- self.w = _snack.compactbutton(text)
238
+ self.w = _snack.compactbutton(text)
240
class Checkbox(Widget):
245
+ - Checkbox(self, text, isOn = 0) : text, and boolean as to default value
246
+ - setValue(self) : set value
247
+ - value(self, value) : return checkbox value
248
+ - selected(self) : returns boolean
249
+ - setFlags(self, flag, sense) : set flags
251
+ flags: FLAG_DISABLED, FLAGS_SET, FLAGS_RESET
254
- return self.w.checkboxValue
255
+ return self.w.checkboxValue
258
- return self.w.checkboxValue != 0
259
+ return self.w.checkboxValue != 0
261
def setFlags (self, flag, sense):
263
return self.w.checkboxSetFlags(flag, sense)
265
def setValue (self, value):
266
return self.w.checkboxSetValue(value)
268
def __init__(self, text, isOn = 0):
269
- self.w = _snack.checkbox(text, isOn)
270
+ self.w = _snack.checkbox(text, isOn)
272
class SingleRadioButton(Widget):
273
+ """Single Radio Button.
277
+ - SingleRadioButton(text, group, isOn = 0) : create button
278
+ - selected(self) : returns bool, whether or not is selected.
282
- return self.w.key == self.w.radioValue;
283
+ return self.w.key == self.w.radioValue;
285
def __init__(self, text, group, isOn = 0):
287
- self.w = _snack.radiobutton(text, group.w, isOn)
289
- self.w = _snack.radiobutton(text, None, isOn)
291
+ self.w = _snack.radiobutton(text, group.w, isOn)
293
+ self.w = _snack.radiobutton(text, None, isOn)
295
class Listbox(Widget):
300
+ - Listbox(self,height, scroll = 0l returnExit = 0, width = 0, showCursor = 0)
301
+ - insert(self, text, item, before) : insert element; before = key to item to insert before, or None.
302
+ - delete(self, item) : delete item from list.
303
+ - replace(self, text,item) : Replace a given item's text
304
+ - current(self) : returns currently selected item
305
+ - setCurrent(self,i tem) : select current.
306
+ - clear(self) : clear listbox
309
def append(self, text, item):
310
- key = self.w.listboxAddItem(text)
311
- self.key2item[key] = item
312
- self.item2key[item] = key
313
+ key = self.w.listboxAddItem(text)
314
+ self.key2item[key] = item
315
+ self.item2key[item] = key
317
def insert(self, text, item, before):
319
- key = self.w.listboxInsertItem(text, 0)
321
- key = self.w.listboxInsertItem(text, self.item2key[before])
322
- self.key2item[key] = item
323
- self.item2key[item] = key
325
+ key = self.w.listboxInsertItem(text, 0)
327
+ key = self.w.listboxInsertItem(text, self.item2key[before])
328
+ self.key2item[key] = item
329
+ self.item2key[item] = key
331
def delete(self, item):
332
- self.w.listboxDeleteItem(self.item2key[item])
333
- del self.key2item[self.item2key[item]]
334
- del self.item2key[item]
335
+ self.w.listboxDeleteItem(self.item2key[item])
336
+ del self.key2item[self.item2key[item]]
337
+ del self.item2key[item]
339
def replace(self, text, item):
340
- key = self.w.listboxInsertItem(text, self.item2key[item])
341
- self.w.listboxDeleteItem(self.item2key[item])
342
- del self.key2item[self.item2key[item]]
343
- self.item2key[item] = key
344
- self.key2item[key] = item
345
+ key = self.w.listboxInsertItem(text, self.item2key[item])
346
+ self.w.listboxDeleteItem(self.item2key[item])
347
+ del self.key2item[self.item2key[item]]
348
+ self.item2key[item] = key
349
+ self.key2item[key] = item
352
- return self.key2item[self.w.listboxGetCurrent()]
353
+ return self.key2item[self.w.listboxGetCurrent()]
355
def setCurrent(self, item):
356
- self.w.listboxSetCurrent(self.item2key[item])
357
+ self.w.listboxSetCurrent(self.item2key[item])
361
@@ -105,59 +190,91 @@
362
self.w.listboxClear()
364
def __init__(self, height, scroll = 0, returnExit = 0, width = 0, showCursor = 0):
365
- self.w = _snack.listbox(height, scroll, returnExit, showCursor)
369
- self.w.listboxSetWidth(width)
370
+ self.w = _snack.listbox(height, scroll, returnExit, showCursor)
374
+ self.w.listboxSetWidth(width)
376
class Textbox(Widget):
377
+ """Textbox, container for text.
381
+ - Textbox(self, width, height, scroll = 0, wrap = 0): scroll, wrap are flags
382
+ include scroll bars, or text wrap.
383
+ - setText(text) : set text.
386
def setText(self, text):
387
- self.w.textboxText(text)
388
+ self.w.textboxText(text)
390
def __init__(self, width, height, text, scroll = 0, wrap = 0):
391
- self.w = _snack.textbox(width, height, text, scroll, wrap)
392
+ self.w = _snack.textbox(width, height, text, scroll, wrap)
394
class TextboxReflowed(Textbox):
396
def __init__(self, width, text, flexDown = 5, flexUp = 10, maxHeight = -1):
397
- (newtext, width, height) = reflow(text, width, flexDown, flexUp)
398
+ (newtext, width, height) = reflow(text, width, flexDown, flexUp)
399
if maxHeight != -1 and height > maxHeight:
400
Textbox.__init__(self, width, maxHeight, newtext, 1)
402
Textbox.__init__(self, width, height, newtext, 0)
405
+ """A Label (simple text).
409
+ - Label(self,text) : create label
410
+ - setText(self,text) : change text.
412
def setText(self, text):
413
- self.w.labelText(text)
414
+ self.w.labelText(text)
416
def __init__(self, text):
417
- self.w = _snack.label(text)
418
+ self.w = _snack.label(text)
421
+ """A Scale (progress bar).
425
+ - Scale(self,width, total) : create scale; width: size on screen, fullamount: integer.
426
+ - set(self,amount) : set amount to integer.
428
def set(self, amount):
429
- self.w.scaleSet(amount)
430
+ self.w.scaleSet(amount)
432
def __init__(self, width, total):
433
- self.w = _snack.scale(width, total)
434
+ self.w = _snack.scale(width, total)
441
+ - Entry(self, width, text = "", hidden = 0, password = 0, scroll = 1, returnExit = 0)
442
+ constructor. hidden doesn't show text, password stars it out,
443
+ scroll includes scroll bars;
444
+ if returnExit is set, return from Form when exiting this element, else
445
+ proceed to next entry widget.
446
+ - value(self): return value.
447
+ - set(text) : set the text
448
+ - setFlags (flag, sense) : flags can be FLAG_DISABLED, FLAGS_SET, FLAGS_RESET, FLAGS_TOGGLE
451
- return self.w.entryValue
452
+ return self.w.entryValue
455
- return self.w.entrySetValue(text)
456
+ return self.w.entrySetValue(text)
458
def setFlags (self, flag, sense):
459
return self.w.entrySetFlags(flag, sense)
461
def __init__(self, width, text = "", hidden = 0, password = 0, scroll = 1,
463
- self.w = _snack.entry(width, text, hidden, password, scroll, returnExit)
465
+ self.w = _snack.entry(width, text, hidden, password, scroll, returnExit)
469
@@ -171,44 +288,56 @@
470
hotkeys[hotkeys[n]] = n
473
+ """ Base Form class, from which Grid, etc. inherit
477
+ - Form(self, helpArg = None) : constructor.
478
+ - addHotKey(self, keyname) : keynames of form "F1" through "F12", "ESC"
479
+ - add(self, widget) : Add a widget
480
+ - run(self): run a form, expecting input
481
+ - draw(self): draw form.
482
+ - setTimer(self, timer) : add a timer
483
+ - watchFile(self, file, flags) : watch a named file
484
+ - setCurrent (self, co): Set a given widget as the current focus
486
def addHotKey(self, keyname):
487
- self.w.addhotkey(hotkeys[keyname])
488
+ self.w.addhotkey(hotkeys[keyname])
490
def add(self, widget):
491
- if widget.__dict__.has_key('hotkeys'):
492
- for key in widget.hotkeys.keys():
493
- self.addHotKey(key)
495
- if widget.__dict__.has_key('gridmembers'):
496
- for w in widget.gridmembers:
498
- elif widget.__dict__.has_key('w'):
499
- self.trans[widget.w.key] = widget
500
- return self.w.add(widget.w)
502
+ if widget.__dict__.has_key('hotkeys'):
503
+ for key in widget.hotkeys.keys():
504
+ self.addHotKey(key)
506
+ if widget.__dict__.has_key('gridmembers'):
507
+ for w in widget.gridmembers:
509
+ elif widget.__dict__.has_key('w'):
510
+ self.trans[widget.w.key] = widget
511
+ return self.w.add(widget.w)
515
- (what, which) = self.w.run()
516
- if (what == _snack.FORM_EXIT_WIDGET):
517
- return self.trans[which]
518
- elif (what == _snack.FORM_EXIT_TIMER):
520
- elif (what == _snack.FORM_EXIT_FDREADY):
521
- return self.filemap[which]
522
+ (what, which) = self.w.run()
523
+ if (what == _snack.FORM_EXIT_WIDGET):
524
+ return self.trans[which]
525
+ elif (what == _snack.FORM_EXIT_TIMER):
527
+ elif (what == _snack.FORM_EXIT_FDREADY):
528
+ return self.filemap[which]
530
- return hotkeys[which]
531
+ return hotkeys[which]
539
def __init__(self, helpArg = None):
542
- self.w = _snack.form(helpArg)
543
- # we do the reference count for the helpArg in python! gross
544
- self.helpArg = helpArg
547
+ self.w = _snack.form(helpArg)
548
+ # we do the reference count for the helpArg in python! gross
549
+ self.helpArg = helpArg
551
def setCurrent (self, co):
552
self.w.setcurrent (co.w)
553
@@ -217,67 +346,90 @@
554
self.w.settimer (timer)
556
def watchFile (self, file, flags):
557
- self.filemap[file.fileno()] = file
558
- self.w.watchfd (file.fileno(), flags)
559
+ self.filemap[file.fileno()] = file
560
+ self.w.watchfd (file.fileno(), flags)
567
+ - place(self,x,y): Return what is placed at (x,y)
568
+ - setField(self, what, col, row, padding = (0, 0, 0, 0),
569
+ anchorLeft = 0, anchorTop = 0, anchorRight = 0,
570
+ anchorBottom = 0, growx = 0, growy = 0):
571
+ used to add widget 'what' to grid.
572
+ - Grid(self, *args): eg. g = Grid(2,3) for 2x3 grid
574
def place(self, x, y):
575
- return self.g.place(x, y)
576
+ return self.g.place(x, y)
578
def setField(self, what, col, row, padding = (0, 0, 0, 0),
579
- anchorLeft = 0, anchorTop = 0, anchorRight = 0,
580
- anchorBottom = 0, growx = 0, growy = 0):
581
- self.gridmembers.append(what)
584
- anchorFlags = _snack.ANCHOR_LEFT
585
- elif (anchorRight):
586
- anchorFlags = _snack.ANCHOR_RIGHT
589
- anchorFlags = anchorFlags | _snack.ANCHOR_TOP
590
- elif (anchorBottom):
591
- anchorFlags = anchorFlags | _snack.ANCHOR_BOTTOM
595
- gridFlags = _snack.GRID_GROWX
597
- gridFlags = gridFlags | _snack.GRID_GROWY
599
- if (what.__dict__.has_key('g')):
600
- return self.g.setfield(col, row, what.g, padding, anchorFlags,
603
- return self.g.setfield(col, row, what.w, padding, anchorFlags)
605
+ anchorLeft = 0, anchorTop = 0, anchorRight = 0,
606
+ anchorBottom = 0, growx = 0, growy = 0):
607
+ self.gridmembers.append(what)
610
+ anchorFlags = _snack.ANCHOR_LEFT
611
+ elif (anchorRight):
612
+ anchorFlags = _snack.ANCHOR_RIGHT
615
+ anchorFlags = anchorFlags | _snack.ANCHOR_TOP
616
+ elif (anchorBottom):
617
+ anchorFlags = anchorFlags | _snack.ANCHOR_BOTTOM
621
+ gridFlags = _snack.GRID_GROWX
623
+ gridFlags = gridFlags | _snack.GRID_GROWY
625
+ if (what.__dict__.has_key('g')):
626
+ return self.g.setfield(col, row, what.g, padding, anchorFlags,
629
+ return self.g.setfield(col, row, what.w, padding, anchorFlags)
631
def __init__(self, *args):
632
- self.g = apply(_snack.grid, args)
633
- self.gridmembers = []
634
+ self.g = apply(_snack.grid, args)
635
+ self.gridmembers = []
642
+ - Screen(self) : constructor
646
+ - doHelpCallback(self,arg) call callback with arg
647
+ - helpCallback(self,cb): Set help callback
648
+ - suspendcallback(self,cb, data=None) : set callback. data=data to pass to cb.
649
+ - openWindow(self,left, top, width, height, title): Open a window.
650
+ - pushHelpLine(self,text): put help line on screen. Returns current help line if text=None
654
- (self.width, self.height) = _snack.size()
655
- self.pushHelpLine(None)
657
+ (self.width, self.height) = _snack.size()
658
+ self.pushHelpLine(None)
661
- return _snack.finish()
662
+ return _snack.finish()
672
def doHelpCallback(self, arg):
673
- self.helpCb(self, arg)
675
+ self.helpCb(self, arg)
677
def helpCallback(self, cb):
679
- return _snack.helpcallback(self.doHelpCallback)
681
+ return _snack.helpcallback(self.doHelpCallback)
683
def suspendCallback(self, cb, data = None):
685
@@ -285,228 +437,289 @@
686
return _snack.suspendcallback(cb)
688
def openWindow(self, left, top, width, height, title):
689
- return _snack.openwindow(left, top, width, height, title)
690
+ return _snack.openwindow(left, top, width, height, title)
692
def pushHelpLine(self, text):
694
- return _snack.pushhelpline("*default*")
696
- return _snack.pushhelpline(text)
698
+ return _snack.pushhelpline("*default*")
700
+ return _snack.pushhelpline(text)
702
def popHelpLine(self):
703
- return _snack.pophelpline()
704
+ return _snack.pophelpline()
706
def drawRootText(self, left, top, text):
707
- return _snack.drawroottext(left, top, text)
708
+ return _snack.drawroottext(left, top, text)
710
def centeredWindow(self, width, height, title):
711
- return _snack.centeredwindow(width, height, title)
712
+ return _snack.centeredwindow(width, height, title)
714
def gridWrappedWindow(self, grid, title, x = None, y = None):
716
- return _snack.gridwrappedwindow(grid.g, title, x, y)
718
+ return _snack.gridwrappedwindow(grid.g, title, x, y)
720
- return _snack.gridwrappedwindow(grid.g, title)
721
+ return _snack.gridwrappedwindow(grid.g, title)
724
- return _snack.popwindow()
725
+ return _snack.popwindow()
728
- return _snack.refresh()
729
+ return _snack.refresh()
731
-# returns a tuple of the wrapped text, the actual width, and the actual height
732
def reflow(text, width, flexDown = 5, flexUp = 5):
733
+ """ returns a tuple of the wrapped text, the actual width, and the actual height
735
return _snack.reflow(text, width, flexDown, flexUp)
739
class RadioGroup(Widget):
740
+ """ Combo widget: Group of Radio buttons
744
+ - RadioGroup(self): constructor.
745
+ - add(self,title, value, default = None): add a button. Returns button.
746
+ - getSelection(self) : returns value of selected button | None
750
- self.buttonlist = []
752
+ self.buttonlist = []
754
def add(self, title, value, default = None):
755
- if not self.prev and default == None:
756
- # If the first element is not explicitly set to
757
- # not be the default, make it be the default
759
- b = SingleRadioButton(title, self.prev, default)
761
- self.buttonlist.append((b, value))
763
+ if not self.prev and default == None:
764
+ # If the first element is not explicitly set to
765
+ # not be the default, make it be the default
767
+ b = SingleRadioButton(title, self.prev, default)
769
+ self.buttonlist.append((b, value))
772
def getSelection(self):
773
- for (b, value) in self.buttonlist:
774
- if b.selected(): return value
776
+ for (b, value) in self.buttonlist:
777
+ if b.selected(): return value
781
class RadioBar(Grid):
782
+ """ Bar of Radio buttons, based on Grid.
786
+ - RadioBar(self, screen, buttonlist) : constructor.
787
+ - getSelection(self): return value of selected button
790
def __init__(self, screen, buttonlist):
793
- self.group = RadioGroup()
794
- Grid.__init__(self, 1, len(buttonlist))
795
- for (title, value, default) in buttonlist:
796
- b = self.group.add(title, value, default)
797
- self.list.append((b, value))
798
- self.setField(b, 0, self.item, anchorLeft = 1)
799
- self.item = self.item + 1
802
+ self.group = RadioGroup()
803
+ Grid.__init__(self, 1, len(buttonlist))
804
+ for (title, value, default) in buttonlist:
805
+ b = self.group.add(title, value, default)
806
+ self.list.append((b, value))
807
+ self.setField(b, 0, self.item, anchorLeft = 1)
808
+ self.item = self.item + 1
810
def getSelection(self):
811
- return self.group.getSelection()
813
+ return self.group.getSelection()
816
# you normally want to pack a ButtonBar with growx = 1
818
class ButtonBar(Grid):
819
+ """ Bar of buttons, based on grid.
823
+ - ButtonBar(screen, buttonlist,buttonlist, compact = 0):
824
+ - buttonPressed(self, result): Takes the widget returned by Form.run and looks to see
825
+ if it was one of the widgets in the ButtonBar.
827
def __init__(self, screen, buttonlist, compact = 0):
831
- Grid.__init__(self, len(buttonlist), 1)
832
- for blist in buttonlist:
833
- if (type(blist) == types.StringType):
835
- value = string.lower(blist)
836
- elif len(blist) == 2:
837
- (title, value) = blist
839
- (title, value, hotkey) = blist
840
- self.hotkeys[hotkey] = value
844
+ Grid.__init__(self, len(buttonlist), 1)
845
+ for blist in buttonlist:
846
+ if (type(blist) == types.StringType):
848
+ value = string.lower(blist)
849
+ elif len(blist) == 2:
850
+ (title, value) = blist
852
+ (title, value, hotkey) = blist
853
+ self.hotkeys[hotkey] = value
856
b = CompactButton(title)
859
- self.list.append((b, value))
860
- self.setField(b, self.item, 0, (1, 0, 1, 0))
861
- self.item = self.item + 1
863
- def buttonPressed(self, result):
864
- """Takes the widget returned by Form.run and looks to see
865
- if it was one of the widgets in the ButtonBar."""
867
- if self.hotkeys.has_key(result):
868
- return self.hotkeys[result]
870
- for (button, value) in self.list:
871
- if result == button:
874
+ self.list.append((b, value))
875
+ self.setField(b, self.item, 0, (1, 0, 1, 0))
876
+ self.item = self.item + 1
878
+ def buttonPressed(self, result):
879
+ if self.hotkeys.has_key(result):
880
+ return self.hotkeys[result]
882
+ for (button, value) in self.list:
883
+ if result == button:
888
class GridFormHelp(Grid):
889
+ """ Subclass of Grid, for the help form text.
893
+ - GridFormHelp(self, screen, title, help, *args) :
894
+ - add (self, widget, col, row, padding = (0, 0, 0, 0),
895
+ anchorLeft = 0, anchorTop = 0, anchorRight = 0,
896
+ anchorBottom = 0, growx = 0, growy = 0):
897
+ - runOnce(self, x = None, y = None): pop up the help window
898
+ - addHotKey(self, keyname):
899
+ - setTimer(self, keyname):
900
+ - create(self, x = None, y = None):
901
+ - run(self, x = None, y = None):
904
+ - setCurrent (self, co):
906
def __init__(self, screen, title, help, *args):
907
- self.screen = screen
909
- self.form = Form(help)
910
- self.childList = []
911
- self.form_created = 0
914
- apply(Grid.__init__, tuple(args))
915
+ self.screen = screen
917
+ self.form = Form(help)
918
+ self.childList = []
919
+ self.form_created = 0
922
+ apply(Grid.__init__, tuple(args))
924
def add(self, widget, col, row, padding = (0, 0, 0, 0),
925
anchorLeft = 0, anchorTop = 0, anchorRight = 0,
926
anchorBottom = 0, growx = 0, growy = 0):
927
- self.setField(widget, col, row, padding, anchorLeft,
928
- anchorTop, anchorRight, anchorBottom,
930
- self.childList.append(widget)
931
+ self.setField(widget, col, row, padding, anchorLeft,
932
+ anchorTop, anchorRight, anchorBottom,
934
+ self.childList.append(widget)
936
def runOnce(self, x = None, y = None):
937
- result = self.run(x, y)
938
- self.screen.popWindow()
940
+ result = self.run(x, y)
941
+ self.screen.popWindow()
944
def addHotKey(self, keyname):
945
- self.form.addHotKey(keyname)
946
+ self.form.addHotKey(keyname)
948
def setTimer(self, keyname):
949
- self.form.setTimer(keyname)
950
+ self.form.setTimer(keyname)
952
def create(self, x = None, y = None):
953
- if not self.form_created:
955
- for child in self.childList:
956
- self.form.add(child)
957
- self.screen.gridWrappedWindow(self, self.title, x, y)
958
- self.form_created = 1
959
+ if not self.form_created:
961
+ for child in self.childList:
962
+ self.form.add(child)
963
+ self.screen.gridWrappedWindow(self, self.title, x, y)
964
+ self.form_created = 1
966
def run(self, x = None, y = None):
968
- return self.form.run()
970
+ return self.form.run()
974
- return self.form.draw()
977
+ return self.form.draw()
981
- self.screen.gridWrappedWindow(self, self.title)
982
- result = self.form.run()
983
- self.screen.popWindow()
986
+ self.screen.gridWrappedWindow(self, self.title)
987
+ result = self.form.run()
988
+ self.screen.popWindow()
991
def setCurrent (self, co):
992
self.form.setCurrent (co)
994
class GridForm(GridFormHelp):
995
+ """ GridForm class (extends GridFormHelp):
999
+ - GridForm(self, screen, title, *args):
1001
def __init__(self, screen, title, *args):
1002
- myargs = (self, screen, title, None) + args
1003
- apply(GridFormHelp.__init__, myargs)
1004
+ myargs = (self, screen, title, None) + args
1005
+ apply(GridFormHelp.__init__, myargs)
1007
class CheckboxTree(Widget):
1008
- def append(self, text, item = None, selected = 0):
1009
- self.addItem(text, (snackArgs['append'], ), item, selected)
1010
+ """ CheckboxTree combo widget,
1014
+ - CheckboxTree(self, height, scroll = 0, width = None, hide_checkbox = 0, unselectable = 0)
1016
+ - append(self, text, item = None, selected = 0):
1017
+ - addItem(self, text, path, item = None, selected = 0):
1018
+ - getCurrent(self):
1019
+ - getSelection(self):
1020
+ - setEntry(self, item, text):
1021
+ - setCurrent(self, item):
1022
+ - setEntryValue(self, item, selected = 1):
1023
+ - getEntryValue(self, item):
1025
+ def append(self, text, item = None, selected = 0):
1026
+ self.addItem(text, (snackArgs['append'], ), item, selected)
1028
def addItem(self, text, path, item = None, selected = 0):
1031
- key = self.w.checkboxtreeAddItem(text, path, selected)
1032
- self.key2item[key] = item
1033
- self.item2key[item] = key
1036
+ key = self.w.checkboxtreeAddItem(text, path, selected)
1037
+ self.key2item[key] = item
1038
+ self.item2key[item] = key
1040
def getCurrent(self):
1041
- curr = self.w.checkboxtreeGetCurrent()
1042
- return self.key2item[curr]
1043
+ curr = self.w.checkboxtreeGetCurrent()
1044
+ return self.key2item[curr]
1046
def __init__(self, height, scroll = 0, width = None, hide_checkbox = 0, unselectable = 0):
1047
- self.w = _snack.checkboxtree(height, scroll, hide_checkbox, unselectable)
1048
- self.key2item = {}
1049
- self.item2key = {}
1051
- self.w.checkboxtreeSetWidth(width)
1052
+ self.w = _snack.checkboxtree(height, scroll, hide_checkbox, unselectable)
1053
+ self.key2item = {}
1054
+ self.item2key = {}
1056
+ self.w.checkboxtreeSetWidth(width)
1058
def getSelection(self):
1060
list = self.w.checkboxtreeGetSelection()
1062
selection.append(self.key2item[key])
1066
def setEntry(self, item, text):
1067
- self.w.checkboxtreeSetEntry(self.item2key[item], text)
1068
+ self.w.checkboxtreeSetEntry(self.item2key[item], text)
1070
def setCurrent(self, item):
1071
- self.w.checkboxtreeSetCurrent(self.item2key[item])
1072
+ self.w.checkboxtreeSetCurrent(self.item2key[item])
1074
def setEntryValue(self, item, selected = 1):
1075
- self.w.checkboxtreeSetEntryValue(self.item2key[item], selected)
1076
+ self.w.checkboxtreeSetEntryValue(self.item2key[item], selected)
1078
def getEntryValue(self, item):
1079
- return self.w.checkboxtreeGetEntryValue(self.item2key[item])
1080
+ return self.w.checkboxtreeGetEntryValue(self.item2key[item])
1082
def ListboxChoiceWindow(screen, title, text, items,
1083
- buttons = ('Ok', 'Cancel'),
1084
- width = 40, scroll = 0, height = -1, default = None,
1086
+ buttons = ('Ok', 'Cancel'),
1087
+ width = 40, scroll = 0, height = -1, default = None,
1090
+ - ListboxChoiceWindow(screen, title, text, items,
1091
+ buttons = ('Ok', 'Cancel'),
1092
+ width = 40, scroll = 0, height = -1, default = None,
1095
if (height == -1): height = len(items)
1097
bb = ButtonBar(screen, buttons)
1098
@@ -514,22 +727,22 @@
1099
l = Listbox(height, scroll = scroll, returnExit = 1)
1102
- if (type(item) == types.TupleType):
1103
- (text, key) = item
1108
- if (default == count):
1110
- elif (default == item):
1112
+ if (type(item) == types.TupleType):
1113
+ (text, key) = item
1118
- l.append(text, key)
1120
+ if (default == count):
1122
+ elif (default == item):
1125
+ l.append(text, key)
1128
if (default != None):
1129
- l.setCurrent (default)
1130
+ l.setCurrent (default)
1132
g = GridFormHelp(screen, title, help, 1, 3)
1134
@@ -541,8 +754,13 @@
1135
return (bb.buttonPressed(rc), l.current())
1137
def ButtonChoiceWindow(screen, title, text,
1138
- buttons = [ 'Ok', 'Cancel' ],
1139
- width = 40, x = None, y = None, help = None):
1140
+ buttons = [ 'Ok', 'Cancel' ],
1141
+ width = 40, x = None, y = None, help = None):
1143
+ - ButtonChoiceWindow(screen, title, text,
1144
+ buttons = [ 'Ok', 'Cancel' ],
1145
+ width = 40, x = None, y = None, help = None):
1147
bb = ButtonBar(screen, buttons)
1148
t = TextboxReflowed(width, text, maxHeight = screen.height - 12)
1150
@@ -552,28 +770,32 @@
1151
return bb.buttonPressed(g.runOnce(x, y))
1153
def EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
1154
- entryWidth = 20, buttons = [ 'Ok', 'Cancel' ], help = None):
1155
+ entryWidth = 20, buttons = [ 'Ok', 'Cancel' ], help = None):
1157
+ EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
1158
+ entryWidth = 20, buttons = [ 'Ok', 'Cancel' ], help = None):
1160
bb = ButtonBar(screen, buttons);
1161
t = TextboxReflowed(width, text)
1173
- if (type(n) == types.TupleType):
1176
- e = Entry(entryWidth)
1178
- sg.setField(Label(n), 0, count, padding = (0, 0, 1, 0), anchorLeft = 1)
1179
- sg.setField(e, 1, count, anchorLeft = 1)
1181
- entryList.append(e)
1182
+ if (type(n) == types.TupleType):
1185
+ e = Entry(entryWidth)
1187
+ sg.setField(Label(n), 0, count, padding = (0, 0, 1, 0), anchorLeft = 1)
1188
+ sg.setField(e, 1, count, anchorLeft = 1)
1190
+ entryList.append(e)
1192
g = GridFormHelp(screen, title, help, 1, 3)
1194
@@ -586,106 +808,122 @@
1198
- entryValues.append(entryList[count].value())
1200
+ entryValues.append(entryList[count].value())
1203
return (bb.buttonPressed(result), tuple(entryValues))
1205
class CListbox(Grid):
1206
- def __init__(self, height, cols, col_widths, scroll = 0,
1207
- returnExit = 0, width = 0, col_pad = 1,
1208
- col_text_align = None, col_labels = None,
1209
- col_label_align = None, adjust_width=0):
1212
- self.col_widths = col_widths[:]
1213
- self.col_pad = col_pad
1214
- self.col_text_align = col_text_align
1216
- if col_labels != None:
1217
- Grid.__init__(self, 1, 2)
1219
+ """Clistbox convenience class.
1223
- lstr = self.colFormText(col_labels, col_label_align,
1224
+ - Clistbox(self, height, cols, cols_widths, scroll = 0) : constructor
1225
+ - colFormText(self, col_text, align = None, adjust_width = 0) : column text.
1226
+ - append(self, col_text, item, col_text_align = None) :
1227
+ - insert(self, col_text, item, before, col_text_align = None)
1228
+ - delete(self, item)
1229
+ - replace(self, col_text, item, col_text_align = None)
1230
+ - current(self) : returns current item
1231
+ - setCurrent(self, item): sets an item as current
1232
+ - clear(self): clear the listbox
1234
+ Alignments may be LEFT, RIGHT, CENTER, None
1236
+ def __init__(self, height, cols, col_widths, scroll = 0,
1237
+ returnExit = 0, width = 0, col_pad = 1,
1238
+ col_text_align = None, col_labels = None,
1239
+ col_label_align = None, adjust_width=0):
1242
+ self.col_widths = col_widths[:]
1243
+ self.col_pad = col_pad
1244
+ self.col_text_align = col_text_align
1246
+ if col_labels != None:
1247
+ Grid.__init__(self, 1, 2)
1250
+ lstr = self.colFormText(col_labels, col_label_align,
1251
adjust_width=adjust_width)
1252
- self.label = Label(lstr)
1253
- self.setField(self.label, 0, 0, anchorLeft=1)
1254
+ self.label = Label(lstr)
1255
+ self.setField(self.label, 0, 0, anchorLeft=1)
1258
+ Grid.__init__(self, 1, 1)
1263
- Grid.__init__(self, 1, 1)
1267
- self.listbox = Listbox(height, scroll, returnExit, width)
1268
- self.setField(self.listbox, 0, box_y, anchorRight=1)
1270
- def colFormText(self, col_text, align = None, adjust_width=0):
1273
- c_len = len(col_text)
1274
- while (i < self.cols) and (i < c_len):
1276
- cstr = col_text[i]
1277
- cstrlen = _snack.wstrlen(cstr)
1278
- if self.col_widths[i] < cstrlen:
1280
- self.col_widths[i] = cstrlen
1282
- cstr = cstr[:self.col_widths[i]]
1283
+ self.listbox = Listbox(height, scroll, returnExit, width)
1284
+ self.setField(self.listbox, 0, box_y, anchorRight=1)
1286
- delta = self.col_widths[i] - _snack.wstrlen(cstr)
1287
+ def colFormText(self, col_text, align = None, adjust_width=0):
1290
+ c_len = len(col_text)
1291
+ while (i < self.cols) and (i < c_len):
1293
+ cstr = col_text[i]
1294
+ cstrlen = _snack.wstrlen(cstr)
1295
+ if self.col_widths[i] < cstrlen:
1297
+ self.col_widths[i] = cstrlen
1299
+ cstr = cstr[:self.col_widths[i]]
1301
+ delta = self.col_widths[i] - _snack.wstrlen(cstr)
1310
- cstr = cstr + (" " * delta)
1312
- cstr = (" " * (delta / 2)) + cstr + \
1313
- (" " * ((delta + 1) / 2))
1315
- cstr = (" " * delta) + cstr
1317
- if i != c_len - 1:
1318
- pstr = (" " * self.col_pad)
1322
- str = str + cstr + pstr
1328
- def append(self, col_text, item, col_text_align = None):
1329
- if col_text_align == None:
1330
- col_text_align = self.col_text_align
1331
- text = self.colFormText(col_text, col_text_align)
1332
- self.listbox.append(text, item)
1334
- def insert(self, col_text, item, before, col_text_align = None):
1335
- if col_text_align == None:
1336
- col_text_align = self.col_text_align
1337
- text = self.colFormText(col_text, col_text_align)
1338
- self.listbox.insert(text, item, before)
1340
- def delete(self, item):
1341
- self.listbox.delete(item)
1343
- def replace(self, col_text, item, col_text_align = None):
1344
- if col_text_align == None:
1345
- col_text_align = self.col_text_align
1346
- text = self.colFormText(col_text, col_text_align)
1347
- self.listbox.replace(text, item)
1355
+ cstr = cstr + (" " * delta)
1357
+ cstr = (" " * (delta / 2)) + cstr + \
1358
+ (" " * ((delta + 1) / 2))
1360
+ cstr = (" " * delta) + cstr
1362
+ if i != c_len - 1:
1363
+ pstr = (" " * self.col_pad)
1367
+ str = str + cstr + pstr
1373
+ def append(self, col_text, item, col_text_align = None):
1374
+ if col_text_align == None:
1375
+ col_text_align = self.col_text_align
1376
+ text = self.colFormText(col_text, col_text_align)
1377
+ self.listbox.append(text, item)
1379
+ def insert(self, col_text, item, before, col_text_align = None):
1380
+ if col_text_align == None:
1381
+ col_text_align = self.col_text_align
1382
+ text = self.colFormText(col_text, col_text_align)
1383
+ self.listbox.insert(text, item, before)
1385
+ def delete(self, item):
1386
+ self.listbox.delete(item)
1388
+ def replace(self, col_text, item, col_text_align = None):
1389
+ if col_text_align == None:
1390
+ col_text_align = self.col_text_align
1391
+ text = self.colFormText(col_text, col_text_align)
1392
+ self.listbox.replace(text, item)
1394
- def current(self):
1395
- return self.listbox.current()
1396
+ def current(self):
1397
+ return self.listbox.current()
1399
- def setCurrent(self, item):
1400
- self.listbox.setCurrent(item)
1401
+ def setCurrent(self, item):
1402
+ self.listbox.setCurrent(item)
1405
self.listbox.clear()
1406
diff -ruN newt-0.51.6-old/whiptail.1 newt-0.51.6/whiptail.1
1407
--- newt-0.51.6-old/whiptail.1 1970-01-01 01:00:00 +0100
1408
+++ newt-0.51.6/whiptail.1 2004-07-11 12:25:36 +0100
1410
+.TH WHIPTAIL 1 "20 September 2003" "Whiptail Version 0.51"
1412
+whiptail \- display dialog boxes from shell scripts
1427
+.B \-\-default\-item
1447
+.B \-\-separate\-output
1455
+is a program that will let you to present a variety of questions or
1456
+display messages using dialog boxes from a shell script. Currently,
1457
+these types of dialog boxes are implemented:
1459
+.BR yes/no " box," " menu" " box," " input" " box,"
1460
+.BR message " box," " text" " box," " info" " box,"
1461
+.BR checklist " box," " radiolist" " box" " gauge" " box, and"
1462
+.BR password " box."
1466
+The screen will be cleared to the
1467
+.BR "screen attribute" " on exit."
1468
+This doesn't work in an xterm (and descendants) if alternate screen
1469
+switching is enabled, because in that case slang writes to (and clears)
1470
+an alternate screen.
1473
+The dialog box will open with the cursor over the
1476
+.B \-\-default\-item "string"
1477
+Set the default item in a menu box.
1478
+Normally the first item in the box is the default.
1481
+Use full buttons. (By default,
1483
+uses compact buttons).
1486
+The dialog box won't have a
1487
+.BR Cancel " button".
1490
+The menu, checklist and radiolist widgets will display tags only, not
1493
+.BI \-\-separate\-output
1494
+For checklist widgets, output result one line at a time, with no
1495
+quoting. This facilitates parsing by another program.
1497
+.BI \-\-output\-fd " fd"
1498
+Direct output to the given file descriptor. Most
1501
+write to the standard error, but error messages may also be
1502
+written there, depending on your script.
1504
+.BI \-\-title " title"
1507
+string to be displayed at the top of the dialog box.
1509
+.BI \-\-backtitle " backtitle"
1512
+string to be displayed on the backdrop, at the top of the screen.
1515
+Force the display of a vertical scrollbar.
1519
+.BI \-\-yesno " text height width"
1520
+.RB A " yes/no" " dialog box of size"
1524
+columns will be displayed. The string specified by
1526
+is displayed inside the dialog box. If this string is too long to be fitted
1527
+in one line, it will be automatically divided into multiple lines at
1528
+appropriate places. The
1530
+string may also contain the sub-string
1533
+or newline characters
1535
+to control line breaking explicitly. This dialog box is useful for
1536
+asking questions that require the user to answer either yes or no.
1537
+.RB "The dialog box has a" " Yes" " button and a " No
1538
+button, in which the user can switch between by pressing the
1541
+.BI \-\-msgbox " text height width"
1542
+.RB A " message" " box is very similar to a" " yes/no" " box."
1543
+The only difference between a
1549
+box has only a single
1551
+button. You can use this dialog box to display any message you like.
1552
+After reading the message, the user can press the
1556
+will exit and the calling shell script can continue its operation.
1558
+.BI \-\-infobox " text height width"
1559
+.RB An " info" " box is basically a" " message" " box."
1560
+However, in this case,
1562
+will exit immediately after displaying the message to the user. The
1563
+screen is not cleared when
1565
+exits, so that the message will remain on the screen until the calling
1566
+shell script clears it later. This is useful when you want to inform
1567
+the user that some operations are carrying on that may require some
1570
+.BI \-\-inputbox " text height width [init]"
1571
+.RB "An " input " box is useful when you want to ask questions that"
1572
+require the user to input a string as the answer. If init is supplied
1573
+it is used to initialize the input string.
1577
+key can be used to correct typing errors. If the input string is longer than
1578
+can be fitted in the dialog box, the input field will be scrolled. On exit,
1579
+the input string will be printed on
1582
+.BI \-\-passwordbox " text height width [init]"
1583
+.RB "A " password " box is similar to an input box, except the text the user"
1584
+enters is not displayed. This is useful when prompting for passwords or other
1585
+sensative information. Be aware that if anything is passed in "init", it
1586
+will be visible in the system's process table to casual snoopers. Also, it
1587
+is very confusing to the user to provide them with a default password they
1588
+cannot see. For these reasons, using "init" is highly discouraged.
1590
+.BI \-\-textbox " file height width"
1591
+.RB A " text" " box lets you display the contents of a text file in a"
1592
+dialog box. It is like a simple text file viewer. The user can move
1593
+through the file by using the
1594
+.IR UP/DOWN ", " PGUP/PGDN
1595
+.RI and " HOME/END" " keys available on most keyboards."
1596
+If the lines are too long to be displayed in the box, the
1598
+keys can be used to scroll the text region horizontally. For more
1599
+convenience, forward and backward searching functions are also provided.
1600
+.IP "\fB\-\-menu \fItext height width menu-height \fR[ \fItag item \fR] \fI..."
1601
+As its name suggests, a
1603
+box is a dialog box that can be used to present a list of choices in
1604
+the form of a menu for the user to choose. Each menu entry consists of a
1605
+.IR tag " string and an " item " string. The"
1607
+gives the entry a name to distinguish it from the other entries in the
1610
+is a short description of the option that the entry represents. The
1611
+user can move between the menu entries by pressing the
1613
+keys, the first letter of the
1615
+as a hot-key, or the number keys
1616
+.IR 1-9 ". There are"
1618
+entries displayed in the menu at one time, but the menu will be
1619
+scrolled if there are more entries than that. When
1623
+of the chosen menu entry will be printed on
1625
+.IP "\fB\-\-checklist \fItext height width list-height \fR[ \fItag item status \fR] \fI..."
1626
+.RB "A " checklist " box is similar to a " menu " box in that there are"
1627
+multiple entries presented in the form of a menu.
1628
+You may select an item using the SPACEW key. Instead of choosing
1629
+one entry among the entries, each entry can be turned on or off by the
1630
+user. The initial on/off state of each entry is specified by
1632
+On exit, a list of the
1634
+strings of those entries that are turned on will be printed on
1637
+.IP "\fB\-\-radiolist \fItext height width list-height \fR [ \fItag item status \fR] \fI..."
1638
+.RB "A " radiolist " box is similar to a " menu " box. The only difference is"
1639
+that you can indicate which entry is currently selected, by setting its
1640
+.IR status " to " on "."
1642
+.IP "\fB\-\-gauge \fItext height width percent\fR"
1643
+.RB "A " gauge " box displays a meter along the bottom of the box.
1644
+The meter indicates the percentage. New percentages are read from
1645
+standard input, one integer per line. The meter is updated
1646
+to reflect each new percentage. If stdin is XXX, then subsequent
1647
+lines up to another XXX are used for a new prompt.
1648
+The gauge exits when EOF is reached on stdin.
1651
+Exit status is 0 if
1652
+.BR whiptail " is exited by pressing the " Yes " or " OK
1653
+button, and 1 if the
1654
+.BR No " or " Cancel
1655
+button is pressed. Otherwise, if errors occur inside
1659
+is exited by pressing the
1661
+key, the exit status is -1.
1663
+Based on the man page for dialog(1) by:
1665
+Savio Lam (lam836@cs.cuhk.hk) - version 0.3
1667
+Stuart Herbert (S.Herbert@sheffield.ac.uk) - patch for version 0.4
1669
+Modifications for whiptail by:
1671
+Enrique Zanardi (ezanard@debian.org)
1673
+Alastair McKinstry (mckinstry@debian.org)