Now uses python-newt instead of python-dialog

This commit is contained in:
Nick Barcet 2008-12-21 06:21:35 +01:00
commit 04f7832216
3 changed files with 124 additions and 75 deletions

1
debian/changelog vendored
View file

@ -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 create new windows
* screen-profile-helper allows to select profiles * screen-profile-helper allows to select profiles
* screen-profile-helper allows to install screen by default * screen-profile-helper allows to install screen by default
* Now uses python-newt instead of python-dialog
[ Dustin Kirkland ] [ Dustin Kirkland ]
* created keybindings directory, moved keybindings there * created keybindings directory, moved keybindings there

View file

@ -1,6 +1,6 @@
******************************************** Welcome to GNU Screen Profiles
** Welcome to the screen powered terminal ** ------------------------------
********************************************
The main benefits of the screen program is that your session can have The main benefits of the screen program is that your session can have
multiple windows and keep context between multiple logins. You will also multiple windows and keep context between multiple logins. You will also
notice the task bar at the bottom that informs you of various system notice the task bar at the bottom that informs you of various system

View file

@ -1,6 +1,26 @@
#! /usr/bin/env python #! /usr/bin/env python
#
# GNU screen-profiles-helper
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Nick Barcet <nick.barcet@ubuntu.com>
#
# 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 def ioctl_GWINSZ(fd): #### TABULATION FUNCTIONS
try: ### Discover terminal width try: ### Discover terminal width
@ -26,96 +46,124 @@ def terminal_size(): ### decide on *some* terminal size
cr = (25, 80) cr = (25, 80)
return int(cr[1]-5), int(cr[0]-5) # reverse rows, cols return int(cr[1]-5), int(cr[0]-5) # reverse rows, cols
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)
def handle_exit_code(d, code): g = GridForm(screen, "GNU Screen Profiles Menu", 1, 2)
# d is supposed to be a Dialog instance g.add(li, 0, 0, padding=(4,2,4,2))
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): g.add(bb, 0, 1, padding=(1,1,0,0))
if code == d.DIALOG_CANCEL:
msg = "You chose cancel. Do you want to " \ if bb.buttonPressed(g.runOnce()) == "exit":
"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)
return 0 return 0
else: else:
return 1 # code is d.DIALOG_OK return li.current()
def menu_demo(d, size): def messagebox(screen, width, height, title, text, \
while 1: scroll=0, \
(code, tag) = d.menu( buttons=(("Ok", "ok"),("Cancel", "cancel")) ):
"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 help(d, size): t = Textbox(width, height, text, scroll=scroll )
d.textbox("/usr/share/doc/screen-profiles/help.txt", width=size[0], height=size[1]) 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(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)
def profile(d):
list = []
for choice in commands.getoutput('select-screen-profile -l').splitlines(): for choice in commands.getoutput('select-screen-profile -l').splitlines():
if choice.startswith("ubuntu"): if choice.startswith("ubuntu"):
el = (choice, "<-- recommended", 1) li.append(choice+" <-- recommended", choice)
list.append(el) li.setCurrent(choice)
else: else:
el = (choice, "", 0) li.append(choice, choice)
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")
def newwindow(d): bb = ButtonBar(screen, (("Apply", "apply"), ("Cancel", "cancel")), compact = 1)
(code, answer) = d.inputbox("New window name?", init="bash")
if code == d.DIALOG_OK:
commands.getoutput('screen -t %s' % answer)
def install(d): 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(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(screen, size):
out = commands.getoutput("bash /usr/share/screen-profiles/screen-install") out = commands.getoutput("bash /usr/share/screen-profiles/screen-install")
if out == "": if out == "":
out = "Screen will be launched automatically next time you login." 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(): def main():
"""This is the main loop of our screen helper. """This is the main loop of our screen helper.
""" """
size = terminal_size() size = terminal_size()
screen = SnackScreen()
screen.drawRootText(1,0,"== GNU Screen Profiles Helper ==")
screen.pushHelpLine("<Tab>/<Alt-Tab> between elements | <Return> Validates")
tag = help(screen, size)
try: while tag > 0 :
d = dialog.Dialog(dialog="dialog") tag = menu(screen, size)
d.add_persistent_args(["--backtitle", "GNU Screen profiles helper"]) if tag == 1:
tag = help(screen, size)
help(d, size) elif tag == 2:
tag = profile(screen, size)
while True: elif tag == 3:
tag = menu_demo(d, size) tag = newwindow(screen, size)
if tag == "1": elif tag == 4:
help (d, size) tag = install(screen, 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) sys.exit(0)