Beispiel #1
0
    def EnableGraphIcon(self, msg):
        """ Enable graph button when loadin data is finished and clear the statusbar.
		"""

        ### update the column width
        activePage = self.notebook.GetSelection()
        sheet = self.notebook.GetPage(activePage)
        sheet.UpdateColWidth()

        toolbar = self.GetToolBar()
        toolbar.EnableTool(self.chart.GetId(), msg.data)
        self.statusbar.SetStatusText("", 0)
Beispiel #2
0
    def EnableGraphIcon(self, msg):
        """ Enable graph button when loading data is finished and clear the statusbar.
		"""

        ### update the column width
        try:
            activePage = self.notebook.GetSelection()
        except Exception as info:
            activePage = 0
            sys.stdout.write(_("Error in SpreadSheet: %s" % info))

        try:
            sheet = self.notebook.GetPage(activePage)
            sheet.UpdateColWidth()
        except Exception as info:
            sys.stdout.write(_("Error in SpreadSheet: %s" % info))
        else:
            toolbar = self.GetToolBar()
            toolbar.EnableTool(self.chart.GetId(), msg)
            printOnStatusBar(self.statusbar, {0: ""})
Beispiel #3
0
 def OnTab(self, event):
     ### update the column width
     activePage = self.notebook.GetSelection()
     sheet = self.notebook.GetPage(activePage)
     sheet.UpdateColWidth()
Beispiel #4
0
class Newt(wx.Frame):
	"""
	"""

	###
	def __init__(self, parent, id, title, aDEVS, separator=" "):
		""" Constructor
		"""

		wx.Frame.__init__(self,
						parent,
						wx.ID_ANY,
						aDEVS.getBlockModel().label,
						size = (550, 500),
						style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)

		self.model = aDEVS
		self.sep = separator

		### toolbar setting
		toolbar = wx.ToolBar(self, wx.ID_ANY, style= wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
		toolbar.SetToolBitmapSize((25,25)) # just for windows
		new = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'new.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('New'), '')
		open_file = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'open.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Open'), '')
		saveas = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'save.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('SaveAs'), '')
		toolbar.AddSeparator()
		cut = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'cut.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Cut'), '')
		copy = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'copy.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Copy'), '')
		paste = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'paste.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Paste'), '')
		self.delete = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'close.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Delete'), '')
		toolbar.AddSeparator()
		update = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'reload.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Update'), '')
		toolbar.AddSeparator()
		self.chart = toolbar.AddSimpleTool(wx.NewId(), wx.Image(os.path.join(ICON_PATH,'graph_guru.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), _('Chart'), '')
		toolbar.EnableTool(self.chart.GetId(), False)
		toolbar.Realize()

		self.SetToolBar(toolbar)

		self.statusbar = self.CreateStatusBar()

		### notebook setting
		self.notebook = wx.Notebook(self, wx.ID_ANY)

		### Load data form devs model
		self.LoadingDataInPage()

		### Layout
		box = wx.BoxSizer(wx.VERTICAL)
		box.Add(self.notebook, 1, wx.EXPAND)
		self.SetSizer(box)

		### binding
		self.Bind(wx.EVT_TOOL, self.OnNew, new)
		self.Bind(wx.EVT_TOOL, self.OnOpen, open_file)
		self.Bind(wx.EVT_TOOL, self.OnSaveAs, saveas)
		self.Bind(wx.EVT_TOOL, self.OnCopy, copy)
		self.Bind(wx.EVT_TOOL, self.OnCut, cut)
		self.Bind(wx.EVT_TOOL, self.OnPaste, paste)
		self.Bind(wx.EVT_TOOL, self.OnDelete, self.delete)
		self.Bind(wx.EVT_TOOL, self.OnUpdate, update)
		self.Bind(wx.EVT_TOOL, self.OnGraph, self.chart)

		self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnTab, self.notebook)

		### pubsub
		### when is sheet is full, graph icon is enabled
		Publisher.subscribe(self.EnableGraphIcon, "isfull")
		Publisher.subscribe(self.OnProgress, "progress")

	###
	def LoadingDataInPage(self):

		### read and load the data in sheet
		for i in xrange(len(self.model.IPorts)):
			fn = "%s%d.dat"%(self.model.fileName, i)
			if os.path.exists(fn):
				iPort = self.model.IPorts[i]
				if iPort.inLine != []:
					oPort = iPort.inLine[0]
					host = oPort.host if hasattr(oPort, 'host') else oPort.hostDEVS
					label = _('%s (on in_%s)')%(host.getBlockModel().label if hasattr(host, 'getBlockModel') else host.name, str(iPort.myID) if hasattr(iPort,'myID') else iPort.name)
					data = self.FileToData(fn, self.sep)
					self.AddPage(data, label)

	###
	def OnUpdate(self, event):

		### remove all pages
		while self.notebook.GetPageCount() >= 1:
			self.notebook.RemovePage(self.notebook.GetSelection())

		### reload all page
		self.LoadingDataInPage()

	###
	def FileToData(self, fn, separator):
		""" Create data from file.
		"""
		with open(fn, 'r') as f:
			if separator != "":
				data = map(lambda a: a.replace('\n','').split(separator), f.readlines())
			else:
				L = f.readlines()
				index = iter(range(len(L)))
				data = map(lambda a:  (index.next(), a.replace('\n','')), L)

		return data

	###
	def EnableGraphIcon(self, msg):
		""" Enable graph button when loading data is finished and clear the statusbar.
		"""

		### update the column width
		try:
			activePage = self.notebook.GetSelection()
		except Exception, info:
			activePage = 0
			sys.stdout.write(_("Error in SpreadSheet: %s"%info))

		try:
			sheet = self.notebook.GetPage(activePage)
			sheet.UpdateColWidth()
		except Exception, info:
			sys.stdout.write(_("Error in SpreadSheet: %s"%info))