⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editobjectattributesdialog.py

📁 一个通用的隐性马尔可夫C代码库 开发环境:C语言 简要说明:这是一个通用的隐性马尔可夫C代码库
💻 PY
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/env python##################################################################################       This file is part of Gato (Graph Algorithm Toolbox) #       version _VERSION_ from _BUILDDATE_. You can find more information at #       http://www.zpr.uni-koeln.de/~gato##	file:   EditObjectAttributesDialog.py#	author: Alexander Schliep (schliep@zpr.uni-koeln.de)##       Copyright (C) 1998-2002, Alexander Schliep, Winfried Hochstaettler and #       ZAIK/ZPR, Universitaet zu Koeln#                                   #       Contact: schliep@zpr.uni-koeln.de, wh@zpr.uni-koeln.de             ##       Information: http://gato.sf.net##       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.1 $ #                       from $Date: 2003/12/23 18:17:15 $#             last change by $Author: aschoen $.#################################################################################from Tkinter import *from ScrolledText import *import tkSimpleDialog import tkMessageBoxfrom tkColorChooser import askcolorimport copyimport sysimport osimport typesdef typed_assign(var, val):    result = type(var)(val)    result.__dict__ = copy.copy(var.__dict__)    return result#-------------------------------------------------------------------------------class TkStringEntry:    """Tk entry field for editing strings"""    def __init__(self, master, width):        self.entryWidget = Entry(master, width=width, exportselection=FALSE)            def tkWidget(self):        return self.entryWidget    def get(self):        return self.entryWidget.get()        def set(self, value):        self.entryWidget.delete(0,END)        self.entryWidget.insert(0,"%s" % value)    def select(self):            self.entryWidget.selection_range(0,"end")        self.entryWidget.focus_set()        class TkIntEntry(TkStringEntry):    """Tk entry field for editing one integer"""    def get(self):        return int(self.entryWidget.get())    class TkFloatEntry(TkStringEntry):    """Tk entry field for editing one float"""    def get(self):        return float(self.entryWidget.get())    class TkDefaultMixin:    """Mixin for TkStringEntry, TkIntEntry, TkFloatEntry, ... to deal with       values which have an externally defined default value. Combination       of 'use default' checkbox and corresponding entry field """    def __init__(self, master, useDefault, defaultValue):        self.frame = Frame(master, relief=FLAT)        self.useDefault = IntVar()        self.useDefault.set(useDefault)        self.defaultValue = defaultValue        useDefaultButton = Checkbutton(self.frame, text="Use default",                                       variable=self.useDefault,                                       command=self.toggleDefault)        useDefaultButton.grid(row=0, column=0, padx=4, pady=3, sticky=W)    def finish(self):        self.entryWidget.grid(row=0, column=1, padx=4, pady=3, sticky=W)        self.switchDefault(self.useDefault.get())               def UseDefault(self):        return self.useDefault.get()    def switchDefault(self, value):        if value == 0:            self.entryWidget['state'] = NORMAL            self.entryWidget.delete(0,END)            self.set(self.defaultValue)        else:            self.entryWidget.delete(0,END)            self.entryWidget['state'] = DISABLED                def toggleDefault(self):        self.switchDefault(self.useDefault.get())            class TkDefaultStringEntry(TkStringEntry, TkDefaultMixin):    def __init__(self, master, width, useDefault, defaultValue):        TkDefaultMixin.__init__(self, master, useDefault, defaultValue)        TkStringEntry.__init__(self, self.frame, width)        self.finish()            def tkWidget(self): # To avoid ambiguity        return self.frameclass TkDefaultIntEntry(TkIntEntry, TkDefaultMixin):    def __init__(self, master, width, useDefault, defaultValue):        TkDefaultMixin.__init__(self, master, useDefault, defaultValue)        TkIntEntry.__init__(self, self.frame, width)        self.finish()            def tkWidget(self): # To avoid ambiguity        return self.frame    def get(self):        if self.UseDefault():            return self.defaultValue        else:            return TkIntEntry.get(self)class TkDefaultFloatEntry(TkFloatEntry, TkDefaultMixin):    def __init__(self, master, width, useDefault, defaultValue):        TkDefaultMixin.__init__(self, master, useDefault, defaultValue)        TkFloatEntry.__init__(self, self.frame, width)        self.finish()            def tkWidget(self): # To avoid ambiguity        return self.frame    def get(self):        if self.UseDefault():            return self.defaultValue        else:            return TkFloatEntry.get(self)class TkPopupSelector:    def __init__(self, master, value2pop, pop2value, width):        self.value2pop = value2pop        self.pop2value = pop2value        self.popupvalue = StringVar()        self.popupvalue.set(self.pop2value.keys()[0]) # XXX first value as default         # XXX Uuughhh        keys = self.value2pop.keys()        keys.sort()        pops = map(lambda x: value2pop[x], keys)        #log.debug("pops = %s" % pops)        args = (master, self.popupvalue) + tuple(pops)                    self.tkwidget = apply(OptionMenu, args)        self.tkwidget.config(height=1, width=width)    def tkWidget(self):        return self.tkwidget    def get(self):        return self.pop2value[self.popupvalue.get()]    def set(self, value):        try:            self.popupvalue.set(self.value2pop[value])        except:            self.popupvalue.set(self.pop2value.keys()[0]) # XXX first value as default           def select(self):            # Cant choose invalid value with popup        pass    class TkStringPopupSelector:    def __init__(self, master, strings):        self.strings = strings        self.popupvalue = StringVar()	if len(self.strings) > 0:            self.popupvalue.set(self.strings[0]) # XXX first value as default 	width = max(map(len, self.strings))        args = (master, self.popupvalue) + tuple(self.strings)        self.tkwidget = apply(OptionMenu, args)        self.tkwidget.config(height=1, width=width)    def tkWidget(self):        return self.tkwidget    def get(self):        return self.popupvalue.get()    def set(self, value):        try:            self.popupvalue.set(value)        except:            self.popupvalue.set(self.strings[0]) # XXX first value as default           def select(self):            # Cant choose invalid value with popup        pass    class TkColorSelector:    def __init__(self, master, color='black'):        #self.tkwidget = Button(master, width=8, command=self.editColor)        self.tkwidget = Frame(master, height=18, width=60, relief=RIDGE, borderwidth=1)        self.tkwidget.bind("<ButtonRelease-1>", self.editColor)	self.set(color)    def editColor(self, event):        color = askcolor(self.color)[1]	if color is not None:            self.set(color)	    def tkWidget(self):        return self.tkwidget    def get(self):        return self.color    def set(self, value):        self.color = value	self.tkwidget.config(bg=self.color)    def select(self):            # Cant choose invalid value with popup        passclass EditObjectAttributesDialog(tkSimpleDialog.Dialog):    """ Creates an editable (pseudo-)inspector for a selected set of        attributes of a given object         - master : tk master widget         - object : the object, whose attributes we want to edit         - attr_names : a list of attr_names        By making use of Python 2.2's capability of subclassing built-in

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -