def add_package(self, button=None): if config.data.path['data']: d = config.data.path['data'] else: d = None filename, alias = dialog.get_filename( title=_("Choose the package to import, and its alias"), action=gtk.FILE_CHOOSER_ACTION_OPEN, button=gtk.STOCK_OPEN, default_dir=d, alias=True, filter='advene') if not filename: return True # p = advene.model.package.Package(uri=file_, importer=self.controller.package) i = advene.model.package.Import(parent=self.controller.package, uri=filename) i.setAlias(alias) self.controller.package.imports.append(i) # Update the ListStore self.ti.add_package(self.ti.store, package=i.package, alias=alias) return True
def insert_resource_data(self, widget, parent=None, title=None, filter=None): if title is None: title = _("Choose the file to insert") filename = dialog.get_filename(title=title, filter=filter) if filename is None: return True basename = os.path.basename(filename) id_ = re.sub('[^a-zA-Z0-9_.]', '_', basename) if id_ != basename: while True: id_ = dialog.entry_dialog( title=_("Select a valid identifier"), text= _("The filename %s contains invalid characters\nthat have been replaced.\nYou can modify this identifier if necessary:" ) % filename, default=id_) if id_ is None: # Edition cancelled return True elif re.match('^[a-zA-Z0-9_.]+$', id_): break self.do_insert_resource_file(parent=parent, filename=filename, id_=id_) return True
def csv_export(self, name=None): if name is None: name=dialog.get_filename(title=_("Export data to file..."), default_file="advene_data.csv", action=Gtk.FileChooserAction.SAVE, button=Gtk.STOCK_SAVE) if name is None: return True try: f=open(name, 'w', encoding='utf-8') except IOError as e: dialog.message_dialog(label=_("Error while exporting data to %(filename)s: %(error)s" % { 'filename': name, 'error': str(e), }), icon=Gtk.MessageType.ERROR) w=csv.writer(f) tv=self.widget.treeview store, paths=tv.get_selection().get_selected_rows() source=[ store.get_iter(p) for p in paths ] if not source: source=tv.get_model() w.writerow( (_("Element title"), _("Element type"), _("Element id")) ) for r in source: w.writerow( (str(r[COLUMN_CONTENT]).encode('utf-8'), str(r[COLUMN_TYPE]).encode('utf-8'), r[COLUMN_ID]) ) f.close() self.log(_("Data exported to %s") % name)
def csv_export(self, name=None): if name is None: name = dialog.get_filename(title=_("Export data to file..."), default_file="advene_data.csv", action=Gtk.FileChooserAction.SAVE, button=Gtk.STOCK_SAVE) if name is None: return True try: f = open(name, 'w', encoding='utf-8') except IOError as e: dialog.message_dialog(label=_( "Error while exporting data to %(filename)s: %(error)s" % { 'filename': name, 'error': str(e), }), icon=Gtk.MessageType.ERROR) w = csv.writer(f) tv = self.widget.treeview store, paths = tv.get_selection().get_selected_rows() source = [store.get_iter(p) for p in paths] if not source: source = tv.get_model() w.writerow((_("Element title"), _("Element type"), _("Element id"))) for r in source: w.writerow((str(r[COLUMN_CONTENT]).encode('utf-8'), str(r[COLUMN_TYPE]).encode('utf-8'), r[COLUMN_ID])) f.close() self.log(_("Data exported to %s") % name)
def save_transcription(self, button=None): fname = dialog.get_filename(title=("Save transcription to..."), action=Gtk.FileChooserAction.SAVE, button=Gtk.STOCK_SAVE) if fname is not None: self.save_output(filename=fname) return True return True
def save_transcription(self, button=None): fname = dialog.get_filename(title=("Save transcription to..."), action=gtk.FILE_CHOOSER_ACTION_SAVE, button=gtk.STOCK_SAVE) if fname is not None: self.save_output(filename=fname) return True return True
def save_transcription(self, button=None): fname=dialog.get_filename(title= ("Save transcription to..."), action=gtk.FILE_CHOOSER_ACTION_SAVE, button=gtk.STOCK_SAVE) if fname is not None: self.save_output(filename=fname) return True return True
def save_transcription(self, button=None): fname=dialog.get_filename(title= ("Save transcription to..."), action=Gtk.FileChooserAction.SAVE, button=Gtk.STOCK_SAVE) if fname is not None: self.save_output(filename=fname) return True return True
def load_transcription_cb(self, button=None): if not self.buffer_is_empty(): if not dialog.message_dialog(_("This will overwrite the current textual content. Are you sure?"), icon=Gtk.MessageType.QUESTION): return True fname=dialog.get_filename(title=_("Select transcription file to load"), default_dir=str(config.data.path['data'])) if fname is not None: self.load_transcription(filename=fname) return True
def filename_chooser(button): name = dialog.get_filename(title=_("Select destination"), action=Gtk.FileChooserAction.SAVE, button=Gtk.STOCK_SAVE, default_dir=str( config.data.path['data']), default_file=self.get_filename()) if name is not None: self.fname_label.set_label(name) return True
def select_file(self, button=None): mp=[ d for d in config.data.path['moviepath'].split(os.path.pathsep) if d != '_' ] if mp: default=mp[0] else: default=None fname = dialog.get_filename(title=_("Select a video file"), default_dir=default, filter='video') if fname is not None: self.set_file(fname) return True
def select_filename(b): if config.data.path['data']: d=config.data.path['data'] else: d=None filename=dialog.get_filename(title=_("Choose the file to import"), action=gtk.FILE_CHOOSER_ACTION_OPEN, button=gtk.STOCK_OPEN, default_dir=d, filter='any') if not filename: return True self.filename_entry.set_text(filename) return True
def select_file(self, button=None, *p): mp = [ d for d in config.data.path['moviepath'].split(os.path.pathsep) if d != '_' ] if mp: default = mp[0] else: default = None fname = dialog.get_filename(title=_("Select a video file"), default_dir=default, filter='video') if fname is not None: self.set_file(fname) return True
def csv_export(self, name=None): if name is None: name=dialog.get_filename(title=_("Export data to file..."), default_file="advene_data.csv", action=gtk.FILE_CHOOSER_ACTION_SAVE, button=gtk.STOCK_SAVE) if name is None: return True try: f=open(name, 'w') except IOError, e: dialog.message_dialog(label=_("Error while exporting data to %(filename)s: %(error)s" % { 'filename': name, 'error': unicode(e), }), icon=gtk.MESSAGE_ERROR)
def save_transcription_cb(self, button=None): if self.sourcefile: fname=self.sourcefile else: # Use current movie filename as basename default_name='transcribe.txt' l=self.controller.player.playlist_get_list() if l: default_name=os.path.splitext(os.path.basename(l[0]))[0] + ".txt" fname=dialog.get_filename(title= ("Save transcription to..."), action=gtk.FILE_CHOOSER_ACTION_SAVE, button=gtk.STOCK_SAVE, default_dir=config.data.path['data'], default_file=default_name ) if fname is not None: self.save_transcription(filename=fname) return True
def save_transcription_cb(self, button=None): if self.sourcefile: fname=self.sourcefile else: # Use current movie filename as basename default_name='transcribe.txt' uri = self.controller.player.get_uri() if uri: default_name=os.path.splitext(os.path.basename(uri))[0] + ".txt" fname=dialog.get_filename(title= ("Save transcription to..."), action=Gtk.FileChooserAction.SAVE, button=Gtk.STOCK_SAVE, default_dir=str(config.data.path['data']), default_file=default_name ) if fname is not None: self.save_transcription(filename=fname) return True
def insert_resource_data(self, widget, parent=None, title=None, filter=None): if title is None: title = _("Choose the file to insert") filename=dialog.get_filename(title=title, filter=filter) if filename is None: return True basename = os.path.basename(filename) id_=re.sub('[^a-zA-Z0-9_.]', '_', basename) if id_ != basename: while True: id_ = dialog.entry_dialog(title=_("Select a valid identifier"), text=_("The filename %s contains invalid characters\nthat have been replaced.\nYou can modify this identifier if necessary:") % filename, default=id_) if id_ is None: # Edition cancelled return True elif re.match('^[a-zA-Z0-9_.]+$', id_): break self.do_insert_resource_file(parent=parent, filename=filename, id_=id_) return True
def add_package(self, button=None): if config.data.path['data']: d=str(config.data.path['data']) else: d=None filename, alias=dialog.get_filename(title=_("Choose the package to import, and its alias"), action=Gtk.FileChooserAction.OPEN, button=Gtk.STOCK_OPEN, default_dir=d, alias=True, filter='advene') if not filename: return True # p = advene.model.package.Package(uri=file_, importer=self.controller.package) i = advene.model.package.Import(parent=self.controller.package, uri=filename) i.setAlias(alias) self.controller.package.imports.append(i) # Update the ListStore self.ti.add_package(self.ti.store, package=i.package, alias=alias) return True