mirror of
https://github.com/erkin/ponysay.git
synced 2025-02-18 02:24:21 +01:00
split out logic for converting png files
Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
parent
d6dc284e60
commit
3bee0c375e
1 changed files with 18 additions and 7 deletions
|
@ -872,6 +872,23 @@ class Ponysay():
|
||||||
print('%s %s' % ('ponysay', VERSION))
|
print('%s %s' % ('ponysay', VERSION))
|
||||||
|
|
||||||
|
|
||||||
|
def __useImage(self, pony):
|
||||||
|
'''
|
||||||
|
Convert image to the ponysay format if it is a regular image
|
||||||
|
|
||||||
|
@param pony:str The pony file
|
||||||
|
@param pony:str The new pony file, or the old if it was already in the ponysay format
|
||||||
|
'''
|
||||||
|
if endswith(pony.lower(), '.png'):
|
||||||
|
pony = '\'' + pony.replace('\'', '\'\\\'\'') + '\''
|
||||||
|
pngcmd = 'ponytool --import image --file %s --balloon n --export ponysay --platform %s --balloon y'
|
||||||
|
pngcmd %= (pony, ('linux' if self.linuxvt else 'xterm')) # XXX xterm should be haiku in Haiku
|
||||||
|
pngpipe = os.pipe()
|
||||||
|
Popen(pngcmd, stdout=os.fdopen(pngpipe[1], 'w'), shell=True).wait()
|
||||||
|
pony = '/proc/' + str(os.getpid()) + '/fd/' + str(pngpipe[0])
|
||||||
|
return pony
|
||||||
|
|
||||||
|
|
||||||
def printPony(self, args):
|
def printPony(self, args):
|
||||||
'''
|
'''
|
||||||
Print the pony with a speech or though bubble. message, pony and wrap from args are used.
|
Print the pony with a speech or though bubble. message, pony and wrap from args are used.
|
||||||
|
@ -932,13 +949,7 @@ class Ponysay():
|
||||||
printinfo('pony file: ' + pony)
|
printinfo('pony file: ' + pony)
|
||||||
|
|
||||||
## Use PNG file as pony file
|
## Use PNG file as pony file
|
||||||
if endswith(pony.lower(), '.png'):
|
pony = self.__useImage(pony)
|
||||||
pony = '\'' + pony.replace('\'', '\'\\\'\'') + '\''
|
|
||||||
pngcmd = 'ponytool --import image --file %s --balloon n --export ponysay --platform %s --balloon y'
|
|
||||||
pngcmd %= (pony, ('linux' if self.linuxvt else 'xterm')) # XXX xterm should be haiku in Haiku
|
|
||||||
pngpipe = os.pipe()
|
|
||||||
Popen(pngcmd, stdout=os.fdopen(pngpipe[1], 'w'), shell=True).wait()
|
|
||||||
pony = '/proc/' + str(os.getpid()) + '/fd/' + str(pngpipe[0])
|
|
||||||
|
|
||||||
## If KMS is utilies, select a KMS pony file and create it if necessary
|
## If KMS is utilies, select a KMS pony file and create it if necessary
|
||||||
pony = KMS.kms(pony, self.HOME, self.linuxvt)
|
pony = KMS.kms(pony, self.HOME, self.linuxvt)
|
||||||
|
|
Loading…
Reference in a new issue