This commit is contained in:
Norbert Schechner 2019-08-18 19:59:40 +02:00
commit 0f67445fad
9 changed files with 75 additions and 23 deletions

View file

@ -186,7 +186,6 @@ HOME_IS_SHARED = 1
# section for main IO controller parameters ----------------------------------- # section for main IO controller parameters -----------------------------------
[MACROS] [MACROS]
MACRO = go_to_position x-pos y-pos z-pos MACRO = go_to_position x-pos y-pos z-pos
MACRO = hallo_world
MACRO = i_am_lost MACRO = i_am_lost
MACRO = increment x-incr y-incr MACRO = increment x-incr y-incr
MACRO = macro_4 MACRO = macro_4
@ -201,6 +200,5 @@ MACRO = macro_12
MACRO = macro_13 MACRO = macro_13
MACRO = macro_14 MACRO = macro_14
MACRO = macro_15 MACRO = macro_15
MACRO = macro_16
MACRO = macro_17

View file

@ -1,6 +1,9 @@
; Testfile go to position ; Testfile go to position
; will jog the machine to a position to give ; will jog the machine to a position to give
; the image path must be relative from your config dir or absolut, "~" is allowed
(IMAGE, ./macros/images/goto_x_y_z.png)
O<go_to_position> sub O<go_to_position> sub
G17 G17

View file

@ -1,6 +1,9 @@
; Testfile I am Lost ; Testfile I am Lost
; will jog to machine cero and set all axis to cero ; will jog to machine cero and set all axis to cero
; the image path must be relative from your config dir or absolut, "~" is allowed
(IMAGE, ./macros/images/i_am_lost.png)
O<i_am_lost> sub O<i_am_lost> sub
G17 G17

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

View file

@ -1,6 +1,9 @@
; Testfile go to position ; Testfile go to position
; will jog the machine to a position to give ; will jog the machine to a position to give
; the image path must be relative from your config dir or absolut, "~" is allowed
(IMAGE, ./macros/images/macro_8.png)
O<macro_8> sub O<macro_8> sub
G17 G17

View file

