|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.widgets.taskview</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.gui.html"><font color="#ffffff">gui</font></a>.<a href="ranger.gui.widgets.html"><font color="#ffffff">widgets</font></a>.taskview</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/gui/widgets/taskview.py">/home/hut/ranger/ranger/gui/widgets/taskview.py</a></font></td></tr></table>
<p><tt>The <a href="#TaskView">TaskView</a> allows you to modify what the loader is doing.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="curses.html">curses</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - edit/002-typing.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.muRecipe { color: #ff8700; }
.muData { color: #ffff00; }
.Special { color: #c00000; }
.muScenario { color: #00af00; }
.Delimiter { color: #800080; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.SalientComment { color: #00ffff; }
.muControl { color: #c0a020; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="SalientComment">## handling events from the keyboard, mouse, touch screen, ...</span>
<span class="Comment"># temporary main: interactive editor</span>
<span class="Comment"># hit ctrl-c to exit</span>
<span class="muRecipe">def!</span> main text:text [
<span class="Constant">local-scope</span>
<span class="Constant">load-ingredients</span>
open-console
editor:&:editor<span class="Special"> <- </span>new-editor text, <span class="Constant">0/screen</span>, <span class="Constant">5/left</span>, <span class="Constant">45/right</span>
editor-event-loop <span class="Constant">0/screen</span>, <span class="Constant">0/console</span>, editor
close-console
]
<span class="muRecipe">def</span> editor-event-loop screen:&:screen, console:&:console, editor:&:editor<span class="muRecipe"> -> </span>screen:&:screen, console:&:console, editor:&:editor [
<span class="Constant">local-scope</span>
<span class="Constant">load-ingredients</span>
<span class="Delimiter">{</span>
<span class="Comment"># looping over each (keyboard or touch) event as it occurs</span>
<span class="Constant"> +next-event</span>
cursor-row:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-row:offset</span>
cursor-column:num<span class="Special"> <- </span>get *editor, <span class="Constant">cursor-column:offset</span>
screen<span class="Special"> <- </span>move-cursor screen, cursor-row, cursor-column
e:event, console:&:console, found?:bool, quit?:bool<span class="Special"> <- </span>read-event console
<span class="muControl">loop-unless</span> found?
<span class="muControl">break-if</span> quit? <span class="Comment"># only in tests</span>
trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span>
<span class="Comment"># 'touch' event</span>
t:touch-event, is-touch?:bool<span class="Special"> <- </span>maybe-convert e, <span class="Constant">touch:variant</span>
<span class="Delimiter">{</span>
<span class="muControl">break-unless</span> is-touch?
move-cursor-in-editor screen, editor, t
<span class="muControl">loop</span> <span class="Constant">+next-event:label</span>
<span class="Delimiter">}</span>
<span class="Comment"># keyboard events</span>
<span class="Delimiter">{</span>
<span class="muControl">break-if</span> is-touch?
screen, editor, go-render?:bool<span class="Special"> <- </span>handle-keyboard-event screen, editor, e
<span class="Delimiter">{</span>
<span class="muControl">break-unless</span> go-render?
screen<span class="Special"> <- </span>editor-render screen, editor
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="muControl">loop</span>
<span class="Delimiter">}</span>
]
<span class="Comment"># process click, return if it was on current editor</span>
<span class="muRecipe">def</span> move-cursor-in-editor screen:&:screen, editor:&:editor, t:touch-event<span class="muRecipe"> -> </span>in-focus?:bool, editor:&:editor [
<span class="Constant">local-scope</span>
<span class="Constant">load-ingredients</span>
<span class="muControl">return-unless</span> editor, <span class="Constant">0/false</span>
click-row:num<span class="Special"> <- </span>get t, <span class="Constant">row:offset</span>
<span class="muControl">return-unless</span> click-row, <span class="Constant">0/false</span> <span class="Comment"># ignore clicks on 'menu'</span>
click-column:num<span class="Special"> <- </span>get t, <span class="Constant">column:offset</span>
left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
too-far-left?:bool<span class="Special"> <- </span>lesser-than click-column, left
<span class="muControl">return-if</span> too-far-left?, <span class="Constant">0/false</span>
right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
too-far-right?:bool<span class="Special"> <- </span>greater-than click-column, right
<span class="muControl">return-if</span> too-far-right?, <span class="Constant">0/false</span>
<span class="Comment"># position cursor</span>
<span class="Constant"> <move-cursor-begin></span>
editor<span class="Special"> <- </span>snap-cursor screen, editor, click-row, click-column
undo-coalesce-tag:num<span class="Special"> <- </span>copy <span class="Constant">0/never</span>
<span class="Constant"> <move-cursor-end></span>
<span class="Comment"># gain focus</span>
<span class="muControl">return</span> <span class="Constant">1/true</span>
]
<span class="Comment"># Variant of 'render' that only moves the cursor (coordinates and</span>
<span class="Comment"># before-cursor). If it's past the end of a line, it 'slides' it left. If it's</span>
<span class="Comment"># past the last line it positions at end of last line.</span>
<span class="muRecipe">def</span> snap-cursor screen:&:screen, editor:&:editor, target-row:num, target-column:num<span class="muRecipe"> -> </span>editor:&:editor [
<span class="Constant">local-scope</span>
<span class="Constant">load-ingredients</span>
<span class="muControl">return-unless</span> editor
left:num<span class="Special"> <- </span>get *editor, <span class="Constant">left:offset</span>
right:num<span class="Special"> <- </span>get *editor, <span class="Constant">right:offset</span>
screen-height:num<span class="Special"> <- </span>screen-height screen
<span class="Comment"># count newlines until screen row</span>
curr:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">top-of-screen:offset</span>
prev:&:duplex-list:char<span class="Special"> <- </span>copy curr <span class="Comment"># just in case curr becomes null and we can't compute prev</span>
curr<span class="Special"> <- </span>next curr
row:num<span class="Special"> <- </span>copy <span class="Constant">1/top</span>
column:num<span class="Special"> <- </span>copy left
*editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-row:offset</span>, target-row
cursor-row:num<span class="Special"> <- </span>copy target-row
*editor<span class="Special"> <- </span>put *editor, <span class="Constant">cursor-column:offset</span>, target-column
cursor-column:num<span class="Special"> <- </span>copy target-column
before-cursor:&:duplex-list:char<span class="Special"> <- </span>get *editor, <span class="Constant">before-cursor:offset</span>
<span class="Delimiter">{</span>
<span class="Constant"> +next-character</span>
<span class="muControl">break-unless</span> curr
off-screen?:bool<span class="Special"> <- </span>greater-or-equal row, screen-height
<span class="muControl">break-if</span> off-screen?
<span class="Comment"># update editor.before-cursor</span>
<span class="Comment"># Doing so at the start of each iteration ensures it stays one step behind</span>
<span class="Comment"># the current character.</span>
<span class="Delimiter">{</span>
at-cursor-row?:bool<span class="Special"> <- </span
|