class PopupMenuItem(MenuItem): def __init__(self, editor): MenuItem.__init__(self, _("Line En_dings")) self.__init_attributes(editor) self.__set_properties() self.__sigid1 = self.__menuitem1.connect("activate", self.__activate_cb) self.__sigid2 = self.__menuitem2.connect("activate", self.__activate_cb) self.__sigid3 = self.__menuitem3.connect("activate", self.__activate_cb) self.__sigid4 = editor.textview.connect("focus-in-event", self.__destroy_cb) def __init_attributes(self, editor): self.__editor = editor from gtk import Menu self.__menu = Menu() self.__menuitem1 = self.__editor.create_menuitem( _("Convert to _Unix (alt + 1)")) self.__menuitem2 = self.__editor.create_menuitem( _("Convert to _Mac (alt + 2)")) self.__menuitem3 = self.__editor.create_menuitem( _("Convert to _Windows (alt + 3)")) return def __set_properties(self): self.set_property("name", "Line Endings Popup MenuItem") self.set_submenu(self.__menu) self.__menu.append(self.__menuitem1) self.__menu.append(self.__menuitem2) self.__menu.append(self.__menuitem3) return def __activate_cb(self, menuitem): if menuitem == self.__menuitem1: self.__editor.trigger("line-endings-to-unix") elif menuitem == self.__menuitem2: self.__editor.trigger("line-endings-to-mac") else: self.__editor.trigger("line-endings-to-windows") return False def __destroy(self): self.__editor.disconnect_signal(self.__sigid1, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid2, self.__menuitem2) self.__editor.disconnect_signal(self.__sigid3, self.__menuitem3) self.__editor.disconnect_signal(self.__sigid4, self.__editor.textview) self.__menu.destroy() self.destroy() del self self = None return def __destroy_cb(self, *args): self.__destroy() return False
class PopupMenuItem(MenuItem): def __init__(self, editor): MenuItem.__init__(self, _("Line En_dings")) self.__init_attributes(editor) self.__set_properties() self.__sigid1 = self.__menuitem1.connect("activate", self.__activate_cb) self.__sigid2 = self.__menuitem2.connect("activate", self.__activate_cb) self.__sigid3 = self.__menuitem3.connect("activate", self.__activate_cb) self.__sigid4 = editor.textview.connect("focus-in-event", self.__destroy_cb) def __init_attributes(self, editor): self.__editor = editor from gtk import Menu self.__menu = Menu() self.__menuitem1 = self.__editor.create_menuitem(_("Convert to _Unix (alt + 1)")) self.__menuitem2 = self.__editor.create_menuitem(_("Convert to _Mac (alt + 2)")) self.__menuitem3 = self.__editor.create_menuitem(_("Convert to _Windows (alt + 3)")) return def __set_properties(self): self.set_property("name", "Line Endings Popup MenuItem") self.set_submenu(self.__menu) self.__menu.append(self.__menuitem1) self.__menu.append(self.__menuitem2) self.__menu.append(self.__menuitem3) return def __activate_cb(self, menuitem): if menuitem == self.__menuitem1: self.__editor.trigger("line-endings-to-unix") elif menuitem == self.__menuitem2: self.__editor.trigger("line-endings-to-mac") else: self.__editor.trigger("line-endings-to-windows") return False def __destroy(self): self.__editor.disconnect_signal(self.__sigid1, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid2, self.__menuitem2) self.__editor.disconnect_signal(self.__sigid3, self.__menuitem3) self.__editor.disconnect_signal(self.__sigid4, self.__editor.textview) self.__menu.destroy() self.destroy() del self self = None return def __destroy_cb(self, *args): self.__destroy() return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("Selection")) self.__init_attributes(editor) self.__creates_widgets() self.__set_properties() self.__signal_id_1 = self.select_word_menuitem.connect( "activate", self.__popup_activate_cb) self.__signal_id_2 = self.select_line_menuitem.connect( "activate", self.__popup_activate_cb) self.__signal_id_3 = self.select_sentence_menuitem.connect( "activate", self.__popup_activate_cb) self.__signal_id_4 = self.paragraph_item.connect( "activate", self.__popup_activate_cb) self.__signal_id_5 = self.select_word_menuitem.connect( "map-event", self.__popup_word_map_event_cb) self.__signal_id_6 = self.select_line_menuitem.connect( "map-event", self.__popup_line_map_event_cb) self.__signal_id_7 = self.select_sentence_menuitem.connect( "map-event", self.__popup_sentence_map_event_cb) self.__signal_id_9 = self.scribesview.connect("focus-in-event", self.__focus_in_event_cb) def __init_attributes(self, editor): self.scribesview = editor.textview self.editor = editor self.menu = None self.image = None self.select_word_menuitem = None self.select_line_menuitem = None self.select_sentence_menuitem = None return def __creates_widgets(self): from gtk import Image, STOCK_BOLD, Menu self.image = Image() self.image.set_property("stock", STOCK_BOLD) self.menu = Menu() self.select_word_menuitem = self.editor.create_menuitem( _("Select word (alt + w)")) self.select_line_menuitem = self.editor.create_menuitem( _("Select line (alt + l)")) self.select_sentence_menuitem = self.editor.create_menuitem( _("Select sentence (alt + s)")) self.paragraph_item = self.editor.create_menuitem( _("Select paragraph (alt + p)")) return def __set_properties(self): self.set_image(self.image) self.set_submenu(self.menu) self.menu.append(self.select_line_menuitem) self.menu.append(self.select_word_menuitem) self.menu.append(self.select_sentence_menuitem) self.menu.append(self.paragraph_item) if self.editor.readonly: self.set_property("sensitive", False) return def __popup_activate_cb(self, menuitem): if menuitem == self.select_word_menuitem: self.editor.trigger("select-word") elif menuitem == self.select_line_menuitem: self.editor.trigger("select-line") elif menuitem == self.select_sentence_menuitem: self.editor.trigger("select-sentence") elif menuitem == self.paragraph_item: self.editor.trigger("select-paragraph") return True def __popup_word_map_event_cb(self, menuitem, event): menuitem.set_property("sensitive", False) from word import inside_word, starts_word, ends_word cursor_position = self.editor.get_cursor_iterator() if inside_word(cursor_position) or starts_word( cursor_position) or ends_word(cursor_position): menuitem.set_property("sensitive", True) return True def __popup_line_map_event_cb(self, menuitem, event): menuitem.set_property("sensitive", False) from lines import get_line_bounds begin_position, end_position = get_line_bounds(self.editor.textbuffer) if not begin_position.get_char() in ["\n", "\x00"]: menuitem.set_property("sensitive", True) return True def __popup_sentence_map_event_cb(self, menuitem, event): menuitem.set_property("sensitive", False) cursor_position = self.editor.get_cursor_iterator() if cursor_position.starts_sentence() or cursor_position.ends_sentence( ) or cursor_position.inside_sentence(): menuitem.set_property("sensitive", True) return True def __focus_in_event_cb(self, event, textview): self.editor.disconnect_signal(self.__signal_id_1, self.select_word_menuitem) self.editor.disconnect_signal(self.__signal_id_2, self.select_line_menuitem) self.editor.disconnect_signal(self.__signal_id_3, self.select_sentence_menuitem) self.editor.disconnect_signal(self.__signal_id_4, self.select_sentence_menuitem) self.editor.disconnect_signal(self.__signal_id_5, self.select_word_menuitem) self.editor.disconnect_signal(self.__signal_id_6, self.select_line_menuitem) self.editor.disconnect_signal(self.__signal_id_7, self.select_sentence_menuitem) self.editor.disconnect_signal(self.__signal_id_9, self.scribesview) if self.select_word_menuitem: self.select_word_menuitem.destroy() if self.select_sentence_menuitem: self.select_sentence_menuitem.destroy() if self.select_line_menuitem: self.select_line_menuitem.destroy() if self.image: self.image.destroy() if self.menu: self.menu.destroy() del self self = None return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("_Case")) self.__init_attributes(editor) self.__set_properties() self.__sigid1 = self.__menuitem1.connect("activate", self.__activate_cb) self.__sigid2 = self.__menuitem2.connect("activate", self.__activate_cb) self.__sigid3 = self.__menuitem3.connect("activate", self.__activate_cb) self.__sigid4 = self.__menuitem1.connect("map-event", self.__map_event_cb) self.__sigid5 = self.__menuitem2.connect("map-event", self.__map_event_cb) self.__sigid6 = self.__menuitem3.connect("map-event", self.__map_event_cb) self.__sigid7 = self.__editor.textview.connect("focus-in-event", self.__focus_cb) def __init_attributes(self, editor): from gtk import Menu, Image, STOCK_SORT_DESCENDING self.__image = Image() self.__image.set_property("stock", STOCK_SORT_DESCENDING) self.__editor = editor self.__menu = Menu() self.__menuitem1 = editor.create_menuitem(_("_Togglecase (alt + u)")) self.__menuitem2 = editor.create_menuitem(_("_Titlecase (alt + shift + u)")) self.__menuitem3 = editor.create_menuitem(_("_Swapcase (alt + shift + l)")) return def __set_properties(self): self.set_property("name", "Case Popup MenuItem") self.set_image(self.__image) self.set_submenu(self.__menu) self.__menu.append(self.__menuitem1) self.__menu.append(self.__menuitem2) self.__menu.append(self.__menuitem3) if self.__editor.readonly: self.set_property("sensitive", False) return def __activate_cb(self, menuitem): if menuitem == self.__menuitem1: self.__editor.trigger("togglecase") elif menuitem == self.__menuitem2: self.__editor.trigger("titlecase") else: self.__editor.trigger("swapcase") return True def __map_event_cb(self, menuitem, event): return False def __focus_cb(self, textview, event): self.__editor.disconnect_signal(self.__sigid1, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid2, self.__menuitem2) self.__editor.disconnect_signal(self.__sigid3, self.__menuitem3) self.__editor.disconnect_signal(self.__sigid4, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid5, self.__menuitem2) self.__editor.disconnect_signal(self.__sigid6, self.__menuitem3) self.__editor.disconnect_signal(self.__sigid7, self.__editor.textview) self.__menu.destroy() self.__image.destroy() self.destroy() del self self = None return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("_Case")) self.__init_attributes(editor) self.__set_properties() self.__sigid1 = self.__menuitem1.connect("activate", self.__activate_cb) self.__sigid2 = self.__menuitem2.connect("activate", self.__activate_cb) self.__sigid3 = self.__menuitem3.connect("activate", self.__activate_cb) self.__sigid4 = self.__menuitem1.connect("map-event", self.__map_event_cb) self.__sigid5 = self.__menuitem2.connect("map-event", self.__map_event_cb) self.__sigid6 = self.__menuitem3.connect("map-event", self.__map_event_cb) self.__sigid7 = self.__editor.textview.connect("focus-in-event", self.__focus_cb) def __init_attributes(self, editor): from gtk import Menu, Image, STOCK_SORT_DESCENDING self.__image = Image() self.__image.set_property("stock", STOCK_SORT_DESCENDING) self.__editor = editor self.__menu = Menu() self.__menuitem1 = editor.create_menuitem(_("_Togglecase (alt + u)")) self.__menuitem2 = editor.create_menuitem( _("_Titlecase (alt + shift + u)")) self.__menuitem3 = editor.create_menuitem( _("_Swapcase (alt + shift + l)")) return def __set_properties(self): self.set_property("name", "Case Popup MenuItem") self.set_image(self.__image) self.set_submenu(self.__menu) self.__menu.append(self.__menuitem1) self.__menu.append(self.__menuitem2) self.__menu.append(self.__menuitem3) if self.__editor.readonly: self.set_property("sensitive", False) return def __activate_cb(self, menuitem): if menuitem == self.__menuitem1: self.__editor.trigger("togglecase") elif menuitem == self.__menuitem2: self.__editor.trigger("titlecase") else: self.__editor.trigger("swapcase") return True def __map_event_cb(self, menuitem, event): return False def __focus_cb(self, textview, event): self.__editor.disconnect_signal(self.__sigid1, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid2, self.__menuitem2) self.__editor.disconnect_signal(self.__sigid3, self.__menuitem3) self.__editor.disconnect_signal(self.__sigid4, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid5, self.__menuitem2) self.__editor.disconnect_signal(self.__sigid6, self.__menuitem3) self.__editor.disconnect_signal(self.__sigid7, self.__editor.textview) self.__menu.destroy() self.__image.destroy() self.destroy() del self self = None return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("Paragraph")) self.__init_attributes(editor) self.__set_properties() self.__sig_id_1 = self.__next_item.connect("activate", self.__activate_cb) self.__sig_id_2 = self.__previous_item.connect("activate", self.__activate_cb) self.__sig_id_3 = self.__reflow_item.connect("activate", self.__activate_cb) self.__sig_id_4 = editor.textview.connect("focus-in-event", self.__destroy_cb) self.__sig_id_5 = self.__select_item.connect("activate", self.__activate_cb) def __init_attributes(self, editor): from gtk import Menu, Image self.__editor = editor self.__menu = Menu() self.__image = Image() self.__previous_item = editor.create_menuitem( _("Previous Paragraph (alt + Right)")) self.__next_item = editor.create_menuitem( _("Next Paragraph (alt + Left)")) self.__reflow_item = editor.create_menuitem( _("Reflow Paragraph (alt + q)")) self.__select_item = editor.create_menuitem( _("Select Paragraph (alt + p)")) return def __set_properties(self): from gtk import STOCK_JUMP_TO self.__image.set_property("stock", STOCK_JUMP_TO) self.set_image(self.__image) self.set_submenu(self.__menu) self.__menu.append(self.__previous_item) self.__menu.append(self.__next_item) self.__menu.append(self.__reflow_item) self.__menu.append(self.__select_item) if self.__editor.readonly: self.__reflow_item.set_property("sensitive", False) return def __activate_cb(self, menuitem): if menuitem == self.__previous_item: self.__editor.trigger("previous-paragraph") elif menuitem == self.__next_item: self.__editor.trigger("next-paragraph") elif menuitem == self.__select_item: self.__editor.trigger("select-paragraph") else: self.__editor.trigger("reflow-paragraph") return False def __destroy_cb(self, *args): self.__editor.disconnect_signal(self.__sig_id_1, self.__next_item) self.__editor.disconnect_signal(self.__sig_id_2, self.__previous_item) self.__editor.disconnect_signal(self.__sig_id_3, self.__reflow_item) self.__editor.disconnect_signal(self.__sig_id_4, self.__editor.textview) self.__editor.disconnect_signal(self.__sig_id_5, self.__select_item) self.__next_item.destroy() self.__select_item.destroy() self.__previous_item.destroy() self.__reflow_item.destroy() self.__menu.destroy() self.__image.destroy() self.destroy() del self self = None return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("Paragraph")) self.__init_attributes(editor) self.__set_properties() self.__sig_id_1 = self.__next_item.connect("activate", self.__activate_cb) self.__sig_id_2 = self.__previous_item.connect("activate", self.__activate_cb) self.__sig_id_3 = self.__reflow_item.connect("activate", self.__activate_cb) self.__sig_id_4 = editor.textview.connect("focus-in-event", self.__destroy_cb) self.__sig_id_5 = self.__select_item.connect("activate", self.__activate_cb) def __init_attributes(self, editor): from gtk import Menu, Image self.__editor = editor self.__menu = Menu() self.__image = Image() self.__previous_item = editor.create_menuitem(_("Previous Paragraph (alt + Right)")) self.__next_item = editor.create_menuitem(_("Next Paragraph (alt + Left)")) self.__reflow_item = editor.create_menuitem(_("Reflow Paragraph (alt + q)")) self.__select_item = editor.create_menuitem(_("Select Paragraph (alt + p)")) return def __set_properties(self): from gtk import STOCK_JUMP_TO self.__image.set_property("stock", STOCK_JUMP_TO) self.set_image(self.__image) self.set_submenu(self.__menu) self.__menu.append(self.__previous_item) self.__menu.append(self.__next_item) self.__menu.append(self.__reflow_item) self.__menu.append(self.__select_item) if self.__editor.readonly: self.__reflow_item.set_property("sensitive", False) return def __activate_cb(self, menuitem): if menuitem == self.__previous_item: self.__editor.trigger("previous-paragraph") elif menuitem == self.__next_item: self.__editor.trigger("next-paragraph") elif menuitem == self.__select_item: self.__editor.trigger("select-paragraph") else: self.__editor.trigger("reflow-paragraph") return False def __destroy_cb(self, *args): self.__editor.disconnect_signal(self.__sig_id_1, self.__next_item) self.__editor.disconnect_signal(self.__sig_id_2, self.__previous_item) self.__editor.disconnect_signal(self.__sig_id_3, self.__reflow_item) self.__editor.disconnect_signal(self.__sig_id_4, self.__editor.textview) self.__editor.disconnect_signal(self.__sig_id_5, self.__select_item) self.__next_item.destroy() self.__select_item.destroy() self.__previous_item.destroy() self.__reflow_item.destroy() self.__menu.destroy() self.__image.destroy() self.destroy() del self self = None return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("Selection")) self.__init_attributes(editor) self.__creates_widgets() self.__set_properties() self.__signal_id_1 = self.select_word_menuitem.connect("activate", self.__popup_activate_cb) self.__signal_id_2 = self.select_line_menuitem.connect("activate", self.__popup_activate_cb) self.__signal_id_3 = self.select_sentence_menuitem.connect("activate", self.__popup_activate_cb) self.__signal_id_4 = self.paragraph_item.connect("activate", self.__popup_activate_cb) self.__signal_id_5 = self.select_word_menuitem.connect("map-event", self.__popup_word_map_event_cb) self.__signal_id_6 = self.select_line_menuitem.connect("map-event", self.__popup_line_map_event_cb) self.__signal_id_7 = self.select_sentence_menuitem.connect("map-event", self.__popup_sentence_map_event_cb) self.__signal_id_9 = self.scribesview.connect("focus-in-event", self.__focus_in_event_cb) def __init_attributes(self, editor): self.scribesview = editor.textview self.editor = editor self.menu = None self.image = None self.select_word_menuitem = None self.select_line_menuitem = None self.select_sentence_menuitem = None return def __creates_widgets(self): from gtk import Image, STOCK_BOLD, Menu self.image = Image() self.image.set_property("stock", STOCK_BOLD) self.menu = Menu() self.select_word_menuitem = self.editor.create_menuitem(_("Select word (alt + w)")) self.select_line_menuitem = self.editor.create_menuitem(_("Select line (alt + l)")) self.select_sentence_menuitem = self.editor.create_menuitem(_("Select sentence (alt + s)")) self.paragraph_item = self.editor.create_menuitem(_("Select paragraph (alt + p)")) return def __set_properties(self): self.set_image(self.image) self.set_submenu(self.menu) self.menu.append(self.select_line_menuitem) self.menu.append(self.select_word_menuitem) self.menu.append(self.select_sentence_menuitem) self.menu.append(self.paragraph_item) if self.editor.readonly: self.set_property("sensitive", False) return def __popup_activate_cb(self, menuitem): if menuitem == self.select_word_menuitem: self.editor.trigger("select-word") elif menuitem == self.select_line_menuitem: self.editor.trigger("select-line") elif menuitem == self.select_sentence_menuitem: self.editor.trigger("select-sentence") elif menuitem == self.paragraph_item: self.editor.trigger("select-paragraph") return True def __popup_word_map_event_cb(self, menuitem, event): menuitem.set_property("sensitive", False) from word import inside_word, starts_word, ends_word cursor_position = self.editor.get_cursor_iterator() if inside_word(cursor_position) or starts_word(cursor_position) or ends_word(cursor_position): menuitem.set_property("sensitive", True) return True def __popup_line_map_event_cb(self, menuitem, event): menuitem.set_property("sensitive", False) from lines import get_line_bounds begin_position, end_position = get_line_bounds(self.editor.textbuffer) if not begin_position.get_char() in ["\n", "\x00"]: menuitem.set_property("sensitive", True) return True def __popup_sentence_map_event_cb(self, menuitem, event): menuitem.set_property("sensitive", False) cursor_position = self.editor.get_cursor_iterator() if cursor_position.starts_sentence() or cursor_position.ends_sentence() or cursor_position.inside_sentence(): menuitem.set_property("sensitive", True) return True def __focus_in_event_cb(self, event, textview): self.editor.disconnect_signal(self.__signal_id_1, self.select_word_menuitem) self.editor.disconnect_signal(self.__signal_id_2, self.select_line_menuitem) self.editor.disconnect_signal(self.__signal_id_3, self.select_sentence_menuitem) self.editor.disconnect_signal(self.__signal_id_4, self.select_sentence_menuitem) self.editor.disconnect_signal(self.__signal_id_5, self.select_word_menuitem) self.editor.disconnect_signal(self.__signal_id_6, self.select_line_menuitem) self.editor.disconnect_signal(self.__signal_id_7, self.select_sentence_menuitem) self.editor.disconnect_signal(self.__signal_id_9, self.scribesview) if self.select_word_menuitem: self.select_word_menuitem.destroy() if self.select_sentence_menuitem: self.select_sentence_menuitem.destroy() if self.select_line_menuitem: self.select_line_menuitem.destroy() if self.image: self.image.destroy() if self.menu: self.menu.destroy() del self self = None return False