Skip to content

Commit

Permalink
Still errors on exit. Still needs settings dialogue.
Browse files Browse the repository at this point in the history
  • Loading branch information
timkrins committed Sep 23, 2011
1 parent fb6aac3 commit 0fd744e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 58 deletions.
41 changes: 28 additions & 13 deletions mainwindow.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>760</width>
<height>305</height>
<height>380</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -31,6 +31,10 @@
<property name="windowTitle">
<string>qtSerialFeeder</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>../Desktop/git/serialfeeder/grblico.png</normaloff>../Desktop/git/serialfeeder/grblico.png</iconset>
</property>
<property name="windowOpacity">
<double>0.950000000000000</double>
</property>
Expand All @@ -41,7 +45,7 @@
<x>10</x>
<y>10</y>
<width>481</width>
<height>251</height>
<height>321</height>
</rect>
</property>
<property name="orientation">
Expand Down Expand Up @@ -152,7 +156,7 @@
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Terminal_Hex'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Testing&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;termWindow&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
Expand Down Expand Up @@ -257,16 +261,21 @@ p, li { white-space: pre-wrap; }
<widget class="QWidget" name="layoutWidget">
<layout class="QHBoxLayout" name="bottomHoriz">
<item>
<widget class="QLabel" name="appTitle">
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>220</width>
<height>100</height>
</size>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:22pt; vertical-align:super;&quot;&gt;qt&lt;/span&gt;&lt;span style=&quot; font-size:22pt;&quot;&gt;SerialFeeder&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string/>
</property>
<property name="pixmap">
<pixmap>../Desktop/git/serialfeeder/grblfeeder.png</pixmap>
</property>
<property name="scaledContents">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
Expand Down Expand Up @@ -297,6 +306,12 @@ p, li { white-space: pre-wrap; }
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>50</height>
</size>
</property>
<property name="text">
<string>Exit</string>
</property>
Expand All @@ -311,7 +326,7 @@ p, li { white-space: pre-wrap; }
<x>500</x>
<y>10</y>
<width>251</width>
<height>211</height>
<height>281</height>
</rect>
</property>
<property name="cursor" stdset="0">
Expand All @@ -334,13 +349,13 @@ p, li { white-space: pre-wrap; }
<property name="geometry">
<rect>
<x>500</x>
<y>230</y>
<y>300</y>
<width>251</width>
<height>31</height>
</rect>
</property>
<property name="value">
<number>24</number>
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
Expand Down
37 changes: 18 additions & 19 deletions outp.py
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created: Fri Sep 23 16:30:27 2011
# Created: Fri Sep 23 18:31:21 2011
# by: pyside-uic 0.2.13 running on PySide 1.0.6
#
# WARNING! All changes made in this file will be lost!
Expand All @@ -12,7 +12,7 @@
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(760, 305)
MainWindow.resize(730, 350)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand All @@ -21,11 +21,14 @@ def setupUi(self, MainWindow):
MainWindow.setMinimumSize(QtCore.QSize(300, 300))
MainWindow.setMouseTracking(True)
MainWindow.setAcceptDrops(True)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("grblico.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
MainWindow.setWindowOpacity(0.95)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
self.splitter = QtGui.QSplitter(self.centralWidget)
self.splitter.setGeometry(QtCore.QRect(10, 10, 481, 251))
self.splitter.setGeometry(QtCore.QRect(10, 10, 481, 321))
self.splitter.setOrientation(QtCore.Qt.Vertical)
self.splitter.setObjectName("splitter")
self.layoutWidget = QtGui.QWidget(self.splitter)
Expand Down Expand Up @@ -116,10 +119,13 @@ def setupUi(self, MainWindow):
self.bottomHoriz = QtGui.QHBoxLayout(self.layoutWidget1)
self.bottomHoriz.setContentsMargins(0, 0, 0, 0)
self.bottomHoriz.setObjectName("bottomHoriz")
self.appTitle = QtGui.QLabel(self.layoutWidget1)
self.appTitle.setScaledContents(False)
self.appTitle.setObjectName("appTitle")
self.bottomHoriz.addWidget(self.appTitle)
self.label = QtGui.QLabel(self.layoutWidget1)
self.label.setMaximumSize(QtCore.QSize(220, 100))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("grblfeeder.png"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.bottomHoriz.addWidget(self.label)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.bottomHoriz.addItem(spacerItem)
self.exitButton = QtGui.QPushButton(self.layoutWidget1)
Expand All @@ -129,19 +135,20 @@ def setupUi(self, MainWindow):
sizePolicy.setHeightForWidth(self.exitButton.sizePolicy().hasHeightForWidth())
self.exitButton.setSizePolicy(sizePolicy)
self.exitButton.setMinimumSize(QtCore.QSize(50, 0))
self.exitButton.setMaximumSize(QtCore.QSize(100, 50))
self.exitButton.setObjectName("exitButton")
self.bottomHoriz.addWidget(self.exitButton)
self.textEdit = QtGui.QTextEdit(self.centralWidget)
self.textEdit.setGeometry(QtCore.QRect(500, 10, 251, 211))
self.textEdit.setGeometry(QtCore.QRect(500, 10, 251, 281))
self.textEdit.setProperty("cursor", QtCore.Qt.ArrowCursor)
self.textEdit.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.textEdit.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.textEdit.setLineWrapMode(QtGui.QTextEdit.NoWrap)
self.textEdit.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
self.textEdit.setObjectName("textEdit")
self.currentProgress = QtGui.QProgressBar(self.centralWidget)
self.currentProgress.setGeometry(QtCore.QRect(500, 230, 251, 31))
self.currentProgress.setProperty("value", 24)
self.currentProgress.setGeometry(QtCore.QRect(500, 300, 251, 31))
self.currentProgress.setProperty("value", 0)
self.currentProgress.setAlignment(QtCore.Qt.AlignCenter)
self.currentProgress.setOrientation(QtCore.Qt.Horizontal)
self.currentProgress.setObjectName("currentProgress")
Expand All @@ -154,9 +161,6 @@ def setupUi(self, MainWindow):
self.menuAbout = QtGui.QMenu(self.menuBar)
self.menuAbout.setObjectName("menuAbout")
MainWindow.setMenuBar(self.menuBar)
self.statusBar = QtGui.QStatusBar(MainWindow)
self.statusBar.setObjectName("statusBar")
MainWindow.setStatusBar(self.statusBar)
self.actionLoad_GCode = QtGui.QAction(MainWindow)
self.actionLoad_GCode.setObjectName("actionLoad_GCode")
self.actionExit = QtGui.QAction(MainWindow)
Expand All @@ -180,19 +184,14 @@ def retranslateUi(self, MainWindow):
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Terminal_Hex\'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Testing</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">termWindow</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.loadButton.setText(QtGui.QApplication.translate("MainWindow", "Load File", None, QtGui.QApplication.UnicodeUTF8))
self.sendOne.setText(QtGui.QApplication.translate("MainWindow", "Send One Line", None, QtGui.QApplication.UnicodeUTF8))
self.sendCont.setText(QtGui.QApplication.translate("MainWindow", "Send Continous", None, QtGui.QApplication.UnicodeUTF8))
self.sendStop.setText(QtGui.QApplication.translate("MainWindow", "Stop Sending", None, QtGui.QApplication.UnicodeUTF8))
self.clearButton.setText(QtGui.QApplication.translate("MainWindow", "Clear Queue", None, QtGui.QApplication.UnicodeUTF8))
self.clearTerm.setText(QtGui.QApplication.translate("MainWindow", "Clear Terminal", None, QtGui.QApplication.UnicodeUTF8))
self.termLine.setText(QtGui.QApplication.translate("MainWindow", "Enter Command", None, QtGui.QApplication.UnicodeUTF8))
self.appTitle.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:22pt; vertical-align:super;\">qt</span><span style=\" font-size:22pt;\">SerialFeeder</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.exitButton.setText(QtGui.QApplication.translate("MainWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8))
self.currentProgress.setFormat(QtGui.QApplication.translate("MainWindow", "Queue Progress: %p%", None, QtGui.QApplication.UnicodeUTF8))
self.menuQt.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
Expand Down
75 changes: 49 additions & 26 deletions ui.py
Expand Up @@ -2,7 +2,6 @@
from PySide import QtCore, QtGui

