diff --git a/debian/changelog b/debian/changelog index 2a9e4179..ae52ce74 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ screen-profiles (1.1-0ubuntu1) jaunty; urgency=low * screen-profile-helper allows to create new windows * screen-profile-helper allows to select profiles * screen-profile-helper allows to install screen by default + * Now uses python-newt instead of python-dialog [ Dustin Kirkland ] * created keybindings directory, moved keybindings there diff --git a/doc/help.txt b/doc/help.txt index 08b4d0bf..3d52bfd1 100644 --- a/doc/help.txt +++ b/doc/help.txt @@ -1,6 +1,6 @@ - ******************************************** - ** Welcome to the screen powered terminal ** - ******************************************** +Welcome to GNU Screen Profiles +------------------------------ + The main benefits of the screen program is that your session can have multiple windows and keep context between multiple logins. You will also notice the task bar at the bottom that informs you of various system diff --git a/screen-profiles-helper b/screen-profiles-helper index b525f482..393be20f 100755 --- a/screen-profiles-helper +++ b/screen-profiles-helper @@ -1,6 +1,26 @@ #! /usr/bin/env python +# +# GNU screen-profiles-helper +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: Nick Barcet +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import sys, os, os.path, time, string, dialog, commands +import sys, os, os.path, time, string, commands +from snack import * def ioctl_GWINSZ(fd): #### TABULATION FUNCTIONS try: ### Discover terminal width @@ -26,96 +46,124 @@ def terminal_size(): ### decide on *some* terminal size cr = (25, 80) return int(cr[1]-5), int(cr[0]-5) # reverse rows, cols - -def handle_exit_code(d, code): - # d is supposed to be a Dialog instance - if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): - if code == d.DIALOG_CANCEL: - msg = "You chose cancel. Do you want to " \ - "exit this program?" - else: - msg = "You pressed ESC. Do you want to " \ - "exit this program?" - # "No" or "ESC" will bring the user back to the demo. - # DIALOG_ERROR is propagated as an exception and caught in main(). - # So we only need to handle OK here. - if d.yesno(msg) == d.DIALOG_OK: - sys.exit(0) +def menu(screen, size): + li = Listbox(height = 4, width = 60, returnExit = 1) + li.append("Help", 1) + li.append("Change screen profile", 2) + li.append("Create new window", 3) + li.append("Install screen by default at login", 4) + bb = ButtonBar(screen, (("Ok", "ok"), ("Exit", "exit")), compact = 1) + + g = GridForm(screen, "GNU Screen Profiles Menu", 1, 2) + g.add(li, 0, 0, padding=(4,2,4,2)) + g.add(bb, 0, 1, padding=(1,1,0,0)) + + if bb.buttonPressed(g.runOnce()) == "exit": return 0 else: - return 1 # code is d.DIALOG_OK + return li.current() -def menu_demo(d, size): - while 1: - (code, tag) = d.menu( - "Please chose an action", - width=size[0], - choices=[("1", "Display some basic help"), - ("2", "Change screen profile"), - ("3", "Create a new window"), - ("4", "Install screen by default at login") - ]) - if handle_exit_code(d, code): - break - return tag +def messagebox(screen, width, height, title, text, \ + scroll=0, \ + buttons=(("Ok", "ok"),("Cancel", "cancel")) ): + + t = Textbox(width, height, text, scroll=scroll ) + bb = ButtonBar(screen, buttons, compact = 1) + g = GridForm(screen, title, 1, 2) + g.add(t, 0, 0, padding=(0,0,0,0)) + g.add(bb, 0, 1, padding=(1,1,0,0)) + + return bb.buttonPressed(g.runOnce()) -def help(d, size): - d.textbox("/usr/share/doc/screen-profiles/help.txt", width=size[0], height=size[1]) - -def profile(d): - list = [] +def help(screen, size): + f=file('/usr/share/doc/screen-profiles/help.txt') + text=f.read() + f.close() + + button = messagebox(screen, 76, 19, "GNU Screen Profiles Help", text, \ + scroll=1, buttons=(("Menu", "menu"), ("Exit", "exit")) ) + + if button == "exit": + return 0 + else: + return 100 + +def profile(screen, size): + li = Listbox(height = 6, width = 60, returnExit = 1) + for choice in commands.getoutput('select-screen-profile -l').splitlines(): if choice.startswith("ubuntu"): - el = (choice, "<-- recommended", 1) - list.append(el) + li.append(choice+" <-- recommended", choice) + li.setCurrent(choice) else: - el = (choice, "", 0) - list.append(el) - (code, tag) = d.radiolist("Which profile would you like to use?", width=65, choices=list) - if code == d.DIALOG_OK: - commands.getoutput('select-screen-profile --set %s' % tag) - d.msgbox("Please press F5 to apply profile") + li.append(choice, choice) + + bb = ButtonBar(screen, (("Apply", "apply"), ("Cancel", "cancel")), compact = 1) + + g = GridForm(screen, "Which profile would you like to use?", 1, 2) + g.add(li, 0, 0, padding=(4,2,4,2)) + g.add(bb, 0, 1, padding=(1,1,0,0)) + + if bb.buttonPressed(g.runOnce()) != "cancel": + commands.getoutput('select-screen-profile --set %s' % li.current()) + button = messagebox(screen, 60, 2, "Message", "Press F5 to apply the new profile", \ + buttons=(("Ok","ok"), ("Exit", "exit")) ) + if button == "exit": + return 0 + + return 100 -def newwindow(d): - (code, answer) = d.inputbox("New window name?", init="bash") - if code == d.DIALOG_OK: - commands.getoutput('screen -t %s' % answer) +def newwindow(screen, size): + title=Entry(8, text="bash", returnExit=1) + titlel=Label("Title: ") + command=Entry(20, text="/bin/bash", returnExit=1) + commandl=Label("Command: ") + bb = ButtonBar(screen, (("Create", "create"), ("Cancel", "cancel")), compact = 1) + g = GridForm(screen, "Create new window:", 2, 3, ) + g.add(titlel, 0, 0, anchorLeft=1,padding=(0,1,0,1)) + g.add(title, 1, 0, anchorLeft=1) + g.add(commandl, 0, 1, anchorLeft=1,padding=(0,0,0,1)) + g.add(command, 1, 1, anchorLeft=1) + g.add(bb, 0, 2, padding=(1,1,0,0)) + + if bb.buttonPressed(g.runOnce()) != "cancel": + commands.getoutput('screen -t %s %s' % (title.value(), command.value()) ) + + return 100 -def install(d): +def install(screen, size): out = commands.getoutput("bash /usr/share/screen-profiles/screen-install") if out == "": out = "Screen will be launched automatically next time you login." - d.msgbox(out) + button = messagebox(screen, 60, 2, "Message", out, \ + buttons=(("Ok","ok"), ("Exit", "exit")) ) + if button == "exit": + return 0 + + return 100 def main(): """This is the main loop of our screen helper. - """ size = terminal_size() + screen = SnackScreen() + screen.drawRootText(1,0,"== GNU Screen Profiles Helper ==") + screen.pushHelpLine("/ between elements | Validates") + tag = help(screen, size) + + while tag > 0 : + tag = menu(screen, size) + if tag == 1: + tag = help(screen, size) + elif tag == 2: + tag = profile(screen, size) + elif tag == 3: + tag = newwindow(screen, size) + elif tag == 4: + tag = install(screen, size) - try: - d = dialog.Dialog(dialog="dialog") - d.add_persistent_args(["--backtitle", "GNU Screen profiles helper"]) - - help(d, size) - - while True: - tag = menu_demo(d, size) - if tag == "1": - help (d, size) - elif tag == "2": - profile(d) - elif tag == "3": - newwindow(d) - elif tag == "4": - install(d) - - except dialog.error, exc_instance: - sys.stderr.write("Error:\n\n%s\n" % exc_instance.complete_message()) - sys.stderr.write("%s\n" % dialog.error) - sys.exit(1) - + screen.finish() sys.exit(0)