Пример #1
0
 def generate_artist(self):
     FigAxline.generate_artist(self)
     idx = np.where([not x for x in self.getp('enabled_point')])[0]
     if self._enable_a is not None:
         self._enable_a.remove()
         self._enable_a = None
     if idx.size == 0:
         return
     self._enable_a = []  ## it is actually for disabled points
     x, y = self._eval_xy()
     container = self.get_container()
     for k in idx:
         lw = self._artists[k].get_linewidth()
         if k < x.size:
             self._enable_a.append(
                 container.axvline(x[k],
                                   color='white',
                                   linestyle='--',
                                   linewidth=lw))
         else:
             self._enable_a.append(
                 container.axhline(y[k - x.size],
                                   color='white',
                                   linestyle='--',
                                   linewidth=lw))
Пример #2
0
 def picker_a(self, a, evt):
     hit, extra = FigAxline.picker_a(self, a, evt)
     if hit:
         self._figc_hit = self._artists.index(extra['child_artist'])
         self._drag_backup = (a.get_xdata(), a.get_ydata())
     else:
         self._figc_hit = -1
     return hit, extra
Пример #3
0
 def picker_a(self, a, evt): 
     hit, extra = FigAxline.picker_a(self, a, evt)
     if hit:
         self._figc_hit = self._artists.index(extra['child_artist'])
         self._drag_backup = (a.get_xdata(), a.get_ydata())
     else:
         self._figc_hit = -1
     return hit, extra
Пример #4
0
 def __new__(cls, *args,**kargs):
     draggable, kargs = ProcessKeywords(kargs, 'draggable', True)
     dragmode, kargs = ProcessKeywords(kargs, 'dragmodee', 'independent')
     enabled_point, kargs = ProcessKeywords(kargs, 'enabled_point', 'all')
     obj = FigAxline.__new__(cls, *args,**kargs)
     if obj is not None:
         obj.setvar('draggable', draggable)
         obj.setvar('dragmode', dragmode)
         if not obj.hasvar('enabled_point'): obj.setvar('enabled_point', enabled_point)
     return obj
Пример #5
0
 def __new__(cls, *args, **kargs):
     draggable, kargs = ProcessKeywords(kargs, 'draggable', True)
     dragmode, kargs = ProcessKeywords(kargs, 'dragmodee', 'independent')
     enabled_point, kargs = ProcessKeywords(kargs, 'enabled_point', 'all')
     obj = FigAxline.__new__(cls, *args, **kargs)
     if obj is not None:
         obj.setvar('draggable', draggable)
         obj.setvar('dragmode', dragmode)
         if not obj.hasvar('enabled_point'):
             obj.setvar('enabled_point', enabled_point)
     return obj
Пример #6
0
 def canvas_menu(self):
     m = [('Add Point', self.onAddPoint, None),]
     if self._figc_hit != -1:
         if self.getp('enabled_point')[self._figc_hit]:
            m = m + [('Delete Point', self.onDelPoint, None),
                     ('Edit Point', self.onEditPoint, None),
                     ('Disable Point', self.onDisablePoint, None),]
         else:
            m = m + [('Delete Point', self.onDelPoint, None),
                     ('Edit Point', self.onEditPoint, None),
                     ('Enable Point', self.onEnablePoint, None),]
     return m + FigAxline.canvas_menu(self)
Пример #7
0
 def generate_artist(self):
     FigAxline.generate_artist(self)
     idx = np.where([not x for x in self.getp('enabled_point')])[0]
     if self._enable_a is not None:
        self._enable_a.remove()
        self._enable_a = None
     if idx.size == 0: 
         return
     self._enable_a = [] ## it is actually for disabled points
     x, y  = self._eval_xy()
     container=self.get_container()
     for k in idx:
         lw = self._artists[k].get_linewidth()
         if k < x.size:
            self._enable_a.append(container.axvline(x[k], 
                                                    color = 'white', 
                                                    linestyle = '--',
                                                    linewidth = lw))
         else:
            self._enable_a.append(container.axhline(y[k-x.size], 
                                                    color = 'white', 
                                                    linestyle = '--',
                                                    linewidth = lw))
Пример #8
0
    def drag(self, a, evt):
        if self.getvar('dragmode') == 'independent':
            if evt.inaxes is None: return 0
            if evt.xdata is None: return

            axes = a.axes
            x, y = self._eval_xy()
            if self._figc_hit < x.size:
                #                self.setp('x')[self._figc_hit] = evt.xdata
                self._artists[self._figc_hit].set_xdata([evt.xdata, evt.xdata])
            else:
                #                self.setp('y')[self._figc_hit - x.size] = evt.ydata
                self._artists[self._figc_hit].set_ydata([evt.ydata, evt.ydata])
        else:
            return FigAxline.drag(self, a, evt)
Пример #9
0
    def drag(self, a, evt):
        if self.getvar('dragmode') == 'independent':
            if evt.inaxes is None: return 0
            if evt.xdata is None:return

            axes = a.axes
            x, y = self._eval_xy()
            if self._figc_hit < x.size:
#                self.setp('x')[self._figc_hit] = evt.xdata
                self._artists[self._figc_hit].set_xdata([evt.xdata, evt.xdata])
            else:
#                self.setp('y')[self._figc_hit - x.size] = evt.ydata
                self._artists[self._figc_hit].set_ydata([evt.ydata, evt.ydata])
        else:
            return FigAxline.drag(self, a, evt)
Пример #10
0
 def canvas_menu(self):
     m = [
         ('Add Point', self.onAddPoint, None),
     ]
     if self._figc_hit != -1:
         if self.getp('enabled_point')[self._figc_hit]:
             m = m + [
                 ('Delete Point', self.onDelPoint, None),
                 ('Edit Point', self.onEditPoint, None),
                 ('Disable Point', self.onDisablePoint, None),
             ]
         else:
             m = m + [
                 ('Delete Point', self.onDelPoint, None),
                 ('Edit Point', self.onEditPoint, None),
                 ('Enable Point', self.onEnablePoint, None),
             ]
     return m + FigAxline.canvas_menu(self)
Пример #11
0
    def dragdone(self, a, evt):
        if self.getvar('dragmode') == 'independent':
            axes = a.axes
            x, y = self._eval_xy()
            if self._figc_hit < x.size:
                x = self.getp('x').copy()
                x[self._figc_hit] = evt.xdata
                y = self.getp('y').copy()
            else:
                x = self.getp('x').copy()
                y = self.getp('y').copy()
                y[self._figc_hit - x.size] = evt.ydata

            action = UndoRedoFigobjMethod(self._artists[0], 'data', (x, y))
            window = evt.guiEvent.GetEventObject().GetTopLevelParent()
            GlobalHistory().get_history(window).make_entry([action])
            return 1
        else:
            return FigAxline.dragdone(self, a, evt)
Пример #12
0
    def dragdone(self, a, evt):
        if self.getvar('dragmode') == 'independent':
            axes = a.axes
            x, y = self._eval_xy()
            if self._figc_hit < x.size:
                x = self.getp('x').copy()
                x[self._figc_hit] = evt.xdata
                y = self.getp('y').copy()
            else:
                x = self.getp('x').copy()
                y = self.getp('y').copy()
                y[self._figc_hit - x.size] = evt.ydata

            action = UndoRedoFigobjMethod(self._artists[0], 
                                         'data', 
                                          (x, y))
            window = evt.guiEvent.GetEventObject().GetTopLevelParent()
            GlobalHistory().get_history(window).make_entry([action])
            return 1
        else:
            return FigAxline.dragdone(self, a, evt)
Пример #13
0
    def postprocess_data(
        self,
        ana,
        viewer,
        color_order=['red', 'blue', 'yellow'],
    ):
        def set_auto_color_to_color(kargs, name, col):
            if (not name in kargs) or (kargs[name] == 'auto'):
                kargs[name] = col
            return kargs

        from ifigure.mto.fig_plot import FigPlot, TimeTrace, StepPlot
        from ifigure.mto.fig_contour import FigContour
        from ifigure.mto.fig_image import FigImage
        from ifigure.mto.fig_surface import FigSurface
        from ifigure.mto.fig_axline import FigAxline
        from ifigure.mto.fig_axspan import FigAxspan
        from ifigure.mto.fig_text import FigText

        self._color_order = color_order
        dprint2('process_data', self)
        if ana.skipped:
            if ana.do_title:
                self.process_title(ana)
            return True

        if (self.isempty() and not self.get_figaxes().isempty()
                and not self._suppress):
            self.generate_artist()
#        app = self.get_app()
#        ax = self.get_container()
#        fig_ax = ax.figobj

        ishot = ana.ishot

        self._analysis_flag[ishot] = False
        col = color_order[ishot % len(color_order)]

        for x in range(ishot - self.num_child() + 1):
            plot_options = self.getvar('plot_options')
            if self._plot_type == 'plot':
                kargs = plot_options['plot'][1].copy()
                kargs = set_auto_color_to_color(kargs, 'color', col)
                kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
                kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
                obj = FigPlot([0], [0], *(plot_options['plot'][0]), **kargs)
            elif self._plot_type == 'timetrace':
                kargs = plot_options['timetrace'][1].copy()
                kargs = set_auto_color_to_color(kargs, 'color', col)
                kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
                kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
                obj = TimeTrace([0], [0], *(plot_options['timetrace'][0]),
                                **kargs)
            elif self._plot_type == 'stepplot':
                kargs = plot_options['stepplot'][1].copy()
                kargs = set_auto_color_to_color(kargs, 'color', col)
                kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
                kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
                obj = StepPlot([0], [0], *(plot_options['stepplot'][0]),
                               **kargs)
            elif self._plot_type == 'contour':
                obj = FigContour([0, 1], [0, 1],
                                 np.arange(4).reshape(2, 2),
                                 *(plot_options['contour'][0]))
            elif self._plot_type == 'image':
                obj = FigImage(np.zeros([2, 2]))
            elif self._plot_type == 'surface':
                obj = FigSurface(np.zeros([2, 2]))
            elif self._plot_type == 'axspan':
                obj = FigAxspan([0, 1])
            elif self._plot_type == 'axline':
                obj = FigAxline(np.zeros([1]))
            elif self._plot_type == 'text':
                obj = FigText(0, 0, '')
            name = self._plot_type + str(self.num_child() + 1)
            self.add_child(name, obj)
            obj.set_container_idx(self._container_idx)
            obj.set_suppress(True)
        if self.get_script_local():
            txt = self.make_script(ana.shot, short=True)
            debug_mode = viewer.debug_mode
            if txt is not None:
                try:
                    vars = viewer.get_globals_for_figmds(ana.shot)
                    #                  print vars
                    for key in vars:
                        ana.result[key] = vars[key]
                    for key in viewer.startup_values:
                        ana.result[key] = viewer.startup_values[key]
                    ana.result['shot'] = ana.shot
                    if self.getvar('posvars') is not None:
                        a = {}
                        b = {}
                        exec self.getvar('posvars') in a, b
                        for key in b:
                            ana.result[key] = b[key]
                    filepath = os.path.join(self.owndir(), script_file_name)
                    from ifigure.widgets.debugger_core import get_breakpoint
                    code = compile(txt, filepath, 'exec')
                    if (len(get_breakpoint(filepath)) != 0 and debug_mode):
                        app = wx.GetApp().TopWindow
                        se = app.script_editor
                        import threading
                        if not se.CheckDebuggerStatus():
                            se.QueueSEDRequest(code, viewer.g, ana.result,
                                               filepath)
#                          print threading.current_thread().name
#                          wx.Yield()
#                          time.sleep(3)
                        else:
                            se.RunSED(code, viewer.g, ana.result, filepath)
                    else:
                        exec code in viewer.g, ana.result
                except:
                    dprint1('error occured when processing data by script')
                    print(
                        'error occured when processing data by following script'
                    )
                    print('#####')
                    print(txt)
                    print('#####')
                    print(traceback.format_exc())
                    self.change_suppress(True, self.get_child(ishot))
                    return False

        if ana.do_title:
            self.process_title(ana)
        if self._plot_type == 'plot':
            self._update_plot(ana, ishot)  #, color_order)
        elif self._plot_type == 'timetrace':
            self._update_plot(ana, ishot)  #, color_order)
        elif self._plot_type == 'stepplot':
            self._update_plot(ana, ishot)  #, color_order)
        elif self._plot_type == 'contour':
            self._update_contour(ana, ishot)
        elif self._plot_type == 'image':
            self._update_image(ana, ishot)
        elif self._plot_type == 'surface':
            self._update_surface(ana, ishot)
        elif self._plot_type == 'axspan':
            self._update_axspan(ana, ishot)
        elif self._plot_type == 'axline':
            self._update_axline(ana, ishot)
        elif self._plot_type == 'text':
            self._update_text(ana, ishot)

        obj = self.get_child(idx=ishot)
        if obj.is_suppress():
            return False

        obj._data_extent = None
        try:
            if (self.get_figaxes() is not None):
                self.get_figaxes().adjust_axes_range()
        except:
            dprint1(
                "failed in adjusting axes at postprocess_data, continuing...")
            pass
        return True
Пример #14
0
 def del_artist(self, artist=None, delall=False):
     if self._enable_a is not None:
         for a in self._enable_a:
             a.remove()
         self._enable_a = None
     return FigAxline.del_artist(self, artist=artist, delall=delall)
Пример #15
0
 def args2var(self):
     val = FigAxline.args2var(self)
     if self.getvar('enabled_point') == 'all':
         self.setp('enabled_point',
                   [True] * (self.getp('x').size + self.getp('y').size))
     return val
Пример #16
0
 def __init__(self, *args, **kargs):
     FigAxline.__init__(self, *args, **kargs)
     FigControl.__init__(self)
     self._figc_hit = -1
     self._enable_a = None
Пример #17
0
 def del_artist(self, artist=None, delall=False):
     if self._enable_a is not None:
        for a in self._enable_a: a.remove()
        self._enable_a = None
     return FigAxline.del_artist(self, artist=artist, delall=delall)
Пример #18
0
 def args2var(self):
     val = FigAxline.args2var(self)
     if self.getvar('enabled_point') == 'all':
        self.setp('enabled_point', 
               [True]*(self.getp('x').size + self.getp('y').size))
     return val
Пример #19
0
 def __init__(self, *args, **kargs):
     FigAxline.__init__(self, *args, **kargs)
     FigControl.__init__(self)
     self._figc_hit = -1
     self._enable_a = None