mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont use win32com for notifying the OS of file association changes
This commit is contained in:
parent
ed85704799
commit
21fbec2820
@ -30,6 +30,9 @@ class TestWinutil(unittest.TestCase):
|
|||||||
def test_special_folder_path(self):
|
def test_special_folder_path(self):
|
||||||
self.assertEqual(os.path.expanduser('~'), self.winutil.special_folder_path(self.winutil.CSIDL_PROFILE))
|
self.assertEqual(os.path.expanduser('~'), self.winutil.special_folder_path(self.winutil.CSIDL_PROFILE))
|
||||||
|
|
||||||
|
def test_associations_changed(self):
|
||||||
|
self.assertIsNone(self.winutil.notify_associations_changed())
|
||||||
|
|
||||||
|
|
||||||
def find_tests():
|
def find_tests():
|
||||||
return unittest.defaultTestLoader.loadTestsFromTestCase(TestWinutil)
|
return unittest.defaultTestLoader.loadTestsFromTestCase(TestWinutil)
|
||||||
|
@ -377,6 +377,7 @@ winutil_strftime(PyObject *self, PyObject *args)
|
|||||||
static char winutil_doc[] = "Defines utility methods to interface with windows.";
|
static char winutil_doc[] = "Defines utility methods to interface with windows.";
|
||||||
extern PyObject *add_to_recent_docs(PyObject *self, PyObject *args);
|
extern PyObject *add_to_recent_docs(PyObject *self, PyObject *args);
|
||||||
extern PyObject *file_association(PyObject *self, PyObject *args);
|
extern PyObject *file_association(PyObject *self, PyObject *args);
|
||||||
|
extern PyObject *notify_associations_changed(PyObject *self, PyObject *args);
|
||||||
|
|
||||||
static PyMethodDef winutil_methods[] = {
|
static PyMethodDef winutil_methods[] = {
|
||||||
{"special_folder_path", winutil_folder_path, METH_VARARGS,
|
{"special_folder_path", winutil_folder_path, METH_VARARGS,
|
||||||
@ -452,6 +453,10 @@ be a unicode string. Returns unicode strings."
|
|||||||
"file_association()\n\nGet the executable associated with the given file extension"
|
"file_association()\n\nGet the executable associated with the given file extension"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{"notify_associations_changed", (PyCFunction)notify_associations_changed, METH_VARARGS,
|
||||||
|
"notify_associations_changed()\n\nNotify the OS that file associations have changed"
|
||||||
|
},
|
||||||
|
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,4 +72,10 @@ file_association(PyObject *self, PyObject *args) {
|
|||||||
return Py_BuildValue("u#", buf, (int)sz);
|
return Py_BuildValue("u#", buf, (int)sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
notify_associations_changed(PyObject *self, PyObject *args) {
|
||||||
|
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_DWORD | SHCNF_FLUSH, NULL, NULL);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ from threading import Thread
|
|||||||
import winerror
|
import winerror
|
||||||
|
|
||||||
from calibre import guess_type, prints
|
from calibre import guess_type, prints
|
||||||
from calibre.constants import is64bit, isportable, isfrozen, __version__, DEBUG
|
from calibre.constants import is64bit, isportable, isfrozen, __version__, DEBUG, plugins
|
||||||
from calibre.utils.winreg.lib import Key, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE
|
from calibre.utils.winreg.lib import Key, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE
|
||||||
from polyglot.builtins import iteritems, itervalues
|
from polyglot.builtins import iteritems, itervalues
|
||||||
|
|
||||||
@ -131,8 +131,8 @@ def register():
|
|||||||
with Key(r'Software\RegisteredApplications') as key:
|
with Key(r'Software\RegisteredApplications') as key:
|
||||||
key.set(data['name'], capabilities_path)
|
key.set(data['name'], capabilities_path)
|
||||||
|
|
||||||
from win32com.shell import shell, shellcon
|
winutil = plugins['winutil'][0]
|
||||||
shell.SHChangeNotify(shellcon.SHCNE_ASSOCCHANGED, shellcon.SHCNF_DWORD | shellcon.SHCNF_FLUSH, 0, 0)
|
winutil.notify_associations_changed()
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user