Skip to content

Commit

Permalink
Open file
Browse files Browse the repository at this point in the history
  • Loading branch information
vyacheslav-shubin committed Feb 25, 2022
1 parent 6fc9e64 commit a48283c
Show file tree
Hide file tree
Showing 10 changed files with 7,257 additions and 65 deletions.
2 changes: 1 addition & 1 deletion plugin/prusha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shui.utils import StartMode
appStartMode=StartMode.UNKNOWN

if os.getenv('START_MODE')=='TEST':
if os.getenv('START_MODE')=='STANDALONE':
appStartMode=StartMode.STANDALONE
else:
appStartMode=StartMode.PRUSA
Expand Down
17 changes: 13 additions & 4 deletions plugin/shui/MainUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ def __init__(self, appStartMode, **kwargs):
elif appStartMode==Core.StartMode.STANDALONE:
if len(argv)>1:
self.inputFileName=sys.argv[1]
else:
if os.getenv('START_MODE')=='TEST':
self.inputFileName="/home/shubin/electronic/firmware/mks-robin/my/shui-src/bh.gcode"
pass
elif appStartMode==Core.StartMode.CURA:
if "output_file_name" in kwargs:
self.outputFileName = kwargs["output_file_name"]

if self.inputFileName is not None and self.outputFileName is None:
if self.inputFileName is None:
self.inputFileName = os.path.join(os.path.dirname(os.path.abspath(__file__)),"..", "shui_prusa.gcode")
if self.outputFileName is None:
self.outputFileName = os.path.basename(self.inputFileName)
self.wifiUart = ConnectionThread(self)
config_file="config_local.json" if os.getenv('USER')=='shubin' else "config.json"
Expand Down Expand Up @@ -82,6 +81,16 @@ def __init__(self, appStartMode, **kwargs):

pass

def selectFile(self):
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(None, "Open file", None, "All Files (*);;GCODE Files (*.gco)", options=options)
if fileName:
self.inputFileName=fileName
self.outputFileName = os.path.basename(self.inputFileName)
return True
return False


