Canvim    /
                    PyPen
                
                            | 1 | import sys  | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 2 | import re  | 
            ||
| 3 | import os  | 
            ||
| 4 | from pypen.settings import settings  | 
            ||
| 5 | |||
| 6 | |||
| 7 | def _check_if_executed_with_python():  | 
            ||
| 8 | if not sys.argv:  | 
            ||
| 9 | return  | 
            ||
| 10 | |||
| 11 | if sys.argv[0] == "-m":  | 
            ||
| 12 | return  | 
            ||
| 13 | |||
| 14 |     match = re.search("pypen", sys.argv[0]) | 
            ||
| 15 | if match:  | 
            ||
| 16 | return  | 
            ||
| 17 | |||
| 18 | print()  | 
            ||
| 19 |     print("It seems like you are trying to run a PyPen sketch using the python command.") | 
            ||
| 20 |     print("Try instead running it with 'pypen {}'!".format(" ".join(sys.argv))) | 
            ||
| 21 | print()  | 
            ||
| 22 |     print("Run 'pypen --help' for more information.") | 
            ||
| 23 | print()  | 
            ||
| 24 | settings._is_executing_with_python = True  | 
            ||
| 25 | |||
| 26 | |||
| 27 | _check_if_executed_with_python()  | 
            ||
| 28 | |||
| 29 | |||
| 30 | from pypen.utils import *  | 
            ||
| 31 | from pypen.drawing import *  | 
            ||
| 32 | from pypen.drawing import _COLORS  | 
            ||
| 33 | |||
| 34 | |||
| 35 | class _Mouse:  | 
            ||
| 36 | def __init__(self, x, y):  | 
            ||
| 37 | self.x = x  | 
            ||
| 38 | self.y = y  | 
            ||
| 39 | |||
| 40 | TIME = T = DELTA_TIME = DT = FRAME = F = FPS = 0  | 
            ||
| 41 | WIDTH = settings.width  | 
            ||
| 42 | HEIGHT = settings.height  | 
            ||
| 43 | |||
| 44 | MOUSE = _Mouse(0, 0)  | 
            ||
| 45 | |||
| 46 | def grid(spacing=1, start_x=0, start_y=0):  | 
            ||
| 47 | spacing = max(1, abs(spacing))  | 
            ||
| 48 | |||
| 49 | x = start_x  | 
            ||
| 50 | y = start_y  | 
            ||
| 51 | while y < settings.height:  | 
            ||
| 52 | yield x, y  | 
            ||
| 53 | |||
| 54 | x = (x + spacing)  | 
            ||
| 55 | |||
| 56 | if x >= settings.width:  | 
            ||
| 57 | x = start_x  | 
            ||
| 58 | y += spacing  | 
            ||
| 59 | |||
| 60 | |||
| 61 | def pixels():  | 
            ||
| 62 | return grid(1, 0, 0)  | 
            ||
| 63 | 
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.