Exemple #1
0
class ViewHandler(ui.Handler):

    # You can initialize this by obtaining it from the methods below and, self.info = info
    info = tr.Instance(ui.UIInfo)

    exit_view = ui.View(ui.VGroup(
        ui.Label('Do you really wish to end '
                 'the session? Any unsaved data '
                 'will be lost.'),
        ui.HGroup(ui.Item('ok', show_label=False, springy=True),
                  ui.Item('cancel', show_label=False, springy=True))),
                        title='Exit dialog',
                        kind='live')

    def menu_utilities_csv_joiner(self):
        csv_joiner = CSVJoiner()
        # kind='modal' pauses the background traits window until this window is closed
        csv_joiner.configure_traits()

    def menu_about_tool(self):
        about_tool = AboutTool()
        about_tool.configure_traits()

    def get_outfile(self, folder_name, file_name):
        '''Returns a file in the specified folder using the home
        directory as root.
        '''
        HOME_DIR = os.path.expanduser("~")
        out_dir = os.path.join(HOME_DIR, folder_name)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        outfile = os.path.join(out_dir, file_name)
        return outfile

    def menu_save(self, info):
        file_name = self.get_outfile(folder_name='.hcft', file_name='')
        file_ = save_file(file_name=file_name)
        if file_:
            pickle.dump(info.object.root, open(file_, 'wb'), 1)

    def menu_open(self, info):
        file_name = self.get_outfile(folder_name='.hcft', file_name='')
        file_ = open_file(file_name=file_name)
        if file_:
            info.object.root = pickle.load(open(file_, 'rb'))

    def menu_exit(self, info):
        if info.initialized:
            info.ui.dispose()
Exemple #2
0
    def chooseVariables(self):
        """Opens a dialog asking user to select columns from a data File that has
        been selected. THese are then returned as a string suitable for Y cols input"""
        columns = self.physics.variables.keys()
        columns.sort()
        values = zip(range(0, len(columns)), columns)

        checklist_group = traitsui.Group(
            '10',  # insert vertical space
            traitsui.Label('Select the additional variables you wish to log'),
            traitsui.UItem('columns',
                           style='custom',
                           editor=traitsui.CheckListEditor(values=values,
                                                           cols=6)),
            traitsui.UItem('selectAllButton'))

        traits_view = traitsui.View(checklist_group,
                                    title='CheckListEditor',
                                    buttons=['OK'],
                                    resizable=True,
                                    kind='livemodal')

        col = ColumnEditor(numberOfColumns=len(columns))
        try:
            col.columns = [
                columns.index(varName) for varName in self.xmlLogVariables
            ]
        except Exception as e:
            logger.error(
                "couldn't selected correct variable names. Returning empty selection"
            )
            logger.error("%s " % e.message)
            col.columns = []
        col.edit_traits(view=traits_view)
        logger.debug("value of columns selected = %s ", col.columns)
        logger.debug("value of columns selected = %s ",
                     [columns[i] for i in col.columns])
        return [columns[i] for i in col.columns]
Exemple #3
0
        _traitsui.Item('messages',
                       show_label=False,
                       springy=True,
                       style='custom'),
        title='Conjoint warning',
        height=300,
        width=600,
        resizable=True,
        buttons=[_traitsui.OKButton],
    )


