📄 hmmeditor.py
字号:
#!/usr/bin/env python################################################################################## This file is part of ghmm## file: HMMEd.py# author: Janne Grunau## Copyright (C) 1998-2002, Alexander Schliep# # Contact: schliep@molgen.mpg.de## Information: http://ghmm.org## This library is free software; you can redistribute it and/or# modify it under the terms of the GNU Library General Public# License as published by the Free Software Foundation; either# version 2 of the License, or (at your option) any later version.## This library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Library General Public License for more details.## You should have received a copy of the GNU Library General Public# License along with this library; if not, write to the Free# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#### This file is version $Revision: 1.29 $ # from $Date: 2005/02/22 11:12:56 $# last change by $Author: schliep $.#################################################################################import Tkinterimport mathfrom Gato import GatoGlobals, ProbEditorBasics, ProbEditorDialogs, ProbEditorWidgets, ProbEditorContinuousfrom Gato.ObjectGred import *import ObjectHMMimport ghmmwrapperclass ContinuousEmissionEditor(ProbEditorContinuous.gauss_editor): def __init__(self, master, plotList): """ the entire dialog """ ProbEditorContinuous.gauss_editor.__init__(self, master, plotList, width=300, height=300) self.normalize = Tkinter.IntVar() self.normalize.set(1) def buildMenu(self): #Menuleiste bar=Tkinter.Menu(self.root) filem=Tkinter.Menu(bar) editm=Tkinter.Menu(bar) zoomm=Tkinter.Menu(bar) addMenu=Tkinter.Menu(editm) delMenu=Tkinter.Menu(editm) if self.sumindi==0: addMenu.add_radiobutton(label="Sum-Fkt", command=self.add_sum) addMenu.add_radiobutton(label="Box-Fkt", command=self.boxadd) #addMenu.add_radiobutton(label="Exp-Fkt", command=self.expadd) #addMenu.add_radiobutton(label="NegExp-Fkt", command=self.oexpadd) addMenu.add_radiobutton(label="Gaussian", command=self.gaussadd) addMenu.add_radiobutton(label="GaussianL", command=self.gaussladd) addMenu.add_radiobutton(label="GaussianR", command=self.gaussradd) for i in xrange(len(self.plot_list)): delMenu.add_radiobutton(label=str(i+1), background = self.plot_list[i].color, command = self.make_del_function(i)) if self.sumindi==1: delMenu.add_radiobutton(label="sum", background='red', command=self.del_sum) filem.add_command(label="Save", command=self.save) filem.add_command(label="Cancel", command=self.cancel) editm.add_cascade(label="Add", menu=addMenu) editm.add_cascade(label="Del", menu=delMenu) zoomm.add_command(label="Zoom-in", command=self.zoom_in) zoomm.add_command(label="Zoom-out", command=self.zoom_out) zoomm.add_command(label="Normalise", command=self.norm) bar.add_cascade(label="File", menu=filem) bar.add_cascade(label="Edit", menu=editm) bar.add_cascade(label="Zoom", menu=zoomm) self.root.config(menu=bar) def boxadd(self): self.top=Tkinter.Toplevel(self.root) label=Tkinter.Frame(self.top) Tkinter.Label(label, justify=CENTER, text="Uniform density:\nf(x)=1/|start-end| for start<x<end\nelse f(x)=0").grid(row=0) Tkinter.Label(label, text="start=").grid(row=1, sticky=E) Tkinter.Label(label, text="end=").grid(row=2, sticky=E) self.e1=Tkinter.Entry(label) self.e2=Tkinter.Entry(label) self.e1.insert(0, -0.5) self.e2.insert(0, 0.5) self.e1.grid(row=1, column=1) self.e2.grid(row=2, column=1) button1=Tkinter.Button(label, text="OK", command=self.box).grid(row=3) button2=Tkinter.Button(label,text="cancel",command=self.top.destroy).grid(row=3, column=1) label.pack() def box(self): s1=string.atof(self.e1.get()) s2=string.atof(self.e2.get()) self.create_new_fkt(ObjectHMM.UniformDensity(start=s1,stop=s2,a=1/math.fabs(s2-s1),color=self.nextColor())) self.top.destroy() def gaussadd(self): self.top=Tkinter.Toplevel(self.root) label=Tkinter.Frame(self.top) Tkinter.Label(label, justify=CENTER, text="Normal density:\n f(x)=\n 1/(sigma*sqrt(2*pi))*exp(-(x-mu)**2/2*(sigma)**2)").grid(row=0) Tkinter.Label(label, text="mu=").grid(row=1, sticky=E) Tkinter.Label(label, text="sigma=").grid(row=2, sticky=E) self.e1=Tkinter.Entry(label) self.e2=Tkinter.Entry(label) self.e1.insert(0, 0.0) self.e2.insert(0, 2.0) self.e1.grid(row=1, column=1) self.e2.grid(row=2, column=1) button1=Tkinter.Button(label, text="OK", command=self.gauss).grid(row=3) button2=Tkinter.Button(label,text="cancel",command=self.top.destroy).grid(row=3, column=1) label.pack() def gauss(self): l=len(self.plot_list) s1=string.atof(self.e1.get()) s2=string.atof(self.e2.get()) self.create_new_fkt(ObjectHMM.NormalDensity(mu=s1,sigma=s2,a=1.0,color=self.nextColor())) self.top.destroy() def gaussladd(self): self.top=Tkinter.Toplevel(self.root) label=Tkinter.Frame(self.top) Tkinter.Label(label, justify=CENTER, text="Normal density (truncated left):\n f(x)=\n 1/(sigma*sqrt(2*pi))*exp(-(x-mu)**2/2*(sigma)**2) for x<=tail\n else f(x)=0").grid(row=0, sticky=E) Tkinter.Label(label, text="mu=").grid(row=1, sticky=E) Tkinter.Label(label, text="sigma=").grid(row=2, sticky=E) Tkinter.Label(label, text="tail=").grid(row=3, sticky=E) self.e1=Tkinter.Entry(label) self.e2=Tkinter.Entry(label) self.e3=Tkinter.Entry(label) self.e1.insert(0, -1.0) self.e2.insert(0, 1.0) self.e3.insert(0, 0.5) self.e1.grid(row=1, column=1) self.e2.grid(row=2, column=1) self.e3.grid(row=3, column=1) button1=Tkinter.Button(label, text="OK", command=self.gaussl).grid(row=4) button2=Tkinter.Button(label,text="cancel",command=self.top.destroy).grid(row=4, column=1) label.pack() def gaussl(self): l=len(self.plot_list) s1=string.atof(self.e1.get()) s2=string.atof(self.e2.get()) s3=string.atof(self.e3.get()) self.create_new_fkt(ObjectHMM.NormalDensityTruncLeft(mu=s1,sigma=s2,tail=s3,a=1.0,color=self.nextColor())) self.top.destroy() def gaussradd(self): self.top=Tkinter.Toplevel(self.root) label=Tkinter.Frame(self.top) Tkinter.Label(label, justify=CENTER, text="Normal density (truncated right):\n f(x)=\n 1/(sigma*sqrt(2*pi))*exp(-(x-mu)**2/2*(sigma)**2) for x>=tail\n else f(x)=0").grid(row=0, sticky=E) Tkinter.Label(label, text="mu=").grid(row=1, sticky=E) Tkinter.Label(label, text="sigma=").grid(row=2, sticky=E) Tkinter.Label(label, text="tail=").grid(row=3, sticky=E) self.e1=Tkinter.Entry(label) self.e2=Tkinter.Entry(label) self.e3=Tkinter.Entry(label) self.e1.insert(0, 1.0) self.e2.insert(0, 1.0) self.e3.insert(0, -0.5) self.e1.grid(row=1, column=1) self.e2.grid(row=2, column=1) self.e3.grid(row=3, column=1) button1=Tkinter.Button(label, text="OK", command=self.gaussr).grid(row=4) button2=Tkinter.Button(label,text="cancel",command=self.top.destroy).grid(row=4, column=1) label.pack() def gaussr(self): l=len(self.plot_list) s1=string.atof(self.e1.get()) s2=string.atof(self.e2.get()) s3=string.atof(self.e3.get()) self.create_new_fkt(ObjectHMM.NormalDensityTruncRight(mu=s1,sigma=s2,tail=s3,a=1.0,color=self.nextColor())) self.top.destroy() def success(self): return self.status class HMMTypeChooser(tkSimpleDialog.Dialog): def buttonbox(self): # Stolen from tkSimpleDialog.py # add standard button box. override if you don't want the # standard buttons box = Frame(self) b_open = Button(box, text="Open existing HMM", width=30, command=self.open, default=ACTIVE) b_open.pack(side=TOP, padx=5, pady=5) b_discrete = Button(box, text="New HMM with discrete emissions", width=30, command=self.discrete) b_discrete.pack(side=TOP, padx=5, pady=5) b_continuous = Button(box, text="New HMM with continuous emissions", width=30, command=self.continuous) b_continuous.pack(side=BOTTOM, padx=5, pady=5) box.pack(side=BOTTOM,fill=X) def open(self): self.etype = 'open' self.ok() def discrete(self): self.etype = 0 self.ok() def continuous(self): self.etype = 1 self.ok() def body(self, master): self.title("New HMM")class HMMGraphEditor(SAGraphEditor): def __init__(self, master=None): self.modeltype = 0; SAGraphEditor.__init__(self, master) self.cEdgeDefault = '#888888' self.cLabelDefault = 'black' #'#FF8000' # 230 215 0 self.cVertexDefault = 'red' #'#007EE0' # 0 125 230 self.SetTitle("HMMEd 0.8_beta1") self.G = ObjectHMM.ObjectHMM(ObjectHMM.State, ObjectHMM.Transition) def makeMenuBar(self): self.menubar = Menu(self,tearoff=0) # Add file menu self.fileMenu = Menu(self.menubar, tearoff=0) self.fileMenu.add_command(label='New', command=self.NewGraph) self.fileMenu.add_command(label='Open ...', command=self.OpenGraph) self.fileMenu.add_command(label='Save', command=self.SaveGraph) self.fileMenu.add_command(label='Save as ...', command=self.SaveAsGraph) self.fileMenu.add_separator() self.fileMenu.add_command(label='Export EPSF...', command=self.ExportEPSF) self.fileMenu.add_separator() self.fileMenu.add_command(label='Quit', command=self.Quit) self.menubar.add_cascade(label="File", menu=self.fileMenu, underline=0) # Add graph menu self.graphMenu = Menu(self.menubar, tearoff=0) self.graphMenu.add_command(label='Edit Prior', command=self.EditPrior) if self.modeltype & ghmmwrapper.kDiscreteHMM: self.graphMenu.add_command(label='Edit Alphabet', command=self.EditAlphabet)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -