Beispiel #1
0
    def __init__(self, target):
        wx.Panel.__init__(self, koko.CANVAS)

        self.target = target

        sizer = wx.FlexGridSizer(
            rows=len(target.PARAMETERS)+2,
            cols = 2)

        txt = wx.StaticText(self, label='type', size=(-1, 25),
                            style=wx.ALIGN_RIGHT|wx.ST_NO_AUTORESIZE)
        sizer.Add(txt, border=3, flag=wx.BOTTOM|wx.TOP|wx.RIGHT|wx.EXPAND)

        # Add this panel's class
        classTxt =  wx.StaticText(self, size=(-1, 25),
                                  label=target.__class__.__name__)
        classTxt.SetFont(wx.Font(14, family=wx.FONTFAMILY_DEFAULT,
                                 style=wx.ITALIC, weight=wx.BOLD))
        sizer.Add(classTxt, border=1, flag=wx.BOTTOM|wx.TOP|wx.LEFT|wx.EXPAND)

        boxes = []
        for p in target.PARAMETERS:
            boxes.append(self.add_row(sizer, p))
        self.update = lambda: [b.pull() for b in boxes]

        outer = wx.BoxSizer()
        outer.Add(sizer, border=10, flag=wx.ALL)
        self.SetSizerAndFit(outer)
        DARK_THEME.apply(self)

        koko.CANVAS.Refresh()
Beispiel #2
0
 def invalidate(self, event=None):
     """ @brief Invalidates final panel in workflow
         @details Disables Save and Start buttons, and deletes paths from canvases to indicate that a generated path is no longer valid.
     """
     DARK_THEME.apply(self)
     if isinstance(self.panels[-1], OutputPanel):
         self.panels[-1].invalidate()
     koko.CANVAS.clear_path()
     koko.GLCANVAS.clear_path()
     if event:   event.Skip()
Beispiel #3
0
    def add_row(self, sizer, label, enabled=True):
        ''' Helper function to add a row to a sizer.
        
            Returns a TextCtrl with extra field 'label'.
        '''
        
        # Create label
        labelTxt = DARK_THEME.apply(
            wx.StaticText(self, label=label,
                          style=wx.ALIGN_RIGHT|wx.ST_NO_AUTORESIZE,
                          size=(-1, 25)))
        sizer.Add(labelTxt, border=3,
                  flag=wx.BOTTOM|wx.TOP|wx.RIGHT|wx.EXPAND)
        
        # Create input box
        inputBox = DARK_THEME.apply(
            wx.TextCtrl(self, size=(150, 25),
                        style=wx.NO_BORDER|wx.TE_PROCESS_ENTER))
        sizer.Add(inputBox, border=3,
                  flag=wx.BOTTOM|wx.TOP|wx.LEFT|wx.EXPAND)
        
        # Add extra field to input box
        inputBox.label = label

        # Silly hack to avoid selecting all of the text when
        # this row gets focus.
        def focus(event):
            txt = event.GetEventObject()
            txt.SetSelection(0,0)
            try:
                txt.SetInsertionPoint(txt.lastInsertionPoint)
                del txt.lastInsertionPoint
            except AttributeError:
                return
        def lost_focus(event):
            txt = event.GetEventObject()
            txt.lastInsertionPoint = txt.GetInsertionPoint()
        
        if enabled:
            inputBox.Bind(wx.EVT_SET_FOCUS, focus)
            inputBox.Bind(wx.EVT_KILL_FOCUS, lost_focus)
        else:
            inputBox.Disable()
        
        return inputBox
Beispiel #4
0
    def __init__(self, parent, title, filename):
        wx.Frame.__init__(self, parent, title=title)

        # Create text pane.
        txt = koko.editor.Editor(self, margins=False, style=wx.NO_BORDER,
                                 size=(600, 400))
        txt.SetCaretLineVisible(0)
        txt.SetReadOnly(True)
                
        with open(filename, 'r') as f:
            txt.text = f.read()

        
        DARK_THEME.apply(txt)
        DARK_THEME.apply(self)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(txt, 1, wx.EXPAND | wx.ALL, border=5)
        self.SetSizerAndFit(sizer)
        self.Show()
