kcjengr / qtpyvcp

QtPyVCP - Qt and Python based Virtual Control Panel framework for LinuxCNC.
https://www.qtpyvcp.com
Other
89 stars 50 forks source link

When system language in chinese, pharse files will have error decoding #141

Closed xzkeee closed 2 weeks ago

xzkeee commented 6 months ago

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/qtpyvcp/widgets/input_widgets/file_system.py", line 111, in data date = parse(data) ^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dateutil/parser/_parser.py", line 1368, in parse return DEFAULTPARSER.parse(timestr, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dateutil/parser/_parser.py", line 643, in parse raise ParserError("Unknown string format: %s", timestr) dateutil.parser._parser.ParserError: Unknown string format: 2024/3/17 上午12:48

i am using prob basic and system language is in chinese; everytime go files section it raise this error, it try to get last modified date and system return a chinese string time and code can not handle it. Is this qtpyvcp problem or probebasic problem tho.

vip74120 commented 3 months ago

`class QtpyVCPQFileSystemModel(QFileSystemModel):

def data(self, index, role=Qt.DisplayRole):
    # Column nº 3 is date, align it to right
    col = index.column()

    if role == Qt.DisplayRole:
        data = QFileSystemModel.data(self, index, role)
        if col == 3:
            try: 
                date = parse(data) 
                formatted_date = f"{date:%m/%d/%y   %I:%M  %p}"
                return formatted_date
            except ValueError as e:
                pass  
        return f"{data}"

    if role == Qt.TextAlignmentRole:
        if col == 3:
            return Qt.AlignVCenter | Qt.AlignRight

    return QFileSystemModel.data(self, index, role)`

修改一下就行了

TurBoss commented 2 weeks ago

fixed in main branch

thank you