Exemple #1
0
    def onRunScript(self, evt):
        """ Save the script to temp dir, and run it."""
        ed = self.CurrentEditor
        fileDir = os.path.split(ed.FilePath)[0]
        if fileDir:
            os.chdir(fileDir)
        txt = ed.Text
        fname = getTempFile(ext="py")
        ed.saveFile(fname, force=True, isTmp=True)

        # Find out if we will use pythonw or just python:
        if "linux" in sys.platform:
            cmd = "python"
        else:
            cmd = "pythonw"
        if _Use_Subprocess:
            #The Echo hack:
            self.pgfEditor.SelectedPage.outputText = ""
            self.pgfEditor.SelectedPage.p = subprocess.Popen(
                (cmd, fname),
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
        else:
            # Use the old way
            os.system("%s %s" % (cmd, fname))
	def write(self):
		"""Write the report to a temporary file, and return the file name."""
		rw = self.ReportWriter
		rw.ReportFormFile = self.ReportForm
		rw.Cursor = self.DataSet
		f = rw.OutputFile = reportUtils.getTempFile()
		rw.write()
		return f
Exemple #3
0
	def onRunScript(self, evt):
		""" Save the script to temp dir, and run it."""
		ed = self.CurrentEditor
		fileDir = os.path.split(ed.FilePath)[0]
		if fileDir:
			os.chdir(fileDir)
		txt = ed.Text
		fname = getTempFile(ext="py")
		ed.saveFile(fname, force=True, isTmp=True)

		# Find out if we will use pythonw or just python:
		if "linux" in sys.platform:
			cmd = "python"
		else:
			cmd = "pythonw"
		if _Use_Subprocess:
			#The Echo hack:
			self.pgfEditor.SelectedPage.outputText = ""
			self.pgfEditor.SelectedPage.p = subprocess.Popen((cmd, fname),
					stdin=subprocess.PIPE,	stdout=subprocess.PIPE,
					stderr=subprocess.PIPE)
		else:
			# Use the old way
			os.system("%s %s" % (cmd, fname))
Exemple #4
0
    def onQuickReport(self, evt):
        # May not have records if called via toolbar button
        if not self.enableQuickReport():
            dabo.ui.exclaim(_("Sorry, there are no records to report on."),
                            title=_("No Records"))
            return

        showAdvancedQuickReport = self.ShowAdvancedQuickReport
        showExpandedQuickReport = self.ShowExpandedQuickReport

        class ReportFormatDialog(dabo.ui.dOkCancelDialog):
            def initProperties(self):
                self.Caption = "Quick Report"
                self.mode = None
                self.records = None
                self.saveNamedReportForm = False

            def addControls(self):
                self.addObject(dabo.ui.dRadioList,
                               RegID="radMode",
                               Caption="Mode",
                               Orientation="Row",
                               Choices=["List Format", "Expanded Format"],
                               ValueMode="Key",
                               Keys={
                                   "list": 0,
                                   "expanded": 1
                               },
                               SaveRestoreValue=True)
                self.Sizer.append1x(self.radMode)
                self.Sizer.appendSpacer(12)

                if not showExpandedQuickReport:
                    self.radMode.enableKey("expanded", False)
                    self.radMode.Value = "list"  ## in case the setting was saved at 'expanded' previously.

                self.addObject(
                    dabo.ui.dRadioList,
                    RegID="radRecords",
                    Caption="Report On",
                    Orientation="Row",
                    Choices=["All records in dataset", "Just current record"],
                    ValueMode="Key",
                    Keys={
                        "all": 0,
                        "one": 1
                    },
                    SaveRestoreValue=True)
                self.Sizer.append1x(self.radRecords)
                self.Sizer.appendSpacer(12)

                if showAdvancedQuickReport:
                    self.addObject(dabo.ui.dButton,
                                   RegID="btnAdvanced",
                                   Caption="Advanced")
                    self.Sizer.append(self.btnAdvanced, halign="center")
                    self.btnAdvanced.bindEvent(dEvents.Hit, self.onAdvanced)

            def onAdvanced(self, evt):
                if dabo.ui.areYouSure(
                        "Would you like to save the report form xml "
                        "(rfxml) to your application's reports directory? If you say "
                        "'yes', you'll be able to modify the file and it will be used "
                        "as the Quick Report from now on (it will no longer be auto-"
                        "generated). The file will be generated when you click 'Yes'."
                        "\n\nGenerate the report form file?",
                        cancelButton=False):
                    self.saveNamedReportForm = True

            def runOK(self):
                self.mode = self.radMode.Value
                self.records = self.radRecords.Value

        # Name the dialog unique to the active page, so that the user's settings
        # will save and restore uniquely. They may want to usually print just the
        # current record in expanded format when on the edit page, and a list
        # format otherwise, for example.
        name = "FrmQuickReport_%s" % self.PageFrame.SelectedPage.Caption
        d = ReportFormatDialog(self, NameBase=name)
        d.show()
        mode = d.mode
        records = d.records
        saveNamedReportForm = d.saveNamedReportForm
        d.release()

        if mode is not None:
            # Run the report
            biz = self.getBizobj()
            rfxml = self.getReportForm(mode)

            if saveNamedReportForm:
                filename = os.path.join(
                    self.Application.HomeDirectory, "reports",
                    "datanav-%s-%s.rfxml" % (biz.DataSource, mode))
                if not os.path.exists(
                        os.path.join(self.Application.HomeDirectory,
                                     "reports")):
                    os.mkdir(
                        os.path.join(self.Application.HomeDirectory,
                                     "reports"))
                open(filename, "w").write(rfxml)

            if records == "all":
                cursor = biz.getDataSet()
            else:
                cursor = biz.getDataSet(rowStart=biz.RowNumber, rows=1)
            outputfile = reportUtils.getTempFile()

            try:
                import dabo.dReportWriter as drw
            except ImportError:
                dabo.ui.stop(
                    "Error importing dReportWriter. Check your terminal output."
                )
                return

            rw = drw.dReportWriter(OutputFile=outputfile,
                                   ReportFormXML=rfxml,
                                   Cursor=cursor,
                                   Encoding=biz.Encoding)
            try:
                rw.write()
            except (UnicodeDecodeError, ), e:
                #error_string = traceback.format_exc()
                error_string = ustr(e)
                row_number = rw.RecordNumber
                dabo.ui.stop(
                    "There was a problem having to do with the Unicode encoding "
                    "of your table, and ReportLab's inability to deal with any encoding "
                    "other than UTF-8. Sorry, but currently we don't have a resolution to "
                    "the problem, other than to recommend that you convert your data to "
                    "UTF-8 encoding. Here's the exact error message received:\n\n%s"
                    "\n\nThis occurred in Record %s of your cursor." %
                    (ustr(e), row_number))
                return

            # Now, preview using the platform's default pdf viewer:
            reportUtils.previewPDF(outputfile)
Exemple #5
0
	def onQuickReport(self, evt):
		# May not have records if called via toolbar button
		if not self.enableQuickReport():
			dabo.ui.exclaim(_("Sorry, there are no records to report on."),
					title=_("No Records"))
			return

		showAdvancedQuickReport = self.ShowAdvancedQuickReport
		showExpandedQuickReport = self.ShowExpandedQuickReport

		class ReportFormatDialog(dabo.ui.dOkCancelDialog):
			def initProperties(self):
				self.Caption = "Quick Report"
				self.mode = None
				self.records = None
				self.saveNamedReportForm = False

			def addControls(self):
				self.addObject(dabo.ui.dRadioList, RegID="radMode",
						Caption="Mode",
						Orientation="Row",
						Choices=["List Format", "Expanded Format"],
						ValueMode="Key",
						Keys={"list":0, "expanded":1},
						SaveRestoreValue=True)
				self.Sizer.append1x(self.radMode)
				self.Sizer.appendSpacer(12)

				if not showExpandedQuickReport:
					self.radMode.enableKey("expanded", False)
					self.radMode.Value = "list"  ## in case the setting was saved at 'expanded' previously.

				self.addObject(dabo.ui.dRadioList, RegID="radRecords",
						Caption="Report On",
						Orientation="Row",
						Choices=["All records in dataset",
								"Just current record"],
						ValueMode="Key",
						Keys={"all":0, "one":1},
						SaveRestoreValue=True)
				self.Sizer.append1x(self.radRecords)
				self.Sizer.appendSpacer(12)

				if showAdvancedQuickReport:
					self.addObject(dabo.ui.dButton, RegID="btnAdvanced", Caption="Advanced")
					self.Sizer.append(self.btnAdvanced, halign="center")
					self.btnAdvanced.bindEvent(dEvents.Hit, self.onAdvanced)

			def onAdvanced(self, evt):
				if dabo.ui.areYouSure("Would you like to save the report form xml "
						"(rfxml) to your application's reports directory? If you say "
						"'yes', you'll be able to modify the file and it will be used "
						"as the Quick Report from now on (it will no longer be auto-"
						"generated). The file will be generated when you click 'Yes'."
						"\n\nGenerate the report form file?", cancelButton=False):
					self.saveNamedReportForm = True

			def runOK(self):
				self.mode = self.radMode.Value
				self.records = self.radRecords.Value

		# Name the dialog unique to the active page, so that the user's settings
		# will save and restore uniquely. They may want to usually print just the
		# current record in expanded format when on the edit page, and a list
		# format otherwise, for example.
		name = "FrmQuickReport_%s" % self.PageFrame.SelectedPage.Caption
		d = ReportFormatDialog(self, NameBase=name)
		d.show()
		mode = d.mode
		records = d.records
		saveNamedReportForm = d.saveNamedReportForm
		d.release()

		if mode is not None:
			# Run the report
			biz = self.getBizobj()
			rfxml = self.getReportForm(mode)

			if saveNamedReportForm:
				filename = os.path.join(self.Application.HomeDirectory, "reports",
						"datanav-%s-%s.rfxml" % (biz.DataSource, mode))
				if not os.path.exists(os.path.join(self.Application.HomeDirectory, "reports")):
					os.mkdir(os.path.join(self.Application.HomeDirectory, "reports"))
				open(filename, "w").write(rfxml)

			if records == "all":
				cursor = biz.getDataSet()
			else:
				cursor = biz.getDataSet(rowStart=biz.RowNumber, rows=1)
			outputfile = reportUtils.getTempFile()

			try:
				import dabo.dReportWriter as drw
			except ImportError:
				dabo.ui.stop("Error importing dReportWriter. Check your terminal output.")
				return

			rw = drw.dReportWriter(OutputFile=outputfile,
					ReportFormXML=rfxml,
					Cursor=cursor,
					Encoding=biz.Encoding)
			try:
				rw.write()
			except (UnicodeDecodeError,), e:
				#error_string = traceback.format_exc()
				error_string = ustr(e)
				row_number = rw.RecordNumber
				dabo.ui.stop("There was a problem having to do with the Unicode encoding "
						"of your table, and ReportLab's inability to deal with any encoding "
						"other than UTF-8. Sorry, but currently we don't have a resolution to "
						"the problem, other than to recommend that you convert your data to "
						"UTF-8 encoding. Here's the exact error message received:\n\n%s"
						"\n\nThis occurred in Record %s of your cursor." % (ustr(e), row_number))
				return

			# Now, preview using the platform's default pdf viewer:
			reportUtils.previewPDF(outputfile)