Пример #1
0
        def __init__(self, inifile):
		# System default Glade file:
                self.gladefile = os.path.join(datadir, "touchy.glade")
                if inifile:
                        self.ini = linuxcnc.ini(inifile)
                        alternate_gladefile = self.ini.find("DISPLAY", "GLADEFILE")
                        if alternate_gladefile:
                                self.gladefile = alternate_gladefile
                else:
                        self.ini = None


	        self.wTree = gtk.glade.XML(self.gladefile) 

		for w in ['wheelinc1', 'wheelinc2', 'wheelinc3',
				'wheelx', 'wheely', 'wheelz',
				'wheela', 'wheelb', 'wheelc',
				'wheelu', 'wheelv', 'wheelw']:
			self.wTree.get_widget(w).get_child().set_property('width-chars', 6)

		for widget in self.wTree.get_widget_prefix(''):
			widget.unset_flags(gtk.CAN_FOCUS)
		self.wTree.get_widget('MainWindow').set_flags(gtk.CAN_FOCUS)
		self.wTree.get_widget('MainWindow').grab_focus()

                self.num_mdi_labels = 11
                self.num_filechooser_labels = 11
                self.num_listing_labels = 20

                self.wheelxyz = 0
                self.wheelinc = 0
                self.wheel = "fo"
                self.radiobutton_mask = 0
                self.resized_wheelbuttons = 0

                self.tab = 0

                self.fo_val = 100
                self.so_val = 100
                self.g10l11 = 0

                self.prefs = preferences.preferences()
                self.mv_val = self.prefs.getpref('maxvel', 100, int)
                self.control_font_name = self.prefs.getpref('control_font', 'Sans 18', str)
                self.dro_font_name = self.prefs.getpref('dro_font', 'Courier 10 Pitch Bold 16', str)
                self.error_font_name = self.prefs.getpref('error_font', 'Sans Bold 10', str)
                self.listing_font_name = self.prefs.getpref('listing_font', 'Sans 10', str)
                self.theme_name = self.prefs.getpref('gtk_theme', 'Follow System Theme', str)
                self.abs_textcolor = self.prefs.getpref('abs_textcolor', 'default', str)
                self.rel_textcolor = self.prefs.getpref('rel_textcolor', 'default', str)
                self.dtg_textcolor = self.prefs.getpref('dtg_textcolor', 'default', str)
                self.err_textcolor = self.prefs.getpref('err_textcolor', 'default', str)
                self.window_geometry = self.prefs.getpref('window_geometry', 'default', str)
                self.window_max = self.prefs.getpref('window_force_max', 'False', bool)

                # initial screen setup
                if os.path.exists(themedir):
                    model = self.wTree.get_widget("theme_choice").get_model()
                    model.clear()
                    model.append(("Follow System Theme",))
                    temp = 0
                    names = os.listdir(themedir)
                    names.sort()
                    for search,dirs in enumerate(names):
                        model.append((dirs,))
                        if dirs  == self.theme_name:
                            temp = search+1
                    self.wTree.get_widget("theme_choice").set_active(temp)

                if self.window_geometry == "default":
		            self.wTree.get_widget("MainWindow").window.maximize()
                else:
                    self.wTree.get_widget("MainWindow").parse_geometry(self.window_geometry)
                    if self.window_max:
                        self.wTree.get_widget("MainWindow").window.maximize()

                self.invisible_cursor = self.prefs.getpref('invisible_cursor', 0)
                if self.invisible_cursor:
                        self.wTree.get_widget("MainWindow").window.set_cursor(invisible)
                else:
                        self.wTree.get_widget("MainWindow").window.set_cursor(None)
                self.wTree.get_widget("controlfontbutton").set_font_name(self.control_font_name)
                self.control_font = pango.FontDescription(self.control_font_name)

                self.wTree.get_widget("drofontbutton").set_font_name(self.dro_font_name)
                self.dro_font = pango.FontDescription(self.dro_font_name)

                self.wTree.get_widget("errorfontbutton").set_font_name(self.error_font_name)
                self.error_font = pango.FontDescription(self.error_font_name)

                self.wTree.get_widget("listingfontbutton").set_font_name(self.listing_font_name)
                self.listing_font = pango.FontDescription(self.listing_font_name)

                settings = gtk.settings_get_default()
                self.system_theme = settings.get_property("gtk-theme-name")
                if not self.theme_name == "Follow System Theme":
                    settings.set_string_property("gtk-theme-name", self.theme_name, "")

                # interactive mdi command builder and issuer
                mdi_labels = []
                mdi_eventboxes = []
                for i in range(self.num_mdi_labels):
                        mdi_labels.append(self.wTree.get_widget("mdi%d" % i))
                        mdi_eventboxes.append(self.wTree.get_widget("eventbox_mdi%d" % i))
                self.mdi_control = mdi.mdi_control(gtk, linuxcnc, mdi_labels, mdi_eventboxes)

                if self.ini:
                    macros = self.ini.findall("TOUCHY", "MACRO")
                    if len(macros) > 0:
                        self.mdi_control.mdi.add_macros(macros)
                    else:
                        self.wTree.get_widget("macro").set_sensitive(0)

                listing_labels = []
                listing_eventboxes = []
                for i in range(self.num_listing_labels):
                        listing_labels.append(self.wTree.get_widget("listing%d" % i))
                        listing_eventboxes.append(self.wTree.get_widget("eventbox_listing%d" % i))
                self.listing = listing.listing(gtk, linuxcnc, listing_labels, listing_eventboxes)

                # emc interface
                self.linuxcnc = emc_interface.emc_control(linuxcnc, self.listing, self.wTree.get_widget("error"))
                self.linuxcnc.continuous_jog_velocity(self.mv_val)
                self.hal = hal_interface.hal_interface(self, self.linuxcnc, self.mdi_control, linuxcnc)

                # silly file chooser
                filechooser_labels = []
                filechooser_eventboxes = []
                for i in range(self.num_filechooser_labels):
                        filechooser_labels.append(self.wTree.get_widget("filechooser%d" % i))
                        filechooser_eventboxes.append(self.wTree.get_widget("eventbox_filechooser%d" % i))
                self.filechooser = filechooser.filechooser(gtk, linuxcnc, filechooser_labels, filechooser_eventboxes, self.listing)

                relative = ['xr', 'yr', 'zr', 'ar', 'br', 'cr', 'ur', 'vr', 'wr']
                absolute = ['xa', 'ya', 'za', 'aa', 'ba', 'ca', 'ua', 'va', 'wa']
                distance = ['xd', 'yd', 'zd', 'ad', 'bd', 'cd', 'ud', 'vd', 'wd']
                relative = [self.wTree.get_widget(i) for i in relative]
                absolute = [self.wTree.get_widget(i) for i in absolute]
                distance = [self.wTree.get_widget(i) for i in distance]
                
                estops = ['estop_reset', 'estop']
                estops = dict((i, self.wTree.get_widget(i)) for i in estops)
                machines = ['on', 'off']
                machines = dict((i, self.wTree.get_widget("machine_" + i)) for i in machines)
                floods = ['on', 'off']
                floods = dict((i, self.wTree.get_widget("flood_" + i)) for i in floods)
                mists = ['on', 'off']
                mists = dict((i, self.wTree.get_widget("mist_" + i)) for i in mists)
                spindles = ['forward', 'off', 'reverse']
                spindles = dict((i, self.wTree.get_widget("spindle_" + i)) for i in spindles)
                stats = ['file', 'file_lines', 'line', 'id', 'dtg', 'velocity', 'delay', 'onlimit',
                         'spindledir', 'spindlespeed', 'loadedtool', 'preppedtool',
                         'xyrotation', 'tlo', 'activecodes', 'spindlespeed2',
                         'label_g5xoffset', 'g5xoffset', 'g92offset', 'tooltable']
                stats = dict((i, self.wTree.get_widget("status_" + i)) for i in stats)
                prefs = ['actual', 'commanded', 'inch', 'mm']
                prefs = dict((i, self.wTree.get_widget("dro_" + i)) for i in prefs)
                opstop = ['on', 'off']
                opstop = dict((i, self.wTree.get_widget("opstop_" + i)) for i in opstop)
                blockdel = ['on', 'off']
                blockdel = dict((i, self.wTree.get_widget("blockdel_" + i)) for i in blockdel)
                self.status = emc_interface.emc_status(gtk, linuxcnc, self.listing, relative, absolute, distance,
                                                       self.wTree.get_widget("dro_table"),
                                                       self.wTree.get_widget("error"),
                                                       estops, machines,
                                                       self.wTree.get_widget("override_limits"),
                                                       stats,
                                                       floods, mists, spindles, prefs,
                                                       opstop, blockdel)

                self.current_file = self.status.emcstat.file
                # check the ini file if UNITS are set to mm"
                # first check the global settings
                units=self.ini.find("TRAJ","LINEAR_UNITS")

                if units==None:
                        units=self.ini.find("AXIS_X","UNITS")

                if units=="mm" or units=="metric" or units == "1.0":
                        self.machine_units_mm=1
                        conversion=[1.0/25.4]*3+[1]*3+[1.0/25.4]*3
                else:
                        self.machine_units_mm=0
                        conversion=[25.4]*3+[1]*3+[25.4]*3

                self.status.set_machine_units(self.machine_units_mm,conversion)

                if self.prefs.getpref('toolsetting_fixture', 0):
                        self.g10l11 = 1
                else:
                        self.g10l11 = 0

                if self.prefs.getpref('dro_mm', 0):
                        self.status.dro_mm(0)
                else:
                        self.status.dro_inch(0)

                if self.prefs.getpref('dro_actual', 0):
                        self.status.dro_actual(0)
                else:
                        self.status.dro_commanded(0)

                if self.prefs.getpref('blockdel', 0):
                        self.linuxcnc.blockdel_on(0)
                else:
                        self.linuxcnc.blockdel_off(0)

                if self.prefs.getpref('opstop', 1):
                        self.linuxcnc.opstop_on(0)
                else:
                        self.linuxcnc.opstop_off(0)                        

		self.linuxcnc.emccommand.program_open(empty_program.name)

                self.linuxcnc.max_velocity(self.mv_val)
                                
                gobject.timeout_add(50, self.periodic_status)
                gobject.timeout_add(100, self.periodic_radiobuttons)

                # event bindings
                dic = {
                        "quit" : self.quit,
                        "on_pointer_show_clicked" : self.pointer_show,
                        "on_pointer_hide_clicked" : self.pointer_hide,
                        "on_opstop_on_clicked" : self.opstop_on,
                        "on_opstop_off_clicked" : self.opstop_off,
                        "on_blockdel_on_clicked" : self.blockdel_on,
                        "on_blockdel_off_clicked" : self.blockdel_off,
                        "on_reload_tooltable_clicked" : self.linuxcnc.reload_tooltable,
                        "on_notebook1_switch_page" : self.tabselect,
                        "on_controlfontbutton_font_set" : self.change_control_font,
                        "on_drofontbutton_font_set" : self.change_dro_font,
                        "on_dro_actual_clicked" : self.dro_actual,
                        "on_dro_commanded_clicked" : self.dro_commanded,
                        "on_dro_inch_clicked" : self.dro_inch,
                        "on_dro_mm_clicked" : self.dro_mm,
                        "on_errorfontbutton_font_set" : self.change_error_font,
                        "on_listingfontbutton_font_set" : self.change_listing_font,
                        "on_estop_clicked" : self.linuxcnc.estop,
                        "on_estop_reset_clicked" : self.linuxcnc.estop_reset,
                        "on_machine_off_clicked" : self.linuxcnc.machine_off,
                        "on_machine_on_clicked" : self.linuxcnc.machine_on,
                        "on_mdi_clear_clicked" : self.mdi_control.clear,
                        "on_mdi_back_clicked" : self.mdi_control.back,
                        "on_mdi_next_clicked" : self.mdi_control.next,
                        "on_mdi_decimal_clicked" : self.mdi_control.decimal,
                        "on_mdi_minus_clicked" : self.mdi_control.minus,
                        "on_mdi_keypad_clicked" : self.mdi_control.keypad,
                        "on_mdi_g_clicked" : self.mdi_control.g,
                        "on_mdi_gp_clicked" : self.mdi_control.gp,
                        "on_mdi_m_clicked" : self.mdi_control.m,
                        "on_mdi_t_clicked" : self.mdi_control.t,
                        "on_mdi_select" : self.mdi_control.select,
                        "on_mdi_set_tool_clicked" : self.mdi_set_tool,
                        "on_mdi_set_origin_clicked" : self.mdi_set_origin,
                        "on_mdi_macro_clicked" : self.mdi_macro,
                        "on_filechooser_select" : self.fileselect,
                        "on_filechooser_up_clicked" : self.filechooser.up,
                        "on_filechooser_down_clicked" : self.filechooser.down,
                        "on_filechooser_reload_clicked" : self.filechooser.reload,
                        "on_listing_up_clicked" : self.listing.up,
                        "on_listing_down_clicked" : self.listing.down,
                        "on_listing_previous_clicked" : self.listing.previous,
                        "on_listing_next_clicked" : self.listing.next,
                        "on_mist_on_clicked" : self.linuxcnc.mist_on,
                        "on_mist_off_clicked" : self.linuxcnc.mist_off,
                        "on_flood_on_clicked" : self.linuxcnc.flood_on,
                        "on_flood_off_clicked" : self.linuxcnc.flood_off,
                        "on_home_all_clicked" : self.linuxcnc.home_all,
                        "on_unhome_all_clicked" : self.linuxcnc.unhome_all,
                        "on_home_selected_clicked" : self.home_selected,
                        "on_unhome_selected_clicked" : self.unhome_selected,
                        "on_fo_clicked" : self.fo,
                        "on_so_clicked" : self.so,
                        "on_mv_clicked" : self.mv,
                        "on_jogging_clicked" : self.jogging,
                        "on_scrolling_clicked" : self.scrolling,
                        "on_wheelx_clicked" : self.wheelx,
                        "on_wheely_clicked" : self.wheely,
                        "on_wheelz_clicked" : self.wheelz,
                        "on_wheela_clicked" : self.wheela,
                        "on_wheelb_clicked" : self.wheelb,
                        "on_wheelc_clicked" : self.wheelc,
                        "on_wheelu_clicked" : self.wheelu,
                        "on_wheelv_clicked" : self.wheelv,
                        "on_wheelw_clicked" : self.wheelw,
                        "on_wheelinc1_clicked" : self.wheelinc1,
                        "on_wheelinc2_clicked" : self.wheelinc2,
                        "on_wheelinc3_clicked" : self.wheelinc3,
                        "on_override_limits_clicked" : self.linuxcnc.override_limits,
                        "on_spindle_forward_clicked" : self.linuxcnc.spindle_forward,
                        "on_spindle_off_clicked" : self.linuxcnc.spindle_off,
                        "on_spindle_reverse_clicked" : self.linuxcnc.spindle_reverse,
                        "on_spindle_slower_clicked" : self.linuxcnc.spindle_slower,
                        "on_spindle_faster_clicked" : self.linuxcnc.spindle_faster,
                        "on_toolset_fixture_clicked" : self.toolset_fixture,
                        "on_toolset_workpiece_clicked" : self.toolset_workpiece,
                        "on_changetheme_clicked" : self.change_theme,
                        }
                self.wTree.signal_autoconnect(dic)

		for widget in self.wTree.get_widget_prefix(''):
			if isinstance(widget, gtk.Button):
				widget.connect_after('released',self.hack_leave)

                self._dynamic_childs = {}
                atexit.register(self.kill_dynamic_childs)
                self.set_dynamic_tabs()

                atexit.register(self.save_maxvel_pref)

                self.setfont()
