1
1
# !/usr/bin/env python
2
2
# -*- coding: UTF-8 -*-
3
-
3
+ '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''
4
+ ' '
5
+ ' Copyright 2018 Gauthier Brière (gauthier.briere "at" gmail.com) '
6
+ ' '
7
+ ' This file is part of cn5X '
8
+ ' '
9
+ ' cn5X is free software: you can redistribute it and/or modify it '
10
+ ' under the terms of the GNU General Public License as published by '
11
+ ' the Free Software Foundation, either version 3 of the License, or '
12
+ ' (at your option) any later version. '
13
+ ' '
14
+ ' cn5X is distributed in the hope that it will be useful, but '
15
+ ' WITHOUT ANY WARRANTY; without even the implied warranty of '
16
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the '
17
+ ' GNU General Public License for more details. '
18
+ ' '
19
+ ' You should have received a copy of the GNU General Public License '
20
+ ' along with this program. If not, see <http://www.gnu.org/licenses/>. '
21
+ ' '
22
+ ''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' '''''' ''''''
4
23
import sys , os , datetime
5
24
from PyQt5 import QtCore , QtGui , QtWidgets
6
- from PyQt5 .QtCore import QThread , pyqtSignal , pyqtSlot
7
- from PyQt5 .QtGui import QKeySequence
25
+ from PyQt5 .QtCore import QThread , pyqtSignal , pyqtSlot , QModelIndex , QItemSelectionModel
26
+ from PyQt5 .QtGui import QKeySequence , QStandardItemModel , QStandardItem
8
27
from PyQt5 .QtSerialPort import QSerialPortInfo
9
28
import mainWindow
10
29
from msgbox import *
@@ -29,6 +48,8 @@ def __init__(self, parent=None):
29
48
self .logCn5X .document ().setMaximumBlockCount (2000 ) # Limite la taille des logs à 2000 lignes
30
49
self .logDebug .document ().setMaximumBlockCount (2000 ) # Limite la taille des logs à 2000 lignes
31
50
51
+ self .gcodeFileContent = QStandardItemModel (self .ui .listGCodeFile )
52
+
32
53
self .timerDblClic = QtCore .QTimer ()
33
54
self .decode = grblDecode (self .ui )
34
55
@@ -69,7 +90,7 @@ def __init__(self, parent=None):
69
90
self .setEnableDisableGroupes ()
70
91
71
92
"""---------- Connections des évennements traités ----------"""
72
- self .ui .btnUrgence .pressed .connect (self .on_arretUrgence ) # Evenements du bouton d'arrêt d'urgence
93
+ self .ui .btnUrgence .pressed .connect (self .on_arretUrgence ) # Evenements du bouton d'arrêt d'urgence
73
94
self .ui .cmbPort .currentIndexChanged .connect (self .on_cmbPort_changed ) # un clic sur un élément de la liste appellera la méthode 'on_cmbPort_changed'
74
95
self .ui .mnuAppOuvrir .triggered .connect (self .on_mnuAppOuvrir ) # Connexions des routines du menu application
75
96
self .ui .mnuAppQuitter .triggered .connect (self .on_mnuAppQuitter )
@@ -84,9 +105,18 @@ def __init__(self, parent=None):
84
105
self .ui .btnStartTimer .clicked .connect (self .startTimer )
85
106
self .ui .btnStopTimer .clicked .connect (self .stopTimer )
86
107
self .ui .btnClearDebug .clicked .connect (self .clearDebug )
108
+ self .ui .btnSpinM3 .clicked .connect (self .on_btnSpinM3 )
109
+ self .ui .btnSpinM4 .clicked .connect (self .on_btnSpinM4 )
110
+ self .ui .btnSpinM5 .clicked .connect (self .on_btnSpinM5 )
87
111
self .ui .btnFloodM7 .clicked .connect (self .on_btnFloodM7 )
88
112
self .ui .btnFloodM8 .clicked .connect (self .on_btnFloodM8 )
89
113
self .ui .btnFloodM9 .clicked .connect (self .on_btnFloodM9 )
114
+ self .ui .lblG54 .clicked .connect (self .on_lblG5xClick )
115
+ self .ui .lblG55 .clicked .connect (self .on_lblG5xClick )
116
+ self .ui .lblG56 .clicked .connect (self .on_lblG5xClick )
117
+ self .ui .lblG57 .clicked .connect (self .on_lblG5xClick )
118
+ self .ui .lblG58 .clicked .connect (self .on_lblG5xClick )
119
+ self .ui .lblG59 .clicked .connect (self .on_lblG5xClick )
90
120
91
121
def populatePortList (self ):
92
122
''' Rempli la liste des ports série '''
@@ -143,6 +173,7 @@ def setEnableDisableGroupes(self):
143
173
self .ui .grpJog .setEnabled (False )
144
174
self .ui .frmGcodeInput .setEnabled (False )
145
175
self .ui .frmBoutons .setEnabled (False )
176
+ self .ui .frmCoordOffsets .setEnabled (False )
146
177
elif self .__arretUrgence :
147
178
# Connecté mais sous arrêt d'urgence : Tout est désactivé sauf l'arrêt d'urgence
148
179
self .ui .btnUrgence .setIcon (QtGui .QIcon ('images/btnUrgenceOff.svg' ))
@@ -152,6 +183,7 @@ def setEnableDisableGroupes(self):
152
183
self .ui .grpJog .setEnabled (False )
153
184
self .ui .frmGcodeInput .setEnabled (False )
154
185
self .ui .frmBoutons .setEnabled (False )
186
+ self .ui .frmCoordOffsets .setEnabled (False )
155
187
else :
156
188
# Tout est en ordre, on active tout
157
189
self .ui .btnUrgence .setIcon (QtGui .QIcon ('images/btnUrgence.svg' ))
@@ -161,10 +193,47 @@ def setEnableDisableGroupes(self):
161
193
self .ui .grpJog .setEnabled (True )
162
194
self .ui .frmGcodeInput .setEnabled (True )
163
195
self .ui .frmBoutons .setEnabled (True )
196
+ self .ui .frmCoordOffsets .setEnabled (True )
164
197
165
198
@pyqtSlot ()
166
199
def on_mnuAppOuvrir (self ):
167
- pass
200
+ # Affiche la boite de dialogue
201
+ opt = QtWidgets .QFileDialog .Options ()
202
+ opt |= QtWidgets .QFileDialog .DontUseNativeDialog
203
+ fileName = QtWidgets .QFileDialog .getOpenFileName (self , "Ouvrir un fichier GCode" , "" , "Fichier GCode (*.gcode *.ngc *.nc *.gc *.cnc)" , options = opt )
204
+ if fileName [0 ] != "" :
205
+ # Lecture du fichier
206
+ self .logCn5X .append ("Lecture du fichier : " + fileName [0 ])
207
+ try :
208
+ f = open (fileName [0 ],'r' )
209
+ lignes = f .readlines ()
210
+ f .close ()
211
+ # Envoi du contenu dans la liste
212
+ self .gcodeFileContent .clear ()
213
+ for l in lignes :
214
+ #print("["+l.strip()+"]")
215
+ item = QStandardItem (l .strip ())
216
+ #item.setCheckable(True)
217
+ self .gcodeFileContent .appendRow (item )
218
+ self .ui .listGCodeFile .setModel (self .gcodeFileContent )
219
+ # Sélectionne la premiere ligne du fichier dans la liste
220
+ self .selectGCodeFileLine (0 )
221
+ # Sélectionne l'onglet du fichier
222
+ self .ui .grpConsole .setCurrentIndex (1 )
223
+ except Exception as e :
224
+ self .logCn5X .append ("Erreur lecture du fichier : " + fileName [0 ])
225
+ self .logCn5X .append (str (e ))
226
+ # Sélectionne l'onglet de la console pour que le message s'affiche
227
+ self .ui .grpConsole .setCurrentIndex (2 )
228
+
229
+ def selectGCodeFileLine (self , num : int ):
230
+ # Selectionne un élément de la liste du fichier GCode
231
+ idx = self .gcodeFileContent .index (num , 0 , QModelIndex ())
232
+ self .ui .listGCodeFile .selectionModel ().setCurrentIndex (idx , QItemSelectionModel .SelectCurrent )
233
+
234
+ def getGCodeSelectedLine (self ):
235
+ indexes = self .ui .listGCodeFile .selectionModel ().selectedIndexes ()
236
+ return self .gcodeFileContent .data (indexes [0 ])
168
237
169
238
@pyqtSlot ()
170
239
def on_mnuAppQuitter (self ):
@@ -246,6 +315,22 @@ def action_btnConnect(self):
246
315
def on_cmbPort_changed (self ):
247
316
self .setEnableDisableConnectControls ()
248
317
318
+ def on_btnSpinM3 (self ):
319
+ #self.logGrbl.append("M3")
320
+ self .__grblCom .sendLine ("M3" , True )
321
+ self .ui .btnSpinM4 .setEnabled (False ) # Interdit un changement de sens de rotation direct
322
+
323
+ def on_btnSpinM4 (self ):
324
+ #self.logGrbl.append("M4")
325
+ self .__grblCom .sendLine ("M4" , True )
326
+ self .ui .btnSpinM3 .setEnabled (False ) # Interdit un changement de sens de rotation direct
327
+
328
+ def on_btnSpinM5 (self ):
329
+ #self.logGrbl.append("M5")
330
+ self .__grblCom .sendLine ("M5" , True )
331
+ self .ui .btnSpinM3 .setEnabled (True )
332
+ self .ui .btnSpinM4 .setEnabled (True )
333
+
249
334
def on_btnFloodM7 (self ):
250
335
if self .decode .get_etatArrosage () != "M7" and self .decode .get_etatArrosage () != "M78" :
251
336
# Envoi "Real Time Command" plutôt que self.__grblCom.enQueue("M7")
@@ -264,6 +349,11 @@ def on_btnFloodM9(self):
264
349
# Envoi "Real Time Command" plutôt que self.__grblCom.enQueue("M9")
265
350
self .__grblCom .sendData (chr (0xA0 ))
266
351
352
+ @pyqtSlot (str , QtGui .QMouseEvent )
353
+ def on_lblG5xClick (self , lblText , e ):
354
+ #self.logGrbl.append(lblText)
355
+ self .__grblCom .sendLine (lblText , True )
356
+
267
357
def sendCmd (self ):
268
358
if self .ui .txtGCode .text () != "" :
269
359
self .logGrbl .append (self .ui .txtGCode .text ().upper ())
0 commit comments