from outp import Ui_MainWindow
from gcodeformat import GForm

class Worker(QtCore.QThread):
def __init__(self, parent = None):
Expand All @@ -15,6 +14,10 @@ def run(self):
if(oksig[0] == True):
oksig[0] = False
self.emit(QtCore.SIGNAL("doney()"))

def __del__(self, parent=None):
self.exiting = True
self.wait()

class SerialProcessor(QtCore.QThread):
def __init__(self, parent = None):
Expand Down Expand Up @@ -47,18 +50,29 @@ def run(self):
while not self.exiting:
time.sleep(0.01)
a += 1
if(True):
if(not self.exiting):
#print("processing chunk serial "+repr(a))
self.processchunk(currentline)
chunked = ser.readline()
if(chunked):
currentline.extend(list(chunked.decode('utf-8')))

try:
chunked = ser.readline()
if(chunked):
currentline.extend(list(chunked.decode('utf-8')))
except:
print('this is a strange error, possibly caused by the serial being deleted before the thread')

def __del__(self, parent=None):
self.exiting = True
self.wait()

class SetUp(Ui_MainWindow):

def __init__(self, parent=None):
Ui_MainWindow.__init__(self)


def centerOnScreen (self, parent=None):
res = QtGui.QDesktopWidget().screenGeometry()
parent.move((res.width() / 2) - (parent.frameSize().width() / 2), (res.height() / 2) - (parent.frameSize().height() / 2))