Пример #2
0
    def __init__(self, inifile):
        # System default Glade file:
        self.gladefile = os.path.join(datadir, "touchy.glade")
        if inifile:
            self.ini = linuxcnc.ini(inifile)
            alternate_gladefile = self.ini.find("DISPLAY", "GLADEFILE")
            if alternate_gladefile:
                self.gladefile = alternate_gladefile
        else:
            self.ini = None

        self.wTree = gtk.glade.XML(self.gladefile)

        for w in [
                'wheelinc1', 'wheelinc2', 'wheelinc3', 'wheelx', 'wheely',
                'wheelz', 'wheela', 'wheelb', 'wheelc', 'wheelu', 'wheelv',
                'wheelw'
        ]:
            self.wTree.get_widget(w).get_child().set_property('width-chars', 6)

        for widget in self.wTree.get_widget_prefix(''):
            widget.unset_flags(gtk.CAN_FOCUS)
        self.wTree.get_widget('MainWindow').set_flags(gtk.CAN_FOCUS)
        self.wTree.get_widget('MainWindow').grab_focus()

        self.num_mdi_labels = 11
        self.num_filechooser_labels = 11
        self.num_listing_labels = 20

        self.wheelxyz = 0
        self.wheelinc = 0
        self.wheel = "fo"
        self.radiobutton_mask = 0
        self.resized_wheelbuttons = 0

        self.tab = 0

        self.fo_val = 100
        self.so_val = 100
        self.g10l11 = 0

        self.prefs = preferences.preferences()
        self.mv_val = self.prefs.getpref('maxvel', 100, int)
        self.control_font_name = self.prefs.getpref('control_font', 'Sans 18',
                                                    str)
        self.dro_font_name = self.prefs.getpref('dro_font',
                                                'Courier 10 Pitch Bold 16',
                                                str)
        self.error_font_name = self.prefs.getpref('error_font', 'Sans Bold 10',
                                                  str)
        self.listing_font_name = self.prefs.getpref('listing_font', 'Sans 10',
                                                    str)
        self.theme_name = self.prefs.getpref('gtk_theme',
                                             'Follow System Theme', str)
        self.abs_textcolor = self.prefs.getpref('abs_textcolor', 'default',
                                                str)
        self.rel_textcolor = self.prefs.getpref('rel_textcolor', 'default',
                                                str)
        self.dtg_textcolor = self.prefs.getpref('dtg_textcolor', 'default',
                                                str)
        self.err_textcolor = self.prefs.getpref('err_textcolor', 'default',
                                                str)
        self.window_geometry = self.prefs.getpref('window_geometry', 'default',
                                                  str)
        self.window_max = self.prefs.getpref('window_force_max', 'False', bool)

        # initial screen setup
        if os.path.exists(themedir):
            model = self.wTree.get_widget("theme_choice").get_model()
            model.clear()
            model.append((_("Follow System Theme"), ))
            temp = 0
            names = os.listdir(themedir)
            names.sort()
            for search, dirs in enumerate(names):
                model.append((dirs, ))
                if dirs == self.theme_name:
                    temp = search + 1
            self.wTree.get_widget("theme_choice").set_active(temp)

        if self.window_geometry == "default":
            self.wTree.get_widget("MainWindow").window.maximize()
        else:
            self.wTree.get_widget("MainWindow").parse_geometry(
                self.window_geometry)
            if self.window_max:
                self.wTree.get_widget("MainWindow").window.maximize()

        self.invisible_cursor = self.prefs.getpref('invisible_cursor', 0)
        if self.invisible_cursor:
            self.wTree.get_widget("MainWindow").window.set_cursor(invisible)
        else:
            self.wTree.get_widget("MainWindow").window.set_cursor(None)
        self.wTree.get_widget("controlfontbutton").set_font_name(
            self.control_font_name)
        self.control_font = pango.FontDescription(self.control_font_name)

        self.wTree.get_widget("drofontbutton").set_font_name(
            self.dro_font_name)
        self.dro_font = pango.FontDescription(self.dro_font_name)

        self.wTree.get_widget("errorfontbutton").set_font_name(
            self.error_font_name)
        self.error_font = pango.FontDescription(self.error_font_name)

        self.wTree.get_widget("listingfontbutton").set_font_name(
            self.listing_font_name)
        self.listing_font = pango.FontDescription(self.listing_font_name)

        settings = gtk.settings_get_default()
        self.system_theme = settings.get_property("gtk-theme-name")
        if not self.theme_name == "Follow System Theme":
            settings.set_string_property("gtk-theme-name", self.theme_name, "")

        # interactive mdi command builder and issuer
        mdi_labels = []
        mdi_eventboxes = []
        for i in range(self.num_mdi_labels):
            mdi_labels.append(self.wTree.get_widget("mdi%d" % i))
            mdi_eventboxes.append(self.wTree.get_widget("eventbox_mdi%d" % i))
        self.mdi_control = mdi.mdi_control(gtk, linuxcnc, mdi_labels,
                                           mdi_eventboxes)

        if self.ini:
            macros = self.ini.findall("TOUCHY", "MACRO")
            if len(macros) > 0:
                self.mdi_control.mdi.add_macros(macros)
            else:
                self.wTree.get_widget("macro").set_sensitive(0)

        listing_labels = []
        listing_eventboxes = []
        for i in range(self.num_listing_labels):
            listing_labels.append(self.wTree.get_widget("listing%d" % i))
            listing_eventboxes.append(
                self.wTree.get_widget("eventbox_listing%d" % i))
        self.listing = listing.listing(gtk, linuxcnc, listing_labels,
                                       listing_eventboxes)

        # emc interface
        self.linuxcnc = emc_interface.emc_control(
            linuxcnc, self.listing, self.wTree.get_widget("error"))
        self.linuxcnc.continuous_jog_velocity(self.mv_val)
        self.hal = hal_interface.hal_interface(self, self.linuxcnc,
                                               self.mdi_control, linuxcnc)

        # silly file chooser
        filechooser_labels = []
        filechooser_eventboxes = []
        for i in range(self.num_filechooser_labels):
            filechooser_labels.append(
                self.wTree.get_widget("filechooser%d" % i))
            filechooser_eventboxes.append(
                self.wTree.get_widget("eventbox_filechooser%d" % i))
        self.filechooser = filechooser.filechooser(gtk, linuxcnc,
                                                   filechooser_labels,
                                                   filechooser_eventboxes,
                                                   self.listing)

        relative = ['xr', 'yr', 'zr', 'ar', 'br', 'cr', 'ur', 'vr', 'wr']
        absolute = ['xa', 'ya', 'za', 'aa', 'ba', 'ca', 'ua', 'va', 'wa']
        distance = ['xd', 'yd', 'zd', 'ad', 'bd', 'cd', 'ud', 'vd', 'wd']
        relative = [self.wTree.get_widget(i) for i in relative]
        absolute = [self.wTree.get_widget(i) for i in absolute]
        distance = [self.wTree.get_widget(i) for i in distance]

        estops = ['estop_reset', 'estop']
        estops = dict((i, self.wTree.get_widget(i)) for i in estops)
        machines = ['on', 'off']
        machines = dict(
            (i, self.wTree.get_widget("machine_" + i)) for i in machines)
        floods = ['on', 'off']
        floods = dict((i, self.wTree.get_widget("flood_" + i)) for i in floods)
        mists = ['on', 'off']
        mists = dict((i, self.wTree.get_widget("mist_" + i)) for i in mists)
        spindles = ['forward', 'off', 'reverse']
        spindles = dict(
            (i, self.wTree.get_widget("spindle_" + i)) for i in spindles)
        stats = [
            'file', 'file_lines', 'line', 'id', 'dtg', 'velocity', 'delay',
            'onlimit', 'spindledir', 'spindlespeed', 'loadedtool',
            'preppedtool', 'xyrotation', 'tlo', 'activecodes', 'spindlespeed2',
            'label_g5xoffset', 'g5xoffset', 'g92offset', 'tooltable'
        ]
        stats = dict((i, self.wTree.get_widget("status_" + i)) for i in stats)
        prefs = ['actual', 'commanded', 'inch', 'mm']
        prefs = dict((i, self.wTree.get_widget("dro_" + i)) for i in prefs)
        opstop = ['on', 'off']
        opstop = dict(
            (i, self.wTree.get_widget("opstop_" + i)) for i in opstop)
        blockdel = ['on', 'off']
        blockdel = dict(
            (i, self.wTree.get_widget("blockdel_" + i)) for i in blockdel)
        self.status = emc_interface.emc_status(
            gtk, linuxcnc, self.listing, relative, absolute, distance,
            self.wTree.get_widget("dro_table"),
            self.wTree.get_widget("error"), estops, machines,
            self.wTree.get_widget("override_limits"), stats, floods, mists,
            spindles, prefs, opstop, blockdel)

        self.current_file = self.status.emcstat.file
        # check the ini file if UNITS are set to mm"
        # first check the global settings
        units = self.ini.find("TRAJ", "LINEAR_UNITS")

        if units == None:
            units = self.ini.find("AXIS_X", "UNITS")

        if units == "mm" or units == "metric" or units == "1.0":
            self.machine_units_mm = 1
            conversion = [1.0 / 25.4] * 3 + [1] * 3 + [1.0 / 25.4] * 3
        else:
            self.machine_units_mm = 0
            conversion = [25.4] * 3 + [1] * 3 + [25.4] * 3

        self.status.set_machine_units(self.machine_units_mm, conversion)

        if self.prefs.getpref('toolsetting_fixture', 0):
            self.g10l11 = 1
        else:
            self.g10l11 = 0

        if self.prefs.getpref('dro_mm', 0):
            self.status.dro_mm(0)
        else:
            self.status.dro_inch(0)

        if self.prefs.getpref('dro_actual', 0):
            self.status.dro_actual(0)
        else:
            self.status.dro_commanded(0)

        if self.prefs.getpref('blockdel', 0):
            self.linuxcnc.blockdel_on(0)
        else:
            self.linuxcnc.blockdel_off(0)

        if self.prefs.getpref('opstop', 1):
            self.linuxcnc.opstop_on(0)
        else:
            self.linuxcnc.opstop_off(0)

        self.linuxcnc.emccommand.program_open(empty_program.name)

        self.linuxcnc.max_velocity(self.mv_val)

        gobject.timeout_add(50, self.periodic_status)
        gobject.timeout_add(100, self.periodic_radiobuttons)

        # event bindings
        dic = {
            "quit": self.quit,
            "on_pointer_show_clicked": self.pointer_show,
            "on_pointer_hide_clicked": self.pointer_hide,
            "on_opstop_on_clicked": self.opstop_on,
            "on_opstop_off_clicked": self.opstop_off,
            "on_blockdel_on_clicked": self.blockdel_on,
            "on_blockdel_off_clicked": self.blockdel_off,
            "on_reload_tooltable_clicked": self.linuxcnc.reload_tooltable,
            "on_notebook1_switch_page": self.tabselect,
            "on_controlfontbutton_font_set": self.change_control_font,
            "on_drofontbutton_font_set": self.change_dro_font,
            "on_dro_actual_clicked": self.dro_actual,
            "on_dro_commanded_clicked": self.dro_commanded,
            "on_dro_inch_clicked": self.dro_inch,
            "on_dro_mm_clicked": self.dro_mm,
            "on_errorfontbutton_font_set": self.change_error_font,
            "on_listingfontbutton_font_set": self.change_listing_font,
            "on_estop_clicked": self.linuxcnc.estop,
            "on_estop_reset_clicked": self.linuxcnc.estop_reset,
            "on_machine_off_clicked": self.linuxcnc.machine_off,
            "on_machine_on_clicked": self.linuxcnc.machine_on,
            "on_mdi_clear_clicked": self.mdi_control.clear,
            "on_mdi_back_clicked": self.mdi_control.back,
            "on_mdi_next_clicked": self.mdi_control.next,
            "on_mdi_decimal_clicked": self.mdi_control.decimal,
            "on_mdi_minus_clicked": self.mdi_control.minus,
            "on_mdi_keypad_clicked": self.mdi_control.keypad,
            "on_mdi_g_clicked": self.mdi_control.g,
            "on_mdi_gp_clicked": self.mdi_control.gp,
            "on_mdi_m_clicked": self.mdi_control.m,
            "on_mdi_t_clicked": self.mdi_control.t,
            "on_mdi_select": self.mdi_control.select,
            "on_mdi_set_tool_clicked": self.mdi_set_tool,
            "on_mdi_set_origin_clicked": self.mdi_set_origin,
            "on_mdi_macro_clicked": self.mdi_macro,
            "on_filechooser_select": self.fileselect,
            "on_filechooser_up_clicked": self.filechooser.up,
            "on_filechooser_down_clicked": self.filechooser.down,
            "on_filechooser_reload_clicked": self.filechooser.reload,
            "on_listing_up_clicked": self.listing.up,
            "on_listing_down_clicked": self.listing.down,
            "on_listing_previous_clicked": self.listing.previous,
            "on_listing_next_clicked": self.listing.next,
            "on_mist_on_clicked": self.linuxcnc.mist_on,
            "on_mist_off_clicked": self.linuxcnc.mist_off,
            "on_flood_on_clicked": self.linuxcnc.flood_on,
            "on_flood_off_clicked": self.linuxcnc.flood_off,
            "on_home_all_clicked": self.linuxcnc.home_all,
            "on_unhome_all_clicked": self.linuxcnc.unhome_all,
            "on_home_selected_clicked": self.home_selected,
            "on_unhome_selected_clicked": self.unhome_selected,
            "on_fo_clicked": self.fo,
            "on_so_clicked": self.so,
            "on_mv_clicked": self.mv,
            "on_jogging_clicked": self.jogging,
            "on_scrolling_clicked": self.scrolling,
            "on_wheelx_clicked": self.wheelx,
            "on_wheely_clicked": self.wheely,
            "on_wheelz_clicked": self.wheelz,
            "on_wheela_clicked": self.wheela,
            "on_wheelb_clicked": self.wheelb,
            "on_wheelc_clicked": self.wheelc,
            "on_wheelu_clicked": self.wheelu,
            "on_wheelv_clicked": self.wheelv,
            "on_wheelw_clicked": self.wheelw,
            "on_wheelinc1_clicked": self.wheelinc1,
            "on_wheelinc2_clicked": self.wheelinc2,
            "on_wheelinc3_clicked": self.wheelinc3,
            "on_override_limits_clicked": self.linuxcnc.override_limits,
            "on_spindle_forward_clicked": self.linuxcnc.spindle_forward,
            "on_spindle_off_clicked": self.linuxcnc.spindle_off,
            "on_spindle_reverse_clicked": self.linuxcnc.spindle_reverse,
            "on_spindle_slower_clicked": self.linuxcnc.spindle_slower,
            "on_spindle_faster_clicked": self.linuxcnc.spindle_faster,
            "on_toolset_fixture_clicked": self.toolset_fixture,
            "on_toolset_workpiece_clicked": self.toolset_workpiece,
            "on_changetheme_clicked": self.change_theme,
        }
        self.wTree.signal_autoconnect(dic)

        for widget in self.wTree.get_widget_prefix(''):
            if isinstance(widget, gtk.Button):
                widget.connect_after('released', self.hack_leave)

        self._dynamic_childs = {}
        atexit.register(self.kill_dynamic_childs)
        self.set_dynamic_tabs()

        atexit.register(self.save_maxvel_pref)

        self.setfont()