Beispiel #5
0
    def regenerate(self, input, output):
        """ @brief Regenerates the workflow UI
            @param input    Input data structure
            @param output   Output module
        """

        self.input = [i for i in INPUTS if i.TYPE == type(input)][0]

        # Make sure we can find a path from the start panel to
        # the desired path panel.
        if output.INPUT in self.input.WORKFLOWS:
            self.output = output

        # If that fails, then load the None machine as our output
        else:
            self.output = MACHINES[0]

        for p in self.panels:   p.Destroy()
        if self.defaults:       self.defaults.Destroy()
        self.panels = []
        self.defaults = None

        if self.output.DEFAULTS:
            self.defaults = DefaultSelector(self, output.DEFAULTS)
            self.sizer.Add(self.defaults, flag=wx.EXPAND|wx.TOP, border=10)

        workflow = (
            self.input.WORKFLOWS[self.output.INPUT] +
            (self.output.INPUT, self.output.PANEL)
        )

        for p in workflow:
            if p is None:   continue

            panel = p(self)

            self.panels.append(panel)
            self.sizer.Add(panel, flag=wx.EXPAND|wx.TOP, border=10)

        DARK_THEME.apply(self)
        self.Layout()
Beispiel #6
0
    def __init__(self, callbacks):
        wx.Frame.__init__(self, parent=None)
        
        # Bind menu callbacks        
        self.Bind(wx.EVT_MENU_HIGHLIGHT, self.OnMenuHighlight)
        self.Bind(wx.EVT_MENU_CLOSE, self.OnMenuClose)
        
        # Bind menu callbacks
        self.build_menus(callbacks)
        
        # Bind idle callback
        self.Bind(wx.EVT_IDLE, callbacks['idle'])
        
        #######################################################################

        
        #######################################################################
        # Create a canvas with a border and status text below
        canvasPanel = wx.Panel(self)
        canvasSizer = wx.BoxSizer(wx.VERTICAL)

        version = wx.StaticText(canvasPanel, label='%s %s ' % 
                                (koko.about.NAME, koko.about.VERSION))
        canvasSizer.Add(version, flag=wx.ALIGN_RIGHT)
        
        self.canvas = Canvas(canvasPanel, callbacks, size=(300, 300))
        koko.globals.CANVAS = weakref.proxy(self.canvas)
        
        canvasSizer.Add(self.canvas, proportion=2,
                        flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND,
                        border=20)
        
        # Add status text
        canvasSizer.Add((0,0), border=5, flag=wx.BOTTOM)
        self._status = wx.StaticText(
            canvasPanel, style=wx.ALIGN_RIGHT|wx.ST_NO_AUTORESIZE)
        canvasSizer.Add(self._status, border=20, flag=wx.EXPAND | wx.RIGHT)
        canvasSizer.Add((0,0), border=15, flag=wx.BOTTOM)
        
        # Add output panel for error messages, etc.
        self._output = Editor(canvasPanel, margins=False, style=wx.NO_BORDER, size=(300, 100))
        self._output.SetReadOnly(True)
        self._output.SetCaretLineVisible(False)
        self._output.SetWrapMode(wx.stc.STC_WRAP_WORD)
        
        self.hide_output = lambda: (self._output.Hide(), canvasPanel.Layout())
        self.show_output = lambda: (self._output.Show(), canvasPanel.Layout())
        
        canvasSizer.Add(self._output, border=20, proportion=1,
                        flag=wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT)
        canvasPanel.SetSizerAndFit(canvasSizer)
        #######################################################################
        
        
        #######################################################################
        # Pack everything into the window        

        editorPanel = wx.Panel(self)
        editorSizer = wx.BoxSizer(wx.VERTICAL)
        
        editorSizer.Add((0,0), border=15, flag=wx.TOP)
        self.editor = Editor(editorPanel, style=wx.NO_BORDER, size=(300, 400))
        koko.globals.EDITOR = weakref.proxy(self.editor)
        
        self.editor.load_template()
        self.editor.bind_callbacks(callbacks)
        
        editorSizer.Add(self.editor, proportion=1, flag=wx.EXPAND)

        self._hint = wx.StaticText(editorPanel)
        editorSizer.Add(self._hint, border=5, flag=wx.ALL)

        editorPanel.SetSizerAndFit(editorSizer)
        
        #######################################################################
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(editorPanel, proportion=2, flag=wx.EXPAND)
        sizer.Add(canvasPanel, proportion=3, flag=wx.EXPAND)
        
        self.hide_script = lambda: (editorPanel.Hide(), self.Layout())
        self.show_script = lambda: (editorPanel.Show(), self.Layout())
        
        self.SetSizerAndFit(sizer)
        #######################################################################
        
        
        DARK_THEME.apply(self)
        DARK_THEME.apply(canvasPanel)
        DARK_THEME.apply(editorPanel)
        DARK_THEME.apply(version)
        DARK_THEME.apply(self._hint)
        DARK_THEME.apply(self._status)
        DARK_THEME.apply(self._output)
        DARK_THEME.apply(self.editor)
        
        self._status.SetForegroundColour(wx.Colour(100, 100, 100))

        self.hide_output()
        self.Maximize()
