├── requirements.txt ├── mkdocs.yml ├── docs ├── google19c382e962fb92a1.html ├── parts.png ├── mkdocs.yml └── index.md ├── _config.yml ├── geometry app-1.png ├── geometry app-2.png ├── CONTRIBUTING.md ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── LICENSE ├── README.md ├── scripts ├── main.py ├── refresh.py ├── global_variables.py ├── gui │ ├── __init__.py │ └── _tkinter_gui.py ├── highlighted_shapes.py ├── key_bindings.py ├── shapes │ ├── _line │ │ ├── _intersecting_lines.py │ │ ├── __init__.py │ │ └── _parallel_lines.py │ ├── __init__.py │ ├── _point │ │ ├── _collinear_points.py │ │ └── __init__.py │ └── _angles │ │ └── __init__.py ├── current_mode.py ├── diagram_viewer.py └── shape_panels.py └── CODE_OF_CONDUCT.md /requirements.txt: -------------------------------------------------------------------------------- 1 | tkscrolledframe -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Geometry app 2 | -------------------------------------------------------------------------------- /docs/google19c382e962fb92a1.html: -------------------------------------------------------------------------------- 1 | google-site-verification: google19c382e962fb92a1.html -------------------------------------------------------------------------------- /docs/parts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/HEAD/docs/parts.png -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: pages-themes/hacker@v0.2.0 2 | plugins: 3 | - jekyll-remote-theme 4 | -------------------------------------------------------------------------------- /geometry app-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/HEAD/geometry app-1.png -------------------------------------------------------------------------------- /geometry app-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/HEAD/geometry app-2.png -------------------------------------------------------------------------------- /docs/mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Geometry app 2 | docs/ 3 | index.md 4 | parts.png 5 | google19c382e962fb92a1.html 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | I am glad to hear that you are willing to contribute. To contribute to time-widget: 2 | - Fork this repository. 3 | - Create a new branch from dev branch if required. 4 | - Make necessary changes and open a pull request to dev branch. 5 | 6 | Thank you. 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug, help wanted 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Version [e.g. 22] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 B.Jothin kumar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Geometry app](https://jothin-kumar.github.io/Geometry-app/) - [B. Jothin kumar](https://jothin-kumar.github.io/) 2 | 3 | A GUI application to "draw and get answers!", Currently in beta stage. 4 | ## Preview: 5 | ![Screenshot of geometry app](https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/master/geometry%20app-1.png) 6 | ![Screenshot of geometry app](https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/master/geometry%20app-2.png) 7 | 8 | ## To run geometry app: 9 | ### Linux: 10 | ``` 11 | git clone https://github.com/Jothin-kumar/Geometry-app.git 12 | cd "Geometry-app" 13 | pip install -r requirements.txt 14 | cd scripts 15 | python3 main.py 16 | ``` 17 | ### Windows: 18 | Note: Make sure that you have python3 installed. 19 | ``` 20 | git clone https://github.com/Jothin-kumar/Geometry-app.git 21 | cd "Geometry-app" 22 | pip install -r requirements.txt 23 | cd scripts 24 | python main.py 25 | ``` 26 | **[Read the documentation to know how to use this app!](http://geometry-app.rtfd.io/)** 27 | 28 | ## My other interesting projects: 29 | - https://github.com/Jothin-kumar/lines-of-code/ 30 | - https://github.com/Jothin-kumar/time-widget/ 31 | -------------------------------------------------------------------------------- /scripts/main.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin-kumar.github.io/) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import diagram_viewer 30 | import gui 31 | import key_bindings 32 | 33 | gui.trigger() 34 | diagram_viewer.trigger() 35 | key_bindings.trigger() 36 | gui.mainloop() 37 | -------------------------------------------------------------------------------- /scripts/refresh.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | from shape_panels import refresh_all as refresh_all_panels 30 | from shapes import refresh_all as refresh_all_shapes 31 | 32 | 33 | def refresh_all(): 34 | refresh_all_shapes() 35 | refresh_all_panels() 36 | -------------------------------------------------------------------------------- /scripts/global_variables.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | dictionary = {} 30 | 31 | 32 | def set_value(key: str, value): 33 | dictionary[key] = value 34 | 35 | 36 | def get_value(key: str): 37 | try: 38 | return dictionary[key] 39 | except KeyError: 40 | return [] 41 | -------------------------------------------------------------------------------- /scripts/gui/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | from ._tkinter_gui import (LinePropertyPane, PointPropertyPane, ShapePane, 30 | bind_key, create_line, create_text, delete, 31 | mainloop, on_diagram_editor_enter, 32 | on_diagram_editor_leave, on_diagram_viewer_click, 33 | refresh_diagram_editor, set_current_mode, trigger) 34 | -------------------------------------------------------------------------------- /scripts/highlighted_shapes.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import global_variables 30 | 31 | 32 | def unhighlight_all_points(): 33 | for point in global_variables.get_value('points'): 34 | point.unhighlight() 35 | 36 | 37 | def unhighlight_all_lines(): 38 | for line in global_variables.get_value('lines'): 39 | line.unhighlight() 40 | 41 | 42 | def unhighlight_all(): 43 | unhighlight_all_points() 44 | unhighlight_all_lines() 45 | -------------------------------------------------------------------------------- /scripts/key_bindings.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import gui 30 | from current_mode import switch_to_point_edit, switch_to_line_edit, switch_to_angle_mode, switch_to_collinear_points_mode, switch_to_parallel_lines_mode 31 | 32 | 33 | def trigger(): 34 | gui.bind_key('p', switch_to_point_edit) 35 | gui.bind_key('l', switch_to_line_edit) 36 | gui.bind_key('a', switch_to_angle_mode) 37 | gui.bind_key('c', switch_to_collinear_points_mode) 38 | gui.bind_key('r', switch_to_parallel_lines_mode) 39 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | Geometry app is a simple GUI application to solve geometrical problems. Currently, it is in beta version, and many more features are yet to come. 3 | # Download 4 | Geometry app is available to download for: 5 | - [Linux](https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/master/Downloads/geometry_1.0.0-1_all.deb) 6 | - [Windows](https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/master/Downloads/geometry-app.exe) 7 | or, you can run the python source code directly if you have python installed: 8 | - [zip](https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/master/Downloads/source%20code.zip) 9 | - [tar.xz for linux and mac](https://raw.githubusercontent.com/Jothin-kumar/Geometry-app/master/Downloads/source%20code.tar.xz) 10 | **[Contribute to Geometry app](https://github.com/Jothin-kumar/Geometry-app/blob/master/CONTRIBUTING.md)** 11 | # User guide 12 | ## Layout 13 | ![Geometry app parts](parts.png) 14 | ## Shapes 15 | Currently, the following shapes are supported: 16 | - Point 17 | - Line 18 | - Angle (autodetect) 19 | - Collinear point (autodetect) 20 | - Parallel lines (autodetect) 21 | **and many more shapes are yet to come!** 22 | ### Point: 23 | This is the default mode of this app. Just click a point on the diagram editor to create a point. Points are named automatically! You can rename if you want by clicking rename in the property pane. To switch between points, just click them on the list in left or on the diagram editor. You can switch to point mode by clicking point on the left side. 24 | **Pro tip: press 'p' to switch to this mode.** 25 | ### Line 26 | To draw a line, switch to line mode first by clicking line on the left side. Click on a point to start a line and click on other point to finish it. The second point would be the starting point of your next line. You can stop this by clicking somewhere on the diagram editor where a point doesn't exist. 27 | **Pro tip: press 'l' to switch to this mode** 28 | ### Angle 29 | Angles are automatically detected! You can only view them in this mode. To view, just switch to this mode by clicking Angles on the left. Then, you can select an angle name from the left to highlight it. 30 | **Pro tip: press 'a' to switch to this mode** 31 | ### Collinear points 32 | Collinear points are automatically detected! Just click collinear points and select a collinear points list. It will be highlighted! 33 | **Pro tip: press 'c' to switch to this mode** 34 | ### Parallel lines 35 | Parallel lines are automatically detected! Just click parallel lines and select a list. It will be highlighted! 36 | **Pro tip: press 'r' to switch to this mode*** 37 | -------------------------------------------------------------------------------- /scripts/shapes/_line/_intersecting_lines.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | 31 | # Import global_variables module 32 | sys.path.append('../../') 33 | import global_variables 34 | 35 | 36 | def refresh_intersecting_lines(create_text_command, delete_line): 37 | global_variables.set_value('intersecting_lines_and_intersection_point', {}) 38 | horizontal_lines = [] 39 | vertical_lines = [] 40 | for line in global_variables.get_value('lines'): 41 | if line.point1.y == line.point2.y: 42 | horizontal_lines.append(line) 43 | elif line.point1.x == line.point2.x: 44 | vertical_lines.append(line) 45 | for horizontal_line in horizontal_lines: 46 | for vertical_line in vertical_lines: 47 | global_variables.get_value('intersecting_lines_and_intersection_point')[(vertical_line.point1.x, 48 | horizontal_line.point1.y)] = { 49 | 'horizontal line': horizontal_line, 'vertical line': vertical_line 50 | } 51 | try: 52 | global_variables.get_value('point')(vertical_line.point1.x, horizontal_line.point1.y, 53 | create_text_command, delete_line) 54 | except ValueError: 55 | pass 56 | -------------------------------------------------------------------------------- /scripts/current_mode.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import global_variables 30 | import gui 31 | import highlighted_shapes 32 | 33 | current_shape = 'point' # point is the default shape 34 | point_modify_mode = False 35 | 36 | 37 | def set_point_modify_mode(): 38 | global point_modify_mode 39 | point_modify_mode = True 40 | 41 | 42 | def get_current_shape(): 43 | return current_shape 44 | 45 | 46 | def on_mode_switch(): 47 | global_variables.set_value('previous_click_point', None) 48 | highlighted_shapes.unhighlight_all() 49 | 50 | 51 | def switch_to_point_edit(): # Switch to point edit. 52 | global current_shape 53 | current_shape = 'point' 54 | gui.set_current_mode('Point') 55 | on_mode_switch() 56 | 57 | 58 | def switch_to_line_edit(): # Switch to Line edit. 59 | global current_shape 60 | current_shape = 'line' 61 | gui.set_current_mode('Line') 62 | on_mode_switch() 63 | 64 | 65 | def switch_to_angle_mode(): 66 | global current_shape 67 | current_shape = 'angle' 68 | gui.set_current_mode('Angle') 69 | on_mode_switch() 70 | 71 | 72 | def switch_to_collinear_points_mode(): 73 | global current_shape 74 | current_shape = 'collinear point' 75 | gui.set_current_mode('Collinear points') 76 | on_mode_switch() 77 | 78 | 79 | def switch_to_parallel_lines_mode(): 80 | global current_shape 81 | current_shape = 'parallel line' 82 | gui.set_current_mode('Parallel lines') 83 | on_mode_switch() 84 | -------------------------------------------------------------------------------- /scripts/shapes/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | 31 | from ._angles import Angle, angle, get_angle_by_name, refresh_angles 32 | from ._line import (Line, delete_line, get_line_by_name, line, 33 | refresh_intersecting_lines, refresh_line, 34 | refresh_parallel_lines) 35 | from ._point import (Point, delete_point, get_point_by_coordinates, 36 | get_point_by_name, point, refresh_collinear_points) 37 | 38 | # Import global_variables module 39 | sys.path.append('../') 40 | import global_variables 41 | 42 | 43 | def refresh_all(): 44 | for line_ in global_variables.get_value('lines'): 45 | line_.refresh() 46 | for point_ in global_variables.get_value('points'): 47 | point_.refresh() 48 | refresh_collinear_points() 49 | refresh_parallel_lines() 50 | refresh_intersecting_lines(create_text_command=global_variables.get_value('create_text_command'), 51 | delete_line=global_variables.get_value('delete_line')) 52 | refresh_angles() 53 | 54 | 55 | global_variables.set_value('Point', Point) 56 | global_variables.set_value('point', point) 57 | global_variables.set_value('delete_point', delete_point) 58 | global_variables.set_value('Line', Line) 59 | global_variables.set_value('line', line) 60 | global_variables.set_value('delete_line', delete_line) 61 | global_variables.set_value('refresh_line', refresh_line) 62 | global_variables.set_value('Angle', Angle) 63 | global_variables.set_value('angle', angle) 64 | global_variables.set_value('refresh_angles', refresh_angles) 65 | global_variables.set_value('points', []) 66 | global_variables.set_value('lines', []) 67 | global_variables.set_value('angles', []) 68 | -------------------------------------------------------------------------------- /scripts/shapes/_point/_collinear_points.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | 31 | # Import global_variables module 32 | sys.path.append('../../') 33 | import global_variables 34 | 35 | 36 | def refresh_collinear_points(): 37 | global_variables.set_value('collinear_points_list', []) 38 | collinear_points_dict_x = {} 39 | collinear_points_dict_y = {} 40 | collinear_points_dict_slant_plus = {} 41 | collinear_points_dict_slant_minus = {} 42 | for point in global_variables.get_value('points'): 43 | try: 44 | collinear_points_dict_x[point.x].append(point) 45 | except KeyError: 46 | collinear_points_dict_x[point.x] = [point] 47 | try: 48 | collinear_points_dict_y[point.y].append(point) 49 | except KeyError: 50 | collinear_points_dict_y[point.y] = [point] 51 | try: 52 | collinear_points_dict_slant_plus[point.x + point.y].append(point) 53 | except KeyError: 54 | collinear_points_dict_slant_plus[point.x + point.y] = [point] 55 | try: 56 | collinear_points_dict_slant_minus[point.x - point.y].append(point) 57 | except KeyError: 58 | collinear_points_dict_slant_minus[point.x - point.y] = [point] 59 | for collinear_points in collinear_points_dict_x.values(): 60 | if len(collinear_points) >= 3: 61 | global_variables.get_value('collinear_points_list').append(collinear_points) 62 | for collinear_points in collinear_points_dict_y.values(): 63 | if len(collinear_points) >= 3: 64 | global_variables.get_value('collinear_points_list').append(collinear_points) 65 | for collinear_points in collinear_points_dict_slant_plus.values(): 66 | if len(collinear_points) >= 3: 67 | global_variables.get_value('collinear_points_list').append(collinear_points) 68 | for collinear_points in collinear_points_dict_slant_minus.values(): 69 | if len(collinear_points) >= 3: 70 | global_variables.get_value('collinear_points_list').append(collinear_points) 71 | -------------------------------------------------------------------------------- /scripts/shapes/_angles/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | 31 | # Import global_variables module 32 | sys.path.append('../../') 33 | import global_variables 34 | 35 | 36 | class Angle: 37 | def __init__(self, line1: global_variables.get_value('Line'), line2: global_variables.get_value('Line')): 38 | for angle_ in global_variables.get_value('angles'): 39 | if angle_.lines in ([line1, line2], [line2, line1]): 40 | raise ValueError('Angle already exists') 41 | self.lines = [line1, line2] 42 | self.vertex = None 43 | for point1 in line1.points: 44 | for point2 in line2.points: 45 | if point1 == point2: 46 | self.vertex = point1 47 | self.points = [] 48 | for line in self.lines: 49 | for point in line.points: 50 | if point not in self.points and point != self.vertex: 51 | self.points.append(point) 52 | self.name = f'{self.points[0].name}{self.vertex.name}{self.points[1].name}' 53 | 54 | def highlight(self): 55 | for angle_ in global_variables.get_value('angles'): 56 | angle_.unhighlight() 57 | for line_ in global_variables.get_value('lines'): 58 | line_.unhighlight() 59 | for line in self.lines: 60 | line.highlight(unhighlighted_others=True) 61 | 62 | def unhighlight(self): 63 | for line in global_variables.get_value('lines'): 64 | line.unhighlight() 65 | 66 | 67 | def angle(line1: global_variables.get_value('Line'), line2: global_variables.get_value('Line')): 68 | angle_ = Angle(line1, line2) 69 | global_variables.get_value('angles').append(angle_) 70 | return angle_ 71 | 72 | 73 | def refresh_angles(): 74 | global_variables.set_value('angles', []) 75 | for line1 in global_variables.get_value('lines'): 76 | for line2 in global_variables.get_value('lines'): 77 | if not line1 == line2: 78 | if line1.point1 == line2.point1 or line1.point1 == line2.point2 or line1.point2 == line2.point1 or line1.point2 == line2.point2: 79 | try: 80 | angle(line1, line2) 81 | except ValueError: 82 | pass 83 | 84 | 85 | def get_angle_by_name(name: str): 86 | for angle_ in global_variables.get_value('angles'): 87 | if angle_.name == name: 88 | return angle_ 89 | -------------------------------------------------------------------------------- /scripts/shapes/_line/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | 31 | from ._intersecting_lines import refresh_intersecting_lines 32 | from ._parallel_lines import refresh_parallel_lines 33 | 34 | # Import global_variables module 35 | sys.path.append('../../') 36 | import global_variables 37 | 38 | 39 | class Line: 40 | def __init__(self, point1: global_variables.get_value('Point'), point2: global_variables.get_value('Point'), 41 | create_line_command, delete_command, show: bool = True): 42 | self.point1 = point1 43 | self.point2 = point2 44 | if self.point1 == self.point2: 45 | raise ValueError('A line must have two different points.') 46 | for line_ in global_variables.get_value('lines'): 47 | if (line_.point1 == point1 and line_.point2 == point2) or ( 48 | line_.point2 == point1 and line_.point1 == point2): 49 | raise ValueError('Line already exists.') 50 | self.points = [point1, point2] 51 | self.name = point1.name + point2.name 52 | self.create_line_command = create_line_command 53 | if show: 54 | self.line = create_line_command(point1.x, point1.y, point2.x, point2.y) 55 | self.displayed = show 56 | self.delete_command = delete_command 57 | 58 | def hide(self): 59 | self.delete_command(self.line) 60 | self.displayed = False 61 | 62 | def show(self): 63 | if not self.displayed: 64 | self.line = self.create_line_command(self.point1.x, self.point1.y, self.point2.x, self.point2.y) 65 | self.displayed = False 66 | 67 | def refresh(self): 68 | self.hide() 69 | self.show() 70 | 71 | def highlight(self, unhighlighted_others=False): 72 | if not unhighlighted_others: 73 | for angle_ in global_variables.get_value('angles'): 74 | angle_.unhighlight() 75 | for line_ in global_variables.get_value('lines'): 76 | line_.unhighlight() 77 | self.hide() 78 | self.line = self.create_line_command(self.point1.x, self.point1.y, self.point2.x, self.point2.y, fill='red') 79 | self.displayed = True 80 | 81 | def unhighlight(self): 82 | self.hide() 83 | if self.point1 and self.point2: 84 | self.show() 85 | 86 | 87 | def line(point1: global_variables.get_value('Point'), point2: global_variables.get_value('Point'), create_line_command, 88 | delete_command, show: bool = True): 89 | line_ = Line(point1, point2, create_line_command, delete_command, show) 90 | global_variables.get_value('lines').append(line_) 91 | global_variables.get_value('refresh_angles')() 92 | return line_ 93 | 94 | 95 | def delete_line(line_: Line): 96 | line_.point1 = None 97 | line_.point2 = None 98 | line_.hide() 99 | del global_variables.get_value('lines')[global_variables.get_value('lines').index(line_)] 100 | global_variables.refresh_angles() 101 | 102 | 103 | def refresh_line(line_: Line): 104 | line_.refresh() 105 | 106 | 107 | def get_line_by_name(name: str): 108 | for line_ in global_variables.get_value('lines'): 109 | if line_.name == name: 110 | return line_ 111 | -------------------------------------------------------------------------------- /scripts/diagram_viewer.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import global_variables 30 | import gui 31 | import shapes 32 | from current_mode import get_current_shape, set_point_modify_mode 33 | from shape_panels import refresh_all as refresh_all_panels 34 | 35 | previous_point_property = None 36 | previous_highlighted_point = None 37 | 38 | 39 | def on_diagram_editor_click(event): # When user clicks on the diagram editor. 40 | x = (int(event.x / 50) * 50) + 25 41 | y = (int(event.y / 50) * 50) + 25 42 | current_shape = get_current_shape() 43 | if current_shape == 'point': # If current shape is Point, Just create a new point where clicked. 44 | global previous_point_property 45 | global previous_highlighted_point 46 | import current_mode 47 | if current_mode.point_modify_mode: 48 | previous_highlighted_point.set_coordinates(x, y) 49 | current_mode.point_modify_mode = False 50 | for line in global_variables.get_value('lines'): 51 | if line.point1.x == previous_highlighted_point.x and line.point1.y == previous_highlighted_point.y: 52 | line.point1 = shapes.get_point_by_coordinates(x, y) 53 | elif line.point2.x == previous_highlighted_point.x and line.point2.y == previous_highlighted_point.y: 54 | line.point2 = shapes.get_point_by_coordinates(x, y) 55 | global_variables.get_value('refresh_line')(line) 56 | else: 57 | try: # Try to create a Point. 58 | shapes.point(x, y, gui.create_text, gui.delete) # Create a point. 59 | except ValueError: # In case it already exists, do nothing. 60 | pass 61 | if previous_highlighted_point: # If previous highlighted point is not None. 62 | previous_highlighted_point.unhighlight() # Un-Highlight. 63 | if previous_point_property: # If previous point property is not None. 64 | previous_point_property.delete() # Delete it. 65 | point = shapes.get_point_by_coordinates(x, y) # Get point object from it's coordinates. 66 | if point: 67 | point.highlight() # Highlight the point. 68 | previous_point_property = gui.PointPropertyPane(point, shapes.refresh_all, point_modify_command=set_point_modify_mode) 69 | # When called next time, this is previous. 70 | previous_highlighted_point = point # When called next time, this point is the previously highlighted one. 71 | elif current_shape == 'line': # If current shape is line, Draw line from previous clicked coordinate to here. 72 | current_click_point = shapes.get_point_by_coordinates(x, y) 73 | if global_variables.get_value('previous_click_point') and current_click_point: 74 | # If the Point 'previous_click_point' and 'current_click_point' exists. 75 | try: # Try to create a line. 76 | shapes.line(global_variables.get_value('previous_click_point'), current_click_point, gui.create_line, 77 | gui.delete) # Create a line. 78 | except ValueError: # In case it already exists, do nothing. 79 | pass 80 | global_variables.set_value('previous_click_point', current_click_point) 81 | shapes.refresh_all() 82 | refresh_all_panels() 83 | 84 | 85 | def trigger(): 86 | gui.on_diagram_viewer_click(on_diagram_editor_click) 87 | -------------------------------------------------------------------------------- /scripts/shapes/_line/_parallel_lines.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | 31 | # Import global_variables module 32 | sys.path.append('../../') 33 | import global_variables 34 | 35 | 36 | def refresh_parallel_lines(): 37 | global_variables.set_value('parallel_lines_list', []) 38 | parallel_lines_dicts_x = [] 39 | parallel_lines_dicts_y = [] 40 | parallel_lines_dicts_plus = [] 41 | parallel_lines_dicts_minus = [] 42 | for line in global_variables.get_value('lines'): 43 | if line.point1.x == line.point2.x: 44 | line_grouped = False 45 | for parallel_line_dict in parallel_lines_dicts_x: 46 | if line.point1.x not in parallel_line_dict['reserved x']: 47 | parallel_line_dict['lines'].append(line) 48 | parallel_line_dict['reserved x'].append(line.point1.x) 49 | line_grouped = True 50 | if not line_grouped: 51 | parallel_lines_dicts_x.append({'lines': [line], 'reserved x': [line.point1.x]}) 52 | elif line.point1.y == line.point2.y: 53 | line_grouped = False 54 | for parallel_line_dict in parallel_lines_dicts_y: 55 | if line.point1.y not in parallel_line_dict['reserved y']: 56 | parallel_line_dict['lines'].append(line) 57 | parallel_line_dict['reserved y'].append(line.point1.y) 58 | line_grouped = True 59 | if not line_grouped: 60 | parallel_lines_dicts_y.append({'lines': [line], 'reserved y': [line.point1.y]}) 61 | elif (line.point1.x + line.point1.y) == (line.point2.x + line.point2.y): 62 | line_grouped = False 63 | for parallel_line_dict in parallel_lines_dicts_plus: 64 | if not (line.point1.x + line.point1.y) in parallel_line_dict['reserved x y sum']: 65 | parallel_line_dict['lines'].append(line) 66 | parallel_line_dict['reserved x y sum'].append(line.point1.x + line.point1.y) 67 | line_grouped = True 68 | if not line_grouped: 69 | parallel_lines_dicts_plus.append( 70 | {'lines': [line], 'reserved x y sum': [line.point1.x + line.point1.y]}) 71 | elif (line.point1.x - line.point1.y) == (line.point2.x - line.point2.y): 72 | line_grouped = False 73 | for parallel_line_dict in parallel_lines_dicts_minus: 74 | if not (line.point1.x - line.point1.y) in parallel_line_dict['reserved x y difference']: 75 | parallel_line_dict['lines'].append(line) 76 | parallel_line_dict['reserved x y difference'].append(line.point1.x - line.point1.y) 77 | line_grouped = True 78 | if not line_grouped: 79 | parallel_lines_dicts_minus.append( 80 | {'lines': [line], 'reserved x y difference': [line.point1.x - line.point1.y]}) 81 | for parallel_line_dict_x in parallel_lines_dicts_x: 82 | global_variables.get_value('parallel_lines_list').append(parallel_line_dict_x['lines']) 83 | for parallel_line_dict_y in parallel_lines_dicts_y: 84 | global_variables.get_value('parallel_lines_list').append(parallel_line_dict_y['lines']) 85 | for parallel_lines_dict_plus in parallel_lines_dicts_plus: 86 | global_variables.get_value('parallel_lines_list').append(parallel_lines_dict_plus['lines']) 87 | for parallel_lines_dict_minus in parallel_lines_dicts_minus: 88 | global_variables.get_value('parallel_lines_list').append(parallel_lines_dict_minus['lines']) 89 | -------------------------------------------------------------------------------- /scripts/shapes/_point/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | from itertools import cycle 31 | 32 | from ._collinear_points import refresh_collinear_points 33 | 34 | # Import global_variables module 35 | sys.path.append('../../') 36 | import global_variables 37 | 38 | variable_letters = iter(cycle(['A', 'B', 'C', 'X', 'Y', 'Z'])) 39 | 40 | variable_num = 1 41 | 42 | 43 | def get_variable_letter(): 44 | global variable_num 45 | current_variable_letter = next(variable_letters) 46 | if current_variable_letter == 'Z': 47 | variable_num += 1 48 | return current_variable_letter + str(variable_num) 49 | 50 | 51 | class Point: 52 | def __init__(self, x: int, y: int, create_text_command, delete_command, show: bool = True): 53 | self.x = x 54 | self.y = y 55 | for point_ in global_variables.get_value('points'): 56 | if point_.x == self.x and point_.y == self.y: 57 | raise ValueError('Point already exists.') 58 | self.name = get_variable_letter() 59 | self.coordinates = (self.x, self.y) 60 | self.create_text_command = create_text_command 61 | if show: 62 | self.text = self.create_text_command(self.x, self.y, text=self.name) 63 | self.displayed = show 64 | self.delete_command = delete_command 65 | self.blink = False 66 | 67 | def hide(self): 68 | if self.displayed: 69 | self.delete_command(self.text) 70 | self.displayed = False 71 | 72 | def show(self): 73 | if not self.displayed: 74 | self.text = self.create_text_command(self.x, self.y, text=self.name) 75 | self.displayed = True 76 | 77 | def set_coordinates(self, x: int, y: int): 78 | self.x = x 79 | self.y = y 80 | self.hide() 81 | self.show() 82 | 83 | def rename(self, new_name: str, refresh_command): 84 | if not new_name == self.name: 85 | for point_ in global_variables.get_value('points'): 86 | if point_.name == new_name: 87 | raise ValueError( 88 | f'A variable with the name {new_name} already exists. Please choose a different variable.' 89 | ) 90 | self.name = new_name 91 | self.hide() 92 | self.show() 93 | for line_ in global_variables.get_value('lines'): 94 | global_variables.get_value('refresh_line')(line_) 95 | refresh_command() 96 | 97 | def highlight(self): 98 | self.hide() 99 | self.text = self.create_text_command(self.x, self.y, text=self.name, fill='red') 100 | self.displayed = True 101 | 102 | def unhighlight(self): 103 | 104 | self.hide() 105 | if self.x and self.y: 106 | self.show() 107 | 108 | def refresh(self): 109 | self.hide() 110 | self.show() 111 | 112 | 113 | def point(x: int, y: int, create_text_command, delete_command, show_point: bool = True): 114 | point_ = Point(x, y, create_text_command, delete_command, show_point) 115 | global_variables.get_value('points').append(point_) 116 | return point_ 117 | 118 | 119 | def delete_point(point_: Point): 120 | point_.x = None 121 | point_.y = None 122 | point_.hide() 123 | del global_variables.get_value('points')[global_variables.get_value('points').index(point_)] 124 | 125 | 126 | def get_point_by_coordinates(x: int, y: int): 127 | for point_ in global_variables.get_value('points'): 128 | if point_.x == x and point_.y == y: 129 | return point_ 130 | 131 | 132 | def get_point_by_name(name: str): 133 | for point_ in global_variables.get_value('points'): 134 | if point_.name == name: 135 | return point_ 136 | 137 | 138 | global_variables.set_value('point', point) 139 | global_variables.set_value('Point', Point) 140 | global_variables.set_value('delete_point', delete_point) 141 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | [@Jothin-kumar](https://github.com/Jothin-kumar). 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /scripts/shape_panels.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import current_mode 30 | import global_variables 31 | import gui 32 | import shapes 33 | from highlighted_shapes import unhighlight_all_lines, unhighlight_all_points 34 | from shapes import refresh_all as _refresh_all 35 | 36 | points_pane = gui.ShapePane(shape_name='Points', 37 | switch_to_this_shape_command=current_mode.switch_to_point_edit) # The points panel. 38 | lines_pane = gui.ShapePane(shape_name='Lines', 39 | switch_to_this_shape_command=current_mode.switch_to_line_edit) # The lines panel. 40 | angle_pane = gui.ShapePane(shape_name='Angles', switch_to_this_shape_command=current_mode.switch_to_angle_mode) 41 | collinear_points_pane = gui.ShapePane('Collinear points', 42 | switch_to_this_shape_command=current_mode.switch_to_collinear_points_mode) 43 | parallel_lines_pane = gui.ShapePane('Parallel lines', 44 | switch_to_this_shape_command=current_mode.switch_to_parallel_lines_mode) 45 | 46 | 47 | def refresh_points_panel(): # Command to refresh points. 48 | points_pane.set_texts(global_variables.get_value('points')) 49 | 50 | 51 | def refresh_lines_panel(): # Command to refresh lines. 52 | lines_pane.set_texts(global_variables.get_value('lines')) 53 | 54 | 55 | def refresh_angles_panel(): 56 | shapes.refresh_angles() 57 | angle_pane.set_texts(global_variables.get_value('angles')) 58 | 59 | 60 | def refresh_collinear_points_panel(): 61 | shapes.refresh_collinear_points() 62 | append_list = [] 63 | for points in global_variables.get_value('collinear_points_list'): 64 | append_value = '' 65 | for point in points: 66 | append_value += point.name 67 | append_value += ' ' 68 | append_list.append(append_value) 69 | collinear_points_pane.set_texts(append_list) 70 | 71 | 72 | def refresh_parallel_lines_panel(): 73 | shapes.refresh_parallel_lines() 74 | append_list = [] 75 | for lines in global_variables.get_value('parallel_lines_list'): 76 | append_value = '' 77 | for line in lines: 78 | append_value += line.name 79 | append_value += ' ' 80 | if len(lines) > 1: 81 | append_list.append(append_value) 82 | parallel_lines_pane.set_texts(append_list) 83 | 84 | 85 | previous_point_property = None 86 | previous_line_property = None 87 | 88 | 89 | def on_point_pane_element_switch(string: str): 90 | global previous_point_property 91 | unhighlight_all_points() 92 | if previous_point_property: # If previous point property is not None. 93 | previous_point_property.delete() # Delete it. 94 | point = shapes.get_point_by_name(string) # Get point object from it's name. 95 | if point: 96 | point.highlight() # Highlight the point. 97 | previous_point_property = gui.PointPropertyPane(point, _refresh_all, 98 | point_modify_command=current_mode.set_point_modify_mode) 99 | # When called next time, this is previous. 100 | 101 | 102 | def on_collinear_points_pane_element_switch(string: str): 103 | unhighlight_all_points() 104 | points = [] 105 | for point_name in string.split(): 106 | points.append(shapes.get_point_by_name(point_name)) 107 | for point in points: 108 | point.highlight() 109 | 110 | 111 | def on_line_pane_element_switch(string: str): 112 | global previous_line_property 113 | unhighlight_all_lines() 114 | if previous_line_property: # If previous line property is not None. 115 | previous_line_property.delete() # Delete it. 116 | line = shapes.get_line_by_name(string) # Get line object from it's name. 117 | if line: 118 | line.highlight() # highlight the line. 119 | previous_line_property = gui.LinePropertyPane(line, _refresh_all) 120 | 121 | 122 | def on_parallel_line_pane_element_switch(string: str): 123 | unhighlight_all_lines() 124 | lines = [] 125 | for line_name in string.split(): 126 | lines.append(shapes.get_line_by_name(line_name)) 127 | for line in lines: 128 | line.highlight(unhighlighted_others=True) 129 | 130 | 131 | def on_angle_pane_element_switch(string: str): 132 | unhighlight_all_lines() 133 | angle = shapes.get_angle_by_name(string) 134 | if angle: 135 | angle.highlight() 136 | 137 | 138 | points_pane.on_listbox_element_switch(current_mode.get_current_shape, on_point_pane_element_switch) 139 | lines_pane.on_listbox_element_switch(current_mode.get_current_shape, on_line_pane_element_switch) 140 | angle_pane.on_listbox_element_switch(current_mode.get_current_shape, on_angle_pane_element_switch) 141 | collinear_points_pane.on_listbox_element_switch(current_mode.get_current_shape, 142 | on_collinear_points_pane_element_switch) 143 | parallel_lines_pane.on_listbox_element_switch(current_mode.get_current_shape, on_parallel_line_pane_element_switch) 144 | 145 | 146 | def refresh_all(): 147 | refresh_points_panel() 148 | refresh_lines_panel() 149 | refresh_angles_panel() 150 | refresh_collinear_points_panel() 151 | refresh_parallel_lines_panel() 152 | 153 | 154 | global_variables.set_value('refresh_all_panels', 'refresh_all') 155 | -------------------------------------------------------------------------------- /scripts/gui/_tkinter_gui.py: -------------------------------------------------------------------------------- 1 | """ 2 | View this repository on github: https://github.com/Jothin-kumar/Geometry-app 3 | 4 | MIT License 5 | 6 | Copyright (c) 2021 B.Jothin kumar 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | Author: Jothin kumar (https://jothin.tech) 27 | Github repository of this project: https://github.com/Jothin-kumar/Geometry-app 28 | """ 29 | import sys 30 | from tkinter import * 31 | from tkinter.messagebox import showerror 32 | from tkinter.simpledialog import askstring 33 | 34 | from tkscrolledframe import ScrolledFrame 35 | 36 | # Import global_variables module 37 | # sys.path.append('../../') 38 | import global_variables 39 | 40 | root = Tk() 41 | root.wm_title('Geometry app') 42 | mainframe = Frame(master=root) 43 | menu_bar = Frame(master=mainframe) 44 | 45 | 46 | def show_all_points(): 47 | for point in global_variables.get_value('points'): 48 | point.show() 49 | 50 | 51 | def hide_all_points(): 52 | for point in global_variables.get_value('points'): 53 | point.hide() 54 | 55 | 56 | variable_view = IntVar() 57 | variable_view.set(1) 58 | 59 | 60 | def variable_view_button_command(): 61 | if variable_view.get(): 62 | show_all_points() 63 | else: 64 | hide_all_points() 65 | 66 | 67 | variable_view_button = Checkbutton(master=menu_bar, text='Show variable names', variable=variable_view, 68 | command=variable_view_button_command) 69 | variable_view_button.pack(side=TOP, anchor=W, expand=False) 70 | menu_bar.pack(side=TOP, anchor=W, fill=Y) 71 | current_mode_label = Label(master=menu_bar, text='Point') 72 | current_mode_label.pack(side=TOP, anchor=W) 73 | 74 | 75 | def set_current_mode(new_mode: str): 76 | current_mode_label['text'] = new_mode 77 | 78 | 79 | split_frame = PanedWindow(master=mainframe) 80 | shape_pane_master = ScrolledFrame(master=split_frame) 81 | shape_pane = shape_pane_master.display_widget(Frame) 82 | 83 | 84 | class ShapePane: 85 | def __init__(self, shape_name: str, switch_to_this_shape_command): 86 | self.mainframe = Frame(master=shape_pane) 87 | self.shape_name = shape_name.lower().replace('s', '') 88 | self.button = Button(master=self.mainframe, text=shape_name, command=switch_to_this_shape_command) 89 | self.button.pack(side=TOP, fill=X) 90 | self.listbox = Listbox(master=self.mainframe) 91 | self.listbox.pack(side=LEFT, fill=Y) 92 | self.scrollbar = Scrollbar(master=self.mainframe) 93 | self.scrollbar.pack(side=RIGHT, fill=Y) 94 | self.listbox.config(yscrollcommand=self.scrollbar.set) 95 | self.scrollbar.config(command=self.listbox.yview) 96 | self.mainframe.pack(side=TOP, expand=False, anchor=W) 97 | self.switch_to_this_shape_command = switch_to_this_shape_command 98 | 99 | def empty(self): 100 | self.listbox.delete(0, END) 101 | 102 | def append(self, string: str): 103 | self.listbox.insert(END, string) 104 | 105 | def set_texts(self, shapes: list): 106 | self.empty() 107 | for shape in shapes: 108 | try: 109 | self.append(shape.name) 110 | except AttributeError: 111 | self.append(shape) 112 | 113 | def on_listbox_element_switch(self, get_current_shape, command): 114 | def get_element(event): 115 | curselection = event.widget.curselection() 116 | if curselection: 117 | curselection = int(curselection[0]) 118 | else: 119 | curselection = 0 120 | if get_current_shape() == self.shape_name: 121 | command(event.widget.get(curselection)) 122 | 123 | def select_command(event): 124 | if not variable_view.get(): 125 | variable_view.set(1) 126 | show_all_points() 127 | get_element(event) 128 | 129 | self.listbox.bind('<>', select_command) 130 | 131 | 132 | split_frame.add(shape_pane_master) 133 | 134 | diagram_editor_frame = Frame(split_frame) 135 | diagram_editor = Canvas( 136 | master=diagram_editor_frame, 137 | bg='white', 138 | width=1450, 139 | height=950, 140 | ) 141 | 142 | 143 | def refresh_diagram_editor(): 144 | diagram_editor.delete('all') 145 | for point in global_variables.get_value('points'): 146 | point.displayed = False 147 | point.show() 148 | for line in global_variables.get_value('lines'): 149 | line.displayed = FALSE 150 | line.show() 151 | for x in range(0, 29): 152 | for y in range(0, 19): 153 | diagram_editor.create_rectangle(x * 50, y * 50, 50 + (x * 50), 50 + (y * 50), outline='lightgreen') 154 | 155 | 156 | refresh_diagram_editor() 157 | diagram_editor.pack(expand=True, fill=BOTH) 158 | create_line = diagram_editor.create_line 159 | create_text = diagram_editor.create_text 160 | delete = diagram_editor.delete 161 | 162 | 163 | def on_diagram_editor_enter(command): 164 | diagram_editor.bind('', command) 165 | 166 | 167 | def on_diagram_editor_leave(command): 168 | diagram_editor.bind('', command) 169 | 170 | 171 | def on_diagram_viewer_click(command): 172 | diagram_editor.bind('', command) 173 | 174 | 175 | split_frame.add(diagram_editor_frame) 176 | 177 | 178 | def get_variable_name_from_user(): 179 | return askstring(title='Rename variable', prompt='Please enter a variable name', parent=root) 180 | 181 | 182 | property_panel = Frame(master=split_frame) 183 | 184 | 185 | class PointPropertyPane: 186 | def __init__(self, point: global_variables.get_value('Point'), refresh_command, point_modify_command): 187 | self.mainframe = Frame(master=property_panel) 188 | name_label = Label(master=self.mainframe, text=f'Point: {point.name}') 189 | name_label.pack() 190 | 191 | def rename(): 192 | user_variable = get_variable_name_from_user() 193 | if str(user_variable).replace(' ', '') and user_variable: 194 | try: 195 | point.rename(str(user_variable), refresh_command) 196 | name_label['text'] = f'Point: {point.name}' 197 | global_variables.get_value('refresh_all_panels')() 198 | except ValueError as error_message: 199 | showerror('Error while renaming', error_message) 200 | 201 | rename_button = Button(master=self.mainframe, text='Rename point', bg='snow', fg='black', command=rename) 202 | rename_button.pack() 203 | 204 | def delete_point_(): 205 | global_variables.get_value('delete_point')(point) 206 | refresh_command() 207 | self.delete() 208 | 209 | change_point_location_button = Button(master=self.mainframe, text="change point location", 210 | command=point_modify_command) 211 | change_point_location_button.pack() 212 | delete_button = Button(master=self.mainframe, text='Delete point', bg='red', fg='snow', command=delete_point_) 213 | delete_button.pack() 214 | self.mainframe.pack(side=TOP, anchor=E, expand=False) 215 | 216 | def delete(self): 217 | self.mainframe.pack_forget() 218 | 219 | 220 | class LinePropertyPane: 221 | def __init__(self, line: global_variables.get_value('Line'), refresh_command): 222 | self.mainframe = Frame(master=property_panel) 223 | name_label = Label(master=self.mainframe, text=f'Line: {line.name}') 224 | name_label.pack() 225 | 226 | def delete_line_(): 227 | global_variables.get_value('delete_line')(line) 228 | refresh_command() 229 | self.delete() 230 | 231 | delete_button = Button(master=self.mainframe, text='Delete line', fg='snow', bg='red', command=delete_line_) 232 | delete_button.pack() 233 | self.mainframe.pack(side=TOP, anchor=E, expand=False) 234 | 235 | def delete(self): 236 | self.mainframe.pack_forget() 237 | 238 | 239 | split_frame.add(property_panel) 240 | split_frame.pack(fill=Y) 241 | on_key_press_dict = {} 242 | 243 | 244 | def bind_key(char: str, command): 245 | on_key_press_dict[char] = command 246 | 247 | 248 | def on_key_press(event): 249 | try: 250 | on_key_press_dict[event.char]() 251 | except KeyError: 252 | pass 253 | 254 | 255 | root.bind('', on_key_press) 256 | root.focus_set() 257 | mainframe.pack(fill=BOTH) 258 | mainloop = root.mainloop 259 | 260 | 261 | def trigger(): 262 | global_variables.set_value('create_text_command', create_text) 263 | global_variables.set_value('create_line_command', create_line) 264 | --------------------------------------------------------------------------------