Exemplo n.º 1
0
	def __get_search_path_from(self, uri):
		self.__manager.response()
		from gio import File
		path = File(uri).get_parse_name()
		path = path.replace(self.__home_folder, "").strip("/\\")
		self.__manager.response()
		return path
Exemplo n.º 2
0
    def _get_g_file(self, uri):
        if type(uri) is not str:
            raise TypeError, 'unexpected "%s"' % repr(uri)

        # Resolve or not ?

        # Your folder is None => new File
        if self._folder is None:
            g_file = File(uri)
        else:
            # Split the uri
            scheme, authority, path, query, fragment = urlsplit(uri)

            # A scheme or an authority => new File
            # XXX This is not truly exact:
            #     we can have a scheme and a relative path.
            if scheme or authority:
                g_file = File(uri)
            else:
                # Else we resolve the path
                g_file = self._folder.resolve_relative_path(uri)

        # Automount a ftp server ?
        if g_file.get_uri_scheme () == 'ftp':
            # Mount the server
            AnonymousConnection(g_file)

        return g_file
Exemplo n.º 3
0
	def __go_up(self):
		from gio import File
		gfile = File(self.__folder_uri).get_parent()
		if not gfile: return False
		from gobject import idle_add
		idle_add(self.__manager.emit, "generate-uris", gfile.get_uri())
		return False
Exemplo n.º 4
0
	def __set_label(self):
		from gio import File
		uri = self.__editor.uri
		if uri: folder = File(uri).get_parent().get_parse_name()
		if not uri: folder = self.__editor.desktop_folder
		folder = folder.replace(self.__editor.home_folder.rstrip("/"), "~")
		self.__label.set_label(message % folder)
		return False
Exemplo n.º 5
0
	def __show(self, data):
		uri, message = data
		self.__editor.emit("load-error", uri)
		from gio import File
		gfile = File(uri)
		title = _("File: %s") % gfile.get_parse_name()
		self.__editor.show_error(title, message)
		return False
Exemplo n.º 6
0
def show_path(path):
	"""Open local @path with default viewer"""
	from gio import File
	# Implemented using gtk.show_uri
	gfile = File(path)
	if not gfile:
		return
	url = gfile.get_uri()
	show_url(url)
class ColorButton(object):

	def __init__(self, editor, manager):
		self.__init_attributes(editor, manager)
		self.__set_properties()
		self.__sigid1 = self.__button.connect("color-set", self.__color_set_cb)
		self.__sigid2 = manager.connect("destroy", self.__destroy_cb)
		self.__monitor.connect("changed", self.__changed_cb)
		self.__button.set_property("sensitive", True)

	def __init_attributes(self, editor, manager):
		self.__editor = editor
		self.__manager = manager
		self.__button = manager.gui.get_widget("BracketSelectionColorButton")
		from os.path import join
		preference_folder = join(editor.metadata_folder, "PluginPreferences")
		_path = join(preference_folder, "LexicalScopeHighlight.gdb")
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(_path).monitor_file(FILE_MONITOR_NONE, None)
		return

	def __set_properties(self):
		from LexicalScopeHighlightMetadata import get_value
		from gtk.gdk import color_parse
		color = color_parse(get_value())
		self.__button.set_color(color)
		return

	def __destroy(self):
		self.__monitor.cancel()
		self.__editor.disconnect_signal(self.__sigid1, self.__button)
		self.__editor.disconnect_signal(self.__sigid2, self.__manager)
		self.__button.destroy()
		del self
		self = None
		return

	def __color_set_cb(self, *args):
		from LexicalScopeHighlightMetadata import set_value
		color = self.__button.get_color().to_string()
		set_value(color)
		return True

	def __destroy_cb(self, *args):
		self.__destroy()
		return True

	def __changed_cb(self, *args):
		monitor, gfile, otherfile, event = args
		if not (event in (0,2,3)): return False
		self.__button.handler_block(self.__sigid1)
		from LexicalScopeHighlightMetadata import get_value
		from gtk.gdk import color_parse
		color = color_parse(get_value())
		self.__button.set_color(color)
		self.__button.handler_unblock(self.__sigid1)
		return True
Exemplo n.º 8
0
	def __get_display_path_from(self, uri):
		self.__manager.response()
		from gio import File
		path = File(uri).get_parent().get_parse_name()
		path = path.replace(self.__home_folder, "").strip("/\\")
		from os.path import split
		self.__manager.response()
		if not path: return split(self.__home_folder)[-1].strip("/\\")
		return path