Beispiel #7
0
    def __init__(self, canvas, target):
        # Save a link upstream
        self.canvas = canvas
        
        # Figure out constructor arguments for target object
        argspec = inspect.getargspec(target.__class__.__init__)
        args = argspec.args[1:]
       
        # Extract properties from this object              
        props = [p for p,t in vars(target.__class__).iteritems()
                 if type(t) == property and p[0] != '_' and p not in args]
        props = sorted(props)        
        
        
        # Filter out hidden arguments and properties
        hidden = target.__class__.HIDDEN_PROPERTIES
        args  = filter(lambda a: a not in hidden, args)
        props = filter(lambda p: p not in hidden, props)
        
        # Start creating the panel
        wx.Panel.__init__(self, canvas)
        
        # Create a sizer of the appropriate size
        sizer = wx.FlexGridSizer(rows=len(args)+len(props)+1, cols=2)
        
        # Add the text 'type'
        txt = DARK_THEME.apply(
            wx.StaticText(self, label='type', size=(-1, 25),
                          style=wx.ALIGN_RIGHT|wx.ST_NO_AUTORESIZE))
        sizer.Add(txt, border=3, flag=wx.BOTTOM|wx.TOP|wx.RIGHT|wx.EXPAND)
                
        # Add this panel's class                
        classTxt = DARK_THEME.apply(
            wx.StaticText(self, size=(-1, 25),
                          label=target.__class__.__name__, ))
        classTxt.SetFont(wx.Font(14, family=wx.FONTFAMILY_DEFAULT,
                                 style=wx.ITALIC, weight=wx.BOLD))
        sizer.Add(classTxt, border=1, flag=wx.BOTTOM|wx.TOP|wx.LEFT|wx.EXPAND)


        ######################################################################
        
        self.inputs = {}
        self.outputs = {}
        while args:
            input = self.add_row(sizer, args[0])
            input.Bind(wx.EVT_CHAR, self.char)
            input.Bind(wx.EVT_TEXT, self.changed)
            input.Bind(wx.EVT_TEXT_ENTER, self.canvas.close_edit_panel)
            self.inputs[args[0]] = input
            args = args[1:]
            
        while props:
            output = self.add_row(sizer, '   '+props[0], enabled=False)
            self.outputs[props[0]] = output
            props = props[1:]
                
        outer = wx.BoxSizer()
        outer.Add(sizer, border=10, flag=wx.ALL)
        self.SetSizerAndFit(outer)
        
        self.target = target
        target.selected = True
        
        # When this panel is closed, invoke a callback.
        canvas.Bind(wx.EVT_WINDOW_DESTROY, canvas.edit_panel_closed, self)
        DARK_THEME.apply(self)
        
        canvas.Refresh()
