本文整理汇总了Python中gladevcp.persistence.IniFile类的典型用法代码示例。如果您正苦于以下问题:Python IniFile类的具体用法?Python IniFile怎么用?Python IniFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IniFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_button_press
class HandlerClass:
def on_button_press(self,widget,data=None):
print "on_button_press"
self.anint += 1
# show retained attributes as inifile and current values
print "attr\tini\tcurrent"
for k in self.defaults[IniFile.vars].keys():
print "%s\t%s\t%s" % (k,self.defaults[IniFile.vars][k],getattr(self,k,None))
def on_destroy(self,obj,data=None):
'''
save state on application exit
'''
print "on_destroy() - saving state"
self.ini.save_state(self)
def on_restore_defaults(self,button,data=None):
'''
example callback for 'Reset to defaults' button (unused)
'''
print "on_restore_defaults() - setting default state"
self.ini.create_default_ini()
self.ini.restore_state(self)
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.useropts = useropts
# use the module basename for the ini file:
self.ini_filename = __name__ + '.save'
# choose widgets and attributes to be retained here:
# this descriptor will not retain any attrbuts,
# but the state of all widgets (HAL widgets and Gtk widgets
# (subject to widget types supported by gladevcp.persistence.accessors())
#self.defaults = { IniFile.vars: dict(),
# IniFile.widgets : widget_defaults(<widgetlist>)
# }
# this descriptor will retain the listed attributes, and only
# HAL widgets state:
self.defaults = { IniFile.vars: { 'afloat' : 1.67, 'anint' : 42, 'abool' : True, 'astring': 'sometext' },
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = False))
}
self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
# it is OK to use self.panel.widgets (all widgets) here because only
# widgets whose state was saved as per descriptor will be restored
self.ini.restore_state(self)
示例2: _on_state_changed
class HandlerClass:
def _on_state_changed(self,hal_pin,data=None):
state = hal_pin.get()
self.builder.get_object("state").set_text(states[state])
def _on_motion_type_changed(self,hal_pin,data=None):
self.builder.get_object("motion_type_label").set_text(motions[hal_pin.get()])
def on_in_position_changed(self,hal_led,data=None):
if self.state.get() and hal_led.hal_pin.get():
self.s.poll()
posfmt = " ".join(["%-8.4f"] * self.s.axes)
posn = posfmt % self.s.position[:self.s.axes]
print "new_position: ", posn, "motion type=",motions[self.motion_type.get()]
def on_unix_signal(self,signum,stack_frame):
print "on_unix_signal(): signal %d received, saving state" % (signum)
self.ini.save_state(self)
gtk.main_quit()
self.halcomp.exit()
def on_destroy(self,obj,data=None):
print "on_destroy() - saving state"
self.ini.save_state(self)
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
(directory,filename) = os.path.split(__file__)
(basename,extension) = os.path.splitext(filename)
self.ini_filename = os.path.join(directory,basename + '.ini')
self.defaults = { IniFile.vars: { },
IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(),
hal_only=True,output_only = True)),
}
self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
self.ini.restore_state(self)
self.c = linuxcnc.command()
self.e = linuxcnc.error_channel()
self.s = linuxcnc.stat()
self.state = hal_glib.GPin(halcomp.newpin('state', hal.HAL_S32, hal.HAL_IN))
self.state.connect('value-changed', self._on_state_changed)
self.motion_type = hal_glib.GPin(halcomp.newpin('motion_type', hal.HAL_S32, hal.HAL_IN))
self.motion_type.connect('value-changed', self._on_motion_type_changed)
示例3: __init__
def __init__(self, halcomp, builder, useropts):
"""
Handler classes are instantiated in the following state:
- the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
- the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
- it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.
after all handlers are instantiated in command line and get_handlers() order, callbacks will be
connected with connect_signals()/signal_autoconnect()
The builder may be either of libglade or GtkBuilder type depending on the glade file format.
"""
self.halcomp = halcomp
self.builder = builder
(directory, filename) = os.path.split(__file__)
(basename, extension) = os.path.splitext(filename)
self.ini_filename = os.path.join(directory, basename + ".ini")
# the dict driving the ini file persistence feature
# a signature checks variable names,types,sections
#
# to see the mechanism at work, do this:
# - run the application, change some values, and exit
# - edit the complex.ini file and change a variable name in the widgets or vars section
# for example, rename 'a' to 'z'
# and remove one of the widgets in the widgets section
# - then re-run the application
# during startup, you get a message saying
# "key 'a' in section 'vars' : missing"
# "key 'hal_radiobutton1' in section 'widgets' : missing"
#
# to see how the protection of ini file versus a changed program works,
# change the defaults dict below, for instance remove the 'c' : "a string variable
# then re-run - the signature check at startup should fail, you should get:
# "signature mismatch in ./complex.ini - resetting to default"
# and a default ini file is generated
self.defaults = { # these will be saved/restored as method attributes
IniFile.vars: {"nhits": 0, "lifetime_ticks": 0, "a": 1.67, "d": True, "c": "a string"},
# we're interested restoring state to output HAL widgets only
# NB: this does NOT restore state pf plain gtk objects - set hal_only to False to do this
IniFile.widgets: widget_defaults(
select_widgets(self.builder.get_objects(), hal_only=True, output_only=True)
),
}
self.ini = IniFile(self.ini_filename, self.defaults, self.builder)
self.ini.restore_state(self)
# at this point it is ok to refer to restored attributes like self.nhits and self.lifetime_ticks:
self.builder.get_object("hal_button1").set_label("past hits: %d" % self.nhits)
self.builder.get_object("message").hal_pin.set(self.lifetime_ticks)
self._hal_setup(halcomp, builder)
# demonstrate a slow background timer - granularity is one second
# for a faster timer, use this:
# glib.timeout_add(5000, self._on_timer_tick)
glib.timeout_add_seconds(1, self._on_timer_tick)
示例4: __init__
def __init__(self, halcomp, builder, useropts):
'''
Handler classes are instantiated in the following state:
- the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
- the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
- it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.
after all handlers are instantiated in command line and get_handlers() order, callbacks will be
connected with connect_signals()/signal_autoconnect()
The builder may be either of libglade or GtkBuilder type depending on the glade file format.
'''
# TODO: add a signal to check if the relay for spindle-pump is ON
halcomp.newpin("spindle.fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.pump", hal.HAL_BIT, hal.HAL_OUT)
self.halcomp = halcomp
self.builder = builder
self.nhits = 0
self.ini_filename = __name__ + '.ini'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.e = EmcInterface()
glib.timeout_add_seconds(1, self._query_emc_status)
示例5: __init__
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.useropts = useropts
# use the module basename for the ini file:
self.ini_filename = __name__ + '.save'
# choose widgets and attributes to be retained here:
# this descriptor will not retain any attrbuts,
# but the state of all widgets (HAL widgets and Gtk widgets
# (subject to widget types supported by gladevcp.persistence.accessors())
#self.defaults = { IniFile.vars: dict(),
# IniFile.widgets : widget_defaults(<widgetlist>)
# }
# this descriptor will retain the listed attributes, and only
# HAL widgets state:
self.defaults = { IniFile.vars: { 'afloat' : 1.67, 'anint' : 42, 'abool' : True, 'astring': 'sometext' },
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = False))
}
self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
# it is OK to use self.panel.widgets (all widgets) here because only
# widgets whose state was saved as per descriptor will be restored
self.ini.restore_state(self)
示例6: __init__
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.ini_filename = __name__ + '.ini'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.e = EmcInterface()
glib.timeout_add_seconds(1, self._query_emc_status)
示例7: __init__
def __init__(self,halcomp,builder,useropts):
self.builder = builder
self.halcomp = halcomp
self.defaults = { IniFile.vars : {"laser_milliseconds" : 166}}
self.ini_filename = __name__ + ".var"
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.laser_hertz_value = hal_glib.GPin(halcomp.newpin("laser_hertz_value", hal.HAL_U32, hal.HAL_OUT))
self.lbl_duration_value = self.builder.get_object("lbl_duration_value")
# sets what got loaded in from the ini_file
self.calc_and_set_milliseconds(self.laser_milliseconds)
# self.btn1 = self.builder.get_object("period_50")
# self.btn1.connect("pressed", self.on_btn_pressed, 50)
self.btn1 = self.builder.get_object("period_50")
self.btn1.connect("pressed", self.on_btn_pressed, 50)
self.btn1 = self.builder.get_object("period_100")
self.btn1.connect("pressed", self.on_btn_pressed, 100)
self.btn1 = self.builder.get_object("period_200")
self.btn1.connect("pressed", self.on_btn_pressed, 200)
self.btn1 = self.builder.get_object("period_500")
self.btn1.connect("pressed", self.on_btn_pressed, 500)
self.btn1 = self.builder.get_object("period_700")
self.btn1.connect("pressed", self.on_btn_pressed, 700)
self.btn1 = self.builder.get_object("period_900")
self.btn1.connect("pressed", self.on_btn_pressed, 900)
self.box = self.builder.get_object("tbl_marius") # arbitrary object to test for ending
self.box.connect("destroy", self._on_destroy)
示例8: __init__
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
(directory,filename) = os.path.split(__file__)
(basename,extension) = os.path.splitext(filename)
self.ini_filename = os.path.join(directory,basename + '.ini')
self.defaults = { IniFile.vars: { },
IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(),
hal_only=True,output_only = True)),
}
self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
self.ini.restore_state(self)
self.c = linuxcnc.command()
self.e = linuxcnc.error_channel()
self.s = linuxcnc.stat()
self.state = hal_glib.GPin(halcomp.newpin('state', hal.HAL_S32, hal.HAL_IN))
self.state.connect('value-changed', self._on_state_changed)
self.motion_type = hal_glib.GPin(halcomp.newpin('motion_type', hal.HAL_S32, hal.HAL_IN))
self.motion_type.connect('value-changed', self._on_motion_type_changed)
示例9: on_manual_mode
class HandlerClass:
def on_manual_mode(self,widget,data=None):
if self.e.ensure_mode(linuxcnc.MODE_MANUAL):
print "switched to manual mode"
else:
print "cant switch to manual in this state"
def on_mdi_mode(self,widget,data=None):
if self.e.ensure_mode(linuxcnc.MODE_MDI):
print "switched to MDI mode"
else:
print "cant switch to MDI in this state"
def _query_emc_status(self,data=None):
(task_mode, task_state, exec_state, interp_state) = self.e.emc_status()
self.builder.get_object('task_mode').set_label("Task mode: " + task_mode)
self.builder.get_object('task_state').set_label("Task state: " + task_state)
self.builder.get_object('exec_state').set_label("Exec state: " + exec_state)
self.builder.get_object('interp_state').set_label("Interp state: " + interp_state)
return True
def on_probe(self,widget,data=None):
label = widget.get_label()
axis = ord(label[0].lower()) - ord('x')
direction = 1.0
if label[1] == '-':
direction = -1.0
self.e.s.poll()
self.start_feed = self.e.s.settings[1]
# determine system we are touching off - 1...g54 etc
self.current_system = self.e.get_current_system()
# remember current abs or rel mode - g91
self.start_relative = (910 in self.e.active_codes())
self.previous_mode = self.e.s.task_mode
if self.e.s.task_state != linuxcnc.STATE_ON:
print "machine not turned on"
return
if not self.e.s.homed[axis]:
print "%s axis not homed" %(chr(axis + ord('X')))
return
if self.e.running(do_poll=False):
print "cant do that now - intepreter running"
return
self.e.ensure_mode(linuxcnc.MODE_MDI)
self.e.mdi_command("#<_Probe_System> = %d " % (self.current_system ),wait=False)
self.e.mdi_command("#<_Probe_Axis> = %d " % (axis),wait=False)
self.e.mdi_command("#<_Probe_Speed> = %s " % (self.builder.get_object('probe_feed').get_value()),wait=False)
self.e.mdi_command("#<_Probe_Diameter> = %s " % (self.builder.get_object('probe_diameter').get_value() ),wait=False)
self.e.mdi_command("#<_Probe_Distance> = %s " % (self.builder.get_object('probe_travel').get_value() * direction),wait=False)
self.e.mdi_command("#<_Probe_Retract> = %s " % (self.builder.get_object('retract').get_value() * direction * -1.0),wait=False)
self.e.mdi_command("O<probe> call",wait=False)
self.e.mdi_command('F%f' % (self.start_feed),wait=False)
self.e.mdi_command('G91' if self.start_relative else 'G90',wait=False)
# self.e.ensure_mode(self.previous_mode)
def on_destroy(self,obj,data=None):
self.ini.save_state(self)
def on_restore_defaults(self,button,data=None):
'''
example callback for 'Reset to defaults' button
currently unused
'''
self.ini.create_default_ini()
self.ini.restore_state(self)
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.ini_filename = __name__ + '.ini'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.e = EmcInterface()
glib.timeout_add_seconds(1, self._query_emc_status)
示例10: on_button_press
#.........这里部分代码省略.........
self.ini.save_state(self)
gtk.main_quit()
self.halcomp.exit()
def on_destroy(self,obj,data=None):
'''
gladevcp_demo.ui has a destroy callback set in the window1 Gobject
note the widget tree is not safely accessible here any more
'''
print "on_destroy() - saving state)"
self.ini.save_state(self)
def on_restore_defaults(self,button,data=None):
self.ini.create_default_ini()
self.ini.restore_state(self)
self.builder.get_object('hal_button1').set_label("past hits: %d" % self.nhits)
def on_save_settings(self,button,data=None):
print "on_save_settings() - saving state"
self.ini.save_state(self)
def _hal_setup(self,halcomp, builder):
'''
hal related initialisation
'''
# the toplevel window is always named 'window1'. Do not change.
# widgets may be accessed through builder.get_object() and
# builder.get_objects()
self.window1 = self.builder.get_object("window1")
self.led1 = self.builder.get_object("hal_led1")
# standard hal pins not associated with any widget
self.halcomp.newpin("example-out", hal.HAL_BIT, hal.HAL_OUT)
self.halcomp.newpin("example-in", hal.HAL_S32, hal.HAL_IN)
# hal pins with change callback. Also unrelated to any HAL widget.
# When the pin's value changes the callback is executed.
self.example_trigger = hal_glib.GPin(halcomp.newpin('example-trigger', hal.HAL_BIT, hal.HAL_IN))
self.example_trigger.connect('value-changed', self._on_example_trigger_change)
def __init__(self, halcomp,builder,useropts):
'''
Handler classes are instantiated in the following state:
- the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
- the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
- it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.
after all handlers are instantiated in command line and get_handlers() order, callbacks will be
connected with connect_signals()/signal_autoconnect()
The builder may be either of libglade or GtkBuilder type depending on the glade file format.
'''
self.halcomp = halcomp
self.builder = builder
(directory,filename) = os.path.split(__file__)
(basename,extension) = os.path.splitext(filename)
self.ini_filename = os.path.join(directory,basename + '.save')
# the dict driving the ini file persistence feature
# a signature checks variable names,types,sections
#
# to see the mechanism at work, do this:
# - run the application, change some values, and exit
# - edit the complex.save file and change a variable name in the widgets or vars section
# for example, rename 'a' to 'z'
# and remove one of the widgets in the widgets section
# - then re-run the application
# during startup, you get a message saying
# "key 'a' in section 'vars' : missing"
# "key 'hal_radiobutton1' in section 'widgets' : missing"
#
# to see how the protection of ini file versus a changed program works,
# change the defaults dict below, for instance remove the 'c' : "a string variable
# then re-run - the signature check at startup should fail, you should get:
# "signature mismatch in ./complex.save - resetting to default"
# and a default ini file is generated
self.defaults = { # these will be saved/restored as method attributes
IniFile.vars: { 'nhits' : 0, 'lifetime_ticks': 0, 'a': 1.67, 'd': True, 'c' : "a string"},
# we're interested restoring state to output HAL widgets only
# NB: this does NOT restore state pf plain gtk objects - set hal_only to False to do this
IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
}
self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
self.ini.restore_state(self)
# at this point it is ok to refer to restored attributes like self.nhits and self.lifetime_ticks:
self.builder.get_object('hal_button1').set_label("past hits: %d" % self.nhits)
self.builder.get_object('message').hal_pin.set(self.lifetime_ticks)
self._hal_setup(halcomp,builder)
# demonstrate a slow background timer - granularity is one second
# for a faster timer, use this:
# glib.timeout_add(5000, self._on_timer_tick)
glib.timeout_add_seconds(1, self._on_timer_tick)
示例11: __init__
def __init__(self,halcomp,builder,useropts):
self.builder = builder
self.halcomp = halcomp
self.defaults = { IniFile.vars : { "thcspeedval" : 15.0 ,
"thcspeedmax" : 20.0 ,
"thcspeedmin" : 1.0 ,
"thcspeedincr" : 1.0 ,
"cutgapval" : 4.0 ,
"cutgapmax" : 10.0 ,
"cutgapmin" : 0.1 ,
"cutgapincr" : 0.1 ,
"g0gapval" : 45.0 ,
"g0gapmax" : 55.0 ,
"g0gapmin" : 0.5 ,
"g0gapincr" : 0.5 ,
"pierceutostart" : True ,
"piercegapval" : 5.0 ,
"piercegapmax" : 12.0 ,
"piercegapmin" : 2.0 ,
"piercegapincr" : 0.5 ,
"piercedelayval" : 0.5 ,
"piercedelaymax" : 10.0 ,
"piercedelaymin" : 0.01 ,
"piercedelayincr" : 0.01 ,
"enableheightlock" : False,
"chlthresholdval" : 60.0 ,
"chlthresholdmax" : 100.0,
"chlthresholdmin" : 10.0 ,
"chlthresholdincr" : 10.0 ,
"thctargetvoltval" : 100.0,
"thctargetvoltmax" : 255.0,
"thctargetvoltmin" : 55.0 ,
"thctargetvoltincr" : 5.0 ,
},
IniFile.widgets: widget_defaults(select_widgets([self.builder.get_object("hal-btn-THC"),
], hal_only=True, output_only = True)),
}
self.ini_filename = __name__ + ".var"
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
# lets make our pins
self.THC_speed = hal_glib.GPin(halcomp.newpin("THC-Speed", hal.HAL_FLOAT, hal.HAL_OUT))
self.cut_gap = hal_glib.GPin(halcomp.newpin("Cut-Gap", hal.HAL_FLOAT, hal.HAL_OUT))
self.g0_gap = hal_glib.GPin(halcomp.newpin("G0-Gap", hal.HAL_FLOAT, hal.HAL_OUT))
self.pierce_deley = hal_glib.GPin(halcomp.newpin("Pierce-Delay", hal.HAL_FLOAT, hal.HAL_OUT))
self.pierce_gap = hal_glib.GPin(halcomp.newpin("Pierce-Gap", hal.HAL_FLOAT, hal.HAL_OUT))
self.target_voltage = hal_glib.GPin(halcomp.newpin("Target-Voltage", hal.HAL_FLOAT, hal.HAL_OUT))
# get all widgets and connect them
self.lbl_prog_volt = self.builder.get_object("lbl_prog_volt")
self.lbl_cut_speed = self.builder.get_object("lbl_cut_speed")
self.lbl_cut_gap = self.builder.get_object("lbl_cut_gap")
self.lbl_g0_gap = self.builder.get_object("lbl_g0_gap")
self.lbl_pierce_gap = self.builder.get_object("lbl_pierce_gap")
self.lbl_pierce_delay = self.builder.get_object("lbl_pierce_delay")
self.btn_THC_speed_minus = self.builder.get_object("btn_THC_speed_minus")
self.btn_THC_speed_minus.connect("pressed", self.on_btn_THC_speed_pressed, -1)
self.btn_THC_speed_plus = self.builder.get_object("btn_THC_speed_plus")
self.btn_THC_speed_plus.connect("pressed", self.on_btn_THC_speed_pressed, 1)
self.adj_THC_speed = self.builder.get_object("adj_THC_speed")
self.adj_THC_speed.connect("value_changed", self.on_adj_THC_speed_value_changed)
self.adj_THC_speed.upper = self.thcspeedmax
self.adj_THC_speed.lower = self.thcspeedmin
self.adj_THC_speed.set_value(self.thcspeedval)
self.tbl_cutting = self.builder.get_object("tbl_cutting")
self.tbl_cutting.connect("destroy", self._on_destroy)
self.btn_cut_gap_minus = self.builder.get_object("btn_cut_gap_minus")
self.btn_cut_gap_minus.connect("pressed", self.on_btn_cut_gap_pressed, -1)
self.btn_cut_gap_plus = self.builder.get_object("btn_cut_gap_plus")
self.btn_cut_gap_plus.connect("pressed", self.on_btn_cut_gap_pressed, 1)
self.adj_cut_gap = self.builder.get_object("adj_cut_gap")
self.adj_cut_gap.connect("value_changed", self.on_adj_cut_gap_value_changed)
self.adj_cut_gap.upper = self.cutgapmax
self.adj_cut_gap.lower = self.cutgapmin
self.adj_cut_gap.set_value(self.cutgapval)
self.btn_g0_minus = self.builder.get_object("btn_g0_minus")
self.btn_g0_minus.connect("pressed", self.on_btn_g0_pressed, -1)
self.btn_g0_plus = self.builder.get_object("btn_g0_plus")
self.btn_g0_plus.connect("pressed", self.on_btn_g0_pressed, 1)
#.........这里部分代码省略.........
示例12: _query_emc_status
#.........这里部分代码省略.........
config.read(fn)
o = config.get("DEFAULT", 'control_font')
l = config.get("DEFAULT", 'listing_font')
control_font = pango.FontDescription(o)
#control_font = pango.FontDescription("San 24")
# # set spin button font
# for i in ["btn_scan_barcode"]:
# w = self.builder.get_object(i)
# if w:
# w = w.child
# w.modify_font(control_font)
'''set label font'''
self.listing_font = pango.FontDescription(l)
for i in ["task_mode","task_state","exec_state","interp_state",
"label3","j4-enc_pos-label",
"label6","current-tool","label7","prepared-tool","label8",
"label9","label10","label11","label12","label13","label14","label15",
"label16","label17","label18","label19","label20"]:
w = self.builder.get_object(i)
if w:
w.modify_font(self.listing_font)
for i in ["prepared-tool","current-tool","j4-enc_pos-label","analog_07"]:
w = self.builder.get_object(i)
if w:
w.modify_font(control_font)
theme_name = config.get("DEFAULT", 'gtk_theme')
settings = gtk.settings_get_default()
settings.set_string_property("gtk-theme-name", theme_name, "")
def _on_update_status(self):
evts = self.zmq_poller.poll(0)
if evts:
msg = self.zmq_server.recv()
'''TODO: 偵測訊息內容'''
if msg:
pass
self.zmq_server.send("message from vbc.py")
return True
def _delayed_sys_init_(self):
self.builder.get_object("task_mode").hide()
self.builder.get_object("task_state").hide()
self.builder.get_object("exec_state").hide()
self.builder.get_object("interp_state").hide()
return False
def __init__(self, halcomp, builder, useropts):
'''
Handler classes are instantiated in the following state:
- the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
- the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
- it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.
after all handlers are instantiated in command line and get_handlers() order, callbacks will be
connected with connect_signals()/signal_autoconnect()
The builder may be either of libglade or GtkBuilder type depending on the glade file format.
'''
# TODO: add a signal to check if the relay for spindle-pump is ON
halcomp.newpin("spindle.fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.pump", hal.HAL_BIT, hal.HAL_OUT)
halcomp.newpin("spindle.brake", hal.HAL_BIT, hal.HAL_OUT)
self.halcomp = halcomp
self.builder = builder
self.nhits = 0
self.set_theme_font()
self.context = zmq.Context()
self.zmq_server = self.context.socket(zmq.PAIR)
self.zmq_server.bind('tcp://127.0.0.1:5556')
self.zmq_poller = zmq.Poller()
self.zmq_poller.register(self.zmq_server, zmq.POLLIN)
self.zmq_context = zmq.Context()
self.zmq_socket = self.zmq_context.socket(zmq.PUSH)
self.zmq_socket.connect('tcp://127.0.0.1:5555')
self.ini_filename = __name__ + '.ini'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.e = EmcInterface()
# program startup
self.timer_id = glib.timeout_add(100, self._delayed_sys_init_)
glib.timeout_add_seconds(1, self._query_emc_status)
glib.timeout_add(100, self._on_update_status)
示例13: __init__
def __init__(self,halcomp,builder,useropts):
self.builder = builder
self.halcomp = halcomp
self.defaults = { IniFile.vars : {"laser_power_val" : 90.0 ,
"laser_power_min" : 1.0 ,
"laser_power_max" : 100.0,
"laser_power_incr" : 1.0,
"spin_oneshot_time" : 1.0}}
self.ini_filename = __name__ + ".var"
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.lbl_program_name = self.builder.get_object("lbl_program_name")
self.laser_on_cont = hal_glib.GPin(halcomp.newpin("laser_on_cont", hal.HAL_BIT, hal.HAL_OUT))
self.laser_pulse = hal_glib.GPin(halcomp.newpin("laser_on_pulse", hal.HAL_BIT, hal.HAL_OUT))
self.laser_pulse_width = hal_glib.GPin(halcomp.newpin("laser_pulse_width", hal.HAL_FLOAT, hal.HAL_OUT))
self.box = self.builder.get_object("hbox1") # arbitrary object to test for ending
self.box.connect("destroy", self._on_destroy)
self.btn_chiller_pressed = self.builder.get_object("btn_chiller")
self.btn_chiller_pressed.connect("pressed", self.on_btn_chiller_pressed)
self.btn_squealer_pressed = self.builder.get_object("squeal_button")
self.btn_squealer_pressed.connect("pressed", self.on_btn_squealer_pressed)
self.mbtn_laser_pressed = self.builder.get_object("mbtn-laser_start")
self.mbtn_laser_pressed.connect("pressed", self.on_mbtn_laser_pressed)
self.mbtn_laser_released = self.builder.get_object("mbtn-laser_start")
self.mbtn_laser_released.connect("released", self.on_mbtn_laser_released)
self.adj_spin_oneshot = self.builder.get_object("spin_adjust")
self.adj_spin_oneshot.connect("value_changed", self.on_adj_spin_oneshot_value_changed)
self.adj_spin_oneshot.set_value(self.spin_oneshot_time)
self.adj_laser_power = self.builder.get_object("slide_adjust")
self.adj_laser_power.connect("value_changed", self.on_adj_laser_power_value_changed)
self.adj_laser_power.upper = self.laser_power_max
self.adj_laser_power.lower = self.laser_power_min
self.adj_laser_power.set_value(self.laser_power_val)
if os.getenv('INI_FILE_NAME'):
ini_file = os.getenv('INI_FILE_NAME')
else:
self.lbl_program_name.set_label("INI_FILE_NAME not set?")
if os.path.isfile(ini_file):
config = ConfigParser.ConfigParser()
config.read(ini_file)
if config.has_option('DISPLAY','PROGRAM_PREFIX') and config.has_option('DISPLAY','PROGRAM_DEFAULT'):
prefix = config.get('DISPLAY','PROGRAM_PREFIX')
prog = config.get('DISPLAY','PROGRAM_DEFAULT')
self.target_path = os.path.join(prefix, prog)
else:
self.lbl_program_name.set_label("ncfile not found")
glib.timeout_add_seconds(1, self.on_timer_tick)
示例14: _query_emc_status
class HandlerClass:
'''
class with gladevcp callback handlers
'''
def _query_emc_status(self,data=None):
(task_mode, task_state, exec_state, interp_state) = self.e.emc_status()
self.builder.get_object('task_mode').set_label("Task mode: " + task_mode)
self.builder.get_object('task_state').set_label("Task state: " + task_state)
self.builder.get_object('exec_state').set_label("Exec state: " + exec_state)
self.builder.get_object('interp_state').set_label("Interp state: " + interp_state)
# looping: if (task_mode == "MANUAL") and (task_state == "ON") and (exec_state == "DONE") and (interp_state == "IDLE"):
# looping: # print ("task_mode: manual...")
# looping: # print ("about to cycle-start...")
# looping: # if self.emcstat.interp_state == self.emc.INTERP_IDLE:
# looping: self.e.c.mode(linuxcnc.MODE_AUTO)
# looping: self.e.c.wait_complete() # linuxcnc.command
# looping: self.e.c.auto(linuxcnc.AUTO_RUN, 0)
return True
def on_button_press(self,widget,data=None):
'''
a callback method
parameters are:
the generating object instance, likte a GtkButton instance
user data passed if any - this is currently unused but
the convention should be retained just in case
'''
print "on_button_press called"
self.nhits += 1
self.builder.get_object('hits').set_label("Hits: %d" % (self.nhits))
def on_destroy(self,obj,data=None):
self.ini.save_state(self)
def on_restore_defaults(self,button,data=None):
'''
example callback for 'Reset to defaults' button
currently unused
'''
self.ini.create_default_ini()
self.ini.restore_state(self)
def __init__(self, halcomp, builder, useropts):
'''
Handler classes are instantiated in the following state:
- the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
- the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
- it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.
after all handlers are instantiated in command line and get_handlers() order, callbacks will be
connected with connect_signals()/signal_autoconnect()
The builder may be either of libglade or GtkBuilder type depending on the glade file format.
'''
# TODO: add a signal to check if the relay for spindle-pump is ON
halcomp.newpin("spindle.fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.pump", hal.HAL_BIT, hal.HAL_OUT)
self.halcomp = halcomp
self.builder = builder
self.nhits = 0
self.ini_filename = __name__ + '.ini'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.e = EmcInterface()
glib.timeout_add_seconds(1, self._query_emc_status)
示例15: _query_emc_status
#.........这里部分代码省略.........
the generating object instance, likte a GtkButton instance
user data passed if any - this is currently unused but
the convention should be retained just in case
'''
print "on_button_press called"
self.nhits += 1
self.builder.get_object('hits').set_label("Hits: %d" % (self.nhits))
def on_destroy(self,obj,data=None):
self.ini.save_state(self)
def on_do7_toggled(self, widget, data=None):
if (not self.e.manual_ok(do_poll=True)):
# bypass issuing MDI when program is running
return
label = gtk.Label("Click OK to TOOL-RELEASE")
dialog = gtk.Dialog("TOOL-RELEASE",
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.vbox.pack_start(label)
label.show()
response = dialog.run()
if response == gtk.RESPONSE_ACCEPT:
print 'on_do7_toggled'
dialog.destroy()
if widget.get_active() == True:
self.e.mdi_command('M64 P7', True) # release tool
else:
self.e.mdi_command('M65 P7', True) # clamp tool
else:
dialog.destroy()
def on_do1_toggled(self, widget, data=None):
# print 'debug: on_do1_toggled'
if (not self.e.manual_ok(do_poll=True)):
# bypass issuing MDI when program is running
return
if widget.get_active() == True:
self.e.mdi_command('M3', True)
else:
if(self.e.spindle_speed() != 0):
self.e.mdi_command('M5', True)
def on_do2_toggled(self, widget, data=None):
# print 'debug: on_do2_toggled'
if (not self.e.manual_ok(do_poll=True)):
# bypass issuing MDI when program is running
return
if widget.get_active() == True:
self.e.mdi_command('M4', True)
else:
if(self.e.spindle_speed() != 0):
self.e.mdi_command('M5', True)
def on_restore_defaults(self,button,data=None):
'''
example callback for 'Reset to defaults' button
currently unused
'''
self.ini.create_default_ini()
self.ini.restore_state(self)
def __init__(self, halcomp, builder, useropts):
'''
Handler classes are instantiated in the following state:
- the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
- the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
- it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.
after all handlers are instantiated in command line and get_handlers() order, callbacks will be
connected with connect_signals()/signal_autoconnect()
The builder may be either of libglade or GtkBuilder type depending on the glade file format.
'''
# TODO: add a signal to check if the relay for spindle-pump is ON
halcomp.newpin("spindle.fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-fwd", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.jog-rev", hal.HAL_BIT, hal.HAL_IN)
halcomp.newpin("spindle.pump", hal.HAL_BIT, hal.HAL_OUT)
self.halcomp = halcomp
self.builder = builder
self.nhits = 0
self.ini_filename = __name__ + '.ini'
self.defaults = { IniFile.vars: dict(),
IniFile.widgets : widget_defaults(select_widgets(self.builder.get_objects(), hal_only=False,output_only = True))
}
self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
self.ini.restore_state(self)
self.e = EmcInterface()
glib.timeout_add_seconds(1, self._query_emc_status)