Exemplo n.º 9
0
	def __set_label(self, fileinfo):
		try:
			if not self.__editor.uri: raise AssertionError
			from gio import File
			path = File(self.__editor.uri).get_parent().get_parse_name()
			folder = path.replace(self.__editor.home_folder.rstrip("/"), "~")
			self.__label.set_text(folder)
		except AssertionError:
			self.__label.set_text("Unknown")
		return False
    def find_project_root(self, path):
        f = File(path)
        project_files = (".git", ".ropeproject", ".bzr", ".hg", ".scribes_project")
        while True:
            if any(f.get_child(r).query_exists() for r in project_files):
                return f.get_uri()

            p = f.get_parent()
            if p:
                f = p
            else:
                return path
        def new_get_dictionary(this, uri):
            title = File(uri).get_basename() if uri else _("Unnamed Document")

            if title.endswith('.py'):
                title = get_python_title(uri)

            return {
                "normal": title,
                "modified": "*" + title,
                "readonly": title + _(" [READONLY]"),
                "loading": _("Loading %s ...") % title,
            }
Exemplo n.º 12
0
def find_project_root(uri):
    f = File(uri)
    special_names = ('.ropeproject', '.git', '.hg', '.bzr', '.scribes_project')
    while True:
        for name in special_names:
            if f.get_child(name).query_exists():
                return f.get_path()

        p = f.get_parent()
        if p:
            f = p
        else:
            return None
Exemplo n.º 13
0
	def __select(self):
		try:
			if not self.__editor.uri: raise ValueError
			from gio import File 
			gfile = File(self.__editor.uri)
			folder_uri = gfile.get_parent().get_uri()
			if folder_uri != self.__chooser.get_current_folder_uri():
				self.__chooser.set_current_folder_uri(folder_uri)
			fileinfo = gfile.query_info("standard::display-name")
			self.__chooser.set_current_name(fileinfo.get_display_name())
		except ValueError:
			self.__chooser.set_current_name(_("Unsaved Document"))
			self.__chooser.set_current_folder(self.__editor.desktop_folder)
		return False
Exemplo n.º 14
0
	def __get_dictionary(self, uri):
		from gio import File
		title = File(uri).get_basename() if uri else _("Unnamed Document")
		ellipsize = self.__ellipsize
		if uri: parent_path = File(uri).get_parent().get_parse_name()
		if uri: parent_path = ellipsize(parent_path.replace(self.__editor.home_folder, "~").strip("/\\"))
		fulltitle = "%s - (%s)" % (title, parent_path) if uri else title
		fulltitle = title if len(title) > 30 else fulltitle
		dictionary = {
			"normal": fulltitle,
			"modified": "*" + fulltitle,
			"readonly": fulltitle + _(" [READONLY]"),
			"loading": _("Loading %s ...") % title,
		}
		return dictionary
Exemplo n.º 15
0
def get_gicon_for_file(uri):
	"""
	Return a GIcon representing the file at
	the @uri, which can be *either* and uri or a path

	return None if not found
	"""

	gfile = File(uri)
	if not gfile.query_exists():
		return None

	finfo = gfile.query_info(FILE_ATTRIBUTE_STANDARD_ICON)
	gicon = finfo.get_attribute_object(FILE_ATTRIBUTE_STANDARD_ICON)
	return gicon
Exemplo n.º 16
0
def get_thumbnail_for_file(uri, width=-1, height=-1):
	"""
	Return a Pixbuf thumbnail for the file at
	the @uri, which can be *either* and uri or a path
	size is @width x @height

	return None if not found
	"""

	gfile = File(uri)
	if not gfile.query_exists():
		return None
	finfo = gfile.query_info(FILE_ATTRIBUTE_THUMBNAIL_PATH)
	thumb_path = finfo.get_attribute_byte_string(FILE_ATTRIBUTE_THUMBNAIL_PATH)

	return get_pixbuf_from_file(thumb_path, width, height)
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		self.__view = editor.textview
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(manager.get_path("MarginPosition.gdb")).monitor_file(FILE_MONITOR_NONE, None)
		return
Exemplo n.º 18
0
def check_uri_permission(uri):
	value = True
	from gio import File
	if File(uri).get_uri_scheme() == "file":
		local_path = File(uri).get_path()
		from os import access, W_OK, path
		if path.exists(local_path):
			value = access(local_path, W_OK)
		else:
			from Globals import home_folder
			if local_path.startswith(home_folder) is False:
				value = False
	else:
		writable_scheme = ["ssh", "sftp", "smb", "dav", "davs", "ftp"]
		scheme = File(uri).get_uri_scheme()
		if not scheme in writable_scheme: value = False
	return value
