def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fileviewer try: function(*args, **kwargs, tab=tab, b=b) finally: b.on_closing() del b
def save(): # make gui b = bfit(None, True) # set menu items ------------------------------------------------------- for v in menu: setv(b, v) # set fileviewer items --------------------------------------------------- tab = b.fileviewer for i, v in enumerate(fileview): setv(tab, v) if i == 1: tab.get_data() # set fetch items -------------------------------------------------------- tab = b.fetch_files for i, v in enumerate(fetch): setv(tab, v) if i == 1: tab.get_data() dline = b.data['2019.40123'] for v in data: setv(dline, v) # set fit items ---------------------------------------------------------- tab = b.fit_files tab.populate() # ~ tab.do_fit() for v in fit: setv(tab, v) tab.populate() tab.populate_param(force_modify=True) fit_line = tab.fit_lines['2019.40123'] for v in fitline: setv(fit_line, v) # misc ------------------------------------------------------------------- # deadtime for v in deadtime: setv(b, v) # data directory for v in datadir: setv(b, v) # save and clean --------------------------------------------------------- b.save_state(filename) b.on_closing() del b
def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fetch_files b.notebook.select(1) try: function(*args, **kwargs, tab=tab, b=b) finally: b.on_closing() del b
def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fit_files tab2 = b.fetch_files b.notebook.select(2) tab2.year.set(2020) tab2.run.set('40123 40127') tab2.get_data() try: function(*args, **kwargs, tab=tab, b=b, tab2=tab2) finally: b.on_closing() del b
def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fileviewer tab.year.set(year) tab.runn.set(run) tab.get_data() units = popup_units(b) try: return function(*args, **kwargs, b=b, tab=tab, units=units) finally: b.on_closing() del b
def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fit_files tab2 = b.fetch_files b.notebook.select(2) tab2.year.set(2020) tab2.run.set('40123 40127, 40129') tab2.get_data() tab.populate() b.draw_fit.set(False) try: return function(*args, **kwargs, b=b, fittab=tab, fetchtab=tab2) finally: b.on_closing() del b
def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fileviewer tab2 = b.fetch_files # get data tab.year.set(2020) tab.runn.set(40123) tab.get_data() tab2.year.set(2020) tab2.run.set('40123 40127') # test try: return function(*args, **kwargs, b=b) finally: b.on_closing() del b
def wrapper(*args, **kwargs): # make gui b = bfit(None, True) tab = b.fetch_files tab2 = b.fit_files b.notebook.select(2) b.draw_fit.set(False) # get data tab.year.set(2021) tab.run.set('40063 40054') tab.get_data() # fit tab2.populate() # test try: return function(*args, **kwargs, b=b) finally: b.on_closing() del b
def test_load(): # save save() # make gui and load b = bfit(None, True) b.load_state(filename) # check list def check(obj, lst): for v in lst: read, desired = getv(obj, v) try: assert read == desired, ('%s\n%s \n\tACTUAL: %s\n\tDESIRED: %s' % \ (str(obj), v[:-1], read, desired)) except AssertionError as err: if type(read) != type(desired): assert str(read) == str(desired), ('%s\n%s \n\tACTUAL: %s\n\tDESIRED: %s' % \ (str(obj), v[:-1], read, desired)) else: raise err from None # check all the lists # ~ check(b, menu) # ~ check(b.fileviewer, fileview) # ~ check(b.fetch_files, fetch) # ~ check(b.data['2019.40123'], data) # ~ check(b.fit_files, fit) check(b.fit_files.fit_lines['2019.40123'], fitline) # ~ check(b, deadtime) # ~ check(b, datadir) # save and clean --------------------------------------------------------- b.on_closing() del b os.remove(filename)
def main(): # check if maxOS if sys.platform == 'darwin': os.environ['OBJC_DISABLE_INITIALIZE_FORK_SAFETY'] = 'YES' # check if windows if sys.platform == 'win32': homedir = os.environ['HOMEPATH'] else: homedir = os.environ['HOME'] # command line switches --------------------------------------------------- parser = argparse.ArgumentParser( description=dedent("""\ Run BNMR data viewer and fitter for online application."""), formatter_class=argparse.RawTextHelpFormatter) # logging level parser.add_argument("-d", "--debug", help='Run in debug mode', dest='debug', action='store_true', default=False) # no gui mode parser.add_argument("-c", "--commandline", help='Run in command line mode', dest='commandline', action='store_true', default=False) # parse args = parser.parse_args() # Setup logging ----------------------------------------------------------- logger = logging.getLogger(logger_name) # get log filename try: filename = os.path.join(homedir, '.bfit.log') except KeyError: filename = 'bfit.log' # make handler handler = RotatingFileHandler( filename, mode='a', maxBytes=500 * 1000, # 500 kB max backupCount=1) # get level and format for output string if args.debug: level = logging.DEBUG fmt = '%(asctime)s %(levelname)-8s %(module)s.%(funcName)s() [%(lineno)d] -- %(message)s' else: level = logging.INFO fmt = '%(asctime)s %(levelname)-8s %(module)s -- %(message)s' # set handler.setFormatter(logging.Formatter(fmt)) handler.setLevel(level) logger.addHandler(handler) logger.setLevel(level) # testing testfn = None # ~ def testfn(self): # ~ self.fetch_files.run.set("40123, 40127") # ~ self.fetch_files.year.set(2012) # ~ self.fetch_files.get_data() # ~ self.fit_files.fit_function_title.set("QuadLorentz") # ~ self.fit_files.populate() # ~ self.notebook.select(2) # ~ self.fit_files.do_fit() # ~ import matplotlib.pyplot as plt # ~ plt.close('all') # ~ self.fit_files.do_add_param() # Check version (credit: https://github.com/alexmojaki/outdated) ---------- try: latest_version = requests.get( 'https://pypi.python.org/pypi/bfit/json').text latest_version = json.loads(latest_version)['info']['version'] latest_version2 = parse_version(latest_version) current_version = parse_version(str(__version__)) if current_version < latest_version2: testfn = lambda x: messagebox.showinfo( "Please update", "Version %s available!" % latest_version) except Exception: pass # start bfit -------------------------------------------------------------- b = bfit(testfn, args.commandline) if args.commandline: code.interact(local=locals()) print('bfit object set to variable "b"')
# get log filename try: filename = os.path.join(os.environ['HOME'], '.bfit.log') except KeyError: filename = 'bfit.log' # make handler handler = RotatingFileHandler( filename, mode='a', maxBytes=100 * 1000, # 100 kB max backupCount=1) # get level and format for output string if args.debug: level = logging.DEBUG fmt = '%(asctime)s %(levelname)-8s %(module)s.%(funcName)s() [%(lineno)d] -- %(message)s' else: level = logging.INFO fmt = '%(asctime)s %(levelname)-8s %(module)s -- %(message)s' # set handler.setFormatter(logging.Formatter(fmt)) handler.setLevel(level) logger.addHandler(handler) logger.setLevel(level) # Run bfit ---------------------------------------------------------------- bfit()