Beispiel #8
0
    def __init__(self, app):

        wx.Frame.__init__(self, parent=None)

        # Build menus and bind callback
        self.build_menus(app)

        # Bind idle callback
        self.Bind(wx.EVT_IDLE, app.idle)

        # The main sizer for the application
        sizer = wx.BoxSizer(wx.VERTICAL)
        version = '%s %s' % (koko.NAME, koko.VERSION)
        sizer.Add(wx.StaticText(self, label=version),
                                flag=wx.ALIGN_RIGHT|wx.ALL, border=5)

        # Horizontal sizer that contains script, output, and canvases
        core = wx.BoxSizer(wx.HORIZONTAL)

        editor_panel = wx.Panel(self)
        editor_sizer = wx.BoxSizer(wx.VERTICAL)

        # Vertical sizer that contains the editor and the output panel
        koko.EDITOR = Editor(editor_panel, style=wx.NO_BORDER, size=(300, 400))
        koko.EDITOR.load_template()
        koko.EDITOR.bind_callbacks(app)

        editor_sizer.Add(koko.EDITOR, proportion=2, flag=wx.EXPAND)
        self.show_editor = lambda b: editor_sizer.ShowItems(b)

        self._output = Editor(editor_panel, margins=False,
                              style=wx.NO_BORDER, size=(300, 100))
        self._output.SetWrapStartIndent(4)
        self._output.SetReadOnly(True)
        self._output.SetCaretLineVisible(False)
        self._output.SetWrapMode(wx.stc.STC_WRAP_WORD)
        editor_sizer.Add(self._output, proportion=1, border=10,
                         flag=wx.EXPAND|wx.TOP)
        editor_panel.SetSizerAndFit(editor_sizer)

        self.show_editor = lambda b: editor_panel.Show(b)

        # Vertical / Horizontal sizer that contains the two canvases
        canvas_sizer = wx.BoxSizer(wx.VERTICAL)
        self.set_canvas_orientation = lambda o: canvas_sizer.SetOrientation(o)

        koko.CANVAS = Canvas(self, app, size=(300, 300))
        canvas_sizer.Add(koko.CANVAS, proportion=1, flag=wx.EXPAND)
        koko.GLCANVAS = GLCanvas(self, size=(300, 300))
        canvas_sizer.Add(koko.GLCANVAS, proportion=1, flag=wx.EXPAND)
        koko.GLCANVAS.Hide()

        core.Add(editor_panel, proportion=4,
                 flag=wx.EXPAND|wx.RIGHT, border=10)
        core.Add(canvas_sizer, proportion=6,
                 flag=wx.EXPAND|wx.RIGHT, border=10)
        koko.FAB = FabWorkflowPanel(self)
        core.Add(koko.FAB, proportion=3,
                 flag=wx.EXPAND|wx.RIGHT, border=10)
        koko.FAB.Hide()

        sizer.Add(core, proportion=1, flag=wx.EXPAND)

        bottom_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self._hint = wx.lib.stattext.GenStaticText(self)
        bottom_sizer.Add(self._hint, proportion=1)

        self._status = wx.lib.stattext.GenStaticText(
            self, style=wx.ALIGN_RIGHT|wx.ST_NO_AUTORESIZE
        )
        bottom_sizer.Add(self._status, proportion=1)

        sizer.Add(bottom_sizer, flag=wx.EXPAND|wx.ALL, border=10)

        self.SetSizerAndFit(sizer)
        DARK_THEME.apply(self)

        self._status.SetForegroundColour(wx.Colour(100, 100, 100))

        # By default, hide the output panel
        self._output.Hide()
        self.Layout()

        """
        # Settings for screen recording
        self.SetClientSize((1280, 720))
        self.SetPosition((0,wx.DisplaySize()[1] - self.GetSize()[1]))
        """

        self.Maximize()