Exemple #1
0
 def CreateLayout(self):
     self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 1, 0)
     self.GroupBorderSpace(4, 4, 4, 4)
     self.GroupBorderNoTitle(c4d.BORDER_ROUND)
     self.AddStaticText(0, 0, name=res.string('ABOUT_LINE1'))
     self.AddStaticText(0, 0, name=res.string('ABOUT_LINE2'))
     self.AddStaticText(0, 0, name=res.string('ABOUT_LINE3'))
     self.GroupEnd()
     return True
Exemple #2
0
 def CreateLayout(self):
     self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 1, 0)
     self.GroupBorderSpace(4, 4, 4, 4)
     self.GroupBorderNoTitle(c4d.BORDER_ROUND)
     self.AddStaticText(0, 0, name=res.string('ABOUT_LINE1'))
     self.AddStaticText(0, 0, name=res.string('ABOUT_LINE2'))
     self.AddStaticText(0, 0, name=res.string('ABOUT_LINE3'))
     self.GroupEnd()
     return True
Exemple #3
0
    def code_submit(self, dialog, code):
        # Create the context in which the script should be
        # executed int.
        doc = c4d.documents.GetActiveDocument()
        scope = {
            '__name__': '__main__',
            'doc': doc,
            'op': doc.GetActiveObject(),
        }

        try:
            exec code in scope
        except Exception as exc:
            self.last_message = str(exc)

            # Print the traceback of the exception (excluding the
            # first level which contains the exec statement from
            # this file.
            tb = sys.exc_info()[2].tb_next
            utils.print_traceback(exc, tb)

            # Move the cursor of the ScriptEditor to the line
            # where the error occured.
            dialog.SetScriptCursor(utils.get_last_traceback().tb_lineno, 0)
            dialog.DisplayTraceback(exc, tb)
        else:
            self.last_message = res.string('IDC_CODE_OK')
Exemple #4
0
    def code_submit(self, dialog, code):
        # Create the context in which the script should be
        # executed int.
        doc = c4d.documents.GetActiveDocument()
        scope = {
            '__name__': '__main__',
            'doc': doc,
            'op': doc.GetActiveObject(),
        }

        try:
            exec code in scope
        except Exception as exc:
            self.last_message = str(exc)

            # Print the traceback of the exception (excluding the
            # first level which contains the exec statement from
            # this file.
            tb = sys.exc_info()[2].tb_next
            utils.print_traceback(exc, tb)

            # Move the cursor of the ScriptEditor to the line
            # where the error occured.
            dialog.SetScriptCursor(utils.get_last_traceback().tb_lineno, 0)
            dialog.DisplayTraceback(exc, tb)
        else:
            self.last_message = res.string('IDC_CODE_OK')
Exemple #5
0
class OpenEditorWindow(c4d.plugins.CommandData):

    PLUGIN_ID = 1038999
    PLUGIN_NAME = res.string('IDS_EDITOR')
    PLUGIN_HELP = res.string('IDS_EDITOR_HELP')
    PLUGIN_INFO = c4d.PLUGINFLAG_HIDEPLUGINMENU
    PLUGIN_ICON = res.bitmap('img', 'editor.png')

    @classmethod
    def Register(cls):
        return c4d.plugins.RegisterCommandPlugin(cls.PLUGIN_ID,
                                                 cls.PLUGIN_NAME,
                                                 cls.PLUGIN_INFO,
                                                 cls.PLUGIN_ICON,
                                                 cls.PLUGIN_HELP, cls())

    # c4d.plugins.CommandData

    def Execute(self, doc):
        return ide.main_window.Open(c4d.DLG_TYPE_ASYNC, self.PLUGIN_ID, 0)

    def RestoreLayout(self, secret):
        return ide.main_window.Restore(self.PLUGIN_ID, secret)
Exemple #6
0
class OpenScriptEditor(c4d.plugins.CommandData):

    PLUGIN_ID = ScriptEditor.GLOBAL_PLUGIN_ID
    PLUGIN_NAME = res.string('IDC_SCRIPT_EDITOR')
    PLUGIN_HELP = res.string('IDC_SCRIPT_EDITOR_HELP')
    PLUGIN_INFO = c4d.PLUGINFLAG_HIDEPLUGINMENU
    PLUGIN_ICON = res.bitmap('img', 'script-editor.tif')

    @classmethod
    def Register(cls):
        return c4d.plugins.RegisterCommandPlugin(cls.PLUGIN_ID,
                                                 cls.PLUGIN_NAME,
                                                 cls.PLUGIN_INFO,
                                                 cls.PLUGIN_ICON,
                                                 cls.PLUGIN_HELP, cls())

    # c4d.plugins.CommandData

    def Execute(self, doc):
        return ScriptEditor.OpenDefault()

    def RestoreLayout(self, secret):
        return ScriptEditor.RestoreDefault(secret)
