def __init__(self, parent, can_change, library): super(AddTagDialog, self).__init__(title=_("Add a Tag"), transient_for=qltk.get_top_parent(parent), use_header_bar=True) self.set_border_width(6) self.set_resizable(False) self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL) add = self.add_icon_button(_("_Add"), Icons.LIST_ADD, Gtk.ResponseType.OK) self.vbox.set_spacing(6) self.set_default_response(Gtk.ResponseType.OK) table = Gtk.Table(n_rows=2, n_columns=2) table.set_row_spacings(12) table.set_col_spacings(6) table.set_border_width(6) self.__tag = (TagsComboBoxEntry() if can_change is True else TagsComboBox(can_change)) label = Gtk.Label() label.set_alignment(0.0, 0.5) label.set_text(_("_Tag:")) label.set_use_underline(True) label.set_mnemonic_widget(self.__tag) table.attach(label, 0, 1, 0, 1) table.attach(self.__tag, 1, 2, 0, 1) self.__val = Gtk.Entry() self.__val.set_completion(LibraryValueCompletion("", library)) label = Gtk.Label() label.set_text(_("_Value:")) label.set_alignment(0.0, 0.5) label.set_use_underline(True) label.set_mnemonic_widget(self.__val) valuebox = Gtk.EventBox() table.attach(label, 0, 1, 1, 2) table.attach(valuebox, 1, 2, 1, 2) hbox = Gtk.HBox() valuebox.add(hbox) hbox.pack_start(self.__val, True, True, 0) hbox.set_spacing(6) invalid = Gtk.Image.new_from_icon_name(Icons.DIALOG_WARNING, Gtk.IconSize.SMALL_TOOLBAR) hbox.pack_start(invalid, True, True, 0) self.vbox.pack_start(table, True, True, 0) self.get_child().show_all() invalid.hide() for entry in [self.__tag, self.__val]: entry.connect('changed', self.__validate, add, invalid, valuebox) self.__tag.connect('changed', self.__set_value_completion, library) self.__set_value_completion(self.__tag, library) if can_change is True: connect_obj(self.__tag.get_child(), 'activate', Gtk.Entry.grab_focus, self.__val)
def __init__(self, parent, can_change, library): super(AddTagDialog, self).__init__( title=_("Add a Tag"), transient_for=qltk.get_top_parent(parent), use_header_bar=True ) self.set_border_width(6) self.set_resizable(False) self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL) add = self.add_icon_button(_("_Add"), Icons.LIST_ADD, Gtk.ResponseType.OK) self.vbox.set_spacing(6) self.set_default_response(Gtk.ResponseType.OK) table = Gtk.Table(n_rows=2, n_columns=2) table.set_row_spacings(12) table.set_col_spacings(6) table.set_border_width(6) self.__tag = TagsComboBoxEntry() if can_change is True else TagsComboBox(can_change) label = Gtk.Label() label.set_alignment(0.0, 0.5) label.set_text(_("_Tag:")) label.set_use_underline(True) label.set_mnemonic_widget(self.__tag) table.attach(label, 0, 1, 0, 1) table.attach(self.__tag, 1, 2, 0, 1) self.__val = Gtk.Entry() self.__val.set_completion(LibraryValueCompletion("", library)) label = Gtk.Label() label.set_text(_("_Value:")) label.set_alignment(0.0, 0.5) label.set_use_underline(True) label.set_mnemonic_widget(self.__val) valuebox = Gtk.EventBox() table.attach(label, 0, 1, 1, 2) table.attach(valuebox, 1, 2, 1, 2) hbox = Gtk.HBox() valuebox.add(hbox) hbox.pack_start(self.__val, True, True, 0) hbox.set_spacing(6) invalid = Gtk.Image.new_from_icon_name(Icons.DIALOG_WARNING, Gtk.IconSize.SMALL_TOOLBAR) hbox.pack_start(invalid, True, True, 0) self.vbox.pack_start(table, True, True, 0) self.get_child().show_all() invalid.hide() for entry in [self.__tag, self.__val]: entry.connect("changed", self.__validate, add, invalid, valuebox) self.__tag.connect("changed", self.__set_value_completion, library) self.__set_value_completion(self.__tag, library) if can_change is True: connect_obj(self.__tag.get_child(), "activate", Gtk.Entry.grab_focus, self.__val)
def __init__(self, parent, can_change, library): super(AddTagDialog, self).__init__(_("Add a Tag"), qltk.get_top_parent(parent)) self.set_border_width(6) self.set_has_separator(False) self.set_resizable(False) self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) add = self.add_button(gtk.STOCK_ADD, gtk.RESPONSE_OK) self.vbox.set_spacing(6) self.set_default_response(gtk.RESPONSE_OK) table = gtk.Table(2, 2) table.set_row_spacings(12) table.set_col_spacings(6) table.set_border_width(6) self.__tag = TagsComboBoxEntry() if can_change == True else TagsComboBox(can_change) label = gtk.Label() label.set_alignment(0.0, 0.5) label.set_text(_("_Tag:")) label.set_use_underline(True) label.set_mnemonic_widget(self.__tag) table.attach(label, 0, 1, 0, 1) table.attach(self.__tag, 1, 2, 0, 1) self.__val = gtk.Entry() self.__val.set_completion(LibraryValueCompletion("", library)) label = gtk.Label() label.set_text(_("_Value:")) label.set_alignment(0.0, 0.5) label.set_use_underline(True) label.set_mnemonic_widget(self.__val) valuebox = gtk.EventBox() table.attach(label, 0, 1, 1, 2) table.attach(valuebox, 1, 2, 1, 2) hbox = gtk.HBox() valuebox.add(hbox) hbox.pack_start(self.__val) hbox.set_spacing(6) invalid = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_SMALL_TOOLBAR) hbox.pack_start(invalid) self.vbox.pack_start(table) self.child.show_all() invalid.hide() for entry in [self.__tag, self.__val]: entry.connect("changed", self.__validate, add, invalid, valuebox) self.__tag.connect("changed", self.__set_value_completion, library) self.__set_value_completion(self.__tag, library) if can_change == True: self.__tag.child.connect_object("activate", gtk.Entry.grab_focus, self.__val)
def __init__(self): super(PatternEditor, self).__init__(spacing=6) self.__headers = headers = {} buttons = [] group = None for tags in self.PRESETS: tied = "~" + "~".join(tags) group = Gtk.RadioButton(group=group, label="_" + util.tag(tied), use_underline=True) headers[group] = tags buttons.append(group) group = Gtk.RadioButton(group=group, label=_("_Custom"), use_underline=True) self.__custom = group headers[group] = [] buttons.append(group) button_box = Gtk.HBox(spacing=6) self.__model = model = Gtk.ListStore(str) radio_box = Gtk.VBox(spacing=6) for button in buttons: radio_box.pack_start(button, False, True, 0) button.connect('toggled', self.__toggled, button_box, model) self.pack_start(radio_box, False, True, 0) tooltip = _("Tag pattern with optional markup " "e.g. <tt>composer</tt> or\n<tt>%s</tt>" % escape(self._COMPLEX_PATTERN_EXAMPLE)) cb = TagsComboBoxEntry(self.COMPLETION, tooltip_markup=tooltip) view = BaseView(model=model) view.set_reorderable(True) view.set_headers_visible(False) ctrl_box = Gtk.VBox(spacing=6) add = Button(_("_Add"), Icons.LIST_ADD) ctrl_box.pack_start(add, False, True, 0) add.connect('clicked', self.__add, model, cb) remove = Button(_("_Remove"), Icons.LIST_REMOVE) ctrl_box.pack_start(remove, False, True, 0) remove.connect('clicked', self.__remove, view) selection = view.get_selection() selection.connect('changed', self.__selection_changed, remove) selection.emit('changed') sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.set_shadow_type(Gtk.ShadowType.IN) sw.add(view) edit_box = Gtk.VBox(spacing=6) edit_box.pack_start(cb, False, True, 0) edit_box.pack_start(sw, True, True, 0) button_box.pack_start(edit_box, True, True, 0) button_box.pack_start(ctrl_box, False, True, 0) self.pack_start(button_box, True, True, 0) render = Gtk.CellRendererText() render.set_property("editable", True) def edited_cb(render, path, text, model): model[path][0] = text render.connect("edited", edited_cb, model) column = Gtk.TreeViewColumn(None, render, text=0) view.append_column(column)
def __init__(self): super().__init__(spacing=12) self.__headers = headers = {} buttons = [] group = None for tags in self.PRESETS: tied = "~" + "~".join([t[0] for t in tags]) group = Gtk.RadioButton(group=group, label="_" + util.tag(tied), use_underline=True) headers[group] = tags buttons.append(group) group = Gtk.RadioButton(group=group, label=_("_Custom"), use_underline=True) self.__custom = group headers[group] = [] buttons.append(group) button_box = Gtk.HBox(spacing=6) self.__model = model = Gtk.ListStore(str, bool) radio_box = Gtk.VBox(spacing=6) for button in buttons: radio_box.pack_start(button, False, True, 0) button.connect('toggled', self.__toggled, button_box, model) self.pack_start(radio_box, False, True, 0) cb = TagsComboBoxEntry(self.COMPLETION) view = BaseView(model=model) view.set_reorderable(True) view.set_headers_visible(True) ctrl_box = Gtk.VBox(spacing=6) add = Button(_("_Add"), Icons.LIST_ADD) ctrl_box.pack_start(add, False, True, 0) add.connect('clicked', self.__add, model, cb) remove = Button(_("_Remove"), Icons.LIST_REMOVE) ctrl_box.pack_start(remove, False, True, 0) remove.connect('clicked', self.__remove, view) selection = view.get_selection() selection.connect('changed', self.__selection_changed, remove) selection.emit('changed') sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.set_shadow_type(Gtk.ShadowType.IN) sw.add(view) edit_box = Gtk.VBox(spacing=6) edit_box.pack_start(cb, False, True, 0) edit_box.pack_start(sw, True, True, 0) button_box.pack_start(edit_box, True, True, 0) button_box.pack_start(ctrl_box, False, True, 0) self.pack_start(button_box, True, True, 0) render = Gtk.CellRendererText() render.set_property("editable", True) def edited_cb(render, path, text, model): model[path][0] = text render.connect("edited", edited_cb, model) column = Gtk.TreeViewColumn(_("Tag"), render, text=0) column.set_expand(True) view.append_column(column) toggle = Gtk.CellRendererToggle() toggle.connect("toggled", self.__toggeled, model) toggle_column = Gtk.TreeViewColumn(_("Merge"), toggle, active=1) view.append_column(toggle_column)
class AddTagDialog(gtk.Dialog): def __init__(self, parent, can_change, library): super(AddTagDialog, self).__init__(_("Add a Tag"), qltk.get_top_parent(parent)) self.set_border_width(6) self.set_has_separator(False) self.set_resizable(False) self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) add = self.add_button(gtk.STOCK_ADD, gtk.RESPONSE_OK) self.vbox.set_spacing(6) self.set_default_response(gtk.RESPONSE_OK) table = gtk.Table(2, 2) table.set_row_spacings(12) table.set_col_spacings(6) table.set_border_width(6) self.__tag = TagsComboBoxEntry() if can_change == True else TagsComboBox(can_change) label = gtk.Label() label.set_alignment(0.0, 0.5) label.set_text(_("_Tag:")) label.set_use_underline(True) label.set_mnemonic_widget(self.__tag) table.attach(label, 0, 1, 0, 1) table.attach(self.__tag, 1, 2, 0, 1) self.__val = gtk.Entry() self.__val.set_completion(LibraryValueCompletion("", library)) label = gtk.Label() label.set_text(_("_Value:")) label.set_alignment(0.0, 0.5) label.set_use_underline(True) label.set_mnemonic_widget(self.__val) valuebox = gtk.EventBox() table.attach(label, 0, 1, 1, 2) table.attach(valuebox, 1, 2, 1, 2) hbox = gtk.HBox() valuebox.add(hbox) hbox.pack_start(self.__val) hbox.set_spacing(6) invalid = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_SMALL_TOOLBAR) hbox.pack_start(invalid) self.vbox.pack_start(table) self.child.show_all() invalid.hide() for entry in [self.__tag, self.__val]: entry.connect("changed", self.__validate, add, invalid, valuebox) self.__tag.connect("changed", self.__set_value_completion, library) self.__set_value_completion(self.__tag, library) if can_change == True: self.__tag.child.connect_object("activate", gtk.Entry.grab_focus, self.__val) def __set_value_completion(self, tag, library): completion = self.__val.get_completion() if completion: completion.set_tag(self.__tag.tag, library) def get_tag(self): try: return self.__tag.tag except AttributeError: return self.__tag.tag def get_value(self): return self.__val.get_text().decode("utf-8") def __validate(self, editable, add, invalid, box): tag = self.get_tag() value = self.get_value() fmt = massagers.tags.get(tag) if fmt: valid = fmt.is_valid(value) else: valid = True add.set_sensitive(valid) if valid: invalid.hide() box.set_tooltip_text(None) else: invalid.show() box.set_tooltip_text(fmt.error) def run(self): self.show() self.__val.set_activates_default(True) self.__tag.grab_focus() return super(AddTagDialog, self).run()