<commit_before>import os
import pickle

from PyQt4 import QtGui
from Orange.base import Model

from Orange.widgets import widget, gui
from Orange.widgets.settings import Setting

from Orange.widgets.classify import owsaveclassifier


class OWLoadClassifier(widget.OWWidget):
    name = "Load Classifier"
    description = "Load a classifier from an input file."
    priority = 3050
    icon = "icons/LoadClassifier.svg"

    outputs = [("Classifier", Model, widget.Dynamic)]

    #: List of recent filenames.
    history = Setting([])
    #: Current (last selected) filename or None.
    filename = Setting(None)

    FILTER = owsaveclassifier.OWSaveClassifier.FILTER

    want_main_area = False
    resizing_enabled = False

    def __init__(self):
        super().__init__()
        self.selectedIndex = -1

        box = gui.widgetBox(
            self.controlArea, self.tr("File"), orientation=QtGui.QHBoxLayout()
        )

        self.filesCB = gui.comboBox(
            box, self, "selectedIndex", callback=self._on_recent)
        self.filesCB.setMinimumContentsLength(20)
        self.filesCB.setSizeAdjustPolicy(
            QtGui.QComboBox.AdjustToMinimumContentsLength)

        self.loadbutton = gui.button(box, self, "...", callback=self.browse)
        self.loadbutton.setIcon(
            self.style().standardIcon(QtGui.QStyle.SP_DirOpenIcon))
        self.loadbutton.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                      QtGui.QSizePolicy.Fixed)

        self.reloadbutton = gui.button(
            box, self, "Reload", callback=self.reload, default=True)
        self.reloadbutton.setIcon(
            self.style().standardIcon(QtGui.QStyle.SP_BrowserReload))
        self.reloadbutton.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                        QtGui.QSizePolicy.Fixed)

        # filter valid existing filenames
        self.history = list(filter(os.path.isfile, self.history))[:20]
        for filename in self.history:
            self.filesCB.addItem(os.path.basename(filename), userData=filename)

        # restore the current selection if the filename is
        # in the history list
        if self.filename in self.history:
            self.selectedIndex = self.history.index(self.filename)
        else:
            self.selectedIndex = -1
            self.filename = None
            self.reloadbutton.setEnabled(False)

    def browse(self):
        """Select a filename using an open file dialog."""
        if self.filename is None:
            startdir = QtGui.QDesktopServices.storageLocation(
                QtGui.QDesktopServices.DocumentsLocation)
        else:
            startdir = os.path.dirname(self.filename)

        filename = QtGui.QFileDialog.getOpenFileName(
            self, self.tr("Open"), directory=startdir, filter=self.FILTER)

        if filename:
            self.load(filename)
<commit_msg>LoadClassifier: Load most recent file in __init__<commit_after>import os
import pickle

from PyQt4 import QtGui
from Orange.base import Model

from Orange.widgets import widget, gui
from Orange.widgets.settings import Setting

from Orange.widgets.classify import owsaveclassifier


class OWLoadClassifier(widget.OWWidget):
    name = "Load Classifier"
    description = "Load a classifier from an input file."
    priority = 3050
    icon = "icons/LoadClassifier.svg"

    outputs = [("Classifier", Model, widget.Dynamic)]

    #: List of recent filenames.
    history = Setting([])
    #: Current (last selected) filename or None.
    filename = Setting(None)

    FILTER = owsaveclassifier.OWSaveClassifier.FILTER

    want_main_area = False
    resizing_enabled = False

    def __init__(self):
        super().__init__()
        self.selectedIndex = -1

        box = gui.widgetBox(
            self.controlArea, self.tr("File"), orientation=QtGui.QHBoxLayout()
        )

        self.filesCB = gui.comboBox(
            box, self, "selectedIndex", callback=self._on_recent)
        self.filesCB.setMinimumContentsLength(20)
        self.filesCB.setSizeAdjustPolicy(
            QtGui.QComboBox.AdjustToMinimumContentsLength)

        self.loadbutton = gui.button(box, self, "...", callback=self.browse)
        self.loadbutton.setIcon(
            self.style().standardIcon(QtGui.QStyle.SP_DirOpenIcon))
        self.loadbutton.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                      QtGui.QSizePolicy.Fixed)

        self.reloadbutton = gui.button(
            box, self, "Reload", callback=self.reload, default=True)
        self.reloadbutton.setIcon(
            self.style().standardIcon(QtGui.QStyle.SP_BrowserReload))
        self.reloadbutton.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                        QtGui.QSizePolicy.Fixed)

        # filter valid existing filenames
        self.history = list(filter(os.path.isfile, self.history))[:20]
        for filename in self.history:
            self.filesCB.addItem(os.path.basename(filename), userData=filename)

        # restore the current selection if the filename is
        # in the history list
        if self.filename in self.history:
            self.selectedIndex = self.history.index(self.filename)
        else:
            self.selectedIndex = -1
            self.filename = None
            self.reloadbutton.setEnabled(False)

        if self.filename:
            self.load(self.filename)

    def browse(self):
        """Select a filename using an open file dialog."""
        if self.filename is None:
            startdir = QtGui.QDesktopServices.storageLocation(
                QtGui.QDesktopServices.DocumentsLocation)
        else:
            startdir = os.path.dirname(self.filename)

        filename = QtGui.QFileDialog.getOpenFileName(
            self, self.tr("Open"), directory=startdir, filter=self.FILTER)

        if filename:
            self.load(filename)

{'fraction_non_alphanumeric': 0.09338983050847458, 'fraction_numerical': 0.003728813559322034, 'mean_word_length': 2.418887601390498, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5889502', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1602, 'n_words': 349}