# -*- coding: utf-8 -*-

import dabo
import dabo.dEvents as dEvents


class MenReports(dabo.ui.dMenu):

	def initProperties(self):
		super(MenReports, self).initProperties()
		self.Caption = "Re&ports"
		self.HelpText = "Run a report to screen or printer"
		self.MenuID = "reports"


	def afterInit(self):
		app = self.Application
		autoHotKeys = False

		# Define the forms you want in your report menu here. Insert a ("-", None)
		# tuple and the code below will insert a separator in its place. Explicitly
		# set up which character has the hotkey by adding a & in front of it and
		# by turning off the autoHotKeys flag. eg:
		forms = (("&Sample Report", app.ui.FrmReportSample),)

		for form in forms:
			caption = form[0]
			if caption == "-":
				# insert separator instead:
				self.appendSeparator()
			else:
				if autoHotKeys and "&" not in caption:
					caption = "&%%s" %% caption
				plainCaption = caption.replace("&", "")
				itm = dabo.ui.dMenuItem(self, Caption=caption,
						HelpText="Run the %%s report" %% plainCaption,
						Tag=form[1])
				itm.bindEvent(dEvents.Hit, self.openForm)
				self.appendItem(itm)


	def openForm(self, evt):
		app = self.Application
		mainForm = app.MainForm
		frm = evt.EventObject.Tag(mainForm)
		frm.show()
		frm.release()

