KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21573/root/usr/lib/python2.4/site-packages/dogtail/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21573/root/usr/lib/python2.4/site-packages/dogtail/trayicon.py
# jhbuild - a build script for GNOME 1.x and 2.x
# Copyright (C) 2001-2004 James Henstridge
#
#       trayicon.py: simple wrapper for zenity based tray icons
#
# 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., 59 Temple Place, Suite 330, Boston, MA      02111-1307      USA

import sys
import os
try:
    import subprocess
except ImportError:
    # I know, let's add an ugly hack!
    # Don't totally bail when not using python2.4 or newer.
    # FIXME: since we aren't using any new functionality of subprocess, we
    #    could just use the deprecated methods.
    class subprocess:
        PIPE = None
        def Popen(cmd, close_fds, preexec_fn, stdin): return None
        Popen = staticmethod(Popen)



class TrayIcon:
    def __init__(self):
        self._run_zenity()
    def _run_zenity(self):
        # run zenity with stdout and stderr directed to /dev/null
        def preexec():
            null = open('/dev/null', 'w')
            try:
                os.dup2(null.fileno(), sys.stdout.fileno())
                os.dup2(null.fileno(), sys.stderr.fileno())
            finally:
                null.close()
            os.setsid()
        try:
            self.proc = subprocess.Popen(['zenity', '--notification',
                                                                     '--listen'],
                                                                     close_fds=True,
                                                                     preexec_fn=preexec,
                                                                     stdin=subprocess.PIPE)
        except (OSError, IOError):
            self.proc = None

    def close(self):
        status = None
        if self.proc:
            self.proc.stdin.close()
            status = self.proc.wait()
            self.proc = None
        return status

    def _send_cmd(self, cmd):
        if not self.proc: return
        if isinstance(cmd, unicode):
            cmd = cmd.encode('utf-8')
        try:
            self.proc.stdin.write(cmd)
            self.proc.stdin.flush()
        except (IOError, OSError), err:
            self.close()
    def set_icon(self, icon):
        self._send_cmd('icon: %s\n' % icon)

    def set_tooltip(self, tooltip):
        self._send_cmd('tooltip: %s\n' % tooltip)

    def set_visible(self, visible):
        if visible:
            visible = 'true'
        else:
            visible = 'false'
        self._send_cmd('visible: %s\n' % visible)

Anon7 - 2021