003 File Manager
Current Path:
/usr/src/contrib/dialog/samples
usr
/
src
/
contrib
/
dialog
/
samples
/
📁
..
📄
README
(274 B)
📄
buildlist
(460 B)
📄
buildlist2
(675 B)
📄
calendar
(229 B)
📄
calendar-stdout
(215 B)
📄
calendar2
(221 B)
📄
calendar2-stdout
(207 B)
📄
calendar3
(280 B)
📄
calendar3-stdout
(266 B)
📄
checklist
(1004 B)
📄
checklist-8bit
(1.28 KB)
📄
checklist-utf8
(1.08 KB)
📄
checklist1
(980 B)
📄
checklist10
(815 B)
📄
checklist11
(1.2 KB)
📄
checklist12
(1.11 KB)
📄
checklist2
(1.24 KB)
📄
checklist3
(1.54 KB)
📄
checklist4
(1.55 KB)
📄
checklist5
(1.67 KB)
📄
checklist6
(1.76 KB)
📄
checklist7
(1.79 KB)
📄
checklist8
(1.63 KB)
📄
checklist9
(209 B)
📄
checklist9.txt
(1.44 KB)
📁
copifuncs
📄
debian.rc
(2.88 KB)
📄
dft-cancel
(147 B)
📄
dft-extra
(145 B)
📄
dft-help
(143 B)
📄
dft-no
(131 B)
📄
dialog.py
(10.68 KB)
📄
dselect
(213 B)
📄
editbox
(1.01 KB)
📄
editbox-utf8
(852 B)
📄
editbox2
(1.05 KB)
📄
editbox3
(300 B)
📄
editbox4
(1.02 KB)
📄
form1
(1.39 KB)
📄
form1-both
(1.3 KB)
📄
form1-extra
(1.29 KB)
📄
form1-help
(1.28 KB)
📄
form1-utf8
(1.31 KB)
📄
form2
(2.14 KB)
📄
form3
(1.32 KB)
📄
form4
(1.39 KB)
📄
form5
(1.41 KB)
📄
form6
(1.41 KB)
📄
fselect
(214 B)
📄
fselect-stdout
(199 B)
📄
fselect0
(210 B)
📄
fselect1
(322 B)
📄
fselect1-stdout
(308 B)
📄
fselect2
(212 B)
📄
fselect2-stdout
(198 B)
📄
gauge
(285 B)
📄
gauge0
(292 B)
📄
gauge0-input-fd
(390 B)
📄
gauge2
(468 B)
📄
infobox
(501 B)
📄
infobox1
(501 B)
📄
infobox2
(500 B)
📄
infobox3
(515 B)
📄
infobox4
(515 B)
📄
infobox5
(766 B)
📄
infobox6
(861 B)
📄
inputbox
(565 B)
📄
inputbox-both
(604 B)
📄
inputbox-extra
(588 B)
📄
inputbox-help
(586 B)
📄
inputbox1
(562 B)
📄
inputbox2
(565 B)
📄
inputbox3
(586 B)
📄
inputbox4
(645 B)
📄
inputbox5
(640 B)
📄
inputbox6-8bit
(272 B)
📄
inputbox6-utf8
(268 B)
📄
inputbox7
(768 B)
📄
inputmenu
(1.46 KB)
📄
inputmenu-stdout
(1.44 KB)
📄
inputmenu1
(1.5 KB)
📄
inputmenu2
(1.73 KB)
📄
inputmenu3
(1.93 KB)
📄
inputmenu4
(1.5 KB)
📁
install
📄
killall
(364 B)
📄
listing
(101 B)
📄
menubox
(835 B)
📄
menubox-8bit
(981 B)
📄
menubox-utf8
(860 B)
📄
menubox1
(857 B)
📄
menubox10
(417 B)
📄
menubox11
(953 B)
📄
menubox12
(981 B)
📄
menubox2
(858 B)
📄
menubox3
(1.08 KB)
📄
menubox4
(1.26 KB)
📄
menubox5
(1.55 KB)
📄
menubox6
(1.19 KB)
📄
menubox7
(1.14 KB)
📄
menubox8
(886 B)
📄
menubox9
(715 B)
📄
mixedform
(1.23 KB)
📄
mixedform2
(1.24 KB)
📄
mixedgauge
(580 B)
📄
msgbox
(352 B)
📄
msgbox-help
(374 B)
📄
msgbox-utf8
(346 B)
📄
msgbox1
(1.54 KB)
📄
msgbox2
(1.54 KB)
📄
msgbox3
(574 B)
📄
msgbox4-8bit
(739 B)
📄
msgbox4-eucjp
(805 B)
📄
msgbox4-utf8
(1019 B)
📄
msgbox5
(654 B)
📄
msgbox6
(456 B)
📄
msgbox6a
(511 B)
📄
password
(570 B)
📄
password1
(585 B)
📄
password2
(592 B)
📄
passwordform1
(1.29 KB)
📄
passwordform1-utf8
(1.33 KB)
📄
pause
(181 B)
📄
pause-both
(244 B)
📄
pause-extra
(228 B)
📄
pause-help
(206 B)
📄
prgbox
(165 B)
📄
prgbox2
(168 B)
📄
programbox
(306 B)
📄
programbox2
(320 B)
📄
progress
(301 B)
📄
progress2
(357 B)
📄
radiolist
(1015 B)
📄
radiolist1
(1.23 KB)
📄
radiolist10
(815 B)
📄
radiolist2
(1.04 KB)
📄
radiolist3
(1.25 KB)
📄
radiolist4
(1.28 KB)
📄
rangebox
(226 B)
📄
rangebox2
(225 B)
📄
rangebox3
(228 B)
📄
rangebox4
(228 B)
📄
report-button
(446 B)
📄
report-edit
(464 B)
📄
report-string
(520 B)
📄
report-tempfile
(544 B)
📄
report-yesno
(433 B)
📄
rotated-data
(369 B)
📄
run_test.sh
(908 B)
📄
setup-edit
(258 B)
📄
setup-tempfile
(214 B)
📄
setup-utf8
(198 B)
📄
setup-vars
(545 B)
📄
shortlist
(319 B)
📄
slackware.rc
(2.85 KB)
📄
sourcemage.rc
(2.82 KB)
📄
suse.rc
(2.84 KB)
📄
tailbox
(241 B)
📄
tailboxbg
(443 B)
📄
tailboxbg1
(757 B)
📄
tailboxbg2
(770 B)
📄
testdata-8bit
(959 B)
📄
textbox
(1.09 KB)
📄
textbox-both
(379 B)
📄
textbox-help
(361 B)
📄
textbox.txt
(785 B)
📄
textbox2
(1.08 KB)
📄
textbox3
(358 B)
📄
timebox
(263 B)
📄
timebox-stdout
(212 B)
📄
timebox2
(217 B)
📄
timebox2-stdout
(204 B)
📄
treeview
(394 B)
📄
treeview2
(853 B)
📄
wheel
(3.87 KB)
📄
whiptail.rc
(2.82 KB)
📄
with-dquotes
(105 B)
📄
with-squotes
(112 B)
📄
yesno
(758 B)
📄
yesno-both
(892 B)
📄
yesno-extra
(876 B)
📄
yesno-help
(739 B)
📄
yesno-utf8
(212 B)
📄
yesno2
(592 B)
📄
yesno3
(605 B)
📄
yesno4
(593 B)
Editing: dialog.py
#!/usr/bin/python # $Id: dialog.py,v 1.4 2012/06/29 09:33:18 tom Exp $ # Module: dialog.py # Copyright (c) 2000 Robb Shecter <robb@acm.org> # All rights reserved. # This source is covered by the GNU GPL. # # This module is a Python wrapper around the Linux "dialog" utility # by Savio Lam and Stuart Herbert. My goals were to make dialog as # easy to use from Python as possible. The demo code at the end of # the module is a good example of how to use it. To run the demo, # execute: # # python dialog.py # # This module has one class in it, "Dialog". An application typically # creates an instance of it, and possibly sets the background title option. # Then, methods can be called on it for interacting with the user. # # I wrote this because I want to use my 486-33 laptop as my main # development computer (!), and I wanted a way to nicely interact with the # user in console mode. There are apparently other modules out there # with similar functionality, but they require the Python curses library. # Writing this module from scratch was easier than figuring out how to # recompile Python with curses enabled. :) # # One interesting feature is that the menu and selection windows allow # *any* objects to be displayed and selected, not just strings. # # TO DO: # Add code so that the input buffer is flushed before a dialog box is # shown. This would make the UI more predictable for users. This # feature could be turned on and off through an instance method. # Drop using temporary files when interacting with 'dialog' # (it's possible -- I've already tried :-). # Try detecting the terminal window size in order to make reasonable # height and width defaults. Hmmm - should also then check for # terminal resizing... # Put into a package name to make more reusable - reduce the possibility # of name collisions. # # NOTES: # there is a bug in (at least) Linux-Mandrake 7.0 Russian Edition # running on AMD K6-2 3D that causes core dump when 'dialog' # is running with --gauge option; # in this case you'll have to recompile 'dialog' program. # # Modifications: # Jul 2000, Sultanbek Tezadov (http://sultan.da.ru) # Added: # - 'gauge' widget *) # - 'title' option to some widgets # - 'checked' option to checklist dialog; clicking "Cancel" is now # recognizable # - 'selected' option to radiolist dialog; clicking "Cancel" is now # recognizable # - some other cosmetic changes and improvements # import os from tempfile import mktemp from string import split from time import sleep # # Path of the dialog executable # DIALOG = os.getenv("DIALOG"); if DIALOG is None: DIALOG="../dialog"; class Dialog: def __init__(self): self.__bgTitle = '' # Default is no background title def setBackgroundTitle(self, text): self.__bgTitle = '--backtitle "%s"' % text def __perform(self, cmd): """Do the actual work of invoking dialog and getting the output.""" fName = mktemp() rv = os.system('%s %s %s 2> %s' % (DIALOG, self.__bgTitle, cmd, fName)) f = open(fName) output = f.readlines() f.close() os.unlink(fName) return (rv, output) def __perform_no_options(self, cmd): """Call dialog w/out passing any more options. Needed by --clear.""" return os.system(DIALOG + ' ' + cmd) def __handleTitle(self, title): if len(title) == 0: return '' else: return '--title "%s" ' % title def yesno(self, text, height=10, width=30, title=''): """ Put a Yes/No question to the user. Uses the dialog --yesno option. Returns a 1 or a 0. """ (code, output) = self.__perform(self.__handleTitle(title) +\ '--yesno "%s" %d %d' % (text, height, width)) return code == 0 def msgbox(self, text, height=10, width=30, title=''): """ Pop up a message to the user which has to be clicked away with "ok". """ self.__perform(self.__handleTitle(title) +\ '--msgbox "%s" %d %d' % (text, height, width)) def infobox(self, text, height=10, width=30): """Make a message to the user, and return immediately.""" self.__perform('--infobox "%s" %d %d' % (text, height, width)) def inputbox(self, text, height=10, width=30, init='', title=''): """ Request a line of input from the user. Returns the user's input or None if cancel was chosen. """ (c, o) = self.__perform(self.__handleTitle(title) +\ '--inputbox "%s" %d %d "%s"' % (text, height, width, init)) try: return o[0] except IndexError: if c == 0: # empty string entered return '' else: # canceled return None def textbox(self, filename, height=20, width=60, title=None): """Display a file in a scrolling text box.""" if title is None: title = filename self.__perform(self.__handleTitle(title) +\ ' --textbox "%s" %d %d' % (filename, height, width)) def menu(self, text, height=15, width=54, list=[]): """ Display a menu of options to the user. This method simplifies the --menu option of dialog, which allows for complex arguments. This method receives a simple list of objects, and each one is assigned a choice number. The selected object is returned, or None if the dialog was canceled. """ menuheight = height - 8 pairs = map(lambda i, item: (i + 1, item), range(len(list)), list) choices = reduce(lambda res, pair: res + '%d "%s" ' % pair, pairs, '') (code, output) = self.__perform('--menu "%s" %d %d %d %s' %\ (text, height, width, menuheight, choices)) try: return list[int(output[0]) - 1] except IndexError: return None def checklist(self, text, height=15, width=54, list=[], checked=None): """ Returns a list of the selected objects. Returns an empty list if nothing was selected. Returns None if the window was canceled. checked -- a list of boolean (0/1) values; len(checked) must equal len(list). """ if checked is None: checked = [0]*len(list) menuheight = height - 8 triples = map( lambda i, item, onoff, fs=('off', 'on'): (i + 1, item, fs[onoff]), range(len(list)), list, checked) choices = reduce(lambda res, triple: res + '%d "%s" %s ' % triple, triples, '') (c, o) = self.__perform('--checklist "%s" %d %d %d %s' %\ (text, height, width, menuheight, choices)) try: output = o[0] indexList = map(lambda x: int(x[1:-1]), split(output)) objectList = filter(lambda item, list=list, indexList=indexList: list.index(item) + 1 in indexList, list) return objectList except IndexError: if c == 0: # Nothing was selected return [] return None # Was canceled def radiolist(self, text, height=15, width=54, list=[], selected=0): """ Return the selected object. Returns empty string if no choice was selected. Returns None if window was canceled. selected -- the selected item (must be between 1 and len(list) or 0, meaning no selection). """ menuheight = height - 8 triples = map(lambda i, item: (i + 1, item, 'off'), range(len(list)), list) if selected: i, item, tmp = triples[selected - 1] triples[selected - 1] = (i, item, 'on') choices = reduce(lambda res, triple: res + '%d "%s" %s ' % triple, triples, '') (c, o) = self.__perform('--radiolist "%s" %d %d %d %s' %\ (text, height, width, menuheight, choices)) try: return list[int(o[0]) - 1] except IndexError: if c == 0: return '' return None def clear(self): """ Clear the screen. Equivalent to the dialog --clear option. """ self.__perform_no_options('--clear') def scrollbox(self, text, height=20, width=60, title=''): """ This is a bonus method. The dialog package only has a function to display a file in a scrolling text field. This method allows any string to be displayed by first saving it in a temp file, and calling --textbox. """ fName = mktemp() f = open(fName, 'w') f.write(text) f.close() self.__perform(self.__handleTitle(title) +\ '--textbox "%s" %d %d' % (fName, height, width)) os.unlink(fName) def gauge_start(self, perc=0, text='', height=8, width=54, title=''): """ Display gauge output window. Gauge normal usage (assuming that there is an instace of 'Dialog' class named 'd'): d.gauge_start() # do something d.gauge_iterate(10) # passed throgh 10% # ... d.gauge_iterate(100, 'any text here') # work is done d.stop_gauge() # clean-up actions """ cmd = self.__handleTitle(title) +\ '--gauge "%s" %d %d %d' % (text, height, width, perc) cmd = '%s %s %s 2> /dev/null' % (DIALOG, self.__bgTitle, cmd) self.pipe = os.popen(cmd, 'w') #/gauge_start() def gauge_iterate(self, perc, text=''): """ Update percentage point value. See gauge_start() function above for the usage. """ if text: text = 'XXX\n%d\n%s\nXXX\n' % (perc, text) else: text = '%d\n' % perc self.pipe.write(text) self.pipe.flush() #/gauge_iterate() def gauge_stop(self): """ Finish previously started gauge. See gauge_start() function above for the usage. """ self.pipe.close() #/gauge_stop() # # DEMO APPLICATION # if __name__ == '__main__': """ This demo tests all the features of the class. """ d = Dialog() d.setBackgroundTitle('dialog.py demo') d.infobox( "One moment... Just wasting some time here to test the infobox...") sleep(3) if d.yesno("Do you like this demo?"): d.msgbox("Excellent! Here's the source code:") else: d.msgbox("Send your complaints to /dev/null") d.textbox("dialog.py") name = d.inputbox("What's your name?", init="Snow White") fday = d.menu("What's your favorite day of the week?", list=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday (The best day of all)", "Saturday", "Sunday"]) food = d.checklist("What sandwich toppings do you like?", list=["Catsup", "Mustard", "Pesto", "Mayonaise", "Horse radish", "Sun-dried tomatoes"], checked=[0,0,0,1,1,1]) sand = d.radiolist("What's your favorite kind of sandwich?", list=["Hamburger", "Hotdog", "Burrito", "Doener", "Falafel", "Bagel", "Big Mac", "Whopper", "Quarter Pounder", "Peanut Butter and Jelly", "Grilled cheese"], selected=4) # Prepare the message for the final window bigMessage = "Here are some vital statistics about you:\n\nName: " + name +\ "\nFavorite day of the week: " + fday +\ "\nFavorite sandwich toppings:\n" for topping in food: bigMessage = bigMessage + " " + topping + "\n" bigMessage = bigMessage + "Favorite sandwich: " + str(sand) d.scrollbox(bigMessage) #<># Gauge Demo d.gauge_start(0, 'percentage: 0', title='Gauge Demo') for i in range(1, 101): if i < 50: msg = 'percentage: %d' % i elif i == 50: msg = 'Over 50%' else: msg = '' d.gauge_iterate(i, msg) sleep(0.1) d.gauge_stop() #<># d.clear()
Upload File
Create Folder