| 1 |
|
| 2 |
|
| 3 |
import PythonQt.QtGui as pqt |
| 4 |
import PythonQt.QtCore as pqtc |
| 5 |
|
| 6 |
def changeToChnget(text): |
| 7 |
lines = text.split("\n") |
| 8 |
newText = "" |
| 9 |
channels = {} |
| 10 |
strchannels = {} |
| 11 |
for line in lines: |
| 12 |
if line.count("invalue") > 0 : |
| 13 |
line = line.replace("invalue", "chnget") |
| 14 |
arg1Index = line.find("chnget") + 7 |
| 15 |
arg1EndIndex = line.find(";", arg1Index) |
| 16 |
if arg1EndIndex == -1: |
| 17 |
arg1EndIndex = None |
| 18 |
arg1 = line[arg1Index : arg1EndIndex].strip() |
| 19 |
if arg1.startswith('"_'): |
| 20 |
line = line.replace("chnget", "invalue") |
| 21 |
newText += line + "\n" |
| 22 |
continue |
| 23 |
if line.strip().startswith('S'): |
| 24 |
if arg1[1:-1] in strchannels: |
| 25 |
strchannels[arg1[1:-1]] |= 1 |
| 26 |
else: |
| 27 |
strchannels[arg1[1:-1]] = 1 |
| 28 |
else: |
| 29 |
if arg1[1:-1] in channels: |
| 30 |
channels[arg1[1:-1]] |= 1 |
| 31 |
else: |
| 32 |
channels[arg1[1:-1]] = 1 |
| 33 |
|
| 34 |
elif line.count("outvalue") > 0: |
| 35 |
line = line.replace("outvalue", "chnset") |
| 36 |
arg1Index = line.find("chnset") + 7 |
| 37 |
arg2Index = line.find(",", arg1Index) + 1 |
| 38 |
arg2EndIndex = line.find(";", arg2Index) |
| 39 |
if arg2EndIndex == -1: |
| 40 |
arg2EndIndex = None |
| 41 |
comment = line[arg2EndIndex :] |
| 42 |
arg1 = line[arg1Index : arg2Index - 1].strip() |
| 43 |
arg2 = line[arg2Index : arg2EndIndex].strip() |
| 44 |
if arg1.startswith('"_'): |
| 45 |
line = line.replace("chnset", "outvalue") |
| 46 |
newText += line + "\n" |
| 47 |
continue |
| 48 |
line = line[:arg1Index] + " " + arg2 + ", " + arg1 |
| 49 |
if (arg2EndIndex > 0): |
| 50 |
line += " " + comment |
| 51 |
if arg2.strip().startswith('S') or arg2.strip().startswith('"'): |
| 52 |
if arg1[1:-1] in channels: |
| 53 |
strchannels[arg1[1:-1]] |= 2 |
| 54 |
else: |
| 55 |
strchannels[arg1[1:-1]] = 2 |
| 56 |
else: |
| 57 |
if arg1[1:-1] in channels: |
| 58 |
channels[arg1[1:-1]] |= 2 |
| 59 |
else: |
| 60 |
channels[arg1[1:-1]] = 2 |
| 61 |
newText += line + "\n" |
| 62 |
chnText = '' |
| 63 |
index = 0 |
| 64 |
if len(channels) > 0 : |
| 65 |
index = newText.find('opcode') |
| 66 |
if index < 0: |
| 67 |
index = newText.find('instr') |
| 68 |
for chan in sorted(channels): |
| 69 |
chnText += 'chn_k "' + chan + '", ' + str(channels[chan]) + '\n' |
| 70 |
if len(strchannels) > 0 : |
| 71 |
index = newText.find('instr') |
| 72 |
for chan in sorted(strchannels): |
| 73 |
chnText += 'chn_S "' + chan + '", ' + str(strchannels[chan]) + '\n' |
| 74 |
newText = newText[:index] + chnText + '\n' + newText[index:] |
| 75 |
q.setOrc(newText) |
| 76 |
|
| 77 |
def changeToInvalue(text): |
| 78 |
lines = text.split("\n") |
| 79 |
newText = "" |
| 80 |
for line in lines: |
| 81 |
if line.count("chnget") > 0: |
| 82 |
line = line.replace("chnget", "invalue") |
| 83 |
elif line.count("chnset") > 0: |
| 84 |
line = line.replace("chnset", "outvalue") |
| 85 |
arg1Index = line.find("outvalue") + 8 |
| 86 |
arg2Index = line.find(",") + 1 |
| 87 |
arg2EndIndex = line.find(";", arg2Index) |
| 88 |
if arg2EndIndex == -1: |
| 89 |
arg2EndIndex = None |
| 90 |
comment = line[arg2EndIndex :] |
| 91 |
arg1 = line[arg1Index : arg2Index - 1].strip() |
| 92 |
arg2 = line[arg2Index : arg2EndIndex].strip() |
| 93 |
line = line[:arg1Index] + " " + arg2 + ", " + arg1 |
| 94 |
if (arg2EndIndex > 0): |
| 95 |
line += " " + comment |
| 96 |
if not (line.strip().startswith('chn_k') or line.strip().startswith('chn_S')): |
| 97 |
newText += line + "\n" |
| 98 |
q.setOrc(newText) |
| 99 |
|
| 100 |
def toInvalue(): |
| 101 |
changeToInvalue(q.getOrc()) |
| 102 |
|
| 103 |
def toChnget(): |
| 104 |
changeToChnget(q.getOrc()) |
| 105 |
|
| 106 |
|
| 107 |
w = pqt.QWidget() |
| 108 |
|
| 109 |
w.setGeometry(50,50, 250,40) |
| 110 |
l = pqt.QGridLayout(w) |
| 111 |
w.setLayout(l) |
| 112 |
w.setWindowTitle("Switch invalue->chnget") |
| 113 |
w.setWindowFlags(w.windowFlags() | pqtc.Qt.WindowStaysOnTopHint); |
| 114 |
|
| 115 |
t = pqt.QLabel("Press the buttons to switch invalue/outvalue for chnget/chnset", w) |
| 116 |
|
| 117 |
toChngetButton = pqt.QPushButton("Invalue -> Chnget",w) |
| 118 |
toInvalueButton = pqt.QPushButton("Chnget -> Invalue",w) |
| 119 |
|
| 120 |
l.addWidget(toChngetButton, 0, 0) |
| 121 |
l.addWidget(toInvalueButton, 0, 1) |
| 122 |
l.addWidget(t, 1, 0, 1, 2) |
| 123 |
|
| 124 |
toInvalueButton.connect("clicked()", toInvalue) |
| 125 |
toChngetButton.connect("clicked()", toChnget) |
| 126 |
|
| 127 |
w.show() |
| 128 |
|
| 129 |
|