Showing posts with label rustykiosk. Show all posts
Showing posts with label rustykiosk. Show all posts

Monday, October 24, 2011

So many things!

I did a lot last week.


The next version of the Kiosk code is up on my github now. I cleaned things up to the point where customizing it is easy thanks to configparser. Why have I never seen this library before?


Here's a sample configuration file.

# Kiosk Settings
# cycler settings...
[kiosk_cycler]

# location of where to toss things

file_location = /Users/fossrit/Desktop

# host to ping to test for a working internet connection
ping_host = www.google.com

# number of times to retry a connection. -1 for unending attempts
ping_counter = 3

# number of seconds to wait in between ping attempts
ping_timer = 30

# list of hosts for the feeds. Follows the format:
# host : /location
# candidate feeds are delimited by commas.
feed_hosts = foss.rit.edu : /files/bookmarks.rss, cs.rit.edu : /~ear7631/feed.rss



And here's the python code to parse it.


parser = SafeConfigParser()
parser.read('kiosk_config')
file_location = parser.get('kiosk_cycler', 'file_location')
ping_host = parser.get('kiosk_cycler', 'ping_host')

ping_counter = int(parser.get('kiosk_cycler', 'ping_counter'))

ping_timer = int(parser.get('kiosk_cycler', 'ping_timer'))
feed_hosts_dirty = parser.get('kiosk_cycler', 'feed_hosts')


Easy, isn't it? I was also messing around with wxWoof, too, and finally got around to tinkering with wxPython a bit more. You can look at the full code here, but I really just wanted to share how easy adding drag-and-drop functionality is. My goal was to make a button that, not only brought up a file selection if clicked, but had file recognized drag-and-drop implemented as well. All that really needs to be done is hook up a FileDropTarget to your container, which handles the magic.
self.boxButton.SetDropTarget(self.dropTarget) self.dropTarget = FileDropTarget(self.boxButton)

After that it's just a matter of hooking up the OnDropFiles function your FileDropTarget.


I've now started working with html5 forms, jquery, and the twisted web framework, so there will be posts on my experiences with these in the coming days.


Wednesday, October 5, 2011

Making a simple Kiosk

Today, a very different sort of project managed to find its way to me. I've been tasked with building a kiosk out of this, this, and last but not least, this. It's a pretty cool idea - make the mini run, mount the monitor, cover it with plexiglass, sand the box, and give it a nice new coat of paint. My parents had always made sure that power tools were more than an arm's length from me at all times, so I've grown up with zero experience in that realm. Needless to say, I started with the mac.

The box needed to do only one task: start up, open a browser, cycle through links. Perfect job for applescript. The script to launch a browser and loop through links is simple:



#!/usr/bin/osascript



-- argv is a list of links to loop through

on run argv
  tell application "Opera.app" to activate
    
    tell application "System Events"
      tell process "Opera"
        click menu item "New Window" of menu "File" of menu bar 1
      end tell
    end tell

    -- list of urls to cycle
    repeat

      repeat with someurl in argv
        tell application "System Events" to set browserRunning to (name of processes) contains "Opera"
        if browserRunning then
        else
          exit repeat
        end if
        
        tell application "Opera.app"
          set URL of document 1 to someurl
          delay 5
        end tell
      end repeat

      tell application "System Events" to set browserRunning to (name of processes) contains "Opera"
      if browserRunning then
      else
        exit repeat
      end if

    end repeat

end run



I made a python script that does everything else. Grabs a list of links from a feed, passes them over to the cycler:

#!/usr/bin/env python

import feedparser
import os
from subprocess import call


# this actually parses the feed as if it uses the firefox live bookmarks format
# your parsing may change on how your links are represented

applecmd = []
applecmd.append("osascript")
applecmd.append("kioskcycle.scpt")
d = feedparser.parse("http://myhost.com/somefeed.rss")
bookmarkitems = d['items']
for item in bookmarkitems:
for link in item.links:
applecmd.append(link.href)


os.chdir("/Users/someuser/Desktop")
call(applecmd)


And got it all working by turning my python script into a natively built python applet, and telling OSX to use it as a startup item. All pretty straight forward, under normal circumstances. Of course, my script initially used Safari, but things can never be that simple. RIT is its own Certification Authority, and Safari thinks some of RIT's sites (ie, my.rit.edu) are traps. Even if you forcefully allow the certificate to pass, Safari will warn you. This got on my nerves, so I went looking for another browser. Firefox dropped support for PPC a long time ago. Chrome never had it. TenFourFox, as nice as that is, doesn't work with applescript. I decided to settle on Opera 10, the last Opera release to work with PPC. It also gained Applescript support since 9.5. Nice.

I've got some major sanding, painting, drilling, and polishing to do tomorrow, so I'll be sure to post a picture of the final product of my labor. Mmmmm... power tools.