Changeset 08f921e in sasview


Ignore:
Timestamp:
Oct 23, 2018 5:49:09 AM (5 years ago)
Author:
krzywon
Branches:
unittest-saveload
Children:
6af5d75
Parents:
add6365
Message:

Thread sasview wx gui so it can be called and run in parallel with tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/projectsaveandload/test/utest_project.py

    r497e06d r08f921e  
    77import unittest 
    88import warnings 
    9 if sys.version_info[0] >= 3: 
    10     from io import StringIO 
    11 else: 
    12     from StringIO import StringIO 
     9import threading 
    1310 
    1411from sas.sascalc.dataloader.loader import Loader 
     
    3431        self.data1d = self.loader.load("test_data/data1D.h5") 
    3532        self.data2d = self.loader.load("test_data/data2D.h5") 
     33        self.sasviewThread = sasviewThread() 
     34        self.sasviewThread.start_local() 
    3635        if not (os.path.isdir(TEMP_FOLDER)): 
    3736            os.makedirs(TEMP_FOLDER) 
     37 
     38    def tearDown(self): 
     39        self.remove_dir() 
     40        if hasattr(self.sasviewThread, "isAlive"): 
     41            if self.sasviewThread.isAlive(): 
     42                print("TODO: Close app directly") 
     43                self.app.gui.Close() 
     44                pass 
    3845 
    3946    def remove_dir(self): 
     
    4552        Test saving and loading a project with a single data set sent to fitting 
    4653        """ 
     54        self.sasviewThread.join(5) 
    4755        self.assertTrue(1 == 1) 
    4856 
     
    5361        # TODO: Send 1D to every perspective, save/load 
    5462        # TODO: Save/load simultaneous/constrained fit project 
     63 
     64 
     65class sasviewThread(threading.Thread): 
     66    """Run the MainLoop as a thread. Access the frame with self.frame.""" 
     67 
     68    def __init__(self, autoStart=True): 
     69        threading.Thread.__init__(self) 
     70        self.setDaemon(1) 
     71        self.start_orig = self.start 
     72        self.start = self.start_local 
     73        self.frame = None  # to be defined in self.run 
     74        self.lock = threading.Lock() 
     75        self.lock.acquire()  # lock until variables are set 
     76        if autoStart: 
     77            self.start()  # automatically start thread on init 
     78 
     79    def run(self): 
     80        import sas.sasview.sasview as sasview 
     81        app = sasview.run_gui() 
     82        self.frame = app.frame 
     83 
     84        # define frame and release lock 
     85        # The lock is used to make sure that SetData is defined. 
     86        self.lock.release() 
     87 
     88        app.MainLoop() 
     89 
     90    def start_local(self): 
     91        self.start_orig() 
     92        # After thread has started, wait until the lock is released 
     93        # before returning so that functions get defined. 
     94        self.lock.acquire() 
Note: See TracChangeset for help on using the changeset viewer.