答案1
我不确定它是否正确,但我正在使用类似这样的东西:
- 复选框:
def check_item_activated_callback (菜单项,a,b): 如果 menuitem.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) == Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED: menuitem.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED) 别的: menuitem.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED) check1 = Dbusmenu.Menuitem.new() check1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "复选框") check1.property_set(Dbusmenu.MENUITEM_PROP_TOGGLE_TYPE,Dbusmenu.MENUITEM_TOGGLE_CHECK) check1.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED) check1.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE,True) check1.connect(Dbusmenu.MENUITEM_SIGNAL_ITEM_ACTIVATED,check_item_activated_callback,无) qucklist.child_append (检查1)
- 单选按钮:
def radio_item_activated_callback (radioitem1, a,radioitem2): radioitem1.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED) radioitem2.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED) radio1 = Dbusmenu.Menuitem.new() radio1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "单选按钮 1") radio1.property_set (Dbusmenu.MENUITEM_PROP_TOGGLE_TYPE,Dbusmenu.MENUITEM_TOGGLE_RADIO) radio1.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED) radio1.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE,True) quicklist.child_append (radio1) radio2 = Dbusmenu.Menuitem.new() radio2.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "单选按钮 2") radio2.property_set (Dbusmenu.MENUITEM_PROP_TOGGLE_TYPE,Dbusmenu.MENUITEM_TOGGLE_RADIO) radio2.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE,Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED) radio2.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE,True) quicklist.child_append (radio2) radio1.connect(Dbusmenu.MENUITEM_SIGNAL_ITEM_ACTIVATED,radio_item_activated_callback,radio2) radio2.connect(Dbusmenu.MENUITEM_SIGNAL_ITEM_ACTIVATED,radio_item_activated_callback,radio1)
- 分隔符(又称“水平分隔符”):
分隔符 = Dbusmenu.Menuitem.new(); 分隔符.property_set(Dbusmenu.MENUITEM_PROP_TYPE,Dbusmenu.CLIENT_TYPES_SEPARATOR) 分隔符.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE,True) quicklist.child_append (分隔符)
- 启用/禁用菜单项:
item1 = Dbusmenu.Menuitem.new() item1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "项目已启用") item1.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE,True) item1.property_set_bool (Dbusmenu.MENUITEM_PROP_ENABLED,True) quicklist.child_append (项目1) item2 = Dbusmenu.Menuitem.new() item2.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "项目已禁用") item2.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE,True) item2.property_set_bool (Dbusmenu.MENUITEM_PROP_ENABLED,False) quicklist.child_append (项目2)
答案2
以下是制作复选框类型快速列表菜单项的示例:
# Create toggle-able menu item for urgency
urgent_menu_item = Dbusmenu.Menuitem.new ()
# Set the tab's name as the menu item's name
urgent_menu_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _('Urgent'))
# Make the menu item toggle-able
urgent_menu_item.property_set(Dbusmenu.MENUITEM_PROP_TOGGLE_TYPE, Dbusmenu.MENUITEM_TOGGLE_CHECK)
urgent_menu_item.property_set_int(Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED)
urgent_menu_item.connect('item_activated', self.urgent_menu_item_activated)
# Make the menu item visible
urgent_menu_item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
# Add the section's menu item to the Quicklist menu
quicklist.child_append(urgent_menu_item)
下面是制作 Radio 类型快捷列表菜单项的方法:
# Create a new item for this section
section_menu_item = Dbusmenu.Menuitem.new ()
# Set the tab's name as the menu item's name
section_menu_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, tab_name)
# Make the menu item toggle-able
section_menu_item.property_set(Dbusmenu.MENUITEM_PROP_TOGGLE_TYPE, Dbusmenu.MENUITEM_TOGGLE_RADIO)
# Make the menu item visible
section_menu_item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
# When the menu item is clicked, make it call menu_item_activated
# with the tab id, which is used to make that the active tab
section_menu_item.connect('item_activated', self.section_menu_item_activated, tab_id)
# Add the section's menu item to the Quicklist menu
quicklist.child_append(section_menu_item)