Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /leo/plugins/

leo
Discussion topic

Back to topic list

CVS update: /leo/plugins/

Author plumloco
Full name Robert Ledger
Date 2007-09-11 02:32:19 PDT
Message User: plumloco
Date: 2007-09-11 02:32:19-0700
Added:
   leo/plugins/zenity_f​ile_dialogs.py

Modified:
   leo/plugins/__wx_tes​t_drawing_interface.​py

Log:
 Initial commit@ zenity_file_dialogs.py

File Changes:

Directory: /leo/plugins/
========================

File [changed]: __wx_test_drawing_interface.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/__wx_test_dr​awing_interface.py?r​1=1.1&r2=1.2
Delta lines: +2 -2
-------------------
--- __wx_test_drawing_interface.py 2007-09-10 04:18:35-0700 1.1
+++ __wx_test_drawing_interface.py 2007-09-11 02:32:16-0700 1.2
@@ -1,5 +1,5 @@
 #@+leo-ver=4-thin
-#@+node:bob.2007090​9152756:@thin __wx_test_drawing_interface.py
+#@+node:bob.2007091​0154126.1:@thin __wx_test_drawing_interface.py
 #@<< docstring >>
 #@+node:bob.20070909​152633.1:<< docstring >>
 '''This is a test plugin to show how to use the prototype
@@ -230,5 +230,5 @@
 #@-node:bob.20070909​163711:onMouseMyIcon​LeftDown
 #@-others
 #@nonl
-#@-node:bob.2007090​9152756:@thin __wx_test_drawing_interface.py
+#@-node:bob.2007091​0154126.1:@thin __wx_test_drawing_interface.py
 #@-leo

File [added]: zenity_file_dialogs.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/zenity_file_​dialogs.py?rev=1.1​&content-type=text​/vnd.viewcvs-markup
Added lines: 170
----------------
#@+leo-ver=4
#@+node:@file zenity_file_dialogs.py
#@<< docstring >>
#@+node:<< docstring >>

'''Replace the tk file dialogs on linux with external
calls to the zenity gtk dialog package.

This plugin is more a proof of concopt demo than
a useful tool. The dialogs presented do not take
filters and starting folders can not be specified.

Despit this, some linux users might prefer it to the
tk dialogs.
'''
#@-node:<< docstring >>
#@nl

#@@language python
#@@tabwidth -4

__version__ = "0.1"
#@<< version history >>
#@+node:<< version history >>
#@@killcolor
#@+at
#
# 0.1 plumloco: Initial version
#@-at
#@nonl
#@-node:<< version history >>
#@nl
#@<< imports >>
#@+node:<< imports >>
import leoGlobals as g
import leoPlugins

import os

trace = False

try:
    from subprocess import *
    ok = True
except:
    ok = False

if trace:
    if ok:
        print 'subprocess imported ok'
    else:
        g.trace('failed to import subprocess')


#@-node:<< imports >>
#@nl


#@+others
#@+node:testForZenity

def testForZenity():


    command = [ 'which', 'zenity']

    o = Popen(command, stdout=PIPE)
    o.wait()
    filename = o.communicate()[0].rstrip()

    ret = o.returncode

    if trace:
        g.trace('\n\texecutable', repr(filename))
        print '\n\treturncode', ret

    if trace and ret:
        g.trace('\n\tCan\'t find Zenity!')

    return not ret

#@-node:testForZenity
#@+node:init
def init ():

    if ok:
        trace and g.trace('zenity ok')
        leoPlugins.registerH​andler('start2', onStart2)
        g.plugin_signon(__name__)
    else:
        g.trace('failed to load zenity')
    return ok
#@-node:init
#@+node:onStart2
def onStart2 (tag, keywords):

    """
    Replace tkfile open/save method with external calls to zenity.
    """
    trace and g.trace('zenity ok')

    g.funcToMethod(runOp​enFileDialog,g.app.g​ui)
    g.funcToMethod(runSa​veFileDialog,g.app.g​ui)
#@nonl
#@-node:onStart2
#@+node:callZenity
def callZenity(title, multiple=False, save=False, test=False):


    command = [ 'zenity', '--file-selection', '--title=%s'%title]

    if save:
        command.append('--save')

    if multiple:
        command.append('--multiple')


    o = Popen(command, stdout=PIPE)
    o.wait()
    filename = o.communicate()[0].rstrip()

    ret = o.returncode

    if trace:
        g.trace('\n\tfiles', repr(filename))
        print '\treturncode', ret

    if ret:
        trace and g.trace(g.choose(sav​e,'save','open'), 'cancelled')
        return ''

    if multiple:
        return filename.split('|')

    return filename


#@-node:callZenity
#@+node:runOpenFileDialog
def runOpenFileDialog(ti​tle=None,filetypes=N​one,defaultextension​=None,multiple=False​):

    """Call zenity's open file(s) dialog."""

    trace and g.trace()

    initialdir = g.app.globalOpenDir or g.os_path_abspath(os.getcwd())

    return callZenity(title, multiple=multiple)

#@-node:runOpenFileDialog
#@+node:runSaveFileDialog
def runSaveFileDialog(in​itialfile=None,title​=None,filetypes=None​,defaultextension=No​ne):

    """Call zenity's save file dialog."""

    trace and g.trace()

    initialdir=g.app.globalOpenDir or g.os_path_abspath(os.getcwd())

    return callZenity(title, save=True)


#@-node:runSaveFileDialog
#@-others

ok = ok and testForZenity()
trace and g.trace('imported ok')
#@-node:@file zenity_file_dialogs.py
#@-leo

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /leo/plugins/ plumloco Robert Ledger 2007-09-11 02:32:19 PDT
Messages per page: