Ejemplo n.º 1
0
    def onButton(self, evt, mode):
        from ifigure.ifigure_config import vv_scratch
        import ifigure.utils.pickle_wrapper as pickle

        idx = self.grid.GetSelectedRows()
        if len(idx) == 0 and mode != 'paste':
            return
        gt = self.grid.GetTable()
        obj = gt.GetTreeDict()

        if mode == 'copy':
            name = str(self.grid.GetRowLabelValue(idx[0]))
            self.GetTopLevelParent().set_status_text('Copy ' + name,
                                                     timeout=3000)
            try:
                fid = open(vv_scratch, 'wb')
                data = {name: obj.getvar(name)}
                pickle.dump(data, fid)
                fid.close()
            except:
                dialog.showtraceback(parent=self,
                                     txt='Failed to copy',
                                     title='Failed to copy',
                                     traceback=traceback.format_exc())
        elif mode == 'paste':
            if not os.path.exists(vv_scratch):
                dialog.showtraceback(parent=self,
                                     txt='paste data does not exists',
                                     title='Failed to paste',
                                     traceback='')
                return
            fid = open(vv_scratch, 'rb')
            data = pickle.load(fid)
            fid.close()
            for key in data:
                if obj.hasvar(key):
                    dlg = wx.MessageDialog(
                        None, 'Do you want to overwrite ' + key + '?',
                        'Variable already existws', wx.OK | wx.CANCEL)
                    ret = dlg.ShowModal()
                    dlg.Destroy()
                    if ret != wx.ID_OK:
                        continue
                self.GetTopLevelParent().set_status_text('Paste tree variable',
                                                         timeout=3000)
                obj.setvar(key, data[key])
                obj._var_changed = True
            self.update()
        elif mode == 'trash':
            name = str(self.grid.GetRowLabelValue(idx[0]))
            dlg = wx.MessageDialog(None, 'Do you want to delete ' + name + '?',
                                   'Deleting variable', wx.OK | wx.CANCEL)
            ret = dlg.ShowModal()
            dlg.Destroy()
            if ret == wx.ID_OK:
                obj.delvar(name)
                obj._var_changed = True
                self.GetTopLevelParent().set_status_text('Deltete ' + name,
                                                         timeout=3000)
                wx.CallAfter(self.update)
Ejemplo n.º 2
0
def importv(dest=None, path=''):
    '''
    import variables which was saved as pickled file

    '''
    import ifigure.utils.pickle_wrapper as pickle
    from ifigure.mto.py_code import PyData
    if dest is None:
        from __main__ import ifig_app
        dest = PyData()
        ifig_app.proj.add_child('data', dest)

    if path == '':
        open_dlg = wx.FileDialog(None,
                                 message="Select Data File",
                                 style=wx.FD_OPEN)
        if open_dlg.ShowModal() != wx.ID_OK:
            open_dlg.Destroy()
            return
        path = open_dlg.GetPath()
        open_dlg.Destroy()
        if path == '':
            return
    fid = open(path, 'r')
    data = pickle.load(fid)
    fid.close()

    for key in data:
        dest.setvar(key, data[key])

    ifigure.events.SendChangedEvent(dest, w=ifig_app, useProcessEvent=True)
    return dest
Ejemplo n.º 3
0
 def load_data(self, fid=None):
     h2 = pickle.load(fid)
     if self.hasp("loaded_property"):
         lp = self.getp("loaded_property")
     else:
         lp = []
     lp.append(h2)
     self.setp("loaded_property", lp)
Ejemplo n.º 4
0
 def recv(self, nowait=True):
     #        print self._check_readbuf()
     if self._check_readbuf() or not nowait:
         try:
             return pickle.load(self.in_f)
         except:
             return {'error message': ['pickle communicaiton error']}
     else:
         return None
Ejemplo n.º 5
0
    def __init__(self, parent=None):
        self.ch = None  # command history panel

        #       self.chistory=collections.deque(maxlen=100)
        self.lvar = {}
        self._no_record = False

        sc = os.path.join(os.path.dirname(ifigure.__file__), 'startup.py')
        txt = '    --- Welcome to piScope (' + ifig_version + ')---'
        super(SimpleShell, self).__init__(parent,
                                          locals=self.lvar,
                                          startupScript=sc,
                                          introText=txt)
        if os.getenv('PYTHONSTARTUP') is not None:
            file = os.getenv('PYTHONSTARTUP')
            if os.path.exists(file):
                dprint1('running startup file', file)
                txt = 'Running user startup file ' + file
                self.push('print %r' % txt)
                #self.execfile(file, globals(), self.lvar)
                self.execStartupScript(file)

        self.SetDropTarget(simple_shell_droptarget(self))

        from ifigure.ifigure_config import rcdir
        file = os.path.join(rcdir, "command_history")
        try:
            f = open(file, 'rb')
            self.history = pickle.load(f)
            f.close()
        except Exception:
            import traceback
            traceback.print_exc()
            print("Can not load command history file")

        if self.history[-1] != '#end of history':
            self.history.append('#end of history')

        SimpleShell.SHELL = self
        self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
        self.Bind(wx.EVT_LEFT_UP, self.onLeftUp)
        self.Bind(wx.EVT_SET_FOCUS, self.onSetFocus)
        self.Bind(wx.EVT_KILL_FOCUS, self.onKillFocus)
        self.st = ''  # search txt
        self.st_flag = False

        self._auto_complete = True
Ejemplo n.º 6
0
 def load_data(self, fid):
     h2 = pickle.load(fid)
     self.setvar("load_property", h2)