Ejemplo n.º 1
0
class ChatViewManager:
    def __init__(self):
        self.__app = GabberApp()
        self.__chats = {}
        self.__query = self.__app.session.registerXPath(
            "/message[@type='chat']", self.__on_chat_node)
        self.__menu_item = MenuItem("One-on-one _Chat...")
        self.__menu_item.connect("activate", self.__on_chat_menu_activate)
        Popups.User().addItem(self.__menu_item)

    def __del__(self):
        self.__app.session.unregisterXPath(self.__query)
        for chat in chats:
            del chat

    def __on_chat_node(self, node):
        msg_from = node.getAttrib("from")
        if not self.__chats.has_key(msg_from):
            self.__chats[msg_from] = ChatView(self, msg_from, node)

    def __on_chat_menu_activate(self, menu):
        to = Popups.User().getSelectedJID()
        if not self.__chats.has_key(to):
            self.__chats[to] = ChatView(self, to)

    def release(self, jid):
        del self.__chats[jid]
Ejemplo n.º 2
0
class ChatViewManager:
    def __init__(self):
        self.__app = GabberApp()
        self.__chats = {}
        self.__query = self.__app.session.registerXPath("/message[@type='chat']", self.__on_chat_node)
        self.__menu_item = MenuItem("One-on-one _Chat...")
        self.__menu_item.connect("activate", self.__on_chat_menu_activate)
        Popups.User().addItem(self.__menu_item)

    def __del__(self):
        self.__app.session.unregisterXPath(self.__query)
        for chat in chats:
            del chat

    def __on_chat_node(self, node):
        msg_from = node.getAttrib("from")
        if not self.__chats.has_key(msg_from):
            self.__chats[msg_from] = ChatView(self, msg_from, node)

    def __on_chat_menu_activate(self, menu):
        to = Popups.User().getSelectedJID()
        if not self.__chats.has_key(to):
            self.__chats[to] = ChatView(self, to)

    def release(self, jid):
        del self.__chats[jid]
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
	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)
Ejemplo n.º 5
0
 def __init__(self):
     self.__app = GabberApp()
     self.__chats = {}
     self.__query = self.__app.session.registerXPath(
         "/message[@type='chat']", self.__on_chat_node)
     self.__menu_item = MenuItem("One-on-one _Chat...")
     self.__menu_item.connect("activate", self.__on_chat_menu_activate)
     Popups.User().addItem(self.__menu_item)
Ejemplo n.º 6
0
 def add(self, label, function, menu=None):
     item = MenuItem(label)
     item.set_name(label)
     self.append(item)
     if menu:
         item.connect('activate', function, label, menu)
     else:
         item.connect('activate', function, label)
     item.show()
     self._menu_dict[label] = item
Ejemplo n.º 7
0
    def createMenuHelp(self):
        menuHelp = MenuItem('_Help')
        menuHelpPop = Menu()

        self.menuAbout = ImageMenuItem(STOCK_ABOUT)

        menuHelpPop.append(self.menuAbout)

        menuHelp.set_submenu(menuHelpPop)

        return menuHelp
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def add(self, label, function, menu=None):
     item = MenuItem(label)
     item.set_name(label)
     self.append(item)
     if menu:
         item.connect('activate', function, label, menu)
     else:
         item.connect('activate', function, label)
     item.show()
     self._menu_dict[label] = item
Ejemplo n.º 10
0
def create_menuitem(string, stock_id=None):
	from gtk import MenuItem, Image, HBox, Label
	hbox = HBox(spacing=7)
	hbox.set_property("border-width", 2)
	if stock_id:
		image = Image()
		image.set_property("stock", stock_id)
		hbox.pack_start(image, False, False, 0)
	label = Label(string)
	label.set_property("use-underline", True)
	hbox.pack_start(label, False, False, 0)
	menuitem = MenuItem()
	menuitem.add(hbox)
	return menuitem
Ejemplo n.º 11
0
 def __init__(self):
     self.__app = GabberApp()
     self.__chats = {}
     self.__query = self.__app.session.registerXPath("/message[@type='chat']", self.__on_chat_node)
     self.__menu_item = MenuItem("One-on-one _Chat...")
     self.__menu_item.connect("activate", self.__on_chat_menu_activate)
     Popups.User().addItem(self.__menu_item)
Ejemplo n.º 12
0
def populate_menu(mainmenu, section, commands, function):
    new_menu = SimpleMenu()
    section_item = MenuItem(section)
    section_item.set_name(section)
    section_item.show()
    section_item.set_submenu(new_menu)
    mainmenu.append(section_item)
    for command in commands:
        new_menu.add(command, function, section_item)
Ejemplo n.º 13
0
def populate_menu(mainmenu, section, commands, function):
    new_menu = SimpleMenu()
    section_item = MenuItem(section)
    section_item.set_name(section)
    section_item.show()
    section_item.set_submenu(new_menu)
    mainmenu.append(section_item)
    for command in commands:
        new_menu.add(command, function, section_item)
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
 def append(self, menu, name):
     item = MenuItem(name)
     item.show()
     item.set_submenu(menu)
     MenuBar.append(self, item)
     self._menu_dict[name] = menu
Ejemplo n.º 16
0
 def append(self, menu, name):
     item = MenuItem(name)
     item.show()
     item.set_submenu(menu)
     MenuBar.append(self, item)
     self._menu_dict[name] = menu