Пример #3
0
        def __init__(self, inifile):
                # begin: read glade file name from ini file
                if inifile:
                    ini = linuxcnc.ini(inifile)
                    self.ini = ini
                else:
                    self.ini = None

		# Set the gettext application domain
		o = ini.find("DISPLAY", "APP_DOMAIN")
                if o == None:
                    # default application domain to emc2.mo
		    o = "emc2"
                LOCALEDIR = os.path.join(BASE, "share", "locale")
                gettext.install(o, localedir=LOCALEDIR, unicode=True)
                gtk.glade.bindtextdomain(o, LOCALEDIR)
                gtk.glade.textdomain(o)
               
                # check for for jog flag
                self.foce_jog = "FALSE"
                self.force_jog = ini.find("DISPLAY", "JOG_ALWAYS")
		# Set the Glade file
		o = ini.find("DISPLAY", "GLADE_FILE")
                if o == None:
                    # default 
		    self.gladefile = os.path.join(datadir, "touchy.glade")
                else:
                    self.gladefile = os.path.join(datadir,o)
                self.wTree = gtk.Builder()
                self.wTree.add_from_file(self.gladefile)

	        #for libglade: self.wTree = gtk.glade.XML(self.gladefile) 
	# 	for widget in self.wTree.get_widget_prefix(''):
	# 		widget.unset_flags(gtk.CAN_FOCUS)
		# self.wTree.get_widget('MainWindow').set_flags(gtk.CAN_FOCUS)
                # self.wTree.get_widget('MainWindow').grab_focus()
	  	for obj in self.wTree.get_objects():
                    if (type(obj) == gtk.Object):
	  		 obj.unset_flags(gtk.CAN_FOCUS)
		self.wTree.get_object('MainWindow').set_flags(gtk.CAN_FOCUS)
                self.wTree.get_object('MainWindow').grab_focus()
                self.num_mdi_labels = 11
                self.num_filechooser_labels = 11
                self.num_listing_labels = 20

                self.wheelxyz = 0
                self.wheelinc = 0
                self.wheel = "fo"
                self.radiobutton_mask = 0
                self.resized_wheelbuttons = 0

                self.tab = 0

                self.fo_val = 100
                self.so_val = 100
                self.g10l11 = 0

                self.prefs = preferences.preferences()
                self.mv_val = self.prefs.getpref('maxvel', 100, int)
                self.control_font_name = self.prefs.getpref('control_font', 'Sans 18', str)
                self.dro_font_name = self.prefs.getpref('dro_font', 'Courier 10 Pitch Bold 16', str)
                self.error_font_name = self.prefs.getpref('error_font', 'Sans Bold 10', str)
                self.listing_font_name = self.prefs.getpref('listing_font', 'Sans 10', str)
                self.theme_name = self.prefs.getpref('gtk_theme', 'Follow System Theme', str)
                self.abs_textcolor = self.prefs.getpref('abs_textcolor', 'default', str)
                self.rel_textcolor = self.prefs.getpref('rel_textcolor', 'default', str)
                self.dtg_textcolor = self.prefs.getpref('dtg_textcolor', 'default', str)
                self.err_textcolor = self.prefs.getpref('err_textcolor', 'default', str)
                self.window_geometry = self.prefs.getpref('window_geometry', 'default', str)
                self.window_max = self.prefs.getpref('window_force_max', 'False', bool)

                # initial screen setup
