thingsinjars

  • 8 Dec 2010

    Testing CSS3 stuff

    You may have seen Google's 'Watch this space' advertising appearing all over the place. They have quite eye-catching diagonally striped backgrounds in various colours. A couple of days ago, I was wondering how easy it would be to recreate this in CSS without images. Unfortunately, the state of CSS 3 is such that some things work wonderfully, some just plain don't (scoped attribute, I'm looking at you). The following code relies on vendor extensions and so, unless you're willing to tend it and correct it after the spec is finalised, don't use this on a production server.

    The most obvious thing to notice from the following code, though, is the competing syntax for the repeating linear gradient style. Mozilla have separated it into a distinct style (-moz-repeating-linear-gradient) while Webkit have built it as an option to their general gradient style (-webkit-gradient).

    body {
    	background-image: -moz-repeating-linear-gradient(
    		-45deg,
    		transparent,
    		transparent       25%,
    		rgba(0,0,0,0.15)  25%,
    		rgba(0,0,0,0.15)  50%,
    		transparent       50%,
    		transparent       75%,
    		rgba(0,0,0,0.15)  75%,
    		rgba(0,0,0,0.15)
    	);
    	background-image: -webkit-gradient(
    		linear,
    		0% 0%,
    		100% 100%,
    		from(transparent),
    		color-stop(0.25, transparent),
    		color-stop(0.25, rgba(0,0,0,0.15)),
    		color-stop(0.50, rgba(0,0,0,0.15)),
    		color-stop(0.50, transparent),
    		color-stop(0.75, transparent),
    		color-stop(0.75, rgba(0,0,0,0.15)),
    		to(rgba(0,0,0,0.15))
    	);
    }

    To get a better idea of what this does, view source on this demo page. This includes a button to change the class on the body (using JS) which simply changes the background colour – the stripes are semi-transparent on top of that. Remember, due to the vendor prefixes, this only works in -moz or -webkit browsers.

    It's supposed to look like this:

    Geek, CSS, Development

  • 15 Oct 2010

    The Elementals

    In one of my day jobs I do something involving education, large public institutions and web stuff and a while back I thought it might be an excellent idea to have a go at designing some cool educational toys. Learnin' 'n' Fun! At the same time! omg! And so forth!

    The idea was to build the kind of thing you could use to squeeze knowledge into people's heads without them complaining. Y'see, it's never a good thing to trick people into learning. If your educational toy/game/experience relies too much on hiding the information behind the fun then the big reveal at the end – "Ha, I tricked you into learning something!" – will leave the player feeling cheated and not change their attitude towards learning. If, on the other hand, you try and push the ideas you want to get across at the expense of the core game mechanic, you'll end up with a bored user. My opinion is that you've got to be up front about the learning. You've got to say to the user "Look, this is learning and it's fun. No tricks here, it's exactly what it looks like". As for getting it to appeal in the first place, I find that very few things can beat extremely cute cartoons.

    To that end, I present my first dabble in interactive educational whaddyamacallits: The Elementals, a fun periodic table where every element has its own unique personality.

    The Elementals

    It's available as an iPhone app initially but I'll be venturing into the Android Marketplace soon and putting it online as a web app.

    Available on the App Store

    Geek, iOS, Design

  • 11 Oct 2010

    Appington concept

    Note: this is a concept sketch only. This doesn't actually exist. It'd be cool if it did, though.

    Appington. Your applications brought to you.

    Appington LogoAppington is, fundamentally, a single-application VNC client with a simple interface for task switching. Where most VNC applications present the user with the entire screen, Appington only shows a single window at any one time. This simplified interface makes interaction easier and saves on client application memory and reduces data transfer allowing the viewer to be more responsive. In some applications, this data transfer saving may be used to facilitate audio capture and transmission.

    Applications list

    This screen shows a list of all available applications grouped by first letter. In the lower-left, the user can toggle between listing all applications or only listing currently running applications. The right-hand panel shows more information about the selected application. In this example, Google Chrome is selected and running. The current memory and CPU usage are shown along with a note of how many active windows the application has. Because Chrome is currently running, the option to quit is shown. If we had selected an unlaunched application, this button would show the option to launch. In case of emergencies, there is always the option to Force Quit a running application.

    Application window (portrait)

    This shows a standard single application window. The button in the top left would return the user to the previous screen. From the right, the remaining buttons allow the user to capture a screen shot, maximize the application window to match the current iPad viewport (if possible), refresh the current screen (in case of render errors) and access the application's menu. In OS X, menu access would be accomplished by way of the accessibility API. At the moment, I'm not sure how it would work on other OSs.

    Application window (landscape)

    This shows a single window of an application with multiple windows. You'll notice the extra button at the top between Menu and Refresh. This menu will allow you to select which window you want to access between however many the application currently has open.

    Other images

    The partner application to this is a modified VNC server running on the host machine. It is responsible for window management, task-switching, menu parsing and audio capture (à la SoundFlower). If there is already a VNC server running, the partner app will leave the standard VNC functionality alone and act purely as a helper, providing the extra functionality but not using extra memory by duplicating functionality. This is a variation of noVNC using the python proxy to manage the socket connection allowing the client to be built in PhoneGap using HTML 5.

    Like I said at the top, this hasn't been built yet. It'd be cool if someone did build it, though.

    Ideas, Geek

  • 30 Sep 2010

    Writing a Plex Plugin Part III

    This is the final part of my walkthrough of the Plex Media Server Transmission plugin.

    Right.

    We've done the required built-in functionality (preference management, for instance) and the bits that talk to Transmission itself. Basically, we're done. Anything else added here is just extra. That is, of course, the best reason to add stuff here. As I have previously ranted at length, there's no point doing anything if you aren't trying to do it as well as it possibly can be done. In this particular instance, that manifests itself in the ability to browse, search for and download torrents all within the Plex client interface.

    EZTV

    I love EZTV. It makes things easy. Previous versions of this plugin included an EZTV search but after rooting around in the source of the µTorrent plugin, I found some nifty code which turned me onto the clever XML parsing Plex can do.

    Note: although some of this stuff looks clever, all the cleverness was done by the Plex dev team and the author of the µTorrent plugin. I'm a good copy-and-paster.

    This function grabs the H2s from the page http://ezrss.it/shows/. If you go there, you'll see that the page lists every TV show in EZTV. The original µTorrent function listed everything but there are a lot of shows there now so it was actually taking a long time just to get that list. As they've split the page up by section, we can just grab the bits we want. This is going to be a full page in Plex (not a popup) so we're using a MediaContainer.

    def TVShowListFolders(sender):
      dir = MediaContainer()

    Using the built-in XML module, we can simply pass in a URL and get back an object containing the hierarchical structure of the entire page. Seriously, how simple is this? As it's HTML, add in the option isHTML=True.

      showsPage = XML.ElementFromURL(
                    'http://ezrss.it/shows/', 
                    isHTML=True, 
                    errors='ignore'
                  )

    Now that we have the whole page structure, take the chunks of the page we want. All the sections we want (and one we don't) are divs with the class 'block' so use that in xpath to pull them out.

      blocks = showsPage.xpath('//div[@class="block"]')

    The first block is the one we don't want (if you look at the page, it's the one that lists all the letters) so we remove it.

      blocks.pop(0)

    For each of the remaining blocks, find the text in the first H2. That is the letter title of the section ('A', 'B', 'C', etc). Add that to Plex as a menu item then return the entire list.

      for block in blocks:
        letter = block.xpath("h2")[0].text
        dir.Append(
          Function(
            DirectoryItem(
              TVShowListSubfolders,
              letter,
              subtitle=None,
              summary=None,
              thumb=R(ICON),
              art=R(ART)
            ),
            letter=letter
          )
        )
      return dir

    I hope I'm not the only one impressed with that (although I have a feeling I might be). Using just a couple of lines from the XML module and a sprinkle of xpath and we've got another menu, dynamically generated from a third-party website. If EZTV ever change their layout, it should be a simple matter of changing the xpath to match and we're done. Again.

    We can now do the same again but this time, we only pull out a single section based on the letter passed in.

    def TVShowListSubfolders(sender, letter):
      dir = MediaContainer()
      showsPage = XML.ElementFromURL(
                    'http://ezrss.it/shows/',
                    isHTML=True,
                    errors='ignore'
                  )
      blocks = showsPage.xpath(
                '//div[@class="block" and h2 = "%s"]' % letter
               )

    Remembering to ignore any 'back to top' links, write out a list of the shows in this section. These will call the TVEpisodeList method next.

     for block in blocks:
      for href in block.xpath('.//a'):
       if href.text != "# Top":
        requestUrl = "http://ezrss.it" + href.get("href") + "&mode=rss"
        dir.Append(
         Function(
          DirectoryItem(
           TVEpisodeList,
           href.text,
           subtitle=None,
           summary=None,
           thumb=R(ICON),
           art=R(ART)
          ),
          name=href.text,
          url=requestUrl
         )
        )
     return dir

    This lists all available torrents for the chosen show. By this point, you should be familiar with how this works. We're using the XML module to grab the page at the URL (this time it's an RSS feed so we don't need to parse it as HTML); we use XPath to iterate through the items in the feed; we generate a menu item from the data which will call a function when selected; we append that to a MediaContainer then return the whole thing to Plex. Done. The AddTorrent function was defined higher up.

    def TVEpisodeList(sender, name, url):
     dir = MediaContainer()
     feed = XML.ElementFromURL(url, isHTML=False, errors='ignore').xpath("//item")
     for element in feed:
      title = element.xpath("title")[0].text
      link = element.xpath("link")[0].text
      dir.Append(
       Function(
        DirectoryItem(
         AddTorrent,
         title,
         subtitle=None,
         summary=None,
         thumb=R(ICON),
         art=R(ART)
        ),
        torrentUrl=link
       )
      )
     return dir

    Adult considerations...

    There is currently a section in the plugin which will allow you to search IsoHunt. This might get dropped in future versions of the plugin as results from IsoHunt are almost exclusively...ahem...adult, regardless of search terms. Sure, that might be exactly what you were looking for but if you were actually looking for Desperate Housewives, you might be surprised when your file comes down and it's actual 'desperate housewives'...

    Search EZTV

    The final part is a straightforward search of EZTV. The interesting thing to note is that this uses a different type of menu item. Where normally, you'd use a DirectoryItem in a Function, this uses an InputDirectoryItem in a Function. This type of menu item will pop open an on-screen keyboard before calling the target function giving you the opportunity to grab some user input.

    It's appended to the menu in the usual way:

     dir.Append(
      Function(
       InputDirectoryItem(
        SearchEZTV,
        L('MenuSearchTV'),
        "Search the TV shows directory",
        summary="This will use EZTV to search.",
        thumb=R(SEARCH),
        art=R(ART)
       )
      )
     )

    By the way, I think there's a minor bug in the InputDirectoryItem in that it doesn't like it when subtitle is passed as a named argument. I should probably file that as a bug with Elan.

    When the user has entered their input and submitted, the named Function SearchEZTV is called with the standard argument sender and the extra argument query containing the user's input.

    This function was a lot longer in the previous version of the Framework. It was so much simpler this time round.

    def SearchEZTV(sender, query=None):
      dir = MediaContainer()
      url = "http://ezrss.it/search/index.php?simple&mode=rss&show_name="
      if query != None:
       url += "%s" % query
      feed = XML.ElementFromURL(
              url, 
              isHTML=False, 
              errors='ignore'
             ).xpath("//item")
      if feed == None:
        return MessageContainer("Error", "Search failed")
      if len(feed) == 0:
        return MessageContainer("Error", "No results")
      for element in feed:
        title = element.xpath("title")[0].text
        category = element.xpath("category")[0].text
        link = element.find("enclosure").get("url")
        size = prettysize(int(element.find("enclosure").get("length")))
        dir.Append(
          Function(
           DirectoryItem(
            AddTorrent,
            title,
            subtitle=None,
            summary="Category: %s\nSize: %s" % (category,size),
            thumb=R(ICON),
            art=R(ART)
           ),
          torrentUrl=link
         )
        )
      return dir

    Done

    That's it. The only other little thing to mention is how handy it is to use the built-in Log function. The first argument is a standard Python string, the second is 'Should this only turn up in the console when in debug mode?' to which the answer will almost always be 'True'. There is a third argument but unless you're messing with character encodings, you don't need to worry about it.

    Log("Message to log is: %s %d" % (errorString, errorCode), True)

    Go, make...

    If you made it to the end here, you're probably either keen to start making your own Plex plugins or my wife who I am going to get to proofread this. Assuming you're the former, here are some handy links:

    • Online plugin development manual

      There are plenty of bits missing but it's still the best reference available for the framework.

    • Plex forums

      Particularly the Media Server Plugins forum

    • Plex Plugins Lighthouse

      This is where bugs are filed, suggestions made and final plugin submission happens. It's handy for picking little tips if someone else has had the same problem as you.

    If you want to use the plugin, it's available in 'Plex Online' in Plex/Nine or 'Plex App Store' in Plex/Eight. If you'd like to read through the complete source, you can download the zipped .Bundle.

    Transmission Plugin for Plex Media Server v1.0 [Zip - 1.1MB]

    Geek, Development

  • newer posts
  • older posts

Categories

Toys, Guides, Opinion, Geek, Non-geek, Development, Design, CSS, JS, Open-source Ideas, Cartoons, Photos

Shop

Colourful clothes for colourful kids

I'm currently reading

Projects

  • Awsm Street – Kid's clothing
  • Stickture
  • Explanating
  • Open Source Snacks
  • My life in sans-serif
  • My life in monospace
Simon Madine (thingsinjars)

@thingsinjars.com

Hi, I’m Simon Madine and I make music, write books and code.

I’m the Engineering Lead for komment.

© 2025 Simon Madine