forked from nilesh-patil/python-XTensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackPlotDialog.py
More file actions
155 lines (119 loc) · 6.87 KB
/
TrackPlotDialog.py
File metadata and controls
155 lines (119 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: utf-8 -*-
# Copyright (C) 2015, Egor Zindy <egor.zindy@manchester.ac.uk>
# vim: set ts=4 sts=4 sw=4 expandtab smartindent:
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import Tkinter as tk
import ttk
import tkMessageBox
from TkDialog import TkDialog
try:
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import matplotlib as mpl
mpl.use('TkAgg')
import numpy as np
hasMPL = True
except:
hasMPL = False
#It's convenient to make the combobox choices global lists.
list_plots = ["3D plot", "Projection"]
###########################################################################
## The dialog
###########################################################################
class TrackPlotDialog(TkDialog):
def __init__(self,is3D = False):
TkDialog.__init__(self)
#Here you can make things pretty
self.arraychannel = None
self.wm_geometry("700x800")
self.title("Tracks plotter - Copyright (c) 2015 Egor Zindy")
self.add_menu("File",["Update objects", "Open configuration", "Save configuration","|","Exit"])
self.add_menu("Help",["About"])
#widget = [ttk.Combobox(self.mainframe, textvariable=self.arrayvar("objects"), values=[], exportselection=0, state="readonly"),
# ttk.Combobox(self.mainframe, textvariable=self.arrayvar("cc_type"), values=list_colourcoding, exportselection=0, state="readonly")]
#self.add_control("Object and coding",widget, "ctrl_objects")
widget = ttk.Combobox(self.mainframe, textvariable=self.arrayvar("objects"), values=[], exportselection=0, state="readonly")
tick = self.arrayvar("check_selected", "off"), "Selected"
self.add_control("Spot object",widget, name="ctrl_objects", tick=tick)
if is3D:
widget = ttk.Combobox(self.mainframe, textvariable=self.arrayvar("plot_type"), values=list_plots, exportselection=0, state="readonly")
self.add_control("Plot type",widget, name="ctrl_plots", tick=tick)
self.ctrl_type = w1 = ttk.Combobox(self.mainframe, textvariable=self.arrayvar("cc_type"), values=[], exportselection=0, state="readonly")
self.ctrl_channel = w2 = ttk.Combobox(self.mainframe, textvariable=self.arrayvar("cc_channel"), values=[], exportselection=0, state="readonly")
widget = [w1, w2]
tick = self.arrayvar("check_cc", "off"), "Use"
self.add_control("Colour coding",widget, tick=tick)
widget = ttk.Entry(self.mainframe,textvariable=self.arrayvar("title"))
tick = self.arrayvar("check_title", "off"), "Display"
self.add_control("Title string",widget,tick=tick)
if is3D:
widget = [ttk.Entry(self.mainframe,textvariable=self.arrayvar("xsize")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("ysize")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("zsize"))]
tick = self.arrayvar("check_defaultsize", "on"), "Default"
self.add_control("Voxel um size X/Y/Z",widget,tick=tick)
else:
widget = [ttk.Entry(self.mainframe,textvariable=self.arrayvar("xsize")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("ysize"))]
tick = self.arrayvar("check_defaultsize", "on"), "Default"
self.add_control("Voxel um size X/Y",widget,tick=tick)
widget = [ttk.Entry(self.mainframe,textvariable=self.arrayvar("xmin")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("xmax"))]
tick = self.arrayvar("xauto", "on"), "Auto"
self.add_control("X range (min/max)",widget,tick=tick)
widget = [ttk.Entry(self.mainframe,textvariable=self.arrayvar("ymin")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("ymax"))]
tick = self.arrayvar("yauto", "on"), "Auto"
self.add_control("Y range (min/max)",widget,tick=tick)
if is3D:
widget = [ttk.Entry(self.mainframe,textvariable=self.arrayvar("zmin")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("zmax"))]
tick = self.arrayvar("zauto", "on"), "Auto"
self.add_control("Z range (min/max)",widget,tick=tick)
widget = [ttk.Entry(self.mainframe,textvariable=self.arrayvar("azimuth")),
ttk.Entry(self.mainframe,textvariable=self.arrayvar("elevation"))]
self.add_control("Azimuth / Elevation",widget) #,tick=tick)
self.figure = Figure(figsize=(10,10), dpi=100)
self.canvas = FigureCanvasTkAgg(self.figure,master=self.mainframe)
self.add_control("",self.canvas.get_tk_widget())
#self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.mainframe)
#self.add_control("",self.toolbar)
widget = ttk.Button(self.mainframe, text="Save high resolution figure", command=self.OnSaveFigure, name="btn3")
self.add_control("",widget)
#we have all the ingredients, now bake the dialog box!
self.bake(has_cancel=False) #, has_preview=True) #"Calculate")
def About(self):
'''About XTTrackPlot'''
tkMessageBox.showinfo("About XTTrackPlot", "Source code available from https://github.com/zindy/libatrous/\n\nAuthor: Egor Zindy <egor.zindy@manchester.ac.uk>\nWellcome Centre for Cell-Matrix Research\nUniversity of Manchester (UK)")
def SetDefaults(self):
#Here you set default values
self.arrayvar["plot_type"] = list_plots[0]
def SetObjects(self, object_list, selected=0):
self.SetDefaults()
n_objects = len(object_list)
self.ctrl_objects['values'] = object_list
self.ctrl_objects.current(selected)
def OnSaveFigure(self,*args):
self.SaveFigure()
def SaveFigure(self):
print "Saving the figure..."
if __name__ == "__main__":
app=TrackPlotDialog(is3D=True)
app.mainloop()