# Some useful building blocks Apps can be composed of a wide variety of building blocks that you can use in your functions, including a small number of functions that get automatically called for you as appropriate. ## Variables you can read * `App.screen` * `width` and `height` -- integer dimensions for the app window in pixels. * `flags` -- some properties of the app window. See [`flags` in `love.graphics.getMode`](https://love2d.org/wiki/love.window.getMode) for details. * `Version` -- the running version of LÖVE as a string, e.g. '11.4'. * `Major_version` -- just the part before the period as an int, e.g. 11. ## Functions that get automatically called * `App.initialize_globals()` -- called before running each test and also before the app starts up. As the name suggests, use this to initialize all your global variables to something consistent. I also find it useful to be able to see all my global variables in one place, and avoid defining top-level variables anywhere else (unless they're constants and never going to be modified). * `App.initialize(arg)` -- called when app starts up after `App.initialize_globals`. Provides in `arg` an array of words typed in if you ran it from a terminal window. (Based on [LÖVE](https://love2d.org/wiki/love.load).) * `App.quit()` -- called before the app shuts down. (Based on [LÖVE](https://love2d.org/wiki/love.quit).) * `App.focus(start?)` -- called when the app starts or stops receiving keypresses. `start?` will be `true` when app starts receiving keypresses and `false` when keypresses move to another window. (Based on [LÖVE](https://love2d.org/wiki/love.focus).) * `App.resize(w,h)` -- called when you resize the app window. Provides new window dimensions in `w` and `h`. Don't bother updating `App.screen.width` and `App.screen.height`, that will happen automatically before calling `App.resize`. (Based on [LÖVE](https://love2d.org/wiki/love.resize)) * `App.filedropped(file)` -- called when a file icon is dragged and dropped on the app window. Provides in `file` an object representing the file that was dropped, that will respond to the following messages: * `file:getFilename()` returning a string name * `file:read()` returning the entire file contents in a single string (Based on [LÖVE](https://love2d.org/wiki/love.filedropped).) * `App.draw()` -- called to draw on the window, around 30 times a second. (Based on [LÖVE](https://love2d.org/wiki/love.draw).) * `App.update(dt)` -- called after every call to `App.draw`. Make changes to your app's variables here rather than in `App.draw`. Provides in `dt` the time since the previous call to `App.update`, which can be useful for things like smooth animations. (Based on [LÖVE](https://love2d.org/wiki/love.update).) * `App.mousepressed(x,y, mouse_button)` -- called when you press down on a mouse button. Provides in `x` and `y` the point on the screen at which the click occurred, and in `mouse_button` an integer id of the mouse button pressed. `1` is the primary mouse button (the left button on a right-handed mouse), `2` is the secondary button (the right button on a right-handed mouse), and `3` is the middle button. Further buttons are mouse-dependent. (Based on [LÖVE](https://love2d.org/wiki/love.mousepressed).) * `App.mousereleased(x,y, mouse_button)` -- called when you release a mouse button. Provides the same arguments as `App.mousepressed()` above. (Based on [LÖVE](https://love2d.org/wiki/love.mousereleased).) * `App.mousemoved(x,y, dx,dy, is_touch)` -- called any time the mouse moves. (Based on [LÖVE](https://love2d.org/wiki/love.mousemoved).) * `App.wheelmoved(dx,dy)` -- called when you use the scroll wheel on a mouse that has it. Provides in `dx` and `dy` an indication of how fast the wheel is being scrolled. Positive values for `dx` indicate movement to the right. Positive values for `dy` indicate upward movement. (Based on [LÖVE](https://love2d.org/wiki/love.wheelmoved).) * `App.mousefocus(in_focus)` -- called when the mouse pointer moves on or off the app window. (Based on [LÖVE](https://love2d.org/wiki/love.mousefocus).) * `App.keychord_press(chord, key)` -- called when you press a key-combination. Provides in `key` a string name for the key most recently pressed ([valid values](https://love2d.org/wiki/KeyConstant)). Provides in `chord` a string representation of the current key combination, consisting of the key with the following prefixes: * `C-` if one of the `ctrl` keys is pressed, * `M-` if one of the `alt` keys is pressed, * `S-` if one of the `shift` keys is pressed, and * `s-` if the `windows`/`cmd`/`super` key is pressed. * `App.textinput(t)` -- called when you press a key combination that yields (roughly) a printable character. For example, `shift` and `a` pressed together will call `App.textinput` with `A`. (Based on [LÖVE](https://love2d.org/wiki/love.textinput).) * `App.keyreleased(key)` -- called when you press a key on the keyboard. Provides in `key` a string name for the key ([valid values](https://love2d.org/wiki/KeyConstant)). (Based on [LÖVE](https://love2d.org/wiki/love.keyreleased), including other variants.) ## Functions you can call Everything in the [LÖVE](https://love2d.org/wiki/Main_Page) and [Lua](https://www.lua.org/manual/5.1/manual.html) guides is available to you, but here's a brief summary of the most useful primitives. Some primitives have new, preferred names under the `App`
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.applications</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</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>.applications</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/work/ranger/ranger/applications.py">/home/hut/work/ranger/ranger/applications.py</a></font></td></tr></table>
<p></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="os.html">os</a><br>
</td><td width="25%" valign=top><a href