Package plugins :: Package misc :: Package where :: Module main
[hide private]
[frames] | no frames]

Source Code for Module plugins.misc.where.main

 1  #-*- coding: utf8 -* 
 2  # 
 3  # Max E. Kuznecov <syhpoon@syhpoon.name> 2009 
 4  # 
 5   
 6  from libxyz.core.plugins import BasePlugin 
 7  from libxyz.core import UserData 
 8   
9 -class XYZPlugin(BasePlugin):
10 "Plugin where" 11 12 NAME = u"where" 13 AUTHOR = u"Max E. Kuznecov <syhpoon@syhpoon.name>" 14 VERSION = u"0.1" 15 BRIEF_DESCRIPTION = _(u"Save panels locations") 16 FULL_DESCRIPTION = _(u"When starting load previously saved locations") 17 NAMESPACE = u"misc" 18 MIN_XYZ_VERSION = 2 19 DOC = None 20 HOMEPAGE = "http://xyzcmd.syhpoon.name/" 21 EVENTS = None 22
23 - def __init__(self, xyz):
24 super(XYZPlugin, self).__init__(xyz) 25 self._ud = UserData() 26 self._wfile = "where" 27 28 self.xyz.hm.register("event:startup", self.load) 29 self.xyz.hm.register("event:shutdown", self.save) 30 31 self.export(self.save) 32 self.export(self.load)
33 34 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 35
36 - def load(self):
37 """ 38 Restore locations on startup 39 """ 40 41 f = None 42 try: 43 f = self._ud.openfile(self._wfile, "r", "data") 44 data = f.readlines() 45 act = data[0].strip() 46 inact = data[1].strip() 47 48 chdir = self.xyz.pm.from_load(":sys:panel", "chdir") 49 chdir(act) 50 chdir(inact, active=False) 51 except Exception: 52 pass 53 54 if f: 55 f.close()
56 57 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 58
59 - def save(self):
60 """ 61 Save locations on shutdown 62 """ 63 64 cwdf = self.xyz.pm.from_load(":sys:panel", "cwd") 65 act = cwdf() 66 inact = cwdf(active=False) 67 68 f = None 69 try: 70 f = self._ud.openfile(self._wfile, "w", "data") 71 f.write("\n".join([act, inact])) 72 except XYZRuntimeError, e: 73 xyzlog.info(_(u"Unable to open where data file: %s") 74 % ustring(str(e))) 75 if f: 76 f.close()
77