Exemple #7
0
 def remove_document(self, doc, confirm_close=True):
     if confirm_close and doc.status == Document.Edited:
         message = res.string('IDC_EDITOR_ASKCLOSE')
         result = c4d.gui.MessageDialog(message, c4d.GEMB_YESNOCANCEL)
         if result == c4d.GEMB_R_YES:
             self.save_document(doc)
         elif result == c4d.GEMB_R_CANCEL:
             return
     doc.window = None
     self.documents.remove(doc)
     if not self.documents:
         self.new_document()
     if self.active_document not in xrange(len(self.documents)):
         self.active_document = len(self.documents) - 1
     c4d.EventAdd()
Exemple #8
0
 def remove_document(self, doc, confirm_close=True):
   if confirm_close and doc.status == Document.Edited:
     message = res.string('IDC_EDITOR_ASKCLOSE')
     result = c4d.gui.MessageDialog(message, c4d.GEMB_YESNOCANCEL)
     if result == c4d.GEMB_R_YES:
       self.save_document(doc)
     elif result == c4d.GEMB_R_CANCEL:
       return
   doc.window = None
   self.documents.remove(doc)
   if not self.documents:
     self.new_document()
   if self.active_document not in xrange(len(self.documents)):
     self.active_document = len(self.documents) - 1
   c4d.EventAdd()
Exemple #9
0
    def __init__(self, title=None, **options):
        super(ScriptEditor, self).__init__()

        self.__script = None
        self.__traceback_data = (None, None)
        self.__traceback_visible = False

        self.title = title or res.string('IDC_SCRIPT_EDITOR')
        self.options = {
                'status_bar': True,
                'highlight_line': True,
                'send_icon': c4d.RESOURCEIMAGE_BROWSER_PLAY,
                'status_line': True,
                'undo_interval': 2.0,
                'display_tracebacks': True,
        }
        self.options.update(options)
Exemple #10
0
    def __init__(self, title=None, **options):
        super(ScriptEditor, self).__init__()

        self.__script = None
        self.__traceback_data = (None, None)
        self.__traceback_visible = False

        self.title = title or res.string('IDC_SCRIPT_EDITOR')
        self.options = {
            'status_bar': True,
            'highlight_line': True,
            'send_icon': c4d.RESOURCEIMAGE_BROWSER_PLAY,
            'status_line': True,
            'undo_interval': 2.0,
            'display_tracebacks': True,
        }
        self.options.update(options)
Exemple #11
0
    def DisplayTraceback(self, exc=None, traceback=None):
        r""" Display a the traceback below the text field in the
        editor. """

        if xor(exc, traceback):
            raise ValueError('require exc and traceback or neither of them')

        if not exc and not traceback:
            exc, traceback = self.__traceback_data

        self.MenuInitString(res.MENU_VIEW_TRACEBACK, True, True)
        self.LayoutFlushGroup(res.GROUP_TRACEBACK)
        self.LayoutCallback(self.TRACEBACKGROUP_START, (exc, traceback))

        # Add a close button to the top right.
        self.GroupBegin(0, c4d.BFH_SCALEFIT, 0, 0)
        self.GroupBorderSpace(4, 4, 4, 4)

        message = str(exc) if exc else res.string('IDC_NO_TRACEBACK')
        self.AddStaticText(0, c4d.BFH_SCALEFIT, name=message)
        self.AddBitmapButton(res.BUTTON_CLOSE_TRACEBACK,
                             0,
                             iconid1=c4d.RESOURCEIMAGE_CLEARSELECTION)
        self.GroupEnd()

        # Add the TreeViewCustomGui and the TracebackModel.
        if exc:
            bc = c4d.BaseContainer()
            bc.SetBool(c4d.TREEVIEW_ALTERNATE_BG, True)
            bc.SetBool(c4d.TREEVIEW_NOENTERRENAME, True)
            bc.SetBool(c4d.TREEVIEW_NO_MULTISELECT, True)
            bc.SetBool(c4d.TREEVIEW_FIXED_LAYOUT, True)
            tree = self.AddCustomGui(res.TREE_TRACEBACK,
                                     c4d.CUSTOMGUI_TREEVIEW, "",
                                     c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 200,
                                     80, bc)
            tree.SetRoot(traceback, TracebackModel(), (exc, ref(self)))

        self.LayoutCallback(self.TRACEBACKGROUP_END, (exc, traceback))
        self.LayoutChanged(res.GROUP_TRACEBACK)

        self.__traceback_data = (exc, traceback)
        self.__traceback_visible = True