#                if os.path.exists(themedir):
                    # model = self.wTree.get_object("theme_choice").get_model()
                    #model = self.wTree.get_widget("theme_choice").get_model()
                    # model.clear()
                    # model.append(("Follow System Theme",))
#                    temp = 0
#                    names = os.listdir(themedir)
#                    names.sort()
#                    for search,dirs in enumerate(names):
#                        model.append((dirs,))
#                        if dirs  == self.theme_name:
#                            temp = search+1
#                    self.wTree.get_object("theme_choice").set_active(temp)
                    # self.wTree.get_widget("theme_choice").set_active(temp)

                if self.window_geometry == "default":
		            self.wTree.get_object("MainWindow").window.maximize()
		            # self.wTree.get_widget("MainWindow").window.maximize()
                else:
                    self.wTree.get_object("MainWindow").parse_geometry(self.window_geometry)
                    # self.wTree.get_widget("MainWindow").parse_geometry(self.window_geometry)
                    if self.window_max:
                        self.wTree.get_object("MainWindow").window.maximize()
                        # self.wTree.get_widget("MainWindow").window.maximize()

                self.wTree.get_object("MainWindow").window.set_cursor(None)
                self.control_font = pango.FontDescription(self.control_font_name)

#                self.wTree.get_object("drofontbutton").set_font_name(self.dro_font_name)
                # self.wTree.get_widget("drofontbutton").set_font_name(self.dro_font_name)
                self.dro_font = pango.FontDescription(self.dro_font_name)

