2011-02-17 19:43:48 +00:00
|
|
|
#!@PYTHON@
|
|
|
|
# -*- mode: Python; indent-tabs-mode: nil; -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
2011-06-23 01:29:20 +00:00
|
|
|
import socket
|
2011-02-17 19:43:48 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import optparse
|
|
|
|
import tempfile
|
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
try:
|
|
|
|
import simplejson as json
|
|
|
|
except ImportError:
|
|
|
|
print 'The Python simplejson module is required'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option("", "--create-extension", action="store_true",
|
|
|
|
help="Create a new GNOME Shell extension")
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if args:
|
|
|
|
parser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2011-06-23 01:32:08 +00:00
|
|
|
SAMPLE_EXTENSION_FILES = {
|
|
|
|
"extension.js": """
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
|
|
|
let text;
|
|
|
|
|
|
|
|
function _hideHello() {
|
|
|
|
Main.uiGroup.remove_actor(text);
|
|
|
|
text = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _showHello() {
|
|
|
|
if (!text) {
|
|
|
|
text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });
|
|
|
|
Main.uiGroup.add_actor(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
text.opacity = 255;
|
|
|
|
|
|
|
|
let monitor = Main.layoutManager.primaryMonitor;
|
|
|
|
|
|
|
|
text.set_position(Math.floor(monitor.width / 2 - text.width / 2),
|
|
|
|
Math.floor(monitor.height / 2 - text.height / 2));
|
|
|
|
|
|
|
|
Tweener.addTween(text,
|
|
|
|
{ opacity: 0,
|
|
|
|
time: 2,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: _hideHello });
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
let button = new St.Bin({ style_class: 'panel-button',
|
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
track_hover: true });
|
|
|
|
let icon = new St.Icon({ icon_name: 'system-run',
|
|
|
|
icon_type: St.IconType.SYMBOLIC,
|
|
|
|
style_class: 'system-status-icon' });
|
|
|
|
|
|
|
|
button.set_child(icon);
|
|
|
|
button.connect('button-press-event', _showHello);
|
|
|
|
|
|
|
|
Main.panel._rightBox.insert_actor(button, 0);
|
|
|
|
}
|
|
|
|
""",
|
|
|
|
|
|
|
|
"stylesheet.css": """
|
|
|
|
.helloworld-label {
|
|
|
|
font-size: 36px;
|
|
|
|
font-weight: bold;
|
|
|
|
color: #ffffff;
|
|
|
|
background-color: rgba(10,10,10,0.7);
|
|
|
|
border-radius: 5px;
|
|
|
|
padding: .5em;
|
|
|
|
}
|
|
|
|
""",
|
|
|
|
}
|
|
|
|
|
2011-02-17 19:43:48 +00:00
|
|
|
if options.create_extension:
|
|
|
|
print
|
|
|
|
print '''Name should be a very short (ideally descriptive) string.
|
|
|
|
Examples are: "Click To Focus", "Adblock", "Shell Window Shrinker".
|
|
|
|
'''
|
|
|
|
name = raw_input('Name: ').strip()
|
|
|
|
print
|
|
|
|
print '''Description is a single-sentence explanation of what your extension does.
|
|
|
|
Examples are: "Make windows visible on click", "Block advertisement popups"
|
|
|
|
"Animate windows shrinking on minimize"
|
|
|
|
'''
|
|
|
|
description = raw_input('Description: ').strip()
|
|
|
|
underifier = re.compile('[^A-Za-z]')
|
|
|
|
sample_uuid = underifier.sub('_', name)
|
|
|
|
# TODO use evolution data server
|
2011-06-23 01:29:20 +00:00
|
|
|
hostname = socket.gethostname()
|
2011-02-17 19:43:48 +00:00
|
|
|
sample_uuid = sample_uuid + '@' + hostname
|
|
|
|
|
|
|
|
print
|
|
|
|
print '''Uuid is a globally-unique identifier for your extension.
|
|
|
|
This should be in the format of an email address (foo.bar@extensions.example.com), but
|
|
|
|
need not be an actual email address, though it's a good idea to base the uuid on your
|
|
|
|
email address. For example, if your email address is janedoe@example.com, you might
|
|
|
|
use an extension title clicktofocus@janedoe.example.com.'''
|
|
|
|
uuid = raw_input('Uuid [%s]: ' % (sample_uuid, )).strip()
|
|
|
|
if uuid == '':
|
|
|
|
uuid = sample_uuid
|
|
|
|
|
|
|
|
extension_path = os.path.join(os.path.expanduser('~/.local'), 'share', 'gnome-shell', 'extensions', uuid)
|
|
|
|
if os.path.exists(extension_path):
|
|
|
|
print "Extension path %r already exists" % (extension_path, )
|
|
|
|
sys.exit(0)
|
|
|
|
os.makedirs(extension_path)
|
|
|
|
meta = { 'name': name,
|
|
|
|
'description': description,
|
|
|
|
'uuid': uuid,
|
|
|
|
'shell-version': ['@VERSION@'] }
|
|
|
|
f = open(os.path.join(extension_path, 'metadata.json'), 'w')
|
|
|
|
try:
|
|
|
|
json.dump(meta, f)
|
|
|
|
except AttributeError:
|
|
|
|
# For Python versions older than 2.6, try using the json-py module
|
|
|
|
f.write(json.write(meta) + '\n')
|
|
|
|
f.close()
|
|
|
|
|
2011-06-23 01:32:08 +00:00
|
|
|
for filename, contents in SAMPLE_EXTENSION_FILES.iteritems():
|
|
|
|
path = os.path.join(extension_path, filename)
|
|
|
|
f = open(path, 'w')
|
|
|
|
f.write(contents)
|
|
|
|
f.close()
|
2011-02-17 19:43:48 +00:00
|
|
|
|
|
|
|
print "Created extension in %r" % (extension_path, )
|
|
|
|
subprocess.Popen(['gnome-open', extensionjs_path])
|
|
|
|
sys.exit(0)
|