Commit 0545846f authored by Martin Urban's avatar Martin Urban
Browse files

Move PXL extension to a different repo

parent 0c98815a
# -*- coding: utf-8 -*-
from vispa.server import AbstractExtension
from controller import PXLBrowserController
import logging
logger = logging.getLogger(__name__)
class PXLBrowserExtension(AbstractExtension):
#required
def name(self):
return "pxlbrowser"
def dependencies(self):
return []
# required
def setup(self):
self.add_controller(PXLBrowserController())
self.add_js("js/extension.js")
self.add_css("css/style.css")
self.add_workspace_directoy()
# -*- coding: utf-8 -*-
import cherrypy
import logging
import vispa.workspace
from vispa.controller import AbstractController
logger = logging.getLogger(__name__)
class PXLBrowserController(AbstractController):
@cherrypy.expose
@cherrypy.tools.ajax()
def start_reader(self, filepath):
rpc = self.extension.get_workspace_instance("PXLBrowserRpc")
rpc.start_reader(filepath)
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def getCache(self):
rpc = self.extension.get_workspace_instance("PXLBrowserRpc")
return rpc.getCache()
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def getObjectProperties(self, oid):
rpc = self.extension.get_workspace_instance("PXLBrowserRpc")
return rpc.getObjectProperties(oid)
\ No newline at end of file
/*
* This is a less-css file. It allows class mixinx, variables, anc basic
* computation tasks (addition, multiplication, etc). You can find more
* information on less-css at http://lesscss.org/. In order to avoid naming
* collisions, you should use prefixes in your class names.
*/
.pxlbrowser_mainpanel {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
/*background-image: url(../img/greyprint.png);*/
overflow: auto;
}
.pxlbrowser_infolabel {
position: fixed;
bottom: 5px;
right: 0px;
padding: 2px 3px 3px 3px;
color: #505050;
background-color: white;
font-size: 11px;
border: 1px solid #b0b0b0;
border-width: 1px 0px 0px 1px;
border-radius: 4px 0px 0px 0px;
}
.pxlbrowser_infolabel_box {
position: relative;
clear: both;
}
.pxlbrowser_infolabel_label {
float: left;
font-weight: bold;
}
.pxlbrowser_infolabel_content {
float: right;
margin-left: 5px;
}
.pxlbrowser_toolbar {
position: relative;
display: table;
float: left;
top: 0px;
left: 12%;
padding: 1px;
z-index: 2;
}
.pxlbrowser_toolbar_display {
height: 27px;
width: 70px;
margin: 0px 10px 0px 10px;
color: grey;
}
.pxlbrowser_toolbar_jumpbox {
height: 25px;
width: 50px;
margin: 0px 5px 0px 20px;
}
.pxlbrowser_tree_outer {
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
width: 50%;
border: 2px solid lightgrey;
border-width: 0px 2px 0px 0px;
z-index: 1;
overflow-y: auto;
overflow-x: hidden;
}
.pxlbrowser_tree {
position: absolute;
top: 30px;
left: 0px;
bottom: 0px;
right: 0px;
}
.pxlbrowser_data_outer {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
width: 50%;
overflow: auto;
}
.pxlbrowser_data {
position: absolute;
top: 30px;
right: 0px;
bottom: 0px;
left: 0px;
}
.pxlbrowser_gridpanel {
margin: 0px 0px 15px 20px;
}
.pxlbrowser_gridpanel_label {
color: #263c60;
font-style: italic;
margin: 0px 0px 2px 5px;
}
.pxlbrowser_treenode {
position: absolute;
border-radius: 3px;
padding: 6px;
font-size: 14px;
color: white;
box-shadow: 1px 1px 2px grey;
background: linear-gradient(top, #39547f 0%, #263c60 100%);
background: -webkit-linear-gradient(top, #39547f 0%, #263c60 100%);
background: -moz-linear-gradient(top, #39547f 0%, #263c60 100%);
background: -o-linear-gradient(top, #39547f 0%, #263c60 100%);
cursor: pointer;
}
.pxlbrowser_treenode:active {
box-shadow: inset 0px 0px 5px black;
}
.pxlbrowser_treenode_selected {
position: absolute;
border-radius: 3px;
padding: 4px;
font-size: 14px;
color: #39547f;
border: 2px solid #39547f;
background: linear-gradient(top, #e8e8e8 0%, #d0d0d0 100%);
background: -webkit-linear-gradient(top, #e8e8e8 0%, #d0d0d0 100%);
background: -moz-linear-gradient(top, #e8e8e8 0%, #d0d0d0 100%);
background: -o-linear-gradient(top, #e8e8e8 0%, #d0d0d0 100%);
cursor: pointer;
}
\ No newline at end of file
<!--
<div style="height:100%;width:100%;">
<h2>PXLBrowser Extension</h2>
<div class="demo-content">
<span class="demo-content-text" data-bind="files"></span>
<br />
<button class="btn btn-info">Change color</button>
</div>
</div>
-->
<div class="pxlbrowser_mainpanel">
<div class="pxlbrowser_infolabel">
<div class="pxlbrowser_infolabel_box">
<div class="pxlbrowser_infolabel_label">
infolabel label 1
</div>
<div class="pxlbrowser_infolabel_content">
infolabel content 1
</div>
</div>
</div>
<div class="pxlbrowser_toolbar">
<button class = "btn btn-primary" type="button" id="prev">Prev</button>
<span class="'pxlbrowser_toolbar_display'"> ?/? </span>
<button class = "btn btn-primary" type="button" id="next">Next</button>
<button class = "btn btn-primary" type="button" id="go" title="Todo">Go to</button>
</div>
<div class="pxlbrowser_tree_outer">
<div class="pxlbrowser_tree">
pxlbrowser tree
</div>
</div>
<div class="pxlbrowser_data_outer">
<div class="pxlbrowser_data">
pxlbrowser data
</div>
</div>
</div>
\ No newline at end of file
var PXLBrowserExtension = vispa.Extension.extend({
init: function() {
this._super("pxlbrowser");
this.addView("PXLBrowser", PXLBrowserView);
var self = this;
this.setOptions(PXLBrowserView, {
maxInstances: 1
});
this.setDefaultPreferences(PXLBrowserView, {
CacheSize: {
// required
type: "integer",
value: 10,
// optional
description: "The number of events to be cached",
range: [1, 100, 1]
}
}, {
title: "PXLBrowser"
});
/*
this.setDefaultShortcuts(PXLBrowserView, {
test: {
description: "some test shortcut",
value: "ctrl+s",
callback: function() {
this.setModified(false);
this.alert("Instance " + this.getId() + " saved!");
}
}
}, {
title: "PXLBrowser"
});
*/
this.addMenuEntry("PXLBrowser", {
iconClass: "glyphicon glyphicon-picture",
callback: function(workspaceId) {
self.createInstance(workspaceId, PXLBrowserView);
}
});
// register to listen to certain file extensions
this.fileExtensions = ["pxlio"];
$.each(this.fileExtensions, function(i, key) {
self.addFileHandler(key, function(workspaceId, path) {
self.createInstance(workspaceId, "center", path);
});
});
}
});
var PXLBrowserView = vispa.ExtensionView.Center.extend({
init: function(preferences, shortcuts, path) {
this._super(preferences, shortcuts);
this.path = "/home/thorben/Test_10.pxlio"; //hard coded, needs to be removed eventually
this.addMenuEntry("Open pxl file...", function() {
self.alert('Here a file selector instance will show up');
});
},
setup: function() {
this._super();
this.setLabel('PXLBrowser');
this.setIcon(this.static("img/myicon.png"));
},
applyPreferences: function() {
this._super();
//this.node.css("background-color", this.getPreference("backgroundColor"));
},
render: function(node) {
var self = this;
this.node = node;
this.setLoading(true);
var dfd = this.getTemplate("html/main.html", function(err, tmpl) {
$(tmpl).appendTo(node);
self.setLoading(false);
});
$.when(dfd).then(function() {
self.POST("start_reader", {
filepath: self.path
}).done(function() {
self.POST("getCache").done(function(data) {
console.log(data);
self.POST("getObjectProperties", {
oid: '773e039e-772f-4748-ba4e-4e440a981831' //just an exemplary ID from the very first event
}).done(function(data) {
console.log(data);
});
});
});
})
},
onResize: function(dimensions) {},
onBeforeShow: function() {
return this;
},
onAfterShow: function() {
return this;
},
onBeforeHide: function() {
return this;
},
onAfterHide: function() {
return this;
},
onBeforeClose: function() {
return this;
},
onAfterClose: function() {
return this;
}
});
$(function() {
vispa.extensions.registerExtension(PXLBrowserExtension);
});
\ No newline at end of file
'''Original code from VISPA 0.5, no modifications have been applied'''
#import cherrypy
from pxl import core, hep, astro
import random
from math import isinf
import logging
try:
from pxl.healpix import *
Healpix_initialize()
logging.getLogger("extension.pxlbrowser.dataaccessor").info("pxl.healpix initialized")
except ImportError:
pass
class DataAccessor(object):
@staticmethod
def canReadObject(object):
return False
@staticmethod
def getProperties(object):
pass
@staticmethod
def getId(object):
pass
@staticmethod
def getChildren(object):
pass
@staticmethod
def getType():
return object
@staticmethod
def getName(object):
return None
class PxlEventDataAccessor(DataAccessor):
@staticmethod
def canReadObject(object):
return isinstance(object, core.Event)
@staticmethod
def getProperties(object):
event = core.toEvent(object)
infoDict= []
return infoDict
@staticmethod
def getId(object):
return core.toEvent(object).getId().toString()
@staticmethod
def getChildren(object):
event=core.toEvent(object)
infoDict=[]
for child in event.getObjects():
infoDict.append(DataObject(child))
return infoDict
@staticmethod
def getType():
return core.Event
class PxlEventViewDataAccessor(DataAccessor):
@staticmethod
def canReadObject(object):
return isinstance(object, hep.EventView)
@staticmethod
def getProperties(object):
eventView=hep.toEventView(object)
infoDict=[]
return infoDict
@staticmethod
def getId(object):
return hep.toEventView(object).getId().toString()
@staticmethod
def getName(object):
return hep.toEventView(object).getName()
@staticmethod
def getChildren(object):
eventView=hep.toEventView(object)
infoDict=[]
for child in eventView.getObjects():
infoDict.append(DataObject(child))
return infoDict
@staticmethod
def getType():
return hep.EventView
class PxlParticleAccessor(DataAccessor):
@staticmethod
def canReadObject(object):
return isinstance(object, hep.Particle)
@staticmethod
def getProperties(object):
particle=hep.toParticle(object)
eta = particle.getEta()
sign = "+" if eta > 0 else "-"
eta = sign + 'inf' if isinf(eta) else eta
infoDict = [
{"E": particle.getE()},
{"Et": particle.getEt()},
{"Mass": particle.getMass()},
{"Eta": eta},
{"Phi": particle.getPhi()},
{"P": particle.getP()},
{"Pt": particle.getPt()},
{"Px": particle.getPx()},
{"Py": particle.getPy()},
{"Pz": particle.getPz()}]
return infoDict
@staticmethod
def getId(object):
return hep.toParticle(object).getId().toString()
@staticmethod
def getName(object):
return hep.toParticle(object).getName()
@staticmethod
def getChildren(object):
return []
@staticmethod
def getType():
return hep.Particle
class PxlRelativeAccessor(DataAccessor):
@staticmethod
def canReadObject(object):
return isinstance(object, hep.Particle)
@staticmethod
def getIdList(objectlist):
list=[]
for obj in objectlist:
list.append(obj.id().toString())
return list
@staticmethod
def getNameList(objectlist):
#check here if object has a getName method - not implemented in pxl::Relative
list=[]
for obj in objectlist:
name="None"
try:
name = obj.getName()
except:
pass
list.append(name)
return list
@staticmethod
def getProperties(object):
relative=core.toRelative(object)
infoDict = [
{"Daughter ids": PxlRelativeAccessor.getIdList(relative.getDaughterRelations().getContainer())},
{"Daughter names": PxlRelativeAccessor.getNameList(relative.getDaughterRelations().getContainer())},
{"Mother ids": PxlRelativeAccessor.getIdList(relative.getMotherRelations().getContainer())},
{"Mother names": PxlRelativeAccessor.getNameList(relative.getMotherRelations().getContainer())},
{"SoftRelations": []}
]
return infoDict
@staticmethod
def getId(object):
return object.getId().toString()
@staticmethod
def getName(object):
return object.getName()
@staticmethod
def getChildren(object):
return []
@staticmethod
def getType():
return core.Relative
class UserRecordHelperAccessor(DataAccessor):
@staticmethod
def canReadObject(object):
return isinstance(object,core.UserRecordHelper)