Exemplo n.º 19
0
	def __init_attributes(self, manager, editor):
		self.__manager = manager
		self.__editor = editor
		from os.path import join
		path_ = join(editor.metadata_folder, "abbreviations.gdb")
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(path_).monitor_file(FILE_MONITOR_NONE, None)
		return
Exemplo n.º 20
0
class Updater(object):

	def __init__(self, editor):
		self.__init_attributes(editor)
		self.__sigid1 = editor.connect("quit", self.__quit_cb)
		self.__monitor.connect("changed", self.__changed_cb)
		self.__update()
		editor.register_object(self)

	def __init_attributes(self, editor):
		self.__editor = editor
		self.__buffer = editor.textbuffer
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(self.__get_path()).monitor_file(FILE_MONITOR_NONE, None)
		return

	def __destroy(self):
		self.__editor.disconnect_signal(self.__sigid1, self.__editor)
		self.__monitor.cancel()
		self.__editor.unregister_object(self)
		del self
		return False

	def __update(self):
		from SCRIBES.ColorThemeMetadata import get_value
		scheme_id = get_value()
		style_scheme = self.__editor.style_scheme_manager.get_scheme(scheme_id)
		if style_scheme: self.__buffer.set_style_scheme(style_scheme)
		self.__editor.emit("syntax-color-theme-changed")
		return False

	def __get_path(self):
		from os.path import join
		folder = join(self.__editor.metadata_folder, "Preferences")
		return join(folder, "ColorTheme.gdb")

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __changed_cb(self, *args):
		monitor, gfile, otherfile, event = args
		if not (event in (0, 2, 3)): return False
		from gobject import idle_add
		idle_add(self.__update)
		return False
Exemplo n.º 21
0
	def __monitor(self, uri):
		self.__uri = uri
		from gio import File, FILE_MONITOR_NONE
		self.__unmonitor()
		self.__file_monitor = File(uri).monitor_file(FILE_MONITOR_NONE, self.__cancellable)
		self.__file_monitor.connect("changed", self.__changed_cb)
		self.__file_monitor.set_rate_limit(RATE_LIMIT)
		return False
Exemplo n.º 22
0
 def __init__(self, obj=None):
     if obj is None:
         self._folder = None
     elif type(obj) is str:
         self._folder = File(obj)
     elif isinstance(obj, File):
         self._folder = obj
     else:
         raise ValueError, 'unexpected obj "%s"' % obj
	def __init_attributes(self, editor, manager):
		self.__editor = editor
		self.__manager = manager
		self.__button = manager.gui.get_widget("BracketSelectionColorButton")
		from os.path import join
		preference_folder = join(editor.metadata_folder, "PluginPreferences")
		_path = join(preference_folder, "LexicalScopeHighlight.gdb")
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(_path).monitor_file(FILE_MONITOR_NONE, None)
		return
Exemplo n.º 24
0
Arquivo: icons.py Projeto: pbx/kupfer
def get_gicon_for_file(uri):
    """
    Return a GIcon representing the file at
    the @uri, which can be *either* and uri or a path

    return None if not found
    """

    gfile = File(uri)
    if not gfile.query_exists():
        return None

    finfo = gfile.query_info(FILE_ATTRIBUTE_STANDARD_ICON)
    gicon = finfo.get_attribute_object(FILE_ATTRIBUTE_STANDARD_ICON)
    # very manually override generic folder icon name
    if isinstance(gicon, ThemedIcon):
        if gicon.get_names()[0] == "inode-directory":
            return ThemedIcon("folder")
    return gicon
Exemplo n.º 25
0
	def __init_attributes(self, editor):
		self.__editor = editor
		self.__uri = ""
		from SCRIBES.GObjectTimerManager import Manager
		self.__timer_manager = Manager()
		from gio import File, FILE_MONITOR_NONE, Cancellable
		self.__cancellable = Cancellable()
		self.__file_monitor = File("").monitor_file(FILE_MONITOR_NONE, self.__cancellable)
		self.__can_reload = True
		return