#                self.wTree.get_object("errorfontbutton").set_font_name(self.error_font_name)
                # self.wTree.get_widget("errorfontbutton").set_font_name(self.error_font_name)
                self.error_font = pango.FontDescription(self.error_font_name)

#                self.wTree.get_object("listingfontbutton").set_font_name(self.listing_font_name)
                # self.wTree.get_widget("listingfontbutton").set_font_name(self.listing_font_name)
                self.listing_font = pango.FontDescription(self.listing_font_name)

                settings = gtk.settings_get_default()
                self.system_theme = settings.get_property("gtk-theme-name")
                if not self.theme_name == "Follow System Theme":
                    settings.set_string_property("gtk-theme-name", self.theme_name, "")

#                # interactive mdi command builder and issuer
#                mdi_labels = []
#                mdi_eventboxes = []
#                for i in range(self.num_mdi_labels):
#                        mdi_labels.append(self.wTree.get_object("mdi%d" % i))
#                        mdi_eventboxes.append(self.wTree.get_object("eventbox_mdi%d" % i))
#                self.mdi_control = mdi.mdi_control(gtk, linuxcnc, mdi_labels, mdi_eventboxes)

                if inifile:
                    ini = linuxcnc.ini(inifile)
#                    self.mdi_control.mdi.add_macros(
#                        ini.findall("TOUCHY", "MACRO"))
                    self.ini = ini
                else:
                    self.ini = None

