| 1060 | else: |
| 1061 | return s |
| 1062 | def pye_edit(content, tab_size=4, undo=50, io_device=None): |
| 1063 | if io_device is None: |
| 1064 | print("IO device not defined") |
| 1065 | return |
| 1066 | gc.collect() |
| 1067 | index = 0 |
| 1068 | undo = max(4, (undo if type(undo) is int else 0)) |
| 1069 | current_dir = os.getcwd() |
| 1070 | if content: |
| 1071 | slot = [] |
| 1072 | for f in content: |
| 1073 | slot.append(Editor(tab_size, undo, io_device)) |
| 1074 | if type(f) == str and f: |
| 1075 | try: |
| 1076 | slot[index].get_file(f) |
| 1077 | except Exception as err: |
| 1078 | slot[index].message = "{!r}".format(err) |
| 1079 | else: |
| 1080 | try: |
| 1081 | slot[index].content = [str(_) for _ in f] |
| 1082 | except: |
| 1083 | slot[index].content = [str(f)] |
| 1084 | index += 1 |
| 1085 | else: |
| 1086 | slot = [Editor(tab_size, undo, io_device)] |
| 1087 | slot[0].get_file(current_dir) |
| 1088 | while True: |
| 1089 | try: |
| 1090 | index %= len(slot) |
| 1091 | key = slot[index].edit_loop() |
| 1092 | if key == KEY_QUIT: |
| 1093 | if len(slot) == 1: |
| 1094 | break |
| 1095 | del slot[index] |
| 1096 | elif key == KEY_GET: |
| 1097 | f = slot[index].line_edit("Open file: ", "", Editor.file_char) |
| 1098 | if f is not None: |
| 1099 | slot.append(Editor(tab_size, undo,io_device)) |
| 1100 | index = len(slot) - 1 |
| 1101 | slot[index].get_file(f) |
| 1102 | elif key == KEY_NEXT: |
| 1103 | index += 1 |
| 1104 | elif key == KEY_FORCE_QUIT: |
| 1105 | break |
| 1106 | except Exception as err: |
| 1107 | slot[index].message = "{!r}".format(err) |
| 1108 | Editor.yank_buffer = [] |
| 1109 | os.chdir(current_dir) |
| 1110 | return slot[0].content if (slot[0].fname == "") else slot[0].fname |
| 1111 | try: |
| 1112 | import usys as sys |
| 1113 | except: |