Advertisement
Guest User

Untitled

a guest
Apr 12th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. [
  2. TODO
  3. write code for these:
  4. Tkinter
  5. Verify that all code samples render at the same coordinates - double-check 0-indexed vs 1-indexed and x-y order
  6. Verify that all code samples work in 2.7 and 3.X, or that dual versions exist
  7. ]
  8.  
  9. Q: How do I draw text anywhere I want on the console?
  10.  
  11. You can draw text anywhere on the screen by positioning the cursor and then using `print` or `sys.stdout.write` as normal. How this can be done, varies on the OS you're using, and possibly on how you're trying to position the cursor.
  12.  
  13. === `curses` (Linux & Mac) ===
  14.  
  15. The built-in `curses` module has a method specifically for moving the cursor. Unfortunately, this module is not available on Windows.
  16.  
  17. [TODO - insert `curses` code here]
  18.  
  19. === ANSI escape sequences (Linux & Mac) ===
  20.  
  21. Some consoles will interpret certain sequences of characters as a signal to change the properties of the console. One such property is the cursor's position. Unfortunately, The Windows command prompt is not one of those consoles.
  22.  
  23. [TODO - insert ANSI escape sequences code here]
  24.  
  25. === The win32 API (Windows) ===
  26.  
  27. You can directly access the Windows handle of the console and call `SetConsoleCursorPosition` on it. If you have [pywin 32](https://sourceforge.net/projects/pywin32/) [installed](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32), most of the heavy lifting is done for you:
  28.  
  29. [TODO - insert pywin demo code here]
  30.  
  31. But if you refuse to use a third-party library, you can use `ctypes` to interface with `windll` directly:
  32.  
  33. [TODO - insert ctypes demo code here]
  34.  
  35. === Third Party Libraries (any OS) ===
  36.  
  37. [`colorama`](https://pypi.python.org/pypi/colorama) implements ANSI escape sequences for Windows:
  38.  
  39. [TODO - insert colorama demo code here]
  40.  
  41. And [`unicurses`](https://sourceforge.net/projects/pyunicurses/) implements `curses` for Windows*.
  42.  
  43. [TODO - insert unicurses demo code here]
  44.  
  45. These may be preferable if you want your code to execute on any OS, without having to write any OS-specific code yourself.
  46.  
  47. === Escape Sequences `"\r"` or `"\b"` (any OS, limited functionality) ===
  48.  
  49. This is the easiest approach of the bunch, but it can only move the cursor farther left on the line it is already on - you can't move up!
  50.  
  51. `"\r"`, the carriage return escape sequence, moves the cursor to the leftmost column.
  52.  
  53. [TODO - insert carriage return code here]
  54.  
  55. `"\b"` moves the cursor one space to the left.
  56.  
  57. [TODO - insert backspace code here]
  58.  
  59. This is primarily useful for creating countdown timers or loading bars.
  60.  
  61. [TODO - countdown timer / loading bar demo]
  62.  
  63. === Writing Your Own GUI ===
  64.  
  65. [TODO - write this section]
  66.  
  67. [TODO - figure out if markup engine has a footnote feature]
  68.  
  69. *requires [pdcurses.dll](https://sourceforge.net/projects/pdcurses/files/pdcurses/) in the current working directory.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement