Commit [r4071] Maximize Restore History

volume API and panel improvements

- volume presets
- new commands: volume_color, volume_ramp_new
- improved volume panel/UI
- custom volume ramps/presets
- support for volumes from maps with transformation matrix (matrix_copy on map)

speleo3 2014-03-12

1 2 > >> (Page 1 of 2)
removed /trunk/pymol/modules/pmg_tk/skins/normal/volume.py
removed /trunk/pymol/modules/pmg_tk/skins/normal/ColorRampModel.py
removed /trunk/pymol/modules/pmg_tk/skins/normal/hist.py
removed /trunk/pymol/modules/pmg_tk/skins/normal/SimpleColorChooser.py
changed /trunk/pymol/modules/pmg_tk/skins/normal/__init__.py
changed /trunk/pymol/modules/pymol/completing.py
changed /trunk/pymol/modules/pymol/menu.py
changed /trunk/pymol/modules/pmg_tk/PMGApp.py
changed /trunk/pymol/layer0/Isosurf.c
changed /trunk/pymol/modules/pymol/api.py
changed /trunk/pymol/layer0/Isosurf.h
changed /trunk/pymol/layer2/ObjectVolume.c
changed /trunk/pymol/modules/pmg_tk/PyMOLMapLoad.py
changed /trunk/pymol/layer2/ObjectVolume.h
changed /trunk/pymol/modules/pymol/gui.py
changed /trunk/pymol/layer2/ObjectMap.c
changed /trunk/pymol/layer4/Cmd.c
changed /trunk/pymol/layer2/ObjectMap.h
changed /trunk/pymol/layer1/Setting.c
changed /trunk/pymol/modules/pymol/querying.py
changed /trunk/pymol/modules/pymol/keywords.py
changed /trunk/pymol/modules/pymol/invocation.py
changed /trunk/pymol/modules/pymol/setting.py
copied /trunk/pymol/modules/pmg_tk/skins/normal/ColorMap.py -> /trunk/pymol/modules/pmg_tk/TextEditor.py
/trunk/pymol/modules/pmg_tk/skins/normal/__init__.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/completing.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/menu.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pmg_tk/PMGApp.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer0/Isosurf.c Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/api.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer0/Isosurf.h Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer2/ObjectVolume.c Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pmg_tk/PyMOLMapLoad.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer2/ObjectVolume.h Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/gui.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer2/ObjectMap.c Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer4/Cmd.c Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer2/ObjectMap.h Diff Switch to side-by-side view
Loading...
/trunk/pymol/layer1/Setting.c Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/querying.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/keywords.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/invocation.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pymol/setting.py Diff Switch to side-by-side view
Loading...
/trunk/pymol/modules/pmg_tk/skins/normal/ColorMap.py to /trunk/pymol/modules/pmg_tk/TextEditor.py
--- a/trunk/pymol/modules/pmg_tk/skins/normal/ColorMap.py
+++ b/trunk/pymol/modules/pmg_tk/TextEditor.py
@@ -1,96 +1,95 @@
+'''
+Simple Text Editor
+'''
 
-from Tkinter import *
+import os
+import sys
+import Tkinter
+import tkFileDialog
+import tkMessageBox
 
-class ColorMap:
-    """
-    A simple converter from a ColorRamp (a gradient of nColors) to
-    a ColorMap (a graph of data + visual way pts)
-    """
-    def __init__(self,parent,ramp,width=None,height=None,data=None):
-        """
-        just produces the canvas/image for
-        the ColorRamp
-        """
-        self.parent = parent
-        self.ramp = ramp
-        self.width = width
-        self.height = height
-        self.data = data
-        # constants
-        self.CIRCLE_RADIUS=3
-        # container
-        self.canvas = None
-        self.canvas_ids = []
+class TextEditor:
 
-    def toCanvas(self,parent=None,canvas=None,ramp=None,width=None,height=None):
-        """
-        get a correct canvas for this color ramp
-        """
-        print " +ColorMap::toCanvas"
-        if None==parent:
-            parent=self.parent
-        if None==width:
-            width=self.width
-        if None==height:
-            height=self.height
-        if None==ramp:
-            ramp = self.ramp
-        if None==canvas:
-            canvas = self.canvas
+    def _write(self, handle):
+        content = self._get()
+        handle.write(content)
+        self._savedcontent = content
 
-        r = self.CIRCLE_RADIUS
+    def _open(self, filename):
+        self.filename = filename or ''
+        if filename and os.path.exists(filename):
+            with open(filename, 'rU') as handle:
+                content = handle.read()
+        else:
+            content = ''
+        self._set(content)
 
