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
def createMenuHelp(self): menuHelp = MenuItem('_Help') menuHelpPop = Menu() self.menuAbout = ImageMenuItem(STOCK_ABOUT) menuHelpPop.append(self.menuAbout) menuHelp.set_submenu(menuHelpPop) return menuHelp
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, _("In_dentation")) 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.__textview.connect("focus-in-event", self.__focus_cb) def __init_attributes(self, editor): self.__editor = editor from gtk import STOCK_INDENT, STOCK_UNINDENT, Image, Menu self.__image = Image() self.__menu = Menu() self.__textview = editor.textview self.__menuitem1 = editor.create_menuitem(_("Shift _Right (ctrl + t)"), STOCK_INDENT) self.__menuitem2 = editor.create_menuitem( _("Shift _Left (ctrl + shift + t)"), STOCK_UNINDENT) return def __set_properties(self): self.set_property("name", "Indentation Popup MenuItem") from gtk import STOCK_JUSTIFY_CENTER self.__image.set_property("stock", STOCK_JUSTIFY_CENTER) self.set_image(self.__image) self.set_submenu(self.__menu) self.__menu.append(self.__menuitem1) self.__menu.append(self.__menuitem2) if self.__editor.readonly: self.set_property("sensitive", False) return def __activate_cb(self, menuitem): if menuitem == self.__menuitem1: self.__editor.trigger("indent") else: self.__editor.trigger("unindent") return True def __focus_cb(self, *args): self.__editor.disconnect_signal(self.__sigid1, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid2, self.__menuitem1) self.__editor.disconnect_signal(self.__sigid3, self.__textview) self.destroy() del self self = None return False
class PopupMenuItem(ImageMenuItem): def __init__(self, editor): ImageMenuItem.__init__(self, _("S_paces")) 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.__view.connect("focus-in-event", self.__destroy_cb) def __init_attributes(self, editor): self.__view = editor.textview self.__editor = editor from gtk import Menu, Image self.__menu = Menu() self.__image = Image() self.__menuitem1 = self.__editor.create_menuitem(_("_Tabs to Spaces (alt+shift+t)")) self.__menuitem2 = self.__editor.create_menuitem(_("_Spaces to Tabs (alt+t)")) self.__menuitem3 = self.__editor.create_menuitem(_("_Remove Trailing Spaces (alt+r)")) return def __set_properties(self): self.set_property("name", "Spaces 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("tabs-to-spaces") elif menuitem == self.__menuitem2: self.__editor.trigger("spaces-to-tabs") else: self.__editor.trigger("remove-trailing-spaces") return True def __destroy_cb(self, *args): 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.__view) self.destroy() del self self = None return False
def build_menu_radio_list(value_list, callback, pref_value=None, suffix=None, show_notset=False, notset_label='∞', notset_lessthan=0, show_other=False): """Build a menu with radio menu items from a list and connect them to the callback. Params: value_list [list]: List of values to build into a menu. callback (function): The function to call when menu item is clicked. pref_value (int): A preferred value to insert into value_list suffix (str): Append a suffix the the menu items in value_list. show_notset (bool): Show the unlimited menu item. notset_label (str): The text for the unlimited menu item. notset_lessthan (int): Activates the unlimited menu item if pref_value is less than this. show_other (bool): Show the `Other` menu item. The pref_value is what you would like to test for the default active radio item. Returns: gtk.Menu: The menu radio """ menu = Menu() group = None if pref_value > -1 and pref_value not in value_list: value_list.pop() value_list.append(pref_value) for value in sorted(value_list): item_text = str(value) if suffix: item_text += ' ' + suffix menuitem = RadioMenuItem(group=group, label=item_text) group = menuitem if pref_value and value == pref_value: menuitem.set_active(True) if callback: menuitem.connect('toggled', callback) menu.append(menuitem) if show_notset: menuitem = RadioMenuItem(group=group, label=notset_label) menuitem.set_name('unlimited') if pref_value and pref_value < notset_lessthan: menuitem.set_active(True) menuitem.connect('toggled', callback) menu.append(menuitem) if show_other: menuitem = SeparatorMenuItem() menu.append(menuitem) menuitem = MenuItem(_('Other...')) menuitem.set_name('other') menuitem.connect('activate', callback) menu.append(menuitem) return menu
def generate_menu(self): """Generates the checklist menu for all the tabs and attaches it""" menu = Menu() # Create 'All' menuitem and a separator menuitem = CheckMenuItem(self.translate_tabs['All'], True) menuitem.set_name('All') all_tabs = True for key in self.tabs: if not self.tabs[key].is_visible: all_tabs = False break menuitem.set_active(all_tabs) menuitem.connect('toggled', self._on_menuitem_toggled) menu.append(menuitem) menuitem = SeparatorMenuItem() menu.append(menuitem) # Create a list in order of tabs to create menu menuitem_list = [] for tab_name in self.tabs: menuitem_list.append((self.tabs[tab_name].weight, tab_name)) menuitem_list.sort() for pos, name in menuitem_list: menuitem = CheckMenuItem(self.translate_tabs[name], True) menuitem.set_name(name) menuitem.set_active(self.tabs[name].is_visible) menuitem.connect('toggled', self._on_menuitem_toggled) menu.append(menuitem) self.menu_tabs.set_submenu(menu) self.menu_tabs.show_all()
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
def build_menu_radio_list( value_list, callback, pref_value=None, suffix=None, show_notset=False, notset_label='∞', notset_lessthan=0, show_other=False, ): """Build a menu with radio menu items from a list and connect them to the callback. Params: value_list [list]: List of values to build into a menu. callback (function): The function to call when menu item is clicked. pref_value (int): A preferred value to insert into value_list suffix (str): Append a suffix the the menu items in value_list. show_notset (bool): Show the unlimited menu item. notset_label (str): The text for the unlimited menu item. notset_lessthan (int): Activates the unlimited menu item if pref_value is less than this. show_other (bool): Show the `Other` menu item. The pref_value is what you would like to test for the default active radio item. Returns: gtk.Menu: The menu radio """ menu = Menu() group = None if pref_value > -1 and pref_value not in value_list: value_list.pop() value_list.append(pref_value) for value in sorted(value_list): item_text = str(value) if suffix: item_text += ' ' + suffix menuitem = RadioMenuItem(group=group, label=item_text) group = menuitem if pref_value and value == pref_value: menuitem.set_active(True) if callback: menuitem.connect('toggled', callback) menu.append(menuitem) if show_notset: menuitem = RadioMenuItem(group=group, label=notset_label) menuitem.set_name('unlimited') if pref_value and pref_value < notset_lessthan: menuitem.set_active(True) menuitem.connect('toggled', callback) menu.append(menuitem) if show_other: menuitem = SeparatorMenuItem() menu.append(menuitem) menuitem = MenuItem(_('Other...')) menuitem.set_name('other') menuitem.connect('activate', callback) menu.append(menuitem) return menu
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, _("_Lines")) 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.__menuitem4.connect("activate", self.__activate_cb) self.__sigid5 = self.__menuitem5.connect("activate", self.__activate_cb) self.__sigid6 = self.__menuitem6.connect("activate", self.__activate_cb) self.__sigid7 = self.__menuitem7.connect("activate", self.__activate_cb) self.__sigid8 = self.__view.connect("focus-in-event", self.__destroy_cb) def __init_attributes(self, editor): self.__editor = editor self.__view = editor.textview from gtk import Menu, Image self.__menu = Menu() self.__image = Image() self.__menuitem1 = self.__editor.create_menuitem(_("_Join Line (alt + j)")) self.__menuitem2 = self.__editor.create_menuitem(_("D_uplicate Line (ctrl + u)")) self.__menuitem3 = self.__editor.create_menuitem(_("_Delete Line (alt + d)")) self.__menuitem4 = self.__editor.create_menuitem(_("Free Line _Below (alt + o)")) self.__menuitem5 = self.__editor.create_menuitem(_("Free Line _Above (alt + shift + o)")) self.__menuitem6 = self.__editor.create_menuitem(_("Delete Cursor to Line _End (alt + End)")) self.__menuitem7 = self.__editor.create_menuitem(_("Delete _Cursor to Line Begin (alt + Home)")) return def __set_properties(self): self.set_property("name", "Line Operation Menuitem") from gtk import STOCK_JUSTIFY_CENTER self.__image.set_property("stock", STOCK_JUSTIFY_CENTER) 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) self.__menu.append(self.__menuitem4) self.__menu.append(self.__menuitem5) self.__menu.append(self.__menuitem6) self.__menu.append(self.__menuitem7) if self.__editor.readonly: self.set_property("sensitive", False) return def __activate_cb(self, menuitem): if menuitem == self.__menuitem1: self.__editor.trigger("join-line") elif menuitem == self.__menuitem2: self.__editor.trigger("duplicate-line") elif menuitem == self.__menuitem3: self.__editor.trigger("delete-line") elif menuitem == self.__menuitem4: self.__editor.trigger("free-line-below") elif menuitem == self.__menuitem5: self.__editor.trigger("free-line-above") elif menuitem == self.__menuitem6: self.__editor.trigger("delete-cursor-to-end") elif menuitem == self.__menuitem7: self.__editor.trigger("delete-cursor-to-start") return True def __destroy_cb(self, *args): 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.__menuitem4) self.__editor.disconnect_signal(self.__sigid5, self.__menuitem5) self.__editor.disconnect_signal(self.__sigid6, self.__menuitem6) self.__editor.disconnect_signal(self.__sigid7, self.__menuitem7) self.__editor.disconnect_signal(self.__sigid8, self.__view) 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, _("_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
def createMenuFile(self): menuFile = MenuItem('_File') menuFilePop = Menu() self.menuNew = ImageMenuItem(STOCK_NEW) self.menuOpen = ImageMenuItem(STOCK_OPEN) self.menuClose = ImageMenuItem(STOCK_CLOSE) self.menuSave = ImageMenuItem(STOCK_SAVE) self.menuSaveAs = ImageMenuItem(STOCK_SAVE_AS) self.menuConvert = ImageMenuItem(STOCK_CONVERT) self.menuQuit = ImageMenuItem(STOCK_QUIT) menuFilePop.append(self.menuNew) menuFilePop.append(self.menuOpen) menuFilePop.append(self.menuClose) menuFilePop.append(SeparatorMenuItem()) menuFilePop.append(self.menuSave) menuFilePop.append(self.menuSaveAs) menuFilePop.append(self.menuConvert) menuFilePop.append(SeparatorMenuItem()) menuFilePop.append(self.menuQuit) menuFile.set_submenu(menuFilePop) return menuFile
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