#                listing_labels = []
#                listing_eventboxes = []
#                for i in range(self.num_listing_labels):
#                        listing_labels.append(self.wTree.get_object("listing%d" % i))
#                        listing_eventboxes.append(self.wTree.get_object("eventbox_listing%d" % i))
#                self.listing = listing.listing(gtk, linuxcnc, listing_labels, listing_eventboxes)

                # emc interface
                # self.linuxcnc = emc_interface.emc_control(linuxcnc, self.listing, self.wTree.get_object("error"))
                self.linuxcnc = emc_interface.emc_control(linuxcnc, None, None)
                self.linuxcnc.continuous_jog_velocity(self.mv_val)

                # set injector to 1 if use_injection is set
                # don't instance injector before halcomp is initialized
                self.injector = None
                o = ini.find("DISPLAY", "USE_INJECTION")
                if o is not None:
                  o = o.lower()
                  if o == 'yes':
                    from injector import InjectorClass
                    self.injector = 1
  
                #self.hal = hal_interface.hal_interface(self, self.linuxcnc, self.mdi_control, linuxcnc)
                self.hal = hal_interface.hal_interface(self, self.linuxcnc, None, linuxcnc)
                if self.injector == 1:
                    # instance injector after halcomp initialized
                    # make hal pin depends description from the xml file
                    panel = gladevcp.makepins.GladePanel( self.hal.c,
                            self.gladefile, self.wTree, None)
                    self.injector = InjectorClass(self,self.hal.c, self.wTree) #

