You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.2 KiB
128 lines
4.2 KiB
#!/bin/env python3
|
|
|
|
import gex
|
|
|
|
import sys
|
|
from PyQt4 import QtGui, QtCore
|
|
import ini_syntax
|
|
|
|
class GexIniEditor(QtGui.QMainWindow):
|
|
"""
|
|
Gexync is a GEX ini file editor.
|
|
The editor loads the INI file through the communication interface
|
|
without having to mount the virtual filesystem, which is unreliable
|
|
on some systems.
|
|
|
|
This utility allows live editing of the UNITS.INI file.
|
|
|
|
On save, a new version is loaded with formatting and error messages
|
|
generated by GEX, as if the virtual config filesystem was re-mounted.
|
|
|
|
The editor does not keep GEX claimed, instead does so only when needed.
|
|
This allows testing of the current configuration without having to close
|
|
and reopen the editor.
|
|
"""
|
|
|
|
def __init__(self, xferLambda):
|
|
self.xferLambda = xferLambda
|
|
|
|
self.filenum = int(sys.argv[1]) if len(sys.argv)>1 else 0
|
|
|
|
super().__init__()
|
|
self.initUI()
|
|
# TODO let user pick GEX device if multiple
|
|
|
|
def initToolbar(self):
|
|
icon = self.style().standardIcon(QtGui.QStyle.SP_BrowserReload)
|
|
loadAction = QtGui.QAction(icon, 'Reload', self)
|
|
loadAction.setShortcut('Ctrl+O')
|
|
loadAction.triggered.connect(self.gexLoad)
|
|
|
|
icon = self.style().standardIcon(QtGui.QStyle.SP_DialogSaveButton)
|
|
syncAction = QtGui.QAction(icon, 'Write Changes', self)
|
|
syncAction.setShortcut('Ctrl+S')
|
|
syncAction.triggered.connect(self.gexSync)
|
|
|
|
icon = self.style().standardIcon(QtGui.QStyle.SP_DialogOkButton)
|
|
persAction = QtGui.QAction(icon, 'Persist', self)
|
|
persAction.setShortcut('Ctrl+P')
|
|
persAction.triggered.connect(self.gexPersist)
|
|
|
|
self.toolbar = self.addToolBar('Toolbar')
|
|
self.toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
|
|
self.toolbar.addAction(loadAction)
|
|
self.toolbar.addAction(syncAction)
|
|
self.toolbar.addSeparator()
|
|
self.toolbar.addAction(persAction)
|
|
|
|
def initEditor(self):
|
|
self.editor = QtGui.QPlainTextEdit()
|
|
|
|
# Editor background and text color
|
|
pal = QtGui.QPalette()
|
|
bgc = QtGui.QColor(0xFFFFF6)
|
|
pal.setColor(QtGui.QPalette.Base, bgc)
|
|
textc = QtGui.QColor(0x000000)
|
|
pal.setColor(QtGui.QPalette.Text, textc)
|
|
self.editor.setPalette(pal)
|
|
# Font
|
|
font = QtGui.QFont('Liberation Mono', 12)
|
|
font.setStyleHint(QtGui.QFont.TypeWriter)
|
|
self.editor.setFont(font)
|
|
# Initial size
|
|
self.highlight = ini_syntax.IniHighlighter(self.editor.document())
|
|
|
|
def initUI(self):
|
|
self.setWindowTitle('GEX config file editor')
|
|
self.initToolbar()
|
|
self.initEditor()
|
|
self.setCentralWidget(self.editor)
|
|
self.show()
|
|
|
|
self.gexLoad()
|
|
|
|
def gexLoad(self):
|
|
self.editor.setPlainText("")
|
|
self.editor.repaint()
|
|
|
|
client = gex.Client(self.xferLambda(), load_units=False)
|
|
read_ini = client.ini_read(self.filenum)
|
|
client.close()
|
|
|
|
self.editor.setPlainText(read_ini)
|
|
self.highlight.rehighlight()
|
|
self.setWindowTitle('GEX config file editor')
|
|
|
|
def gexSync(self):
|
|
new_txt = self.editor.toPlainText()
|
|
self.editor.setPlainText("")
|
|
self.editor.repaint()
|
|
|
|
client = gex.Client(self.xferLambda(), load_units=False)
|
|
client.ini_write(new_txt)
|
|
read_ini = client.ini_read(self.filenum)
|
|
client.close()
|
|
|
|
self.editor.setPlainText(read_ini)
|
|
self.highlight.rehighlight()
|
|
self.setWindowTitle('*GEX config file editor')
|
|
|
|
def gexPersist(self):
|
|
client = gex.Client(self.xferLambda(), load_units=False)
|
|
client.ini_persist()
|
|
client.close()
|
|
self.setWindowTitle('GEX config file editor')
|
|
|
|
if __name__ == '__main__':
|
|
app = QtGui.QApplication(sys.argv)
|
|
editor = GexIniEditor(lambda: gex.TrxRawUSB())
|
|
# editor = GexIniEditor(lambda: gex.TrxSerialThread(port='/dev/ttyUSB1',
|
|
# baud=57600))
|
|
|
|
# centered resize
|
|
w = 800
|
|
h = 900
|
|
ss = app.desktop().availableGeometry().size()
|
|
editor.setGeometry(int(ss.width() / 2 - w / 2), int(ss.height() / 2 - h / 2), w, h)
|
|
|
|
sys.exit(app.exec_())
|
|
|