Ejemplo n.º 1
0
def get_string_input(message, title='Rename', old_name=None):
    """
    Shows a Input dialog to allow the user to input a new string
    :param message: str, mesage to show in the dialog
    :param title: str, title of the input dialog
    :param old_name: str (optional): old name where are trying to rename
    :return: str, new name
    """

    dialog = QInputDialog()
    flags = dialog.windowFlags(
    ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint

    if not old_name:
        comment, ok = dialog.getText(None, title, message, flags=flags)
    else:
        comment, ok = dialog.getText(None,
                                     title,
                                     message,
                                     text=old_name,
                                     flags=flags)

    comment = comment.replace('\\', '_')

    if ok:
        return str(comment)
Ejemplo n.º 2
0
def get_comment(text_message='Add Comment',
                title='Save',
                comment_text='',
                parent=None):
    """
    Shows a comment dialog to allow user to input a new comment
    :param parent: QwWidget
    :param text_message: str, text to show before message input
    :param title: str, title of message dialog
    :param comment_text: str, default text for the commment
    :return: str, input comment write by the user
    """

    comment_dialog = QInputDialog()
    flags = comment_dialog.windowFlags(
    ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint
    if is_pyside2() or is_pyqt5():
        comment, ok = comment_dialog.getMultiLineText(parent,
                                                      title,
                                                      text_message,
                                                      flags=flags,
                                                      text=comment_text)
    else:
        comment, ok = comment_dialog.getText(parent,
                                             title,
                                             text_message,
                                             flags=flags,
                                             text=comment_text)
    if ok:
        return comment
    def onExportToPackage(self):
        # check if category is not empty
        if self._rawNode._rawGraph.category == '':
            QMessageBox.information(
                None, "Warning",
                "Category is not set! Please step into compound and type category name."
            )
            return

        packageNames = list(GET_PACKAGES().keys())
        selectedPackageName, accepted = QInputDialog.getItem(None,
                                                             "Select",
                                                             "Select package",
                                                             packageNames,
                                                             editable=False)
        if accepted:
            packagePath = GET_PACKAGE_PATH(selectedPackageName)
            compoundsDir = os.path.join(packagePath, "Compounds")
            if not os.path.isdir(compoundsDir):
                os.mkdir(compoundsDir)
            self.onExport(root=compoundsDir)
            # refresh node box
            app = self.canvasRef().getApp()
            nodeBoxes = app.getRegisteredTools(
                classNameFilters=["NodeBoxTool"])
            for nodeBox in nodeBoxes:
                nodeBox.refresh()
Ejemplo n.º 4
0
def mulcon(data):
    """Multiply by a constant, taken from user input"""
    parent = QDialog()
    constant, ok = QInputDialog.getDouble(parent, "X*C", "Input constant:")
    if not ok:
        raise RuntimeError("User cancelled input")
    return data * constant
Ejemplo n.º 5
0
def subcon(data):
    """Subtract a constant, taken from user input"""
    parent = QDialog()
    constant, ok = QInputDialog.getDouble(parent, "X-C", "Input constant:")
    if not ok:
        raise RuntimeError("User cancelled input")
    return data - constant
Ejemplo n.º 6
0
def addcon(data):
    """Add a constant, taken from user input"""
    parent = QDialog()
    constant, ok = QInputDialog.getDouble(parent, "X+C", "Input constant:")
    if not ok:
        raise RuntimeError("User cancelled input")
    return data + constant
Ejemplo n.º 7
0
def divcon(data):
    """Divide by a constant, taken from user input"""
    parent = QDialog()
    constant, ok = QInputDialog.getDouble(parent, "X/C", "Input constant:")
    if not ok:
        raise RuntimeError("User cancelled input")
    return data / constant
Ejemplo n.º 8
0
 def rename(self):
     name, confirmed = QInputDialog.getText(None, "Rename",
                                            "Enter new pin name")
     if confirmed and name != self.name and name != "":
         self.displayName = self.canvasRef().getUniqNodeDisplayName(name)
         self.update()
     self.setFocus()
Ejemplo n.º 9
0
 def selectStructure(self):
     item, ok = QInputDialog.getItem(None, "", "",
                                     ([i.name
                                       for i in list(StructureType)]), 0,
                                     False)
     if ok and item:
         self._rawPin.changeStructure(StructureType[item], True)
Ejemplo n.º 10
0
	def addGroup(self):
		groupName, rtn = QInputDialog.getText(self, "Group Name", "", text="GroupName")
		if not rtn or not groupName:
			return

		self.uiGroupsLIST.addItem(groupName)
		self._guide.addGroup(groupName)
		self.commit()
Ejemplo n.º 11
0
def inputname():
    parent = QDialog()
    title = "Change Name"
    label = "Enter new name:"
    dialog = QInputDialog.getText(parent, title, label)
    if dialog[1]:
        name = dialog[0]
    return name
Ejemplo n.º 12
0
def getUnitFactor():
    parent = QDialog()
    title = "Change Units"
    label = "Enter conversion factor:"
    factor, ok = QInputDialog.getDouble(parent, title, label)
    if not ok:
        raise RuntimeError("User cancelled input")
    return factor
Ejemplo n.º 13
0
def inputname():
    parent = QDialog()
    title = "Change Name"
    label = "Enter new name:"
    dialog = QInputDialog.getText(parent, title, label)
    if dialog[1]:
        name = dialog[0]
    return name
Ejemplo n.º 14
0
def getUnitFactor():
    parent = QDialog()
    title = "Change Units"
    label = "Enter conversion factor:"
    dialog = QInputDialog.getDouble(parent, title, label)
    if dialog[1]:
        return dialog[0]
    else:
        return None
Ejemplo n.º 15
0
 def onRename(self):
     name, confirmed = QInputDialog.getText(None, "Rename",
                                            "Enter new pin name")
     if confirmed and name != self.name and name != "":
         uniqueName = self._rawPin.owningNode().getUniqPinName(name)
         self.setName(uniqueName)
         self.setDisplayName(uniqueName)
         self.owningNode().invalidateNodeLayouts()
         self.owningNode().updateNodeShape()
Ejemplo n.º 16
0
 def generateShapeIncrementals(self):
     sel = cmds.ls(sl=True)[0]
     if len(sel) >= 2:
         # TODO, build a UI for this
         increments = QInputDialog.getInt(self.window, "Increments",
                                          "Number of Increments", 4, 1, 100)
         if increments is None:
             return
         generateShapeIncrementals(sel[0], sel[1], increments)
Ejemplo n.º 17
0
def addcon(data):
    result = XPadDataItem(data)
    parent = QDialog()
    dialog = QInputDialog.getDouble(parent, "X+C", "Input constant:")
    if dialog[1]:
        constant = dialog[0]
    result.data = np.add(data.data, constant)
    result.name = "(" + data.name + ")+" + str(constant)
    result.label = "(" + data.label + ")+" + str(constant)
    return result
Ejemplo n.º 18
0
def subcon(data):
    result = XPadDataItem(data)
    parent = QDialog()
    dialog = QInputDialog.getDouble(parent, "X-C", "Input constant:")
    if dialog[1]:
        constant = dialog[0]
    constant = 1.
    result.data = np.subtract(data.data, constant)
    result.name = "(" + data.name + ")-" + str(constant)
    result.label = "(" + data.label + ")-" + str(constant)
    return result
Ejemplo n.º 19
0
def powcon(data):
    result = XPadDataItem(data)
    parent = QDialog()
    dialog = QInputDialog.getDouble(parent, "X^C", "Input constant:")
    if dialog[1]:
        constant = dialog[0]
    result.data = np.power(data.data, constant)
    result.name = "(" + data.name + ")^" + str(constant)
    result.label = "(" + data.label + ")^" + str(constant)
    result.units = "(" + data.units + ")^" + str(constant)
    return result
Ejemplo n.º 20
0
def timeOffset(data):
    result = XPadDataItem(data)
    parent = QDialog()
    offset, ok = QInputDialog.getDouble(parent, "Time Offset",
                                        "Input time offest:")
    if not ok:
        raise RuntimeError("User cancelled input")
    result.dim[data.order].data = np.add(result.dim[data.order].data, offset)
    result.name = f"Timoff({result.name}, {offset})"
    result.label = f"Timoff({result.label}, {offset})"
    return result
Ejemplo n.º 21
0
	def renameGroup(self):
		groupItem = self.uiGroupsLIST.currentItem()
		groupName = groupItem.text()

		newName, rtn = QInputDialog.getText(self, "Group Name", "", text=groupName)
		if not rtn or not newName:
			return

		groupItem.setText(newName)
		self._guide.renameGroup(groupName, newName)
		self.commit()
Ejemplo n.º 22
0
def timeOffset(data):
    result = XPadDataItem(data)
    parent = QDialog()
    title = "Time Offset"
    label = "Input time offest:"
    dialog = QInputDialog.getDouble(parent, title, label)
    if dialog[1]:
        offset = dialog[0]
        result.dim[data.order].data = np.add(result.dim[data.order].data, offset)
        result.name = "Timoff(" + result.name + ", " + str(offset) + ")"
        result.label = "Timoff(" + result.label + ", " + str(offset) + ")"
        return result
Ejemplo n.º 23
0
def powcon(data):
    """Exponentiate by a constant, taken from user input"""
    result = XPadDataItem(data)
    parent = QDialog()
    constant, ok = QInputDialog.getDouble(parent, "X^C", "Input constant:")
    if not ok:
        raise RuntimeError("User cancelled input")
    result.data = np.power(data.data, constant)
    result.name = f"({data.name})^{constant}"
    result.label = f"({data.label})^{constant}"
    result.units = f"({data.units})^{constant}"
    return result
Ejemplo n.º 24
0
def changeunits(data):
    result = XPadDataItem(data)
    parent = QDialog()
    title = "Change Units"
    label = "Enter new units:"
    dialog = QInputDialog.getText(parent, title, label)
    if dialog[1]:
        newUnit = dialog[0]
        unitFact = getUnitFactor()
    if unitFact and newUnit:
        result.data = np.multiply(data.data, unitFact)
        result.units = newUnit
        return result
Ejemplo n.º 25
0
def changeunits(data):
    result = XPadDataItem(data)
    parent = QDialog()
    title = "Change Units"
    label = "Enter new units:"
    new_unit, ok = QInputDialog.getText(parent, title, label)
    if not ok:
        raise RuntimeError("User cancelled input")
    unit_factor = getUnitFactor()
    if unit_factor and new_unit:
        result.data = np.multiply(data.data, unit_factor)
        result.units = new_unit
        return result
Ejemplo n.º 26
0
 def onExportToPackage(self):
     packageNames = list(GET_PACKAGES().keys())
     selectedPackageName, accepted = QInputDialog.getItem(None, "Select", "Select package", packageNames, editable=False)
     if accepted:
         packagePath = GET_PACKAGE_PATH(selectedPackageName)
         pyNodesDir = os.path.join(packagePath, "PyNodes")
         if not os.path.isdir(pyNodesDir):
             os.mkdir(pyNodesDir)
         self.onExport(root=pyNodesDir)
         # refresh node boxes
         app = self.canvasRef().getApp()
         nodeBoxes = app.getRegisteredTools(classNameFilters=["NodeBoxTool"])
         for nodeBox in nodeBoxes:
             nodeBox.refresh()
Ejemplo n.º 27
0
 def onKillClicked(self):
     # check refs and ask user what to do
     refs = self._rawVariable.findRefs()
     if len(refs) > 0:
         item, accepted = QInputDialog.getItem(None, 'Decide!', 'What to do with getters and setters in canvas?', ['kill', 'leave'], editable=False)
         if accepted:
             self.variablesWidget.killVar(self)
             if item == 'kill':
                 for i in refs:
                     i.kill()
             elif item == 'leave':
                 for i in refs:
                     i.var = None
     else:
         self.variablesWidget.killVar(self)
Ejemplo n.º 28
0
 def create_new_directory(self):
     name, ok = QInputDialog.getText(self, 'New directory name', 'Name:',
                                     QLineEdit.Normal, 'New Directory')
     if ok and name:
         path = os.path.join(self.directory, name)
         if os.path.exists(path):
             msg_box = QMessageBox(self)
             msg_box.setWindowTitle('Error')
             msg_box.setText('Directory already exists')
             msg_box.exec_()
         else:
             try:
                 os.makedirs(path)
                 self.update_view()
             except os.error as e:
                 msg_box = QMessageBox(self)
                 msg_box.setWindowTitle('Error')
                 msg_box.setText('Cannot create directory')
                 msg_box.exec_()
Ejemplo n.º 29
0
 def onKillClicked(self):
     # check refs and ask user what to do
     refs = self._rawVariable.findRefs()
     if len(refs) > 0:
         item, accepted = QInputDialog.getItem(
             None,
             'Decide!',
             'What to do with getters and setters in canvas?',
             ['kill', 'leave'],
             editable=False)
         if accepted:
             if item == 'kill':
                 self.variablesWidget.killVar(self)
             elif item == 'leave':
                 # mark node as invalid
                 # TODO: For future. Like in ue4, if variable is removed, it can be recreated from node (e.g. promote to variable)
                 print('leave')
     else:
         self.variablesWidget.killVar(self)
Ejemplo n.º 30
0
 def OnRename():
     res = QInputDialog.getText(None, 'Rename pin', 'label')
     if res[1]:
         newName = self.getUniqPinName(res[0])
         self._map[newName] = self._map.pop(p.name)
         p.setName(newName)
Ejemplo n.º 31
0
 def rename(self):
     name, confirmed = QInputDialog.getText(None, "Rename",
                                            "Enter new pin name")
     if confirmed and name != self.name and name != "":
         self.update()
Ejemplo n.º 32
0
 def newPlugin(self, pluginType):
     name, result = QInputDialog.getText(self, 'Plugin name',
                                         'Enter plugin name')
     if result:
         _implementPlugin(name, pluginType)