Beispiel #1
0
 def __get_uri(self, folder, fileinfo):
     from gio import File
     from os.path import join
     self.__editor.refresh(False)
     path = join(File(folder).get_path(), fileinfo.get_name())
     self.__editor.refresh(False)
     return File(path).get_uri()
def __new(uri):
	try:
		from gio import File
		if File(uri).get_uri_scheme() != "file": raise ValueError
		File(uri).replace_contents("")
	except ValueError:
		print "Error: %s is a remote file. Cannot create remote files from \
		terminal" % File(uri).get_path()
	except:
		print "Error: could not create %s" % File(uri).get_path()
	return uri
Beispiel #3
0
	def __process(self):
		uris = self.__editor.uris
		if not uris: return False
		get_mimetype = self.__editor.get_mimetype
		from gio import File, content_type_get_description as get_desc
		get_mime = lambda uri: get_desc(get_mimetype(uri)).split()[0].capitalize()
		get_filename = lambda uri: File(uri).get_basename()
		get_path = lambda uri: File(uri).get_parse_name()
		hfolder = self.__editor.home_folder
		format = lambda filename: filename.replace(hfolder, "~") if filename.startswith(hfolder) else filename
		def get_data(uri):
			return get_mime(uri), get_filename(uri), format(get_path(uri)), uri
		data = [get_data(uri) for uri in uris]
		self.__manager.emit("update", data)
		return False
Beispiel #4
0
 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
Beispiel #5
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
Beispiel #6
0
	def __init_attributes(self, manager, editor):
		self.__editor = editor
		self.__view = editor.textview
		self.__manager = manager
		from gio import File, FILE_MONITOR_NONE
		self.__monitor = File(manager.get_path("UseTabs.gdb")).monitor_file(FILE_MONITOR_NONE, None)
		return
Beispiel #7
0
	def __path_message(self):
		from gio import File
		path = File(self.__path).get_path()
		message = _("<span foreground='blue'><b>%s is the current search path</b></span>") % path
		self.__manager.emit("message", message)
		from gobject import timeout_add
		self.__timer3 = timeout_add(5000, self.__clear, "")
		return False
Beispiel #8
0
 def __enumerate(self, user_data):
     folder_uri, unique_id = user_data
     attributes = "standard::*"
     from gio import File
     File(folder_uri).enumerate_children_async(attributes,
                                               self.__enumerate_children_cb,
                                               user_data=user_data)
     return False
Beispiel #9
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
Beispiel #10
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
Beispiel #11
0
 def __send(self, folder):
     attributes = "standard::*"
     from gio import File
     File(folder).enumerate_children_async(attributes,
                                           self.__children_async_cb,
                                           cancellable=self.__cancellable,
                                           user_data=folder)
     return False
Beispiel #12
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
Beispiel #13
0
	def __replace(self, data):
		from gio import File, FILE_CREATE_NONE
		session_id, uri, encoding, text = data
		from glib import PRIORITY_DEFAULT
		File(uri).replace_async(self.__replace_async_cb,
			etag=None, make_backup=False, flags=FILE_CREATE_NONE,
			io_priority=PRIORITY_DEFAULT, cancellable=None, user_data=data)
		return False
Beispiel #14
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
Beispiel #15
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
Beispiel #16
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
Beispiel #17
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)
Beispiel #18
0
    def _get_g_file(self, uri):
        if type(uri) is not str:
            raise TypeError, 'unexpected "%s"' % repr(uri)

        # Your folder is None => new File
        if self._folder is None:
            return File(uri)

        # Your folder is not None, we must resolve 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:
            return File(uri)

        # Else we resolve the path
        return self._folder.resolve_relative_path(uri)
Beispiel #19
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
Beispiel #20
0
 def __update(self, parent=False):
     try:
         pwduri = self.__path if self.__path else self.__editor.pwd_uri
         from gio import File
         self.__path = File(
             pwduri).get_parent().get_uri() if parent else pwduri
         self.__manager.emit("current-path", self.__path)
     except AttributeError:
         pass
     return False
Beispiel #21
0
 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
Beispiel #22
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
Beispiel #23
0
 def __update(self):
     self.__remove_timer(1)
     if self.__folder_uri:
         from gio import File
         self.__show("in ../%s/" % File(self.__folder_uri).get_basename(),
                     True, False, "blue")
         from gobject import timeout_add
         self.__timer1 = timeout_add(10000, self.__hide)
     else:
         self.__hide()
     return False
Beispiel #24
0
 def __validate(self):
     uri = self.__chooser.get_uri()
     if not uri: return False
     from gio import File
     text = File(uri).get_basename()
     if not text: return False
     if "/" in text: return False
     if len(text) > 256: return False
     if self.__editor.uri_is_folder(uri): return False
     self.__manager.emit("rename")
     return False
        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,
            }
Beispiel #26
0
 def __print_settings_to_file(self):
     try:
         self.__print_settings = self.__operation.get_print_settings()
         from os.path import exists
         if not exists(self.__editor.print_settings_filename):
             raise AssertionError
     except AssertionError:
         from gio import File
         File(self.__editor.print_settings_filename).replace_contents("")
     finally:
         self.__print_settings.to_file(
             self.__editor.print_settings_filename)
     return False
Beispiel #27
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
    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
Beispiel #29
0
def replace_special_placeholder(placeholder, uri="", clipboards=None):
	from time import localtime
	if placeholder == "${day}":
		thetime = localtime()
		return pad_zero(thetime[2])
	if placeholder == "${month}":
		thetime = localtime()
		return pad_zero(thetime[1])
	if placeholder == "${year}":
		thetime = localtime()
		return pad_zero(thetime[0])
	if placeholder == "${date}":
		thetime = localtime()
		return "%s:%s:%s" % (pad_zero(thetime[0]), pad_zero(thetime[1]), pad_zero(thetime[2]))
	if placeholder == "${time}":
		thetime = localtime()
		return "%s:%s:%s" % (pad_zero(thetime[3]), pad_zero(thetime[4]), pad_zero(thetime[5]))
	if placeholder == "${timestring}":
		from time import ctime
		return ctime() # utils.py
	if placeholder == "${timestamp}":
		thetime = localtime()
		return "[%s-%s-%s] %s:%s:%s" % (thetime[0], pad_zero(thetime[1]), pad_zero(thetime[2]), pad_zero(thetime[3]), pad_zero(thetime[4]), pad_zero(thetime[5]))
	if placeholder == "${rfc2822}":
		from email.utils import formatdate
		return formatdate(localtime=1)        
	if placeholder == "${author}":
		return get_author_name()
	if placeholder == "${fileuri}": return uri if uri else ''
	from gio import File
	if placeholder == "${filepath}": return File(uri).get_path() if uri else ''
	if placeholder == "${filename}": return File(uri).get_basename() if uri else ""
	if placeholder == "${clipboard}":
		return clipboards['CLIPBOARD'].text_clip if clipboards and clipboards['CLIPBOARD'] and clipboards['CLIPBOARD'].text_clip else ''
	if placeholder == "${selection}":
		return clipboards['SELECTION'].text_clip if clipboards and clipboards['SELECTION'] and clipboards['SELECTION'].text_clip else ''
Beispiel #30
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)