Ejemplo n.º 1
0
def run():
    from sim_model import SimModel
    from sim_array import SimArray

    pstudy = SimArray(sim_model=SimModel())
    pstudy_view = SimArrayView(model=pstudy)
    pstudy_view.configure_traits()
Ejemplo n.º 2
0
 def new(self):
     sim_model = self.sim_array.sim_model
     self.sim_array = SimArray(sim_model=sim_model)
     self.dirty = False
Ejemplo n.º 3
0
 def _sim_array_default(self):
     return SimArray()
Ejemplo n.º 4
0
class SimPStudy(HasTraits):
    """ The main application window. """

    def __init__(self, **kw):
        super(SimPStudy, self).__init__(**kw)

        # The initialization should not be considered dirty
        # therefore set the flag to indicate unsaved study to false
        #
        self.dirty = False

    sim_array = Instance(SimArray)

    def _sim_array_default(self):
        return SimArray()

    sim_model = Property()

    def _set_sim_model(self, value):
        self.sim_array.sim_model = value

    def __getitem__(self, factor_slices):
        '''Direct access to the sim_array.
        '''
        return self.sim_array[factor_slices]

    #---------------------------------------------------------------
    # PERSISTENCY
    #-------------------------------------------------------------------

    file_base_name = Property()

    def _get_file_base_name(self):
        return self.sim_model.__class__.__name__

    file_path = Str('')

    dirty = False

    @on_trait_change('sim_array.changed')
    def _set_dirty(self):
        self.dirty = True

    def new(self):
        sim_model = self.sim_array.sim_model
        self.sim_array = SimArray(sim_model=sim_model)
        self.dirty = False

    def load(self, file_name):
        file = open(file_name, 'r')
        self.sim_array = pickle.load(file)
        file.close()
        self.dirty = False

    def save(self, file_name):
        file = open(file_name, 'w')
        pickle.dump(self.sim_array, file)
        file.close()
        self.dirty = False

    def clear_cache(self):
        self.sim_array.clear_cache()

    toolbar = ToolBar(
        Action(name="New Study",
               tooltip='Create a new study',
               image=ImageResource('New-32'),
               action="new_study"),
        Action(name="Open Study",
               tooltip='Open a study',
               image=ImageResource('fileopen-32'),
               action="open_study"),
        Action(name="Save Study",
               tooltip='Save study',
               image=ImageResource('save'),
               action="save_study"),
        Action(name="New View",
               tooltip='Create new view',
               image=ImageResource('new_view'),
               action="new_view"),
        Action(name="Clear Cache",
               tooltip='Reset cache',
               image=ImageResource('reset'),
               action="clear_cache"),
        image_size=(22, 22),
        show_tool_names=False,
        show_divider=True,
        name='study_toolbar')

    menubar = MenuBar(Menu(Action(name="&New",
                                  action="new_study"),
                           Action(name="&Open",
                                  action="open_study"),
                           Action(name="&Save",
                                  action="save_study"),
                           Action(name="Save &As",
                                  action="save_study_as"),
                           Action(name="&Exit",
                                  action="exit_study"),
                           name="&File"),
                      Menu(Action(name="&New View",
                                  action="new_view"),
                           name="&View"),
                      Menu(Action(name="&Clear Cache",
                                  action="clear_cache"),
                           name="&Data"),
                      Menu(Action(name="About PStudy",
                                  action="about_pstudy"),
                           HelpAction,
                           name="Help")
                      )

    view = View(
        Item('sim_array@', show_label=False),
        id='simvisage.simiter.pstudy',
        dock='tab',
        menubar=menubar,
        toolbar=toolbar,
        resizable=True,
        width=0.8,
        height=0.8,
        title='SimVisage: Parametric Study',
        handler=SimPStudyController,
    )