Exemplo n.º 26
0
class Listener(object):

	def __init__(self, manager, editor):
		self.__init_attributes(manager, editor)
		self.__sigid1 = manager.connect("destroy", self.__destroy_cb)
		self.__monitor.connect("changed", self.__update_cb)
		self.__update()

	def __init_attributes(self, manager, editor):
		self.__editor = editor
		self.__manager = manager
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(self.__get_path()).monitor_file(FILE_MONITOR_NONE, None)
		return

	def __destroy(self):
		self.__monitor.cancel()
		self.__editor.disconnect_signal(self.__sigid1, self.__manager)
		del self
		self = None
		return False

	def __get_path(self):
		from os.path import join
		folder = join(self.__editor.metadata_folder, "PluginPreferences")
		return join(folder, "TemplateIndentation.gdb")

	def __update(self):
		from Metadata import get_value
		self.__manager.emit("get-data", get_value())
		return False

	def __destroy_cb(self, *args):
		self.__destroy()
		return False

	def __update_cb(self, *args):
		monitor, gfile, otherfile, event = args
		if not (event in (0,2,3)): return False
		from gobject import idle_add
		idle_add(self.__update, priority=9999)
		return False
Exemplo n.º 27
0
    def __init__(self, g_file):
        self._folder = None
        self._loop = MainLoop()

        # Make the archive uri
        uri = g_file.get_uri()
        uri = 'archive://' + quote(uri, '')

        # Mount the archive if needed
        g_file = File(uri)
        # Already mounted ?
        if g_file.query_exists():
            self._folder = g_file
        else:
            mount_operation = MountOperation()
            mount_operation.set_anonymous(True)
            g_file.mount_enclosing_volume(mount_operation, self._mount_end)

            # Wait
            self._loop.run()
def get_python_title(uri):
    f = File(uri)
    title = f.get_basename()
    packages = []
    while True:
        f = f.get_parent()
        if not f: break
        
        if f.get_child('__init__.py').query_exists():
            packages.append(f.get_basename())
        else:
            break
            
    if packages:
        if title != '__init__.py':
            packages.insert(0, title.partition('.py')[0])
            
        return '.'.join(reversed(packages))
    else:
        return title
Exemplo n.º 29
0
class Listener(object):

	def __init__(self, manager, editor):
		self.__init_attributes(manager, editor)
		self.__sigid1 = editor.connect("quit", self.__quit_cb)
		self.__monitor.connect("changed", self.__changed_cb)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__editor = editor
		self.__view = editor.textview
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(manager.get_path("Font.gdb")).monitor_file(FILE_MONITOR_NONE, None)
		self.__manager = manager
		return

	def __destroy(self):
		self.__monitor.cancel()
		self.__editor.disconnect_signal(self.__sigid1, self.__editor)
		self.__editor.unregister_object(self)
		del self
		self = None
		return False

	def __update(self):
		from pango import FontDescription
		from SCRIBES.FontMetadata import get_value
		new_font = FontDescription(get_value(self.__manager.get_language()))
		self.__view.modify_font(new_font)
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __changed_cb(self, *args):
		monitor, gfile, otherfile, event = args
		if not (event in (0,2,3)): return False
		from gobject import idle_add
		idle_add(self.__update)
		return False
Exemplo n.º 30
0
class Listener(object):

	def __init__(self, manager, editor):
		self.__init_attributes(manager, editor)
		self.__sigid1 = editor.connect("quit", self.__quit_cb)
		self.__monitor.connect("changed", self.__changed_cb)
		editor.register_object(self)

	def __init_attributes(self, manager, editor):
		self.__editor = editor
		self.__manager = manager
		self.__view = editor.textview
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(manager.get_path("TextWrapping.gdb")).monitor_file(FILE_MONITOR_NONE, None)
		return

	def __destroy(self):
		self.__monitor.cancel()
		self.__editor.disconnect_signal(self.__sigid1, self.__editor)
		self.__editor.unregister_object(self)
		del self
		return False

	def __update(self):
		from gtk import WRAP_NONE, WRAP_WORD_CHAR
		from SCRIBES.TextWrappingMetadata import get_value
		wrap_mode = self.__view.set_wrap_mode
		wrap_mode(WRAP_WORD_CHAR) if get_value(self.__manager.get_language()) else wrap_mode(WRAP_NONE)
		return False

	def __quit_cb(self, *args):
		self.__destroy()
		return False

	def __changed_cb(self, *args):
		monitor, gfile, otherfile, event = args
		if not (event in (0,2,3)): return False
		from gobject import idle_add
		idle_add(self.__update)
		return False