<commit_before>from UM.Qt.ListModel import ListModel
from UM.Application import Application

from PyQt5.QtCore import Qt, pyqtProperty, pyqtSignal, QUrl

import os
import os.path

class DirectoryListModel(ListModel):
    NameRole = Qt.UserRole + 1
    UrlRole = Qt.UserRole + 2

    def __init__(self):
        super().__init__()

        self.addRoleName(self.NameRole, 'name')
        self.addRoleName(self.UrlRole, 'url')

        self._directory = None

    directoryChanged = pyqtSignal()

    def getDirectory(self):
        return self._directory

    def setDirectory(self, path):
        if path != self._directory:
            if path.startswith('file://'):
                path = path[7:]
            self._directory = os.path.dirname(path)

            self.clear()
            extensions = Application.getInstance().getMeshFileHandler().getSupportedFileTypesRead()
            for entry in os.listdir(self._directory):
                if os.path.splitext(entry)[1] in extensions:
                    self.appendItem({ 'name': os.path.basename(entry), 'url': QUrl.fromLocalFile(os.path.join(self._directory, entry)) })

        self.sort(lambda e: e['name'])

    directory = pyqtProperty(str, fget = getDirectory, fset = setDirectory, notify = directoryChanged)<commit_msg>Fix directory listing on windows.<commit_after>from UM.Qt.ListModel import ListModel
from UM.Application import Application

from PyQt5.QtCore import Qt, pyqtProperty, pyqtSignal, QUrl

import os
import os.path
import platform

class DirectoryListModel(ListModel):
    NameRole = Qt.UserRole + 1
    UrlRole = Qt.UserRole + 2

    def __init__(self):
        super().__init__()

        self.addRoleName(self.NameRole, 'name')
        self.addRoleName(self.UrlRole, 'url')

        self._directory = None

    directoryChanged = pyqtSignal()

    def getDirectory(self):
        return self._directory

    def setDirectory(self, path):
        if path != self._directory:
            if path.startswith('file://'):
                if platform.system() == "Windows" and path.startswith('file:///'):
                    path = path[8:]
                else:
                    path = path[7:]
            self._directory = os.path.dirname(path)

            self.clear()
            extensions = Application.getInstance().getMeshFileHandler().getSupportedFileTypesRead()
            for entry in os.listdir(self._directory):
                if os.path.splitext(entry)[1] in extensions:
                    self.appendItem({ 'name': os.path.basename(entry), 'url': QUrl.fromLocalFile(os.path.join(self._directory, entry)) })

        self.sort(lambda e: e['name'])

    directory = pyqtProperty(str, fget = getDirectory, fset = setDirectory, notify = directoryChanged)
{'fraction_non_alphanumeric': 0.11369415183436252, 'fraction_numerical': 0.003995641118779513, 'mean_word_length': 2.61892247043364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2538742', 'n_tokens_mistral': 800, 'n_tokens_neox': 756, 'n_words': 177}