def open_cb(source, result, *data): info = source.query_info_finish(result) file_type = info.get_file_type() if file_type == gio.FILE_TYPE_DIRECTORY: os_open(source.get_path()) elif file_type == gio.FILE_TYPE_REGULAR: content_type = info.get_content_type() path = source.get_path() if gio.content_type_is_a(content_type, "text/plain"): editor = self.prefs.get_editor_command([path]) if editor: subprocess.Popen(editor) else: os_open(path) else: os_open(path) else: # TODO: Add some kind of 'failed to open' notification pass
def open_cb(source, result, *data): info = source.query_info_finish(result) file_type = info.get_file_type() if file_type == gio.FILE_TYPE_DIRECTORY: os_open(source.get_path()) elif file_type == gio.FILE_TYPE_REGULAR: content_type = info.get_content_type() path = source.get_path() # FIXME: Content types are broken on Windows with current gio if gio.content_type_is_a(content_type, "text/plain") or \ sys.platform == "win32": editor = self.prefs.get_editor_command(path, line) if editor: subprocess.Popen(editor) else: os_open(path) else: os_open(path) else: # TODO: Add some kind of 'failed to open' notification pass
def is_mime_type_subset(self, mime_type, super_type): """Check whether specified mime_type is a subset of super_type""" return gio.content_type_is_a(mime_type, super_type)
def test_content_type_is_a(): assert gio.content_type_is_a('foo', 'foo') assert gio.content_type_is_a('text/html', 'text/plain') assert not gio.content_type_is_a('text/plain', 'application/x-tar-gz')