1

我有一个简单的程序,它从用户那里获取文本输入,并将其显示在仪器(Keithley)上。但是,属性似乎没有改变。也就是说,当我运行 Start 方法时,输出是“Wowee”,即使我在弹出窗口中更改了显示。我必须让它可编辑吗?我不这么认为。我基本上遵循Gael Varoquaux对特质的介绍。

控制面板.py:

from traits.api import *
from traitsui.api import *

import Keithley3706A_module



class ControlPanel(HasTraits):
    keithley2430settings = Instance(Keithley2430.Keithley2430Settings, ())
    keithley3706Asettings = Instance(Keithley3706A_module.Keithley3706ASettings, ())
    start = Button("Start Measurements")
    clear_3706A_display = Button("Clear K3706A Display")

    k3706A_settings = Keithley3706A_module.Keithley3706ASettings()
    k3706A = Keithley3706A_module.Keithley3706A()
    view = View(Item('start', show_label=False,style='custom' ),
        Item('clear_3706A_display', show_label=False,style='custom' ),
        Item('keithley2430settings',style='custom'),
        Item('keithley3706Asettings',style='simple'))


    def _start_fired(self):
        print "hello %s" % self.k3706A_settings.display
        self.k3706A.message(self.k3706A_settings.display)

    def _clear_3706A_display_fired(self):
        self.k3706A.clear()

if __name__ == '__main__':
    ControlPanel().configure_traits()

Keithley3706A.py:

from traits.api import *
from traitsui.api import *

import visa
import time

class Keithley3706ASettings(HasTraits):
    display = String("Wowee")

class Keithley3706A(HasTraits):
    def __init__(self):
       self.Keithley3706AUSB = visa.instrument("USB0::0x05E6::0x3706::04019447::INSTR") 

    def message(self,foo):
        s="display.settext('%s')" % foo
        self.Keithley3706AUSB.write("display.clear()")
        self.Keithley3706AUSB.write(s)

    def clear(self):
        self.Keithley3706AUSB.write("display.clear()")
4

1 回答 1

2

ControlPanel课堂上,您创建了 的两个不同实例Keithley3706ASettings,即keithley3706Asettingsk3706A_settings。如果我删除后者,并替换使用k3706A_settingswith keithley3706Asettings,它的工作原理。这是我的版本(删除了对 2430 设备的引用,k3706A声明为Instanceof的特征Keithley3706A,以及其他一些不相关的 UI 更改):

class ControlPanel(HasTraits):

    keithley3706Asettings = Instance(Keithley3706A_module.Keithley3706ASettings, ())

    k3706A = Instance(Keithley3706A_module.Keithley3706A, ())

    start = Button("Start Measurements")
    clear_3706A_display = Button("Clear K3706A Display")

    view = View(UItem('start'),
                UItem('clear_3706A_display'),
                Item('keithley3706Asettings', style='simple'))

    def _start_fired(self):
        print "hello %s" % self.keithley3706Asettings.display
        self.k3706A.message(self.keithley3706Asettings.display)

    def _clear_3706A_display_fired(self):
        self.k3706A.clear()
于 2013-11-04T13:44:00.213 回答