Commit 77356c6dcd635b665d64f926fc64c69ee06f8f85
Committed by
GitHub
1 parent
df13f481
Exists in
master
Move initializations to main() (#409)
To enable starting InVesalius by importing app.py and calling main().
Showing
1 changed file
with
35 additions
and
27 deletions
Show diff stats
app.py
| ... | ... | @@ -490,9 +490,41 @@ def print_events(topic=Publisher.AUTO_TOPIC, **msg_data): |
| 490 | 490 | utils.debug("%s\n\tParameters: %s" % (topic, msg_data)) |
| 491 | 491 | |
| 492 | 492 | |
| 493 | +def init(): | |
| 494 | + """ | |
| 495 | + Initialize InVesalius. | |
| 496 | + | |
| 497 | + Mostly file-system related initializations. | |
| 498 | + """ | |
| 499 | + #Is needed because of pyinstaller | |
| 500 | + multiprocessing.freeze_support() | |
| 501 | + | |
| 502 | + #Needed in win 32 exe | |
| 503 | + if hasattr(sys,"frozen") and sys.platform.startswith('win'): | |
| 504 | + | |
| 505 | + #Click in the .inv3 file support | |
| 506 | + root = winreg.HKEY_CLASSES_ROOT | |
| 507 | + key = "InVesalius 3.1\InstallationDir" | |
| 508 | + hKey = winreg.OpenKey (root, key, 0, winreg.KEY_READ) | |
| 509 | + value, type_ = winreg.QueryValueEx (hKey, "") | |
| 510 | + path = os.path.join(value,'dist') | |
| 511 | + | |
| 512 | + os.chdir(path) | |
| 513 | + | |
| 514 | + if not inv_paths.USER_INV_DIR.exists(): | |
| 515 | + inv_paths.create_conf_folders() | |
| 516 | + if inv_paths.OLD_USER_INV_DIR.exists(): | |
| 517 | + inv_paths.copy_old_files() | |
| 518 | + | |
| 519 | + if hasattr(sys,"frozen") and sys.frozen == "windows_exe": | |
| 520 | + # Set system standard error output to file | |
| 521 | + path = inv_paths.USER_LOG_DIR.join("stderr.log") | |
| 522 | + sys.stderr = open(path, "w") | |
| 523 | + | |
| 524 | + | |
| 493 | 525 | def main(connection=None): |
| 494 | 526 | """ |
| 495 | - Initialize InVesalius GUI | |
| 527 | + Start InVesalius. | |
| 496 | 528 | |
| 497 | 529 | Parameters: |
| 498 | 530 | connection: An object to communicate with the outside world. |
| ... | ... | @@ -505,6 +537,8 @@ def main(connection=None): |
| 505 | 537 | functionality, InVesalius needs to be started by calling the main |
| 506 | 538 | function directly with a proper connection object. |
| 507 | 539 | """ |
| 540 | + init() | |
| 541 | + | |
| 508 | 542 | options, args = parse_command_line() |
| 509 | 543 | |
| 510 | 544 | session = ses.Session() |
| ... | ... | @@ -536,30 +570,4 @@ def main(connection=None): |
| 536 | 570 | |
| 537 | 571 | |
| 538 | 572 | if __name__ == '__main__': |
| 539 | - #Is needed because of pyinstaller | |
| 540 | - multiprocessing.freeze_support() | |
| 541 | - | |
| 542 | - #Needed in win 32 exe | |
| 543 | - if hasattr(sys,"frozen") and sys.platform.startswith('win'): | |
| 544 | - | |
| 545 | - #Click in the .inv3 file support | |
| 546 | - root = winreg.HKEY_CLASSES_ROOT | |
| 547 | - key = "InVesalius 3.1\InstallationDir" | |
| 548 | - hKey = winreg.OpenKey (root, key, 0, winreg.KEY_READ) | |
| 549 | - value, type_ = winreg.QueryValueEx (hKey, "") | |
| 550 | - path = os.path.join(value,'dist') | |
| 551 | - | |
| 552 | - os.chdir(path) | |
| 553 | - | |
| 554 | - if not inv_paths.USER_INV_DIR.exists(): | |
| 555 | - inv_paths.create_conf_folders() | |
| 556 | - if inv_paths.OLD_USER_INV_DIR.exists(): | |
| 557 | - inv_paths.copy_old_files() | |
| 558 | - | |
| 559 | - if hasattr(sys,"frozen") and sys.frozen == "windows_exe": | |
| 560 | - # Set system standard error output to file | |
| 561 | - path = inv_paths.USER_LOG_DIR.join("stderr.log") | |
| 562 | - sys.stderr = open(path, "w") | |
| 563 | - | |
| 564 | - # Init application | |
| 565 | 573 | main() | ... | ... |