Changes for user to use Up, Down, Enter key without ctrl

31 views
Skip to first unread message

sgwong

unread,
Dec 11, 2011, 11:28:55 AM12/11/11
to DreamPie
I am used to the Ipython way on how it works. So, I find it very hard
to type Ctrl + .... I just made some changes to the dreampie code so
that I can work like the existing Ipython way. (all the ctrl + still
work the same way but user can use Up, Down and Enter key like
Ipython)

There are some difference for Ipython due to Dreampie support for
multiline editor(which implement nicely).

For single line, user can press 'Up/Down' anywhere in the line to call
history up/down. When calling code from history, it will place cursor
at the end of line (which will be differrent for multi line code)
For execute code, user can press 'Enter' at any where of the line,
except the case when there is a space in front of the cursor which it
will enter a new line instead of execute code.

For multiline code, it will be a bit tricky...
For history searching, user can press 'Up/Down' to call history up/
down, but when calling the code from history, it will place cursor at
the start of the line, so that user can continue searching code from
history. When user has multiline code in the editor area, user have to
place the cursor at first line and start of the code in order to use
the 'Down' key. For 'Up' key, can be anywhere as long as the cursor is
in the first line.
when user call existing multi-line code from history, if user want to
go to next line, user must move the cursor to next character on first
line(or any where but not start of line for first line) in order to
use the 'Up/Down' key to move cursor to differrent line.
For execute code, user can press 'Enter' at last line and beginning of
the last line.

Here is my changes (the line number is not accurate due to other
changes in dreampie):

--- C:/Users/swong24/Development/dreampie/dreampie-1.1.1/dreampielib/
gui/__init__.py Mon Nov 7 16:17:52 2011

+++ C:/Users/swong24/Development/dreampie/dreampie-1.1.1 - updategtk/
dreampielib/gui/__init__.py Sun Dec 11 23:33:31 2011


@@ -453,6 +450,35 @@


self.subp.write(s)

+ @sourceview_keyhandler('Up', 0)
+ def on_sourceview_up(self):
+ sb = self.sourcebuffer
+ insert_iter = sb.get_iter_at_mark(sb.get_insert())
+ if insert_iter.get_line() == 0:
+ self.history.history_up()
+ return True
+ else:
+ return False
+
+ @sourceview_keyhandler('Down', 0)
+ def on_sourceview_down(self):
+ sb = self.sourcebuffer
+ insert_iter = sb.get_iter_at_mark(sb.get_insert())
+ if insert_iter.get_line() == 0:
+ if sb.get_line_count() == 1:
+ self.history.history_down()
+ return True
+ else:
+ if insert_iter.get_offset() == 0:
+ self.history.history_down()
+ return True
+ else:
+ return False
+ else:
+ return False
+
@sourceview_keyhandler('Return', 0)
def on_sourceview_return(self):
sb = self.sourcebuffer
@@ -462,21 +488,28 @@

# with normal behavior)
# * If we are executing, send the line as stdin.
insert_iter = sb.get_iter_at_mark(sb.get_insert())
- if (insert_iter.equal(sb.get_end_iter())
- and insert_iter.get_line() == 0
- and insert_iter.get_offset() != 0
- and not self.sb_get_text(sb.get_start_iter(),
- insert_iter).endswith(' ')):
+ if ((insert_iter.get_line() == 0
+ and not self.sb_get_text(sb.get_start_iter(),
insert_iter).endswith(' ')
+ ) or insert_iter.get_line_offset() == 0):

if not self.is_executing:
source = self.sb_get_text(sb.get_start_iter(),
sb.get_end_iter())
source = source.rstrip()
source = self.replace_gtk_quotes(source)
- is_incomplete = self.call_subp(u'is_incomplete',
source)
- if not is_incomplete:
+ if (insert_iter.get_line_offset() == 0
+ and sb.get_line_count() > 1
+ and insert_iter.get_line() == sb.get_line_count()
- 1
+ and
insert_iter.get_text(sb.get_end_iter()).strip() == ''):
self.execute_source()
return True
+ else:
+ is_incomplete = self.call_subp(u'is_incomplete',
source)
+ #print 'is_incomplete', is_incomplete
+ if not is_incomplete:
+ self.execute_source()
+ return True
else:
# is_executing
self.send_stdin()

Reply all
Reply to author
Forward
0 new messages