#                # silly file chooser
#                filechooser_labels = []
#                filechooser_eventboxes = []
#                for i in range(self.num_filechooser_labels):
#                        filechooser_labels.append(self.wTree.get_object("filechooser%d" % i))
#                        filechooser_eventboxes.append(self.wTree.get_object("eventbox_filechooser%d" % i))
#                self.filechooser = filechooser.filechooser(gtk, linuxcnc, filechooser_labels, filechooser_eventboxes, self.listing)

                relative = ['xr', 'yr', 'zr', 'ar', 'br', 'cr', 'ur', 'vr', 'wr']
                absolute = ['xa', 'ya', 'za', 'aa', 'ba', 'ca', 'ua', 'va', 'wa']
                distance = ['xd', 'yd', 'zd', 'ad', 'bd', 'cd', 'ud', 'vd', 'wd']
                # relative = [self.wTree.get_widget(i) for i in relative]
                # absolute = [self.wTree.get_widget(i) for i in absolute]
                # distance = [self.wTree.get_widget(i) for i in distance]
                relative = [self.wTree.get_object(i) for i in relative]
                absolute = [self.wTree.get_object(i) for i in absolute]
                distance = [self.wTree.get_object(i) for i in distance]
                
                estops = ['estop_reset', 'estop']
                estops = dict((i, self.wTree.get_object(i)) for i in estops)
                # estops = dict((i, self.wTree.get_widget(i)) for i in estops)
                machines = ['on', 'off']
                machines = dict((i, self.wTree.get_object("machine_" + i)) for i in machines)
                # machines = dict((i, self.wTree.get_widget("machine_" + i)) for i in machines)
                floods = ['on', 'off']
                floods = dict((i, self.wTree.get_object("flood_" + i)) for i in floods)
                # floods = dict((i, self.wTree.get_widget("flood_" + i)) for i in floods)
                mists = ['on', 'off']
                mists = dict((i, self.wTree.get_object("mist_" + i)) for i in mists)
                # mists = dict((i, self.wTree.get_widget("mist_" + i)) for i in mists)
                spindles = ['forward', 'off', 'reverse']
                spindles = dict((i, self.wTree.get_object("spindle_" + i)) for i in spindles)
                # spindles = dict((i, self.wTree.get_widget("spindle_" + i)) for i in spindles)
                stats = ['file', 'file_lines', 'line', 'id', 'dtg', 'velocity', 'delay', 'onlimit',
                         'spindledir', 'spindlespeed', 'loadedtool', 'preppedtool',
                         'xyrotation', 'tlo', 'activecodes', 'spindlespeed2',
                         'label_g5xoffset', 'g5xoffset', 'g92offset', 'tooltable']
                stats = dict((i, self.wTree.get_object("status_" + i)) for i in stats)
                # stats = dict((i, self.wTree.get_widget("status_" + i)) for i in stats)
                prefs = ['actual', 'commanded', 'inch', 'mm']
                prefs = dict((i, self.wTree.get_object("dro_" + i)) for i in prefs)
                # prefs = dict((i, self.wTree.get_widget("dro_" + i)) for i in prefs)
                opstop = ['on', 'off']
                opstop = dict((i, self.wTree.get_object("opstop_" + i)) for i in opstop)
                # opstop = dict((i, self.wTree.get_widget("opstop_" + i)) for i in opstop)
                blockdel = ['on', 'off']
                blockdel = dict((i, self.wTree.get_object("blockdel_" + i)) for i in blockdel)
                self.status = emc_interface.emc_status(gtk, linuxcnc, None, relative, absolute, distance,
                                                       self.wTree.get_object("dro_table"),
                                                       self.wTree.get_object("error"),
                                                       estops, machines,
                                                       self.wTree.get_object("override_limits"),
                                                       # self.wTree.get_widget("override_limits"),
                                                       stats,
                                                       floods, mists, spindles, prefs,
                                                       opstop, blockdel)

                # check the ini file if UNITS are set to mm"
                inifile=self.linuxcnc.emc.ini(sys.argv[2])
                # first check the global settings
                units=inifile.find("TRAJ","LINEAR_UNITS")

                if units==None:
                        units=inifile.find("AXIS_0","UNITS")

                if units=="mm" or units=="metric" or units == "1.0":
                        self.machine_units_mm=1
                        conversion=[1.0/25.4]*3+[1]*3+[1.0/25.4]*3
                else:
                        self.machine_units_mm=0
                        conversion=[25.4]*3+[1]*3+[25.4]*3

                self.status.set_machine_units(self.machine_units_mm,conversion)

                if self.prefs.getpref('toolsetting_fixture', 0):
                        self.g10l11 = 1
                else:
                        self.g10l11 = 0

                if self.prefs.getpref('dro_mm', 0):
                        self.status.dro_mm(0)
                else:
                        self.status.dro_inch(0)

                if self.prefs.getpref('dro_actual', 0):
                        self.status.dro_actual(0)
                else:
                        self.status.dro_commanded(0)

                if self.prefs.getpref('blockdel', 0):
                        self.linuxcnc.blockdel_on(0)
                else:
                        self.linuxcnc.blockdel_off(0)

                if self.prefs.getpref('opstop', 1):
                        self.linuxcnc.opstop_on(0)
                else:
                        self.linuxcnc.opstop_off(0)                        

