Commit b08ec43b authored by Matheus Müller's avatar Matheus Müller

Melhorias na janela de elementos, programa que retorna lista de pares ordenados.

parent 2d73c305
# -*- coding: iso-8859-15 -*-
import Tkinter as tk
from PTE import *
from numpy import ones
......@@ -19,30 +21,67 @@ Econtrol = 0
##############################################################################
# Element callback
def elem_callback(edict , ebutton, canvas, i, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS):
global Econtrol
def elem_callback(x, edict , ebutton, Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol):
PTable(edict[x] , ebutton[x], Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol)
##############################################################################
# Element selection
def elem_select(i, button, Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol):
global Econtrol, Edict
button[Econtrol]['relief']='raised'
Econtrol = i
PTable(edict , ebutton, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS)
button[i]['relief']='sunken'
Labelmass.configure(text = 'Mass - %f' %Edict[i]['mass'])
LabelZ.configure(text = 'Z - %f' %Edict[i]['Z'])
Labelname.configure(text = '%s' %Edict[i]['name'])
Labelsymbol.configure(text = 'Symbol - %s' %Edict[i]['symbol'])
Entrymass.delete (0, len(Entrymass.get()))
Entryname.delete (0, len(Entryname.get()))
EntryZ.delete (0, len(EntryZ.get()))
Entrysymbol.delete (0, len(Entrysymbol.get()))
Entrymass.insert(0, Edict[int(Econtrol)]['mass'])
Entryname.insert(0, Edict[int(Econtrol)]['name'])
EntryZ.insert(0, Edict[int(Econtrol)]['Z'])
Entrysymbol.insert(0, Edict[int(Econtrol)]['symbol'])
#if Edict[i]['name'] == 'New':
# butPTE.invoke()
##############################################################################
# Element addition
# Init
def ewin_build(window, xmax, xstep):
##############################################################################
# Element addition
def create():
global i, Edict, Ebuttons
Edict[i] = dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = ones(int(xmax/xstep)), control = 0, LineShape = 200.)
Ebuttons.insert(i, tk.Button(Eframe,text=i,width=1,height=1, command=lambda i=i : elem_callback(Edict[i] , Ebuttons[i], Distcanvas, i, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS )))
Ebuttons.insert(i, tk.Button(Eframe, text=i, width=1, height=1, command = lambda i=i : elem_select(i,Ebuttons,Labelmass,LabelZ,Labelname,Labelsymbol,Entrymass,EntryZ,Entryname,Entrysymbol)))
Ebuttons[i].pack(side='left')
i=i+1
##############################################################################
# Element deletion
def remove():
global i, Edict, Ebuttons
global i, Edict, Ebuttons, Econtrol
if i > 1:
i=i-1
del Edict[i]
Ebuttons[i].destroy()
del Ebuttons[i]
if Econtrol == i:
Econtrol = Econtrol -1
Ebuttons[Econtrol]['relief']='sunken'
##############################################################################
# Element Frames
......@@ -70,49 +109,66 @@ def ewin_build(window, xmax, xstep):
Labelname.configure(text = '%s' %Edict[i]['name'])
Edict[i]['symbol'] = str(Entrysymbol.get())
Labelsymbol.configure(text = 'Symbol - %s' %Edict[i]['symbol'])
Edict[i]['LineShape'] = float(EntryLS.get())
LabelLS.configure(text = 'Line Shape - %f' %Edict[i]['LineShape'])
#Edict[i]['LineShape'] = float(EntryLS.get())
#LabelLS.configure(text = 'Line Shape α - %f' %Edict[i]['LineShape'])
print Edict[i]
Labelprop = tk.LabelFrame(window, text = 'Properties', relief='raised', bd=2)
#Labelprop.pack()
Labelprop.place(anchor='w', y=125, x=5)
Labelprop.place(anchor='w', y=100, x=5)
EPframel = tk.Frame(Labelprop)
LpFrame1 = tk.Frame(Labelprop)
LpFrame1.pack(side='left')
LpFrame2 = tk.Frame(Labelprop)
LpFrame2.pack(side='top')
LpFrame3 = tk.Frame(Labelprop)
LpFrame3.pack(side='right')
EPframel = tk.Frame(LpFrame1)
EPframel.pack(side='left')
EPframee = tk.Frame(Labelprop)
EPframee = tk.Frame(LpFrame1)
EPframee.pack(side='right')
Labelname = tk.Label(EPframel, width=30, pady=2, text='%s' %Edict[int(Econtrol)]['name'])
Labelmass = tk.Label(EPframel, width=30, pady=2, text='Mass - %f' %Edict[int(Econtrol)]['mass'])
LabelZ = tk.Label(EPframel, width=30, pady=2, text='Z - %f' %Edict[int(Econtrol)]['Z'])
Labelsymbol = tk.Label(EPframel, width=30, pady=2, text= 'Symbol - %s' %Edict[int(Econtrol)]['symbol'])
LabelLS = tk.Label(EPframel, width=30, pady=2, text='Line Shape - %f' %Edict[int(Econtrol)]['LineShape'])
EPframel2 = tk.Frame(LpFrame2)
EPframel2.pack(side='left')
EPframee2 = tk.Frame(LpFrame2)
EPframee2.pack(side='right')
Labelname = tk.Label(EPframel, width=20, pady=2, text='%s' %Edict[int(Econtrol)]['name'])
Labelmass = tk.Label(EPframel, width=20, pady=2, text='Mass - %f' %Edict[int(Econtrol)]['mass'])
LabelZ = tk.Label(EPframel, width=20, pady=2, text='Z - %f' %Edict[int(Econtrol)]['Z'])
Labelsymbol = tk.Label(EPframel, width=20, pady=2, text= 'Symbol - %s' %Edict[int(Econtrol)]['symbol'])
#LabelLS = tk.Label(EPframel, width=30, pady=2, text='Line Shape α - %f' %Edict[int(Econtrol)]['LineShape'])
Labelname.pack()
Labelmass.pack()
LabelZ.pack()
Labelsymbol.pack()
LabelLS.pack()
#LabelLS.pack()
Entryname = tk.Entry(EPframee, width=22)
Entrymass = tk.Entry(EPframee, width=22)
EntryZ = tk.Entry(EPframee, width=22)
Entrysymbol = tk.Entry(EPframee, width=22)
EntryLS = tk.Entry(EPframee, width=22)
Entryname = tk.Entry(EPframee, width=15)
Entrymass = tk.Entry(EPframee, width=15)
EntryZ = tk.Entry(EPframee, width=15)
Entrysymbol = tk.Entry(EPframee, width=15)
#EntryLS = tk.Entry(EPframee, width=22)
Entryname.pack()
Entrymass.pack()
EntryZ.pack()
Entrysymbol.pack()
EntryLS.pack()
#EntryLS.pack()
BUpdate = tk.Button(EPframee2, text ='Update properties', command=lambda i=int(Econtrol) :update(i), width=15)
BUpdate.pack()#side='right')
BUpdateD = tk.Button(EPframee2, text ='Update Distribution', command=lambda i=int(Econtrol) :update(i), width=15)
BUpdateD.pack()#side='left')
BUpdate = tk.Button(EPframee, text ='Update', command=lambda i=int(Econtrol) :update(i), width=20)
BUpdate.pack(side='bottom')
but = tk.Button(EPframel2, command=create, text='Add element', bd=1, height=1,width=15)
but.pack()#side='left')
but = tk.Button(EPframel, command=create, text='Add element', bd=1, height=1,width=15)
but.pack(side='left')
butrmv = tk.Button(EPframel2, command=remove, text='Remove element', bd=1, height=1,width=15)
butrmv.pack()#side='right')
butrmv = tk.Button(EPframel, command=remove, text='Remove element', bd=1, height=1,width=15)
butrmv.pack(side='right')
butPTE = tk.Button(EPframel2, text='Show PTE', bd=1, width=15, command=lambda i=i :elem_callback(Econtrol,Edict,Ebuttons,Labelmass,LabelZ,Labelname,Labelsymbol,Entrymass,EntryZ,Entryname,Entrysymbol))
butPTE.pack()#side='left')
##############################################################################
# Init
......@@ -120,7 +176,7 @@ def ewin_build(window, xmax, xstep):
Entryname.insert(0, Edict[int(Econtrol)]['name'])
EntryZ.insert(0, Edict[int(Econtrol)]['Z'])
Entrysymbol.insert(0, Edict[int(Econtrol)]['symbol'])
EntryLS.insert(0, Edict[int(Econtrol)]['LineShape'])
#EntryLS.insert(0, Edict[int(Econtrol)]['LineShape'])
##############################################################################
# Canvas callback
......@@ -153,7 +209,7 @@ def ewin_build(window, xmax, xstep):
Label2 = tk.LabelFrame(window, text = 'Distribution', bd=1)
#Label2.pack()
Label2.place(anchor='w', y=375, x=5)
Label2.place(anchor='w', y=320, x=5)
Distcanvas = tk.Canvas(Label2, bg="white", width=800, height= 300)
#Distcanvas.configure(cursor="crosshair")
......
......@@ -31,9 +31,9 @@ def init_calc():
# Main window
root = tk.Tk()
root.minsize(400,290)
root.minsize(375,270)
root.title('Open Flatus')
root.geometry('400x290+200+400')
root.geometry('375x270+200+400')
##############################################################################
# Elements window
......@@ -76,7 +76,7 @@ LabelT_in = tk.Label(Pframel, width=9, text='θ in', pady=2)
LabelEmin = tk.Label(Pframel, width=9, text='Emin', pady=2)
LabelEmax = tk.Label(Pframel, width=9, text='Emax', pady=2)
LabelEstep = tk.Label(Pframel, width=9, text='Estep', pady=2)
LabelDstep = tk.Label(Pframel, width=9, text='Depht step', pady=2)
LabelDstep = tk.Label(Pframel, width=9, text='Depth step', pady=2)
Labeldedx.pack()
LabeldW2dx.pack()
LabelT_out.pack()
......@@ -143,6 +143,7 @@ R1 = tk.Radiobutton(Label4, text="Gaussian", variable=modelvar, value='gaussiana
R1.pack()
R2 = tk.Radiobutton(Label4, text="Bessel", variable=modelvar, value='bessel')
R2.pack()
R2.select()
##############################################################################
# Line shape checkbox
......@@ -150,6 +151,7 @@ R2.pack()
LSvar = tk.IntVar()
C1 = tk.Checkbutton(Label4, text="Use Line Shape", variable=LSvar)
C1.pack()
C1.select()
##############################################################################
......
import Tkinter as tk
from PTEdict import *
from Eprop import atomsubmenu
##from Ewindow import Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol
####################################################
# PTE building
def PTable(Elem , Elembut, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS):
def PTable(Elem , Elembut, Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol):
####################################################
# Returns element parameters on click
......
# draggable rectangle with the animation blit techniques; see
# http://www.scipy.org/Cookbook/Matplotlib/Animations
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
lista = list()
class DraggableRectangle:
lock = None # only one can be animated at a time
def __init__(self, rect):
self.rect = rect
self.press = None
self.background = None
def connect(self):
'connect to all the events we need'
self.cidpress = self.rect.figure.canvas.mpl_connect(
'button_press_event', self.on_press)
self.cidrelease = self.rect.figure.canvas.mpl_connect(
'button_release_event', self.on_release)
self.cidmotion = self.rect.figure.canvas.mpl_connect(
'motion_notify_event', self.on_motion)
def on_press(self, event):
'on button press we will see if the mouse is over us and store some data'
if event.inaxes != self.rect.axes: return
if DraggableRectangle.lock is not None: return
contains, attrd = self.rect.contains(event)
if not contains: return
#print 'event contains', self.rect.xy
x0, y0 = self.rect.xy
self.press = x0, y0, event.xdata, event.ydata
DraggableRectangle.lock = self
# draw everything but the selected rectangle and store the pixel buffer
canvas = self.rect.figure.canvas
axes = self.rect.axes
self.rect.set_animated(True)
canvas.draw()
self.background = canvas.copy_from_bbox(self.rect.axes.bbox)
# now redraw just the rectangle
axes.draw_artist(self.rect)
# and blit just the redrawn area
canvas.blit(axes.bbox)
def on_motion(self, event):
'on motion we will move the rect if the mouse is over us'
if DraggableRectangle.lock is not self:
return
if event.inaxes != self.rect.axes: return
x0, y0, xpress, ypress = self.press
dx = event.xdata - xpress
dy = event.ydata - ypress
self.rect.set_x(x0+dx)
self.rect.set_y(y0+dy)
canvas = self.rect.figure.canvas
axes = self.rect.axes
# restore the background region
canvas.restore_region(self.background)
# redraw just the current rectangle
axes.draw_artist(self.rect)
# blit just the redrawn area
canvas.blit(axes.bbox)
def on_release(self, event):
'on release we reset the press data'
if DraggableRectangle.lock is not self:
return
self.press = None
DraggableRectangle.lock = None
# turn off the rect animation property and reset the background
self.rect.set_animated(False)
self.background = None
# redraw the full figure
self.rect.figure.canvas.draw()
for i in range(10):
lista[i] = drs[i].rect.xy
print lista
def disconnect(self):
'disconnect all the stored connection ids'
self.rect.figure.canvas.mpl_disconnect(self.cidpress)
self.rect.figure.canvas.mpl_disconnect(self.cidrelease)
self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
fig = plt.figure()
ax = fig.add_subplot(111)
rects = ax.bar(range(10), (1 + 0.01*np.random.rand(10)))
drs = []
for rect in rects:
dr = DraggableRectangle(rect)
dr.connect()
drs.append(dr)
lista.append(dr.rect.xy)
ylim([0,50])
xlim([0,50])
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment