Skip to content

Commit

Permalink
Initial commit on github
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Apr 6, 2015
0 parents commit 9559104
Show file tree
Hide file tree
Showing 70 changed files with 6,232 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*.xpi
/build
15 changes: 15 additions & 0 deletions chrome.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
content extensiondev jar:koextensiondev.jar!/content/
locale extensiondev en-US jar:koextensiondev.jar!/locale/en-US/
skin extensiondev classic/1.0 jar:koextensiondev.jar!/skin/
overlay chrome://browser/content/browser.xul chrome://extensiondev/content/firefoxOverlay.xul
overlay chrome://messenger/content/messenger.xul chrome://extensiondev/content/thunderbirdOverlay.xul
overlay chrome://navigator/content/navigatorOverlay.xul chrome://extensiondev/content/seamonkeyOverlay.xul
overlay chrome://komodo/content/komodo.xul chrome://extensiondev/content/komodoOverlay.xul
style chrome://global/content/customizeToolbar.xul chrome://extensiondev/skin/extensiondev.css

# Need to specify alternative xpt file - as nsIVairant changed from 1.9.x
interfaces components/moz2/pyIShell.xpt
component {4e5c9764-d465-4fef-ae24-8032f257d174} components/pyShell.py
contract @twhiteman.netfirms.com/pyShell;1 {4e5c9764-d465-4fef-ae24-8032f257d174}

manifest components/component.manifest
3 changes: 3 additions & 0 deletions components/component.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
contract @twhiteman.netfirms.com/pyShell;1 {4e5c9764-d465-4fef-ae24-8032f257d174}
component {4e5c9764-d465-4fef-ae24-8032f257d174} pyShell.py
interfaces pyIShell.xpt
Binary file added components/moz2/pyIShell.xpt
Binary file not shown.
Binary file added components/pyIShell.xpt
Binary file not shown.
132 changes: 132 additions & 0 deletions components/pyShell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env python

#**** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is PyShell code.
#
# The Initial Developer of the Original Code is Todd Whiteman.
# Portions created by the Initial Developer are Copyright (C) 2007-2008.
# All Rights Reserved.
#
# Contributor(s):
# Todd Whiteman
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
#**** END LICENSE BLOCK *****

#
# Overview:
# Provides Python evaluation and completions for the PyShell UI.
#

import os
import sys
import time
import traceback
from cStringIO import StringIO

from xpcom import components, ServerException, nsError
from xpcom.server import WrapObject

class pyShell:
_com_interfaces_ = [components.interfaces.pyIShell]
_reg_clsid_ = "{4e5c9764-d465-4fef-ae24-8032f257d174}"
_reg_contractid_ = "@twhiteman.netfirms.com/pyShell;1"
_reg_desc_ = "Python shell service"

pyshellGlobals = {
# Give away some free items...
"os": os,
"sys": sys,
"time": time,
# And xpcom accessors.
"components": components,
"Components": components
}

def __init__(self):
pass

def _eval_code_and_return_result(self, code):
return eval(code, self.pyshellGlobals, self.pyshellGlobals)

# This little exec snippet comes from the python mailing list, see:
# http://mail.python.org/pipermail/python-list/2005-June/328628.html
def _exec_code_and_get_output(self, code):
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
exec code in self.pyshellGlobals, self.pyshellGlobals
return sys.stdout.getvalue()
finally:
sys.stdout = old_stdout

def evalPythonString(self, code):
# Ensure the code ends with an empty newline
code += '\n\n'
try:
try:
result = self._eval_code_and_return_result(code)
try:
# See if the result can be turned into an xpcom object
return WrapObject(result, components.interfaces.nsIVariant)
except ValueError:
# else, we'll just return a string representation
return repr(result)
except SyntaxError:
return self._exec_code_and_get_output(code)
except Exception, e:
# Format the exception, removing the exec/eval sections.
exc_tb = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
return "".join(exc_tb[:1] + exc_tb[3:])