selection_view = _traitsui.Group(
    _traitsui.Group(
        _traitsui.Group(
            _traitsui.Label('Design:'),
            _traitsui.Item(
                'controller.selected_design',
                editor=_traitsui.CheckListEditor(
                    name='controller.available_design_sets'),
                style='simple',
                show_label=False,
            ),
            _traitsui.Label('Variables:'),
            _traitsui.Item(
                'controller.sel_design_var',
                editor=_traitsui.CheckListEditor(
                    name='controller.design_vars'),
                style='custom',
                show_label=False,
            ),
Exemple #4
0
        if len(info.object.rsubs) > 0:
            self.summary += "Column coloring classes: {}\n".format(", ".join(
                info.object.rsubs.keys()))


transpose_action = _traitsui.Action(
    name='Create transposed copy',
    action='handler.transpose_ds(editor, object)')

tr_menu = _traitsui.Menu(transpose_action, _te.DeleteAction)

ds_view = _traitsui.View(
    _traitsui.Group(
        _traitsui.Group(
            _traitsui.Item('id', style='readonly'),
            _traitsui.Label('Data set name:'),
            _traitsui.Item('display_name', show_label=False),
            _traitsui.Label('Data set type:'),
            _traitsui.Item('kind', show_label=False),
        ),
        _traitsui.Group(
            _traitsui.Item('handler.summary',
                           style='readonly',
                           show_label=False),
            label='Data set summary',
            show_border=True,
        ),
    ),
    kind='nonmodal',
    handler=DSHandler(),
)
Exemple #5
0
class Sike(HasTraits):
    """ Tie several profile-related widgets together.

    Sike is like Gotcha, only less mature.
    """

    # The main pstats.Stats() object providing the data.
    stats = Any()

    # The main results and the subcalls.
    main_results = Instance(ProfileResults, args=())
    caller_results = Instance(ProfileResults, args=())
    callee_results = Instance(ProfileResults, args=())

    # The records have list of callers. Invert this to give a map from function
    # to callee.
    callee_map = Dict()

    # Map from the (file, lineno, name) tuple to the record.
    record_map = Dict()

    #### GUI traits ############################################################

    basenames = Bool(True)
    percentages = Bool(True)
    filename = Str()
    line = Int(1)
    code = Str()

    traits_view = tui.View(
        tui.VGroup(
            tui.HGroup(
                tui.Item('basenames'),
                tui.Item('percentages'), ),
            tui.HGroup(
                tui.UItem('main_results'),
                tui.VGroup(
                    tui.Label('Callees'),
                    tui.UItem('callee_results'),
                    tui.Label('Callers'),
                    tui.UItem('caller_results'),
                    tui.UItem(
                        'filename', style='readonly'),
                    tui.UItem(
                        'code', editor=tui.CodeEditor(line='line')), ),
                style='custom', ), ),
        width=1024,
        height=768,
        resizable=True,
        title='Profiling results', )

    @classmethod
    def fromstats(cls, stats, **traits):
        """ Instantiate an Sike from a Stats object, Stats.stats dictionary, or
        Profile object, or a filename of the saved Stats data.
        """
        stats = SillyStatsWrapper.getstats(stats)

        self = cls(stats=stats, **traits)
        self._refresh_stats()
        return self

    def add_stats(self, stats):
        """ Add new statistics.
        """
        stats = SillyStatsWrapper.getstats(stats)
        self.stats.add(stats)
        self._refresh_stats()

    def records_from_stats(self, stats):
        """ Create a list of records from a stats dictionary.
        """
        records = []
        for file_line_name, (ncalls, nonrec_calls, inline_time, cum_time,
                             calls) in list(stats.items()):
            newcalls = []
            for sub_file_line_name, sub_call in list(calls.items()):
                newcalls.append(Subrecord((sub_file_line_name, ) + sub_call))
            records.append(
                Record((file_line_name, ncalls, nonrec_calls, inline_time,
                        cum_time, newcalls)))
        return records

    def get_callee_map(self, records):
        """ Create a callee map.
        """
        callees = defaultdict(list)
        for record in records:
            for caller in record.callers:
                callees[caller.file_line_name].append(
                    Subrecord((record.file_line_name, ) + caller[1:]))
        return callees

    @on_trait_change('percentages,basenames')
    def _adapter_traits_changed(self, object, name, old, new):
        for obj in [
                self.main_results, self.callee_results, self.caller_results
        ]:
            setattr(obj, name, new)

    @on_trait_change('main_results:selected_record')
    def update_sub_results(self, new):
        if new is None:
            return
        self.caller_results.total_time = new.cum_time
        self.caller_results.records = new.callers
        self.callee_results._resort()
        self.caller_results.selected_record = self.caller_results.activated_record = None

        self.callee_results.total_time = new.cum_time
        self.callee_results.records = self.callee_map.get(new.file_line_name,
                                                          [])
        self.callee_results._resort()
        self.callee_results.selected_record = self.callee_results.activated_record = None

        filename, line, name = new.file_line_name
        if os.path.exists(filename):
            with open(filename, 'ru') as f:
                code = f.read()
            self.code = code
            self.filename = filename
            self.line = line
        else:
            self.trait_set(
                code='',
                filename='',
                line=1, )

    @on_trait_change('caller_results:dclicked,' 'callee_results:dclicked')
    def goto_record(self, new):
        if new is None:
            return
        if new.item.file_line_name in self.record_map:
            record = self.record_map[new.item.file_line_name]
            self.main_results.selected_record = record

    @on_trait_change('stats')
    def _refresh_stats(self):
        """ Refresh the records from the stored Stats object.
        """
        self.main_results.records = self.main_results.sort_records(
            self.records_from_stats(self.stats.stats))
        self.callee_map = self.get_callee_map(self.main_results.records)
        self.record_map = {}
        total_time = 0.0
        for record in self.main_results.records:
            self.record_map[record.file_line_name] = record
            total_time += record.inline_time
        self.main_results.total_time = total_time