Exemple #12
0
    def DisplayTraceback(self, exc=None, traceback=None):
        r""" Display a the traceback below the text field in the
        editor. """

        if xor(exc, traceback):
            raise ValueError('require exc and traceback or neither of them')

        if not exc and not traceback:
            exc, traceback = self.__traceback_data

        self.MenuInitString(res.MENU_VIEW_TRACEBACK, True, True)
        self.LayoutFlushGroup(res.GROUP_TRACEBACK)
        self.LayoutCallback(self.TRACEBACKGROUP_START, (exc, traceback))

        # Add a close button to the top right.
        self.GroupBegin(0, c4d.BFH_SCALEFIT, 0, 0)
        self.GroupBorderSpace(4, 4, 4, 4)

        message = str(exc) if exc else res.string('IDC_NO_TRACEBACK')
        self.AddStaticText(0, c4d.BFH_SCALEFIT, name=message)
        self.AddBitmapButton(
                    res.BUTTON_CLOSE_TRACEBACK, 0,
                    iconid1=c4d.RESOURCEIMAGE_CLEARSELECTION)
        self.GroupEnd()

        # Add the TreeViewCustomGui and the TracebackModel.
        if exc:
            bc = c4d.BaseContainer()
            bc.SetBool(c4d.TREEVIEW_ALTERNATE_BG, True)
            bc.SetBool(c4d.TREEVIEW_NOENTERRENAME, True)
            bc.SetBool(c4d.TREEVIEW_NO_MULTISELECT, True)
            bc.SetBool(c4d.TREEVIEW_FIXED_LAYOUT, True)
            tree = self.AddCustomGui(
                        res.TREE_TRACEBACK, c4d.CUSTOMGUI_TREEVIEW, "",
                        c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 200, 80, bc)
            tree.SetRoot(traceback, TracebackModel(), (exc, ref(self)))

        self.LayoutCallback(self.TRACEBACKGROUP_END, (exc, traceback))
        self.LayoutChanged(res.GROUP_TRACEBACK)

        self.__traceback_data = (exc, traceback)
        self.__traceback_visible = True
Exemple #13
0
 def get_status_string(self):
     return self.last_message or res.string('IDC_CODE_OK')
Exemple #14
0
    def CreateLayout(self):
        HV_SCALEFIT = c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT

        self.MenuSubBegin(res.string('MENU_FILE'))
        self.MenuAddString(*res.tup('MENU_FILE_OPEN'))
        self.MenuAddString(*res.tup('MENU_FILE_SAVETO'))
        self.MenuSubEnd()

        self.MenuSubBegin(res.string('MENU_VIEW'))
        self.MenuAddString(*res.tup('MENU_VIEW_TRACEBACK'))
        self.MenuSubEnd()

        self.MenuSubBegin(res.string('MENU_HELP'))
        self.MenuAddString(*res.tup('MENU_HELP_ABOUT'))
        self.MenuSubEnd()

        self.MenuFinished()

        # Build the menu line with the "Send" button. The
        # respective LayoutCallbacks are invoked.
        self.GroupBeginInMenuLine()
        self.LayoutCallback(self.MENULINE_START)

        # Should we also display a status line in the menuline?
        if self.options['status_line']:
            self.AddStaticText(res.STATIC_STATUS, 0)
            self.AddStaticText(0, 0, name=" ") # separator

        self.AddButton(res.BUTTON_UNDO, 0, name=res.string('BUTTON_UNDO'))
        self.AddButton(res.BUTTON_REDO, 0, name=res.string('BUTTON_REDO'))

        # Create the "Send" BitmapButton.
        self.LayoutCallback(self.MENULINE_BEFORESEND)
        self.AddBitmapButton(
                res.BUTTON_SEND, 0, 16, 16,
                iconid1=self.options['send_icon'],
                tooltip=res.string('BUTTON_SEND_TOOLTIP'))

        # Send the LayoutCallback for the end of the menuline
        # group and close it.
        self.LayoutCallback(self.MENULINE_END)
        self.GroupEnd()

        # Open the main group and add the multiline text box
        # with respective LayoutCallbacks.
        self.GroupBegin(res.GROUP_MAIN, HV_SCALEFIT, 1, 0)
        self.LayoutCallback(self.MAINGROUP_START)

        style = c4d.DR_MULTILINE_MONOSPACED | c4d.DR_MULTILINE_SYNTAXCOLOR | \
                c4d.DR_MULTILINE_PYTHON | c4d.DR_MULTILINE_HIGHLIGHTLINE
        if self.options['status_bar']:
            style |= c4d.DR_MULTILINE_STATUSBAR
        if self.options['highlight_line']:
            style |= c4d.DR_MULTILINE_HIGHLIGHTLINE
        self.AddMultiLineEditText(res.TEXT_SCRIPT, HV_SCALEFIT, style=style)

        # Close the group.
        self.LayoutCallback(self.MAINGROUP_END)
        self.GroupEnd()

        # Create the Traceback group.
        self.GroupBegin(res.GROUP_TRACEBACK, c4d.BFH_SCALEFIT, 1, 0)
        self.GroupEnd()
        self.HideTraceback()

        self.__Update()
        return True
