Beispiel #1
0
	def OnGraph(self, event):
		""" Graph button has been pressed.
		"""

		activePage = self.notebook.GetSelection()
		sheet = self.notebook.GetPage(activePage)
		title = self.notebook.GetPageText(activePage)

		### selected rows with mouse but on label colonn
		#selected_rows = sheet.GetSelectedRows()

		### really selected cells with mouse
		a = sheet.GetSelectionBlockTopLeft()
		b = sheet.GetSelectionBlockBottomRight()

		### selected rows with mouse
		try:
			i=a[0][0]
			j=b[0][0]
		### selected all rows
		except IndexError:
			i=0
			j=sheet.GetNumberRows()
		
		selected_rows = range(i,j)
		
		nbc = xrange(sheet.GetNumberCols())
		nbr = xrange(sheet.GetNumberRows()) if selected_rows == [] else selected_rows

		data = []
		for i in nbr:
			v = sheet.GetCellValue(i,sheet.GetNumberCols()-1)
			
			if '<<' in v or '>>' in v: 
				s = sheet.GetCellValue(i,sheet.GetNumberCols()-1).replace('<< ', '').replace('>>','') 
			else:
				s = "value = %s; time = %s"%(v,sheet.GetCellValue(i,0))

			### globals containt the time and value variables after exec of the statement
			exec(str(s), globals())

			if isinstance(value, list):
				data.append((time,float(value[0])))
			### first if int is digit or if float is digit
			elif str(value).isdigit() or str(value).replace(".", "", 1).isdigit():
				data.append((time,float(value)))
			else:
				wx.MessageBox(_('Type of data should be float or int : %s'%info), _('Info'))
				break
					
		if data != []:
			frame = StaticPlot(self, wx.ID_ANY, title, data)
			frame.Center()
			frame.Show()
Beispiel #2
0
    def OnGraph(self, event):
        """ Graph button has been pressed.
		"""

        activePage = self.notebook.GetSelection()
        sheet = self.notebook.GetPage(activePage)
        title = self.notebook.GetPageText(activePage)

        ### selected rows with mouse but on label colonn
        selected_rows = sheet.GetSelectedRows()

        ### really selected cells with mouse
        a = sheet.GetSelectionBlockTopLeft()
        b = sheet.GetSelectionBlockBottomRight()

        if a != [] and b != []:
            selected_rows = range(a[0][0], b[0][0])

        nbc = xrange(sheet.GetNumberCols())
        nbr = xrange(
            sheet.GetNumberRows()) if selected_rows == [] else selected_rows

        try:
            data = [[float(sheet.GetCellValue(r, c)) for c in nbc]
                    for r in nbr]
        except Exception, info:
            wx.MessageBox(_('Type of data should be float or int : %s' % info),
                          _('Info'))
Beispiel #3
0
	def OnSaveAs(self, event):
		""" SaveAs button has been pressed.
		"""
		wcd = _("DataSheet file (*.dat)|*.dat|All files (*)|*")
		home = HOME_PATH
		save_dlg = wx.FileDialog(self, message=_('Save file as...'), defaultDir=home, defaultFile='', wildcard=wcd, style=wx.SAVE | wx.OVERWRITE_PROMPT)
		if save_dlg.ShowModal() == wx.ID_OK:
			fn = save_dlg.GetFilename()

			activePage = self.notebook.GetSelection()
			sheet = self.notebook.GetPage(activePage)
			nbr = sheet.GetNumberRows()
			nbc = sheet.GetNumberCols()

			with open(fn,'w') as f:
				for row in xrange(nbr):
					f.write("%s %s\n"%(sheet.GetCellValue(row,0),sheet.GetCellValue(row,1)))
Beispiel #4
0
    def OnGraph(self, event):
        """ Graph button has been pressed.
		"""

        activePage = self.notebook.GetSelection()
        sheet = self.notebook.GetPage(activePage)
        title = self.notebook.GetPageText(activePage)

        ### selected rows with mouse but on label colonn
        #selected_rows = sheet.GetSelectedRows()

        ### really selected cells with mouse
        a = sheet.GetSelectionBlockTopLeft()
        b = sheet.GetSelectionBlockBottomRight()

        ### selected rows with mouse
        try:
            i = a[0][0]
            j = b[0][0]
        ### selected all rows
        except IndexError:
            i = 0
            j = sheet.GetNumberRows()

        selected_rows = list(range(i, j))

        nbc = range(sheet.GetNumberCols())
        nbr = range(
            sheet.GetNumberRows()) if selected_rows == [] else selected_rows

        data = []
        select = -1
        for i in nbr:
            v = sheet.GetCellValue(i, sheet.GetNumberCols() - 1)

            if '<<' in v or '>>' in v:
                s = sheet.GetCellValue(i,
                                       sheet.GetNumberCols() - 1).replace(
                                           '<< ',
                                           '').replace('<<', '').replace(
                                               '>>', '').replace('],', '];')
            else:
                s = "value = %s; time = %s" % (v, sheet.GetCellValue(i, 0))

            ### globals containt the time and value variables after exec of the statement
            exec(str(s), globals())

            ### if value is a list, we must choose an index to plot amoung the values of the list
            if isinstance(value, list):
                if select == -1:
                    dlg = wx.TextEntryDialog(
                        self,
                        _('Choose one index between [%d-%d] to plot into the list of values.'
                          ) % (0, len(value) - 1),
                        _('Plotting Manager'),
                        value="0")
                    if dlg.ShowModal() == wx.ID_OK:
                        select = int(dlg.GetValue())
                        dlg.Destroy()
                    else:
                        dlg.Destroy()
                        break

                ### choice is digit else we break
                if select in range(
                        0,
                        len(value) - 1) and not isinstance(value[select], str):
                    data.append((time, float(value[select])))
                else:
                    wx.MessageBox(_('Value to plot must be digit!'),
                                  _('Warning'), wx.OK | wx.ICON_WARNING)
                    break

            ### first if int is digit or if float is digit
            else:
                v = str(format(value, 'f')).lstrip('-')
                if v.isdigit() or v.replace(".", "", 1).isdigit():
                    data.append((time, float(value)))
                else:
                    wx.MessageBox(
                        _('Type of data should be float or int : %s') %
                        str(value), _('Info'))
                    break

        if data != []:
            frame = StaticPlot(self, wx.NewIdRef(), title, data)
            frame.Center()
            frame.Show()