Пример #1
0
    def OnDuplicateItemFromModel(self, evt):
        indices = self.tree.GetIndexOfItem(self.tree.GetSelection())
        self.tree.SelectItem(self.tree.GetSelection(), select=False)

        mm = self.model.GetItem(indices)
        name = mm.name()
        base, num = mm.split_digits()
        parent = mm.parent

        newmm = pickle.loads(pickle.dumps(mm))

        index = list(parent).index(name)
        nums = []
        for key in parent.keys():
            #base0 = ''.join([k for k in key if not k.isdigit()])
            base0, num = parent[key].split_digits()
            if base0 != base: continue

            #nums.append(int(''.join([k for k in key if k.isdigit()])))
            nums.append(int(num))

        parent.insert_item(index + 1, base + str(int(max(nums)) + 1), newmm)
        self.tree.RefreshItems()

        new_item = self.tree.GetItemByIndex(newmm.GetIndices())
        self.tree.SelectItem(new_item)
        self.OnEvalNS(evt)
Пример #2
0
    def __call_server0(self, name, *params, **kparams):
        if self.p is None: return
        verbose = kparams.pop("verbose", False)
        force_protocol1 = kparams.pop("force_protocol1", False)
        prompt = kparams.pop("prompt", "?")
        nowait = kparams.pop("nowait", False)
        command = [name, params, kparams]
        data = binascii.b2a_hex(pickle.dumps(command))
        print("Sending request", command)
        self.p.stdin.write(data.decode('utf-8') + '\n')
        self.p.stdin.flush()

        if nowait:
           return
        protocol = 1 if force_protocol1 else self.p.evalsvr_protocol

        import threading
        print("calling wait for prompt", threading.current_thread())
        output, alive = wait_for_prompt(self.p,
                                        prompt=prompt, 
                                        verbose = verbose,
                                        withsize = protocol > 1)
        if not alive:
           self.p = None
           return
        if protocol > 1:
            response = output[-1]
        else:
            response = binascii.a2b_hex(output[-1].strip())
        try:
            result = pickle.loads(response)
            if verbose:
                print("result", result)
        except:
            traceback.print_exc()
            print("response", response)
            print("output", output)
            assert False, "Unpickle failed"
        #print('output is', result)
        if result[0] == 'ok':
            return result[1]
        elif result[0] == 'echo':
            print(result[1])
        else:
            print(result)
            #assert False, result[1]
            message = ''.join(result[1])
            assert False, message