def show_context_menu(self, event): selected_item = self.get_selected_item()[0] if selected_item.__class__.__name__ == "AssetCategory": context_menu = self.builder.get_object("asset_allocation_contextmenu") # accounts account_menu = self.builder.get_object("aa_add_account_menu") all_accounts = account.get_all_accounts() if all_accounts: account_menu.set_visible(True) menu = Gtk.Menu() account_menu.set_submenu(menu) for acc in all_accounts: if selected_item not in acc.asset_categories: item = Gtk.MenuItem(label=acc.name) item.connect("activate", self.on_aa_add_account, selected_item, acc) menu.append(item) # positions positions_menu = self.builder.get_object("aa_add_positions_menu") positions = position.get_all_portfolio_positions() if positions: positions_menu.set_visible(True) menu = Gtk.Menu() positions_menu.set_submenu(menu) for pos in positions: if pos.quantity > 0: item = Gtk.MenuItem(label=pos.asset.name) item.connect("activate", self.on_aa_add_position, selected_item, pos) menu.append(item) account_menu.show_all() else: context_menu = self.builder.get_object("asset_allocation_item_contextmenu") context_menu.show_all() context_menu.popup(None, None, None, None, event.button, event.time)
def __init__(self, pf, position=None): Gtk.ComboBox.__init__(self) cell = Gtk.CellRendererText() self.pack_start(cell, True) self.add_attribute(cell, 'text', 1) self.set_active(0) # self.set_button_sensitivity(GTK_SENSITIVITY_AUTO) liststore = Gtk.ListStore(object, str) liststore.append([-1, 'Select a position']) i = 1 if pf is not None: for pos in sorted(pf, key=lambda pos: pos.asset.name): if pos.quantity > 0: liststore.append([pos, str(pos.quantity) + ' ' + pos.asset.name]) if position and position == pos: self.set_active(i) i += 1 else: for pos in sorted(position_m.get_all_portfolio_positions(), key=lambda pos: pos.asset.name): if pos.quantity > 0: liststore.append([pos, pos.portfolio.name + ": " + str(pos.quantity) + ' ' + pos.asset.name]) self.set_model(liststore)