Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
def _make_jog_increments(self):
print("**** GMOCCAPY INFO ****")
print("**** Entering make jog increments")
# Now we will build the option buttons to select the Jog-rates
# We do this dynamically, because users are able to set them in INI File
# because of space on the screen only 10 items are allowed
# jogging increments
self.incr_rbt_dic = {}
# We get the increments from INI File
if len(self.jog_increments) > 10:
print(_("**** GMOCCAPY build_GUI INFO ****"))
print(_("**** To many increments given in INI File for this screen ****"))
print(_("**** Only the first 10 will be reachable through this screen ****"))
# we shorten the increment list to 10 (first is default = 0)
self.jog_increments = self.jog_increments[0:11]
# The first radio button is created to get a radio button group
# The group is called according the name off the first button
# We use the pressed signal, not the toggled, otherwise two signals will be emitted
# One from the released button and one from the pressed button
# we make a list of the buttons to later add the hardware pins to them
label = _("Continuous")
rbt = gtk.RadioButton(None, label)
rbt.set_property("name","rbt_0")
rbt.connect("pressed", self._jog_increment_changed)
self.widgets.vbtb_jog_incr.pack_start(rbt, True, True, 0)
rbt.set_property("draw_indicator", False)
rbt.show()
rbt.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("#FFFF00"))
self.incr_rbt_dic[rbt.name] = rbt
# the rest of the buttons are now added to the group
# self.no_increments is set while setting the hal pins with self._check_len_increments
for item in range(1, len(self.jog_increments)):
name = "rbt_{0}".format(item)
rbt = gtk.RadioButton(self.incr_rbt_dic["rbt_0"], self.jog_increments[item])
rbt.set_property("name",name)
rbt.connect("pressed", self._jog_increment_changed)
self.widgets.vbtb_jog_incr.pack_start(rbt, True, True, 0)
rbt.set_property("draw_indicator", False)
rbt.show()
rbt.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("#FFFF00"))
self.incr_rbt_dic[rbt.name] = rbt
self.incr_rbt_dic["rbt_0"].set_active(True)
self.active_increment = "rbt_0"
def _jog_increment_changed(self, widget,):
# first cancel any joints jogging
JOGMODE = self._get_jog_mode()
for jnum in range(self.stat.joints):
self.command.jog(linuxcnc.JOG_STOP, JOGMODE, jnum)
self.distance = self._parse_increment(widget.name)
self.halcomp["jog.jog-increment"] = self.distance
self.active_increment = widget.name
def _on_btn_jog_pressed(self, widget, button_name, shift=False):
print("Jog Button pressed = {0}".format(button_name))
# only in manual mode we will allow jogging the axis at this development state
# needed to avoid error on start up, machine not on
if not self.stat.enabled or self.stat.task_mode != linuxcnc.MODE_MANUAL:
return
joint_no_or_axis_index = self._get_joint_no_or_axis_index(button_name)
if joint_no_or_axis_index is None:
print("Did not get an axis number in jog part of the code")
return
# if shift = True, then the user pressed SHIFT for Jogging and
# want's to jog at full speed
# This can only happen on keyboard jogging, not with the on screen jog button
# We just only use one function for both cases
if shift:
# There are no keyboard shortcuts to home angular axis, but
# we implement the possibility for future options
if button_name[0] in "abc":
value = self.widgets.spc_ang_jog_vel.get_property("max") / 60
else:
value = self.stat.max_velocity
else:
if button_name[0] in "abc":
value = self.widgets.spc_ang_jog_vel.get_value() / 60
else:
value = self.widgets.spc_lin_jog_vel.get_value() / 60
velocity = value * (1 / self.faktor)
if button_name[1] == "+":
dir = 1
else:
dir = -1
JOGMODE = self._get_jog_mode()
if self.distance <> 0: # incremental jogging
distance = self.distance
if self.lathe_mode and self.diameter_mode and button_name[0] == "x":
distance = self.distance/2
self.command.jog(linuxcnc.JOG_INCREMENT, JOGMODE, joint_no_or_axis_index, dir * velocity, distance)
else: # continuous jogging
self.command.jog(linuxcnc.JOG_CONTINUOUS, JOGMODE, joint_no_or_axis_index, dir * velocity)
def _on_btn_jog_released(self, widget, button_name, shift=False):
print ("Jog Button released = {0}".format(button_name))
# only in manual mode we will allow jogging the axis at this development state
if not self.stat.enabled or self.stat.task_mode != linuxcnc.MODE_MANUAL:
return
joint_no_or_axis_index = self._get_joint_no_or_axis_index(button_name)
JOGMODE = self._get_jog_mode()
# Otherwise the movement would stop before the desired distance was moved
if self.distance <> 0:
pass
else:
self.command.jog(linuxcnc.JOG_STOP, JOGMODE, joint_no_or_axis_index)
def _get_jog_mode(self):
# self.stat.motion_mode ==
# 1 = Joint
# 2 = MDI
# 3 = TELOP
if self.stat.motion_mode == 1:
JOGMODE = 1
else :
JOGMODE = 0
return JOGMODE
def _get_joint_no_or_axis_index(self, button_name):
joint_btn = False
if not button_name[0] in "xyzabcuvw":
print("Axis button")
# OK, it may be a Joints button
if button_name[0] in "012345678":
print("joint button")
joint_btn = True
else:
print(_("**** GMOCCAPY INFO ****"))
print (_("unknown jog command {0}".format(button_name)))
return None
if not joint_btn:
# get the axisnumber from the index as specified in python interface documentation
if self.all_homed:
joint_no_or_axis_index = "xyzabcuvw".index(button_name[0])
else:
joint_no_or_axis_index = self._get_joint_from_joint_axis_dic(button_name[0])
else:
joint_no_or_axis_index = int(button_name[0])
return joint_no_or_axis_index
def _make_jog_button(self):
print("**** GMOCCAPY INFO ****")
print("**** Entering make jog button")
self.jog_button_dic = OrderedDict()
for axis in self.axis_list:
for direction in ["+","-"]:
name = "{0}{1}".format(str(axis), direction)
btn = gtk.Button(name.upper())
btn.set_property("name", name)
btn.connect("pressed", self._on_btn_jog_pressed, name)
btn.connect("released", self._on_btn_jog_released, name)
btn.set_property("tooltip-text", _("Press to jog axis {0}".format(axis)))
btn.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("#FFFF00"))
btn.set_size_request(48,48)
self.jog_button_dic[name] = btn
def _make_joints_button(self):
print("**** GMOCCAPY INFO ****")
print("**** Entering make joints button")
self.joints_button_dic = {}
for joint in range(0, self.stat.joints):
for direction in ["+","-"]:
name = "{0}{1}".format(str(joint), direction)
btn = gtk.Button(name.upper())
btn.set_property("name", name)
btn.connect("pressed", self._on_btn_jog_pressed, name)
btn.connect("released", self._on_btn_jog_released, name)
btn.set_property("tooltip-text", _("Press to jog joint {0}".format(joint)))
btn.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("#FFFF00"))
btn.set_size_request(48,48)
self.joints_button_dic[name] = btn
# check if macros are in the INI file and add them to MDI Button List
def _make_macro_button(self):
print("**** GMOCCAPY INFO ****")
print("**** Entering make macro button")
macros = self.get_ini_info.get_macros()
# if no macros at all are found, we receive a NONE, so we have to check:
if not macros:
num_macros = 0
# no return here, otherwise we will not get filling labels
else:
num_macros = len(macros)
print("found {0} Macros".format(num_macros))
if num_macros > 16:
message = _("**** GMOCCAPY INFO ****\n")
message += _("**** found more than 16 macros, will use only the first 16 ****")
print(message)
num_macros = 16
btn = self._get_button_with_image("previous_button", None, gtk.STOCK_GO_BACK)
btn.hide()
btn.set_property("tooltip-text", _("Press to display previous macro button"))
btn.connect("clicked", self._on_btn_previous_macro_clicked)
self.widgets.hbtb_MDI.pack_start(btn)
for pos in range(0, num_macros):
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]
# shorten / break line of the name if it is to long
if len(lbl) > 11:
lbl = lbl[0:10] + "\n" + lbl[11:20]
btn = gtk.Button(lbl, None, False)
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.position = pos
btn.show()
self.widgets.hbtb_MDI.pack_start(btn, True, True, 0)
btn = self._get_button_with_image("next_button", None, gtk.STOCK_GO_FORWARD)
btn.set_property("tooltip-text", _("Press to display next macro button"))
btn.connect("clicked", self._on_btn_next_macro_clicked)
btn.hide()
self.widgets.hbtb_MDI.pack_start(btn)
file = "keyboard.png"
filepath = os.path.join(IMAGEDIR, file)
# if there is still place, we fill it with empty labels, to be sure the button will not be on different
# places if the amount of macros change.
if num_macros < 9:
for pos in range(num_macros, 9):
lbl = gtk.Label()
lbl.set_property("name","lbl_space_{0}".format(pos))
lbl.set_text("")
self.widgets.hbtb_MDI.pack_start(lbl, True, True, 0)
lbl.show()
name = "keyboard"
btn = self._get_button_with_image(name, filepath, None)
btn.set_property("tooltip-text", _("Press to display the virtual keyboard"))
btn.connect("clicked", self.on_btn_show_kbd_clicked)
btn.set_property("name", name)
self.widgets.hbtb_MDI.pack_start(btn)
self.macro_dic = {}
children = self.widgets.hbtb_MDI.get_children()
for child in children:
#print(child.name)
self.macro_dic[child.name] = child
if num_macros >= 9:
self.macro_dic["next_button"].show()
for pos in range(8, num_macros):
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
def _make_lathe(self):
print("**** GMOCCAPY INFO ****")
print("**** we have a lathe here")
# if we have a lathe, we will need an additional DRO to display
# diameter and radius simultaneous, we will call that one Combi_DRO_9, as that value
# should never be used due to the limit in axis from 0 to 8
dro = Combi_DRO()
dro.set_property("name", "Combi_DRO_9")
dro.set_property("abs_color", gtk.gdk.color_parse(self.abs_color))
dro.set_property("rel_color", gtk.gdk.color_parse(self.rel_color))
dro.set_property("dtg_color", gtk.gdk.color_parse(self.dtg_color))
dro.set_property("homed_color", gtk.gdk.color_parse(self.homed_color))
dro.set_property("unhomed_color", gtk.gdk.color_parse(self.unhomed_color))
dro.set_property("actual", self.dro_actual)
joint = self._get_joint_from_joint_axis_dic("x")
dro.set_joint_no(joint)
dro.set_axis("x")
dro.change_axisletter("D")
dro.set_property("diameter", True)
dro.show()
dro.connect("clicked", self._on_DRO_clicked)
dro.connect('axis_clicked', self._on_DRO_axis_clicked)
self.dro_dic[dro.name] = dro
self.dro_dic["Combi_DRO_0"].change_axisletter("R")
# For a lathe we don"t need the following button
self.widgets.rbt_view_p.hide()
self.widgets.rbt_view_x.hide()
self.widgets.rbt_view_z.hide()
self.widgets.lbl_hide_tto_x.hide()
self.widgets.lbl_blockheight.hide()
# but we have to show this one
self.widgets.rbt_view_y2.show()
if self.backtool_lathe:
view = "y2"
else:
view = "y"
self.prefs.putpref("view", view)
self.widgets["rbt_view_{0}".format(view)].set_active(True)
self.widgets.gremlin.set_property("view", view)
self._switch_to_g7(False)
# we need to arrange the jog button,
# a lathe should have at least X and Z axis
if not "x" in self.axis_list or not "z" in self.axis_list:
message = _("***** GMOCCAPY ERROR *****")
message += _("this is not a lathe, as a lathe must have at least\n")
message += _("an X and an Z axis\n")
message += _("Wrong lathe configuration, we will leave here")
self.dialogs.warning_dialog(self, _("Very critical situation"), message, sound = False)
sys.exit()
else:
if len(self.axis_list) == 2:
self.widgets.tbl_jog_btn_axes.resize(3,3)
elif len(self.axis_list) < 6:
self.widgets.tbl_jog_btn_axes.resize(3,4)
else:
self._arrange_jog_button_by_axis()
return
count = 0
for btn_name in self.jog_button_dic:
if btn_name == "x+":
col = 1
row = 2
if self.backtool_lathe:
row = 0
elif btn_name == "x-":
col = 1
row = 0
if self.backtool_lathe:
row = 2
elif btn_name == "z+":
col = 2
row = 1
elif btn_name == "z-":
col = 0
row = 1
else:
if count < 2:
col = 3
elif count < 4:
col = 2
else:
col = 0
if "+" in btn_name:
row = 0
else:
row = 2
count +=1
self.widgets.tbl_jog_btn_axes.attach(self.jog_button_dic[btn_name], col, col + 1, row, row + 1)
self.jog_button_dic[btn_name].show()
def _arrange_dro(self):
print("**** GMOCCAPY INFO ****")
print("**** arrange DRO")
print(len(self.dro_dic))
# if we have less than 4 axis, we can resize the table, as we have
# enough space to display each one in it's own line
if len(self.dro_dic) < 4:
self._place_in_table(len(self.dro_dic),1, self.dro_size)
# having 4 DRO we need to reduce the size, to fit the available space
elif len(self.dro_dic) == 4:
self._place_in_table(len(self.dro_dic),1, self.dro_size * 0.75)
# having 5 axis we will display 3 in an one line and two DRO share
# the last line, the size of the DRO must be reduced also
# this is a special case so we do not use _place_in_table
elif len(self.dro_dic) == 5:
self.widgets.tbl_DRO.resize(4,2)
dro_order = self._get_DRO_order()
for dro, dro_name in enumerate(dro_order):
# as a lathe might not have all Axis, we check if the key is in directory
if dro < 3:
size = self.dro_size * 0.75
self.widgets.tbl_DRO.attach(self.dro_dic[dro_name],
0, 2, int(dro), int(dro + 1), ypadding = 0)
else:
size = self.dro_size * 0.65
if dro == 3:
self.widgets.tbl_DRO.attach(self.dro_dic[dro_name],
0, 1, int(dro), int(dro + 1), ypadding = 0)
else:
self.widgets.tbl_DRO.attach(self.dro_dic[dro_name],
1, 2, int(dro-1), int(dro), ypadding = 0)
self.dro_dic[dro_name].set_property("font_size", size)
else:
print("**** GMOCCAPY build_GUI INFO ****")
print("**** more than 5 axis ")
# check if amount of axis is an even number, adapt the needed lines
if len(self.dro_dic) % 2 == 0:
rows = len(self.dro_dic) / 2
else:
rows = (len(self.dro_dic) + 1) / 2
self._place_in_table(rows, 2, self.dro_size * 0.65)
# set values to dro size adjustments
self.widgets.adj_dro_size.set_value(self.dro_size)
def _place_in_table(self, rows, cols, dro_size):
print("**** GMOCCAPY INFO ****")
print("**** Place in table")
self.widgets.tbl_DRO.resize(rows, cols)
col = 0
row = 0
dro_order = self._get_DRO_order()
for dro, dro_name in enumerate(dro_order):
# as a lathe might not have all Axis, we check if the key is in directory
if dro_name not in self.dro_dic.keys():
continue
self.dro_dic[dro_name].set_property("font_size", dro_size)
self.widgets.tbl_DRO.attach(self.dro_dic[dro_name],
col, col+1, row, row + 1, ypadding = 0)
if cols > 1:
# calculate if we have to place in the first or the second column
if (dro % 2 == 1):
col = 0
row +=1
else:
col += 1
else:
row += 1
def _get_DRO_order(self):
print("**** GMOCCAPY INFO ****")
print("**** get DRO order")
dro_order = []
# if Combi_DRO_9 exist we have a lathe with an additional DRO for diameter mode
if "Combi_DRO_9" in self.dro_dic.keys():
for dro_name in ["Combi_DRO_0", "Combi_DRO_9", "Combi_DRO_1", "Combi_DRO_2", "Combi_DRO_3",
"Combi_DRO_4", "Combi_DRO_5", "Combi_DRO_6", "Combi_DRO_7", "Combi_DRO_8"]:
if dro_name in self.dro_dic.keys():
dro_order.append(dro_name)
else:
dro_order = sorted(self.dro_dic.keys())
return dro_order
def _arrange_jog_button(self):
print("**** GMOCCAPY INFO ****")
print("**** arrange JOG button")
# if we have a lathe, we have done the arrangement in _make_lathe
# but if the lathe has more than 5 axis we will use standard
if self.lathe_mode:
return
if len(self.axis_list) > 5:
self._arrange_jog_button_by_axis()
return
if not "x" in self.axis_list or not "y" in self.axis_list or not "z" in self.axis_list:
message = _("***** GMOCCAPY INFO *****")
message += _("this is not a usual config\n")
message += _("we miss one of X , Y or Z axis\n")
message += _("We will use by axisletter ordered jog button")
print(message)
self._arrange_jog_button_by_axis()
return
if len(self.axis_list) < 3:
print("Less than 3 axis")
# we can resize the jog_btn_table
self.widgets.tbl_jog_btn_axes.resize(3, 3)
else:
print("less than 6 axis")
# we can resize the jog_btn_table
self.widgets.tbl_jog_btn_axes.resize(3, 4)
count = 0
for btn_name in self.jog_button_dic:
if btn_name == "x+":
col = 2
row = 1
elif btn_name == "x-":
col = 0
row = 1
elif btn_name == "y+":
col = 1
row = 0
elif btn_name =="y-":
col = 1
row = 2
elif btn_name == "z+":
col = 3
row = 0
elif btn_name == "z-":
col = 3
row = 2
# order of the data in the dict matters for extra buttons.
# This is why we use ordered dict for self.jog_button_dic
else:
if count < 2:
col = 2
else:
col = 0
if "+" in btn_name:
row = 0
else:
row = 2
count +=1
self.widgets.tbl_jog_btn_axes.attach(self.jog_button_dic[btn_name], col, col + 1, row, row + 1)
self.widgets.tbl_jog_btn_axes.show_all()
def _arrange_jog_button_by_axis(self):
print("**** GMOCCAPY INFO ****")
print("**** arrange JOG button by axis")
print sorted(self.jog_button_dic.keys())
# check if amount of axis is an even number, adapt the needed lines
cols = 4
if len(self.dro_dic) % 2 == 0:
rows = len(self.dro_dic) / 2
else:
rows = (len(self.dro_dic) + 1) / 2
self.widgets.tbl_jog_btn_axes.resize(rows, cols)
#print (cols,rows)
col = 0
row = 0
for pos, btn in enumerate("xyzabcuvw"):
btn_name = "{0}-".format(btn)
if btn_name not in self.jog_button_dic.keys():
continue
self.widgets.tbl_jog_btn_axes.attach(self.jog_button_dic[btn_name],
col, col+1, row, row + 1, ypadding = 0)
btn_name = "{0}+".format(btn)
self.widgets.tbl_jog_btn_axes.attach(self.jog_button_dic[btn_name],
col+1, col+2, row, row + 1, ypadding = 0)
row +=1
# calculate if we have to place in the first or the second column
if row >= rows:
col = 2
row = 0
self.widgets.tbl_jog_btn_axes.show_all()
def _arrange_joint_button(self):
print("**** GMOCCAPY INFO ****")
print("**** arrange JOINTS button")
print("Found {0} Joints Button".format(len(self.joints_button_dic)))
cols = 4
if self.stat.joints % 2 == 0:
rows = self.stat.joints / 2
else:
rows = (self.stat.joints + 1) / 2
self.widgets.tbl_jog_btn_joints.resize(rows, cols)
col = 0
row = 0
for joint in range(0, self.stat.joints):
#print(joint)
joint_name = "{0}-".format(joint)
self.widgets.tbl_jog_btn_joints.attach(self.joints_button_dic[joint_name],
col, col+1, row, row + 1, ypadding = 0)
joint_name = "{0}+".format(joint)
self.widgets.tbl_jog_btn_joints.attach(self.joints_button_dic[joint_name],
col+1, col+2, row, row + 1, ypadding = 0)
row +=1
# calculate if we have to place in the first or the second column
if row >= rows:
col = 2
row = 0
self.widgets.tbl_jog_btn_joints.show_all()
def _init_preferences(self):
# check if NO_FORCE_HOMING is used in ini
# disable reload tool on start up, if True
if self.no_force_homing:
self.widgets.chk_reload_tool.set_sensitive(False)
self.widgets.chk_reload_tool.set_active(False)
self.widgets.lbl_reload_tool.set_visible(True)
# set the slider limits
self.widgets.spc_lin_jog_vel.set_property("min", 0)
self.widgets.spc_lin_jog_vel.set_property("max", self.jog_rate_max)
self.widgets.spc_lin_jog_vel.set_value(self.rabbit_jog)
self.widgets.spc_spindle.set_property("min", self.spindle_override_min * 100)
self.widgets.spc_spindle.set_property("max", self.spindle_override_max * 100)
self.widgets.spc_spindle.set_value(100)
self.widgets.spc_rapid.set_property("min", 0)
self.widgets.spc_rapid.set_property("max", self.rapid_override_max * 100)
self.widgets.spc_rapid.set_value(100)
self.widgets.spc_feed.set_property("min", 0)
self.widgets.spc_feed.set_property("max", self.feed_override_max * 100)
self.widgets.spc_feed.set_value(100)
# the scales to apply to the count of the hardware mpg wheel, to avoid to much turning
self.widgets.adj_scale_jog_vel.set_value(self.scale_jog_vel)
self.widgets.adj_scale_spindle_override.set_value(self.scale_spindle_override)
self.widgets.adj_scale_feed_override.set_value(self.scale_feed_override)
self.widgets.adj_scale_rapid_override.set_value(self.scale_rapid_override)
# set and get all information for turtle jogging
# self.rabbit_jog will be used in future to store the last value
# so it can be recovered after jog_vel_mode switch
self.widgets.chk_turtle_jog.set_active(self.hide_turtle_jog_button)
self.widgets.adj_turtle_jog_factor.configure(self.turtle_jog_factor, 1,
100, 1, 0, 0)
if self.hide_turtle_jog_button:
self.widgets.tbtn_turtle_jog.hide()
self.turtle_jog_factor = 1
self.turtle_jog = self.rabbit_jog / self.turtle_jog_factor
# and according to machine units the digits to display
if self.stat.linear_units == _MM:
self.widgets.spc_lin_jog_vel.set_digits(0)
self.widgets.spc_lin_jog_vel.set_property("unit", _("mm/min"))
else:
self.widgets.spc_lin_jog_vel.set_digits(2)
self.widgets.spc_lin_jog_vel.set_property("unit", _("inch/min"))
# the size of the DRO ; self.dro_size is initialized in _get_pref_data
self.widgets.adj_dro_size.set_value(self.dro_size)
# hide the angular jog vel if no angular joint is used
if not "a" in self.axis_list and not "b" in self.axis_list and not "c" in self.axis_list:
self.widgets.spc_ang_jog_vel.hide()
else:
self.widgets.spc_ang_jog_vel.set_property("min", self.min_ang_vel)
self.widgets.spc_ang_jog_vel.set_property("max", self.max_ang_vel)
self.widgets.spc_ang_jog_vel.set_value(self.default_ang_vel)
# =============================================================
# Dynamic tabs handling Start
def _init_dynamic_tabs(self):
# dynamic tabs setup
self._dynamic_childs = {}
# register all tabs, so they will be closed together with the GUI
atexit.register(self._kill_dynamic_childs)
tab_names, tab_locations, tab_cmd = self.get_ini_info.get_embedded_tabs()
if not tab_names:
print (_("**** GMOCCAPY INFO ****"))
print (_("**** Invalid embedded tab configuration ****"))
print (_("**** No tabs will be added! ****"))
return
try:
for t, c, name in zip(tab_names, tab_cmd, tab_locations):
nb = self.widgets[name]
xid = self._dynamic_tab(nb, t)
if not xid: continue
cmd = c.replace('{XID}', str(xid))
child = subprocess.Popen(cmd.split())
self._dynamic_childs[xid] = child
nb.show_all()
except:
print(_("ERROR, trying to initialize the user tabs or panels, check for typos"))
self.set_up_user_tab_widgets(tab_locations)
# adds the embedded object to a notebook tab or box
def _dynamic_tab(self, widget, text):
s = gtk.Socket()
try:
widget.append_page(s, gtk.Label(" " + text + " "))
except:
try:
widget.pack_end(s, True, True, 0)
except:
return None
return s.get_id()
# Gotta kill the embedded processes when gmoccapy closes
def _kill_dynamic_childs(self):
for child in self._dynamic_childs.values():
child.terminate()
def set_up_user_tab_widgets(self, tab_locations):
print(tab_locations)
if tab_locations:
# make sure the user tabs button is disabled
# if no ntb_user_tabs in location is given
if "ntb_user_tabs" in tab_locations:
self.widgets.tbtn_user_tabs.set_sensitive( True )
else:
self.widgets.tbtn_user_tabs.set_sensitive( False )
if "ntb_preview" in tab_locations:
self.widgets.ntb_preview.set_property( "show-tabs", True )
# This is normaly only used for the plasma screen layout
if "box_coolant_and_spindle" in tab_locations:
widgetlist = ["box_spindle", "box_cooling"]
for widget in widgetlist:
self.widgets[widget].hide()
if "box_cooling" in tab_locations:
widgetlist = ["frm_cooling"]
for widget in widgetlist:
self.widgets[widget].hide()
if "box_spindle" in tab_locations:
widgetlist = ["frm_spindle"]
for widget in widgetlist:
self.widgets[widget].hide()
if "box_vel_info" in tab_locations:
widgetlist = ["frm_max_vel", "frm_feed_override"]
for widget in widgetlist:
self.widgets[widget].hide()
if "box_custom_1" in tab_locations:
self.widgets.box_custom_1.show()
if "box_custom_2" in tab_locations:
self.widgets.box_custom_2.show()
if "box_custom_3" in tab_locations:
self.widgets.box_custom_3.show()
if "box_custom_4" in tab_locations:
self.widgets.box_custom_4.show()
if "box_tool_and_code_info" in tab_locations:
widgetlist = ["frm_tool_info", "active_speed_label", "lbl_speed", "box_vel_info"]
for widget in widgetlist:
self.widgets[widget].hide()
self.widgets.btn_tool.set_sensitive( False )
# Dynamic tabs handling End
# =============================================================
# and we load the tooltable data
def _init_tooleditor(self):
# get the path to the tool table
tooltable = self.get_ini_info.get_toolfile()
if not tooltable:
message = _("**** GMOCCAPY ERROR ****\n")
message += _("**** Did not find a toolfile file in [EMCIO] TOOL_TABLE ****")
print(message)
self.dialogs.warning_dialog(self, _("Very critical situation"), message, sound = False)
sys.exit()
toolfile = os.path.join(CONFIGPATH, tooltable)
self.widgets.tooledit1.set_filename(toolfile)
# first we hide all the axis columns the unhide the ones we want
self.widgets.tooledit1.set_visible("abcxyzuvwijq", False)
for axis in self.axis_list:
self.widgets.tooledit1.set_visible("{0}".format(axis), True)
# if it's a lathe config we show lathe related columns
if self.lathe_mode:
self.widgets.tooledit1.set_visible("ijq", True)
if not self.get_ini_info.get_lathe_wear_offsets():
# hide the wear offset tabs
self.widgets.tooledit1.set_lathe_display(False)
self.widgets.tooledit1.hide_buttonbox(True)
def _init_themes(self):
# If there are themes then add them to combo box
model = self.widgets.theme_choice.get_model()
model.clear()
model.append((_("Follow System Theme"),))
themes = []
if os.path.exists(USERTHEMEDIR):
names = os.listdir(USERTHEMEDIR)
names.sort()
for dirs in names:
try:
sbdirs = os.listdir(os.path.join(USERTHEMEDIR, dirs))
if 'gtk-2.0' in sbdirs:
themes.append(dirs)
except:
pass
if os.path.exists(THEMEDIR):
names = os.listdir(THEMEDIR)
names.sort()
for dirs in names:
try:
sbdirs = os.listdir(os.path.join(THEMEDIR, dirs))
if 'gtk-2.0' in sbdirs:
themes.append(dirs)
except:
pass
temp = 0
theme_name = self.prefs.getpref("gtk_theme", "Follow System Theme", str)
for index, theme in enumerate(themes):
model.append((theme,))
if theme == theme_name:
temp = index + 1
self.widgets.theme_choice.set_active(temp)
settings = gtk.settings_get_default()
if not theme_name == "Follow System Theme":
settings.set_string_property("gtk-theme-name", theme_name, "")
def _init_audio(self):
# try to add ability for audio feedback to user.
if _AUDIO_AVAILABLE:
print (_("**** GMOCCAPY INFO ****"))
print (_("**** audio available! ****"))
# the sounds to play if an error or message rises
self.alert_sound = "/usr/share/sounds/freedesktop/stereo/dialog-warning.oga"
self.error_sound = "/usr/share/sounds/freedesktop/stereo/dialog-error.oga"
self.audio = player.Player()
self.alert_sound = self.prefs.getpref('audio_alert', self.alert_sound, str)
self.error_sound = self.prefs.getpref('audio_error', self.error_sound, str)
self.widgets.audio_alert_chooser.set_filename(self.alert_sound)
self.widgets.audio_error_chooser.set_filename(self.error_sound)
else:
print (_("**** GMOCCAPY INFO ****"))
print (_("**** no audio available! ****"))
print(_("**** PYGST libray not installed? ****"))
print(_("**** is python-gstX.XX installed? ****"))
self.widgets.audio_alert_chooser.set_sensitive(False)
self.widgets.audio_error_chooser.set_sensitive(False)
# init the preview
def _init_gremlin( self ):
print (_("**** GMOCCAPY INFO ****"))
print (_("**** Entering init gremlin ****"))
grid_size = self.prefs.getpref( 'grid_size', 1.0, float )
self.widgets.grid_size.set_value( grid_size )
self.widgets.gremlin.grid_size = grid_size
view = view = self.prefs.getpref("view", "p", str )
self.widgets.gremlin.set_property("view", view )
self.widgets.gremlin.set_property("metric_units", int( self.stat.linear_units ) )
self.widgets.gremlin.set_property("mouse_btn_mode", self.prefs.getpref( "mouse_btn_mode", 4, int ) )
self.widgets.gremlin.set_property("use_commanded", not self.dro_actual)
self.widgets.gremlin.set_property("enable_dro", self.enable_gremlin_dro)
self.widgets.eb_program_label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0))
self.widgets.eb_blockheight_label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0))
def _init_kinematics_type (self):
print("Kinematics type changed")
if self.stat.kinematics_type != linuxcnc.KINEMATICS_IDENTITY:
self.widgets.gremlin.set_property("enable_dro", True )
self.widgets.gremlin.use_joints_mode = True
self.widgets.tbtn_switch_mode.show()
self.widgets.tbtn_switch_mode.set_label(_(" Joint\nmode"))
self.widgets.tbtn_switch_mode.set_sensitive(False)
self.widgets.tbtn_switch_mode.set_active(True)
self.widgets.lbl_replace_mode_btn.hide()
self.widgets.ntb_jog_JA.set_page(1)
else:
self.widgets.gremlin.set_property("enable_dro", self.enable_gremlin_dro )
self.widgets.gremlin.use_joints_mode = False
self.widgets.tbtn_switch_mode.hide()
self.widgets.lbl_replace_mode_btn.show()
self.widgets.ntb_jog_JA.set_page(0)
# init the function to hide the cursor
def _init_hide_cursor(self):
hide_cursor = self.prefs.getpref('hide_cursor', False, bool)
self.widgets.chk_hide_cursor.set_active(hide_cursor)
# if hide cursor requested
# we set the graphics to use touchscreen controls
if hide_cursor:
self.widgets.window1.window.set_cursor(INVISABLE)
self.widgets.gremlin.set_property("use_default_controls", False)
else:
self.widgets.window1.window.set_cursor(None)
self.widgets.gremlin.set_property("use_default_controls", True)
# =============================================================
# Onboard keybord handling Start
# shows "Onboard" virtual keyboard if available
# else error message
def _init_keyboard(self, args="", x="", y=""):
self.onboard = False
# now we check if onboard or matchbox-keyboard is installed
try:
if os.path.isfile("/usr/bin/onboard"):
self.onboard_kb = subprocess.Popen(["onboard", "--xid", args, x, y],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
close_fds=True)
print (_("**** GMOCCAPY INFO ****"))
print (_("**** virtual keyboard program found : <onboard>"))
elif os.path.isfile("/usr/bin/matchbox-keyboard"):
self.onboard_kb = subprocess.Popen(["matchbox-keyboard", "--xid"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
close_fds=True)
print (_("**** GMOCCAPY INFO ****"))
print (_("**** virtual keyboard program found : <matchbox-keyboard>"))
else:
print (_("**** GMOCCAPY INFO ****"))
print (_("**** No virtual keyboard installed, we checked for <onboard> and <matchbox-keyboard>."))
self._no_virt_keyboard()
return
sid = self.onboard_kb.stdout.readline()
self.socket = gtk.Socket()
self.widgets.key_box.add(self.socket)
self.socket.add_id(long(sid))
self.socket.show_all()
self.widgets.key_box.show_all()
self.onboard = True
except Exception, e:
print (_("**** GMOCCAPY ERROR ****"))
print (_("**** Error with launching virtual keyboard,"))
print (_("**** is onboard or matchbox-keyboard installed? ****"))
traceback.print_exc()
self._no_virt_keyboard()
# get when the keyboard should be shown
# and set the corresponding button active
# only if onbaoard keyboard is ok.
if self.onboard:
self.widgets.chk_use_kb_on_offset.set_active(self.prefs.getpref("show_keyboard_on_offset",
False, bool))
self.widgets.chk_use_kb_on_tooledit.set_active(self.prefs.getpref("show_keyboard_on_tooledit",
False, bool))
self.widgets.chk_use_kb_on_edit.set_active(self.prefs.getpref("show_keyboard_on_edit",
True, bool))
self.widgets.chk_use_kb_on_mdi.set_active(self.prefs.getpref("show_keyboard_on_mdi",
True, bool))
self.widgets.chk_use_kb_on_file_selection.set_active(self.prefs.getpref("show_keyboard_on_file_selection",
False, bool))
else:
self._no_virt_keyboard()