wnck FTW!

well, yesterday’s hack turned out to be pretty useless.  effectively it just converted hamster into zeitgeist journal (or gnome activity monitor)  – which is okay until you start using an app which isn’t a zeitgeist data provider or which doesn’t happen to emit a signal for the activity you’re performing.

so, i thought i’d have a go at converting hamster into creeper instead.  thanks to creeper for showing me how it’s done.  i’ve called this cree.py 😉

#!/usr/bin/python

# a python version of creeper (a vala app) to monitor active windows
# actually turns hamster into creeper

# because the mainloop appears to catch exceptions
from traceback import print_exc
import hamster.client
class hamster_handler(hamster.client.Storage):
   def __init__(self):
      self.nc = None
      hamster.client.Storage.__init__(self)
      
   def add_fact(self, fact):
      # FIXME insert clever rules here
      fact = fact.replace(",", ";") # don't accidentally create descriptions
      fact = fact.replace("@", "(a)") # don't accidentally create categories
      hamster.client.Storage.add_fact(self, fact)

   def handler(self, scr, prev = None):
      try:
         if prev and self.nc != None: prev.disconnect(self.nc)
         win = scr.get_active_window()
         if win:
            self.add_fact(win.get_name())
            self.nc = win.connect("name_changed", self.name_handler)
      except KeyboardInterrupt: raise
      except:
         print_exc()
        
   def name_handler(self, win):
      try:
         self.add_fact(win.get_name())
      except KeyboardInterrupt: raise
      except:
         print_exc()

hh = hamster_handler()
from gobject import MainLoop
ml = MainLoop()
from wnck import screen_get_default
sc = screen_get_default()
sc.connect("active_window_changed", hh.handler)
sc.connect("window_stacking_changed", hh.handler)
hh.handler(sc)
ml.run()

this is working pretty well for me so far .. on fedora 14.  just tried on 13 and the hamster python library is too old i think.  ah well – yet another reason to upgrade!

Advertisements

python, hamster and zeitgeist FTW!

update: note that this turned out not to be all that useful – tracking active windows into hamster turned out better.

in response to gnome bug 639018 and my general desire to track automatically what i’ve done, i’ve made a python script which connects to the zeitgeist activity monitor and copies its messages to the hamster time tracker.  it goes like this:

#!/usr/bin/python

# monitor zeitgeist and do stuff
from zeitgeist.client import ZeitgeistClient
from zeitgeist.datamodel import TimeRange, Event
from gobject import MainLoop

import hamster.client
class hamster_handler(hamster.client.Storage):
   def handler(self, tr, ev):
      # because the mainloop appears to catch exceptions
      from traceback import print_exc
      from urlparse import urlparse
      try:
         # FIXME insert clever rules here
         app = urlparse(ev[0].actor).netloc
         desk = open("/usr/share/applications/" + app)
         comments = filter(lambda x: x.startswith("Comment[en_GB]="), desk)
         comment = comments[0].split("=")[1].strip()
         self.add_fact(comment + " - " + ev[0].subjects[0].text)
      except:
         print_exc()

hh = hamster_handler()
ml = MainLoop()
ZeitgeistClient().install_monitor(
    TimeRange.from_now(),
    [Event()],
    hh.handler,
    hh.handler)
ml.run()

It never ends until it’s killed so you’ll probably want to run it in the background – i’ve added it to my session ‘startup applications’.  if it doesn’t appear to be working then run it from the command line instead – you should see some error messages if it’s failing to update hamster.

on my fedora 14 system i only get updates for local text files, images and videos opened in gedit, EoG and totem.  on ubuntu i imagine you’ll get a lot more updates.  OTOH, on ubuntu the script will probably need some tweaking for the hard-coded paths and locale.

under surveillance

i’ve decided not to link this to my hamster-to-empathy updater – i don’t really want to broadcast a stream of every little thing i do .. particularly if my IM accounts include twitter and facebook status feeds.  🙂

another desktopish thought

along with all the great stuff that’s on the way in gnome-shell – with all its thinking about desktop use cases etc, i think we should add a ‘restart session’ option which does a ‘logout and log back in’ without asking for a password.

mind you, that’s only needed when certain pieces of software get updated.  under those circumstances it would be better if those apps sorted themselves out silently.  but until that’s the case the option could just be available on the PackageKit “you need to log out and in again” notification.

screenshot of gnome shell overlay modewhile i’m thinking about gnome-shell, i think when you drag something from the sidebar to a desktop in overlay mode it shouldn’t automatically take you out of overlay mode – it should assume you’ll want to get more than one thing.

or should we just be able to multi-select from the sidebar?  can you do that already?  i don’t like multi-select anyway – means you have to use both mouse and keyboard.

