Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Friday, March 10, 2017

Preventing Windows OS from sleeping while your python code runs

Do you have a python script that you want to run through to completion, but might take several hours without user interaction?

Might you run on a laptop or other Windows computer that has power management enabled, so that it might go to sleep or hibernate when not being used?

If you do nothing, windows will likely sleep or hibernate before your script can complete.

The following simple piece of code can prevent this problem. When used, it will ask windows not to sleep while the script runs. (In some cases, such as when the battery is running out, Windows will ignore your request.)

class WindowsInhibitor:
    '''Prevent OS sleep/hibernate in windows; code from:
    https://github.com/h3llrais3r/Deluge-PreventSuspendPlus/blob/master/preventsuspendplus/core.py
    API documentation:
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa373208(v=vs.85).aspx'''
    ES_CONTINUOUS = 0x80000000
    ES_SYSTEM_REQUIRED = 0x00000001

    def __init__(self):
        pass

    def inhibit(self):
        import ctypes
        print("Preventing Windows from going to sleep")
        ctypes.windll.kernel32.SetThreadExecutionState(
            WindowsInhibitor.ES_CONTINUOUS | \
            WindowsInhibitor.ES_SYSTEM_REQUIRED)

    def uninhibit(self):
        import ctypes
        print("Allowing Windows to go to sleep")
        ctypes.windll.kernel32.SetThreadExecutionState(
            WindowsInhibitor.ES_CONTINUOUS)


To run it, simply:

import os

osSleep = None
# in Windows, prevent the OS from sleeping while we run
if os.name == 'nt':
    osSleep = WindowsInhibitor()
    osSleep.inhibit()

# do slow stuff

if osSleep:
    osSleep.uninhibit()

It is based on code from here, which also has code for preventing suspension on Linux under GNOME and KDE, should you need that.

Tuesday, July 21, 2015

Gallerific: A Modern HTML5 Lightroom Web Gallery

Latest update May 2016.  
 Also in Español, Français & Deutch.


This post is to announce the release of a powerful new Web Gallery plugin for Adobe Lightroom.

Like many photographers, I use Lightroom to manage my photos and do most of my adjustments, and it's just great. But when it comes to exporting them in an easily viewable way, I was shocked to realize how poor the options were. The included galleries are simply ancient; most of them use Adobe Flash, which is being phased out on the web, is slow and painful to use and is a security headache to boot. The rest use decade-old HTML code and produce web pages that are just plain painful to use. And searching around, I wasn't able to find any third-party web albums that worked reasonably well either, especially for larger sets of photos.

The free Gallerific HTML5 Web Gallery plugin is here to fix all of that and bring Lightroom web exports into the present.




Features:
  • Allows you to create great albums, with captions (or not), from the program you already use to manage your photos and metadata.
  • The entire web site is generated automatically, with multiple customization options. No special expertise is needed, but there are customization options for those wanting more control.
  • Albums are fast, responsive, and support large numbers of images (up to thousands, anyway).
  • Albums are standards-compliant, using Javascript, HTML5 and CSS3 - and no obsolete Flash! They should work well on any modern web browser or device, and have great backward compatibility too. They even work minimally if your browser doesn't support Javascript.
  • Albums follow modern responsive web design principles, automatically adapting to the size of the web browser or mobile display.
  • Images can be navigated by mouse or touch screen (including by swiping), or by using keyboard shortcuts (Left/Right, Page Up/Down, Home, End, Space).
  • For a hands-free experience, you can play a slideshow to flip through photos automatically.
  • The web page uses no server-side scripting, so it can be served very cheaply from a static web server such as Amazon S3 (or any other web server).
  • Lightroom versions 2.0 to 6 (and CC) should all be supported
  • Runs under Windows or MacOS (generated galleries are viewable under any OS)
  • Available in English, Español, Français, & Deutch
  • Totally FREE!

Version 1.0 (22 July 2015, in brief):