class MainWidget(QtWidgets.QDialog):
def __init__(self, app):
Expand Down
8 changes: 6 additions & 2 deletions plugin/shui/langs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
"inherited":["en"],
"lang": {
"close": "Закрыть",
"send": "Отправить",
"connect": "Подключить",
"disconnect": "Отключить",
"select": "Выбрать",

"file": "Файл",
"terminal": "Терминал",
"printer": "Принтер",

"start-printing": "Запустить печать",
"output-name": "Имя файла",
"output-name": "Файл",

"save-to-file": "Сохранить файл",
"send-to-printer": "Отправить на печать",
Expand All @@ -28,6 +30,8 @@
"lang": {
"title": "SHUI Wifi Plugin",
"close": "Close",
"send": "Send",
"select": "Select",
"connect": "Connect",
"disconnect": "Disconnect",

Expand All @@ -36,7 +40,7 @@
"printer": "Printer",

"start-printing": "Start printing",
"output-name": "File name",
"output-name": "File",

"save-to-file": "Save to file",
"send-to-printer": "Send to SHUI Wifi",
Expand Down
2 changes: 1 addition & 1 deletion plugin/shui/utils/ConsoleTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, app):
self.btSenb = QtWidgets.QPushButton()
self.btSenb.setMaximumSize(QtCore.QSize(100, 16777215))
self.btSenb.setMinimumWidth(100)
self.btSenb.setText("Send")
self.btSenb.setText(self.app.lang["send"])
self.btSenb.setDisabled(True)


Expand Down
102 changes: 46 additions & 56 deletions plugin/shui/utils/FileTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,62 @@ def __init__(self, app):
self.app.onProgress.connect(self.onProgress)
self.app.onMessage.connect(self.onMessage)

mainLayout=QtWidgets.QHBoxLayout()

self.bigPic = QtWidgets.QLabel()
self.bigPic.setFixedWidth(200)
self.bigPic.setFixedHeight(200)

mainLayout.addWidget(self.bigPic, alignment=QtCore.Qt.AlignTop)

rightArea = QtWidgets.QVBoxLayout()
mainLayout.addLayout(rightArea)

actions_layout = QtWidgets.QVBoxLayout()
cb = QtWidgets.QCheckBox(self.app.lang["start-printing"])
cb.setChecked(True)
self.cbStartPrinting=cb
actions_layout.addWidget(cb)
self.cbStartPrinting = QtWidgets.QCheckBox(self.app.lang["start-printing"])
self.cbStartPrinting.setChecked(True)

file_name_layout = QtWidgets.QHBoxLayout()
file_name_layout.addWidget(QtWidgets.QLabel(self.app.lang["output-name"]), alignment=QtCore.Qt.AlignLeft)
self.leFileName = QtWidgets.QLineEdit()
if self.app.outputFileName is not None:
self.leFileName.setText(self.app.outputFileName)
self.leFileName.setMaxLength(32)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
self.leFileName.setSizePolicy(sizePolicy)
file_name_layout.addWidget(self.leFileName, alignment=QtCore.Qt.AlignLeft)

progress_layout = QtWidgets.QVBoxLayout()
progress=QtWidgets.QProgressBar()
progress_layout.addWidget(progress)
progress.setMaximum(100)
progress.setValue(0)
self.progress = progress

progress_label=QtWidgets.QLabel()
progress_layout.addWidget(progress_label)
self.progress_label=progress_label
progress_label.setText("---")

buttons_layout = QtWidgets.QHBoxLayout()

self.progress=QtWidgets.QProgressBar()
self.progress.setMaximum(100)
self.progress.setValue(0)

self.progress_label=QtWidgets.QLabel()
self.progress_label.setText("---")
self.okButton = QtWidgets.QPushButton("OK")
#self.okButton.setMaximumSize(QtCore.QSize(200, 16777215))
#self.cancelButton = QtWidgets.QPushButton("Cancel")
#buttons_layout.addWidget(self.cancelButton)
buttons_layout.addWidget(self.okButton, alignment=QtCore.Qt.AlignRight)

rightArea_top=QtWidgets.QVBoxLayout()
rightArea_bottom=QtWidgets.QVBoxLayout()
rightArea_bottom.setAlignment(QtCore.Qt.AlignBottom)
rightArea_top.setAlignment(QtCore.Qt.AlignTop)
rightArea.addLayout(rightArea_top)
rightArea.addLayout(rightArea_bottom)

actions_layout.setAlignment(QtCore.Qt.AlignTop)
buttons_layout.setAlignment(QtCore.Qt.AlignBottom)
progress_layout.setAlignment(QtCore.Qt.AlignBottom)
file_name_layout.setAlignment(QtCore.Qt.AlignLeft)

rightArea_top.addLayout(actions_layout)
rightArea_top.addLayout(file_name_layout)
rightArea_bottom.addLayout(progress_layout)
rightArea_bottom.addLayout(buttons_layout)

mainLayout=QtWidgets.QHBoxLayout()
self.setLayout(mainLayout)
mainLayout.addWidget(self.bigPic)
rightArea = QtWidgets.QVBoxLayout()
mainLayout.addLayout(rightArea)

fileNameLayout = QtWidgets.QHBoxLayout()
fileNameLayout.addWidget(QtWidgets.QLabel(self.app.lang["output-name"]))
fileNameLayout.addWidget(self.leFileName)

if self.app.startMode!=StartMode.CURA:
self.btFileSelect = QtWidgets.QToolButton()
self.btFileSelect.setText(self.app.lang["select"])
fileNameLayout.addWidget(self.btFileSelect)
self.btFileSelect.clicked.connect(self.selectFile)

rightArea.addLayout(fileNameLayout)
rightArea.addWidget(self.cbStartPrinting)
rightArea.addStretch()
rightArea.addWidget(self.progress)
rightArea.addWidget(self.progress_label)

buttonsLayout = QtWidgets.QHBoxLayout()
buttonsLayout.addStretch()
buttonsLayout.addWidget(self.okButton)
rightArea.addLayout(buttonsLayout)

self.okButton.clicked.connect(self.onOk)

self.setLayout(mainLayout)
self.loadSource()
if self.app.inputFileName is not None:
self.loadSource()
pass

def selectFile(self):
if self.app.selectFile():
self.loadSource()
pass

def onOk(self, a):
Expand Down Expand Up @@ -171,6 +158,9 @@ def loadSource(self):
self.parser.parse()
self.bigPic.setPixmap(self.parser.getLargePreview())

if self.app.outputFileName is not None:
self.leFileName.setText(self.app.outputFileName)

def onFinised(self, state):
self.lockUILock(False)
self.sender=None
Expand Down
1 change: 0 additions & 1 deletion plugin/shui/utils/controls/GCodeActionsControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def __init__(self, parent, app):
idx=idx+1
if idx==8:
break
print(s)

self.uartControls=self.uartControls + [self.tbMoveXPlus,self.tbMoveYPlus,self.tbMoveZPlus,self.tbMoveXMinus, self.tbMoveYMinus,self.tbMoveZMinus]+self.snippet_btns

Expand Down
Loading

0 comments on commit a48283c

Please sign in to comment.