def setupDefaults(self, parent=None):
self.termLine.setCursorPosition(2)
self.currentProgress.setValue(0)
Expand All @@ -67,7 +81,13 @@ def setupDefaults(self, parent=None):
self.clearButton.setDisabled(True)
self.sendOne.setDisabled(True)
self.sendCont.setDisabled(True)
parent.resize(500, 305)
self.origwid = parent.size().width()
self.orighit = parent.size().height()
self.label.setPixmap(QtGui.QPixmap("grblfeeder.png"))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("grblico.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)

parent.resize(500, self.orighit)
self.termWindow.setHtml("")
self.serialThread = SerialProcessor()
self.serialThread.start()
Expand All @@ -83,21 +103,24 @@ def hitEnter(self, parent=None):
self.termLine.clear()

def openFile(self, parent=None):
fileName = QtGui.QFileDialog.getOpenFileName(None, u"Select G-Code to send to CNC",u"",u"GCode Files (*.nc *.gc);;All Files (*.*)")
fLoad = open(fileName[0],'r')
del(contents[:])
del(formattedcontents[:])
self.clearButton.setDisabled(False)
self.sendOne.setDisabled(False)
self.sendCont.setDisabled(False)
outerdisplay.resize(760, 305)
for line in fLoad:
contents.append(line)
lined = line+"<br>"
formattedcontents.append(lined)
fLoad.close()
self.origlength = len(contents)
self.regenContentWindow()
try:
fileName = QtGui.QFileDialog.getOpenFileName(None, u"Select G-Code to send to CNC",u"",u"GCode Files (*.nc *.gc);;All Files (*.*)")
fLoad = open(fileName[0],'r')
del(contents[:])
del(formattedcontents[:])
self.clearButton.setDisabled(False)
self.sendOne.setDisabled(False)
self.sendCont.setDisabled(False)
outerdisplay.resize(760, self.orighit)
for line in fLoad:
contents.append(line)
lined = line+"<br>"
formattedcontents.append(lined)
fLoad.close()
self.origlength = len(contents)
self.regenContentWindow()
except:
print('file not opened correctly')

def click_sendOne(self, parent=None):
currentliner = contents.pop(0)
Expand Down Expand Up @@ -207,14 +230,14 @@ def setupSlots(self, parent=None):
oksig = [1]
origlength = 0
currentline = [0]
Formatter = GForm()
ser = serial.Serial('COM10',9600,8,'N',1,0.01)
app = QtGui.QApplication(sys.argv)
outerdisplay = QtGui.QMainWindow()
window = SetUp(app)
window.setupUi(outerdisplay)
window.setupDefaults(outerdisplay)
window.setupSlots(outerdisplay)

window.centerOnScreen(outerdisplay)
outerdisplay.show()
sys.exit(app.exec_())
app.exec_()
#sys.exit()

0 comments on commit 0fd744e

Please sign in to comment.