私はチュートリアル「TraitsUI http://code.enthought.com/projects/traits/docs/html/tutorials/traits_ui_scientific_app.html を使用して科学的プログラミング用のグラフィカル アプリケーションを作成する」に従い、次のコード スニペットをテストしました。
from enthought.traits.api import *
from enthought.traits.ui.api import *
class Camera(HasTraits):
""" Camera object """
gain = Enum(1, 2, 3,
desc="the gain index of the camera",
label="gain", )
exposure = CInt(10,
desc="the exposure time, in ms",
label="Exposure", )
def capture(self):
""" Captures an image on the camera and returns it """
print "capturing an image at %i ms exposure, gain: %i" % (
self.exposure, self.gain )
if __name__ == "__main__":
camera = Camera()
camera.configure_traits()
camera.capture()
コマンドラインでこれを実行すると、宣伝どおりに機能します。GUI がポップアップします。パラメータを調整し、[OK] をクリックすると、変更された値が返されます。しかし、実行ボタンをクリックして Canopy エディター内から同じコードを実行すると、デフォルトのパラメーターがすぐに出力されます。その後、ウィンドウがポップアップします。GUI でパラメーターを調整して [OK] をクリックすると、GUI は終了しますが、新しいパラメーター値は出力されません。
どういうわけか camera.capture() が camera.configure_traits の前に実行されているようです。