Commits

Matthew Turk committed 77f5f1f

Updates, and adding new files I forgot.

Comments (0)

Files changed (4)

bottle/column.html

+<html>
+<head>
+  <title>Column Layout</title>
+	<link rel="stylesheet" type="text/css" href="resources/ext-all.css" />
+
+    <!-- GC -->
+ 	<!-- LIBS -->
+ 	<script type="text/javascript" src="resources/ext-base.js"></script>
+ 	<!-- ENDLIBS -->
+
+    <script type="text/javascript" src="resources/ext-all.js"></script>
+
+	<style type="text/css">
+	html, body {
+        font:normal 12px verdana;
+        margin:0;
+        padding:0;
+        border:0 none;
+        overflow:hidden;
+        height:100%;
+    }
+	.x-panel-body p {
+	    margin:5px;
+	}
+    .x-column-layout-ct .x-panel {
+        margin-bottom:5px;
+    }
+    .x-column-layout-ct .x-panel-dd-spacer {
+        margin-bottom:5px;
+    }
+    .settings {
+        background-image:url(resources/folder_wrench.png) !important;
+    }
+    .nav {
+        background-image:url(resources/folder_go.png) !important;
+    }
+    </style>
+	<script type="text/javascript">
+
+    Ext.onReady(function(){
+
+       // NOTE: This is an example showing simple state management. During development,
+       // it is generally best to disable state management as dynamically-generated ids
+       // can change across page loads, leading to unpredictable results.  The developer
+       // should ensure that stable state ids are set for stateful components in real apps.
+       Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
+
+       var viewport = new Ext.Viewport({
+            layout:'border',
+            items:[{
+                region:'west',
+                id:'west-panel',
+                title:'West',
+                split:true,
+                width: 200,
+                minSize: 175,
+                maxSize: 400,
+                collapsible: true,
+                margins:'35 0 5 5',
+                cmargins:'35 5 5 5',
+                layout:'accordion',
+                layoutConfig:{
+                    animate:true
+                },
+                items: [{
+                    html: Ext.example.shortBogusMarkup,
+                    title:'Navigation',
+                    autoScroll:true,
+                    border:false,
+                    iconCls:'nav'
+                },{
+                    title:'Settings',
+                    html: Ext.example.shortBogusMarkup,
+                    border:false,
+                    autoScroll:true,
+                    iconCls:'settings'
+                }]
+            },{
+                region:'center',
+                margins:'35 5 5 0',
+                layout:'column',
+                autoScroll:true,
+                items:[{
+                    columnWidth:.33,
+                    baseCls:'x-plain',
+                    bodyStyle:'padding:5px 0 5px 5px',
+                    items:[{
+                        title: 'A Panel',
+                        html: Ext.example.shortBogusMarkup
+                    }]
+                },{
+                    columnWidth:.33, 
+                    baseCls:'x-plain',
+                    bodyStyle:'padding:5px 0 5px 5px',
+                    items:[{
+                        title: 'A Panel',
+                        html: Ext.example.shortBogusMarkup
+                    }]
+                },{
+                    columnWidth:.33,
+                    baseCls:'x-plain',
+                    bodyStyle:'padding:5px',
+                    items:[{
+                        title: 'A Panel',
+                        html: Ext.example.shortBogusMarkup
+                    },{
+                        title: 'Another Panel',
+                        html: Ext.example.shortBogusMarkup
+                    }]
+                }]
+            }]
+        });
+    });
+	</script>
+</head>
+<body>
+<script type="text/javascript" src="resources/examples.js"></script><!-- EXAMPLES -->
+  </body>
+</html>

bottle/ext_widgets.py