def getCompletionsForName(self, objname, prefix):
#print "getCompletionsForName:: obname: %r, prefix: %r" % (objname, prefix, )
# Global scope.
if not objname:
cplns = self.pyshellGlobals.keys()
# Hack for nice xpcom completions.
elif objname.lower() == "components.interfaces":
cplns = components.interfaces.keys()
elif objname.lower() == "components.classes":
cplns = components.classes.keys()
# Object scope.
else:
foundObject = None
names = objname.split(".")
foundObject = self.pyshellGlobals[names[0]]
for name in names[1:]:
foundObject = getattr(foundObject, name)
# Got the object, now return the matches
cplns = dir(foundObject)

if prefix:
cplns = [x for x in cplns if x.startswith(prefix)]
return cplns

# The static list of PyXPCOM classes in this module:
PYXPCOM_CLASSES = [
pyShell,
]
97 changes: 97 additions & 0 deletions content/chromeShellExtras.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
function printDoScope(s, scopeObjText)
{
var newdiv = document.createElement("div");
var a = document.createElement("a");
a.href = "javascript:go('scope(" + scopeObjText + ")')";
a.appendChild(document.createTextNode(s));
newdiv.appendChild(a);
newdiv.className = "normalOutput";
_out.appendChild(newdiv);
return newdiv;
}

shellCommands.enumerateWindows = function enumerateWindows()
{
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var en = wm.getEnumerator("");

var n = 0;
Shell.enumWins = [];
while(en.hasMoreElements()) {
var w = en.getNext();
if(w.document.getElementById("content") && w.document.getElementById("content").tagName == "tabbrowser") {
var b = w.document.getElementById("content");
var ntabs = b.mPanelContainer.childNodes.length;
for(var i=0; i<ntabs; i++) {
var tb = b.getBrowserAtIndex(i);
try {
Shell.enumWins[n] = tb.contentWindow;
printDoScope(tb.currentURI.spec, "Shell.enumWins[" + n + "]");
n++;
} catch(e) {}
}
}

Shell.enumWins[n] = w;
printDoScope(w.location.href,"Shell.enumWins[" + n + "]");
n++;
}
}

function onChromeShellExtrasLoad()
{
var a = document.createElement("a");
a.appendChild(document.createTextNode("enumerateWindows()"));
a.href = "javascript:go('enumerateWindows()')";
a.setAttribute("accesskey","E");
var odiv = document.getElementById("output");
odiv.appendChild(document.createTextNode(" "));
odiv.appendChild(a);

loadHistory();
window.setTimeout(function() {
window.shellCommands.enumerateWindows();
window.shellCommands.scope(Shell.enumWins[Shell.enumWins.length - 1].opener);
}, 50);
}

function loadHistory()
{
var items = loadHistoryItems("http://ted.mielczarek.org/code/mozilla/extensiondev#jsshell_history", "http://ted.mielczarek.org/code/mozilla/extensiondev#jsshell_historyitem");
histList = items;
if(histList[histList.length-1] != "")
histList.push("");
histPos = (histList.length > 0) ? histList.length-1 : 0;
}

function saveHistory()
{
var num = min(histList.length, 20 + 1);
var start = histList.length - num;

saveHistoryItems(histList.slice(start, histList.length), "http://ted.mielczarek.org/code/mozilla/extensiondev#jsshell_history", "http://ted.mielczarek.org/code/mozilla/extensiondev#jsshell_historyitem");
}

function onChromeShellExtrasUnload()
{
saveHistory();
releaseRDFService();
}

shellCommands.propsPlus = function(o) {
for(var x in o) {
try {
var v = o[x];
if(v instanceof Function) {
println(x + ": Function");
}
else {
println(x + ": " + v);
}
}
catch(ex) {}
}
}

window.addEventListener("load", onChromeShellExtrasLoad, true);
window.addEventListener("unload", onChromeShellExtrasUnload, true);
Loading

0 comments on commit 9559104

Please sign in to comment.