keep ghostscript running - even if fed garbage - python

Short version: how can I tell ghostscript, "keep going, even if you find garbage" when running in batch mode?
Longer version: I have a bit of Python code on Windows that uses check_subprocess to call Ghostcript. (I'm merging several PDFs into one).
popenargs = [r'C:\Program Files\gs\gs9.15\bin\gswin64.exe'
,'-dBATCH'
,'-dNOPAUSE'
,'-dLastPage=5'
,'-q'
,'-sDEVICE=pdfwrite'
,r'-sOutputFile=C:\temp\bar.pdf'
,r'c:\temp\a.pdf',r'c:\temp\b.pdf']
subprocess.check_call(args)
While things are running, you see the Ghostcript window pop up and disappear, and that's OK with me.
The problem occurs when ghostscript encounters a corrupted PDF. It leaves the window up, with some details about the error, and instructions to close the window manually. This is problematic, because it leaves the python script hanging. I don't want that -- if an error is found, that's OK with me -- I just want the file skipped and for things to keep moving.
Is there any way to tell Ghostscript to do what I want?

I would have to see an example to say for sure, but the simple answer (on Windows) is no.
You could, of course, use gswin64c.exe instead, its much more suitable for automation anyway.

Related

What does it mean to "restart" a program (in my case IDLE)?

This answer on Stack Overflow offers a solution I am trying to implement. In particular, see the sections "Installation Instructions" and "How to Use".
Can anyone tell me the steps required to "restart" IDLE?
New Information:
Just as people have suggested I thought this simply meant closing the program and opening it back up again...but I already tried that.
The other twist to my situation is that I'm working on a virtual machine so I was unable to do the installation of IDLE2HTML.py myself. My work's Help Desk had to do it so I cannot speak for the accuracy of their work. For now I'm assuming they did it correctly, but when I go to the "Options" menu there is no option to "Save as HTML".
My only guess at this point is that I still need to "restart IDLE".
Just wanted to double check if there was something else I could do before going back to my Help Desk department.
IDLE reads the idlelib/config-xyz.def files, including config-extensions.def, just once, when it starts. So any changes to config-extensions.def only takes effect the next time you start IDLE.
If you do not see 'Save as HTML' after starting IDLE, the extension is not installed properly.
It means you need to close the IDLE so that any changes made by the script can affect the IDLE
Simply close the IDLE either via the X, Ctrl+Q or File>Exit, then open the IDLE again.
If you are using idlelib module from a Python program then close your program and run it again.

PyCharm won't accept code completion on enter

since yesterday PyCharm 2016.3 won't accept selected lines from the list of code completion:
If I hit enter, a new line will be set into the editor rather than the selected line of the popup window. Is there any setting for this behaviour? Until now I couldn't find anything.
I noticed on a few occasions the GUI going somehow off-rails, including in ways similar to the one described. I couldn't determine a pattern in the occurences. Just closing and re-opening the project didn't always help.
What worked pretty reliably for me in the end was exiting PyCharm (giving it ample time to finish), making sure no related java processes remains active (running on Linux, in some cases I had to manually kill such processes when it became clear they're not going away by themselves) and then re-starting the IDE.
I found the current keymap for code completion by chance. This is set via:
Settings > Keymap > Code > Completion > Basic

extend Pyinstaller executable visible range

I had a python code and I used Pyinstaller to make it a stand-alone .exe executable.
In my code, I use "print" function to output result.
However, if the result is really long, (several screen page long) the result is cut short because the limitation of the console, I can scroll up but I guess the total length of the viewable text region is limited. (I am running my .exe in Windows)
Is there a way to extend the visible range so I can see all my output?
Thanks!
================
update:
I agree with #supremefist that it is the shell that is limit the visible range.
Is there a way to pass parameters to the shell so that when I double click it in Windows, the view range is extended.
Also, if it is possible, I would like to have my executable robust across different OSs. I am trying to write a small program and my target users maybe inexperienced computer users.
================
update2:
Now, I understand that Pyinstaller is only for Windows, previous update for different Oss is completely wrong.
The good news is that I switch to Qt and this problem goes away as I am now displaying my result in a window rather than a shell console.
I don't think the limit is related to PyInstaller, but to the constraints being set on your windows shell. You could try changing your shell settings by doing the following:
Open a windows shell by either running 'cmd' or by finding it under Accessories in your Start Menu.
Right click on the title of the shell window and select Properties.
Increase the screen buffer height setting under the 'Layout' tab to a large number. Something like 9999.
Re-run your program, you should see a much longer history of text.

Take all input in Python (like UAC)

Is there any way I can create a UAC-like environment in Python? I want to basically lock the workstation without actually using the Windows lock screen. The user should not be able to do anything except, say, type a password to unlock the workstation.
You cannot do this without cooperation with operating system. Whatever you do, Ctrl-Alt-Del will allow the user to circumvent your lock.
The API call you're looking for Win32-wise is a combination of CreateDesktop and SetThreadDesktop.
In terms of the internals of Vista+ desktops, MSDN covers this, as does this blog post. This'll give you the requisite background to know what you're doing.
In terms of making it look like the UAC dialog - well, consent.exe actually takes a screenshot of the desktop and copies it to the background of the new desktop; otherwise, the desktop will be empty.
As the other answerer has pointed out - Ctrl+Alt+Delete will still work. There's no way around that - at least, not without replacing the keyboard driver, anyway.
As to how to do this in Python - it looks like pywin32 implements SetThreadDesktop etc. I'm not sure how compatible it is with Win32; if you find it doesn't work as you need, then you might need a python extension to do it. They're not nearly as hard to write as they sound.
You might be able to get the effect you desire using a GUI toolkit that draws a window that covers the entire screen, then do a global grab of the keyboard events. I'm not sure if it will catch something like ctrl-alt-del on windows, however.
For example, with Tkinter you can create a main window, then call the overrideredirect method to turn off all window decorations (the standard window titlebar and window borders, assuming your window manager has such things). You can query the size of the monitor, then set this window to that size. I'm not sure if this will let you overlay the OSX menubar, though. Finally, you can do a grab which will force all input to a specific window.
How effective this is depends on just how "locked out" you want the user to be. On a *nix/X11 system you can pretty much completely lock them out (so make sure you can remotely log in while testing, or you may have to forcibly reboot if your code has a bug). On windows or OSX the effectiveness might be a little less.
I would try with pygame, because it can lock mouse to itself and thus keep all input to itself, but i wouldn't call this secure without much testing, ctr-alt-del probably escape it, can't try on windows right now.
(not very different of Bryan Oakley's answer, except with pygame)

Windows Balloon-tooltips in Python

Following the example at http://article.gmane.org/gmane.comp.python.general/541418, I've succeeded in creating a callable class for balloon tooltips, but the greater complexities of that code elude me when it comes to customization. I browsed a bit of how it works through msdn, but being a novice at more windows-esque languagues like c and vb, etc. I was unable to make much sense of it.
So I ask ye snakely academics:
Things I'd like to be able to do with that code aside from the standard icon, title, text:
Perform actions based on clicking the tooltip
Modify the tooltip that pops up over the icon in the system tray after loading it (to reflect changing values)
Multiple lines? (Not sure if this can even be done, really)
More information on other things you could do in a windows 7 environment versus XP (which seems to be what this was written for).
Ideally I'd get some sort of return value or some semblance of an event when the tooltip is clicked so that I could run some code, but currently I'm importing that code as a module and calling at various times, so I'm not sure how to handle clicks outside of the popup code itself...
Information on handling these things with python seems quite scarce. Thanks in advance.
Perform actions based on clicking the tooltip
Whats the problem OnTaskbarNotify? Hock yourself in there.
Modify the tooltip that pops up over the icon in the system tray after loading it (to reflect changing values)
Probably not, I am not sure about the WinAPI here. I haven't seen it in the wild, so...
Multiple lines? (Not sure if this can even be done, really)
With most WinAPI, just insert a \n in the string.
More information on other things you could do in a windows 7 environment versus XP (which seems to be what this was written for).
LOTS... But that is a bit vague... It depends what your needs are. But for kol feturez you need to google on your own...
On Linux and Unix systems I use the notify-send OS already implemented system.
import os
os.system('notify-send "'+title+'" "'+message+'")
Maybe in Windows there is some API32 for this.
Check this https://gist.github.com/wontoncc/1808234

Categories