@ -89,7 +89,7 @@ if debug:
# constants # constants
# # gmoccapy #" # # gmoccapy #"
_RELEASE = " 3.0.7.3" _RELEASE = " 3.0.8"
_INCH = 0 # imperial units are active _INCH = 0 # imperial units are active
_MM = 1 # metric units are active _MM = 1 # metric units are active
@ -694,19 +694,24 @@ class gmoccapy(object):
def _get_button_with_image(self, name, filepath, stock): def _get_button_with_image(self, name, filepath, stock):
image = gtk.Image() image = gtk.Image()
image.set_size_request(48,48) image.set_size_request(72,48)
btn = self._get_button(name, image)
if filepath:
image.set_from_file(filepath)
else:
image.set_from_stock(stock, 48)
return btn
def _get_button(self, name, image):
btn = gtk.Button() btn = gtk.Button()
btn.set_size_request(85,56) btn.set_size_request(85,56)
btn.add(image)
btn.set_property("name", name) btn.set_property("name", name)
try:
if filepath:
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filepath, 72, 48)
image.set_from_pixbuf(pixbuf)
else:
image.set_from_stock(stock, 48)
btn.add(image)
except:
message = _("**** GMOCCAPY ERROR ****\n")
message += _("**** could not resolv the image path '{0}' given for macro button '{1}' ****".format(filepath, name))
print(message)
image.set_from_stock(gtk.STOCK_MISSING_IMAGE, 48)
btn.add(image)
btn.show_all() btn.show_all()
return btn return btn
@ -1172,25 +1177,33 @@ class gmoccapy(object):
btn = self._get_button_with_image("previous_button", None, gtk.STOCK_GO_BACK) btn = self._get_button_with_image("previous_button", None, gtk.STOCK_GO_BACK)
btn.hide() btn.hide()
btn.set_property("tooltip-text", _("Press to display previous button")) btn.set_property("tooltip-text", _("Press to display previous macro button"))
btn.connect("clicked", self._on_btn_previous_macro_clicked) btn.connect("clicked", self._on_btn_previous_macro_clicked)
self.widgets.hbtb_MDI.pack_start(btn) self.widgets.hbtb_MDI.pack_start(btn)
for pos in range(0, num_macros): for pos in range(0, num_macros):
name = macros[pos] name = macros[pos]
image = self._check_macro_for_image(name)
if image:
print("Macro {0} has image link".format(name))
print("Image = {0}".format(image))
btn = self._get_button_with_image("macro_{0}".format(pos), image, None)
else:
lbl = name.split()[0] lbl = name.split()[0]
# shorten / break line of the name if it is to long # shorten / break line of the name if it is to long
if len(lbl) > 11: if len(lbl) > 11:
lbl = lbl[0:10] + "\n" + lbl[11:20] lbl = lbl[0:10] + "\n" + lbl[11:20]
btn = gtk.Button(lbl, None, False) btn = gtk.Button(lbl, None, False)
btn.set_property("name","macro_{0}".format(pos)) btn.set_property("name","macro_{0}".format(pos))
btn.set_property("tooltip-text", _("Press to run macro {0}".format(name)))
btn.connect("pressed", self._on_btn_macro_pressed, name) btn.connect("pressed", self._on_btn_macro_pressed, name)
btn.position = pos btn.position = pos
btn.show() btn.show()
self.widgets.hbtb_MDI.pack_start(btn, True, True, 0) self.widgets.hbtb_MDI.pack_start(btn, True, True, 0)
btn = self._get_button_with_image("next_button", None, gtk.STOCK_GO_FORWARD) btn = self._get_button_with_image("next_button", None, gtk.STOCK_GO_FORWARD)
btn.set_property("tooltip-text", _("Press to display next button")) btn.set_property("tooltip-text", _("Press to display next macro button"))
btn.connect("clicked", self._on_btn_next_macro_clicked) btn.connect("clicked", self._on_btn_next_macro_clicked)
btn.hide() btn.hide()
self.widgets.hbtb_MDI.pack_start(btn) self.widgets.hbtb_MDI.pack_start(btn)
@ -1227,6 +1240,33 @@ class gmoccapy(object):
for pos in range(8, num_macros): for pos in range(8, num_macros):
self.macro_dic["macro_{0}".format(pos)].hide() self.macro_dic["macro_{0}".format(pos)].hide()
def _check_macro_for_image(self, name):
image = False
for path in self.get_ini_info.get_subroutine_paths().split(":"):
file = path + "/" + name.split()[0] + ".ngc"
if os.path.isfile(file):
macrofile = open(file, "r")
lines = macrofile.readlines()
macrofile.close()
for line in lines:
if line[0] == ";":
continue
if "image" in line.lower():
image = True
break
# should be like that in ngc file
# (IMAGE, /home/my_home/my_image_dir/my_image.png)
# so we need to get the correct image path
if image:
image = line.split(",")[1]
image = image.strip()
image = image.replace(")","")
if "~" in image:
image = image.replace("~", os.path.expanduser("~"))
image = os.path.abspath(image)
return image
# if this is a lathe we need to rearrange some button and add a additional DRO # if this is a lathe we need to rearrange some button and add a additional DRO
def _make_lathe(self): def _make_lathe(self):
@ -2659,7 +2699,6 @@ class gmoccapy(object):
file = self.prefs.getpref("open_file", "", str) file = self.prefs.getpref("open_file", "", str)
if file: if file:
self.widgets.file_to_load_chooser.set_filename(file) self.widgets.file_to_load_chooser.set_filename(file)
# self.command.program_open(file)
self.widgets.hal_action_open.load_file(file) self.widgets.hal_action_open.load_file(file)
# check how to start the GUI # check how to start the GUI

View file

@ -1,3 +1,9 @@
ver 3.0.8
- added the possibility to add also images to macro button. The images will be
resized to fit the buttons (72x48). The macro file need to contain a line like
(IMAGE, ./macros/images/goto_x_y_z.png)
the path must be absolute or relative to the config dir, "~" is allowed in path
ver 3.0.7.3 ver 3.0.7.3
- Ralf reported an error toggling the Edit Offsets button. It was caused because - Ralf reported an error toggling the Edit Offsets button. It was caused because
I missed to change the widget handling of the dynamically created widgets on I missed to change the widget handling of the dynamically created widgets on