Smart image pre-fetching for immediate transitions between images, touch support, responsive design adapts to page size. Thumb navigation. Captions may overlay image or lie below it. Various configuration options, color schemes and example templates. A limited representation of the album is viewable as a preview inside Lightroom. Center-crops images to create aesthetically-pleasing square thumbnails (something Lightroom doesn't support).

New in version 1.1 (23 August 2015):
  • Album loading speed is massively improved, using a variety of techniques.
  • Greatly improved mobile / touch device support:
    • Smaller mobile devices, or tablets in portrait orientation are shown thumbnails on the bottom, with native, re-flow-enabled scrolling. This means that thumbnails scroll totally naturally for touchscreens, without losing any functionality on small window non-touch devices (buttons and mouse-wheel will work in this case).
    • Apple iOS bug causing flickering animations has been addressed.
    • Very small devices like phones are now supported without any quirks.
    • Pinching to zoom will open full size images (when full size image links are provided).
  • Adds options to not include full size images, and to disable ability to right click for saving images.

New in version 1.2 (11 September 2015):
  • Full gallery previews are now available inside Lightroom! Now almost all functionality and styling can be seen when changing settings.
  • Galleries can now be social media sharing enabled. Users can click to share galleries via Facebook, Google, Twitter, and Pinterest.
  • Maps from Google can now be opened for any image with geo-location data (GPS or city/country).
  • The icon scheme has been standardized. High quality, scalable SVG icons are shown in 95% of browsers, with PNG images used as a backup for the rest.
  • Page loading is even faster now, and more robust, using CDNs where possible. It still works when you're running locally (even if offline), or if CDN services are blocked or down.
  • The album is now compatible with Internet Explorer all the way back to 5.5 and other older browsers as well as Opera Mini.
  • Additional customization options.
  • Other minor improvements and bug fixes.


New in version 1.3 (12 January 2016):
  • Much greater control over where to place identity plate (logo), titles, and contact info
  • Allow customization of all text in generated galleries
  • Internationalization - now includes versions in Spanish, French and German
  • Better appearance on low-performance devices
  • Various minor improvements and bug fixes, and additional documentation
New in version 1.3.1 (9 May 2016):
  • New tool to optionally allow downloading all images in the gallery.
  • You can now choose the maximum number of thumbnail columns that will be shown (from 2-4). Also improved the layout and use of screen real estate to allow slightly larger image area.
  • Various minor bug fixes and improvements.
Update to version 1.3.1 (7 September 2017):
  • Minor bugfixes for viewing GPS position and auto-starting slideshows.


Installation:
  • Unzip the "GallerificAlbum.lrwebengine" folder and copy this to the Lightroom Web Galleries folder. This folder can be opened within Lightroom preferences (Win: Edit->Preferences, Mac: Lightroom->Preferences) by clicking on the "Show Lightroom Presets Folder" button then opening the Web Galleries folder.
    • On a Mac this is located under: /Users/username/Library/Application Support/Adobe/Lightroom/Web Galleries/
    • On Windows Vista/7/8, this is normally under: C:\Users\username\AppData\Roaming\Adobe\Lightroom\Web Galleries\ 
    • On Windows XP this is normally under: C:\Documents and Settings\username\Application Data\Adobe\Lightroom\Web Galleries\
  • Recommended but optional: Install the set of templates ("skins") for albums by copying the "Gallerific-Templates" folder into the Web Templates\ folder under the Lightroom presets folder. These will give you a good idea of output options and possible color schemes.
  • (Re-)Start Lightroom; the Gallerific gallery should appear in the list under the Web workflow

Usage:
  • As with any web album, select the images you wish to export using the Library view in Lightroom. Be sure they have all the metadata you want to include in the album. When you're happy with the images and their order, open the Web view.
  • Select the "Gallerific HTML5 Gallery" from the Layout style at the top right.
  • In the Web view, choose the options you want. Enter titles, descriptions, customize your image captions and use a custom logo, and choose where they appear. Customize your color scheme and how images will appear. Choose the size of the gallery image slide and an expanded full size image to be generated, as well as caption metadata and watermark to include. You can use the Preview in Browser button to check out your album’s appearance. And then simply Export to disk or Upload (to a server via FTP/SFTP) the complete album when you’re ready! The resulting HTML pages and supporting files will be generated in the folder or server location you selected. 
    • You can view the gallery on your local computer by opening the file index.html in a web browser.
    • After exporting to disk, the generated folder can be loaded onto a web server for access via the web or just copied to a CD/DVD or shared folder to share with others.
  • More details about creating web albums in general are available from Adobe.

Click here to see an example album - note that galleries are quite customizable and this is just an example.


Download here and get started!


License: This project is open source and released under the MIT License.


Many thanks:
This project couldn't have been done without the galleriffic and jquery history jQuery plugins; these have been extensively modified and improved for this project and have been forked on github. The project also benefits from the touchSwipe and transit plugins, the grunticon toolkit, the mediamatch polyfilljszipfilesaver.js, and fallback.js. Tablet image above is thanks to zanilic.com. Loader icons were generated from spiffygif.com and preloaders.net and compressed with kraken.io. Scalable icon designs are by Elusive, Typicons, Font Awesome, and Icomoon. And thanks to Henriette Donis for invaluable help in translating.


I'd love to hear about any websites that you create using this tool. Feel free to email me or leave a message below to let me know! And if you have any problems, suggestions or requests, leave them here too.


If you find the Gallerific Web plugin useful to you or your business, or if it's saving you time or money, I'd really appreciate a contribution. It's taken me countless hours to set this up and make it work well (now I realize why there are so few other options available!). Every bit counts. And many thanks.


Addendum: If you want to deploy your website onto Amazon S3, I provide an automated approach here (A word of warning that unlike creating an album, it does require somewhat advanced computer skills. An easier, but less efficient, option is to simply drag and drop the album using a GUI tool like S3 Browser or CrossFTP).