Skip to content

Commit 7775fcb

Browse files
committed
Build popup menu from available column actions
1 parent da34a34 commit 7775fcb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Form/entrygrid.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ def got_focus(self, entry, event, row):
160160
self.selected = self.model.get_iter((row,))
161161
self.indicators[row].set_active(True)
162162

163+
def activate_action(self, widget, row, column, action):
164+
pass
165+
166+
def populate_popup(self, entry, menu, row, column):
167+
if self.actions[column - 1]:
168+
action_id = 0
169+
for action in self.actions[column - 1]:
170+
action_menuitem = Gtk.MenuItem(label=action.title)
171+
# add the action if there is no 'enable_if' expression or the result of eval(action.enable_if) is True (or convertible to True)
172+
if action.enable_if is None or eval(action.enable_if):
173+
action_menuitem.connect('activate', self.activate_action, row, column, action)
174+
action_menuitem.show_all()
175+
menu.insert(action_menuitem, action_id)
176+
action_id += 1
177+
if action_id:
178+
separator = Gtk.SeparatorMenuItem()
179+
separator.show_all()
180+
menu.insert(separator, action_id)
181+
163182
def changed(self, entry, row, column):
164183
set_size(entry)
165184
self.model.handler_block(self.sig_id)

0 commit comments

Comments
 (0)