import os

import anki.exporting
import anki.hooks
import anki.utils
import aqt.exporting
import aqt.utils
from aqt import QFileDialog
from aqt.exporting import ExportDialog
from ...utils import constants


# aqt part:


def exporter_changed(self, exporter_id):
    self.exporter = aqt.exporting.exporters()[exporter_id][1](self.col)
    self.frm.includeMedia.setVisible(hasattr(self.exporter, "includeMedia"))


def get_save_file(parent, title, dir_description, key, ext, fname=None):
    if ext == constants.ANKI_EXPORT_EXTENSION:
        directory = str(QFileDialog.getExistingDirectory(caption="Select Export Directory",
                                                         directory=fname))
        if directory:
            return os.path.join(directory, str(anki.utils.intTime()))
        return None

    return aqt.utils.getSaveFile_old(parent, title, dir_description, key, ext, fname)


ExportDialog.exporterChanged = anki.hooks.wrap(ExportDialog.exporterChanged, exporter_changed)

aqt.utils.getSaveFile_old = aqt.utils.getSaveFile
aqt.exporting.getSaveFile = get_save_file  # Overriding instance imported with from style import
aqt.utils.getSaveFile = get_save_file

import os

import anki.exporting
import anki.hooks
import anki.utils
import aqt.exporting
import aqt.utils
from aqt import QFileDialog
from aqt.exporting import ExportDialog
from ...utils import constants


# aqt part:


def exporter_changed(self, exporter_id):
    self.exporter = aqt.exporting.exporters(self.col)[exporter_id][1](self.col)
    self.frm.includeMedia.setVisible(hasattr(self.exporter, "includeMedia"))


def get_save_file(parent, title, dir_description, key, ext, fname=None):
    if ext == constants.ANKI_EXPORT_EXTENSION:
        directory = str(QFileDialog.getExistingDirectory(caption="Select Export Directory",
                                                         directory=fname))
        if directory:
            return os.path.join(directory, str(anki.utils.intTime()))
        return None

    return aqt.utils.getSaveFile_old(parent, title, dir_description, key, ext, fname)


ExportDialog.exporterChanged = anki.hooks.wrap(ExportDialog.exporterChanged, exporter_changed)

aqt.utils.getSaveFile_old = aqt.utils.getSaveFile
aqt.exporting.getSaveFile = get_save_file  # Overriding instance imported with from style import
aqt.utils.getSaveFile = get_save_file

Update exporter to work with Anki ≥ 2.1.36
Update exporter to work with Anki ≥ 2.1.36

`exporters` now takes an argument.

See e3b4802f47395b9c1a75ff89505410e91f34477e

Introduced after 2.1.35 but before 2.1.36.  (Testing explicitly shows
that this change is needed for 2.1.36 and 2.1.37, but breaks 2.1.35.)

Fix #113.
