capn-freako/PyBERT

Save & Load Configuration Not Working in Version 4.4.1?

denzchoe opened this issue · 3 comments

running Python version 3.8.11

As per the title, saving and loading configuration doesn't work.
File is created during the save attempt but it is an empty file.

image

The following error log was reported:

Traceback (most recent call last):
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\pybert\pybert_view.py", line 78, in do_save_cfg
    pickle.dump(the_PyBertCfg, the_file)
TypeError: write() argument must be str, not bytes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\traitsui\qt4\ui_base.py", line 57, in perform
    self.ui.do_undoable(handler.perform, self.ui.info, self.action, None)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\traitsui\ui.py", line 655, in do_undoable
    action(*args, **kw)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\traitsui\handler.py", line 217, in perform
    method(info)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\pybert\pybert_view.py", line 83, in do_save_cfg
    the_pybert.log("Exception raised by pybert.pybert_view.MyHandler.do_save_cfg().",
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\pybert\pybert.py", line 608, in log
    raise exception
RuntimeError: The following error occured:
        {err}
The configuration was NOT saved.

Hi David,

I've edited the lines from the file as you have recommended. The saving feature works (i think). But the loading feature does not.

Here is the error log after trying to load it.

Traceback (most recent call last):
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\pybert\pybert_view.py", line 95, in do_load_cfg
    the_PyBertCfg = pickle.load(the_file)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 46: character maps to <undefined>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\traitsui\qt4\ui_base.py", line 57, in perform
    self.ui.do_undoable(handler.perform, self.ui.info, self.action, None)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\traitsui\ui.py", line 655, in do_undoable
    action(*args, **kw)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\traitsui\handler.py", line 217, in perform
    method(info)
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\pybert\pybert_view.py", line 113, in do_load_cfg
    the_pybert.log("Exception raised by pybert.pybert_view.MyHandler.do_load_cfg().",
  File "C:\Users\Denz\anaconda3\envs\PYBERT_Env\lib\site-packages\pybert\pybert.py", line 608, in log
    raise exception
RuntimeError: The following error occured:
        'charmap' codec can't decode byte 0x81 in position 46: character maps to <undefined>
The configuration was NOT loaded.

Found the fix.
According to documentation here;
https://github.com/enthought/pyface/blob/9ad6e3a73dae6a52289f8b1d04016451ac325192/pyface/image/image.py#L145

The line from here should be edited from;

with open(dlg.path, "r") as the_file:

to

            `with open(dlg.path, "rb") as the_file:`

If anyone else can verify this, I guess the issue can be closed after the bug fix?