pax_global_header00006660000000000000000000000064116763417240014525gustar00rootroot0000000000000052 comment=88b52a8a6010463caac5dd5052514fb25f2c3307 python-vsgui-0.3.3/000077500000000000000000000000001167634172400142045ustar00rootroot00000000000000python-vsgui-0.3.3/MANIFEST.in000066400000000000000000000001211167634172400157340ustar00rootroot00000000000000include * recursive-include example *.txt *.py exclude .gitignore MANIFEST *.swp python-vsgui-0.3.3/PKG-INFO000066400000000000000000000116411167634172400153040ustar00rootroot00000000000000Metadata-Version: 1.1 Name: vsgui Version: 0.3.3 Summary: Very Simple Graphical library for Python shell script Home-page: UNKNOWN Author: Hsin-Yi Chen 陳信屹 (hychen) Author-email: ossug.hychen@gmail.com License: BSD-2-clause License Description: VSGUI - Very Simple Graphic Interface Library for Python ======================================================== Description ----------- It proides a simple functions to comuunicate with `zenity` which is a program that will display GTK+ dialogs, and return (either in the return code, or on standard output) the users input. This allows you to present information, and ask for information from the user, from all manner of shell scripts. Requirement ----------- * Python >=2.5 * Python UCLTIP module >= 0.6-1 (http://pypi.python.org/pypi/ucltip) * Zenity How To install -------------- for Ubuntu Users :: $ apt-get install python-ucltip for Debian Users :: $ apt-get install zenity $ apt-get install python-ucltip VSGUI is not in Debian/Ubuntu archive. right now please use `setup.py` to install How To Use ---------- The source code includes some examples which are in example directory, so you can take a qucik look before you start coding, and thre are two part of this library as below 1. High Level API functions --------------------------- Before start, you need to import api funcitons: :: from vsgui.api import * Dialogs :: from vsgui.api import * # information dialog info(msg) # warring dialog warning(msg): # error dialog error(msg): # error dialog and terminate script die(msg): # notice dialog (does not work in Unity) notice(msg): Input Text :: # input text ask_text(text, initial=None) # input password, ask_passwd(text) # check password # # - 1234 is the password we except user to type # - 5 means user can try to input 5 times if the password is wrong # - password is wrong is just a error message shows in an error dialog check_passwd('1234', 5, 'password is wrong') Questions :: # ask user the anwser is yes or no ask_yesno(text, y=None, n=None): # ask user select a or b ask_ab(text, a, b): # ask user passowrd, and check it check_passwd(wanted, count=3, text='', errmsg='wrong password, try again!') Progress ------- :: # launch a progress bar and create a update function update = progress('downloading files') # update progress bar message ot 'md5sum checking' and progessive number to 90 update(90, 'md5sum checking') # launch a progress bar pulsate_progress('starting') File ---- :: # ask user to select a file path ask_filepath() # ask user to select multiple file paths ask_filepaths() # ask user to select a directory path ask_dirpath() # ask user to select multiple directory paths ask_dirpaths() Other ----- ask_scalevalue('label') 2. Zenity Class --------------- if api functions is not enough, you can use Zenity class direcly to get more powerful feature. :: from vsgui.zenity import Zenity z = Zenity() # same as executing 'zenity --file-selection --filename=a.txt' z.file_selection(filename='a.txt') Get invlolved ============= if you are interesting to help, please contact author, Hychen, his email is . The VCS of code is avaliabl on http://github.com/hychen/vsgui Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Topic :: Software Development :: Libraries :: Python Modules Requires: ucltip(>=0.6) python-vsgui-0.3.3/README.txt000066400000000000000000000057371167634172400157160ustar00rootroot00000000000000VSGUI - Very Simple Graphic Interface Library for Python ======================================================== Description ----------- It proides a simple functions to comuunicate with `zenity` which is a program that will display GTK+ dialogs, and return (either in the return code, or on standard output) the users input. This allows you to present information, and ask for information from the user, from all manner of shell scripts. Requirement ----------- * Python >=2.5 * Python UCLTIP module >= 0.6-1 (http://pypi.python.org/pypi/ucltip) * Zenity How To install -------------- for Ubuntu Users :: $ apt-get install python-ucltip for Debian Users :: $ apt-get install zenity $ apt-get install python-ucltip VSGUI is not in Debian/Ubuntu archive. right now please use `setup.py` to install How To Use ---------- The source code includes some examples which are in example directory, so you can take a qucik look before you start coding, and thre are two part of this library as below 1. High Level API functions --------------------------- Before start, you need to import api funcitons: :: from vsgui.api import * Dialogs :: from vsgui.api import * # information dialog info(msg) # warring dialog warning(msg): # error dialog error(msg): # error dialog and terminate script die(msg): # notice dialog (does not work in Unity) notice(msg): Input Text :: # input text ask_text(text, initial=None) # input password, ask_passwd(text) # check password # # - 1234 is the password we except user to type # - 5 means user can try to input 5 times if the password is wrong # - password is wrong is just a error message shows in an error dialog check_passwd('1234', 5, 'password is wrong') Questions :: # ask user the anwser is yes or no ask_yesno(text, y=None, n=None): # ask user select a or b ask_ab(text, a, b): # ask user passowrd, and check it check_passwd(wanted, count=3, text='', errmsg='wrong password, try again!') Progress ------- :: # launch a progress bar and create a update function update = progress('downloading files') # update progress bar message ot 'md5sum checking' and progessive number to 90 update(90, 'md5sum checking') # launch a progress bar pulsate_progress('starting') File ---- :: # ask user to select a file path ask_filepath() # ask user to select multiple file paths ask_filepaths() # ask user to select a directory path ask_dirpath() # ask user to select multiple directory paths ask_dirpaths() Other ----- ask_scalevalue('label') 2. Zenity Class --------------- if api functions is not enough, you can use Zenity class direcly to get more powerful feature. :: from vsgui.zenity import Zenity z = Zenity() # same as executing 'zenity --file-selection --filename=a.txt' z.file_selection(filename='a.txt') Get invlolved ============= if you are interesting to help, please contact author, Hychen, his email is . The VCS of code is avaliabl on http://github.com/hychen/vsgui python-vsgui-0.3.3/VERSION.txt000066400000000000000000000000061167634172400160660ustar00rootroot000000000000000.3.3 python-vsgui-0.3.3/__init__.py000066400000000000000000000000001167634172400163030ustar00rootroot00000000000000python-vsgui-0.3.3/example/000077500000000000000000000000001167634172400156375ustar00rootroot00000000000000python-vsgui-0.3.3/example/example_api.py000066400000000000000000000027051167634172400205010ustar00rootroot00000000000000# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 #!/usr/bin/env python # -*- encoding=utf8 -*- # # Author 2011 Hsin-Yi Chen # # This is a 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 software 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 software; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA from vsgui.api import * # the backed is zenity by default info("this is a information dialog") warning("this is a warning dialog") error("this is a error dialog") ret=ask_text("This is a input dialog", "please input some thing") while not ask_yesno("Do you input {0}".format(ret), 'sure', 'not this one'): pass update=progress("processing text....") import time update(20, "setp 1") time.sleep(1) update(40, "setp 2") time.sleep(1) update(60, "setp 3") time.sleep(1) update(80, "setp 4") time.sleep(1) update(100, "Done") ask_scalevalue('scale') ask_ab('hi', 'M' , 'F') # file info(ask_filepath()) ask_filepaths() ask_dirpath() ask_dirpaths() python-vsgui-0.3.3/setup.py000077500000000000000000000020051167634172400157160ustar00rootroot00000000000000#!/usr/bin/env python # -*- encoding=utf8 -*- # # Copyright © 2010 Hsin Yi Chen from distutils.core import setup setup( name = 'vsgui', requires = ['ucltip(>=0.6)'], version = open('VERSION.txt').read().strip(), description = 'Very Simple Graphical library for Python shell script', long_description=open('README.txt').read(), author = 'Hsin-Yi Chen 陳信屹 (hychen)', author_email = 'ossug.hychen@gmail.com', license = 'BSD-2-clause License', packages=['vsgui'], classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules", ] ) python-vsgui-0.3.3/vsgui/000077500000000000000000000000001167634172400153415ustar00rootroot00000000000000python-vsgui-0.3.3/vsgui/__init__.py000066400000000000000000000000001167634172400174400ustar00rootroot00000000000000python-vsgui-0.3.3/vsgui/api.py000066400000000000000000000056521167634172400164740ustar00rootroot00000000000000# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 #!/usr/bin/env python # -*- encoding=utf8 -*- # # Author 2011 Hsin-Yi Chen import ucltip from vsgui import zenity from vsgui.utils import deprecated try: _dialoger = zenity.Zenity() except ucltip.CommandNotFound, e: print e exit() # Dialog # --------------------------------------------- def info(msg): _dialoger.info(text=msg) def warning(msg): _dialoger.warning(text=msg) def error(msg): _dialoger.error(text=msg) def die(msg): error(msg) exit() def notice(msg): _dialoger.notification(text=msg) # Inpit text #------------------------------------------------------------- def ask_text(text, initial=None): kdws = { 'text':text, } if initial: kdws['entry-text'] = initial return _dialoger.entry(**kdws) @deprecated(ask_text) def input_text(*args, **kwargs): pass def ask_passwd(text): kdws = { 'text':'please input password: '+ '\n' + text, 'hide-text':True } return _dialoger.entry(**kdws) @deprecated(ask_passwd) def input_passwd(): pass # Question #------------------------------------------------------------- def ask_yesno(text, y=None, n=None): kdws = {'text':text} if y: kdws['ok-label'] = y if n: kdws['cancel-label'] = n return _dialoger.question(**kdws) @deprecated(ask_yesno) def input_yesno(): pass def ask_ab(text, a, b): if ask_yesno(text, y=a,n=b): return a return b @deprecated(ask_ab) def input_ab(text, a, b): pass def check_passwd(wanted, count=3, text='', errmsg='wrong password, try again!'): for i in range(1, count): if (ask_passwd(text) != wanted): die(errmsg) if i == count else error(errmsg) else: return True # progress #------------------------------------------------------------- def pulsate_progress(text, auto_close=False, auto_kill=False): return _dialoger.progress(text=text, auto_close=auto_close, auto_kill=auto_kill, pulsate=True) def progress(text, auto_close=False, auto_kill=False): return _dialoger.progress(text=text, auto_close=auto_close, auto_kill=auto_kill) def ask_scalevalue(label, initial_value=0, **kwargs): return _dialoger.scale(text=label, value=initial_value, **kwargs) # file #------------------------------------------------------------- def first_or_none(list): try: return list[0] except IndexError: return None def ask_filepath(**kwargs): return first_or_none(ask_filepaths(**kwargs)) def ask_filepaths(**kwargs): kwargs['multiple'] = True return _dialoger.file_selection(**kwargs) def ask_dirpath(**kwargs): return first_or_none(ask_dirpaths(**kwargs)) def ask_dirpaths(**kwargs): kwargs['directory'] = True kwargs['multiple'] = True return _dialoger.file_selection(**kwargs) python-vsgui-0.3.3/vsgui/utils.py000066400000000000000000000037251167634172400170620ustar00rootroot00000000000000import os import warnings import functools # enable to show warring warnings.simplefilter('default') def deprecated(replacement=None): """This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. ref: - recipe-391367-1 on active stack code - recipe-577819-1 on active stack code @replacement function replacement function """ def wrapper(old_func): wrapped_func = replacement and replacement or old_func @functools.wraps(wrapped_func) def new_func(*args, **kwargs): msg = "Call to deprecated function %(funcname)s." % { 'funcname': old_func.__name__} if replacement: msg += "; use {} instead".format(replacement.__name__) warnings.warn_explicit(msg, category=DeprecationWarning, filename=old_func.func_code.co_filename, lineno=old_func.func_code.co_firstlineno + 1 ) return wrapped_func(*args, **kwargs) return new_func return wrapper def parse_kwds(kwds, extra): """parse options from kwds @return filtered kwds, options """ opts = {} for k in extra: opts[k] = kwds.get(k) try: del(kwds[k]) except KeyError: pass return kwds, opts def savefile(filename, content, backup='.bak'): """save file @param filename path of filename @param content content of file @param backup extention of backup filename, default is .bak (optional) """ if backup: os.system("cp %s %s%s" % (filename, filename, backup)) with open(filename, 'r') as old: oldstr = old.read() with open(filename, 'w') as new: newstr = content if newstr != oldstr: new.write(newstr) if __name__ == '__main__': kwds = {'save':True,'nono':'oo'} print parse_kwds(kwds, ['save']) python-vsgui-0.3.3/vsgui/zenity.py000066400000000000000000000143341167634172400172420ustar00rootroot00000000000000import datetime import os import subprocess from vsgui import utils import ucltip class Zenity(ucltip.CmdDispatcher): """ To communicate with Zenity in Python Zenity is a program that will display GTK+ dialogs, and return (either in the return code, or on standard output) the users input. This allows you to present information, and ask for information from the user, from all manner of shell scripts. Here is the concept, more method could be found in `zenity --help` zenity.info() maps to `zenity --info` zenity.info(text="hello") maps to `zenity --info --text='hello' """ def __init__(self): super(Zenity, self).__init__('zenity') self.subcmd_prefix = '--' self.conf.opt_style = 'gnu' setattr(self, 'entry', lambda *args, **kwargs: self.__call('entry', *args, **kwargs)) setattr(self, 'error', lambda *args, **kwargs: self.__call('error', *args, **kwargs)) setattr(self, 'info', lambda *args, **kwargs: self.__call('info', *args, **kwargs)) setattr(self, 'notification', lambda *args, **kwargs: self.__call('notification', *args, **kwargs)) setattr(self, 'warning', lambda *args, **kwargs: self.__call('warning', *args, **kwargs)) def calendar(self, *args, **kwds): """display calendar dialog @param text=TEXT Set the dialog text @param selected_day=DAY Set the calendar day @param date_format=PATTERN Set the format for the returned date @return datetime.date """ (_kwds, opts) = utils.parse_kwds(kwds, ['selected_day']) selected = opts.get('selected_day') if selected: _kwds['day'] = selected.day _kwds['month'] = selected.month _kwds['year'] = selected.year retval = self.__call('calendar', *args, **_kwds) if self.conf.dry_run: return retval if retval: (month, day, year) = map(int, retval.split('/')) return datetime.date(year, month, day) def question(self, *args, **kdws): """display question dialog @param text title text @param y text of OK label @param n text of Cancel label @return True or False """ kdws['with_extend_output'] = True retval = self.__call('question', *args, **kdws) return not retval[0] def text_info(self, *args, **kwds): """dispaly Display text information dialog @param save save the content in current file @param backup extenion of backup filename @return content content user inputed """ (_kwds, opts) = utils.parse_kwds(kwds, ['save', 'backup']) content = self.__call('text-info', *args, **_kwds) if opts.get('save') and _kwds.get('filename'): utils.savefile(_kwds.get('filename'), content, backup=opts.get('backup')) return content def progress(self, *args, **kwds): """display progress dialog @param text=TEXT Set the dialog text @param percentage=PERCENTAGE Set initial percentage @param pulsate Pulsate progress bar @param auto_close Dismiss the dialog when 100% has been reached @param auto_kill Kill parent process if cancel button is pressed @return update function callable function to update dialog @example update = zenity.progress(text="Download Script") update("10", "starting") time.sleep(1) update("20", "closing") time.sleep(1) """ kwds['stdin'] = subprocess.PIPE p = self.__call('progress', as_process=True, *args, **kwds) def update(percent, message=''): if type(percent) == float: percent = int(percent * 100) try: p.stdin.write(str(percent) + '\n') if message: p.stdin.write('# %s\n' % message) except IOError: exit() return p.returncode return update def file_selection(self, *args, **kwds): """display file or directory selection dialog @return list of selection path of files or directories """ retstr = self.__call('file-selection', *args, **kwds) return [] if not retstr else retstr.strip().split('|') def list(self, columns, data=[], **kwds): """display selection dialog @param columns @param data data of cells , its size must be equal to the number of columns @return list """ args = [] for col in columns: args.append("--column=%s" % col) args += data retstr = self.__call('list', *args, **kwds) if kwds.get('checklist'): return [] if not retstr else retstr.split('|') return retstr def scale(self, *args, **kwargs): """Display scale dialog @return int scale value """ ret = self.__call('scale', *args, **kwargs) if ret: return int(ret) else: raise Exception def __call(self, name, *args, **kwargs): if name[:1] == '_': raise AttributeError(name) try: method = self._subcmds.setdefault(name, ucltip.SubCmd(name, self)) except KeyError: raise AttributeError else: try: ret = method(*args, **kwargs) return ret.replace('\n','') if type(ret) is str else ret except ucltip.CommandExecutedError, e: if e.errmsg: print e.errmsg return False if __name__ == '__main__': obj = Zenity() import datetime import time #print obj.error(text='hi') #print obj.question() #print obj.text_info() print obj.calendar(selected_day=datetime.date(2015,3,25)) #up= obj.progress() #up(30,'hi') #time.sleep(1) #up(40, 'no') print obj.list(('a','b'), [1,2,3,4], checklist=True)