stepconf.py

来自「CNC 的开放码,EMC2 V2.2.8版」· Python 代码 · 共 1,576 行 · 第 1/4 页

PY
1,576
字号
	print >>file, _("Generated by stepconf at %s") % time.asctime()	file.close()	self.add_md5sum(filename)    def copy(self, base, filename):	dest = os.path.join(base, filename)	if not os.path.exists(dest):	    shutil.copy(os.path.join(distdir, filename), dest)    def save(self):	base = os.path.expanduser("~/emc2/configs/%s" % self.machinename)	makedirs(base)	self.md5sums = []	self.write_readme(base)	self.write_inifile(base)	self.write_halfile(base)	self.copy(base, "emc.nml")	self.copy(base, "tool.tbl")	self.copy(base, "emc.var")	filename = "%s.stepconf" % base	d = xml.dom.minidom.getDOMImplementation().createDocument(                            None, "stepconf", None)        e = d.documentElement	for k, v in sorted(self.__dict__.iteritems()):	    if k.startswith("_"): continue            n = d.createElement('property')            e.appendChild(n)            if isinstance(v, float): n.setAttribute('type', 'float')            elif isinstance(v, bool): n.setAttribute('type', 'bool')            elif isinstance(v, int): n.setAttribute('type', 'int')            elif isinstance(v, list): n.setAttribute('type', 'eval')            else: n.setAttribute('type', 'string')            n.setAttribute('name', k)            n.setAttribute('value', str(v))        d.writexml(open(filename, "wb"), addindent="  ", newl="\n")    def __getitem__(self, item):	return getattr(self, item)    def __setitem__(self, item, value):	return setattr(self, item, value)class App:    fname = 'stepconf.glade'  # XXX search path    def _getwidget(self, doc, id):	for i in doc.getElementsByTagName('widget'):	    if i.getAttribute('id') == id: return i    def make_axispage(self, doc, axisname):	axispage = self._getwidget(doc, 'xaxis').parentNode.cloneNode(True)	nextpage = self._getwidget(doc, 'spindle').parentNode	widget = self._getwidget(axispage, "xaxis")	for node in widget.childNodes:	    if (node.nodeType == xml.dom.Node.ELEMENT_NODE		    and node.tagName == "property"		    and node.getAttribute('name') == "title"):		node.childNodes[0].data = _("%s Axis Configuration") % axisname.upper()	for node in axispage.getElementsByTagName("widget"):	    id = node.getAttribute('id')	    if id.startswith("x"):		node.setAttribute('id', axisname + id[1:])	    else:		node.setAttribute('id', axisname + id)	for node in axispage.getElementsByTagName("signal"):	    handler = node.getAttribute('handler')	    node.setAttribute('handler', handler.replace("on_x", "on_" + axisname))	for node in axispage.getElementsByTagName("property"):	    name = node.getAttribute('name')	    if name == "mnemonic_widget":		node.childNodes[0].data = axisname + node.childNodes[0].data[1:]	nextpage.parentNode.insertBefore(axispage, nextpage)    def __init__(self):	gnome.init("stepconf", "0.6") 	glade = xml.dom.minidom.parse(os.path.join(datadir, self.fname))	self.make_axispage(glade, 'y')	self.make_axispage(glade, 'z')	self.make_axispage(glade, 'a')	doc = glade.toxml().encode("utf-8")	self.xml = gtk.glade.xml_new_from_buffer(doc, len(doc), domain="axis")	self.widgets = Widgets(self.xml)        self.watermark = gtk.gdk.pixbuf_new_from_file(wizard)	self.widgets.dialog1.hide()	self.widgets.druidpagestart1.show()        self.widgets.druidpagestart1.set_watermark(self.watermark)	self.widgets.complete.show()        self.widgets.complete.set_watermark(self.watermark)		self.xml.signal_autoconnect(self)	self.in_pport_prepare = False	self.axis_under_test = False        self.jogminus = self.jogplus = 0	self.data = Data()    def gtk_main_quit(self, *args):	gtk.main_quit()    def on_window1_delete_event(self, *args):        dialog = gtk.MessageDialog(self.widgets.window1,	    gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,	    gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,		 _("Quit Stepconf and discard changes?"))	dialog.show_all()	result = dialog.run()	dialog.destroy()	if result == gtk.RESPONSE_YES:	    gtk.main_quit()	    return False	else:	    return True    on_druid1_cancel = on_window1_delete_event    def on_page_newormodify_next(self, *args):	if not self.widgets.createconfig.get_active():	    filter = gtk.FileFilter()	    filter.add_pattern("*.stepconf")	    filter.set_name(_("EMC2 'stepconf' configuration files"))	    dialog = gtk.FileChooserDialog(_("Modify Existing Configuration"),		self.widgets.window1, gtk.FILE_CHOOSER_ACTION_OPEN,		(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,		 gtk.STOCK_OPEN, gtk.RESPONSE_OK))	    dialog.set_default_response(gtk.RESPONSE_OK)	    dialog.add_filter(filter) 	    dialog.add_shortcut_folder(os.path.expanduser("~/emc2/configs"))	    dialog.set_current_folder(os.path.expanduser("~/emc2/configs"))	    dialog.show_all()	    result = dialog.run()	    if result == gtk.RESPONSE_OK:		filename = dialog.get_filename()		dialog.destroy()		self.data.load(filename, self)	    else:		dialog.destroy()		return True    def on_basicinfo_prepare(self, *args):	self.widgets.machinename.set_text(self.data.machinename)	self.widgets.axes.set_active(self.data.axes)	self.widgets.units.set_active(self.data.units)	self.widgets.latency.set_value(self.data.latency)	self.widgets.steptime.set_value(self.data.steptime)	self.widgets.stepspace.set_value(self.data.stepspace)	self.widgets.dirsetup.set_value(self.data.dirsetup)	self.widgets.dirhold.set_value(self.data.dirhold)	self.widgets.drivertype.set_active(self.data.drivertype)	self.widgets.manualtoolchange.set_active(self.data.manualtoolchange)	self.widgets.ioaddr.set_text(self.data.ioaddr)	self.widgets.machinename.grab_focus()    def on_basicinfo_next(self, *args):	self.data.machinename = self.widgets.machinename.get_text()	self.data.axes = self.widgets.axes.get_active()	self.data.units = self.widgets.units.get_active()	self.data.drivertype = self.widgets.drivertype.get_active()	self.data.steptime = self.widgets.steptime.get_value()	self.data.stepspace = self.widgets.stepspace.get_value()	self.data.dirsetup = self.widgets.dirsetup.get_value()	self.data.dirhold = self.widgets.dirhold.get_value()	self.data.latency = self.widgets.latency.get_value()	self.data.manualtoolchange = self.widgets.manualtoolchange.get_active()	self.data.ioaddr = self.widgets.ioaddr.get_text()    def on_machinename_changed(self, *args):	self.widgets.confdir.set_text(	    "~/emc2/configs/%s" % self.widgets.machinename.get_text())    def on_drivertype_changed(self, *args):	drive_characteristics = [	    [4000, 500, 20000, 1000],     # Gecko	    [500,  4000, 4000, 1000],     # L297   XXX active low	    [1000, 2000, 1000, 1000],     # PMDX-150	    [1000, 6000, 24000, 20000],   # Sherline  XXX find proper values	    [1000, 2000, 200, 200],       # Xylotex	    [1000, 1000, 1000, 200000],   # Parker-Compumotor oem750	]	v = self.widgets.drivertype.get_active()	if v < len(drive_characteristics):	    d = drive_characteristics[v]	    self.widgets.steptime.set_value(d[0])	    self.widgets.stepspace.set_value(d[1])	    self.widgets.dirhold.set_value(d[2])	    self.widgets.dirsetup.set_value(d[3])	    self.widgets.steptime.set_sensitive(0)	    self.widgets.stepspace.set_sensitive(0)	    self.widgets.dirhold.set_sensitive(0)	    self.widgets.dirsetup.set_sensitive(0)	else:	    self.widgets.steptime.set_sensitive(1)	    self.widgets.stepspace.set_sensitive(1)	    self.widgets.dirhold.set_sensitive(1)	    self.widgets.dirsetup.set_sensitive(1)    def do_exclusive_inputs(self, pin):	if self.in_pport_prepare: return	exclusive = {	    HOME_X: (MAX_HOME_X, MIN_HOME_X, BOTH_HOME_X, ALL_HOME),	    HOME_Y: (MAX_HOME_Y, MIN_HOME_Y, BOTH_HOME_Y, ALL_HOME),	    HOME_Z: (MAX_HOME_Z, MIN_HOME_Z, BOTH_HOME_Z, ALL_HOME),	    HOME_A: (MAX_HOME_A, MIN_HOME_A, BOTH_HOME_A, ALL_HOME),	    MAX_HOME_X: (HOME_X, MIN_HOME_X, MAX_HOME_X, BOTH_HOME_X, ALL_LIMIT, ALL_HOME),	    MAX_HOME_Y: (HOME_Y, MIN_HOME_Y, MAX_HOME_Y, BOTH_HOME_Y, ALL_LIMIT, ALL_HOME),	    MAX_HOME_Z: (HOME_Z, MIN_HOME_Z, MAX_HOME_Z, BOTH_HOME_Z, ALL_LIMIT, ALL_HOME),	    MAX_HOME_A: (HOME_A, MIN_HOME_A, MAX_HOME_A, BOTH_HOME_A, ALL_LIMIT, ALL_HOME),	    MIN_HOME_X: (HOME_X, MAX_HOME_X, BOTH_HOME_X, ALL_LIMIT, ALL_HOME),	    MIN_HOME_Y: (HOME_Y, MAX_HOME_Y, BOTH_HOME_Y, ALL_LIMIT, ALL_HOME),	    MIN_HOME_Z: (HOME_Z, MAX_HOME_Z, BOTH_HOME_Z, ALL_LIMIT, ALL_HOME),	    MIN_HOME_A: (HOME_A, MAX_HOME_A, BOTH_HOME_A, ALL_LIMIT, ALL_HOME),	    BOTH_HOME_X: (HOME_X, MAX_HOME_X, MIN_HOME_X, ALL_LIMIT, ALL_HOME),	    BOTH_HOME_Y: (HOME_Y, MAX_HOME_Y, MIN_HOME_Y, ALL_LIMIT, ALL_HOME),	    BOTH_HOME_Z: (HOME_Z, MAX_HOME_Z, MIN_HOME_Z, ALL_LIMIT, ALL_HOME),	    BOTH_HOME_A: (HOME_A, MAX_HOME_A, MIN_HOME_A, ALL_LIMIT, ALL_HOME),	    MIN_X: (BOTH_X, BOTH_HOME_X, MIN_HOME_X, ALL_LIMIT),	    MIN_Y: (BOTH_Y, BOTH_HOME_Y, MIN_HOME_Y, ALL_LIMIT),	    MIN_Z: (BOTH_Z, BOTH_HOME_Z, MIN_HOME_Z, ALL_LIMIT),	    MIN_A: (BOTH_A, BOTH_HOME_A, MIN_HOME_A, ALL_LIMIT),	    MAX_X: (BOTH_X, BOTH_HOME_X, MIN_HOME_X, ALL_LIMIT),	    MAX_Y: (BOTH_Y, BOTH_HOME_Y, MIN_HOME_Y, ALL_LIMIT),	    MAX_Z: (BOTH_Z, BOTH_HOME_Z, MIN_HOME_Z, ALL_LIMIT),	    MAX_A: (BOTH_A, BOTH_HOME_A, MIN_HOME_A, ALL_LIMIT),	    BOTH_X: (MIN_X, MAX_X, MIN_HOME_X, MAX_HOME_X, BOTH_HOME_X, ALL_LIMIT),	    BOTH_Y: (MIN_Y, MAX_Y, MIN_HOME_Y, MAX_HOME_Y, BOTH_HOME_Y, ALL_LIMIT),	    BOTH_Z: (MIN_Z, MAX_Z, MIN_HOME_Z, MAX_HOME_Z, BOTH_HOME_Z, ALL_LIMIT),	    BOTH_A: (MIN_A, MAX_A, MIN_HOME_A, MAX_HOME_A, BOTH_HOME_A, ALL_LIMIT),	    ALL_LIMIT: (		MIN_X, MAX_X, BOTH_X, MIN_HOME_X, MAX_HOME_X, BOTH_HOME_X,		MIN_Y, MAX_Y, BOTH_Y, MIN_HOME_Y, MAX_HOME_Y, BOTH_HOME_Y,		MIN_Z, MAX_Z, BOTH_Z, MIN_HOME_Z, MAX_HOME_Z, BOTH_HOME_Z,		MIN_A, MAX_A, BOTH_A, MIN_HOME_A, MAX_HOME_A, BOTH_HOME_A),	    ALL_HOME: (		HOME_X, MIN_HOME_X, MAX_HOME_X, BOTH_HOME_X,		HOME_Y, MIN_HOME_Y, MAX_HOME_Y, BOTH_HOME_Y,		HOME_Z, MIN_HOME_Z, MAX_HOME_Z, BOTH_HOME_Z,		HOME_A, MIN_HOME_A, MAX_HOME_A, BOTH_HOME_A),	} 	p = 'pin%d' % pin	v = self.widgets[p].get_active()	ex = exclusive.get(v, ())	for pin1 in (10,11,12,13,15):	    if pin1 == pin: continue	    p = 'pin%d' % pin1	    v1 = self.widgets[p].get_active()	    if v1 in ex or v1 == v:		self.widgets[p].set_active(UNUSED_INPUT)    def on_pin10_changed(self, *args):	self.do_exclusive_inputs(10)    def on_pin11_changed(self, *args):	self.do_exclusive_inputs(11)    def on_pin12_changed(self, *args):	self.do_exclusive_inputs(12)    def on_pin13_changed(self, *args):	self.do_exclusive_inputs(13)    def on_pin15_changed(self, *args):	self.do_exclusive_inputs(15)	       def on_pport_prepare(self, *args):	self.in_pport_prepare = True	for pin in (1,2,3,4,5,6,7,8,9,14,16,17):	    p = 'pin%d' % pin	    model = self.widgets[p].get_model()	    model.clear()	    for name in human_output_names: model.append((name,))	for pin in (10,11,12,13,15):	    p = 'pin%d' % pin	    model = self.widgets[p].get_model()	    model.clear()	    for name in human_input_names: model.append((name,))	for pin in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17):	    p = 'pin%d' % pin	    self.widgets[p].set_active(self.data[p])	    p = 'pin%dinv' % pin	    self.widgets[p].set_active(self.data[p])	self.widgets.customhal.set_active(self.data.customhal)	self.widgets.pyvcp.set_active(self.data.pyvcp)	self.widgets.pin1.grab_focus()	self.in_pport_prepare = False     def on_pport_next(self, *args):	for pin in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17):	    p = 'pin%d' % pin	    self.data[p] = self.widgets[p].get_active()	    p = 'pin%dinv' % pin	    self.data[p] = self.widgets[p].get_active()	self.data.customhal = self.widgets.customhal.get_active()	self.data.pyvcp = self.widgets.pyvcp.get_active()    on_pport_back = on_pport_next    def on_sherlinedefault_clicked(self, *args):	self.widgets.pin2.set_active(1)	self.widgets.pin3.set_active(0)	self.widgets.pin4.set_active(3)	self.widgets.pin5.set_active(2)	self.widgets.pin6.set_active(5)	self.widgets.pin7.set_active(4)	self.widgets.pin8.set_active(7)	self.widgets.pin9.set_active(6)    def on_xylotexdefault_clicked(self, *args):	self.widgets.pin2.set_active(0)	self.widgets.pin3.set_active(1)	self.widgets.pin4.set_active(2)	self.widgets.pin5.set_active(3)	self.widgets.pin6.set_active(4)	self.widgets.pin7.set_active(5)	self.widgets.pin8.set_active(6)	self.widgets.pin9.set_active(7)    def axis_prepare(self, axis):	d = self.data	w = self.widgets	def set_text(n): w[axis + n].set_text("%s" % d[axis + n])	def set_active(n): w[axis + n].set_active(d[axis + n])	set_text("steprev")	set_text("microstep")	set_text("pulleynum")	set_text("pulleyden")	set_text("leadscrew")	set_text("maxvel")	set_text("maxacc")	set_text("homepos")	set_text("minlim")	set_text("maxlim")	set_text("homesw")	set_text("homevel")	set_active("latchdir")	if axis == "a":	    w[axis + "screwunits"].set_text(_("degree / rev"))	    w[axis + "velunits"].set_text(_("deg / s"))	    w[axis + "accunits"].set_text(_("deg / s虏"))	    w[axis + "accdistunits"].set_text(_("deg"))	elif d.units:	    w[axis + "screwunits"].set_text(_("mm / rev"))	    w[axis + "velunits"].set_text(_("mm / s"))	    w[axis + "accunits"].set_text(_("mm / s虏"))	    w[axis + "accdistunits"].set_text(_("mm"))	else:	    w[axis + "screwunits"].set_text(_("rev / in"))	    w[axis + "velunits"].set_text(_("in / s"))	    w[axis + "accunits"].set_text(_("in / s虏"))	    w[axis + "accdistunits"].set_text(_("in"))	n = "xyza".index(axis)	inputs = set((d.pin10, d.pin11, d.pin12, d.pin13, d.pin15))	thisaxishome = set((ALL_HOME, HOME_X + n, MIN_HOME_X + n,			    MAX_HOME_X + n, BOTH_HOME_X + n))	homes = bool(inputs & thisaxishome)	w[axis + "homesw"].set_sensitive(homes)	w[axis + "homevel"].set_sensitive(homes)	w[axis + "latchdir"].set_sensitive(homes)	w[axis + "steprev"].grab_focus()	gobject.idle_add(lambda: self.update_pps(axis))    def axis_done(self, axis):	d = self.data	w = self.widgets	def get_text(n): d[axis + n] = float(w[axis + n].get_text())	def get_active(n): d[axis + n] = w[axis + n].get_active()	get_text("steprev")	get_text("microstep")	get_text("pulleynum")	get_text("pulleyden")	get_text("leadscrew")	get_text("maxvel")	get_text("maxacc")	get_text("homepos")	get_text("minlim")	get_text("maxlim")	get_text("homesw")	get_text("homevel")	get_active("latchdir")	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?