-        ## if self.canvas!=None:
-        ##     # empty the canvas
-        ##     for x in self.canvas_ids:
-        ##         self.canvas.delete(x)
-        ##     self.canvas_ids = []
-        ## else:
-        ##     # create empty canvas
-        ##     self.canvas = Canvas(parent,width=width,height=height,bg="white")
-        
-        # draw colored circles where the users clicked
-        for key in ramp.keys.keys():
-            curColorPt = ramp.keys[key]
+    def _get(self):
+        return self.text.get(0.0, Tkinter.END)
 
-            # get original values
-            origX, origY, origColor = curColorPt.idx, curColorPt.color[3], curColorPt.color
-        
-            # convert to scaled and Tkinter-friendly formats
-            # scale X
-            x = int(float(origX)/float(ramp.nColors) * width)
-            # scale Y
-            y = int(height * (1.0-float(origY)))
-            # convert the color from RGBA --> HEX6
-            colHEX6 = "#%02x%02x%02x" % (origColor[0]*255., origColor[1]*255., origColor[2]*255.)
-            # plot the pt
-            unique_id = canvas.create_oval((x-r,y-r,x+r,y+r),fill=colHEX6,tags="colorPt")
-            self.canvas_ids.append(unique_id)
-        print " -ColorMap::toCanvas"            
-        return canvas
+    def _set(self, content):
+        self.text.delete(0.0, Tkinter.END)
+        self.text.insert(0.0, content)
+        self._savedcontent = self._get()
 
-    def clearCanvas(self):
-        for x in self.canvas_ids:
-            self.canvas.delete(x)
+    def doSaveAs(self, *args):
+        handle = tkFileDialog.asksaveasfile(mode='w',
+                initialfile=os.path.basename(self.filename),
+                initialdir=os.path.dirname(self.filename),
+                parent=self.root)
+        if handle:
+            with handle:
+                self._write(handle)
+                self.filename = handle.name
 
+    def doSave(self, *args):
+        if not self.filename:
+            return self.doSaveAs()
+        with open(self.filename, 'w') as handle:
+            self._write(handle)
 
-if __name__=="__main__":
+    def doOpen(self, *args):
+        filename = tkFileDialog.askopenfilename(parent=self.root)
+        if filename:
+            self._open(filename)
 
-    # test with a ColorRamp
+    def onClose(self):
+        if self._get() != self._savedcontent:
+            ok = tkMessageBox.askyesnocancel("Save?", "Save before quit?",
+                    parent=self.root)
+            if ok:
+                self.doSave()
+            elif ok is None:
+                return
+        self.root.destroy()
+
+    def __init__(self, parent=None, filename='', title='Text Editor'):
+        self.root = Tkinter.Toplevel(parent) if parent else Tkinter.Tk()
+        self.root.title(title)
+        self.root.minsize(width=500, height=400)
+        self.root.protocol("WM_DELETE_WINDOW", self.onClose)
+
+        menubar = Tkinter.Menu(self.root)
+        filemenu = Tkinter.Menu(menubar)
+        filemenu.add_command(label="Open", command=self.doOpen, accelerator="Ctrl+O")
+        filemenu.add_command(label="Save", command=self.doSave, accelerator="Ctrl+S")
+        filemenu.add_command(label="Save as ...", command=self.doSaveAs, accelerator="Ctrl+Shift+S")
+        menubar.add_cascade(label="File", menu=filemenu)
+        self.root.config(menu=menubar)
+
+        self.text = Tkinter.Text(self.root, background='white', foreground='black')
+        self.text.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
+
+        self._open(filename)
+
+        self.text.bind("<Control-o>", self.doOpen)
+        self.text.bind("<Control-s>", self.doSave)
+        self.text.bind("<Control-S>", self.doSaveAs)
+
+if __name__ == '__main__':
     try:
-        root = Tk()
-        from ColorRamp import ColorRamp
-        c = ColorRamp(256)
-        c.addColor(0, (0,0,0,0.7))
-        c.addColor(128, (1,0,0,0.5))
-        c.addColor(255, (1,1,1,0.2))
-        
-        m = ColorMap(root, ramp=c, width=256, height=100)
-        
-        can = m.toCanvas(root)
-        can.pack()
-        root.mainloop()
-    except ImportError:
-        print "Warning: Cannot test with a color ramp"
-
-        
+        filename = sys.argv[1]
+    except:
+        filename = ''
+    app = TextEditor(None, filename)
+    app.root.mainloop()
1 2 > >> (Page 1 of 2)