Show More
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | # -*- coding: iso-8859-1 -*- |
|
2 | 2 | |
|
3 | import curses, fcntl, signal, struct, tty, textwrap | |
|
3 | import curses, fcntl, signal, struct, tty, textwrap, inspect | |
|
4 | 4 | |
|
5 | 5 | import astyle, ipipe |
|
6 | 6 | |
@@ -13,119 +13,6 b' except NameError:' | |||
|
13 | 13 | set = sets.Set |
|
14 | 14 | |
|
15 | 15 | |
|
16 | _ibrowse_help = """ | |
|
17 | down | |
|
18 | Move the cursor to the next line. | |
|
19 | ||
|
20 | up | |
|
21 | Move the cursor to the previous line. | |
|
22 | ||
|
23 | pagedown | |
|
24 | Move the cursor down one page (minus overlap). | |
|
25 | ||
|
26 | pageup | |
|
27 | Move the cursor up one page (minus overlap). | |
|
28 | ||
|
29 | left | |
|
30 | Move the cursor left. | |
|
31 | ||
|
32 | right | |
|
33 | Move the cursor right. | |
|
34 | ||
|
35 | home | |
|
36 | Move the cursor to the first column. | |
|
37 | ||
|
38 | end | |
|
39 | Move the cursor to the last column. | |
|
40 | ||
|
41 | prevattr | |
|
42 | Move the cursor one attribute column to the left. | |
|
43 | ||
|
44 | nextattr | |
|
45 | Move the cursor one attribute column to the right. | |
|
46 | ||
|
47 | pick | |
|
48 | 'Pick' the object under the cursor (i.e. the row the cursor is on). This | |
|
49 | leaves the browser and returns the picked object to the caller. (In IPython | |
|
50 | this object will be available as the '_' variable.) | |
|
51 | ||
|
52 | pickattr | |
|
53 | 'Pick' the attribute under the cursor (i.e. the row/column the cursor is on). | |
|
54 | ||
|
55 | pickallattrs | |
|
56 | Pick' the complete column under the cursor (i.e. the attribute under the | |
|
57 | cursor) from all currently fetched objects. These attributes will be returned | |
|
58 | as a list. | |
|
59 | ||
|
60 | tooglemark | |
|
61 | Mark/unmark the object under the cursor. Marked objects have a '!' after the | |
|
62 | row number). | |
|
63 | ||
|
64 | pickmarked | |
|
65 | 'Pick' marked objects. Marked objects will be returned as a list. | |
|
66 | ||
|
67 | pickmarkedattr | |
|
68 | 'Pick' the attribute under the cursor from all marked objects (This returns a | |
|
69 | list). | |
|
70 | ||
|
71 | enterdefault | |
|
72 | Enter the object under the cursor. (what this mean depends on the object | |
|
73 | itself (i.e. how it implements the '__xiter__' method). This opens a new | |
|
74 | browser 'level'. | |
|
75 | ||
|
76 | enter | |
|
77 | Enter the object under the cursor. If the object provides different enter | |
|
78 | modes a menu of all modes will be presented; choose one and enter it (via the | |
|
79 | 'enter' or 'enterdefault' command). | |
|
80 | ||
|
81 | enterattr | |
|
82 | Enter the attribute under the cursor. | |
|
83 | ||
|
84 | leave | |
|
85 | Leave the current browser level and go back to the previous one. | |
|
86 | ||
|
87 | detail | |
|
88 | Show a detail view of the object under the cursor. This shows the name, type, | |
|
89 | doc string and value of the object attributes (and it might show more | |
|
90 | attributes than in the list view, depending on the object). | |
|
91 | ||
|
92 | detailattr | |
|
93 | Show a detail view of the attribute under the cursor. | |
|
94 | ||
|
95 | markrange | |
|
96 | Mark all objects from the last marked object before the current cursor | |
|
97 | position to the cursor position. | |
|
98 | ||
|
99 | sortattrasc | |
|
100 | Sort the objects (in ascending order) using the attribute under the cursor as | |
|
101 | the sort key. | |
|
102 | ||
|
103 | sortattrdesc | |
|
104 | Sort the objects (in descending order) using the attribute under the cursor as | |
|
105 | the sort key. | |
|
106 | ||
|
107 | hideattr | |
|
108 | Hide the attribute under the cursor. | |
|
109 | ||
|
110 | unhideattrs | |
|
111 | Make all attributes visible again. | |
|
112 | ||
|
113 | goto | |
|
114 | Jump to a row. The row number can be entered at the bottom of the screen. | |
|
115 | ||
|
116 | find | |
|
117 | Search forward for a row. At the bottom of the screen the condition can be | |
|
118 | entered. | |
|
119 | ||
|
120 | findbackwards | |
|
121 | Search backward for a row. At the bottom of the screen the condition can be | |
|
122 | entered. | |
|
123 | ||
|
124 | help | |
|
125 | This screen. | |
|
126 | """ | |
|
127 | ||
|
128 | ||
|
129 | 16 | class UnassignedKeyError(Exception): |
|
130 | 17 | """ |
|
131 | 18 | Exception that is used for reporting unassigned keys. |
@@ -213,13 +100,25 b' class _BrowserHelp(object):' | |||
|
213 | 100 | |
|
214 | 101 | fields = ("key", "description") |
|
215 | 102 | |
|
216 | for (i, command) in enumerate(_ibrowse_help.strip().split("\n\n")): | |
|
103 | commands = [] | |
|
104 | for name in dir(self.browser): | |
|
105 | if name.startswith("cmd_"): | |
|
106 | command = getattr(self.browser, name) | |
|
107 | commands.append((inspect.getsourcelines(command)[-1], name[4:], command)) | |
|
108 | commands.sort() | |
|
109 | commands = [(c[1], c[2]) for c in commands] | |
|
110 | for (i, (name, command)) in enumerate(commands): | |
|
217 | 111 | if i: |
|
218 | 112 | yield ipipe.Fields(fields, key="", description="") |
|
219 | 113 | |
|
220 |
|
|
|
114 | description = command.__doc__ | |
|
115 | if description is None: | |
|
116 | lines = [] | |
|
117 | else: | |
|
118 | lines = [l.strip() for l in description.splitlines() if l.strip()] | |
|
119 | description = "\n".join(lines) | |
|
120 | lines = textwrap.wrap(description, 60) | |
|
221 | 121 | keys = allkeys.get(name, []) |
|
222 | lines = textwrap.wrap(description, 60) | |
|
223 | 122 | |
|
224 | 123 | yield ipipe.Fields(fields, description=astyle.Text((self.style_header, name))) |
|
225 | 124 | for i in xrange(max(len(keys), len(lines))): |
@@ -1026,51 +925,74 b' class ibrowse(ipipe.Display):' | |||
|
1026 | 925 | # don't beep again (as long as the same key is pressed) |
|
1027 | 926 | self._dobeep = False |
|
1028 | 927 | |
|
1029 | def cmd_quit(self): | |
|
1030 | self.returnvalue = None | |
|
1031 | return True | |
|
1032 | ||
|
1033 | 928 | def cmd_up(self): |
|
929 | """ | |
|
930 | Move the cursor to the previous row. | |
|
931 | """ | |
|
1034 | 932 | level = self.levels[-1] |
|
1035 | 933 | self.report("up") |
|
1036 | 934 | level.moveto(level.curx, level.cury-self.stepy) |
|
1037 | 935 | |
|
1038 | 936 | def cmd_down(self): |
|
937 | """ | |
|
938 | Move the cursor to the next row. | |
|
939 | """ | |
|
1039 | 940 | level = self.levels[-1] |
|
1040 | 941 | self.report("down") |
|
1041 | 942 | level.moveto(level.curx, level.cury+self.stepy) |
|
1042 | 943 | |
|
1043 | 944 | def cmd_pageup(self): |
|
945 | """ | |
|
946 | Move the cursor up one page. | |
|
947 | """ | |
|
1044 | 948 | level = self.levels[-1] |
|
1045 | 949 | self.report("page up") |
|
1046 | 950 | level.moveto(level.curx, level.cury-level.mainsizey+self.pageoverlapy) |
|
1047 | 951 | |
|
1048 | 952 | def cmd_pagedown(self): |
|
953 | """ | |
|
954 | Move the cursor down one page. | |
|
955 | """ | |
|
1049 | 956 | level = self.levels[-1] |
|
1050 | 957 | self.report("page down") |
|
1051 | 958 | level.moveto(level.curx, level.cury+level.mainsizey-self.pageoverlapy) |
|
1052 | 959 | |
|
1053 | 960 | def cmd_left(self): |
|
961 | """ | |
|
962 | Move the cursor left. | |
|
963 | """ | |
|
1054 | 964 | level = self.levels[-1] |
|
1055 | 965 | self.report("left") |
|
1056 | 966 | level.moveto(level.curx-self.stepx, level.cury) |
|
1057 | 967 | |
|
1058 | 968 | def cmd_right(self): |
|
969 | """ | |
|
970 | Move the cursor right. | |
|
971 | """ | |
|
1059 | 972 | level = self.levels[-1] |
|
1060 | 973 | self.report("right") |
|
1061 | 974 | level.moveto(level.curx+self.stepx, level.cury) |
|
1062 | 975 | |
|
1063 | 976 | def cmd_home(self): |
|
977 | """ | |
|
978 | Move the cursor to the first column. | |
|
979 | """ | |
|
1064 | 980 | level = self.levels[-1] |
|
1065 | 981 | self.report("home") |
|
1066 | 982 | level.moveto(0, level.cury) |
|
1067 | 983 | |
|
1068 | 984 | def cmd_end(self): |
|
985 | """ | |
|
986 | Move the cursor to the last column. | |
|
987 | """ | |
|
1069 | 988 | level = self.levels[-1] |
|
1070 | 989 | self.report("end") |
|
1071 | 990 | level.moveto(level.datasizex+level.mainsizey-self.pageoverlapx, level.cury) |
|
1072 | 991 | |
|
1073 | 992 | def cmd_prevattr(self): |
|
993 | """ | |
|
994 | Move the cursor one attribute column to the left. | |
|
995 | """ | |
|
1074 | 996 | level = self.levels[-1] |
|
1075 | 997 | if level.displayattr[0] is None or level.displayattr[0] == 0: |
|
1076 | 998 | self.beep() |
@@ -1084,6 +1006,9 b' class ibrowse(ipipe.Display):' | |||
|
1084 | 1006 | level.moveto(pos, level.cury) |
|
1085 | 1007 | |
|
1086 | 1008 | def cmd_nextattr(self): |
|
1009 | """ | |
|
1010 | Move the cursor one attribute column to the right. | |
|
1011 | """ | |
|
1087 | 1012 | level = self.levels[-1] |
|
1088 | 1013 | if level.displayattr[0] is None or level.displayattr[0] == len(level.displayattrs)-1: |
|
1089 | 1014 | self.beep() |
@@ -1097,11 +1022,20 b' class ibrowse(ipipe.Display):' | |||
|
1097 | 1022 | level.moveto(pos, level.cury) |
|
1098 | 1023 | |
|
1099 | 1024 | def cmd_pick(self): |
|
1025 | """ | |
|
1026 | 'Pick' the object under the cursor (i.e. the row the cursor is on). | |
|
1027 | This leaves the browser and returns the picked object to the caller. | |
|
1028 | (In IPython this object will be available as the '_' variable.) | |
|
1029 | """ | |
|
1100 | 1030 | level = self.levels[-1] |
|
1101 | 1031 | self.returnvalue = level.items[level.cury].item |
|
1102 | 1032 | return True |
|
1103 | 1033 | |
|
1104 | 1034 | def cmd_pickattr(self): |
|
1035 | """ | |
|
1036 | 'Pick' the attribute under the cursor (i.e. the row/column the | |
|
1037 | cursor is on). | |
|
1038 | """ | |
|
1105 | 1039 | level = self.levels[-1] |
|
1106 | 1040 | attrname = level.displayattr[1] |
|
1107 | 1041 | if attrname is ipipe.noitem: |
@@ -1117,6 +1051,11 b' class ibrowse(ipipe.Display):' | |||
|
1117 | 1051 | return True |
|
1118 | 1052 | |
|
1119 | 1053 | def cmd_pickallattrs(self): |
|
1054 | """ | |
|
1055 | Pick' the complete column under the cursor (i.e. the attribute under | |
|
1056 | the cursor) from all currently fetched objects. These attributes | |
|
1057 | will be returned as a list. | |
|
1058 | """ | |
|
1120 | 1059 | level = self.levels[-1] |
|
1121 | 1060 | attrname = level.displayattr[1] |
|
1122 | 1061 | if attrname is ipipe.noitem: |
@@ -1132,11 +1071,19 b' class ibrowse(ipipe.Display):' | |||
|
1132 | 1071 | return True |
|
1133 | 1072 | |
|
1134 | 1073 | def cmd_pickmarked(self): |
|
1074 | """ | |
|
1075 | 'Pick' marked objects. Marked objects will be returned as a list. | |
|
1076 | """ | |
|
1135 | 1077 | level = self.levels[-1] |
|
1136 | 1078 | self.returnvalue = [cache.item for cache in level.items if cache.marked] |
|
1137 | 1079 | return True |
|
1138 | 1080 | |
|
1139 | 1081 | def cmd_pickmarkedattr(self): |
|
1082 | """ | |
|
1083 | 'Pick' the attribute under the cursor from all marked objects | |
|
1084 | (This returns a list). | |
|
1085 | """ | |
|
1086 | ||
|
1140 | 1087 | level = self.levels[-1] |
|
1141 | 1088 | attrname = level.displayattr[1] |
|
1142 | 1089 | if attrname is ipipe.noitem: |
@@ -1153,6 +1100,10 b' class ibrowse(ipipe.Display):' | |||
|
1153 | 1100 | return True |
|
1154 | 1101 | |
|
1155 | 1102 | def cmd_markrange(self): |
|
1103 | """ | |
|
1104 | Mark all objects from the last marked object before the current cursor | |
|
1105 | position to the cursor position. | |
|
1106 | """ | |
|
1156 | 1107 | level = self.levels[-1] |
|
1157 | 1108 | self.report("markrange") |
|
1158 | 1109 | start = None |
@@ -1172,6 +1123,11 b' class ibrowse(ipipe.Display):' | |||
|
1172 | 1123 | level.marked += 1 |
|
1173 | 1124 | |
|
1174 | 1125 | def cmd_enterdefault(self): |
|
1126 | """ | |
|
1127 | Enter the object under the cursor. (what this mean depends on the object | |
|
1128 | itself (i.e. how it implements the '__xiter__' method). This opens a new | |
|
1129 | browser 'level'. | |
|
1130 | """ | |
|
1175 | 1131 | level = self.levels[-1] |
|
1176 | 1132 | try: |
|
1177 | 1133 | item = level.items[level.cury].item |
@@ -1183,6 +1139,9 b' class ibrowse(ipipe.Display):' | |||
|
1183 | 1139 | self.enter(item, "default") |
|
1184 | 1140 | |
|
1185 | 1141 | def cmd_leave(self): |
|
1142 | """ | |
|
1143 | Leave the current browser level and go back to the previous one. | |
|
1144 | """ | |
|
1186 | 1145 | self.report("leave") |
|
1187 | 1146 | if len(self.levels) > 1: |
|
1188 | 1147 | self._calcheaderlines(len(self.levels)-1) |
@@ -1192,6 +1151,11 b' class ibrowse(ipipe.Display):' | |||
|
1192 | 1151 | curses.beep() |
|
1193 | 1152 | |
|
1194 | 1153 | def cmd_enter(self): |
|
1154 | """ | |
|
1155 | Enter the object under the cursor. If the object provides different | |
|
1156 | enter modes a menu of all modes will be presented; choose one and enter | |
|
1157 | it (via the 'enter' or 'enterdefault' command). | |
|
1158 | """ | |
|
1195 | 1159 | level = self.levels[-1] |
|
1196 | 1160 | try: |
|
1197 | 1161 | item = level.items[level.cury].item |
@@ -1203,6 +1167,9 b' class ibrowse(ipipe.Display):' | |||
|
1203 | 1167 | self.enter(item, None) |
|
1204 | 1168 | |
|
1205 | 1169 | def cmd_enterattr(self): |
|
1170 | """ | |
|
1171 | Enter the attribute under the cursor. | |
|
1172 | """ | |
|
1206 | 1173 | level = self.levels[-1] |
|
1207 | 1174 | attrname = level.displayattr[1] |
|
1208 | 1175 | if attrname is ipipe.noitem: |
@@ -1223,6 +1190,12 b' class ibrowse(ipipe.Display):' | |||
|
1223 | 1190 | self.enter(attr, None) |
|
1224 | 1191 | |
|
1225 | 1192 | def cmd_detail(self): |
|
1193 | """ | |
|
1194 | Show a detail view of the object under the cursor. This shows the | |
|
1195 | name, type, doc string and value of the object attributes (and it | |
|
1196 | might show more attributes than in the list view, depending on | |
|
1197 | the object). | |
|
1198 | """ | |
|
1226 | 1199 | level = self.levels[-1] |
|
1227 | 1200 | try: |
|
1228 | 1201 | item = level.items[level.cury].item |
@@ -1234,6 +1207,9 b' class ibrowse(ipipe.Display):' | |||
|
1234 | 1207 | self.enter(item, "detail") |
|
1235 | 1208 | |
|
1236 | 1209 | def cmd_detailattr(self): |
|
1210 | """ | |
|
1211 | Show a detail view of the attribute under the cursor. | |
|
1212 | """ | |
|
1237 | 1213 | level = self.levels[-1] |
|
1238 | 1214 | attrname = level.displayattr[1] |
|
1239 | 1215 | if attrname is ipipe.noitem: |
@@ -1254,6 +1230,10 b' class ibrowse(ipipe.Display):' | |||
|
1254 | 1230 | self.enter(attr, "detail") |
|
1255 | 1231 | |
|
1256 | 1232 | def cmd_tooglemark(self): |
|
1233 | """ | |
|
1234 | Mark/unmark the object under the cursor. Marked objects have a '!' | |
|
1235 | after the row number). | |
|
1236 | """ | |
|
1257 | 1237 | level = self.levels[-1] |
|
1258 | 1238 | self.report("toggle mark") |
|
1259 | 1239 | try: |
@@ -1269,6 +1249,10 b' class ibrowse(ipipe.Display):' | |||
|
1269 | 1249 | level.marked += 1 |
|
1270 | 1250 | |
|
1271 | 1251 | def cmd_sortattrasc(self): |
|
1252 | """ | |
|
1253 | Sort the objects (in ascending order) using the attribute under | |
|
1254 | the cursor as the sort key. | |
|
1255 | """ | |
|
1272 | 1256 | level = self.levels[-1] |
|
1273 | 1257 | attrname = level.displayattr[1] |
|
1274 | 1258 | if attrname is ipipe.noitem: |
@@ -1286,6 +1270,10 b' class ibrowse(ipipe.Display):' | |||
|
1286 | 1270 | level.sort(key) |
|
1287 | 1271 | |
|
1288 | 1272 | def cmd_sortattrdesc(self): |
|
1273 | """ | |
|
1274 | Sort the objects (in descending order) using the attribute under | |
|
1275 | the cursor as the sort key. | |
|
1276 | """ | |
|
1289 | 1277 | level = self.levels[-1] |
|
1290 | 1278 | attrname = level.displayattr[1] |
|
1291 | 1279 | if attrname is ipipe.noitem: |
@@ -1302,18 +1290,52 b' class ibrowse(ipipe.Display):' | |||
|
1302 | 1290 | return None |
|
1303 | 1291 | level.sort(key, reverse=True) |
|
1304 | 1292 | |
|
1293 | def cmd_hideattr(self): | |
|
1294 | """ | |
|
1295 | Hide the attribute under the cursor. | |
|
1296 | """ | |
|
1297 | level = self.levels[-1] | |
|
1298 | if level.displayattr[0] is None: | |
|
1299 | self.beep() | |
|
1300 | else: | |
|
1301 | self.report("hideattr") | |
|
1302 | level.hiddenattrs.add(level.displayattr[1]) | |
|
1303 | level.moveto(level.curx, level.cury, refresh=True) | |
|
1304 | ||
|
1305 | def cmd_unhideattrs(self): | |
|
1306 | """ | |
|
1307 | Make all attributes visible again. | |
|
1308 | """ | |
|
1309 | level = self.levels[-1] | |
|
1310 | self.report("unhideattrs") | |
|
1311 | level.hiddenattrs.clear() | |
|
1312 | level.moveto(level.curx, level.cury, refresh=True) | |
|
1313 | ||
|
1305 | 1314 | def cmd_goto(self): |
|
1315 | """ | |
|
1316 | Jump to a row. The row number can be entered at the | |
|
1317 | bottom of the screen. | |
|
1318 | """ | |
|
1306 | 1319 | self.startkeyboardinput("goto") |
|
1307 | 1320 | |
|
1308 | 1321 | def cmd_find(self): |
|
1322 | """ | |
|
1323 | Search forward for a row. The search condition can be entered at the | |
|
1324 | bottom of the screen. | |
|
1325 | """ | |
|
1309 | 1326 | self.startkeyboardinput("find") |
|
1310 | 1327 | |
|
1311 | 1328 | def cmd_findbackwards(self): |
|
1329 | """ | |
|
1330 | Search backward for a row. The search condition can be entered at the | |
|
1331 | bottom of the screen. | |
|
1332 | """ | |
|
1312 | 1333 | self.startkeyboardinput("findbackwards") |
|
1313 | 1334 | |
|
1314 | 1335 | def cmd_help(self): |
|
1315 | 1336 | """ |
|
1316 | The help command | |
|
1337 | Opens the help screen as a new browser level, describing keyboard | |
|
1338 | shortcuts. | |
|
1317 | 1339 | """ |
|
1318 | 1340 | for level in self.levels: |
|
1319 | 1341 | if isinstance(level.input, _BrowserHelp): |
@@ -1323,24 +1345,16 b' class ibrowse(ipipe.Display):' | |||
|
1323 | 1345 | |
|
1324 | 1346 | self.enter(_BrowserHelp(self), "default") |
|
1325 | 1347 | |
|
1348 | def cmd_quit(self): | |
|
1349 | """ | |
|
1350 | Quit the browser and return to the IPython prompt. | |
|
1351 | """ | |
|
1352 | self.returnvalue = None | |
|
1353 | return True | |
|
1354 | ||
|
1326 | 1355 | def sigwinchhandler(self, signal, frame): |
|
1327 | 1356 | self.resized = True |
|
1328 | 1357 | |
|
1329 | def cmd_hideattr(self): | |
|
1330 | level = self.levels[-1] | |
|
1331 | if level.displayattr[0] is None: | |
|
1332 | self.beep() | |
|
1333 | else: | |
|
1334 | self.report("hideattr") | |
|
1335 | level.hiddenattrs.add(level.displayattr[1]) | |
|
1336 | level.moveto(level.curx, level.cury, refresh=True) | |
|
1337 | ||
|
1338 | def cmd_unhideattrs(self): | |
|
1339 | level = self.levels[-1] | |
|
1340 | self.report("unhideattrs") | |
|
1341 | level.hiddenattrs.clear() | |
|
1342 | level.moveto(level.curx, level.cury, refresh=True) | |
|
1343 | ||
|
1344 | 1358 | def _dodisplay(self, scr): |
|
1345 | 1359 | """ |
|
1346 | 1360 | This method is the workhorse of the browser. It handles screen |
@@ -1,3 +1,8 b'' | |||
|
1 | 2006-06-23 Walter Doerwald <walter@livinglogic.de> | |
|
2 | ||
|
3 | * IPython/Extensions/ibrowse.py: Put the documentation of the keyboard | |
|
4 | commands into the methods implementing them. | |
|
5 | ||
|
1 | 6 | 2006-06-22 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 7 | |
|
3 | 8 | * ipython.el (ipython-indentation-hook): cleanup patch, submitted |
General Comments 0
You need to be logged in to leave comments.
Login now