From: Chris M. <gi...@gi...> - 2013-07-14 01:12:52
|
gladevcp -change the layout and control functions of offsetpage_widget for consistancy have the axes in the colomns and the offsets in rows. You can now edit any user system. You can add descriptions of the systems. The current system's text is in red, others are black. you can hide or show any colomn or row. different highlighting options Gscreen is changed to not error - rows and colums are switched now. http://git.linuxcnc.org/?p=linuxcnc.git;a=commitdiff;h=a4a02af --- lib/python/gladevcp/offsetpage.glade | 394 ++++++++++--- lib/python/gladevcp/offsetpage_widget.py | 950 +++++++++++++++++-------------- src/emc/usr_intf/gscreen/gscreen.py | 3 +- 3 files changed, 831 insertions(+), 516 deletions(-) diff --git a/lib/python/gladevcp/offsetpage.glade b/lib/python/gladevcp/offsetpage.glade index fd2fec1..13285b2 100644 --- a/lib/python/gladevcp/offsetpage.glade +++ b/lib/python/gladevcp/offsetpage.glade @@ -4,35 +4,263 @@ <!-- interface-naming-policy project-wide --> <object class="GtkListStore" id="liststore2"> <columns> - <!-- column-name Axis --> + <!-- column-name name --> <column type="gchararray"/> - <!-- column-name Tool --> + <!-- column-name X --> <column type="gchararray"/> - <!-- column-name G5x --> + <!-- column-name Y --> <column type="gchararray"/> - <!-- column-name G92 --> + <!-- column-name Z --> <column type="gchararray"/> - <!-- column-name Rot --> + <!-- column-name A --> <column type="gchararray"/> - <!-- column-name G54 --> + <!-- column-name B --> <column type="gchararray"/> - <!-- column-name G55 --> + <!-- column-name C --> <column type="gchararray"/> - <!-- column-name G56 --> + <!-- column-name U --> <column type="gchararray"/> - <!-- column-name G57 --> + <!-- column-name V --> <column type="gchararray"/> - <!-- column-name G58 --> + <!-- column-name W --> <column type="gchararray"/> - <!-- column-name G59 --> + <!-- column-name display_row --> + <column type="gboolean"/> + <!-- column-name editable --> + <column type="gboolean"/> + <!-- column-name background_color --> <column type="gchararray"/> - <!-- column-name G59.1 --> + <!-- column-name foreground_color --> <column type="gchararray"/> - <!-- column-name G59.2 --> - <column type="gchararray"/> - <!-- column-name G59.3 --> + <!-- column-name type --> <column type="gchararray"/> </columns> + <data> + <row> + <col id="0" translatable="yes">Tool</col> + <col id="1" translatable="yes">1</col> + <col id="2" translatable="yes">2</col> + <col id="3" translatable="yes">3</col> + <col id="4" translatable="yes">4</col> + <col id="5" translatable="yes">5</col> + <col id="6" translatable="yes">6</col> + <col id="7" translatable="yes">7</col> + <col id="8" translatable="yes">8</col> + <col id="9" translatable="yes">9</col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">Tool</col> + </row> + <row> + <col id="0" translatable="yes">G5x</col> + <col id="1" translatable="yes">1</col> + <col id="2" translatable="yes">2</col> + <col id="3" translatable="yes">3</col> + <col id="4" translatable="yes">4</col> + <col id="5" translatable="yes">5</col> + <col id="6" translatable="yes">6</col> + <col id="7" translatable="yes">7</col> + <col id="8" translatable="yes">8</col> + <col id="9" translatable="yes">9</col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G5x</col> + </row> + <row> + <col id="0" translatable="yes">Rot</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">Rot</col> + </row> + <row> + <col id="0" translatable="yes">G92</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes">0</col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G92</col> + </row> + <row> + <col id="0" translatable="yes">G54</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G54</col> + </row> + <row> + <col id="0" translatable="yes">G55</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G55</col> + </row> + <row> + <col id="0" translatable="yes">G56</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G56</col> + </row> + <row> + <col id="0" translatable="yes">G57</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G57</col> + </row> + <row> + <col id="0" translatable="yes">G58</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G58</col> + </row> + <row> + <col id="0" translatable="yes">G59</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G59</col> + </row> + <row> + <col id="0" translatable="yes">G59.1</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G59.1</col> + </row> + <row> + <col id="0" translatable="yes">G59.2</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G59.2</col> + </row> + <row> + <col id="0" translatable="yes">G59.3</col> + <col id="1" translatable="yes"></col> + <col id="2" translatable="yes"></col> + <col id="3" translatable="yes"></col> + <col id="4" translatable="yes"></col> + <col id="5" translatable="yes"></col> + <col id="6" translatable="yes"></col> + <col id="7" translatable="yes"></col> + <col id="8" translatable="yes"></col> + <col id="9" translatable="yes"></col> + <col id="10">True</col> + <col id="11">False</col> + <col id="12" translatable="yes">white</col> + <col id="13" translatable="yes">black</col> + <col id="14" translatable="yes">G59.3</col> + </row> + </data> + </object> + <object class="GtkTreeModelFilter" id="modelfilter"> + <property name="child_model">liststore2</property> </object> <object class="GtkWindow" id="window1"> <child> @@ -48,163 +276,159 @@ <object class="GtkTreeView" id="treeview2"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="model">liststore2</property> + <property name="model">modelfilter</property> <property name="search_column">0</property> <property name="hover_expand">True</property> <property name="enable_grid_lines">both</property> <child> - <object class="GtkTreeViewColumn" id="axis"> - <property name="title">Axis</property> - <property name="sort_indicator">True</property> - <property name="sort_column_id">1</property> + <object class="GtkTreeViewColumn" id="name"> + <property name="title">Offset</property> + <property name="sort_column_id">0</property> <child> - <object class="GtkCellRendererText" id="cell_axis"/> + <object class="GtkCellRendererText" id="cell_name"/> <attributes> + <attribute name="foreground">13</attribute> <attribute name="text">0</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="tool"> - <property name="title">Tool</property> + <object class="GtkTreeViewColumn" id="X"> + <property name="title">X</property> <child> - <object class="GtkCellRendererText" id="cell_tool"/> + <object class="GtkCellRendererText" id="cell_X"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">1</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g5x"> - <property name="title">G5x</property> + <object class="GtkTreeViewColumn" id="Y"> + <property name="title">Y</property> <child> - <object class="GtkCellRendererText" id="cell_g5x"/> + <object class="GtkCellRendererText" id="cell_Y"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">2</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g92"> - <property name="title">G92</property> + <object class="GtkTreeViewColumn" id="Z"> + <property name="title">Z</property> <child> - <object class="GtkCellRendererText" id="cell_g92"/> + <object class="GtkCellRendererText" id="cell_Z"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">3</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="rot"> + <object class="GtkTreeViewColumn" id="A"> <property name="spacing">3</property> - <property name="title">R</property> + <property name="title">A</property> <child> - <object class="GtkCellRendererText" id="cell_rot"/> + <object class="GtkCellRendererText" id="cell_A"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">4</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g54"> - <property name="title">G54</property> + <object class="GtkTreeViewColumn" id="B"> + <property name="title">B</property> <child> - <object class="GtkCellRendererText" id="cell_g54"/> + <object class="GtkCellRendererText" id="cell_B"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">5</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g55"> - <property name="title">G55</property> + <object class="GtkTreeViewColumn" id="C"> + <property name="title">C</property> <child> - <object class="GtkCellRendererText" id="cell_g55"/> + <object class="GtkCellRendererText" id="cell_C"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">6</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g56"> - <property name="title">G56</property> + <object class="GtkTreeViewColumn" id="U"> + <property name="title">U</property> <child> - <object class="GtkCellRendererText" id="cell_g56"/> + <object class="GtkCellRendererText" id="cell_U"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">7</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g57"> - <property name="title">G57</property> + <object class="GtkTreeViewColumn" id="V"> + <property name="title">V</property> <child> - <object class="GtkCellRendererText" id="cell_g57"/> + <object class="GtkCellRendererText" id="cell_V"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">8</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g58"> - <property name="title">G58</property> + <object class="GtkTreeViewColumn" id="W"> + <property name="title">W</property> <child> - <object class="GtkCellRendererText" id="cell_g58"/> + <object class="GtkCellRendererText" id="cell_W"/> <attributes> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> <attribute name="text">9</attribute> </attributes> </child> </object> </child> <child> - <object class="GtkTreeViewColumn" id="g59"> - <property name="title">G59</property> - <child> - <object class="GtkCellRendererText" id="cell_g59"/> - <attributes> - <attribute name="text">10</attribute> - </attributes> - </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="g59_1"> - <property name="title">G59.1</property> - <child> - <object class="GtkCellRendererText" id="cell_g59_1"/> - <attributes> - <attribute name="text">11</attribute> - </attributes> - </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="g59_2"> - <property name="title">G59.2</property> - <child> - <object class="GtkCellRendererText" id="cell_g59_2"/> - <attributes> - <attribute name="text">12</attribute> - </attributes> - </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="g59_3"> - <property name="title">G59.3</property> + <object class="GtkTreeViewColumn" id="type"> + <property name="title">Offset Name</property> <child> - <object class="GtkCellRendererText" id="cell_g59_3"/> + <object class="GtkCellRendererText" id="cell_type"/> <attributes> - <attribute name="text">13</attribute> + <attribute name="background">12</attribute> + <attribute name="editable">11</attribute> + <attribute name="foreground">13</attribute> + <attribute name="text">14</attribute> </attributes> </child> </object> diff --git a/lib/python/gladevcp/offsetpage_widget.py b/lib/python/gladevcp/offsetpage_widget.py index fae4579..e754212 100644 --- a/lib/python/gladevcp/offsetpage_widget.py +++ b/lib/python/gladevcp/offsetpage_widget.py @@ -1,430 +1,520 @@ -#!/usr/bin/env python -# GladeVcp Widget - offsetpage -# -# Copyright (c) 2013 Chris Morley -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# This widget reads the offsets for current tool, current G5x, G92 using python library linuxcnc. -# all other offsets are read directly from the Var file, if available, as linuxcnc does not give -# access to all offsets thru NML, only current ones. -# you can hide any axes or any columns -# set metric or imperial -# set the var file to search -# set the text formatting for metric/imperial separately - -import sys, os, pango, linuxcnc -datadir = os.path.abspath(os.path.dirname(__file__)) -KEYWORDS = ["axis","tool","g5x","g92","rot","g54","g55","g56","g57","g58","g59","g59_1","g59_2","g59_3"] -AXISLIST = ['X','Y','Z','A','B','C','U','V','W'] - -try: - import gobject,gtk -except: - print('GTK not available') - sys.exit(1) - -# we put this in a try so there is no error in the glade editor -# linuxcnc is probably not running then -try: - INIPATH = os.environ['INI_FILE_NAME'] -except: - pass - -class OffsetPage(gtk.VBox): - __gtype_name__ = 'OffsetPage' - __gproperties__ = { - 'display_units_mm' : ( gobject.TYPE_BOOLEAN, 'Display Units', 'Display in metric or not', - False, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT), - 'mm_text_template' : ( gobject.TYPE_STRING, 'Text template for Metric Units', - 'Text template to display. Python formatting may be used for one variable', - "%10.3f", gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT), - 'imperial_text_template' : ( gobject.TYPE_STRING, 'Text template for Imperial Units', - 'Text template to display. Python formatting may be used for one variable', - "%9.4f", gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT), - 'font' : ( gobject.TYPE_STRING, 'Pango Font', 'Display font to use', - "sans 12", gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT), - 'highlight_color' : ( gtk.gdk.Color.__gtype__, 'Highlight color', "", - gobject.PARAM_READWRITE), - 'hide_columns' : ( gobject.TYPE_STRING, 'Hidden Columns', 'A no-spaces list of columns to hide: 0-9 a-d are the options', - "", gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT), - 'hide_joints' : ( gobject.TYPE_STRING, 'Hidden Joints', 'A no-spaces list of joints to hide: 0-9 and/or axis lettets are the options', - "", gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT), - } - __gproperties = __gproperties__ - - def __init__(self,filename=None, *a, **kw): - super(OffsetPage, self).__init__() - self.filename = filename - self.linuxcnc = linuxcnc - self.status = linuxcnc.stat() - self.cmd = linuxcnc.command() - self.hash_check = None - self.display_units_mm=0 - self.machine_units_mm=0 - self.unit_convert=[1]*9 - self.font="sans 12" - self.editing_mode = False - self.highlight_color = gtk.gdk.Color("lightblue") - self.hidejointslist = [] - self.hidecollist = [] - self.wTree = gtk.Builder() - self.wTree.add_from_file(os.path.join(datadir, "offsetpage.glade") ) - - # global references - self.model = self.wTree.get_object("liststore2") - self.all_window = self.wTree.get_object("all_window") - self.view2 = self.wTree.get_object("treeview2") - self.edit_button = self.wTree.get_object("edit_button") - self.edit_button.connect( 'toggled', self.set_editing) - zero_g92_button = self.wTree.get_object("zero_g92_button") - zero_g92_button.connect( 'clicked', self.zero_g92) - - for col,name in enumerate(KEYWORDS): - temp = self.wTree.get_object("cell_"+ name) - temp.connect( 'edited', self.col_editted, col ) - temp.set_property('font', self.font) - # reparent tooledit box from Glades top level window to widgets VBox - window = self.wTree.get_object("offsetpage_box") - window.reparent(self) - - # check the ini file if UNITS are set to mm - # first check the global settings - # else then the X axis units - try: - self.inifile = self.linuxcnc.ini(INIPATH) - units=self.inifile.find("TRAJ","LINEAR_UNITS") - if units==None: - units=self.inifile.find("AXIS_0","UNITS") - except: - print "**** Offsetpage widget ERROR: LINEAR_UNITS not found in INI's TRAJ section" - units = "inch" - - # now setup the conversion array depending on the machine native units - if units=="mm" or units=="metric" or units == "1.0": - self.machine_units_mm=1 - self.conversion=[1.0/25.4]*3+[1]*3+[1.0/25.4]*3 - else: - self.machine_units_mm=0 - self.conversion=[25.4]*3+[1]*3+[25.4]*3 - - # make a list of available axis - try: - temp = self.inifile.find("TRAJ","COORDINATES") - self.axisletters = "" - for letter in temp: - if not letter.lower() in ["x","y","z","a","b","c","u","v","w"]: continue - self.axisletters += letter.lower() - except: - print "**** Offsetpage widget ERROR: Axis list not found in INI's TRAJ COODINATES section" - self.axisletters ="xyz" - - # check linuxcnc status every half second - gobject.timeout_add(1000, self.periodic_check) - - # Reload the offsets into display - def reload_offsets(self): - # clear the current liststore - self.model.clear() - - g54,g55,g56,g57,g58,g59,g59_1,g59_2,g59_3 = self.read_file() - - # Get the offsets arrays and convert the units if the display - # is not in machine native units - g5x = self.status.g5x_offset - tool = self.status.tool_offset - g92 = self.status.g92_offset - rot = self.status.rotation_xy - - if self.display_units_mm != self.machine_units_mm: - g5x = self.convert_units(g5x) - tool = self.convert_units(tool) - g92 = self.convert_units(g92) - g54 = self.convert_units(g54) - g55 = self.convert_units(g55) - g56 = self.convert_units(g56) - g57 = self.convert_units(g57) - g58 = self.convert_units(g58) - g59 = self.convert_units(g59) - g59_1 = self.convert_units(g59_1) - g59_2 = self.convert_units(g59_2) - g59_3 = self.convert_units(g59_3) - - # set the text style based on unit type - if self.display_units_mm: - tmpl = lambda s: self.mm_text_template % s - else: - tmpl = lambda s: self.imperial_text_template % s - - # fill each row of the array fron the offsets arrays - array = ['0','0','0','0','0','0','0','0','0','0','0','0','0','0'] - for axisnum, axis in enumerate(AXISLIST): - array[0] = axis - array[1] = tmpl(tool[axisnum]) - array[2] = tmpl(g5x[axisnum]) - array[3] = tmpl(g92[axisnum]) - if axisnum == 0: - array[4] = rot - else: array[4] = "" - array[5] = tmpl(g54[axisnum]) - array[6] = tmpl(g55[axisnum]) - array[7] = tmpl(g56[axisnum]) - array[8] = tmpl(g57[axisnum]) - array[9] = tmpl(g58[axisnum]) - array[10] = tmpl(g59[axisnum]) - array[11] = tmpl(g59_1[axisnum]) - array[12] = tmpl(g59_2[axisnum]) - array[13] = tmpl(g59_3[axisnum]) - # add array line to liststore - # skipping the ones that are set to be hidden - if axisnum in self.hidejointslist: continue - self.model.append(array) - - # This is for adding a filename path after the offsetpage is already loaded. - def set_filename(self,filename): - self.filename = filename - self.reload_offsets() - - # We read the var file directly - # and pull out the info we need - # if anything goes wrong we set all the info to 0 - def read_file(self): - g54=[0,0,0,0,0,0,0,0,0] - g55=[0,0,0,0,0,0,0,0,0] - g56=[0,0,0,0,0,0,0,0,0] - g57=[0,0,0,0,0,0,0,0,0] - g58=[0,0,0,0,0,0,0,0,0] - g59=[0,0,0,0,0,0,0,0,0] - g59_1=[0,0,0,0,0,0,0,0,0] - g59_2=[0,0,0,0,0,0,0,0,0] - g59_3=[0,0,0,0,0,0,0,0,0] - if self.filename == None:return g54,g55,g56,g57,g58,g59,g59_1,g59_2,g59_3 - if not os.path.exists(self.filename): - return g54,g55,g56,g57,g58,g59,g59_1,g59_2,g59_3 - logfile = open(self.filename, "r").readlines() - for line in logfile: - temp = line.split() - param = int(temp[0]) - data = float(temp[1]) - - if 5229 >= param >= 5221: - g54[param -5221] = data - elif 5249 >= param >= 5241: - g55[param -5241] = data - elif 5269 >= param >= 5261: - g56[param -5261] = data - elif 5289 >= param >= 5281: - g57[param -5281] = data - elif 5309 >= param >= 5301: - g58[param -5301] = data - elif 5329 >= param >= 5321: - g59[param -5321] = data - elif 5349 >= param >= 5341: - g59_1[param -5341] = data - elif 5369 >= param >= 5361: - g59_2[param -5361] = data - elif 5389 >= param >= 5381: - g59_3[param -5381] = data - return g54,g55,g56,g57,g58,g59,g59_1,g59_2,g59_3 - - # This allows hiding or showing columns 0-9 a-d from a text string of columnns - # eg list ='12' - # default, all the columns are shown - def set_col_visible(self,list,bool): - try: - for index in range(0,len(list)): - colstr = str(list[index]) - colnum = "0123456789abcd".index(colstr.lower()) - name = KEYWORDS[colnum] - renderer = self.wTree.get_object(name) - renderer.set_property('visible', bool) - except: - pass - - # hide/show the joint rows from a text string of joint numbers - # eg list ='123' - # convert that to separate integers list - # eg index = '1' - # the hidejointslist is alway the joints to hide, so if the user asked for - # visible-True, then change that list to joints-to-hide - # ultimately this list is used to decide if the row will be added to the model or not - def set_row_visible(self,list,bool): - try: - if bool: - # must convert to joints-to-hide by removing the visible ones from a full list - self.hidejointslist = [0,1,2,3,4,5,6,7,8] - for index in range(0,len(list)): - try: - self.hidejointslist.remove(int(list[index])) - except: - axnum = "xyzabcuvw".index(str(list[index]).lower()) - self.hidejointslist.remove(axnum) - else: - self.hidejointslist = [] - for index in range(0,len(list)): - try: - self.hidejointslist.append(int(list[index])) - except: - axnum = "xyzabcuvw".index(str(list[index]).lower()) - self.hidejointslist.append(axnum) - except: - self.hidejointslist = [] - - # This does the units conversion - # it just mutiplies the two arrays - def convert_units(self,v): - c = self.conversion - return map(lambda x,y: x*y, v, c) - - # make the cells editable and hilight them - def set_editing(self, widget): - state = widget.get_active() - self.editing_mode = state - for obj in ("cell_g5x","cell_g92"): - temp = self.wTree.get_object(obj) - temp.set_property('editable', state) - if state: - temp.set_property('background', self.highlight_color) - else: - temp.set_property('background', None) - self.queue_draw() - - # When the column is edited this does the work - # TODO the edited column does not end up showing the editted number even though linuxcnc - # registered the change - def col_editted(self, widget, path, new_text, col): - print new_text, col, self.axisletters[int(path)] - try: - if self.status.task_mode != self.linuxcnc.MODE_MDI: - self.cmd.mode(self.linuxcnc.MODE_MDI) - self.cmd.wait_complete() - if col == 2: - self.cmd.mdi( "G10 L2 P0 %s %10.4f"%(self.axisletters[int(path)],float(new_text)) ) - elif col == 3: - self.cmd.mdi( "G92 %s %10.4f"%(self.axisletters[int(path)],float(new_text)) ) - self.cmd.mode(self.linuxcnc.MODE_MANUAL) - self.cmd.wait_complete() - self.cmd.mode(self.linuxcnc.MODE_MDI) - self.cmd.wait_complete() - except: - print "MDI error in offsetpage widget" - try: - self.model[path][col] = ("%10.4f"%float(new_text)) - except: - print "offsetpage widget error: unrecognized float input" - self.reload_offsets() - - # callback to cancel G92 when button pressed - def zero_g92(self,widget): - print "zero g92" - try: - if self.status.task_mode != self.linuxcnc.MODE_MDI: - self.cmd.mode(self.linuxcnc.MODE_MDI) - self.cmd.wait_complete() - self.cmd.mdi( "G92.2" ) - self.cmd.mode(self.linuxcnc.MODE_MANUAL) - self.cmd.wait_complete() - self.cmd.mode(self.linuxcnc.MODE_MDI) - self.cmd.wait_complete() - except: - print "MDI error in offsetpage widget" - - # check for linnuxcnc ON and IDLE which is the only safe time to edit the tool file. - # if in editing mode don't update else you can't actually edit - def periodic_check(self): - try: - self.status.poll() - on = self.status.task_state > linuxcnc.STATE_OFF - idle = self.status.interp_state == linuxcnc.INTERP_IDLE - self.edit_button.set_sensitive(bool(on and idle)) - except: - pass - if self.filename and not self.editing_mode: - self.reload_offsets() - return True - - # sets the color when editing is active - def set_highlight_color(self,value): - self.highlight_color = gtk.gdk.Color(value) - - # Allows you to set the text font of all the rows and columns - def set_font(self,value): - for col,name in enumerate(KEYWORDS): - temp = self.wTree.get_object("cell_"+ name) - temp.set_property('font', value) - - # helper function to set the units to inch - def set_to_inch(self): - self.display_units_mm = 0 - - # helper function to set the units to mm - def set_to_mm(self): - self.display_units_mm = 1 - - # standard Gobject method - def do_get_property(self, property): - name = property.name.replace('-', '_') - if name in self.__gproperties.keys(): - return getattr(self, name) - else: - raise AttributeError('unknown property %s' % property.name) - - # standard Gobject method - # This is so that in the Glade editor, you can change the display - def do_set_property(self, property, value): - name = property.name.replace('-', '_') - if name == 'font': - pass - if name == 'hide_columns': - self.set_col_visible("0123456789abcd",True) - self.set_col_visible("%s"%value,False) - if name == 'hide_joints': - self.set_row_visible("%s"%value,False) - if name in self.__gproperties.keys(): - setattr(self, name, value) - - # boiler code for variable access - def __getitem__(self, item): - return getattr(self, item) - def __setitem__(self, item, value): - return setattr(self, item, value) - - -# for testing without glade editor: -# Must linuxcnc running to see anything -def main(filename=None): - window = gtk.Dialog("My dialog", - None, - gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, - (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, - gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) - offsetpage = OffsetPage() - - window.vbox.add(offsetpage) - offsetpage.set_filename("../../../configs/sim/gscreen_custom/sim.var") - #offsetpage.set_col_visible("1abC",False) - #offsetpage.set_row_visible("0yz3b",True) - #offsetpage.set_to_mm() - #offsetpage.set_font("sans 20") - #offsetpage.set_property("highlight_color",gtk.gdk.Color('blue')) - #offsetpage.set_highlight_color("violet") - window.connect("destroy", gtk.main_quit) - window.show_all() - response = window.run() - if response == gtk.RESPONSE_ACCEPT: - print "True" - else: - print "False" - -if __name__ == "__main__": - main() - - +#!/usr/bin/env python +# GladeVcp Widget - offsetpage +# +# Copyright (c) 2013 Chris Morley +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# This widget reads the offsets for current tool, current G5x, G92 using python library linuxcnc. +# all other offsets are read directly from the Var file, if available, as linuxcnc does not give +# access to all offsets thru NML, only current ones. +# you can hide any axes or any columns +# set metric or imperial +# set the var file to search +# set the text formatting for metric/imperial separately + +import sys, os, pango, linuxcnc +datadir = os.path.abspath(os.path.dirname(__file__)) +AXISLIST = ['name','X','Y','Z','A','B','C','U','V','W','type'] +# we need to know if linuxcnc isn't running when using the GLADE editor |