+import abc
+import numpy as na
+import uuid
+import base64
+import tempfile
+
+from yt.utilities.amr_utils import write_png_to_file
+from yt.visualization.image_writer import map_to_colors
+
+class YTExtWebWidget(object):
+    __metaclass__ = abc.ABCMeta
+
+    def __init__(self, my_id):
+        self.my_id = my_id
+
+    @abc.abstractproperty
+    def _widget_name(self):
+        pass
+
+    @abc.abstractproperty
+    def _widget_source(self):
+        pass
+
+    @abc.abstractmethod
+    def create_object_creator(cls, widgets, local_vars):
+        pass
+
+    @abc.abstractmethod
+    def do_action(self, parameters):
+        pass
+
+_image_panner_source = r"""
+<form name="test_form_%(my_id)s">
+<img src="" width=512 height=512 id="pan_image_%(my_id)s" style="float:left;">
+<br/>
+<input type=button onClick="panner_widget_action('%(my_id)s', 'L');" value="left" title="left">
+<input type=button onClick="panner_widget_action('%(my_id)s', 'R');" value="right" title="right">
+<input type=button onClick="panner_widget_action('%(my_id)s', 'U');" value="up" title="up">
+<input type=button onClick="panner_widget_action('%(my_id)s', 'D');" value="down" title="down">
+<br/>
+<input type=button onClick="panner_widget_action('%(my_id)s', 'Z2');" value="Z2" title="Z2">
+<input type=button onClick="panner_widget_action('%(my_id)s', 'Z10');" value="Z10" title="Z10">
+<input type=button onClick="panner_widget_action('%(my_id)s', 'ZO2');" value="ZO2" title="ZO2">
+<input type=button onClick="panner_widget_action('%(my_id)s', 'ZO10');" value="ZO10" title="ZO10">
+<br/>
+<input type=button onClick="panner_widget_action('%(my_id)s', 'REFRESH');" value="REFRESH" title="REFRESH">
+<br clear="all"/>
+</form>
+"""
+
+class PannerWidget(YTExtWebWidget):
+
+    _widget_name = "image_panner"
+    _widget_source = _image_panner_source
+    # Returns: image_data
+    def __init__(self, my_id, panner):
+        YTExtWebWidget.__init__(self, my_id)
+        self.panner = panner
+
+    def do_action(self, parameters):
+        action = parameters['widget_action']
+        if action == "L":
+            self.panner.pan_rel_x(+0.1)
+        elif action == "R":
+            self.panner.pan_rel_x(-0.1)
+        elif action == "D":
+            self.panner.pan_rel_y(+0.1)
+        elif action == "U":
+            self.panner.pan_rel_y(-0.1)
+        elif action == "Z2":
+            self.panner.zoom(2.0)
+        elif action == "ZO2":
+            self.panner.zoom(0.5)
+        elif action == "Z10":
+            self.panner.zoom(10.0)
+        elif action == "ZO10":
+            self.panner.zoom(0.1)
+        elif action == "REFRESH":
+            self.panner.zoom(1.0)
+        nb = self.scale_buffer(self.panner.buffer)
+        iv = base64.encodestring(nb)
+        return dict( image_data = iv )
+
+    def scale_buffer(self, buffer):
+        image = na.log10(buffer)
+        mi = na.nanmin(image[~na.isinf(image)])
+        ma = na.nanmax(image[~na.isinf(image)])
+        color_bounds = mi, ma
+        image = (image - color_bounds[0])/(color_bounds[1] - color_bounds[0])
+        to_plot = map_to_colors(image, "algae")
+        to_plot = na.clip(to_plot, 0, 255)
+        tf = tempfile.TemporaryFile()
+        write_png_to_file(to_plot, tf)
+        tf.seek(0)
+        s = tf.read()
+        tf.close()
+        return s
+
+    @classmethod
+    def create_object_creator(cls, widgets, local_vars):
+        def add_panner(panner):
+            unique_id = str(uuid.uuid1())
+            widget = cls(unique_id, panner)
+            widgets[unique_id] = widget
+            s = cls._widget_source % dict(my_id = unique_id)
+            local_vars['new_values'] = s
+            #print "Setting new values:\n\n" + s
+        return add_panner
+
+class TestingExtJS(YTExtWebWidget):
+    _widget_name = "tester"
+    _widget_source = _image_panner_source
+    # Returns: image_data
+    def __init__(self, my_id):
+        YTExtWebWidget.__init__(self, my_id)
+
+    def do_action(self, parameters):
+        pass
+
+    @classmethod
+    def create_object_creator(cls, widgets, local_vars):
+        def add_tester():
+            unique_id = str(uuid.uuid1())
+            widget = cls(unique_id)
+            widgets[unique_id] = widget
+            s = cls._widget_source % dict(my_id = unique_id)
+            local_vars['execute'] = "Ext.Msg.alert('Hey!', 'Hi there.');"
+            #print "Setting new values:\n\n" + s
+        return add_tester

bottle/ytrepl_extpanel.html

 <html>
 <head>
-  <title>Column Layout</title>
+  <title>yt</title>
 	<link rel="stylesheet" type="text/css" href="resources/ext-all.css" />
 
     <!-- GC -->
     </style>
 	<script type="text/javascript">
 
+    var handle_result = function(f, a) {
+        Ext.get("output").dom.innerHTML +=
+        '>>> ' + f.findField("line").getValue() + '<br/>' + a.result.text + '<br/>';
+        f.findField("line").setValue("");
+        eval(a.result.execute);
+    }
+
     var repl_input = new Ext.FormPanel({
         url: 'push',
         items: [{
             fieldLabel: '>>>',
             name: 'line',
             allowBlank: 'True',
+            bodyStyle: 'font-family: monospace;',
             listeners: {
                 specialkey: function(f, e){
                     if (e.getKey() == e.ENTER) {
                         repl_input.getForm().submit({
-                            success: function(f, a){
-                                Ext.get("output").dom.innerHTML +=
-                                '>>> ' + f.findField("line").getValue() + '<br/>'
-                              + a.result.text + '<br/>';
-                               },
+                            success: handle_result,
                             failure: function(f, a){
                                 Ext.get("output").dom.innerHTML +=
                                     '>>> FAILURE<br/>';
                 items:[{
                     columnWidth:1.0,
                     baseCls:'x-plain',
-                    bodyStyle:'padding:5px 0 5px 5px',
+                    bodyStyle:'padding:5px 0 5px 5px; font-family: monospace;',
                     items:[{
                        title: 'Output',
                        html: "",
                 },]
             }]
         });
+    Ext.get("output").dom.innerHTML += 'Welcome to the yt web interface.<br/>';
     }
     
-    
     );
 	</script>
 </head>

bottle/ytrepl_extpanel.py

 from bottle import request, response, route, run, server_names, debug
 
+import cgi
 import codeop
 import inspect
 import os
 def push():
     """Push 'line' and return exec results as a bare response."""
     line = request.POST['line']
-    result = repl.push(line)
+    result = cgi.escape(repl.push(line))
     new_values = repl.locals.pop("new_values", "")
+    execute = repl.locals.pop("execute", "")
     if result is None:
         # More input lines needed.
         response.status = 204
-    tr = dict(success = 'true', text = result, new_values = new_values)
+    tr = dict(success = 'true', text = result, new_values = new_values,
+              execute = execute)
     print tr
     return json.dumps(tr)