Exemplo n.º 1
0
    def remove_connection(cls):
        app = QtWidgets.QApplication.instance()  # type: QtWidgets.QApplication
        try:
            app.focusChanged.disconnect(cls.on_focus_changed)
        except RuntimeError:
            pass

        Logger.debug("Removed connection")
Exemplo n.º 2
0
    def apply_rules(self):
        Logger.debug("Writing rules dict: {0}".format(self.rules_dict))
        with open(self.USER_RULES, "w") as json_file:
            json.dump(self.rules_dict, json_file, indent=4)

        try:
            syntax.HighlightManager.remove_connection()
            syntax.HighlightManager.create_connection()
        except BaseException:
            Logger.exception("Failed to apply new rules")
Exemplo n.º 3
0
 def create(cls):
     cls.delete_old()
     try:
         pm.menuItem(cls.ITEM_OBJECT,
                     l=cls.ITEM_LABEL,
                     parent=cls.WINDOW_MENU,
                     i="colorProfile.svg",
                     ia="wmNodeEditor",
                     c=settingsDialog.Dialog.display)
         Logger.info("Created menuItem: Windows>ColorOut")
     except Exception:
         Logger.exception("Error when creating menu item")
Exemplo n.º 4
0
    def save_changes(self):
        check_expression = QtCore.QRegExp(self.rule_pattern.text())
        if not check_expression.isValid():
            error_message = QtWidgets.QErrorMessage(self)
            error_message.showMessage("Invalid regular expression: {0}".format(
                self.rule_pattern.text()))
            Logger.error("Invalid regular expression: {0}".format(
                self.rule_pattern.text()))
            return

        new_info_dict = {self.rule_name.text(): self.serialize_info()}
        self.rules_dict.update(new_info_dict)
        self.update_rule_list()
Exemplo n.º 5
0
    def highlightBlock(self, text):
        if not hasattr(self, "rules"):
            # ? Sometimes throws Attribute error
            Logger.debug("No rulese attr found")
            return
        for rule in self.rules:
            pattern = rule.pattern
            index = pattern.indexIn(text)
            while index >= 0:
                matchLen = pattern.matchedLength()
                self.setFormat(index, matchLen, rule.form)
                index = pattern.indexIn(text, index + matchLen)

            self.setCurrentBlockState(0)
Exemplo n.º 6
0
    def set_color(self, color):
        Logger.debug("Set color: {0}".format(color))
        if isinstance(color, list):
            if not color:
                color = [1, 1, 1]
            color = QtGui.QColor.fromRgb(*color)

        color = QtGui.QColor(color)
        if self._color == color:
            return

        self._color = color
        pixmap = QtGui.QPixmap(self.size())
        pixmap.fill(self._color)
        self.setPixmap(pixmap)
        self.color_changed.emit(self._color)
Exemplo n.º 7
0
    def load_rules(cls):
        if not os.path.isfile(cls.USER_RULES):
            shutil.copy2(cls.DEFAULT_RULES, cls.USER_RULES)

        # Import rules
        rules = None
        with open(cls.USER_RULES, "r") as json_file:
            rules = json.load(json_file)
        if not rules:
            Logger.error("User rules are empty, using defaults")
            with open(cls.DEFAULT_RULES, "r") as json_file:
                rules = json.load(json_file)

        rule_objects = []
        for r in rules.keys():
            rule_objects.append(HighlighRule.from_dict(rules[r]))

        return rule_objects
Exemplo n.º 8
0
    def applyHighlight(cls):
        i = 1
        while i:
            try:
                seReporter = cls.get_script_editor_reporter(
                )  # type:QtWidgets.QTextEdit
                # Remove the old syntax and raise exception to get out of the loop
                assert seReporter.findChild(
                    QtGui.QSyntaxHighlighter).deleteLater()
            except TypeError:
                # If no widget found - increment
                i += 1
            except (AttributeError, AssertionError):
                break

        stdOut = StdOutSyntax(seReporter, cls.load_rules())
        Logger.debug("Highlighter applied")
        return stdOut
Exemplo n.º 9
0
def run():
    # Logging
    log_file = os.path.join(pm.moduleInfo(mn="ColorOut", p=1),
                            "ColorOut.log")  # type:str
    Logger.write_to_rotating_file(log_file)
    Logger.info("Logging to file: {0}".format(log_file))

    syntax.HighlightManager.create_connection()
    Logger.info("Applied stdout highlighting")
    menuItem.ColorOutItem.save_add_scriptJob()
Exemplo n.º 10
0
 def save_add_scriptJob(cls):
     create_script = "from ColorOut import menuItem\nmenuItem.ColorOutItem.create()"
     # ? TODO:Find better event to connect to
     pm.scriptJob(e=["SceneOpened", create_script], ro=1)
     Logger.debug("Safe add scriptJob added")
Exemplo n.º 11
0
from ColorOut.loggingFn import Logger

Logger.info("Test info")
Logger.debug("Test debug")
Logger.error("Test error")
Logger.warning("Test warning")
Logger.critical("Test critical")
Logger.log(5, "Log message")

# try:
#     a = []
#     b = a[0]
# except BaseException:
#     Logger.exception("Exception message")
Exemplo n.º 12
0
import os
import pymel.core as pm
from ColorOut import syntax
from ColorOut import menuItem
from ColorOut.loggingFn import Logger

Logger.set_level(20)


def run():
    # Logging
    log_file = os.path.join(pm.moduleInfo(mn="ColorOut", p=1),
                            "ColorOut.log")  # type:str
    Logger.write_to_rotating_file(log_file)
    Logger.info("Logging to file: {0}".format(log_file))

    syntax.HighlightManager.create_connection()
    Logger.info("Applied stdout highlighting")
    menuItem.ColorOutItem.save_add_scriptJob()