├── .gitignore ├── LICENSE ├── README.md ├── img ├── main_window.png └── settings.png └── load.py /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/python,visualstudio 3 | 4 | ### Python ### 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | env/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *,cover 51 | .hypothesis/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # dotenv 87 | .env 88 | 89 | # virtualenv 90 | .venv 91 | venv/ 92 | ENV/ 93 | 94 | # Spyder project settings 95 | .spyderproject 96 | .spyproject 97 | 98 | # Rope project settings 99 | .ropeproject 100 | 101 | # mkdocs documentation 102 | /site 103 | 104 | ### VisualStudio ### 105 | ## Ignore Visual Studio temporary files, build results, and 106 | ## files generated by popular Visual Studio add-ons. 107 | ## 108 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 109 | 110 | # User-specific files 111 | *.suo 112 | *.user 113 | *.userosscache 114 | *.sln.docstates 115 | 116 | # User-specific files (MonoDevelop/Xamarin Studio) 117 | *.userprefs 118 | 119 | # Build results 120 | [Dd]ebug/ 121 | [Dd]ebugPublic/ 122 | [Rr]elease/ 123 | [Rr]eleases/ 124 | x64/ 125 | x86/ 126 | bld/ 127 | [Bb]in/ 128 | [Oo]bj/ 129 | [Ll]og/ 130 | 131 | # Visual Studio 2015 cache/options directory 132 | .vs/ 133 | # Uncomment if you have tasks that create the project's static files in wwwroot 134 | #wwwroot/ 135 | 136 | # MSTest test Results 137 | [Tt]est[Rr]esult*/ 138 | [Bb]uild[Ll]og.* 139 | 140 | # NUNIT 141 | *.VisualState.xml 142 | TestResult.xml 143 | 144 | # Build Results of an ATL Project 145 | [Dd]ebugPS/ 146 | [Rr]eleasePS/ 147 | dlldata.c 148 | 149 | # .NET Core 150 | project.lock.json 151 | project.fragment.lock.json 152 | artifacts/ 153 | **/Properties/launchSettings.json 154 | 155 | *_i.c 156 | *_p.c 157 | *_i.h 158 | *.ilk 159 | *.meta 160 | *.obj 161 | *.pch 162 | *.pdb 163 | *.pgc 164 | *.pgd 165 | *.rsp 166 | *.sbr 167 | *.tlb 168 | *.tli 169 | *.tlh 170 | *.tmp 171 | *.tmp_proj 172 | *.vspscc 173 | *.vssscc 174 | .builds 175 | *.pidb 176 | *.svclog 177 | *.scc 178 | 179 | # Chutzpah Test files 180 | _Chutzpah* 181 | 182 | # Visual C++ cache files 183 | ipch/ 184 | *.aps 185 | *.ncb 186 | *.opendb 187 | *.opensdf 188 | *.sdf 189 | *.cachefile 190 | *.VC.db 191 | *.VC.VC.opendb 192 | 193 | # Visual Studio profiler 194 | *.psess 195 | *.vsp 196 | *.vspx 197 | *.sap 198 | 199 | # TFS 2012 Local Workspace 200 | $tf/ 201 | 202 | # Guidance Automation Toolkit 203 | *.gpState 204 | 205 | # ReSharper is a .NET coding add-in 206 | _ReSharper*/ 207 | *.[Rr]e[Ss]harper 208 | *.DotSettings.user 209 | 210 | # JustCode is a .NET coding add-in 211 | .JustCode 212 | 213 | # TeamCity is a build add-in 214 | _TeamCity* 215 | 216 | # DotCover is a Code Coverage Tool 217 | *.dotCover 218 | 219 | # Visual Studio code coverage results 220 | *.coverage 221 | *.coveragexml 222 | 223 | # NCrunch 224 | _NCrunch_* 225 | .*crunch*.local.xml 226 | nCrunchTemp_* 227 | 228 | # MightyMoose 229 | *.mm.* 230 | AutoTest.Net/ 231 | 232 | # Web workbench (sass) 233 | .sass-cache/ 234 | 235 | # Installshield output folder 236 | [Ee]xpress/ 237 | 238 | # DocProject is a documentation generator add-in 239 | DocProject/buildhelp/ 240 | DocProject/Help/*.HxT 241 | DocProject/Help/*.HxC 242 | DocProject/Help/*.hhc 243 | DocProject/Help/*.hhk 244 | DocProject/Help/*.hhp 245 | DocProject/Help/Html2 246 | DocProject/Help/html 247 | 248 | # Click-Once directory 249 | publish/ 250 | 251 | # Publish Web Output 252 | *.[Pp]ublish.xml 253 | *.azurePubxml 254 | # TODO: Uncomment the next line to ignore your web deploy settings. 255 | # By default, sensitive information, such as encrypted password 256 | # should be stored in the .pubxml.user file. 257 | #*.pubxml 258 | *.pubxml.user 259 | *.publishproj 260 | 261 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 262 | # checkin your Azure Web App publish settings, but sensitive information contained 263 | # in these scripts will be unencrypted 264 | PublishScripts/ 265 | 266 | # NuGet Packages 267 | *.nupkg 268 | # The packages folder can be ignored because of Package Restore 269 | **/packages/* 270 | # except build/, which is used as an MSBuild target. 271 | !**/packages/build/ 272 | # Uncomment if necessary however generally it will be regenerated when needed 273 | #!**/packages/repositories.config 274 | # NuGet v3's project.json files produces more ignorable files 275 | *.nuget.props 276 | *.nuget.targets 277 | 278 | # Microsoft Azure Build Output 279 | csx/ 280 | *.build.csdef 281 | 282 | # Microsoft Azure Emulator 283 | ecf/ 284 | rcf/ 285 | 286 | # Windows Store app package directories and files 287 | AppPackages/ 288 | BundleArtifacts/ 289 | Package.StoreAssociation.xml 290 | _pkginfo.txt 291 | 292 | # Visual Studio cache files 293 | # files ending in .cache can be ignored 294 | *.[Cc]ache 295 | # but keep track of directories ending in .cache 296 | !*.[Cc]ache/ 297 | 298 | # Others 299 | ClientBin/ 300 | ~$* 301 | *~ 302 | *.dbmdl 303 | *.dbproj.schemaview 304 | *.jfm 305 | *.pfx 306 | *.publishsettings 307 | orleans.codegen.cs 308 | 309 | # Since there are multiple workflows, uncomment next line to ignore bower_components 310 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 311 | #bower_components/ 312 | 313 | # RIA/Silverlight projects 314 | Generated_Code/ 315 | 316 | # Backup & report files from converting an old project file 317 | # to a newer Visual Studio version. Backup files are not needed, 318 | # because we have git ;-) 319 | _UpgradeReport_Files/ 320 | Backup*/ 321 | UpgradeLog*.XML 322 | UpgradeLog*.htm 323 | 324 | # SQL Server files 325 | *.mdf 326 | *.ldf 327 | *.ndf 328 | 329 | # Business Intelligence projects 330 | *.rdl.data 331 | *.bim.layout 332 | *.bim_*.settings 333 | 334 | # Microsoft Fakes 335 | FakesAssemblies/ 336 | 337 | # GhostDoc plugin setting file 338 | *.GhostDoc.xml 339 | 340 | # Node.js Tools for Visual Studio 341 | .ntvs_analysis.dat 342 | node_modules/ 343 | 344 | # Typescript v1 declaration files 345 | typings/ 346 | 347 | # Visual Studio 6 build log 348 | *.plg 349 | 350 | # Visual Studio 6 workspace options file 351 | *.opt 352 | 353 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 354 | *.vbw 355 | 356 | # Visual Studio LightSwitch build output 357 | **/*.HTMLClient/GeneratedArtifacts 358 | **/*.DesktopClient/GeneratedArtifacts 359 | **/*.DesktopClient/ModelManifest.xml 360 | **/*.Server/GeneratedArtifacts 361 | **/*.Server/ModelManifest.xml 362 | _Pvt_Extensions 363 | 364 | # Paket dependency manager 365 | .paket/paket.exe 366 | paket-files/ 367 | 368 | # FAKE - F# Make 369 | .fake/ 370 | 371 | # JetBrains Rider 372 | .idea/ 373 | *.sln.iml 374 | 375 | # CodeRush 376 | .cr/ 377 | 378 | # Python Tools for Visual Studio (PTVS) 379 | *.pyc 380 | 381 | # Cake - Uncomment if you are using it 382 | # tools/** 383 | # !tools/packages.config 384 | 385 | # Telerik's JustMock configuration file 386 | *.jmconfig 387 | 388 | # BizTalk build output 389 | *.btp.cs 390 | *.btm.cs 391 | *.odx.cs 392 | *.xsd.cs 393 | 394 | ### VisualStudio Patch ### 395 | # By default, sensitive information, such as encrypted password 396 | # should be stored in the .pubxml.user file. 397 | 398 | # End of https://www.gitignore.io/api/python,visualstudio 399 | *.pyproj 400 | *.sln 401 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | DistanceCalc a plugin for EDMC 294 | Copyright (C) 2017 Sebastian Bauer 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Distance Calculator plugin for [EDMC](https://github.com/Marginal/EDMarketConnector/wiki) 2 | 3 | ![Screenshot](img/main_window.png) 4 | 5 | This plugin displays the distance to up to three points you can freely specify. The distance is updated after each FSD jump. 6 | 7 | ![Screenshot](img/settings.png) 8 | 9 | 10 | ## Installation 11 | 12 | 1. On EDMC's Plugins settings tab press the _Open_ button. This reveals the _plugins_ folder where EDMC looks for plugins. 13 | 2. Download the [latest release](https://github.com/Thurion/DistanceCalc/releases). 14 | 3. Open the _.zip_ archive that you downloaded and move the _DistanceCalc_ folder contained inside into the _plugins_ folder. 15 | 16 | You will need to re-start EDMC for it to notice the new plugin. 17 | 18 | ## Usage 19 | 20 | You can add up to three systems or points in the settings. Non valid entries (e.g. x, y or z is empty) won't be stored when you close the settings. 21 | It is possible to clear an entire row by pressing the _Clear_ button. The _EDSM_ button fills in the coordinates for a system providing the system name can be found on EDSM. 22 | Once at least one system/point has been added in the settings, the main window shows the distance from your current location to those systems/points in light years. 23 | 24 | Further more it is possible to display the travelled distance. The plugin uses the distance provided by the journal files for the calculation. 25 | The _total distance_ is stored and is available even when the program is closed. Uncheck the option if you don't want to your jumps added to it. This also causes it to be hidden from the main window. To reset it, press the button underneath it. 26 | The travelled distance for the current session has two available options: 27 | * Calculate it for the current EDSM session: Add distances as long as EDSM runs 28 | * Calculate it for the current Elite Session: Add distances as long as you don't load into Elite or close EDSM 29 | -------------------------------------------------------------------------------- /img/main_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thurion/DistanceCalc/fec65c65f6f69a593af7afcb43b5d888fba67d49/img/main_window.png -------------------------------------------------------------------------------- /img/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thurion/DistanceCalc/fec65c65f6f69a593af7afcb43b5d888fba67d49/img/settings.png -------------------------------------------------------------------------------- /load.py: -------------------------------------------------------------------------------- 1 | """ 2 | DistanceCalc a plugin for EDMC 3 | Copyright (C) 2017 Sebastian Bauer 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | """ 19 | 20 | import sys 21 | import os 22 | import math 23 | import json 24 | import logging 25 | from urllib import request, parse 26 | from threading import Thread 27 | from functools import partial 28 | from typing import List, Tuple, Union 29 | 30 | from config import config, appname 31 | from l10n import Locale 32 | from ttkHyperlinkLabel import HyperlinkLabel 33 | import myNotebook as nb 34 | import tkinter as tk 35 | import tkinter.ttk as ttk 36 | 37 | this = sys.modules[__name__] # For holding module globals 38 | 39 | this.VERSION = "1.3" 40 | this.BG_UPDATE_JSON = "bg_update_json" 41 | this.NUMBER_OF_SYSTEMS = 10 42 | this.PADX = 5 43 | this.WIDTH = 10 44 | this.distanceCalc = None # type DistanceCalc 45 | 46 | logger = logging.getLogger(f"{appname}.{os.path.basename(os.path.dirname(__file__))}") 47 | if not logger.hasHandlers(): 48 | level = logging.INFO # So logger.info(...) is equivalent to print() 49 | logger.setLevel(logging.INFO) 50 | logger_channel = logging.StreamHandler() 51 | logger_channel.setLevel(level) 52 | logger_formatter = logging.Formatter(f"%(asctime)s - %(name)s - %(levelname)s - %(module)s:%(lineno)d:%(funcName)s: %(message)s") 53 | logger_formatter.default_time_format = "%Y-%m-%d %H:%M:%S" 54 | logger_formatter.default_msec_format = "%s.%03d" 55 | logger_channel.setFormatter(logger_formatter) 56 | #logger.addHandler(this.logger_channel) 57 | 58 | 59 | class SettingsUiElements(object): 60 | def __init__(self, system_entry: nb.Entry, x_entry: nb.Entry, y_entry: nb.Entry, z_entry: nb.Entry, 61 | edsm_button: nb.Button, has_data: bool = False, success: bool = False, 62 | x: Union[float, int] = 0, y: Union[float, int] = 0, z: Union[float, int] = 0, 63 | system_name: str = "", error_text: str = ""): 64 | self.system_entry = system_entry 65 | self.x_entry = x_entry 66 | self.y_entry = y_entry 67 | self.z_entry = z_entry 68 | self.edsm_button = edsm_button 69 | self.has_data = has_data 70 | self.success = success 71 | self.x = x 72 | self.y = y 73 | self.z = z 74 | self.system_name = system_name 75 | self.status_text = error_text 76 | 77 | def reset_response_data(self): 78 | self.has_data = False 79 | self.success = False 80 | self.x = 0 81 | self.y = 0 82 | self.z = 0 83 | self.system_name = "" 84 | self.status_text = "" 85 | 86 | 87 | class DistanceCalc(object): 88 | EVENT_EDSM_RESPONSE = "<>" 89 | 90 | def __init__(self): 91 | distances = json.loads(config.get_str("DistanceCalc") or "[]") 92 | self.distances = distances[:this.NUMBER_OF_SYSTEMS] 93 | self.coordinates: Union[Tuple[float, float, float], None] = None 94 | self.distance_total: float = float(config.get_int("DistanceCalc_travelled") or 0) / 1000.0 95 | self.distance_session: float = 0.0 96 | a, b, c = self.get_settings_travelled() 97 | self.travelled_total_option: tk.IntVar = tk.IntVar(value=a and 1) 98 | self.travelled_session_option: tk.IntVar = tk.IntVar(value=b and 1) 99 | self.travelled_session_selected: tk.IntVar = tk.IntVar(value=c and 1) 100 | self.error_label: Union[tk.Label, None] = None 101 | self.settings_ui_elements: List[SettingsUiElements] = list() 102 | self.distance_labels: List[Tuple[tk.Label, tk.Label]] = list() 103 | self.travelled_labels: List[tk.Label] = list() 104 | self.empty_frame: Union[tk.Frame, None] = None 105 | self.update_notification_label: Union[HyperlinkLabel, None] = None 106 | self.prefs_frame: Union[tk.Frame, None] = None 107 | 108 | # region static and helper methods 109 | @staticmethod 110 | def fill_entries(system_name: str, x: Union[str, int, float], y: Union[str, int, float], z: Union[str, int, float], 111 | system_entry: nb.Entry, x_entry: nb.Entry, y_entry: nb.Entry, z_entry: nb.Entry): 112 | system_entry.insert(0, system_name) 113 | if type(x) == str: 114 | x_entry.insert(0, x) 115 | else: 116 | x_entry.insert(0, Locale.string_from_number(x, 3)) 117 | if type(y) == str: 118 | y_entry.insert(0, y) 119 | else: 120 | y_entry.insert(0, Locale.string_from_number(y, 3)) 121 | if type(z) == str: 122 | z_entry.insert(0, z) 123 | else: 124 | z_entry.insert(0, Locale.string_from_number(z, 3)) 125 | 126 | @staticmethod 127 | def validate(action, index, value_if_allowed, prior_value, text, validation_type, trigger_type, widget_name): 128 | if value_if_allowed == "-" or value_if_allowed == "": 129 | return True 130 | elif text in "0123456789.," or text == value_if_allowed: 131 | try: 132 | t = type(Locale.number_from_string(value_if_allowed)) 133 | if t is float or t is int: 134 | return True 135 | except ValueError: 136 | return False 137 | return False 138 | 139 | @staticmethod 140 | def get_settings_travelled(): 141 | settings = config.get_int("DistanceCalc_options") 142 | setting_total = settings & 1 # calculate total distance travelled 143 | setting_session = (settings >> 1) & 1 # calculate for session only 144 | setting_session_option = (settings >> 2) & 1 # 1 = calculate for ED session; 0 = calculate for EDMC session 145 | return setting_total, setting_session, setting_session_option 146 | 147 | @staticmethod 148 | def calculate_distance(x1: Union[int, float], y1: Union[int, float], z1: Union[int, float], x2: Union[int, float], y2: Union[int, float], z2: Union[int, float]): 149 | return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2) 150 | # endregion 151 | 152 | # region interface methods 153 | def plugin_app(self, parent: tk.Frame): 154 | frame = tk.Frame(parent) 155 | self.empty_frame = tk.Frame(frame) 156 | frame.columnconfigure(1, weight=1) 157 | for i in range(this.NUMBER_OF_SYSTEMS): 158 | self.distance_labels.append((tk.Label(frame), tk.Label(frame))) 159 | 160 | self.travelled_labels = list() 161 | for i in range(2): # total and session 162 | self.travelled_labels.append((tk.Label(frame), tk.Label(frame))) 163 | 164 | self.update_notification_label = HyperlinkLabel(frame, text="Plugin update available", background=nb.Label().cget("background"), 165 | url="https://github.com/Thurion/DistanceCalc/releases", underline=True) 166 | 167 | self.update_main_ui() 168 | return frame 169 | 170 | def open_prefs(self, parent, cmdr: str, is_beta: bool): 171 | row_top = 0 172 | 173 | def next_row_top(): 174 | nonlocal row_top 175 | row_top += 1 176 | return row_top 177 | 178 | self.prefs_frame = nb.Frame(parent) 179 | self.prefs_frame.bind_all(DistanceCalc.EVENT_EDSM_RESPONSE, self.update_prefs_ui) 180 | frame_top = nb.Frame(self.prefs_frame) 181 | frame_top.grid(row=0, column=0, sticky=tk.W) 182 | frame_bottom = nb.Frame(self.prefs_frame) 183 | frame_bottom.grid(row=1, column=0, sticky=tk.SW) 184 | 185 | # headline 186 | nb.Label(frame_top, text="Systems").grid(row=row_top, column=2, sticky=tk.EW) 187 | nb.Label(frame_top, text="X").grid(row=row_top, column=3, sticky=tk.EW) 188 | nb.Label(frame_top, text="Y").grid(row=row_top, column=4, sticky=tk.EW) 189 | nb.Label(frame_top, text="Z").grid(row=row_top, column=5, sticky=tk.EW) 190 | 191 | self.error_label = nb.Label(frame_top, text="") 192 | 193 | self.settings_ui_elements = list() 194 | vcmd = (frame_top.register(self.validate), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') 195 | 196 | # create and add fields to enter systems 197 | for i in range(this.NUMBER_OF_SYSTEMS): 198 | next_row_top() 199 | 200 | up_button = nb.Button(frame_top, text="\u25B2", command=partial(self.rearrange_order, i, i - 1)) 201 | up_button.grid(row=row_top, column=0, padx=(this.PADX * 2, 1), sticky=tk.W) 202 | up_button.config(width=3) 203 | if i == 0: 204 | up_button["state"] = tk.DISABLED 205 | 206 | down_button = nb.Button(frame_top, text="\u25BC", command=partial(self.rearrange_order, i, i + 1)) 207 | down_button.grid(row=row_top, column=1, padx=(1, this.PADX), sticky=tk.W) 208 | down_button.config(width=3) 209 | if i == this.NUMBER_OF_SYSTEMS - 1: 210 | down_button["state"] = tk.DISABLED 211 | 212 | system_entry = nb.Entry(frame_top) 213 | system_entry.grid(row=row_top, column=2, padx=this.PADX, sticky=tk.W) 214 | system_entry.config(width=this.WIDTH * 4) # set fixed width. columnconfigure doesn't work because it already fits 215 | 216 | x_entry = nb.Entry(frame_top, validate='key', validatecommand=vcmd) 217 | x_entry.grid(row=row_top, column=3, padx=this.PADX, sticky=tk.W) 218 | x_entry.config(width=this.WIDTH) # set fixed width. columnconfigure doesn't work because it already fits 219 | 220 | y_entry = nb.Entry(frame_top, validate='key', validatecommand=vcmd) 221 | y_entry.grid(row=row_top, column=4, padx=this.PADX, sticky=tk.W) 222 | y_entry.config(width=this.WIDTH) # set fixed width. columnconfigure doesn't work because it already fits 223 | 224 | z_entry = nb.Entry(frame_top, validate='key', validatecommand=vcmd) 225 | z_entry.grid(row=row_top, column=5, padx=this.PADX, sticky=tk.W) 226 | z_entry.config(width=this.WIDTH) # set fixed width. columnconfigure doesn't work because it already fits 227 | 228 | clear_button = nb.Button(frame_top, text="Clear", command=partial(self.clear_input_fields, i)) 229 | clear_button.grid(row=row_top, column=6, padx=this.PADX, sticky=tk.W) 230 | clear_button.config(width=7) 231 | 232 | edsm_button = nb.Button(frame_top, text="EDSM") 233 | edsm_button.grid(row=row_top, column=7, padx=(this.PADX, this.PADX * 2), sticky=tk.W) 234 | edsm_button.config(width=7, command=partial(self.fill_system_information_from_edsm_async, i, system_entry)) 235 | 236 | self.settings_ui_elements.append(SettingsUiElements(system_entry, x_entry, y_entry, z_entry, edsm_button)) 237 | 238 | # EDSM result label and information about what coordinates can be entered 239 | self.error_label.grid(row=next_row_top(), column=0, columnspan=6, padx=this.PADX * 2, sticky=tk.W) 240 | nb.Label(frame_top, text="You can get coordinates from EDDB or EDSM or enter any valid coordinate.").grid(row=next_row_top(), column=0, columnspan=6, 241 | padx=this.PADX * 2, 242 | sticky=tk.W) 243 | ttk.Separator(frame_top, orient=tk.HORIZONTAL).grid(row=next_row_top(), columnspan=6, padx=this.PADX * 2, pady=8, sticky=tk.EW) 244 | 245 | row_bottom = 0 246 | 247 | def next_row_bottom(): 248 | nonlocal row_bottom 249 | row_bottom += 1 250 | return row_bottom 251 | 252 | # total travelled distance 253 | travelled_total = nb.Checkbutton(frame_bottom, variable=self.travelled_total_option, text="Calculate total travelled distance") 254 | travelled_total.var = self.travelled_total_option 255 | travelled_total.grid(row=row_bottom, column=0, padx=this.PADX * 2, sticky=tk.W) 256 | reset_button = nb.Button(frame_bottom, text="Reset", command=self.reset_total_travelled_distance) 257 | reset_button.grid(row=next_row_bottom(), column=0, padx=this.PADX * 4, pady=5, sticky=tk.W) 258 | 259 | travelled_session = nb.Checkbutton(frame_bottom, variable=self.travelled_session_option, text="Calculate travelled distance for current session") 260 | travelled_session.var = self.travelled_session_option 261 | travelled_session.grid(row=next_row_bottom(), column=0, padx=this.PADX * 2, sticky=tk.W) 262 | 263 | # radio button value: 1 = calculate for ED session; 0 = calculate for EDMC session 264 | travelled_session_edmc = nb.Radiobutton(frame_bottom, variable=self.travelled_session_selected, value=0, text="EDMC session") 265 | travelled_session_edmc.var = self.travelled_session_selected 266 | travelled_session_edmc.grid(row=next_row_bottom(), column=0, padx=this.PADX * 4, sticky=tk.W) 267 | 268 | travelled_session_elite = nb.Radiobutton(frame_bottom, variable=self.travelled_session_selected, value=1, text="Elite session") 269 | travelled_session_elite.var = self.travelled_session_selected 270 | travelled_session_elite.grid(row=next_row_bottom(), column=0, padx=this.PADX * 4, sticky=tk.W) 271 | 272 | self.set_state_radio_buttons(travelled_session_edmc, travelled_session_elite) 273 | travelled_session.config(command=partial(self.set_state_radio_buttons, travelled_session_edmc, travelled_session_elite)) 274 | 275 | nb.Label(frame_bottom).grid(row=next_row_bottom()) # spacer 276 | nb.Label(frame_bottom).grid(row=next_row_bottom()) # spacer 277 | nb.Label(frame_bottom, text="Plugin version: {0}".format(this.VERSION)).grid(row=next_row_bottom(), column=0, padx=this.PADX, sticky=tk.W) 278 | HyperlinkLabel(self.prefs_frame, text="Open the Github page for this plugin", background=nb.Label().cget("background"), 279 | url="https://github.com/Thurion/DistanceCalc/", underline=True).grid(row=next_row_bottom(), column=0, padx=this.PADX, sticky=tk.W) 280 | HyperlinkLabel(self.prefs_frame, text="Get estimated coordinates from EDTS", background=nb.Label().cget("background"), 281 | url="http://edts.thargoid.space/", underline=True).grid(row=next_row_bottom(), column=0, padx=this.PADX, sticky=tk.W) 282 | 283 | row = 0 284 | if len(self.distances) > 0: 285 | for var in self.distances: 286 | settings_ui_element = self.settings_ui_elements[row] 287 | self.fill_entries(var["system"], var["x"], var["y"], var["z"], 288 | settings_ui_element.system_entry, 289 | settings_ui_element.x_entry, 290 | settings_ui_element.y_entry, 291 | settings_ui_element.z_entry) 292 | row += 1 293 | 294 | return self.prefs_frame 295 | 296 | def prefs_changed(self, cmdr: str, is_beta: bool): 297 | distances = list() 298 | for settings_ui_element in self.settings_ui_elements: 299 | system_text = settings_ui_element.system_entry.get() 300 | x_text = settings_ui_element.x_entry.get() 301 | y_text = settings_ui_element.y_entry.get() 302 | z_text = settings_ui_element.z_entry.get() 303 | if system_text and x_text and y_text and z_text: 304 | try: 305 | distances.append({ 306 | "system": system_text.strip(), 307 | "x": Locale.number_from_string(x_text.strip()), 308 | "y": Locale.number_from_string(y_text.strip()), 309 | "z": Locale.number_from_string(z_text.strip()) 310 | }) 311 | 312 | except Exception as e: # error while parsing the numbers 313 | logger.exception(f"DistanceCalc: Error while parsing the coordinates for {system_text.strip()}") 314 | continue 315 | self.distances = distances 316 | config.set("DistanceCalc", json.dumps(self.distances)) 317 | 318 | settings = self.travelled_total_option.get() | (self.travelled_session_option.get() << 1) | (self.travelled_session_selected.get() << 2) 319 | config.set("DistanceCalc_options", settings) 320 | 321 | self.update_main_ui() 322 | self.update_distances() 323 | self.prefs_frame = None 324 | 325 | def journal_entry(self, cmdr, is_beta, system, station, entry, state): 326 | if entry["event"] in ["FSDJump", "Location", "CarrierJump", "StartUp"]: 327 | # We arrived at a new system! 328 | if "StarPos" in entry: 329 | self.coordinates = tuple(entry["StarPos"]) 330 | if "JumpDist" in entry: 331 | distance = entry["JumpDist"] 332 | if self.travelled_total_option.get(): 333 | self.distance_total += distance 334 | config.set("DistanceCalc_travelled", int(self.distance_total * 1000)) 335 | if self.travelled_session_option.get(): 336 | self.distance_session += distance 337 | self.update_distances() 338 | if entry["event"] == "LoadGame" and self.travelled_session_option.get() and self.travelled_session_selected.get(): 339 | self.distance_session = 0.0 340 | self.update_distances() 341 | # endregion 342 | 343 | # region user interface 344 | def clear_input_fields(self, index): 345 | settings_ui_elements = self.settings_ui_elements[index] # type SettingsUiElements 346 | settings_ui_elements.system_entry.delete(0, tk.END) 347 | settings_ui_elements.x_entry.delete(0, tk.END) 348 | settings_ui_elements.y_entry.delete(0, tk.END) 349 | settings_ui_elements.z_entry.delete(0, tk.END) 350 | 351 | def rearrange_order(self, old_index: int, new_index: int): 352 | if old_index < 0 or old_index >= len(self.settings_ui_elements) or new_index < 0 or new_index >= len(self.settings_ui_elements): 353 | logger.error(f"DistanceCalc: Can't rearrange system from index {old_index} to {new_index}") 354 | return # something went wrong with the indexes 355 | 356 | old_system_text = self.settings_ui_elements[old_index].system_entry.get() 357 | old_x_text = self.settings_ui_elements[old_index].x_entry.get() 358 | old_y_text = self.settings_ui_elements[old_index].y_entry.get() 359 | old_z_text = self.settings_ui_elements[old_index].z_entry.get() 360 | 361 | new_system_text = self.settings_ui_elements[new_index].system_entry.get() 362 | new_x_text = self.settings_ui_elements[new_index].x_entry.get() 363 | new_y_text = self.settings_ui_elements[new_index].y_entry.get() 364 | new_z_text = self.settings_ui_elements[new_index].z_entry.get() 365 | 366 | self.clear_input_fields(old_index) 367 | self.clear_input_fields(new_index) 368 | uiElements = self.settings_ui_elements[old_index] # type: SettingsUiElements 369 | self.fill_entries(new_system_text, new_x_text, new_y_text, new_z_text, uiElements.system_entry, uiElements.x_entry, uiElements.y_entry, uiElements.z_entry) 370 | uiElements = self.settings_ui_elements[new_index] # type: SettingsUiElements 371 | self.fill_entries(old_system_text, old_x_text, old_y_text, old_z_text, uiElements.system_entry, uiElements.x_entry, uiElements.y_entry, uiElements.z_entry) 372 | 373 | def update_main_ui(self): 374 | # labels for distances to systems 375 | row = 0 376 | for (system, distance) in self.distance_labels: 377 | if len(self.distances) >= row + 1: 378 | s = self.distances[row] 379 | system.grid(row=row, column=0, sticky=tk.W) 380 | system["text"] = "Distance {0}:".format(s["system"]) 381 | distance.grid(row=row, column=1, sticky=tk.W) 382 | distance["text"] = "? Ly" 383 | row += 1 384 | else: 385 | system.grid_remove() 386 | distance.grid_remove() 387 | 388 | # labels for total travelled distance 389 | setting_total, setting_session, setting_session_option = self.get_settings_travelled() 390 | 391 | for i in range(len(self.travelled_labels)): 392 | description, distance = self.travelled_labels[i] 393 | if (i == 0 and setting_total) or (i == 1 and setting_session): 394 | description.grid(row=row, column=0, sticky=tk.W) 395 | description["text"] = "Travelled ({0}):".format("total" if i == 0 else "session") 396 | distance.grid(row=row, column=1, sticky=tk.W) 397 | distance["text"] = "{0} Ly".format(Locale.string_from_number(self.distance_total, 2) if i == 0 else Locale.string_from_number(self.distance_session, 2)) 398 | row += 1 399 | else: 400 | description.grid_remove() 401 | distance.grid_remove() 402 | 403 | if row == 0: 404 | self.empty_frame.grid(row=0) 405 | else: 406 | self.empty_frame.grid_remove() 407 | 408 | def update_prefs_ui(self, event=None): 409 | for i, settings_ui_element in enumerate(self.settings_ui_elements): 410 | if settings_ui_element.has_data: 411 | if settings_ui_element.success: 412 | self.clear_input_fields(i) 413 | settings_ui_element.system_entry.insert(0, settings_ui_element.system_name) 414 | settings_ui_element.x_entry.insert(0, Locale.string_from_number(settings_ui_element.x)) 415 | settings_ui_element.y_entry.insert(0, Locale.string_from_number(settings_ui_element.y)) 416 | settings_ui_element.z_entry.insert(0, Locale.string_from_number(settings_ui_element.z)) 417 | self.error_label["text"] = settings_ui_element.status_text 418 | self.error_label.config(foreground="dark green") 419 | else: 420 | self.error_label["text"] = settings_ui_element.status_text 421 | self.error_label.config(foreground="red") 422 | 423 | settings_ui_element.edsm_button["state"] = tk.NORMAL 424 | settings_ui_element.reset_response_data() 425 | 426 | def set_state_radio_buttons(self, travelled_session_edmc, travelled_session_elite): 427 | if self.travelled_session_option.get() == 1: 428 | travelled_session_edmc["state"] = "normal" 429 | travelled_session_elite["state"] = "normal" 430 | else: 431 | travelled_session_edmc["state"] = "disabled" 432 | travelled_session_elite["state"] = "disabled" 433 | 434 | def update_distances(self): 435 | if not self.coordinates: 436 | for (_, distance) in self.distance_labels: 437 | distance["text"] = "? Ly" 438 | else: 439 | for i in range(len(self.distances)): 440 | system = self.distances[i] 441 | distance = self.calculate_distance(system["x"], system["y"], system["z"], *self.coordinates) 442 | self.distance_labels[i][1]["text"] = "{0} Ly".format(Locale.string_from_number(distance, 2)) 443 | 444 | _, distance = self.travelled_labels[0] 445 | distance["text"] = "{0} Ly".format(Locale.string_from_number(self.distance_total, 2)) 446 | _, distance = self.travelled_labels[1] 447 | distance["text"] = "{0} Ly".format(Locale.string_from_number(self.distance_session, 2)) 448 | # endregion 449 | 450 | # region EDSM 451 | def get_system_information_from_edsm(self, button_number: int, system_name: str): 452 | # Don't access UI elements from here because of thread safety. Use the regular (int, str, bool) variables and fire an event 453 | settings_ui_elements = self.settings_ui_elements[button_number] 454 | settings_ui_elements.reset_response_data() 455 | 456 | edsmUrl = "https://www.edsm.net/api-v1/system?systemName={SYSTEM}&showCoordinates=1".format(SYSTEM=parse.quote(system_name)) 457 | try: 458 | url = request.urlopen(edsmUrl, timeout=15) 459 | response = url.read() 460 | edsm_json = json.loads(response) 461 | if "name" in edsm_json and "coords" in edsm_json: 462 | settings_ui_elements.success = True 463 | settings_ui_elements.system_name = edsm_json["name"] 464 | settings_ui_elements.x = edsm_json["coords"]["x"] 465 | settings_ui_elements.y = edsm_json["coords"]["y"] 466 | settings_ui_elements.z = edsm_json["coords"]["z"] 467 | settings_ui_elements.status_text = f"Coordinates filled in for system {edsm_json['name']}" 468 | else: 469 | settings_ui_elements.status_text = f"Could not get system information for {system_name} from EDSM" 470 | except: 471 | settings_ui_elements.status_text = f"Could not get system information for {system_name} from EDSM" 472 | logger.error(f"Could not get system information for {system_name} from EDSM") 473 | finally: 474 | settings_ui_elements.has_data = True 475 | if self.prefs_frame: 476 | self.prefs_frame.event_generate(DistanceCalc.EVENT_EDSM_RESPONSE, when="tail") 477 | 478 | def fill_system_information_from_edsm_async(self, button_number: int, system_entry: nb.Entry): 479 | if system_entry.get() == "": 480 | self.error_label["text"] = "No system name provided." 481 | self.error_label.config(foreground="red") 482 | else: 483 | self.settings_ui_elements[button_number].edsm_button["state"] = tk.DISABLED 484 | t = Thread(name="EDSM_caller_{0}".format(button_number), target=self.get_system_information_from_edsm, args=(button_number, system_entry.get())) 485 | t.start() 486 | # endregion 487 | 488 | def reset_total_travelled_distance(self): 489 | config.set("DistanceCalc_travelled", 0) 490 | self.distance_total = 0.0 491 | 492 | 493 | """ 494 | def showUpdateNotification(self, event=None): 495 | updateVersionInfo = this.rseData.lastEventInfo.get(this.BG_UPDATE_JSON, None) 496 | if updateVersionInfo: 497 | url = updateVersionInfo["url"] 498 | text = "Plugin update to {version} available".format(version=updateVersionInfo["version"]) 499 | else: 500 | url = "https://github.com/Thurion/DistanceCalc/releases" 501 | text = "Plugin update available" 502 | this.updateNotificationLabel["url"] = url 503 | this.updateNotificationLabel["text"] = text 504 | this.updateNotificationLabel.grid(row=99, column=0, columnspan=2, sticky=tk.W) # always put in last row 505 | 506 | def checkVersion(self): 507 | try: 508 | response = urllib.request.urlopen("https://api.github.com/repos/Thurion/DistanceCalc/releases", timeout=10) 509 | releasesInfo = json.loads(response.read()) 510 | runningVersion = tuple(this.VERSION.split(".")) 511 | for releaseInfo in releasesInfo: 512 | if not releaseInfo["draft"] and not releaseInfo["prerelease"]: 513 | newVersionText = releaseInfo["tag_name"].split("_")[1] 514 | newVersionInfo = tuple(newVersionText.split(".")) 515 | if runningVersion < newVersionInfo: 516 | self.rseData.lastEventInfo[RseData.BG_UPDATE_JSON] = {"version": newVersionText, "url": releaseInfo["html_url"]} 517 | self.rseData.frame.event_generate(RseData.EVENT_RSE_UPDATE_AVAILABLE, when="tail") 518 | break 519 | 520 | except Exception as e: 521 | logger.exception("Failed to retrieve information about available updates.") 522 | """ 523 | 524 | 525 | def plugin_start3(plugin_dir): 526 | this.distanceCalc = DistanceCalc() 527 | return "DistanceCalc" 528 | 529 | 530 | def plugin_prefs(parent, cmdr, is_beta): 531 | return this.distanceCalc.open_prefs(parent, cmdr, is_beta) 532 | 533 | 534 | def prefs_changed(cmdr, is_beta): 535 | this.distanceCalc.prefs_changed(cmdr, is_beta) 536 | 537 | 538 | def plugin_app(parent): 539 | return this.distanceCalc.plugin_app(parent) 540 | 541 | 542 | def journal_entry(cmdr, is_beta, system, station, entry, state): 543 | this.distanceCalc.journal_entry(cmdr, is_beta, system, station, entry, state) 544 | --------------------------------------------------------------------------------