def __init__(self, main_gui_window, shareid, guiname, sharepath, fs_gui): self.fs_gui = fs_gui self.share = filesharing.get_share(shareid) if self.share == None: warning('Bad share in Edit_Metadata_Dialog %d\n' % shareid) return self.sharepath = sharepath self.meta = self.share.get_filemeta(self.sharepath, forceread=True) if self.meta == None: self.meta = Content_Meta() self.dialog = gtk.Dialog('Edit %s\'s Metadata' %(guiname), main_gui_window, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self.dialog.set_border_width(5) self.dialog.vbox.set_spacing(2) self.meta_widgets = {} self.initialize_widgets() self.dialog.connect("response", self.response_handler) self.dialog.show_all()
class Edit_Metadata_Dialog: def __init__(self, main_gui_window, shareid, guiname, sharepath, fs_gui): self.fs_gui = fs_gui self.share = filesharing.get_share(shareid) if self.share == None: warning('Bad share in Edit_Metadata_Dialog %d\n' % shareid) return self.sharepath = sharepath self.meta = self.share.get_filemeta(self.sharepath, forceread=True) if self.meta == None: self.meta = Content_Meta() self.dialog = gtk.Dialog('Edit %s\'s Metadata' %(guiname), main_gui_window, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self.dialog.set_border_width(5) self.dialog.vbox.set_spacing(2) self.meta_widgets = {} self.initialize_widgets() self.dialog.connect("response", self.response_handler) self.dialog.show_all() def response_handler(self, widget, event): if event == gtk.RESPONSE_OK: self.update_content_metadata() self.dialog.destroy() def initialize_widgets(self): main_vbox = gtk.VBox() meta_components = (('title', 'Title:'), ('keywords', 'Keywords:'), ('author', 'Author:'), ('year', 'Year:'), ('type', 'File type:'), ('description', 'Description:')) filetypes = ('application', 'audio', 'image', 'text', 'video') for (key, header) in meta_components: hbox = gtk.HBox() label = gtk.Label(header) label.set_size_request(150, -1) label.set_alignment(0, 0.5) hbox.pack_start(label, False, False) value = self.meta.get(key) text = '' if value != None: text = str(value) if key == 'type': # create dropdown box separately widget = gtk.combo_box_entry_new_text() for type in filetypes: widget.append_text(type) entry = widget.child entry.set_text(text) self.meta_widgets[key] = entry else: widget = gtk.Entry() widget.set_text(text) self.meta_widgets[key] = widget widget.set_size_request(250, -1) hbox.pack_start(widget, True, True) main_vbox.pack_start(hbox, False, False) self.dialog.vbox.add(main_vbox) def update_content_metadata(self): for (key, widget) in self.meta_widgets.items(): value = widget.get_text() if value == '': value = None self.meta.set(key, value) self.share.update_meta(self.sharepath, self.meta)