# -*- coding: utf-8 -*-
import sys, os, gettext, platform
import pluginsystem, configsystem, utils
reload(sys)
#Locale support
try:
LOCALE_DIR = "plugins" + os.path.sep + "jake" + os.path.sep + "locale"
t = gettext.translation("main", LOCALE_DIR)
_ = t.ugettext
except:
_ = utils.fake_locale
#Global vars
capabilities = [_("!config"), _("!about"), _("?config"), _("?about")]
config_struct = (
(_("Jake-PyQT4"),
(
('prompt', ('string', (_('Console prompt')))),
('skin', ('list', (_("Jake-PyQT4 skin")), utils.get_skins())),
('appwidth', ('slider', (_("Application width")), 10, 100, 10)),
('appheight', ('slider', (_("Application height")), 10, 100, 10)),
('screen', ('list', (_("Appear on screen:")), utils.get_screens())),
('alwaysontop', ('bool', (_("Always on top")))),
)
),
)
config_prefs = {
'prompt' : 'console@jake: ',
'skin' : 0,
'appwidth' : 100,
'appheight' : 50,
'screen' : 0,
'alwaysontop' : False
}
#Init event
@pluginsystem.register("init")
def init(*args, **kwargs):
global config_prefs
config_prefs = configsystem.load_config("jake", config_prefs)
#Reload-config event to make a specific plugin reload it's config
@pluginsystem.register("reload_config")
def reload_config(*args, **kwargs):
global config_prefs
if "plugin" in kwargs:
if kwargs["plugin"] == "jake":
config_prefs = configsystem.load_config("jake", config_prefs)
else:
print _("WARNING from Jake plugin: reload_config event was called with inappropiate number of arguments! Please check code.")
#Triggered after return/enter hit
@pluginsystem.register("analyze_command")
def analyze_command(*args, **kwargs):
if "data" in kwargs and "obj" in kwargs:
cmd = kwargs["data"]
console = kwargs["obj"] #save the console from which we got the call
if cmd == _("!about"):
output = "<a href='http://jake-pyqt4.blogspot.com/'>" + config_others[0] + "</a>" + config_others[1] + "<br>"
output += _("Jake-PyQT4 is a console based app written in Python and Qt4 bindings that aims to make your life easy searching those things that you want, for example search in google, show the weather, find a download link for an mp3, and a lot more stuff.")
console.printString(output, False, False)
elif cmd == _("!config"):
configsystem.config_dialog("jake", config_struct, config_prefs, console)
elif cmd == _("?about"):
console.printString(_("The command !about will print a short description about Jake-PyQT4 in the console."), False, False)
elif cmd == _("?config"):
console.printString(_("The command !config will show up a config dialog which will let you configure the behavior of Jake-PyQT4."), False, False)
else:
print _("WARNING from Jake plugin: analyze_command event was called with inappropiate number of arguments! Please check code.")
#Send all available commands to the plugin system
@pluginsystem.register("get_capabilities")
def get_capabilities(*args, **kwargs):
if "cap" in kwargs:
kwargs["cap"].extend(capabilities)
else:
print _("WARNING from Jake plugin: get_capabilities event was called with inappropiate number of arguments! Please check code.")
#Return Jake-PyQT4 config
@pluginsystem.register("get_config")
def get_config(*args, **kwargs):
global config, config_others
if "config" in kwargs and "plugin" in kwargs:
if kwargs["plugin"] == "jake":
kwargs["config"].append(config_prefs)
else:
print _("WARNING from Jake plugin: get_config event was called with inappropiate number of arguments! Please check code.")