export slides as PNG files

This commit is contained in:
q
2016-06-16 22:34:35 +03:00
parent e26f16532b
commit 8a3f4b0c7d

View File

@@ -218,6 +218,10 @@ Keyboard shortcuts:
help="Execute commands in `! or `> tags at show time with Enter key. WARNING: Potentially very dangerous to run others' slides with this switch!")
parser.add_argument("-E",action="store_true",dest="execute_read",default=False,
help="Execute commands in $> tags at file read time. WARNING: Potentially very dangerous to run others' slides with this switch!")
parser.add_argument("--exit",action="store_true",dest="exit_last",default=False,
help="Exit after last slide.")
parser.add_argument("--export",action="store",dest="screenshots",default=False,
type=str, help="Take screenshots of the slideshow in the given folder.")
parser.add_argument("-m",action="store_true",dest="autocolor",default=False,
help="Color by markdown structure.")
parser.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
@@ -240,6 +244,10 @@ Keyboard shortcuts:
help="File to show")
opts=parser.parse_args()
opts.slideShow=not not opts.slideTimer
if opts.screenshots:
opts.slideShow=True
opts.slideTimer=1
opts.exit_last=True
return opts
def page_print(reader,opts,offset):
@@ -279,6 +287,7 @@ def page_print(reader,opts,offset):
break
r+=row_lines+1
sys.stdout.write("\n")
sys.stdout.flush()
return
def menu_print(reader,opts):
@@ -338,6 +347,9 @@ def browser(opts,filename):
if opts.menu:
menu_print(reader,opts)
sys.stdout.write(bc.pos(opts.size[0], opts.size[1]))
sys.stdout.flush()
if opts.screenshots:
take_screenshot(reader,opts)
while 1:
if opts.slideTimer and opts.slideShow:
signal.signal(signal.SIGALRM, timeouthandler)
@@ -345,6 +357,9 @@ def browser(opts,filename):
inkey=getkeypress()
signal.alarm(0)
if not inkey and opts.slideShow:
if opts.exit_last:
if reader.page+1==reader.pages:
return
reader.inc_page_no(1,True)
offset=(0,0)
break
@@ -353,6 +368,9 @@ def browser(opts,filename):
#print('Exited in: ')
return
if inkey in [67,54,32]: # PGDN or space
if opts.exit_last:
if reader.page+1==reader.pages:
return
reader.inc_page_no(1)
offset=(0, 0)
if inkey in [68,53,127]:
@@ -385,6 +403,7 @@ def browser(opts,filename):
launch(reader,opts,offset)
break
except IOError:
pass
except KeyboardInterrupt:
@@ -472,6 +491,14 @@ def launch(reader,opts,offset):
shell=True)
return
return
def take_screenshot(reader,opts):
out_file=os.path.join(opts.screenshots,"slide%03d.png"%(reader.page+1))
if not os.path.exists(opts.screenshots):
os.mkdir(opts.screenshots)
subprocess.call("sleep 0.5; import -window $WINDOWID '%s'"%(out_file,),
stdout=subprocess.PIPE,stderr=subprocess.PIPE,
shell=True)
bc=ansi.code()
getch=getch()
opts=setup_options()