def __init__(self, name): gobject.GObject.__init__(self) uri = gnomevfs.make_uri_from_shell_arg(name) gnomevfs.monitor_add(uri, gnomevfs.MONITOR_FILE, self._on_monitor) self.name = name
def open(self): if not self.monitor: if self.type == gnomevfs.FILE_TYPE_DIRECTORY: monitor_type = gnomevfs.MONITOR_DIRECTORY else: monitor_type = gnomevfs.MONITOR_FILE self.monitor = gnomevfs.monitor_add(self.path, monitor_type, self._queue_event)
def __init__(self): UITricks.__init__(self, 'ui/webilder_desktop.glade', 'WebilderDesktopWindow') self.sort_combo.set_active(1) # date renderer = gtk.CellRendererText() self.tree.append_column( column=gtk.TreeViewColumn("Album", renderer, markup=0)) self.tree.columns_autosize() self.load_collection_tree(config.get('collection.dir')) self.iconview.set_pixbuf_column(IV_PIXBUF_COLUMN) self.iconview.set_markup_column(IV_TEXT_COLUMN) self.on_iconview_handle_selection_changed(self.iconview) self.collection_monitor = dict(monitor=None, dir=None) self.image_popup = ImagePopup(self) self.download_dialog = None if gnomevfs: self.tree_monitor = gnomevfs.monitor_add( config.get('collection.dir'), gnomevfs.MONITOR_DIRECTORY, self.collection_tree_changed) self.restore_window_state() self.top_widget.show_all() self.hand_cursor = gtk.gdk.Cursor(gtk.gdk.HAND2)
def __init__(self): UITricks.__init__(self, 'ui/webilder_desktop.glade', 'WebilderDesktopWindow') self.sort_combo.set_active(1) # date renderer = gtk.CellRendererText() self.tree.append_column( column=gtk.TreeViewColumn("Album", renderer, markup=0)) self.tree.columns_autosize() self.load_collection_tree(config.get('collection.dir')) self.iconview.set_pixbuf_column(IV_PIXBUF_COLUMN) self.iconview.set_markup_column(IV_TEXT_COLUMN) self.on_iconview_handle_selection_changed(self.iconview) self.collection_monitor = dict(monitor=None, dir=None) self.image_popup = ImagePopup(self) self.download_dialog = None if gnomevfs: self.tree_monitor = gnomevfs.monitor_add( config.get('collection.dir'), gnomevfs.MONITOR_DIRECTORY, self.collection_tree_changed) self.restore_window_state() self.top_widget.show_all() self.hand_cursor = gtk.gdk.Cursor(gtk.gdk.HAND2)
def file_monitor(file, callback): "Starts monitoring a file" try: return gnomevfs.monitor_add(file_normpath(file), gnomevfs.MONITOR_FILE, callback) except gnomevfs.NotSupportedError: return None
def load_collection(self, images, monitor_dir=None): """Loads a list of images into the photo browser.""" model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT) image_list = [] for image in images: dirname, filename = os.path.split(image) basename, ext = os.path.splitext(filename) thumb = os.path.join(dirname, '.thumbs', basename + '.thumbnail' + ext) info_file = os.path.join(dirname, basename) + '.inf' inf = infofile.parse_info_file(info_file) title = inf.get('title', basename) album = inf.get('albumTitle', dirname) credit = inf.get('credit', _('Not available')) tags = inf.get('tags', '') title = html_escape(title) album = html_escape(album) credit = html_escape(credit) tags = html_escape(tags) data = dict(title=title, filename=image, thumb=thumb, inf=inf, info_file=info_file, album=album, tags=tags, file_time=os.path.getctime(image), credit=credit) if len(title) > 24: title = title[:21] + '...' if 0 <= time.time() - os.path.getmtime(image) < 24 * 3600: title = _('<b>*New* %s</b>') % title position = model.append((title, EMPTY_PICTURE, data)) image_list.append(dict(position=position, data=data)) old_model = self.iconview.get_model() if old_model is not None: old_model.clear() self.sort_photos(model) self.iconview.set_model(model) gobject.idle_add( ThumbLoader(self.iconview, model, reversed(image_list))) self.on_iconview_handle_selection_changed(self.iconview) if gnomevfs: if self.collection_monitor['monitor'] is not None: gobject.idle_add(gnomevfs.monitor_cancel, self.collection_monitor['monitor']) self.collection_monitor = dict(monitor=None, dir=None) if monitor_dir: self.collection_monitor['dir'] = monitor_dir self.collection_monitor['monitor'] = gnomevfs.monitor_add( monitor_dir, gnomevfs.MONITOR_DIRECTORY, self.collection_directory_changed) gc.collect()
def add(self, folder, monitorType): if self._id != None: gnomevfs.monitor_cancel(self._id) self._id = None try: self._id = gnomevfs.monitor_add(folder, monitorType, self._monitor_cb) except gnomevfs.NotSupportedError: # silently fail if we are looking at a folder that doesn't support directory monitoring self._id = None
def main(): parser = optparse.OptionParser("%prog src dest") options, args = parser.parse_args() if len(args) != 2: parser.error("Insufficient arguments") src = args[0].rstrip("/") dest = args[1] if os.path.isdir(src): # i.e. like -a but not recursive if call(["rsync", "-lptgoDdvz", src + "/", dest]) != 0: sys.exit(0) gnomevfs.monitor_add(os.path.abspath(src), gnomevfs.MONITOR_DIRECTORY, callback, dest) else: if call(["rsync", "-avz", src, dest]) != 0: sys.exit(0) gnomevfs.monitor_add(os.path.abspath(src), gnomevfs.MONITOR_FILE, callback, dest) try: gobject.MainLoop().run() except KeyboardInterrupt: pass
def delete_files(main_window, forever): """Delete the selected files.""" iconview = main_window.iconview selected = iconview.get_selected_items() if selected and len(selected)>1: if forever: message = _('Would you like to permanently delete the ' 'selected images?') else: message = _('Would you like to delete the selected images?') dlg = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format=message) response = dlg.run() dlg.destroy() if response != gtk.RESPONSE_YES: return banned = open(os.path.expanduser('~/.webilder/banned_photos'), 'a') model = iconview.get_model() monitor = main_window.collection_monitor if monitor['monitor'] is not None: gnomevfs.monitor_cancel(monitor['monitor']) monitor['monitor'] = None for path in selected: iterator = model.get_iter(path) data = model.get_value(iterator, IV_DATA_COLUMN) for fname in (data['filename'], data['info_file'], data['thumb']): try: os.remove(fname) except (IOError, OSError): pass if forever: banned.write(os.path.basename(data['filename'])+'\n') model.remove(iterator) if monitor['dir']: monitor['monitor'] = gnomevfs.monitor_add( monitor['dir'], gnomevfs.MONITOR_DIRECTORY, main_window.collection_directory_changed) banned.close()
def delete_files(main_window, forever): """Delete the selected files.""" iconview = main_window.iconview selected = iconview.get_selected_items() if selected and len(selected) > 1: if forever: message = _('Would you like to permanently delete the ' 'selected images?') else: message = _('Would you like to delete the selected images?') dlg = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format=message) response = dlg.run() dlg.destroy() if response != gtk.RESPONSE_YES: return banned = open(os.path.expanduser('~/.webilder/banned_photos'), 'a') model = iconview.get_model() monitor = main_window.collection_monitor if monitor['monitor'] is not None: gnomevfs.monitor_cancel(monitor['monitor']) monitor['monitor'] = None for path in selected: iterator = model.get_iter(path) data = model.get_value(iterator, IV_DATA_COLUMN) for fname in (data['filename'], data['info_file'], data['thumb']): try: os.remove(fname) except (IOError, OSError): pass if forever: banned.write(os.path.basename(data['filename']) + '\n') model.remove(iterator) if monitor['dir']: monitor['monitor'] = gnomevfs.monitor_add( monitor['dir'], gnomevfs.MONITOR_DIRECTORY, main_window.collection_directory_changed) banned.close()
def __init__(self): self.scanStack = [] self.allvfs = {} self.inv_dirs = set() from tortoisehg.util import menuthg self.hgtk = paths.find_in_path(thg_main) self.menu = menuthg.menuThg() self.notify = os.path.expanduser('~/.tortoisehg/notify') try: f = open(self.notify, 'w') f.close() ds_uri = gnomevfs.get_uri_from_local_path(self.notify) self.gmon = gnomevfs.monitor_add(ds_uri, gnomevfs.MONITOR_FILE, self.notified) except (gnomevfs.NotSupportedError, IOError), e: debugf('no notification because of %s', e) self.notify = ''
def load_collection(self, images, monitor_dir=None): """Loads a list of images into the photo browser.""" model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT) image_list = [] for image in images: dirname, filename = os.path.split(image) basename, ext = os.path.splitext(filename) thumb = os.path.join(dirname, '.thumbs', basename+'.thumbnail'+ext) info_file = os.path.join(dirname, basename)+'.inf' try: fileobj = open(info_file, 'r') inf = wbz.parse_metadata(fileobj.read()) fileobj.close() except IOError: inf = {} title = inf.get('title', basename) album = inf.get('albumTitle', dirname) credit = inf.get('credit', _('Not available')) tags = inf.get('tags', '') title = html_escape(title) album = html_escape(album) credit = html_escape(credit) tags = html_escape(tags) data = dict(title=title, filename=image, thumb=thumb, info_file=info_file, inf = inf, album = album, tags = tags, file_time = os.path.getctime(image), credit = credit) if len(title)>24: title = title[:21] + '...' if 0 <= time.time() - os.path.getmtime(image) < 24*3600: title = _('<b>*New* %s</b>') % title position = model.append((title, EMPTY_PICTURE, data)) image_list.append(dict( position=position, data=data)) old_model = self.iconview.get_model() if old_model is not None: old_model.clear() self.sort_photos(model) self.iconview.set_model(model) gobject.idle_add(ThumbLoader(self.iconview, model, reversed(image_list))) self.on_iconview_handle_selection_changed(self.iconview) if gnomevfs: if self.collection_monitor['monitor'] is not None: gobject.idle_add(gnomevfs.monitor_cancel, self.collection_monitor['monitor']) self.collection_monitor = dict(monitor=None, dir=None) if monitor_dir: self.collection_monitor['dir'] = monitor_dir self.collection_monitor['monitor'] = gnomevfs.monitor_add( monitor_dir, gnomevfs.MONITOR_DIRECTORY, self.collection_directory_changed) gc.collect()
def __init__(self, path, montype, cb): super(GnomeVfsMonitor, self).__init__() self.__path = path self.__cb = cb self.__idle_id = 0 self.__monid = gnomevfs.monitor_add(path, montype, self.__on_vfsmon)
def __init__(self, path, montype, cb): super(GnomeVfsMonitor, self).__init__() self.__path = path self.__cb = cb self.__idle_id = 0 self.__monid = gnomevfs.monitor_add(path, montype, self.__on_vfsmon)