cutright / DVH-Analytics

A DICOM Database Application for Radiation Oncology
Other
82 stars 30 forks source link

Changing locale may prevent timestamp generation on Windows #140

Closed cutright closed 3 years ago

cutright commented 3 years ago

Changing locale caused a hard crash when trying to access an icon from DVHA local storage. Commenting out the following function resolved the issue. This code was just to avoid a message in the terminal abut an unknown locale, so not worth keeping it.

https://github.com/cutright/DVH-Analytics/blob/a0e29af70b5703e6b41c6251dd9da9a72310efd3/dvha/main.py#L1857-L1861

cutright commented 3 years ago

fixed in v0.9.4

cutright commented 3 years ago

This locale issue needs to be fixed to be able to write time stamps to the SQL database (maybe only for SQLite?)

cutright commented 3 years ago

Testing this out instead: https://github.com/cutright/DVH-Analytics/blob/1fce354a1fede2cbbc6e8ee3f79b0cec8576c3cc/dvha/main.py#L1866-L1871

cutright commented 3 years ago

The code in the previous commit appears to avoid errors, however timestamps from DICOM (e.g., plan timestamp) are not being determined. Timestamps from SQL (e.g., import timestamps) work fine. So think with the above fix, this issue amounts to a minor issue. Dates appear to be OK (e.g., Sim Study Date).

I tried the following, but no dice.

This code produced the following error and hard crash on MSW7:

def InitLocale(self):

    if is_windows():

        self.ResetLocale()

        try:

            import locale

            lang, enc = locale.getdefaultlocale()

            lang = lang.replace('_', '-')

            self._initial_locale = wx.Locale(lang, lang[:2], lang)

            # locale.setlocale(locale.LC_ALL, lang)

        except Exception as e:

            print(e)
    
    else:

        super().InitLocale()
ERROR: Unhandled exception: Traceback (most recent call last):
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\main.py", line 1853, in OnInit
    self.frame = DVHAMainFrame(None, wx.ID_ANY, "")
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\main.py", line 218, in __init__
    self.__add_tool_bar()
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\main.py", line 308, in __add_tool_bar
    bitmap = wx.Bitmap(ICONS[key], wx.BITMAP_TYPE_ANY)
wx._core.wxAssertionError: C++ assertion "strcmp(setlocale(0, 0), "C") == 0" failed at ..\..\src\common\intl.cpp(1694) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a misma
tch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!
cutright commented 3 years ago

Changing to 'bug: minor'

Will release new InitLocale with v0.9.5 later today