예제 #1
0
	def onSaveClassDesign(self, evt):
		"""Save the contents of the designer, excluding the outer form,
		as a separate class that can be used in other designs.
		"""
		# See if they want to save the entire contents of the form, or
		# just the current selection.
		class ClassScopeDialog(dabo.ui.dOkCancelDialog):
			def addControls(self):
				self.Caption = _("Save as Class")
				# This is the attribute used to determine their choice
				self.saveType = 0
				lbl = dabo.ui.dLabel(self, Caption=_("Do you want to save"))
				self.Sizer.append(lbl, halign="center")
				chc = [_("The contents of the form"), _("Just the current selection")]
				rgrp = dabo.ui.dRadioList(self, Choices=chc, DataSource=self,
						DataField="saveType", ValueMode="Position")
				self.Sizer.append(rgrp, halign="center")

		savType = None
		dlg = ClassScopeDialog(self)
		dlg.saveType = 1
		dlg.update()
		dlg.show()
		if dlg.Accepted:
			savType = dlg.saveType
		#dlg.release()
		if savType is None:
			return
		if savType == 0:
			# Entire contents; start with the mainPanel
			topObj = self.mainPanel
		else:
			topObj = self.Controller._selection[0]

		# Saving just a part of the design, so get the new file name
		clsFile = dabo.ui.getSaveAs(wildcard="cdxml")
		if not clsFile:
			# User canceled
			return
		else:
			if not os.path.splitext(clsFile)[1] == ".cdxml":
				clsFile += ".cdxml"

		# If there is a code editing form, flush the current page
		self.Controller.flushCodeEditor()
		topObj.__setattr__(classFlagProp, clsFile)
		propDict = self.getClassDesignerDict(topObj)
		xml = xtd.dicttoxml(propDict)
		# Try opening the file. If it is read-only, it will raise an
		# IOError that the calling method can catch.
		codecs.open(clsFile, "wb", encoding="utf-8").write(xml)
예제 #2
0
	def saveMenu(self):
		if not self._menuFile:
			self._menuFile = dabo.ui.getSaveAs(wildcard="mnxml")
			if not self._menuFile:
				# User canceled
				return
			else:
				if not os.path.splitext(self._menuFile)[1] == ".mnxml":
					self._menuFile += ".mnxml"
		propDict = self._getState()
		xml = xtd.dicttoxml(propDict)
		fname = self._menuFile
		# Try opening the file. If it is read-only, it will raise an
		# IOErrorrror that the calling method can catch.
		codecs.open(fname, "wb", encoding="utf-8").write(xml)
		self.saveState()
예제 #3
0
	def saveMenu(self):
		if not self._menuFile:
			self._menuFile = dabo.ui.getSaveAs(wildcard="mnxml")
			if not self._menuFile:
				# User canceled
				return
			else:
				if not os.path.splitext(self._menuFile)[1] == ".mnxml":
					self._menuFile += ".mnxml"
		propDict = self._getState()
		xml = xtd.dicttoxml(propDict)
		fname = self._menuFile
		# Try opening the file. If it is read-only, it will raise an
		# IOErrorrror that the calling method can catch.
		codecs.open(fname, "wb", encoding="utf-8").write(xml)
		self.saveState()
예제 #4
0
	def onSaveDesign(self, evt, useTmp=False):
		currForm = self.Controller.CurrentForm
		newFile = False

		# Replace this with a setting of some sort
		self.useJSON = False
		fileExt = {True: "json", False: "cdxml"}[self.useJSON]

		if useTmp:
			osp = os.path
			if self._classFile:
				loc = os.path.split(self._classFile)[0]
			else:
				loc = os.getcwd()
			fname = self.Application.getTempFile("cdxml", directory=loc)
		else:
			if not self._classFile:
				self._classFile = dabo.ui.getSaveAs(wildcard="cdxml")
				if not self._classFile:
					# User canceled
					return
				else:
					self._classFile = self._classFile.rstrip(".")
					if not self._classFile.endswith(".cdxml"):
						self._classFile += ".cdxml"
				newFile = True
			fname = self._classFile

		# If there is a code editing form, flush the current page
		self.Controller.flushCodeEditor()
		# Create the property dictionary
		if self._formMode:
			# Save the whole form
			propDict = self.getDesignerDict()
			propDictCompare = self.getDesignerDict(propsToExclude=("Top", "Left"))
		else:
			# The main object is the child of the main panel.
			obj = self.mainPanel.Children[0]
			# Make sure it has its class flag set
			obj.__setattr__(classFlagProp, self._classFile)
			self.Controller.saveAllProps = True
			propDict = propDictCompare = self.getClassDesignerDict(obj)
			self.Controller.saveAllProps = False

		if not useTmp and not newFile and (propDictCompare == self._savedState):
			return

		imp = self.Controller.getImportDict(self)
		if imp:
			cd = propDict.get("code", {})
			cd.update({"importStatements": imp})
			propDict["code"] = cd
		singleFile = useTmp or self.Application.getUserSetting("saveCodeInXML", False)
		if not singleFile:
			propDict, codeDict = self._extractCodeFromPropDict(propDict)
		if self.useJSON:
			textToSave = pformat(propDict)
		else:
			textToSave = xtd.dicttoxml(propDict)
		# Try opening the file. If it is read-only, it will raise an
		# IOErrorrror that the calling method can catch.
		codecs.open(fname, "wb", encoding="utf-8").write(textToSave)
		cfName = "%s-code.py" % os.path.splitext(fname)[0]
		if newFile:
			self.Controller.addMRUPath(fname)
		if singleFile:
			# Delete the code file if present.
			if os.path.exists(cfName):
				os.remove(cfName)
		else:
			# Write out the code file
			desCode = self._createDesignerCode(codeDict)
			codecs.open(cfName, "w", encoding="utf-8").write(desCode)
		if currForm:
			currForm.bringToFront()
		self.saveState()
		return fname
예제 #5
0
        print comment
        # found a badge object, copy it, shift it 288 points to the right.
        newobj=copy.deepcopy(obj)
        x = get_attrib_val(obj,'x')
        newx = "'%s pt'" % (pt2f(x)+288)
        set_attrib_val(newobj, 'x', newx )
        objs.append(newobj)

    if 260-115<=y<=260 and comment=="'copy biz'":
        print comment
        # found a ticket object, 
        # copy it into the other ticket locations (3x4 grid of 199x115 tickets)
        for row in range(4):
            for col in range(3):
                # 0,0 is the original, 
                # so don't make a 2nd copy of it.
                if (row,col)!=(0,0):
                    newobj=copy.deepcopy(obj)
                    x = get_attrib_val(obj,'x')
                    newx = "'%s pt'" % (pt2f(x)+199*col)
                    set_attrib_val(newobj, 'x', newx )
                    newy = "'%s pt'" % (y-115*row)
                    set_attrib_val(newobj, 'y', newy )
                    objs.append(newobj)

rfxml = xmltodict.dicttoxml(rfd)
open('badge_full.rfxml','w').write(rfxml)