maybe we just need a mechanism for defining a group of things and making that group appear as an object in the sidebar – perhaps just a ‘save task/workspace’ option somewhere.

the way i want my computer to work

prompted by the post about PackageKit requesting better names, i’m wondering if we need to stop worrying about whether it’s called “software” or “packages” or “applications” or “programs” and instead get on with the idea of task or function-based usage.

rather than picking software from a list of what “office” applications are available, or even a list of “popular spreadsheet applications” we should get back to the “what do you want to do” model and provide an interface that starts (or installs and then starts) all the software you’ll need to do that thing.

doesn’t cover the scenario, “i just want to see what kind of things i can do” – but i guess you could always have a “random” button and a “popular tasks” (“do what everyone else does”) button. maybe a “recent tasks” list and a “do what everyone else is doing” button which is really “popular recent tasks”.

it might be nice to add into those task lists some items that reflect the hardware available in this particular PC. especially anything added recently or which is unusual.

i don’t mean a pop-up message, “you seem to have installed a new graphics card. do you want to play a game?” but something more subtle. fancy 3D games, flight sims, planetaria and 3D design tasks might appear nearer the top of the list than usual, that’s all.

ha! the control panel for the task list could be a set of sliders (“on a scale of one to ten, where one is….”!):

  1. i just bought a PC, it came with a bunch of stuff |—————-| if it’s there i want to use it
  2. i like to do what everyone else does |—————-| i like to do my own thing
  3. i do the same stuff every day |—————-| i never know what i might do next

i’m hoping something like that will come out of the applications part of mugshot and the online desktop project but we also need a better way of describing the tasks each application is capable of.

i guess this needs to be a list of inputs, outputs and processes (internally – the user doesn’t see this) – file formats, sources and destinations, devices and functions.

for example, a simple web browser has:

  • inputs “html from web”
  • outputs “screen”
  • no processes

whereas a simple word processor has:

  • inputs “document from file” and “user on keyboard”
  • outputs “screen” and “document to file”
  • processes such as “capitalise”

hmm. the lists could get quite big but that’s okay as long as they can be searched. then help files can be built on top of that metadata as well. then the “what task” system can start by searching the ‘processes’ list, then check the ‘in/out’ list and finally scan the help text.

application usage stats can be extended to cover which ‘processes’ were used and which types of inputs and outputs. when software updates are available the system can report to the user any update highlights, emphasising things which affect processes the user uses as part of their tasks.

this is all getting close to COM+ isn’t it? urk. i hate it when they get things right.

another extension to the apps usage metadata could come from the user as well as the apps themselves – are they being used for fun or for ‘serious’ stuff. then a ‘what mood am i in?‘ slider(s) could be part of the desktop control panel.

keep an eye on keyboard/mouse activity, watch the current music/video playlist, look at the time of day and time of year, connect the mic and webcam to some biometrics software and we might be able to make some frighteningly good suggestions in the tasks lists! eek.

here’s a hypothetical conversation between the system and the user when what they want isn’t in the lists:

system: what do you want to do (today 😉 )? (search/find, view/open/see/look, create/record, update/modify/edit/change/process/filter, is there anything else? copy/duplicate?)

user: i want to look at something.

system: what do you want to look at?

system opens the ‘stuff finder’ – which searches files, emails, etc and the web.

user (to self): ah. right, i want to find something and then i want to look at it.

user finds object or page (link in results) and clicks on it to view.

system: okay! what do you want to do next?

how not to reboot in ten easy steps

following on from the ‘give it a name’ post, here’s a priority list for the desktop:

  1. get suspend working all the time on all laptops
  2. get suspend and/or hibernate working on everything
  3. get apps working so you can stay logged in forever
    • you shouldn’t ever need to kill or restart an app.
  4. extend rpm/yum so you can do all software installs/updates without logging out or rebooting
    • make sure it can start/restart anything that needs it for the new/updated software to happen
    • make sure it installs new stuff without you having to know that software/driver/firmware has appeared
  5. get kernel module minor version revisions working properly so that you only ever have to reboot if you’ve updated the actual kernel.
  6. split more kernel functionality into modules so that this happens less often
  7. look into applying some/all kernel updates with a suspend/resume to ram or disk.
  8. make all apps save state properly so that if you do have to reboot everything picks up from exactly where it left off.
  9. see if you can run an efficient system with a host kernel with two guest VMs running on it as a HA cluster so that each VM can get a transparent kernel update. then you only have to reboot if the host kernel has to be updated.
    • obviously you then do something to make sure that the host kernel is excessively simplified so that it hardly ever needs any updates.
  10. do that update to grub so that you can do a warm-ish reboot and not have to go back through the BIOS.

there! job done.