Top > OOoPython > ContextMenuInterceptor

* ContextMenuInterceptor [#rdbf45a9]

ContextMenuInterceptor を Python から利用しようとすると項目の作成時に利用するデフォルトの css.ui.ActionTrigger サービスのインスタンスにプロパティ値を設定できません。バインディングとリフレクションの相性が悪いようです。
右クリックしたときのメニューを編集する ContextMenuInterceptor を Python から利用しようとすると項目の作成時に利用するデフォルトの css.ui.ActionTrigger サービスのインスタンスにプロパティ値を設定できません。バインディングとリフレクションの相性が悪いようです。

次のようにして Python のオブジェクトを渡してやります。


import uno
import unohelper

from import XContextMenuInterceptor
from import (
from import XPropertySet
from import XMultiServiceFactory, XServiceInfo
from import XIndexContainer, XContainer

class BaseServiceInfo(XServiceInfo):
	# XServiceInfo
	def getImplementationName(self):
		return self.IMPL_NAME
	def supportsService(self, name):
		return name == self.SERVICE_NAME
	def getSupportedServiceNames(self):
		return self.SERVICE_NAME,

class ActionTriggerContainer(unohelper.Base, BaseServiceInfo, XIndexContainer, XMultiServiceFactory):
	""" Provides container for items. """
	IMPL_NAME = "hoge"
	def __init__(self):
		self.items = []
	def append(self, item):
	# XMultiServiceFactory
	def createInstance(self, name):
	def createInstanceWithArguments(self, name, args):
	def getAvailableServiceNames(self):
		return ()
	# XIndexContainer
	def hasElements(self):
		return len(self.items) != 0
	def getElementType(self):
		return uno.Type("")
	def getCount(self):
		return len(self.items)
	def getByIndex(self, n):
		if 0 <= n < len(self.items):
			return self.items[n]
		return None # should be raise IllegalArgumentException
	def replaceByIndex(self, n, item):
		if 0 <= n < len(self.items):
			self.items[n] = item
	def insertByIndex(self, n, item):
		if 0 <= n <= len(self.items):
			self.items.insert(n, item)
	def removeByIndex(self, n):
		if 0 <= n < len(self.items):

class BasePropertySet(unohelper.Base, XPropertySet):
	# XPropertySet
	def addPropertyChangeListener(self, l): pass
	def removePropertyChangeListener(self, l): pass
	def addVetoableChangeListener(self, l): pass
	def removeVetoableChangeListener(self, l): pass
	def getPropertySetInfo(self): pass
	def setPropertyValue(self, name, value): pass
	def getPropertyValue(self, name): pass

class ActionTriggerItem(BasePropertySet, BaseServiceInfo, object):
	""" Provides item. """
	IMPL_NAME = "hoge"
	def __init__(self, command_url, text, help_url, sub_menu=None):
		self.command_url = command_url
		self.text = text
		self.help_url = help_url
		self.sub_menu = sub_menu
	def getPropertyValue(self, name):
		if name == "CommandURL":
			return self.command_url
		elif name == "Text":
			return self.text
		elif name == "HelpURL":
			return self.help_url
		elif name == "SubContainer":
			return self.sub_menu
			return None

from import LINE

class SheetTabContextMenuInterceptor(unohelper.Base, XContextMenuInterceptor):
	INSERT_SHEET = "slot:26269"
	def __init__(self, doc):
		self.doc = doc
	def notifyContextMenuExecute(self, ev):
		cont = ev.ActionTriggerContainer
		if cont.getByIndex(0).CommandURL == self.INSERT_SHEET:
			#item = cont.createInstance("")
			#item.SeparatorType = LINE
			#cont.insertByIndex(8, item)
			items = ActionTriggerContainer()
			items.insertByIndex(0, ActionTriggerItem(
				".uno:SelectTables", "Sheet...", 
				"", None))
			item = ActionTriggerItem("GoTo", "Go to", "123", items)
			cont.insertByIndex(7, item)
		return IGNORED

def register(*args):
	#ctx = XSCRIPTCONTEXT.getComponentContext()
	doc = XSCRIPTCONTEXT.getDocument()
	controller = doc.getCurrentController()


Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes