Commits

Matthew Turk committed c946d3b

Playing with scatter widgets

  • Participants

Comments (0)

Files changed (2)

File vr_widget.kv

+#:kivy 1.0
+#:import kivy kivy
+#:import win kivy.core.window
+
+<VolumeRendering>:
+    id: vr_widget
+    GridLayout:
+        size: 640, 640
+        size_hint: None, None
+        cols: 2
+        padding: 0
+        Slider:
+            id: 'width_slider'
+            orientation: 'vertical'
+            size: 128, 512
+            size_hint_x: None
+            size_hint_y: None
+            on_value: vr_widget.g_width = self.value_normalized
+        Image:
+            size: 512, 512
+            source: '/home/mturk/yt_vr_small.png'
+            size_hint_x: None
+            size_hint_y: None
+        Button:
+            size: 128, 128
+            size_hint_x: None
+            size_hint_y: None
+            label: 'Render'
+            on_release: vr_widget.render()
+        Slider:
+            id: 'val_slider'
+            orientation: 'horizontal'
+            size: 512, 128
+            size_hint_x: None
+            size_hint_y: None
+            on_value: vr_widget.g_center = self.value_normalized

File vr_widget.py

+from kivy.lang import Builder
+from kivy.uix.widget import Widget
+from kivy.uix.gridlayout import GridLayout
+from kivy.uix.button import Button
+from kivy.uix.slider import Slider
+from kivy.uix.image import Image
+from kivy.app import App
+from kivy.uix.scatter import Scatter
+from kivy.uix.floatlayout import FloatLayout
+
+Builder.load_file('vr_widget.kv')
+
+class VolumeRendering(Scatter):
+    g_width = None
+    g_center = None
+    def render(self, *args, **kwargs):
+        self.cam.tf = ColorTransferFunction((mi, ma))
+        v = (ma - mi) * self.g_center + mi
+        w = (ma - mi) * self.g_width
+        self.cam.tf.sample_colormap( v, w)
+        self.cam.snapshot("temp.png")
+        print self.children
+
+class MyApp(App):
+    def build(self):
+        parent = FloatLayout()
+        parent.add_widget(VolumeRendering())
+        add_new = Button(text='Add New', pos_hint={'x':0.0, 'y':0.0},
+                         width=96, height=96, size_hint=(None, None))
+        parent.add_widget(add_new)
+        def new_widget(obj):
+            parent.add_widget(VolumeRendering())
+        add_new.bind(on_release = new_widget)
+        return parent
+
+from yt.mods import *
+pf = load("/home/mturk/data/JHK-DD0030/galaxy0030")
+dd = pf.h.all_data()
+mi, ma = na.log10(dd.quantities["Extrema"]("Density"))
+
+if __name__ in ('__android__', '__main__'):
+    MyApp().run()