当前位置: 首页>>代码示例>>Python>>正文


Python IniFile.restore_state方法代码示例

本文整理汇总了Python中gladevcp.persistence.IniFile.restore_state方法的典型用法代码示例。如果您正苦于以下问题:Python IniFile.restore_state方法的具体用法?Python IniFile.restore_state怎么用?Python IniFile.restore_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gladevcp.persistence.IniFile的用法示例。


在下文中一共展示了IniFile.restore_state方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_button_press

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
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)
开发者ID:AndreasHFA,项目名称:machinekit,代码行数:56,代码来源:classhandler_persistent.py

示例2: _on_state_changed

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
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)
开发者ID:13788593535,项目名称:machinekit,代码行数:51,代码来源:gladevcp-jwp.py

示例3: on_manual_mode

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
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)
开发者ID:AceXIE,项目名称:LinuxCNC-EtherCAT-HAL-Driver,代码行数:88,代码来源:probe.py

示例4: __init__

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
class PlasmaClass:

    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")
#.........这里部分代码省略.........
开发者ID:brianmorel99,项目名称:linuxcnc-mirror,代码行数:103,代码来源:plasma.py

示例5: on_button_press

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
class HandlerClass:
    '''
    class with gladevcp callback handlers
    '''

    def on_button_press(self,halwidget,data=None):
        '''
        a callback method
        parameters are:
            the generating object instance, like 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()"
        self.nhits += 1
        halwidget.set_label("hits: %d" % self.nhits)


    def on_toggle_button(self,hal_button,data=None):
        '''
        standard button-pressed callback. Parameter is the widget object instance.
        '''
        print "on_toggle_button() HAL pin value: %s" %(str(hal_button.hal_pin.get()))

    def _on_example_trigger_change(self,hal_pin,data=None):
        '''
        executed when the 'example-trigger' hal pin value changes
        note that this callback will not be exposed as potential callback
        handler through gladevcp since the name begins with an underscore (_) .
        Parameter is the HAL pin instance.
        '''
        print "_on_example_trigger_change() - HAL pin value: %s" % (hal_pin.get())

    def on_led_pin_changed(self,hal_led,data=None):
        '''
        this is an example of a hal-pin-changed signal handler as set in glade.
        The purpose of this callback is to deliver an optional notification to your code beyond
        just reacting to the changed HAL pin.
        the on_led_pin_changed signal is set in the complex.ui hal_led1 signals section
        '''
        print "on_led_pin_changed() - HAL pin value:",hal_led.hal_pin.get()

    def _on_timer_tick(self,userdata=None):
        '''
        the full glib functionality is available if needed.
        here's a timer function which will be called periodically
        returning True restarts the timer
        returning False makes it a one-shot
        '''
        self.lifetime_ticks += 1
        self.builder.get_object('message').hal_pin.set(self.lifetime_ticks)
        return True


    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):
        '''
        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:
#.........这里部分代码省略.........
开发者ID:AndreasHFA,项目名称:machinekit,代码行数:103,代码来源:complex.py

示例6: __init__

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
class PWMClass:

    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)

    def calc_and_set_milliseconds(self, value):
        self.laser_milliseconds = value
        if (self.laser_milliseconds < 20):
            self.laser_milliseconds = 20
        if (self.laser_milliseconds > 990):
            self.laser_milliseconds = 990
        self.halcomp["laser_hertz_value"]  = (1000000 / self.laser_milliseconds)

        self.lbl_duration_value.set_label("%d" % self.laser_milliseconds)
        os.system("halcmd setp hm2_5i20.0.pwmgen.pwm_frequency %d" % self.halcomp["laser_hertz_value"])

    def on_btn_pressed(self, pin, value):
        self.calc_and_set_milliseconds(value)

    def on_unix_signal(self,signum,stack_frame):
        print "on_unix_signal(): signal %d received, saving state" % (signum)
        self.ini.save_state(self)

    def _on_destroy(self, obj, data = None):
        self.ini.save_state(self)
开发者ID:owhite,项目名称:linuxcnc_config,代码行数:64,代码来源:pwm_tab.py

示例7: __init__

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
class LaserClass:
    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)

    def human_readable_file_date(self, f):
        seconds = int(float(time.time()) - float(os.path.getmtime(f)))
        value = ''
        if seconds < 10:
            value = 'NEW'
        elif seconds < 60:
            value = '%d sec' % seconds
        elif seconds < (60 * 2):
            value = '%d min' % (seconds / 60)
        elif seconds < (2 * 60 * 60):
            value = '%d mins' % (seconds / 60)
        elif seconds > (60 * 60 * 60):
            value = '%dh' % (seconds / (60 * 60 * 60))
        else:
            value = 'age?'
        return (value)

    # chows the thing.ngc file and finds the numth occurance of 
    #  of a comment in the form "^(text)"
    def extract_headline(self, file_name, num):
        f = open(file_name, "r")
        tag = self.human_readable_file_date(file_name)
        count = 0
        for line in f.read().splitlines():
            if re.match("^\(.*", line):
                if count == (num - 1):
                    line = re.sub('[\(\))]', '', line)
                    return('%s (%s)' % (line, tag))
                count += 1

    def on_btn_squealer_pressed(self, pin, data = None):
        print "poked squealer button"

    def on_timer_tick(self,userdata=None):
        if os.path.isfile(self.target_path):
            r = self.extract_headline(self.target_path, 1)
#.........这里部分代码省略.........
开发者ID:owhite,项目名称:linuxcnc_config,代码行数:103,代码来源:appliances.py

示例8: _query_emc_status

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
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)
开发者ID:CNCBASHER,项目名称:linuxcnc,代码行数:79,代码来源:miller_vcp.py

示例9: _query_emc_status

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]

#.........这里部分代码省略.........
#            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_spindle_brake_toggled(self, widget, data=None):
#        if (not self.e.manual_ok(do_poll=True)):
#            # bypass issuing MDI when program is running
#            return        
#
#        if (self.halcomp['spindle.brake'] == 0):
#            self.halcomp['spindle.brake'] = 1
##            self.e.mdi_command('M64 P9', True)  
#        else:
#            self.halcomp['spindle.brake'] = 0
##            self.e.mdi_command('M65 P9', 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 set_theme_font(self):
        # set ui theme
        config = ConfigParser.ConfigParser()
        fn = os.path.expanduser(".touchy_preferences")
        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)        

开发者ID:araisrobo,项目名称:linuxcnc,代码行数:68,代码来源:css_vcp.py

示例10: _query_emc_status

# 需要导入模块: from gladevcp.persistence import IniFile [as 别名]
# 或者: from gladevcp.persistence.IniFile import restore_state [as 别名]
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)
        # 為了左右邊的 mdi command 訊號可以同步
        if(self.e.spindle_speed() > 0):
            self.builder.get_object('do1').set_active(True)     # M3, SPINDLE.FWD
            self.builder.get_object('do2').set_active(False)    # M4, SPINDLE.REV
        elif(self.e.spindle_speed() < 0):
            self.builder.get_object('do1').set_active(False)    # M3, SPINDLE.FWD
            self.builder.get_object('do2').set_active(True)     # M4, SPINDLE.REV
        else:
            self.builder.get_object('do1').set_active(False)
            self.builder.get_object('do2').set_active(False)

#        print self.e.active_modes()
        # 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_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)
#.........这里部分代码省略.........
开发者ID:araisrobo,项目名称:linuxcnc,代码行数:103,代码来源:miller_vcp.py


注:本文中的gladevcp.persistence.IniFile.restore_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。