# TODO:		self.linuxcnc.emccommand.program_open(empty_program.name)

                self.linuxcnc.max_velocity(self.mv_val)
                                
                gobject.timeout_add(50, self.periodic_status)
                gobject.timeout_add(100, self.periodic_radiobuttons)
                
                # event bindings
                dic = {
                        "quit" : self.quit,
                        "on_opstop_on_clicked" : self.opstop_on,
                        "on_opstop_off_clicked" : self.opstop_off,
                        "on_blockdel_on_clicked" : self.blockdel_on,
                        "on_blockdel_off_clicked" : self.blockdel_off,
                        "on_reload_tooltable_clicked" : self.linuxcnc.reload_tooltable,
                        "on_notebook1_switch_page" : self.tabselect,
                        "on_controlfontbutton_font_set" : self.change_control_font,
                        "on_drofontbutton_font_set" : self.change_dro_font,
                        "on_dro_actual_clicked" : self.dro_actual,
                        "on_dro_commanded_clicked" : self.dro_commanded,
                        "on_dro_inch_clicked" : self.dro_inch,
                        "on_dro_mm_clicked" : self.dro_mm,
                        "on_errorfontbutton_font_set" : self.change_error_font,
                        "on_listingfontbutton_font_set" : self.change_listing_font,
                        "on_estop_clicked" : self.linuxcnc.estop,
                        "on_estop_reset_clicked" : self.linuxcnc.estop_reset,
                        "on_machine_off_clicked" : self.linuxcnc.machine_off,
                        "on_machine_on_clicked" : self.linuxcnc.machine_on,
#                        "on_mdi_clear_clicked" : self.mdi_control.clear,
#                        "on_mdi_back_clicked" : self.mdi_control.back,
#                        "on_mdi_next_clicked" : self.mdi_control.next,
#                        "on_mdi_decimal_clicked" : self.mdi_control.decimal,
#                        "on_mdi_minus_clicked" : self.mdi_control.minus,
#                        "on_mdi_keypad_clicked" : self.mdi_control.keypad,
#                        "on_mdi_g_clicked" : self.mdi_control.g,
#                        "on_mdi_gp_clicked" : self.mdi_control.gp,
#                        "on_mdi_m_clicked" : self.mdi_control.m,
#                        "on_mdi_t_clicked" : self.mdi_control.t,
#                        "on_mdi_select" : self.mdi_control.select,
#                        "on_mdi_set_tool_clicked" : self.mdi_set_tool,
#                        "on_mdi_set_origin_clicked" : self.mdi_set_origin,
#                        "on_mdi_macro_clicked" : self.mdi_macro,
#                        "on_filechooser_select" : self.fileselect,
#                        "on_filechooser_up_clicked" : self.filechooser.up,
#                        "on_filechooser_down_clicked" : self.filechooser.down,
#                        "on_filechooser_reload_clicked" : self.filechooser.reload,
#                        "on_listing_up_clicked" : self.listing.up,
#                        "on_listing_down_clicked" : self.listing.down,
#                        "on_listing_previous_clicked" : self.listing.previous,
#                        "on_listing_next_clicked" : self.listing.next,
                        "on_mist_on_clicked" : self.linuxcnc.mist_on,
                        "on_mist_off_clicked" : self.linuxcnc.mist_off,
                        "on_flood_on_clicked" : self.linuxcnc.flood_on,
                        "on_flood_off_clicked" : self.linuxcnc.flood_off,
                        "on_home_all_clicked" : self.linuxcnc.home_all,
                        "on_unhome_all_clicked" : self.linuxcnc.unhome_all,
                        "on_home_selected_clicked" : self.home_selected,
                        "on_unhome_selected_clicked" : self.unhome_selected,
                        "on_fo_clicked" : self.fo,
                        "on_so_clicked" : self.so,
                        "on_mv_clicked" : self.mv,
                        "on_jogging_clicked" : self.jogging,
                        "on_wheelx_clicked" : self.wheelx,
                        "on_wheely_clicked" : self.wheely,
                        "on_wheelz_clicked" : self.wheelz,
                        "on_wheela_clicked" : self.wheela,
                        "on_wheelb_clicked" : self.wheelb,
                        "on_wheelc_clicked" : self.wheelc,
                        "on_wheelu_clicked" : self.wheelu,
                        "on_wheelv_clicked" : self.wheelv,
                        "on_wheelw_clicked" : self.wheelw,
                        "on_wheelinc1_clicked" : self.wheelinc1,
                        "on_wheelinc2_clicked" : self.wheelinc2,
                        "on_wheelinc3_clicked" : self.wheelinc3,
                        "on_override_limits_clicked" : self.linuxcnc.override_limits,
                        "on_spindle_forward_clicked" : self.linuxcnc.spindle_forward,
                        "on_spindle_off_clicked" : self.linuxcnc.spindle_off,
                        "on_spindle_reverse_clicked" : self.linuxcnc.spindle_reverse,
                        "on_spindle_slower_clicked" : self.linuxcnc.spindle_slower,
                        "on_spindle_faster_clicked" : self.linuxcnc.spindle_faster,
                        "on_toolset_fixture_clicked" : self.toolset_fixture,
                        "on_toolset_workpiece_clicked" : self.toolset_workpiece,
                        "on_changetheme_clicked" : self.change_theme,
                        }
                # also connect singal to injector
                if self.injector is not None:
                  dic.update(self.injector.dic)
                self.wTree.connect_signals(dic)
                if self.injector is not None:
                  self.wTree.connect_signals(self.injector)
                # self.wTree.signal_autoconnect(dic)

		#necessary? for widget in self.wTree.get_objects():
		#necessary? # for widget in self.wTree.get_widget_prefix(''):
		#necessary? 	if isinstance(widget, gtk.Button):
		#necessary? 		widget.connect_after('released',self.hack_leave)

                self._dynamic_childs = {}
                atexit.register(self.kill_dynamic_childs)
                self.set_dynamic_tabs()
                 
                atexit.register(self.save_maxvel_pref)

                self.setfont()
                try:
                  self.wGladevcp = GladeBuilder(self.wTree)
                except:
                  pass