Plugins Install
I can now install plugins through drag and drop / universal open. For now, installing plugins involves copying the file to ~/.saria/plugins/.
This commit is contained in:
parent
a87653f056
commit
853dde3ea7
|
@ -1,7 +1,7 @@
|
|||
# Bryan Schumaker (8/7/2010)
|
||||
|
||||
__all__ = [ "collection", "music",
|
||||
"data", "event", "map", "path"]
|
||||
"data", "event", "map", "path", "plugin"]
|
||||
|
||||
import event
|
||||
import path
|
||||
|
@ -12,7 +12,8 @@ vars = None
|
|||
prefs = None
|
||||
|
||||
|
||||
def startup():
|
||||
# Initialize helpful variables
|
||||
def init():
|
||||
global vars
|
||||
global prefs
|
||||
vars = Map()
|
||||
|
@ -20,7 +21,12 @@ def startup():
|
|||
event.start("POSTINIT")
|
||||
|
||||
|
||||
# If a preference has not already been set, set pref[key] = value
|
||||
def init_pref(key, value):
|
||||
global prefs
|
||||
if prefs.get(key) == None:
|
||||
prefs[key] = value
|
||||
|
||||
|
||||
def startup():
|
||||
pass
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
from libsaria import path
|
||||
import cPickle as pickle
|
||||
plugin = None
|
||||
|
||||
PROTO = pickle.HIGHEST_PROTOCOL
|
||||
|
||||
def save(item, file, ext="pickle"):
|
||||
file = "%s.%s" % (path.join(path.sariadir(),file), ext)
|
||||
file = "%s.%s" % (path.join(path.saria_dir(),file), ext)
|
||||
savefile(item, file)
|
||||
|
||||
|
||||
|
@ -18,7 +19,7 @@ def savefile(item, file):
|
|||
|
||||
|
||||
def load(file, ext="pickle"):
|
||||
file = "%s.%s" % (path.join(path.sariadir(),file),ext)
|
||||
file = "%s.%s" % (path.join(path.saria_dir(),file),ext)
|
||||
return loadfile(file)
|
||||
|
||||
|
||||
|
@ -32,3 +33,12 @@ def loadfile(file):
|
|||
return item
|
||||
|
||||
|
||||
def universal_open(file):
|
||||
global plugin
|
||||
split = file.rsplit('.', 1)
|
||||
ext = split[len(split)-1]
|
||||
# Install and start a plugin
|
||||
if ext == "py":
|
||||
if plugin == None:
|
||||
from libsaria import plugin
|
||||
plugin.install(file)
|
||||
|
|
|
@ -8,13 +8,50 @@ join = os.path.join
|
|||
mkdir = os.mkdir
|
||||
rm = os.remove
|
||||
walk = os.walk
|
||||
sep = os.sep
|
||||
|
||||
dir = None
|
||||
def sariadir():
|
||||
global dir
|
||||
if dir == None:
|
||||
dir = join(expand("~"), ".saria")
|
||||
if exists(dir) == False:
|
||||
mkdir(dir)
|
||||
return dir
|
||||
cp = None
|
||||
saria_dir = None
|
||||
plugin_dir = None
|
||||
|
||||
shutil = None
|
||||
s_dir = None
|
||||
p_dir = None
|
||||
|
||||
|
||||
def saria_dir_once():
|
||||
global s_dir
|
||||
global saria_dir
|
||||
s_dir = join(expand("~"), ".saria")
|
||||
if exists(s_dir) == False:
|
||||
mkdir(s_dir)
|
||||
saria_dir = saria_dir_rest
|
||||
return s_dir
|
||||
def saria_dir_rest():
|
||||
global s_dir
|
||||
return s_dir
|
||||
saria_dir = saria_dir_once
|
||||
|
||||
|
||||
def plugin_dir_once():
|
||||
global p_dir
|
||||
global saria_dir
|
||||
saria = saria_dir()
|
||||
p_dir = join(saria, "plugins")
|
||||
if exists(p_dir) == False:
|
||||
mkdir(p_dir)
|
||||
plugin_dir = plugin_dir_rest
|
||||
return p_dir
|
||||
def plugin_dir_rest():
|
||||
global p_dir
|
||||
return p_dir
|
||||
plugin_dir = plugin_dir_once
|
||||
|
||||
|
||||
def cp_once(src, dest):
|
||||
global cp
|
||||
global shutil
|
||||
import shutil
|
||||
cp = shutil.copy
|
||||
cp(src, dest)
|
||||
cp = cp_once
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# Bryan Schumaker (8/15/2010)
|
||||
|
||||
path = None
|
||||
|
||||
def install(filepath):
|
||||
global path
|
||||
if path == None:
|
||||
from libsaria import path
|
||||
split = filepath.rsplit(path.sep, 1)
|
||||
file = split[len(split)-1]
|
||||
dest = path.join(path.plugin_dir(), file)
|
||||
path.cp(filepath, dest)
|
|
@ -4,7 +4,7 @@
|
|||
import libsaria
|
||||
import ocarina
|
||||
|
||||
libsaria.startup()
|
||||
libsaria.init()
|
||||
libsaria.init_pref("window_size", (800,600))
|
||||
|
||||
prefs = libsaria.prefs
|
||||
|
@ -17,4 +17,5 @@ win = ocarina.get_window(prefs["window_size"])
|
|||
#win.move(0,0)
|
||||
ocarina.add_tab("Test", label)
|
||||
|
||||
libsaria.startup()
|
||||
ocarina.startup()
|
||||
|
|
|
@ -9,8 +9,8 @@ tabs = None
|
|||
|
||||
|
||||
# Function override variables
|
||||
get_main_tabs = None
|
||||
get_window = None
|
||||
get_tabs = None
|
||||
get_window = None
|
||||
|
||||
|
||||
# Global variables for some objects
|
||||
|
@ -27,37 +27,37 @@ def exit(widget, event):
|
|||
gtk.main_quit()
|
||||
|
||||
|
||||
def get_main_tabs_init():
|
||||
def get_tabs_once():
|
||||
global tabs
|
||||
global get_main_tabs
|
||||
global get_tabs
|
||||
global main_tabs
|
||||
import tabs
|
||||
main_tabs = tabs.Tabs()
|
||||
main_tabs
|
||||
get_main_tabs = get_main_tabs_always
|
||||
get_tabs = get_tabs_rest
|
||||
return main_tabs
|
||||
def get_main_tabs_always():
|
||||
def get_tabs_rest():
|
||||
global main_tabs
|
||||
return main_tabs
|
||||
get_main_tabs = get_main_tabs_init
|
||||
get_tabs = get_tabs_once
|
||||
|
||||
def add_tab(text, content):
|
||||
tabs = get_main_tabs()
|
||||
tabs = get_tabs()
|
||||
tabs.append_page(content, text)
|
||||
|
||||
|
||||
def get_window_init(size):
|
||||
def get_window_once(size):
|
||||
global window
|
||||
global get_window
|
||||
global main_window
|
||||
import window
|
||||
main_window = window.Window(size)
|
||||
main_window.add(get_main_tabs())
|
||||
get_window = get_window_always
|
||||
main_window.add(get_tabs())
|
||||
get_window = get_window_rest
|
||||
return main_window
|
||||
def get_window_always(size=None):
|
||||
def get_window_rest(size=None):
|
||||
global main_window
|
||||
if size != None:
|
||||
main_window.resize(size[0], size[1])
|
||||
return main_window
|
||||
get_window = get_window_init
|
||||
get_window = get_window_once
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import ocarina
|
||||
libsaria = ocarina.libsaria
|
||||
gtk = ocarina.gtk
|
||||
data = None
|
||||
|
||||
TARGET_TYPE_URI_LIST = 80
|
||||
|
||||
|
@ -28,9 +29,12 @@ class Window(gtk.Window):
|
|||
|
||||
|
||||
def dnd_receive(self, widget, context, x, y, selection, type, time):
|
||||
global data
|
||||
if data == None:
|
||||
from libsaria import data
|
||||
if type == TARGET_TYPE_URI_LIST:
|
||||
uri = selection.data.strip('\r\n\x00')
|
||||
import os
|
||||
for file in uri.split():
|
||||
file = file[7:]
|
||||
print file, os.path.isfile(file)
|
||||
data.universal_open(file)
|
||||
|
|
|
@ -16,7 +16,7 @@ print "libsaria loaded (", after-before, ")"
|
|||
|
||||
if len(sys.argv) == 1:
|
||||
before = now()
|
||||
libsaria.startup()
|
||||
libsaria.init()
|
||||
after = now()
|
||||
print "startup took", after-before
|
||||
print
|
||||
|
|
Loading…
Reference in New Issue