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)
|
# Bryan Schumaker (8/7/2010)
|
||||||
|
|
||||||
__all__ = [ "collection", "music",
|
__all__ = [ "collection", "music",
|
||||||
"data", "event", "map", "path"]
|
"data", "event", "map", "path", "plugin"]
|
||||||
|
|
||||||
import event
|
import event
|
||||||
import path
|
import path
|
||||||
|
@ -12,7 +12,8 @@ vars = None
|
||||||
prefs = None
|
prefs = None
|
||||||
|
|
||||||
|
|
||||||
def startup():
|
# Initialize helpful variables
|
||||||
|
def init():
|
||||||
global vars
|
global vars
|
||||||
global prefs
|
global prefs
|
||||||
vars = Map()
|
vars = Map()
|
||||||
|
@ -20,7 +21,12 @@ def startup():
|
||||||
event.start("POSTINIT")
|
event.start("POSTINIT")
|
||||||
|
|
||||||
|
|
||||||
|
# If a preference has not already been set, set pref[key] = value
|
||||||
def init_pref(key, value):
|
def init_pref(key, value):
|
||||||
global prefs
|
global prefs
|
||||||
if prefs.get(key) == None:
|
if prefs.get(key) == None:
|
||||||
prefs[key] = value
|
prefs[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
def startup():
|
||||||
|
pass
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
from libsaria import path
|
from libsaria import path
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
plugin = None
|
||||||
|
|
||||||
PROTO = pickle.HIGHEST_PROTOCOL
|
PROTO = pickle.HIGHEST_PROTOCOL
|
||||||
|
|
||||||
def save(item, file, ext="pickle"):
|
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)
|
savefile(item, file)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ def savefile(item, file):
|
||||||
|
|
||||||
|
|
||||||
def load(file, ext="pickle"):
|
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)
|
return loadfile(file)
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,3 +33,12 @@ def loadfile(file):
|
||||||
return item
|
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
|
mkdir = os.mkdir
|
||||||
rm = os.remove
|
rm = os.remove
|
||||||
walk = os.walk
|
walk = os.walk
|
||||||
|
sep = os.sep
|
||||||
|
|
||||||
dir = None
|
cp = None
|
||||||
def sariadir():
|
saria_dir = None
|
||||||
global dir
|
plugin_dir = None
|
||||||
if dir == None:
|
|
||||||
dir = join(expand("~"), ".saria")
|
|
||||||
if exists(dir) == False:
|
|
||||||
mkdir(dir)
|
|
||||||
return dir
|
|
||||||
|
|
||||||
|
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 libsaria
|
||||||
import ocarina
|
import ocarina
|
||||||
|
|
||||||
libsaria.startup()
|
libsaria.init()
|
||||||
libsaria.init_pref("window_size", (800,600))
|
libsaria.init_pref("window_size", (800,600))
|
||||||
|
|
||||||
prefs = libsaria.prefs
|
prefs = libsaria.prefs
|
||||||
|
@ -17,4 +17,5 @@ win = ocarina.get_window(prefs["window_size"])
|
||||||
#win.move(0,0)
|
#win.move(0,0)
|
||||||
ocarina.add_tab("Test", label)
|
ocarina.add_tab("Test", label)
|
||||||
|
|
||||||
|
libsaria.startup()
|
||||||
ocarina.startup()
|
ocarina.startup()
|
||||||
|
|
|
@ -9,8 +9,8 @@ tabs = None
|
||||||
|
|
||||||
|
|
||||||
# Function override variables
|
# Function override variables
|
||||||
get_main_tabs = None
|
get_tabs = None
|
||||||
get_window = None
|
get_window = None
|
||||||
|
|
||||||
|
|
||||||
# Global variables for some objects
|
# Global variables for some objects
|
||||||
|
@ -27,37 +27,37 @@ def exit(widget, event):
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
||||||
|
|
||||||
def get_main_tabs_init():
|
def get_tabs_once():
|
||||||
global tabs
|
global tabs
|
||||||
global get_main_tabs
|
global get_tabs
|
||||||
global main_tabs
|
global main_tabs
|
||||||
import tabs
|
import tabs
|
||||||
main_tabs = tabs.Tabs()
|
main_tabs = tabs.Tabs()
|
||||||
main_tabs
|
main_tabs
|
||||||
get_main_tabs = get_main_tabs_always
|
get_tabs = get_tabs_rest
|
||||||
return main_tabs
|
return main_tabs
|
||||||
def get_main_tabs_always():
|
def get_tabs_rest():
|
||||||
global main_tabs
|
global main_tabs
|
||||||
return main_tabs
|
return main_tabs
|
||||||
get_main_tabs = get_main_tabs_init
|
get_tabs = get_tabs_once
|
||||||
|
|
||||||
def add_tab(text, content):
|
def add_tab(text, content):
|
||||||
tabs = get_main_tabs()
|
tabs = get_tabs()
|
||||||
tabs.append_page(content, text)
|
tabs.append_page(content, text)
|
||||||
|
|
||||||
|
|
||||||
def get_window_init(size):
|
def get_window_once(size):
|
||||||
global window
|
global window
|
||||||
global get_window
|
global get_window
|
||||||
global main_window
|
global main_window
|
||||||
import window
|
import window
|
||||||
main_window = window.Window(size)
|
main_window = window.Window(size)
|
||||||
main_window.add(get_main_tabs())
|
main_window.add(get_tabs())
|
||||||
get_window = get_window_always
|
get_window = get_window_rest
|
||||||
return main_window
|
return main_window
|
||||||
def get_window_always(size=None):
|
def get_window_rest(size=None):
|
||||||
global main_window
|
global main_window
|
||||||
if size != None:
|
if size != None:
|
||||||
main_window.resize(size[0], size[1])
|
main_window.resize(size[0], size[1])
|
||||||
return main_window
|
return main_window
|
||||||
get_window = get_window_init
|
get_window = get_window_once
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import ocarina
|
import ocarina
|
||||||
libsaria = ocarina.libsaria
|
libsaria = ocarina.libsaria
|
||||||
gtk = ocarina.gtk
|
gtk = ocarina.gtk
|
||||||
|
data = None
|
||||||
|
|
||||||
TARGET_TYPE_URI_LIST = 80
|
TARGET_TYPE_URI_LIST = 80
|
||||||
|
|
||||||
|
@ -28,9 +29,12 @@ class Window(gtk.Window):
|
||||||
|
|
||||||
|
|
||||||
def dnd_receive(self, widget, context, x, y, selection, type, time):
|
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:
|
if type == TARGET_TYPE_URI_LIST:
|
||||||
uri = selection.data.strip('\r\n\x00')
|
uri = selection.data.strip('\r\n\x00')
|
||||||
import os
|
import os
|
||||||
for file in uri.split():
|
for file in uri.split():
|
||||||
file = file[7:]
|
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:
|
if len(sys.argv) == 1:
|
||||||
before = now()
|
before = now()
|
||||||
libsaria.startup()
|
libsaria.init()
|
||||||
after = now()
|
after = now()
|
||||||
print "startup took", after-before
|
print "startup took", after-before
|
||||||
print
|
print
|
||||||
|
|
Loading…
Reference in New Issue