def __init__(self, category): super(DataTaskView, self).__init__(category, 'Data') self.pp = pprint.PrettyPrinter() self.left.child.setSizePolicy( gui.SizePolicy.MinimumExpanding, gui.SizePolicy.MinimumExpanding) self.tree = self.addLeftWidget(DataTree(G.app)) self.clear = self.addLeftWidget(gui.Button('Clear')) self.text = self.addTopWidget(gui.DocumentEdit()) self.tree.setHeaderHidden(True) self.tree.resizeColumnToContents(0) self.tree.setSizePolicy( gui.SizePolicy.Ignored, gui.SizePolicy.Expanding) self.left.layout.setStretchFactor(self.tree, 1) @self.tree.mhEvent def onActivate(item): path = self.tree.getItemPath(item) # log.message('data: %s', path) self.showData(path) @self.tree.mhEvent def onExpand(item): self.tree.populate(item) self.tree.resizeColumnToContents(0) @self.clear.mhEvent def onClicked(event): self.clearData()
def __init__(self, category): super(ShellTaskView, self).__init__(category, 'Shell') self.globals = {'G': G} self.history = [] self.histitem = None self.main = self.addTopWidget(QtGui.QWidget()) self.layout = QtGui.QGridLayout(self.main) self.layout.setRowStretch(0, 0) self.layout.setRowStretch(1, 0) self.layout.setColumnStretch(0, 1) self.layout.setColumnStretch(1, 0) self.text = gui.DocumentEdit() self.text.setSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.layout.addWidget(self.text, 0, 0, 1, 2) self.line = gui.TextEdit() self.line.setFocusPolicy(QtCore.Qt.StrongFocus) self.layout.addWidget(self.line, 1, 0, 1, 1) self.globals = {'G': G} self.clear = gui.Button("Clear") self.layout.addWidget(self.clear, 1, 1, 1, 1) @self.line.mhEvent def onActivate(text): self.execute(text) self.history.append(text) self.histitem = None self.line.setText('') @self.clear.mhEvent def onClicked(event): self.clearText() @self.line.mhEvent def onUpArrow(_dummy): self.upArrow() @self.line.mhEvent def onDownArrow(_dummy): self.downArrow()
def __init__(self, category): """ Constructor for the TaskView. This accepts the category under which this feature is enabled. The category is registered with the app and passed into this constructor on the `load()` API below. """ self.human = gui3d.app.selectedHuman gui3d.TaskView.__init__(self, category, "MHServer") fr_left = self.addLeftWidget(gui.GroupBox("Settings:")) self.txt_port = fr_left.addWidget(gui.TextEdit(text="18830")) self.btn_restart = fr_left.addWidget(gui.Button("Restart")) @self.btn_restart.mhEvent def onClicked(e): self.restart_server() self.logbox = self.addTopWidget(gui.DocumentEdit()) self.logbox.setText("") self.logbox.setLineWrapMode(gui.DocumentEdit.NoWrap)
def __init__(self, category): self.human = gui3d.app.selectedHuman gui3d.TaskView.__init__(self, category, 'Socket') box = self.addLeftWidget(gui.GroupBox('Server')) self.aToggleButton = box.addWidget(gui.CheckBox('Accept connections')) @self.aToggleButton.mhEvent def onClicked(event): if self.aToggleButton.selected: self.openSocket() else: self.closeSocket() self.scriptText = self.addTopWidget(gui.DocumentEdit()) self.scriptText.setText('') self.scriptText.setLineWrapMode(gui.DocumentEdit.NoWrap) self.dirops = SocketDirOps(self) self.meshops = SocketMeshOps(self) self.modops = SocketModifierOps(self)
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Scripting') self.directory = os.getcwd() self.filename = None scriptingHome = mh.getPath('scripts') if not os.path.exists(scriptingHome): try: os.mkdir(scriptingHome) except OSError: scriptingHome = mh.getPath() box = self.addLeftWidget(gui.GroupBox('Script')) self.scriptText = self.addTopWidget(gui.DocumentEdit()) self.scriptText.setText('') self.scriptText.setLineWrapMode(gui.DocumentEdit.NoWrap) self.loadButton = box.addWidget(gui.BrowseButton(mode='open'), 0, 0) self.loadButton.setLabel('Load ...') self.loadButton.directory = scriptingHome self.saveButton = box.addWidget(gui.BrowseButton(mode='save'), 0, 1) self.saveButton.setLabel('Save ...') self.saveButton.directory = scriptingHome @self.loadButton.mhEvent def onClicked(filename): if not filename: return if (os.path.exists(filename)): contents = io.open(filename, 'r', encoding="utf-8").read() self.scriptText.setText(contents) dlg = gui.Dialog() dlg.prompt("Load script", "File was loaded in an acceptable manner", "OK") self.filename = filename self.directory = os.path.split(filename)[0] else: dlg = gui.Dialog() dlg.prompt("Load script", "File %s does not exist", "OK", fmtArgs=filename) @self.saveButton.mhEvent def onClicked(filename): if not filename: return with io.open(filename, "w", encoding="utf-8") as f: f.write(self.scriptText.getText()) dlg = gui.Dialog() dlg.prompt("Save script", "File was written in an acceptable manner", "OK") self.filename = filename self.directory = os.path.split(filename)[0] box2 = self.addLeftWidget(gui.GroupBox('Examples')) self.insertLabel = box2.addWidget( gui.TextView('Append example to script')) self.listView = box2.addWidget(gui.ListView()) self.listView.setSizePolicy(gui.SizePolicy.Ignored, gui.SizePolicy.Preferred) testlist = [ 'applyTarget()', 'incrementingFilename()', 'getHeightCm()', 'getPositionX()', 'getPositionY()', 'getPositionZ()', 'getRotationX()', 'getRotationY()', 'getRotationZ()', 'getZoom()', 'loadModel()', 'modifyPositionX()', 'modifyPositionY()', 'modifyPositionZ()', 'modifyRotationX()', 'modifyRotationY()', 'modifyRotationZ()', 'modifyZoom()', 'printCameraInfo()', 'printDetailStack()', 'printPositionInfo()', 'printRotationInfo()', 'saveModel()', 'screenShot()', 'setAge()', 'setPositionX()', 'setPositionY()', 'setPositionZ()', 'setRotationX()', 'setRotationY()', 'setRotationZ()', 'setZoom()', 'setWeight()', 'setMaterial()', 'setHeadSquareness()', 'getModelingParameters()', 'updateModelingParameter()', 'updateModelingParameters()', 'saveObj()' ] self.listView.setData(testlist) self.insertButton = box2.addWidget(gui.Button('Append')) @self.insertButton.mhEvent def onClicked(event): item = self.listView.getSelectedItem() if (item == 'applyTarget()'): text = "# applyTarget(<target file name>, <power (from 0.0 to 1.0)>)\n" text = text + "#\n" text = text + "# This will apply the target on the model. If the target was already applied, the power will be updated\n" text = text + "# Note that targets are relative to the data/targets directory, and should not include the .target\n" text = text + "# extension, so a valid target name would be, for example, \"breast/breast-dist-max\"\n\n" text = text + "MHScript.applyTarget('aTargetName',1.0)\n\n" self.scriptText.addText(text) if (item == 'loadModel()'): text = "# loadModel(<model name>,[path])\n" text = text + "#\n" text = text + "# This will load a human model from an MHM file. The <model name> part should be a string without spaces\n" text = text + "# and without the .MHM extension. The [path] part defaults to the user's makehuman/models directory.\n\n" text = text + "MHScript.loadModel('myTestModel')\n\n" self.scriptText.addText(text) if (item == 'incrementingFilename()'): text = "# incrementingFilename(<file name base>, [file extension], [pad length])\n" text = text + "#\n" text = text + "# This will return a file name containing a numerical component which increases by one for each call.\n" text = text + "# The default file extension is \".png\". The default pad length is 4. For example, the following lines:\n" text = text + "#\n" text = text + "# print incrementingFilename(\"test\",\".target\",3) + \"\\n\"\n" text = text + "# print incrementingFilename(\"test\",\".target\",3) + \"\\n\"\n" text = text + "#\n" text = text + "# Will print:\n" text = text + "#\n" text = text + "# test001.target\n" text = text + "# test002.target\n" text = text + "#\n" text = text + "# The counter is reset each time the script is executed\n\n" text = text + "filename = MHScript.incrementingFilename('test')\n\n" self.scriptText.addText(text) if (item == 'printCameraInfo()'): text = "# printCameraInfo()\n" text = text + "#\n" text = text + "# This will print info about how the camera is targeted and focused .\n\n" text = text + "MHScript.printCameraInfo()\n\n" self.scriptText.addText(text) if (item == 'printDetailStack()'): text = "# printDetailStack()\n" text = text + "#\n" text = text + "# This will print a list of all applied targets (and their weights) to standard output.\n\n" text = text + "MHScript.printDetailStack()\n\n" self.scriptText.addText(text) if (item == 'printPositionInfo()'): text = "# printPositionInfo()\n" text = text + "#\n" text = text + "# This will print info about where the human object is currently located.\n\n" text = text + "MHScript.printPositionInfo()\n\n" self.scriptText.addText(text) if (item == 'printRotationInfo()'): text = "# printRotationInfo()\n" text = text + "#\n" text = text + "# This will print info about how the human object is currently rotated.\n\n" text = text + "MHScript.printRotationInfo()\n\n" self.scriptText.addText(text) if (item == 'saveModel()'): text = "# saveModel(<model name>,[path])\n" text = text + "#\n" text = text + "# This will save the human model to an MHM file. The <model name> part should be a string without spaces\n" text = text + "# and without the .MHM extension. The [path] part defaults to the user's makehuman/models directory.\n" text = text + "# Note that this will not save any thumbnail.\n\n" text = text + "MHScript.saveModel('myTestModel')\n\n" self.scriptText.addText(text) if (item == 'saveObj()'): text = "# saveObj(<model name>,[path])\n" text = text + "#\n" text = text + "# This will save the human model to a wavefront .OBJ file. The <model name> part should be a string without spaces\n" text = text + "# and without the .obj extension. The [path] part defaults to the user's makehuman/exports directory.\n" text = text + "MHScript.saveObj('myOBJExport')\n\n" self.scriptText.addText(text) if (item == 'screenShot()'): text = "# screenShot(<png file name>)\n" text = text + "#\n" text = text + "# This will save a png file of how the model currently looks.\n\n" text = text + "MHScript.screenShot('screenshot.png')\n\n" self.scriptText.addText(text) if (item == 'setAge()'): text = "# setAge(age)\n" text = text + "#\n" text = text + "# Sets the age of the model. The age parameter is a float between 0 and 1, where 0 is 1 year old, 0.18 is 10 years old, 0.5 is 25 years and 1 equals 90 years old.\n\n" text = text + "MHScript.setAge(0.5)\n\n" self.scriptText.addText(text) if (item == 'setWeight()'): text = "# setWeight(weight)\n" text = text + "#\n" text = text + "# Sets the weight of the model. The weight parameter is a float between 0 and 1, where 0 is starved and\n" text = text + "# 1 is severely overweight\n\n" text = text + "MHScript.setWeight(0.5)\n\n" self.scriptText.addText(text) if (item == 'setHeadSquareness()'): text = "# setHeadSquareness(squareness)\n" text = text + "#\n" text = text + "# Sets the squaredness of the model's head. The squareness parameter is a float between 0 and 1, where 0 is not square and\n" text = text + "# 1 is very square shaped\n\n" text = text + "MHScript.setHeadSquareness(0.5)\n\n" self.scriptText.addText(text) if (item == 'setMaterial()'): text = "# setMaterial(mhmat_filename)\n" text = text + "#\n" text = text + "# Sets the skin material of the 3D model\n" text = text + "# The filename must be realtive to the App Resources directory\n\n" text = text + "MHScript.setMaterial('data/skins/young_caucasian_female/young_caucasian_female.mhmat')\n\n" self.scriptText.addText(text) if (item == 'getHeightCm()'): text = "# getHeightCm()\n" text = text + "#\n" text = text + "# Gets the current height of the model, in cm.\n\n" text = text + "height = MHScript.getHeightCm()\n" text = text + "print('height='+str(height))\n\n" self.scriptText.addText(text) if (item == 'getModelingParameters()'): text = "# getModelingParameters()\n" text = text + "#\n" text = text + "# Prints the names of all modeling aspects that can be modified on the human model.\n" text = text + "MHScript.getModelingParameters()\n\n" self.scriptText.addText(text) if (item == 'updateModelingParameter()'): text = "# updateModelingParameter(parameterName, value)\n" text = text + "#\n" text = text + "# Sets the modeling parameter with specified name of the model to the specified value.\n" text = text + "# The value is a float between 0 and 1, where 0 means nothing at all or minimal, and 1 is the maximum value.\n\n" text = text + "MHScript.updateModelingParameter('macrodetails/Age', 0.7)\n\n" self.scriptText.addText(text) if (item == 'updateModelingParameters()'): text = "# updateModelingParameters(dictOfParameterNameAndValue)\n" text = text + "#\n" text = text + "# Sets more modeling parameters with specified names of the model to the specified values.\n" text = text + "# Faster than setting parameters one by one because the 3D mesh is updated only once.\n" text = text + "# The values are a float between 0 and 1, where 0 means nothing at all or minimal, and 1 is the maximum value.\n\n" text = text + "MHScript.updateModelingParameters({'macrodetails/Caucasian': 1.000,'macrodetails/Gender': 1.000,'macrodetails/Age': 0.250})\n\n" self.scriptText.addText(text) if (item == 'setPositionX()'): text = "# setPositionX(xpos)\n" text = text + "#\n" text = text + "# Sets the X position of the model of the model in 3d space, where 0.0 is centered.\n\n" text = text + "MHScript.setPositionX(2.0)\n\n" self.scriptText.addText(text) if (item == 'getPositionX()'): text = "# getPositionX()\n" text = text + "#\n" text = text + "# Returns the current X position of the model of the model in 3d space.\n\n" text = text + "MHScript.getPositionX()\n\n" self.scriptText.addText(text) if (item == 'modifyPositionX()'): text = "# modifyPositionX(xmod)\n" text = text + "#\n" text = text + "# Modifies X position of the model of the model in 3d space.\n\n" text = text + "MHScript.modifyPositionX(-0.1)\n\n" self.scriptText.addText(text) if (item == 'setPositionZ()'): text = "# setPositionZ(zpos)\n" text = text + "#\n" text = text + "# Sets the Z position of the model of the model in 3d space, where 0.0 is centered.\n\n" text = text + "MHScript.setPositionZ(2.0)\n\n" self.scriptText.addText(text) if (item == 'getPositionZ()'): text = "# getPositionZ()\n" text = text + "#\n" text = text + "# Returns the current Z position of the model of the model in 3d space.\n\n" text = text + "MHScript.getPositionZ()\n\n" self.scriptText.addText(text) if (item == 'modifyPositionZ()'): text = "# modifyPositionZ(zmod)\n" text = text + "#\n" text = text + "# Modifies Z position of the model of the model in 3d space.\n\n" text = text + "MHScript.modifyPositionZ(-0.1)\n\n" self.scriptText.addText(text) if (item == 'setPositionY()'): text = "# setPositionY(ypos)\n" text = text + "#\n" text = text + "# Sets the Y position of the model of the model in 3d space, where 0.0 is centered.\n" text = text + "# Note that the depth of the scene is clipped, so if you move the model too far back\n" text = text + "# it will disappear. You will most likely want to use zoom instead of Y position.\n\n" text = text + "MHScript.setPositionY(2.0)\n\n" self.scriptText.addText(text) if (item == 'getPositionY()'): text = "# getPositionY()\n" text = text + "#\n" text = text + "# Returns the current Y position of the model of the model in 3d space.\n\n" text = text + "MHScript.getPositionY()\n\n" self.scriptText.addText(text) if (item == 'modifyPositionY()'): text = "# modifyPositionY(ymod)\n" text = text + "#\n" text = text + "# Modifies Y position of the model of the model in 3d space.\n" text = text + "# Note that the depth of the scene is clipped, so if you move the model too far back\n" text = text + "# it will disappear. You will most likely want to use zoom instead of Y position.\n\n" text = text + "MHScript.modifyPositionY(-0.1)\n\n" self.scriptText.addText(text) if (item == 'setRotationX()'): text = "# setRotationX(xrot)\n" text = text + "#\n" text = text + "# Sets the rotation around the X axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.setRotationX(90.0)\n\n" self.scriptText.addText(text) if (item == 'getRotationX()'): text = "# getRotationX()\n" text = text + "#\n" text = text + "# Returns the current rotatation around the X axis of the model.\n\n" text = text + "MHScript.getRotationX()\n\n" self.scriptText.addText(text) if (item == 'modifyRotationX()'): text = "# modifyRotationX(xmod)\n" text = text + "#\n" text = text + "# Modifies the rotation around the X axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.modifyRotationX(-5.0)\n\n" self.scriptText.addText(text) if (item == 'setRotationZ()'): text = "# setRotationZ(zrot)\n" text = text + "#\n" text = text + "# Sets the rotation around the Z axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.setRotationZ(90.0)\n\n" self.scriptText.addText(text) if (item == 'getRotationZ()'): text = "# getRotationZ()\n" text = text + "#\n" text = text + "# Returns the current rotatation around the Z axis of the model.\n\n" text = text + "MHScript.getRotationZ()\n\n" self.scriptText.addText(text) if (item == 'modifyRotationZ()'): text = "# modifyRotationZ(zmod)\n" text = text + "#\n" text = text + "# Modifies the rotation around the Z axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.modifyRotationZ(-5.0)\n\n" self.scriptText.addText(text) if (item == 'setRotationY()'): text = "# setRotationY(yrot)\n" text = text + "#\n" text = text + "# Sets the rotation around the Y axis for the model, where 0.0 is upright projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.setRotationY(90.0)\n\n" self.scriptText.addText(text) if (item == 'getRotationY()'): text = "# getRotationY()\n" text = text + "#\n" text = text + "# Returns the current rotatation around the Y axis of the model.\n\n" text = text + "MHScript.getRotationY()\n\n" self.scriptText.addText(text) if (item == 'modifyRotationY()'): text = "# modifyRotationY(ymod)\n" text = text + "#\n" text = text + "# Modifies the rotation around the Y axis for the model, where 0.0 is upright projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.modifyRotationY(-5.0)\n\n" self.scriptText.addText(text) if (item == 'setZoom()'): text = "# setZoom(zoom)\n" text = text + "#\n" text = text + "# Sets current camera zoom. In practise this moves the camera closer or further from the.\n" text = text + "# the model. The zoom factor is reversed ans goes from 100.0 which is far away from the\n" text = text + "# the model as possible (if you move further away, the model will be clipped and disappear)\n" text = text + "# and 0.0 is inside the model. A zoom factor of 10.0 is what is used for the face\n" text = text + "# projection, and is in most cases as zoomed in as is functional.\n\n" text = text + "MHScript.setZoom(70.0)\n\n" self.scriptText.addText(text) if (item == 'modifyZoom()'): text = "# modifyZoom(zmod)\n" text = text + "#\n" text = text + "# Modifies current camera zoom. In practise this moves the camera closer or further from the.\n" text = text + "# the model. The zoom factor is reversed ans goes from 100.0 which is far away from the\n" text = text + "# the model as possible (if you move further away, the model will be clipped and disappear)\n" text = text + "# and 0.0 is inside the model. A zoom factor of 10.0 is what is used for the face\n" text = text + "# projection, and is in most cases as zoomed in as is functional.\n\n" text = text + "MHScript.modifyZoom(1.0)\n\n" self.scriptText.addText(text) if (item == 'getZoom()'): text = "# getZoom()\n" text = text + "#\n" text = text + "# Returns the current camera zoom factor.\n\n" text = text + "MHScript.getZoom()\n\n" self.scriptText.addText(text)
def __init__(self, category): super(ShellTaskView, self).__init__(category, 'Shell') self.globals = {'G': G} self.history = [] self.histitem = None if hasIpython: # Use the more advanced Ipython console self.console = self.addTopWidget( ipythonconsole.IPythonConsoleWidget()) def gotoshell(): mh.changeTask('Utilities', 'Shell') action = gui.Action('ishell', language.getLanguageString('IPython shell'), gotoshell) G.app.mainwin.addAction(action) mh.setShortcut(mh.Modifiers.CTRL, mh.Keys.i, action) return # Fall back to old console self.console = None self.main = self.addTopWidget(QtWidgets.QWidget()) self.layout = QtWidgets.QGridLayout(self.main) self.layout.setRowStretch(0, 0) self.layout.setRowStretch(1, 0) self.layout.setColumnStretch(0, 1) self.layout.setColumnStretch(1, 0) self.text = gui.DocumentEdit() self.text.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.layout.addWidget(self.text, 0, 0, 1, 2) self.line = ShellTextEdit() self.line.setFocusPolicy(QtCore.Qt.StrongFocus) self.layout.addWidget(self.line, 1, 0, 1, 1) self.globals = {'G': G} self.clear = gui.Button("Clear") self.layout.addWidget(self.clear, 1, 1, 1, 1) action = gui.Action('shell', language.getLanguageString('Default shell'), self.gotodefaultshell) G.app.mainwin.addAction(action) mh.setShortcut(mh.Modifiers.SHIFT, mh.Keys.s, action) @self.line.mhEvent def onActivate(text): self.execute(text) self.history.append(text) self.histitem = None self.line.setText('') @self.line.mhEvent def onTabPressed(edit): def _longest_common_substring(s1, s2): """ This is simply the O(n) left-aligned version """ limit = min(len(s1), len(s2)) i = 0 while i < limit and s1[i] == s2[i]: i += 1 return s1[:i] def _largest_common(strings): strings = list(strings) try: strings.remove('...') except: pass if len(strings) == 0: return "" elif len(strings) == 1: return strings[0] else: result = strings[0] for s in strings[1:]: result = _longest_common_substring(result, s) return result line = edit.getText() suggestions = self.getSuggestions(line) if len(suggestions) == 0: return if len(suggestions) > 1: self.write('\n'.join(suggestions) + "\n") scrollbar = self.text.verticalScrollBar() scrollbar.setSliderPosition(scrollbar.maximum()) edit.setText(_largest_common(suggestions)) elif len(suggestions) == 1: edit.setText(suggestions[0]) @self.clear.mhEvent def onClicked(event): self.clearText() @self.line.mhEvent def onUpArrow(_dummy): self.upArrow() @self.line.mhEvent def onDownArrow(_dummy): self.downArrow()
def __init__(self, category): super(ShellTaskView, self).__init__(category, 'Shell') self.globals = {'G': G} self.history = [] self.histitem = None self.main = self.addTopWidget(QtGui.QWidget()) self.layout = QtGui.QGridLayout(self.main) self.layout.setRowStretch(0, 0) self.layout.setRowStretch(1, 0) self.layout.setColumnStretch(0, 1) self.layout.setColumnStretch(1, 0) self.text = gui.DocumentEdit() self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.layout.addWidget(self.text, 0, 0, 1, 2) self.line = ShellTextEdit() self.line.setFocusPolicy(QtCore.Qt.StrongFocus) self.layout.addWidget(self.line, 1, 0, 1, 1) self.globals = {'G': G} self.clear = gui.Button("Clear") self.layout.addWidget(self.clear, 1, 1, 1, 1) @self.line.mhEvent def onActivate(text): self.execute(text) self.history.append(text) self.histitem = None self.line.setText('') @self.line.mhEvent def onTabPressed(edit): def _longest_common_substring(s1, s2): """ This is simply the O(n) left-aligned version """ limit = min(len(s1), len(s2)) i = 0 while i < limit and s1[i] == s2[i]: i += 1 return s1[:i] def _largest_common(strings): strings = list(strings) try: strings.remove('...') except: pass if len(strings) == 0: return "" elif len(strings) == 1: return strings[0] else: result = strings[0] for s in strings[1:]: result = _longest_common_substring(result, s) return result line = edit.getText() suggestions = self.getSuggestions(line) if len(suggestions) == 0: return if len(suggestions) > 1: self.write('\n'.join(suggestions) + "\n") scrollbar = self.text.verticalScrollBar() scrollbar.setSliderPosition(scrollbar.maximum()) edit.setText(_largest_common(suggestions)) elif len(suggestions) == 1: edit.setText(suggestions[0]) @self.clear.mhEvent def onClicked(event): self.clearText() @self.line.mhEvent def onUpArrow(_dummy): self.upArrow() @self.line.mhEvent def onDownArrow(_dummy): self.downArrow()
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Scripting') self.directory = os.getcwd() self.filename = None box = self.addLeftWidget(gui.GroupBox('Script')) self.scriptText = self.addTopWidget(gui.DocumentEdit()) self.scriptText.setText('') self.scriptText.setLineWrapMode(gui.DocumentEdit.NoWrap) self.loadButton = box.addWidget(gui.Button('Load ...'), 0, 0) self.saveButton = box.addWidget(gui.Button('Save ...'), 0, 1) @self.loadButton.mhEvent def onClicked(event): filename = mh.getOpenFileName( self.directory, 'Python scripts (*.py);;All files (*.*)') if (os.path.exists(filename)): contents = open(filename, 'r').read() self.scriptText.setText(contents) dlg = gui.Dialog() dlg.prompt("Load script", "File was loaded in an acceptable manner", "OK") self.filename = filename self.directory = os.path.split(filename)[0] else: dlg = gui.Dialog() dlg.prompt("Load script", "File " + filename + " does not seem to exist", "OK") @self.saveButton.mhEvent def onClicked(event): filename = mh.getSaveFileName( self.filename or self.directory, 'Python scripts (*.py);;All files (*.*)') with open(filename, "w") as f: f.write(self.scriptText.getText()) dlg = gui.Dialog() dlg.prompt("Save script", "File was written in an acceptable manner", "OK") self.filename = filename self.directory = os.path.split(filename)[0] box2 = self.addLeftWidget(gui.GroupBox('Examples')) self.insertLabel = box2.addWidget( gui.TextView('Append example to script')) self.listView = box2.addWidget(gui.ListView()) self.listView.setSizePolicy(gui.SizePolicy.Ignored, gui.SizePolicy.Preferred) testlist = [ 'applyTarget()', 'incrementingFilename()', 'getPositionX()', 'getPositionY()', 'getPositionZ()', 'getRotationX()', 'getRotationY()', 'getRotationZ()', 'getZoom()', 'loadModel()', 'modifyPositionX()', 'modifyPositionY()', 'modifyPositionZ()', 'modifyRotationX()', 'modifyRotationY()', 'modifyRotationZ()', 'modifyZoom()', 'printCameraInfo()', 'printDetailStack()', 'printPositionInfo()', 'printRotationInfo()', 'saveModel()', 'screenShot()', 'setAge()', 'setPositionX()', 'setPositionY()', 'setPositionZ()', 'setRotationX()', 'setRotationY()', 'setRotationZ()', 'setZoom()', 'setWeight()' ] self.listView.setData(testlist) self.insertButton = box2.addWidget(gui.Button('Append')) @self.insertButton.mhEvent def onClicked(event): item = self.listView.getSelectedItem() if (item == 'applyTarget()'): text = "# applyTarget(<target file name>, <power (from 0.0 to 1.0)>)\n" text = text + "#\n" text = text + "# This will apply the target on the model. If the target was already applied, the power will be updated\n" text = text + "# Note that targets are relative to the data/targets directory, and should not include the .target\n" text = text + "# extension, so a valid target name would be, for example, \"breast/breast-dist-max\"\n\n" text = text + "MHScript.applyTarget('aTargetName',1.0)\n\n" self.scriptText.addText(text) if (item == 'loadModel()'): text = "# loadModel(<model name>,[path])\n" text = text + "#\n" text = text + "# This will load a human model from an MHM file. The <model name> part should be a string without spaces\n" text = text + "# and without the .MHM extension. The [path] part defaults to the user's makehuman/models directory.\n\n" text = text + "MHScript.loadModel('myTestModel')\n\n" self.scriptText.addText(text) if (item == 'incrementingFilename()'): text = "# incrementingFilename(<file name base>, [file extension], [pad length])\n" text = text + "#\n" text = text + "# This will return a file name containing a numerical component which increases by one for each call.\n" text = text + "# The default file extension is \".png\". The default pad length is 4. For example, the following lines:\n" text = text + "#\n" text = text + "# print incrementingFilename(\"test\",\".target\",3) + \"\\n\"\n" text = text + "# print incrementingFilename(\"test\",\".target\",3) + \"\\n\"\n" text = text + "#\n" text = text + "# Will print:\n" text = text + "#\n" text = text + "# test001.target\n" text = text + "# test002.target\n" text = text + "#\n" text = text + "# The counter is reset each time the script is executed\n\n" text = text + "filename = MHScript.incrementingFilename('test')\n\n" self.scriptText.addText(text) if (item == 'printCameraInfo()'): text = "# printCameraInfo()\n" text = text + "#\n" text = text + "# This will print info about how the camera is targeted and focused .\n\n" text = text + "MHScript.printCameraInfo()\n\n" self.scriptText.addText(text) if (item == 'printDetailStack()'): text = "# printDetailStack()\n" text = text + "#\n" text = text + "# This will print a list of all applied targets (and their weights) to standard output.\n\n" text = text + "MHScript.printDetailStack()\n\n" self.scriptText.addText(text) if (item == 'printPositionInfo()'): text = "# printPositionInfo()\n" text = text + "#\n" text = text + "# This will print info about where the human object is currently located.\n\n" text = text + "MHScript.printPositionInfo()\n\n" self.scriptText.addText(text) if (item == 'printRotationInfo()'): text = "# printRotationInfo()\n" text = text + "#\n" text = text + "# This will print info about how the human object is currently rotated.\n\n" text = text + "MHScript.printRotationInfo()\n\n" self.scriptText.addText(text) if (item == 'saveModel()'): text = "# saveModel(<model name>,[path])\n" text = text + "#\n" text = text + "# This will save the human model to an MHM file. The <model name> part should be a string without spaces\n" text = text + "# and without the .MHM extension. The [path] part defaults to the user's makehuman/models directory.\n" text = text + "# Note that this will not save any thumbnail.\n\n" text = text + "MHScript.saveModel('myTestModel')\n\n" self.scriptText.addText(text) if (item == 'screenShot()'): text = "# screenShot(<png file name>)\n" text = text + "#\n" text = text + "# This will save a png file of how the model currently looks.\n\n" text = text + "MHScript.screenShot('screenshot.png')\n\n" self.scriptText.addText(text) if (item == 'setAge()'): text = "# setAge(age)\n" text = text + "#\n" text = text + "# Sets the age of the model. The age parameter is a float between 0 and 1, where 0 is 12 years old and 1 is 70.\n\n" text = text + "MHScript.setAge(0.5)\n\n" self.scriptText.addText(text) if (item == 'setWeight()'): text = "# setWeight(weight)\n" text = text + "#\n" text = text + "# Sets the weight of the model. The weight parameter is a float between 0 and 1, where 0 is starved and\n" text = text + "# 1 is severely overweight\n\n" text = text + "MHScript.setWeight(0.5)\n\n" self.scriptText.addText(text) if (item == 'setPositionX()'): text = "# setPositionX(xpos)\n" text = text + "#\n" text = text + "# Sets the X position of the model of the model in 3d space, where 0.0 is centered.\n\n" text = text + "MHScript.setPositionX(2.0)\n\n" self.scriptText.addText(text) if (item == 'getPositionX()'): text = "# getPositionX()\n" text = text + "#\n" text = text + "# Returns the current X position of the model of the model in 3d space.\n\n" text = text + "MHScript.getPositionX()\n\n" self.scriptText.addText(text) if (item == 'modifyPositionX()'): text = "# modifyPositionX(xmod)\n" text = text + "#\n" text = text + "# Modifies X position of the model of the model in 3d space.\n\n" text = text + "MHScript.modifyPositionX(-0.1)\n\n" self.scriptText.addText(text) if (item == 'setPositionZ()'): text = "# setPositionZ(zpos)\n" text = text + "#\n" text = text + "# Sets the Z position of the model of the model in 3d space, where 0.0 is centered.\n\n" text = text + "MHScript.setPositionZ(2.0)\n\n" self.scriptText.addText(text) if (item == 'getPositionZ()'): text = "# getPositionZ()\n" text = text + "#\n" text = text + "# Returns the current Z position of the model of the model in 3d space.\n\n" text = text + "MHScript.getPositionZ()\n\n" self.scriptText.addText(text) if (item == 'modifyPositionZ()'): text = "# modifyPositionZ(zmod)\n" text = text + "#\n" text = text + "# Modifies Z position of the model of the model in 3d space.\n\n" text = text + "MHScript.modifyPositionZ(-0.1)\n\n" self.scriptText.addText(text) if (item == 'setPositionY()'): text = "# setPositionY(ypos)\n" text = text + "#\n" text = text + "# Sets the Y position of the model of the model in 3d space, where 0.0 is centered.\n" text = text + "# Note that the depth of the scene is clipped, so if you move the model too far back\n" text = text + "# it will disappear. You will most likely want to use zoom instead of Y position.\n\n" text = text + "MHScript.setPositionY(2.0)\n\n" self.scriptText.addText(text) if (item == 'getPositionY()'): text = "# getPositionY()\n" text = text + "#\n" text = text + "# Returns the current Y position of the model of the model in 3d space.\n\n" text = text + "MHScript.getPositionY()\n\n" self.scriptText.addText(text) if (item == 'modifyPositionY()'): text = "# modifyPositionY(ymod)\n" text = text + "#\n" text = text + "# Modifies Y position of the model of the model in 3d space.\n" text = text + "# Note that the depth of the scene is clipped, so if you move the model too far back\n" text = text + "# it will disappear. You will most likely want to use zoom instead of Y position.\n\n" text = text + "MHScript.modifyPositionY(-0.1)\n\n" self.scriptText.addText(text) if (item == 'setRotationX()'): text = "# setRotationX(xrot)\n" text = text + "#\n" text = text + "# Sets the rotation around the X axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.setRotationX(90.0)\n\n" self.scriptText.addText(text) if (item == 'getRotationX()'): text = "# getRotationX()\n" text = text + "#\n" text = text + "# Returns the current rotatation around the X axis of the model.\n\n" text = text + "MHScript.getRotationX()\n\n" self.scriptText.addText(text) if (item == 'modifyRotationX()'): text = "# modifyRotationX(xmod)\n" text = text + "#\n" text = text + "# Modifies the rotation around the X axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.modifyRotationX(-5.0)\n\n" self.scriptText.addText(text) if (item == 'setRotationZ()'): text = "# setRotationZ(zrot)\n" text = text + "#\n" text = text + "# Sets the rotation around the Z axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.setRotationZ(90.0)\n\n" self.scriptText.addText(text) if (item == 'getRotationZ()'): text = "# getRotationZ()\n" text = text + "#\n" text = text + "# Returns the current rotatation around the Z axis of the model.\n\n" text = text + "MHScript.getRotationZ()\n\n" self.scriptText.addText(text) if (item == 'modifyRotationZ()'): text = "# modifyRotationZ(zmod)\n" text = text + "#\n" text = text + "# Modifies the rotation around the Z axis for the model, where 0.0 is frontal projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.modifyRotationZ(-5.0)\n\n" self.scriptText.addText(text) if (item == 'setRotationY()'): text = "# setRotationY(yrot)\n" text = text + "#\n" text = text + "# Sets the rotation around the Y axis for the model, where 0.0 is upright projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.setRotationY(90.0)\n\n" self.scriptText.addText(text) if (item == 'getRotationY()'): text = "# getRotationY()\n" text = text + "#\n" text = text + "# Returns the current rotatation around the Y axis of the model.\n\n" text = text + "MHScript.getRotationY()\n\n" self.scriptText.addText(text) if (item == 'modifyRotationY()'): text = "# modifyRotationY(ymod)\n" text = text + "#\n" text = text + "# Modifies the rotation around the Y axis for the model, where 0.0 is upright projection.\n" text = text + "# Rotation is set in degrees from -180.0 to +180.0 (these two extremes are equal)\n\n" text = text + "MHScript.modifyRotationY(-5.0)\n\n" self.scriptText.addText(text) if (item == 'setZoom()'): text = "# setZoom(zoom)\n" text = text + "#\n" text = text + "# Sets current camera zoom. In practise this moves the camera closer or further from the.\n" text = text + "# the model. The zoom factor is reversed ans goes from 100.0 which is far away from the\n" text = text + "# the model as possible (if you move further away, the model will be clipped and disappear)\n" text = text + "# and 0.0 is inside the model. A zoom factor of 10.0 is what is used for the face\n" text = text + "# projection, and is in most cases as zoomed in as is functional.\n\n" text = text + "MHScript.setZoom(70.0)\n\n" self.scriptText.addText(text) if (item == 'modifyZoom()'): text = "# modifyZoom(zmod)\n" text = text + "#\n" text = text + "# Modifies current camera zoom. In practise this moves the camera closer or further from the.\n" text = text + "# the model. The zoom factor is reversed ans goes from 100.0 which is far away from the\n" text = text + "# the model as possible (if you move further away, the model will be clipped and disappear)\n" text = text + "# and 0.0 is inside the model. A zoom factor of 10.0 is what is used for the face\n" text = text + "# projection, and is in most cases as zoomed in as is functional.\n\n" text = text + "MHScript.modifyZoom(1.0)\n\n" self.scriptText.addText(text) if (item == 'getZoom()'): text = "# getZoom()\n" text = text + "#\n" text = text + "# Returns the current camera zoom factor.\n\n" text = text + "MHScript.getZoom()\n\n" self.scriptText.addText(text)
def __init__(self, category, socketConfig=None): self.human = gui3d.app.selectedHuman gui3d.TaskView.__init__(self, category, 'Socket') self.socketConfig = {'acceptConnections': False, 'advanced': False, 'host': '127.0.0.1', 'port': 12345 } if socketConfig and isinstance(socketConfig, dict): self.socketConfig['acceptConnections'] = socketConfig.get('acceptConnections', False) self.socketConfig['advanced'] = socketConfig.get('advanced', False) self.socketConfig['host'] = socketConfig.get('host', '127.0.0.1') self.socketConfig['port'] = socketConfig.get('port', 12345) self.workerthread = None self.log = mhapi.utility.getLogChannel("socket") box = self.addLeftWidget(gui.GroupBox('Server')) self.accToggleButton = box.addWidget(gui.CheckBox('Accept connections')) box.addWidget(gui.QtWidgets.QLabel('')) self.advToggleButton = box.addWidget(gui.CheckBox('Advanced Setings')) self.hostLabel = box.addWidget(gui.QtWidgets.QLabel('\nHost [Default=127.0.0.1] :')) self.hostEdit = box.addWidget(gui.TextEdit(str(self.socketConfig.get('host')))) self.portLabel = box.addWidget(gui.QtWidgets.QLabel('\nPort [Default=12345] :')) self.portEdit = box.addWidget(gui.TextEdit(str(self.socketConfig.get('port')))) self.spacer = box.addWidget(gui.QtWidgets.QLabel('')) self.changeAddrButton = box.addWidget(gui.Button('Change Host + Port')) self.hostEdit.textChanged.connect(self.onHostChanged) self.portEdit.textChanged.connect(self.onPortChanged) @self.accToggleButton.mhEvent def onClicked(event): if isPy3: if self.accToggleButton.selected: self.socketConfig['acceptConnections'] = True self.openSocket() else: self.socketConfig['acceptConnections'] = False self.closeSocket() @self.advToggleButton.mhEvent def onClicked(event): self.enableAdvanced(self.advToggleButton.selected) self.socketConfig['advanced'] = self.advToggleButton.selected @self.changeAddrButton.mhEvent def onClicked(event): if isPy3: gui3d.app.prompt('Attention', 'The host and port must be changed in Blender, too', 'OK', helpId='socketInfo') self.accToggleButton.setChecked(True) self.closeSocket() self.openSocket() self.scriptText = self.addTopWidget(gui.DocumentEdit()) if isPy3: self.scriptText.setText('') else: self.scriptText.setText('This version of the socket plugin requires the py3 version of MH from github.') self.scriptText.setLineWrapMode(gui.DocumentEdit.NoWrap) if isPy3: self.dirops = SocketDirOps(self) self.meshops = SocketMeshOps(self) self.modops = SocketModifierOps(self) if self.socketConfig.get('acceptConnections'): self.accToggleButton.setChecked(True) self.openSocket() self.enableAdvanced(self.socketConfig.get('advanced', False)) self.advToggleButton.setChecked(self.socketConfig.get('advanced', False))
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Scripting') self.directory = os.getcwd() self.filename = None box = self.addLeftWidget(gui.GroupBox('Script')) self.scriptText = self.addTopWidget(gui.DocumentEdit()) self.scriptText.setText(''); self.scriptText.setLineWrapMode(gui.DocumentEdit.NoWrap) self.loadButton = box.addWidget(gui.Button('Load ...'), 0, 0) self.saveButton = box.addWidget(gui.Button('Save ...'), 0, 1) @self.loadButton.mhEvent def onClicked(event): filename = mh.getOpenFileName(self.directory, 'Python scripts (*.py);;All files (*.*)') if(os.path.exists(filename)): contents = open(filename, 'r').read() self.scriptText.setText(contents) dlg = gui.Dialog() dlg.prompt("Load script","File was loaded in an acceptable manner","OK") self.filename = filename self.directory = os.path.split(filename)[0] else: dlg = gui.Dialog() dlg.prompt("Load script","File " + filename + " does not seem to exist","OK") @self.saveButton.mhEvent def onClicked(event): filename = mh.getSaveFileName(self.filename or self.directory, 'Python scripts (*.py);;All files (*.*)') with open(filename, "w") as f: f.write(self.scriptText.getText()) dlg = gui.Dialog() dlg.prompt("Save script","File was written in an acceptable manner","OK") self.filename = filename self.directory = os.path.split(filename)[0] box2 = self.addLeftWidget(gui.GroupBox('Examples')) self.insertLabel = box2.addWidget(gui.TextView('Append example to script')) self.listView = box2.addWidget(gui.ListView()) self.listView.setSizePolicy(gui.SizePolicy.Ignored, gui.SizePolicy.Preferred) testlist = [ 'applyTarget()', 'incrementingFilename()', 'loadModel()', 'saveModel()', 'screenShot()', 'setAge()', 'printDetailStack()', 'setWeight()' ] self.listView.setData(testlist) self.insertButton = box2.addWidget(gui.Button('Append')) @self.insertButton.mhEvent def onClicked(event): item = self.listView.getSelectedItem() if(item == 'applyTarget()'): text = "# applyTarget(<target file name>, <power (from 0.0 to 1.0)>)\n" text = text + "#\n" text = text + "# This will apply the target on the model. If the target was already applied, the power will be updated\n" text = text + "# Note that targets are relative to the data/targets directory, and should not include the .target\n" text = text + "# extension, so a valid target name would be, for example, \"breast/breast-dist-max\"\n\n" text = text + "MHScript.applyTarget('aTargetName',1.0)\n\n" self.scriptText.addText(text) if(item == 'loadModel()'): text = "# loadModel(<model name>,[path])\n" text = text + "#\n" text = text + "# This will load a human model from an MHM file. The <model name> part should be a string without spaces\n" text = text + "# and without the .MHM extension. The [path] part defaults to the user's makehuman/models directory.\n\n" text = text + "MHScript.loadModel('myTestModel')\n\n" self.scriptText.addText(text) if(item == 'incrementingFilename()'): text = "# incrementingFilename(<file name base>, [file extension], [pad length])\n" text = text + "#\n" text = text + "# This will return a file name containing a numerical component which increases by one for each call.\n" text = text + "# The default file extension is \".png\". The default pad length is 4. For example, the following lines:\n"; text = text + "#\n" text = text + "# print incrementingFilename(\"test\",\".target\",3) + \"\\n\"\n" text = text + "# print incrementingFilename(\"test\",\".target\",3) + \"\\n\"\n" text = text + "#\n" text = text + "# Will print:\n" text = text + "#\n" text = text + "# test001.target\n" text = text + "# test002.target\n" text = text + "#\n" text = text + "# The counter is reset each time the script is executed\n\n" text = text + "filename = MHScript.incrementingFilename('test')\n\n" self.scriptText.addText(text) if(item == 'printDetailStack()'): text = "# printDetailStack()\n" text = text + "#\n" text = text + "# This will print a list of all applied targets (and their weights) to standard output.\n\n" text = text + "MHScript.printDetailStack()\n\n" self.scriptText.addText(text) if(item == 'saveModel()'): text = "# saveModel(<model name>,[path])\n" text = text + "#\n" text = text + "# This will save the human model to an MHM file. The <model name> part should be a string without spaces\n" text = text + "# and without the .MHM extension. The [path] part defaults to the user's makehuman/models directory.\n" text = text + "# Note that this will not save any thumbnail.\n\n" text = text + "MHScript.saveModel('myTestModel')\n\n" self.scriptText.addText(text) if(item == 'screenShot()'): text = "# screenShot(<png file name>)\n" text = text + "#\n" text = text + "# This will save a png file of how the model currently looks.\n\n" text = text + "MHScript.screenShot('screenshot.png')\n\n" self.scriptText.addText(text) if(item == 'setAge()'): text = "# setAge(age)\n" text = text + "#\n" text = text + "# Sets the age of the model. The age parameter is a float between 0 and 1, where 0 is 12 years old and 1 is 70.\n\n" text = text + "MHScript.setAge(0.5)\n\n" self.scriptText.addText(text) if(item == 'setWeight()'): text = "# setWeight(weight)\n" text = text + "#\n" text = text + "# Sets the weight of the model. The weight parameter is a float between 0 and 1, where 0 is starved and\n" text = text + "# 1 is severely overweight\n\n" text = text + "MHScript.setWeight(0.5)\n\n" self.scriptText.addText(text)