Exemple #15
0
 def get_status_string(self):
     return self.last_message or res.string('IDC_CODE_OK')
Exemple #16
0
    def CreateLayout(self):
        HV_SCALEFIT = c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT

        self.MenuSubBegin(res.string('MENU_FILE'))
        self.MenuAddString(*res.tup('MENU_FILE_OPEN'))
        self.MenuAddString(*res.tup('MENU_FILE_SAVETO'))
        self.MenuSubEnd()

        self.MenuSubBegin(res.string('MENU_VIEW'))
        self.MenuAddString(*res.tup('MENU_VIEW_TRACEBACK'))
        self.MenuSubEnd()

        self.MenuSubBegin(res.string('MENU_HELP'))
        self.MenuAddString(*res.tup('MENU_HELP_ABOUT'))
        self.MenuSubEnd()

        self.MenuFinished()

        # Build the menu line with the "Send" button. The
        # respective LayoutCallbacks are invoked.
        self.GroupBeginInMenuLine()
        self.LayoutCallback(self.MENULINE_START)

        # Should we also display a status line in the menuline?
        if self.options['status_line']:
            self.AddStaticText(res.STATIC_STATUS, 0)
            self.AddStaticText(0, 0, name=" ")  # separator

        self.AddButton(res.BUTTON_UNDO, 0, name=res.string('BUTTON_UNDO'))
        self.AddButton(res.BUTTON_REDO, 0, name=res.string('BUTTON_REDO'))

        # Create the "Send" BitmapButton.
        self.LayoutCallback(self.MENULINE_BEFORESEND)
        self.AddBitmapButton(res.BUTTON_SEND,
                             0,
                             16,
                             16,
                             iconid1=self.options['send_icon'],
                             tooltip=res.string('BUTTON_SEND_TOOLTIP'))

        # Send the LayoutCallback for the end of the menuline
        # group and close it.
        self.LayoutCallback(self.MENULINE_END)
        self.GroupEnd()

        # Open the main group and add the multiline text box
        # with respective LayoutCallbacks.
        self.GroupBegin(res.GROUP_MAIN, HV_SCALEFIT, 1, 0)
        self.LayoutCallback(self.MAINGROUP_START)

        style = c4d.DR_MULTILINE_MONOSPACED | c4d.DR_MULTILINE_SYNTAXCOLOR | \
                c4d.DR_MULTILINE_PYTHON | c4d.DR_MULTILINE_HIGHLIGHTLINE
        if self.options['status_bar']:
            style |= c4d.DR_MULTILINE_STATUSBAR
        if self.options['highlight_line']:
            style |= c4d.DR_MULTILINE_HIGHLIGHTLINE
        self.AddMultiLineEditText(res.TEXT_SCRIPT, HV_SCALEFIT, style=style)

        # Close the group.
        self.LayoutCallback(self.MAINGROUP_END)
        self.GroupEnd()

        # Create the Traceback group.
        self.GroupBegin(res.GROUP_TRACEBACK, c4d.BFH_SCALEFIT, 1, 0)
        self.GroupEnd()
        self.HideTraceback()

        self.__Update()
        return True