Skip to content

Commit

Permalink
first pass subtool drop down
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasOuellet committed Mar 13, 2023
1 parent ab299ef commit a281ade
Show file tree
Hide file tree
Showing 10 changed files with 1,782 additions and 1,730 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"request": "launch",
"module": "zlm_ui",
"args": [
"370",
"406",
"${workspaceFolder}\\layers.TXT"
],
"envFile": "${workspaceFolder}/.env",
Expand Down
24 changes: 10 additions & 14 deletions dist/ZlmData/zLayerUpdate.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@

<zscriptinsert, "zlmOps.txt">

// check if there is a subtool loaded
[If, [IExists, "Tool:Layers:Layers Scrollbar"],
[VarSet, filePath, ""]
[VarSet, exec, ""]
[RoutineCall, zlmGetLayerPath, filePath]
[RoutineCall, zlmSaveLayerInfo, filePath]
[RoutineCall, zlmGetExecutable, exec]
[VarSet, quote, [StrFromAsc, 34]]

[VarSet, cmd, [StrMerge, "start ", #quote, #quote, " ", #quote, #exec, #quote, " -o -f ", #quote, #filePath, #quote]]
// [Note, cmd]
[ShellExecute, cmd]
,
]
[VarSet, filePath, ""]
[VarSet, exec, ""]
[RoutineCall, zlmGetLayerPath, filePath]
[RoutineCall, zlmSaveLayerInfo, filePath]
[RoutineCall, zlmGetExecutable, exec]
[VarSet, quote, [StrFromAsc, 34]]

[VarSet, cmd, [StrMerge, "start ", #quote, #quote, " ", #quote, #exec, #quote, " -o -f ", #quote, #filePath, #quote]]
// [Note, cmd]
[ShellExecute, cmd]
96 changes: 57 additions & 39 deletions dist/ZlmData/zlmOps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@

//initialise output value to 0
[VarSet, output, 0]
[If, [IExists, "Tool:Layers:Layers Scrollbar"],
//if there's a scrollbar there is more than one layer
[If, [IsEnabled, "Tool:Layers:Layers Scrollbar"],

//if there's a scrollbar there is more than one layer
[If, [IsEnabled, "Tool:Layers:Layers Scrollbar"],

//store current scroll bar position
[VarSet, tmpLyScrPos, [IGetSecondary, "Tool:Layers:Layers Scrollbar"]]
//store current scroll bar position
[VarSet, tmpLyScrPos, [IGetSecondary, "Tool:Layers:Layers Scrollbar"]]

//set scroll bar to a maximum to ensure it is at the top
[ISet, "Tool:Layers:Layers Scrollbar", 0, 256]
[VarSet, output, [IGetSecondary, "Tool:Layers:Layers Scrollbar"] + 1]
//set scroll bar to a maximum to ensure it is at the top
[ISet, "Tool:Layers:Layers Scrollbar", 0, 256]
[VarSet, output, [IGetSecondary, "Tool:Layers:Layers Scrollbar"] + 1]

// restore scroll bar position
[ISet, "Tool:Layers:Layers Scrollbar", 0, tmpLyScrPos]
,

[If,[IsEnabled, "Tool:Layers:Layer Intensity"],
[VarSet,output,1]
]
]
// restore scroll bar position
[ISet, "Tool:Layers:Layers Scrollbar", 0, tmpLyScrPos]
,

[If,[IsEnabled, "Tool:Layers:Layer Intensity"],
[VarSet,output,1]
]
]
]
]
,output]

Expand All @@ -44,13 +45,14 @@
[VarSet, layersCount, 0]
[RoutineCall, zlmGetLayerCount, layersCount]

// set max subdivs
[VarSet, subdiv, [IGet, "Tool:Geometry:SDiv"]]
[VarSet, tmpLyScrPos, [IGetSecondary, "Tool:Layers:Layers Scrollbar"]]

[VarSet, isRecording, 0]
[VarSet, recordingYpos, 0]
[If, layersCount > 0,
// set max subdivs
[VarSet, subdiv, [IGet, "Tool:Geometry:SDiv"]]
[VarSet, tmpLyScrPos, [IGetSecondary, "Tool:Layers:Layers Scrollbar"]]

[VarSet, isRecording, 0]
[VarSet, recordingYpos, 0]


[VarSet, layerIdOne, 0]
[RoutineCall, zlmGetIdFirstLayerID, layerIdOne]
Expand Down Expand Up @@ -119,20 +121,31 @@

, counter]

// Write the name of the sub tools
[VarSet, subtoolName, [IGetTitle, "Tool:ItemInfo"]]
[VarSet, idx, [SubToolGetActiveIndex]]
[VarSet, subtoolLine, [StrMerge, #quote, #subtoolName, #quote, " ", #idx]]

[VarSet, currentSubToolIndex, [SubToolGetActiveIndex]]
[VarSet, subtoolLine, [StrMerge, "SubTools: ", #currentSubToolIndex, [StrFromAsc, 10]]]
[VarAdd, currentSize, [StrLength, subtoolLine]]

// Check if memory is big enough
// Resize it enough so we dont have to resize everytime
[If, currentSize > [MemGetSize, layerNameMem],
[MemResize, layerNameMem, currentSize]
,]
[VarAdd, byteOffset, [MemWriteString, layerNameMem, subtoolLine, byteOffset, 0]]

[VarSet, subToolCount, [SubToolGetCount]]
[Loop, subToolCount,
[SubToolSelect, #index]
[VarSet, subToolName, [StrMerge, #quote, [IGetTitle, "Tool:ItemInfo"], #quote]]
[If, #index + 1 < subToolCount,
[VarSet, subToolName, [StrMerge, #subToolName, [StrFromAsc, 10]]]
]
[VarAdd, currentSize, [StrLength, subToolName]]
// Check if memory is big enough
// Resize it enough so we dont have to resize everytime
[If, currentSize > [MemGetSize, layerNameMem],
[MemResize, layerNameMem, currentSize]
,]
[VarAdd, byteOffset, [MemWriteString, layerNameMem, subToolName, byteOffset, 0]]
, index]

// Resize memory to the actual total size so we don't write any empty bits.
[MemResize, layerNameMem, currentSize]
Expand All @@ -141,20 +154,25 @@

[MemDelete, layerNameMem]

[SubToolSelect, #currentSubToolIndex]

// If was recording
[If, #isRecording,
[ISet, "Tool:Layers:Layers Scrollbar", 0, recordingYpos]
[VarSet, wid, [IWidth, #layerIdOne]]
[IClick, #layerIdOne, wid-20, 5]
]
[If, layersCount > 0,
[If, #isRecording,
[ISet, "Tool:Layers:Layers Scrollbar", 0, recordingYpos]
[VarSet, wid, [IWidth, #layerIdOne]]
[IClick, #layerIdOne, wid-20, 5]
]

// restore scroll bar position
[If, [IsEnabled, "Tool:Layers:Layers Scrollbar"],
[ISet, "Tool:Layers:Layers Scrollbar", 0, tmpLyScrPos]
]
// restore scroll bar position
[If, [IsEnabled, "Tool:Layers:Layers Scrollbar"],
[ISet, "Tool:Layers:Layers Scrollbar", 0, tmpLyScrPos]
]

// restore subdiv.
[ISet, "Tool:Geometry:SDiv", #subdiv, 0]

// restore subdiv.
[ISet, "Tool:Geometry:SDiv", #subdiv, 0]
]

] // IFreeze

Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Pygments==2.10.0
pyinstaller==4.5.1
pyinstaller-hooks-contrib==2021.3
pyparsing==2.4.7
PyQt5==5.12.1
PyQt5_sip==4.19.15
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.1
pytz==2021.3
pywin32-ctypes==0.2.0
requests==2.22.0
Expand All @@ -40,4 +41,5 @@ sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
typing-extensions==3.10.0.2
urllib3==1.25.11
zipp==3.6.0
51 changes: 33 additions & 18 deletions src/zlm_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ def __init__(self, name, index):
self.index = index

@staticmethod
def from_line(line):
def from_line(line, index):
line = line.strip()
start = line.find("\"")
end = line.find("\"", start+1)
splitted = line[end+1:].strip()
name = line[start+1: end]
start = line.find("\"") + 1
end = line.find("\"", start)
name = line[start: end]
if name.endswith('.'):
name = name[:-1]
return ZlmSubTool(name, int(splitted))
return ZlmSubTool(name, index)


class ZlmLayer(object):
Expand Down Expand Up @@ -92,7 +91,8 @@ def __init__(self):
self.instances = {}
self.instances_list: List[ZlmLayer] = []

self.subtool = None
self.current_sub_tool: int = 0
self.subtools: List[ZlmSubTool] = []

self.recording_layer = None

Expand Down Expand Up @@ -132,12 +132,10 @@ def _add_layer(self, layer, index=None):

layer.master = self

def set_subtool(self, subtool):
self.subtool = subtool

def clear(self):
self.instances.clear()
self.instances_list.clear()
self.subtools.clear()

def layers_it(self, exclude_record=True, backward=False):
layers = self.instances_list
Expand Down Expand Up @@ -223,18 +221,35 @@ def duplicate_layer(self, layer, move_down=False):

return layer, new_layer

def _parse_layer(self, lines: List[str]) -> int:
# layer index starts a 1
for x, line in enumerate(lines, 1):
if line.startswith('SubTools:'):
return x - 1
self._add_layer(ZlmLayer.from_line(line, x))
return 0

def _parse_subtool_line(self, lines: List[str]):
if not lines:
return

line = lines[0].strip()
# get current subtool
self.current_sub_tool = int(line.split(' ')[1])
for index, line in enumerate(lines[1:]):
self.subtools.append(ZlmSubTool.from_line(line, index))

def load_from_file(self, file_path):
self.clear()
subTool = None

with open(file_path, mode='r') as f:
lines = f.readlines()
# last line is for subtools
for x, line in enumerate(lines[:-1]):
layer = ZlmLayer.from_line(line, x+1)
self._add_layer(layer)
subTool = ZlmSubTool.from_line(lines[-1])
self.set_subtool(subTool)
try:
layer_end = self._parse_layer(lines)
self._parse_subtool_line(lines[layer_end:])
except:
pass

for cb in self._cb_on_layer_updated:
cb()

Expand All @@ -245,7 +260,7 @@ def validate_layer_name(self, name):

number = 1
# replace number with new number
match = re.search('(\d+)$', name)
match = re.search(r'(\d+)$', name)
if match:
name = name[:match.span()[0]]
number = int(match.group(0)) + 1
Expand Down
8 changes: 5 additions & 3 deletions src/zlm_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

ZBRUSH_PATH = None
LAYER_INDEX = 368
UPDATE_SCRIPT_FILE = 'zLayerUpdate.TXT'


if getattr(sys, 'frozen', False):
# frozen
dirname = os.path.dirname(sys.executable)
SCRIPT_PATH = os.path.join(dirname, 'zlm.TXT')

UPDATE_SCRIPT_PATH = os.path.join(dirname, 'zLayerUpdate.TXT')
UPDATE_SCRIPT_PATH = os.path.join(dirname, UPDATE_SCRIPT_FILE)

else:
dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
SCRIPT_PATH = os.path.join(dirname, 'zlm.TXT')
UPDATE_SCRIPT_PATH = os.path.join(dirname, 'dist', 'ZlmData', 'zLayerUpdate.TXT')
SCRIPT_PATH = os.path.join(dirname, 'dist', 'ZlmData', 'zlm.TXT')
UPDATE_SCRIPT_PATH = os.path.join(dirname, 'dist', 'ZlmData', UPDATE_SCRIPT_FILE)


def get_zbrush_path() -> str:
Expand Down
9 changes: 9 additions & 0 deletions src/zlm_to_zbrush.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,12 @@ def send_new_layer_order(layers: List[zlm_core.ZlmLayer]):
# call a ui update
for cb in zlm_core.main_layers._cb_on_layers_changed:
cb()


def send_new_sub_tool(index: int, port: int):
with zsc.ZScript(zlm_info.SCRIPT_PATH):
zsc.TextCommand(f'[SubToolSelect, {index}]')

# include update script so we update the new layers
zsc.TextCommand(f'<zscriptinsert, "{zlm_info.UPDATE_SCRIPT_FILE}"')
_send_script()
3 changes: 3 additions & 0 deletions src/zlm_ui/comserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def isRunning(self):

return self._deamon.isRunning()

def get_port(self) -> int:
return self._address[1]

def start(self):
if not self.isRunning():
self._address = ('localhost', 0)
Expand Down
27 changes: 17 additions & 10 deletions src/zlm_ui/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
send_new_layer_order,
send_to_zbrush,
send_update_request,
send_new_layers_name
send_new_layers_name,
send_new_sub_tool
)
import zlm_app
import version
Expand Down Expand Up @@ -107,14 +108,17 @@ def __init__(self, file_path=None):
pb_help = QtWidgets.QPushButton(QtGui.QIcon(':/help.png'), '')
pb_help.clicked.connect(self.open_help_url)

self.cb_subtool = QtWidgets.QComboBox()
self.cb_subtool.currentIndexChanged.connect(self.sub_tool_index_changed)

topLayout = QtWidgets.QHBoxLayout()
topLayout.addWidget(self.lbl_subtool)
topLayout.addStretch()
topLayout.addWidget(self.lbl_subtool, 0)
topLayout.addWidget(self.cb_subtool, 1)
topLayout.addWidget(self.lbl_layer_count, 0, QtCore.Qt.AlignRight)
topLayout.addWidget(QtWidgets.QLabel("Layers"), 0, QtCore.Qt.AlignRight)
topLayout.addSpacing(20)
topLayout.addWidget(pb_option)
topLayout.addWidget(pb_help)
topLayout.addWidget(pb_option, 0)
topLayout.addWidget(pb_help, 0)

mainLayout = QtWidgets.QVBoxLayout()

Expand Down Expand Up @@ -209,11 +213,11 @@ def load_layers(self, file_path):
self.update_subtool_label()

def update_subtool_label(self):
subtool = zlm_core.main_layers.subtool
if subtool:
self.lbl_subtool.setText("SubTool: " + subtool.name)
else:
self.lbl_subtool.setText("SubTool: ")
signal_blocked = self.cb_subtool.blockSignals(True)
self.cb_subtool.clear()
self.cb_subtool.addItems([st.name for st in zlm_core.main_layers.subtools])
self.cb_subtool.setCurrentIndex(zlm_core.main_layers.current_sub_tool)
self.cb_subtool.blockSignals(signal_blocked)

def _apply_custom_stylesheet(self):
if getattr(sys, 'frozen', False):
Expand Down Expand Up @@ -309,3 +313,6 @@ def bulk_rename(self):

if mod_layers:
send_new_layers_name(mod_layers)

def sub_tool_index_changed(self, index: int):
send_new_sub_tool(index, self.com_server.get_port())
Loading

0 comments on commit a281ade

Please sign in to comment.