示例#1
0
class LayoutSpacingExample(VerticalLayout, IClickListener):

    def __init__(self):
        super(LayoutSpacingExample, self).__init__()

        # Create a grid layout.
        self.grid = GridLayout(3, 3)

        # Enable sp for the example layout (this is the one we'll toggle
        # with the checkbox)
        self.grid.setSpacing(False)

        # CheckBox for toggling sp on and off
        self.sp = CheckBox("Spacing enabled")
#        self.sp.setValue(True)  # FIXME:
        self.sp.setImmediate(True)

        self.sp.addListener(self, IClickListener)
        self.addComponent(self.sp)

        # Add the layout to the containing layout.
        self.addComponent(self.grid)

        # Populate the layout with components.
        for i in range(9):
            self.grid.addComponent(Button('Component %d' % (i + 1)))

        self.setSpacing(True)  # enable sp for the example itself


    def buttonClick(self, event):
        enabled = self.sp.booleanValue()
        self.grid.setSpacing(enabled)
示例#2
0
    def init(self):
        # Application.init is called once for each application. Here it
        # creates the UI and connects it to the business logic.

        # Create the main layout for our application (4 columns, 5 rows)
        layout = GridLayout(4, 5)

        # Create the main window for the application using the main layout.
        # The main window is shown when the application is starts.
        self.setMainWindow(Window('Calculator Application', layout))

        # Create a result label that over all 4 columns in the first row
        layout.addComponent(self._display, 0, 0, 3, 0)

        # The operations for the calculator in the order they appear on the
        # screen (left to right, top to bottom)
        operations = ['7', '8', '9', '/', '4', '5', '6',
                '*', '1', '2', '3', '-', '0', '=', 'C', '+']

        for caption in operations:
            # Create a button and use this application for event handling
            button = Button(caption)
            button.addListener(self)

            # Add the button to our main layout
            layout.addComponent(button)
class LayoutSpacingExample(VerticalLayout, IClickListener):
    def __init__(self):
        super(LayoutSpacingExample, self).__init__()

        # Create a grid layout.
        self.grid = GridLayout(3, 3)

        # Enable sp for the example layout (this is the one we'll toggle
        # with the checkbox)
        self.grid.setSpacing(False)

        # CheckBox for toggling sp on and off
        self.sp = CheckBox("Spacing enabled")
        #        self.sp.setValue(True)  # FIXME:
        self.sp.setImmediate(True)

        self.sp.addListener(self, IClickListener)
        self.addComponent(self.sp)

        # Add the layout to the containing layout.
        self.addComponent(self.grid)

        # Populate the layout with components.
        for i in range(9):
            self.grid.addComponent(Button('Component %d' % (i + 1)))

        self.setSpacing(True)  # enable sp for the example itself

    def buttonClick(self, event):
        enabled = self.sp.booleanValue()
        self.grid.setSpacing(enabled)
示例#4
0
 def buildLabels(self):
     grid = GridLayout()
     grid.setSpacing(True)
     grid.setWidth("100%")
     grid.setColumns(6)
     for prop in CssProperty.values():
         l = Label("-")
         l.setSizeUndefined()
         l.setCaption(str(prop))
         self._props[prop] = l
         grid.addComponent(l)
     return grid
示例#5
0
 def buildLabels(self):
     grid = GridLayout()
     grid.setSpacing(True)
     grid.setWidth('100%')
     grid.setColumns(6)
     for prop in CssProperty.values():
         l = Label('-')
         l.setSizeUndefined()
         l.setCaption(str(prop))
         self._props[prop] = l
         grid.addComponent(l)
     return grid
示例#6
0
    def __init__(self):
        super(PackageIconsExample, self).__init__()

        self._icons = ['arrow-down.png', 'arrow-left.png', 'arrow-right.png',
            'arrow-up.png', 'attention.png', 'calendar.png', 'cancel.png',
            'document.png', 'document-add.png', 'document-delete.png',
            'document-doc.png', 'document-image.png', 'document-pdf.png',
            'document-ppt.png', 'document-txt.png', 'document-web.png',
            'document-xsl.png', 'email.png', 'email-reply.png',
            'email-send.png', 'folder.png', 'folder-add.png',
            'folder-delete.png', 'globe.png', 'help.png', 'lock.png',
            'note.png', 'ok.png', 'reload.png', 'settings.png', 'trash.png',
            'trash-full.png', 'user.png', 'users.png']

        self._sizes = ['16', '32', '64']

        self.setSpacing(True)

        tabSheet = TabSheet()
        tabSheet.setStyleName(Reindeer.TABSHEET_MINIMAL)

        for size in self._sizes:
            iconsSideBySide = 2 if size == '64' else 3
            grid = GridLayout(iconsSideBySide * 2, 1)
            grid.setSpacing(True)
            grid.setMargin(True)
            tabSheet.addTab(grid, size + 'x' + size, None)

            tabSheet.addComponent(grid)
            for icon in self._icons:
                res = ThemeResource('../runo/icons/' + size + '/' + icon)

                e = Embedded(None, res)

                # Set size to avoid flickering when loading
                e.setWidth(size + 'px')
                e.setHeight(size + 'px')

                name = Label(icon)
                if size == '64':
                    name.setWidth('185px')
                else:
                    name.setWidth('150px')

                grid.addComponent(e)
                grid.addComponent(name)

                grid.setComponentAlignment(name, Alignment.MIDDLE_LEFT)

        self.addComponent(tabSheet)
示例#7
0
    def init(self):

        layout = GridLayout(4, 5)

        self.setMainWindow(Window('Calculator Application', layout))

        layout.addComponent(self._display, 0, 0, 3, 0)

        operations = ['7', '8', '9', '/', '4', '5', '6',
                '*', '1', '2', '3', '-', '0', '=', 'C', '+']

        for caption in operations:
            # Create a button and use this application for event handling
            button = Button(caption)
            button.addListener(self)

            # Add the button to our main layout
            layout.addComponent(button)
    def createChildComponentClickableLayout(self):
        # Create a grid layout with click events
        layout = GridLayout(5, 2)
        layout.addStyleName('border')
        layout.setSpacing(True)
        layout.setWidth('90%')
        layout.setMargin(True)

        # Add some components to the layout
        layout.addComponent(Label('<b>Clickable layout events include a '
                'reference to the child component beneath the click. '
                'Try clicking anywhere in this layout.</b>',
                Label.CONTENT_RAW), 0, 0, 4, 0)
        layout.addComponent(TextField(None, 'Click here'))
        layout.addComponent(Link('Click here', None))
        select = Select(None, ['Click here'])
        select.select('Click here')
        layout.addComponent(select)

        # Listen for layout click event
        layout.addListener(GridListener(self), ILayoutClickListener)
        return layout
    def createChildComponentClickableLayout(self):
        # Create a grid layout with click events
        layout = GridLayout(5, 2)
        layout.addStyleName('border')
        layout.setSpacing(True)
        layout.setWidth('90%')
        layout.setMargin(True)

        # Add some components to the layout
        layout.addComponent(
            Label(
                '<b>Clickable layout events include a '
                'reference to the child component beneath the click. '
                'Try clicking anywhere in this layout.</b>',
                Label.CONTENT_RAW), 0, 0, 4, 0)
        layout.addComponent(TextField(None, 'Click here'))
        layout.addComponent(Link('Click here', None))
        select = Select(None, ['Click here'])
        select.select('Click here')
        layout.addComponent(select)

        # Listen for layout click event
        layout.addListener(GridListener(self), ILayoutClickListener)
        return layout
    def __init__(self):
        super(GridLayoutBasicExample, self).__init__()

        # Create a grid layout
        grid = GridLayout(3, 3)
        grid.setSpacing(True)

        # The style allows us to visualize the cell borders in this example.
        grid.addStyleName('gridexample')

        grid.setWidth(400, ISizeable.UNITS_PIXELS)
        grid.setHeight(400, ISizeable.UNITS_PIXELS)

        # First we insert four components that occupy one cell each
        topleft = Button('Top Left')
        grid.addComponent(topleft, 0, 0)
        grid.setComponentAlignment(topleft, Alignment.MIDDLE_CENTER)

        topcenter = Button('Top Center')
        grid.addComponent(topcenter, 1, 0)
        grid.setComponentAlignment(topcenter, Alignment.MIDDLE_CENTER)

        bottomleft = Button('Bottom Left')
        grid.addComponent(bottomleft, 0, 2)
        grid.setComponentAlignment(bottomleft, Alignment.MIDDLE_CENTER)

        bottomcenter = Button('Bottom Center')
        grid.addComponent(bottomcenter, 1, 2)
        grid.setComponentAlignment(bottomcenter, Alignment.MIDDLE_CENTER)

        # Insert a component that occupies all the rightmost cells
        topright = Button('Extra height')
        grid.addComponent(topright, 2, 0, 2, 2)
        grid.setComponentAlignment(topright, Alignment.MIDDLE_CENTER)

        # Insert a component that occupies two cells in horizontal direction
        middleleft = Button('This is a wide cell in GridLayout')
        grid.addComponent(middleleft, 0, 1, 1, 1)
        grid.setComponentAlignment(middleleft, Alignment.MIDDLE_CENTER)

        # Add the layout to the containing layout.
        self.addComponent(grid)

        # Align the grid itself within its container layout.
        self.setComponentAlignment(grid, Alignment.MIDDLE_CENTER)
示例#11
0
    def addTestButtons(self):
        grid = GridLayout(4, 1)
        grid.setSpacing(True)
        self.getMainWindow().addComponent(grid)

        l = DraggabilityClickListener(self)
        grid.addComponent(Button('Toggle marker 3 draggability', l))

        l = VisibilityClickListener(self)
        grid.addComponent(Button('Toggle marker 4 visibility', l))

        l = RandomizeClickListener(self)
        grid.addComponent(Button('Randomize Marker 5 location', l))

        l = UpdateClickListener(self)
        grid.addComponent(Button('Update marker 5 title', l))

        l = RemoveClickListener(self)
        grid.addComponent(Button('Remove \"Test marker2\"', l))

        l = AddClickListener(self)
        grid.addComponent(Button('Add \"Test marker2\"', l))

        l = ToggleMarkerClickListener(self)
        grid.addComponent(Button('Toggle marker 1 icon', l))

        l = ToggleLoggingClickListener(self)
        grid.addComponent(Button('Toggle client logging', l))

        # Popup test
        l = PopupClickListener(self)
        grid.addComponent(Button('Open a map in a popup', l))

        l = ResizeClickListener(self)
        grid.addComponent(Button('Resize map', l))

        l = DrawClickListener(self)
        grid.addComponent(Button('Draw polygon', l))

        l = RemovePolygonClickListener(self)
        grid.addComponent(Button('Remove first polygon', l))
    def init(self):
        mainWindow = Window('CodeMirror Sample Application')

        hl = GridLayout(2, 5)
        hl.setSpacing(True)
        mainWindow.addComponent(hl)

        # #1
        code = CodeMirror('Your Code', CodeMode.TEXT)
        code.setValue(self._SAMPLE_CODE)
        code.setWidth('500px')
        code.setHeight('350px')
        hl.addComponent(code)

        # #2
        code2 = CodeMirror('Your Code Too', CodeMode.PYTHON)
        code2.setValue(self._SAMPLE_CODE)
        #        code2.setWidth('400px')
        #        code2.setHeight('300px')
        hl.addComponent(code2)

        codeMode = Select('Select your mode')
        for cs in CodeMode.values():
            codeMode.addItem(cs)
        codeMode.setNewItemsAllowed(False)
        codeMode.setNullSelectionAllowed(False)
        codeMode.setImmediate(True)
        hl.addComponent(codeMode)

        l = CodeModeChangeListener(code, codeMode)
        codeMode.addListener(l, IValueChangeListener)
        codeMode.setValue(CodeMode.TEXT)

        codeMode = Select('Select your mode too')
        for cs in CodeMode.values():
            codeMode.addItem(cs)
        codeMode.setNewItemsAllowed(False)
        codeMode.setNullSelectionAllowed(False)
        codeMode.setImmediate(True)
        hl.addComponent(codeMode)

        l = CodeModeChangeListener(code2, codeMode)
        codeMode.addListener(l, IValueChangeListener)
        codeMode.setValue(CodeMode.PYTHON)

        codeTheme = Select('Select your theme')
        for ct in CodeTheme.values():
            codeTheme.addItem(ct)
        codeTheme.setNewItemsAllowed(False)
        codeTheme.setImmediate(True)
        hl.addComponent(codeTheme)

        l = CodeThemeChangeListener(code, codeTheme)
        codeTheme.addListener(l, IValueChangeListener)
        codeTheme.setValue(CodeTheme.DEFAULT)

        codeTheme = Select('Select your theme too')
        for ct in CodeTheme.values():
            codeTheme.addItem(ct)
        codeTheme.setNewItemsAllowed(False)
        codeTheme.setImmediate(True)
        hl.addComponent(codeTheme)

        l = CodeThemeChangeListener(code2, codeTheme)
        codeTheme.addListener(l, IValueChangeListener)
        codeTheme.setValue(CodeTheme.ECLIPSE)

        l = CopyClickListener(code, code2)
        hl.addComponent(Button('copy to -->', l))

        l = CopyClickListener(code2, code)
        hl.addComponent(Button('<- copy to', l))

        l = ShowLineNumbersListener(code)
        cb = CheckBox("Show line numbers", l)
        cb.setImmediate(True)
        hl.addComponent(cb)

        l = ShowLineNumbersListener(code2)
        cb = CheckBox("Show line numbers", l)
        cb.setImmediate(True)
        hl.addComponent(cb)

        self.setMainWindow(mainWindow)
示例#13
0
文件: ui_panel.py 项目: rwl/traitsui
    def _add_items(self, content, outer=None):
        """Adds a list of Item objects, creating a layout if needed.  Return
           the outermost layout.
        """
        # Get local references to various objects we need:
        ui = self.ui
        info = ui.info
        handler = ui.handler

        group = self.group
        show_left = group.show_left
        padding = group.padding
        columns = group.columns

        # See if a label is needed.
        show_labels = False
        for item in content:
            show_labels |= item.show_label

        # See if a grid layout is needed.
        if show_labels or columns > 1:
            inner = GridLayout(columns * 2, len(content))
            inner.setSpacing(True)
            inner.setSizeUndefined()

            if outer is None:
                outer = inner
            else:
                outer.addComponent(inner)

            row = 0
            if show_left:
                label_alignment = Alignment.MIDDLE_RIGHT
            else:
                label_alignment = Alignment.MIDDLE_LEFT

        else:
            # Use the existing layout if there is one.
            if outer is None:
                if self.horizontal:
                    outer = HorizontalLayout()
                else:
                    outer = VerticalLayout()
                outer.setSizeUndefined()

            inner = outer

            row = -1
            label_alignment = 0

        # Process each Item in the list:
        col = -1
        for item in content:

            # Keep a track of the current logical row and column unless the
            # layout is not a grid.
            col += 1
            if row >= 0 and col >= columns:
                col = 0
                row += 1

            # Get the name in order to determine its type:
            name = item.name

            # Check if is a label:
            if name == '':
                label = item.label
                if label != "":

                    # Create the label widget.
                    if item.style == 'simple':
                        label = Label(label)
                    else:
                        label = heading_text(None, text=label).control

                    self._add_widget(inner, label, row, col, show_labels)

                    if item.emphasized:
                        self._add_emphasis(label)

                # Continue on to the next Item in the list:
                continue

            # Check if it is a separator:
            if name == '_':
                cols = columns

                # See if the layout is a grid.
                if row >= 0:
                    # Move to the start of the next row if necessary.
                    if col > 0:
                        col = 0
                        row += 1

#                    # Skip the row we are about to do.
#                    row += 1

                    # Allow for the columns.
                    if show_labels:
                        cols *= 2

                for i in range(cols):
                    if self.horizontal:
                        # Add a vertical separator:
                        line = Panel()
                        line.setWidth('2px')
                        line.setHeight('-1px')
                        if row < 0:
                            inner.addComponent(line)
                        else:
                            inner.addComponent(line, row, i)
                    else:
                        # Add a horizontal separator:
                        line = Label('<hr />', Label.CONTENT_XHTML)
                        line.setWidth('100%')  # FIXME: explicit container size
                        if row < 0:
                            inner.addComponent(line)
                        else:
                            inner.addComponent(line, i, row)

                # Continue on to the next Item in the list:
                continue

            # Convert a blank to a 5 pixel spacer:
            if name == ' ':
                name = '5'

            # Check if it is a spacer:
            if all_digits.match( name ):

                # If so, add the appropriate amount of space to the layout:
                spacer = Label('')
                if self.horizontal:
                    # Add a horizontal spacer:
                    spacer.setWidth(name + 'px')
                else:
                    # Add a vertical spacer:
                    spacer.setHeight(name + 'px')

                self._add_widget(inner, spacer, row, col, show_labels)

                # Continue on to the next Item in the list:
                continue

            # Otherwise, it must be a trait Item:
            object      = eval( item.object_, globals(), ui.context )
            trait       = object.base_trait( name )
            desc        = trait.desc or ''
            fixed_width = False

            # Handle any label.
            if item.show_label:
                label = self._create_label(item, ui, desc)
                self._add_widget(inner, label, row, col, show_labels,
                                 label_alignment)
            else:
                label = None

            # Get the editor factory associated with the Item:
            editor_factory = item.editor
            if editor_factory is None:
                editor_factory = trait.get_editor()

                # If still no editor factory found, use a default text editor:
                if editor_factory is None:
                    from text_editor import ToolkitEditorFactory
                    editor_factory = ToolkitEditorFactory()

                # If the item has formatting traits set them in the editor
                # factory:
                if item.format_func is not None:
                    editor_factory.format_func = item.format_func

                if item.format_str != '':
                    editor_factory.format_str = item.format_str

                # If the item has an invalid state extended trait name, set it
                # in the editor factory:
                if item.invalid != '':
                    editor_factory.invalid = item.invalid

            # Create the requested type of editor from the editor factory:
            factory_method = getattr( editor_factory, item.style + '_editor' )
            editor         = factory_method( ui, object, name, item.tooltip,
                                        None).set(
                                 item        = item,
                                 object_name = item.object )

            # Tell the editor to actually build the editing widget.  Note that
            # "inner" is a layout.  This shouldn't matter as individual editors
            # shouldn't be using it as a parent anyway.  The important thing is
            # that it is not None (otherwise the main TraitsUI code can change
            # the "kind" of the created UI object).
            editor.prepare(inner)
            control = editor.control

            # Set the initial 'enabled' state of the editor from the factory:
            editor.enabled = editor_factory.enabled

            # Add emphasis to the editor control if requested:
            if item.emphasized:
                self._add_emphasis(control)

            # Give the editor focus if it requested it:
            if item.has_focus:
                control.focus()

            # Set the correct size on the control, as specified by the user:
            stretch = 0
            scrollable = editor.scrollable
            item_width = item.width
            item_height = item.height
            if (item_width != -1) or (item_height != -1):
                is_horizontal = self.horizontal

                min_size = control.minimumSizeHint()
                width = min_size.width()
                height = min_size.height()

                if (0.0 < item_width <= 1.0) and is_horizontal:
                    stretch = int(100 * item_width)

                item_width = int(item_width)
                if item_width < -1:
                    item_width  = -item_width
                else:
                    item_width = max(item_width, width)

                if (0.0 < item_height <= 1.0) and (not is_horizontal):
                    stretch = int(100 * item_height)

                item_height = int(item_height)
                if item_height < -1:
                    item_height = -item_height
                else:
                    item_height = max(item_height, height)

                control.setWidth(max(item_width, 0))
                control.setHeight(max(item_height, 0))

            # Bind the editor into the UIInfo object name space so it can be
            # referred to by a Handler while the user interface is active:
            Id = item.id or name
            info.bind( Id, editor, item.id )

            # Also, add the editors to the list of editors used to construct
            # the user interface:
            ui._editors.append( editor )

            # If the handler wants to be notified when the editor is created,
            # add it to the list of methods to be called when the UI is
            # complete:
            defined = getattr( handler, Id + '_defined', None )
            if defined is not None:
                ui.add_defined( defined )

            # If the editor is conditionally visible, add the visibility
            # 'expression' and the editor to the UI object's list of monitored
            # objects:
            if item.visible_when != '':
                ui.add_visible( item.visible_when, editor )

            # If the editor is conditionally enabled, add the enabling
            # 'expression' and the editor to the UI object's list of monitored
            # objects:
            if item.enabled_when != '':
                ui.add_enabled( item.enabled_when, editor )

            # Add the created editor control to the layout with the appropriate
            # size and stretch policies:
            ui._scrollable |= scrollable
#            item_resizable  = ((item.resizable is True) or
#                               ((item.resizable is Undefined) and scrollable))
#            if item_resizable:
#                stretch = stretch or 50
#                self.resizable = True
#            elif item.springy:
#                stretch = stretch or 50
#            policy = control.sizePolicy()
#            if self.horizontal:
#                policy.setHorizontalStretch(stretch)
#                if item_resizable or item.springy:
#                    policy.setHorizontalPolicy(QtGui.QSizePolicy.Expanding)
#            else:
#                policy.setVerticalStretch(stretch)
#                if item_resizable or item.springy:
#                    policy.setVerticalPolicy(QtGui.QSizePolicy.Expanding)
#            control.setSizePolicy(policy)

            # FIXME: Need to decide what to do about border_size and padding
            self._add_widget(inner, control, row, col, show_labels)

            # Save the reference to the label control (if any) in the editor:
            editor.label_control = label

        return outer
示例#14
0
    def addTestButtons(self):
        grid = GridLayout(4, 1)
        grid.setSpacing(True)
        self.getMainWindow().addComponent(grid)

        l = DraggabilityClickListener(self)
        grid.addComponent(Button('Toggle marker 3 draggability', l))

        l = VisibilityClickListener(self)
        grid.addComponent(Button('Toggle marker 4 visibility', l))

        l = RandomizeClickListener(self)
        grid.addComponent(Button('Randomize Marker 5 location', l))

        l = UpdateClickListener(self)
        grid.addComponent(Button('Update marker 5 title', l))

        l = RemoveClickListener(self)
        grid.addComponent(Button('Remove \"Test marker2\"', l))

        l = AddClickListener(self)
        grid.addComponent(Button('Add \"Test marker2\"', l))

        l = ToggleMarkerClickListener(self)
        grid.addComponent(Button('Toggle marker 1 icon', l))

        l = ToggleLoggingClickListener(self)
        grid.addComponent(Button('Toggle client logging', l))

        # Popup test
        l = PopupClickListener(self)
        grid.addComponent(Button('Open a map in a popup', l))

        l = ResizeClickListener(self)
        grid.addComponent(Button('Resize map', l))

        l = DrawClickListener(self)
        grid.addComponent(Button('Draw polygon', l))

        l = RemovePolygonClickListener(self)
        grid.addComponent(Button('Remove first polygon', l))
示例#15
0
    def __init__(self):
        super(GridLayoutBasicExample, self).__init__()

        # Create a grid layout
        grid = GridLayout(3, 3)
        grid.setSpacing(True)

        # The style allows us to visualize the cell borders in this example.
        grid.addStyleName('gridexample')

        grid.setWidth(400, ISizeable.UNITS_PIXELS)
        grid.setHeight(400, ISizeable.UNITS_PIXELS)

        # First we insert four components that occupy one cell each
        topleft = Button('Top Left')
        grid.addComponent(topleft, 0, 0)
        grid.setComponentAlignment(topleft, Alignment.MIDDLE_CENTER)

        topcenter = Button('Top Center')
        grid.addComponent(topcenter, 1, 0)
        grid.setComponentAlignment(topcenter, Alignment.MIDDLE_CENTER)

        bottomleft = Button('Bottom Left')
        grid.addComponent(bottomleft, 0, 2)
        grid.setComponentAlignment(bottomleft, Alignment.MIDDLE_CENTER)

        bottomcenter = Button('Bottom Center')
        grid.addComponent(bottomcenter, 1, 2)
        grid.setComponentAlignment(bottomcenter, Alignment.MIDDLE_CENTER)

        # Insert a component that occupies all the rightmost cells
        topright = Button('Extra height')
        grid.addComponent(topright, 2, 0, 2, 2)
        grid.setComponentAlignment(topright, Alignment.MIDDLE_CENTER)

        # Insert a component that occupies two cells in horizontal direction
        middleleft = Button('This is a wide cell in GridLayout')
        grid.addComponent(middleleft, 0, 1, 1, 1)
        grid.setComponentAlignment(middleleft, Alignment.MIDDLE_CENTER)

        # Add the layout to the containing layout.
        self.addComponent(grid)

        # Align the grid itself within its container layout.
        self.setComponentAlignment(grid, Alignment.MIDDLE_CENTER)
示例#16
0
    def __init__(self):
        super(LayoutAlignmentExample, self).__init__()

        # Create a grid layout
        grid = GridLayout(1, 9)
        grid.setSpacing(True)

        # The style allows us to visualize the cell borders in this example.
        grid.addStyleName('gridexample')

        grid.setWidth('300px')
        grid.setHeight('500px')

        # Put a component in each cell with respective alignment.
        # We'll use different ways to set the alignment: constants, bitmasks,
        # and string-shorthand.

        # Here we use the shorthand constants to set the alignment:
        # Alignment.TOP_LEFT, Alignment.TOP_CENTER, Alignment.TOP_RIGHT
        # Alignment.MIDDLE_LEFT, Alignment.MIDDLE_CENTER,
        # Alignment.MIDDLE_RIGHT
        # Alignment.BOTTOM_LEFT, Alignment.BOTTOM_CENTER,
        # Alignment.BOTTOM_RIGHT

        topleft = Button('Top Left')
        grid.addComponent(topleft)
        grid.setComponentAlignment(topleft, Alignment.TOP_LEFT)

        topcenter = Button('Top Center')
        grid.addComponent(topcenter)
        grid.setComponentAlignment(topcenter, Alignment.TOP_CENTER)

        topright = Button('Top Right')
        grid.addComponent(topright)
        grid.setComponentAlignment(topright, Alignment.TOP_RIGHT)

        # Here we use bit additions to set the alignment:
        # Bits.ALIGNMENT_LEFT, Bits.ALIGNMENT_RIGHT
        # Bits.ALIGNMENT_TOP, Bits.ALIGNMENT_BOTTOM
        # Bits.ALIGNMENT_VERTICAL_CENTER, Bits.ALIGNMENT_HORIZONTAL_CENTER

        middleleft = Button('Middle Left')
        grid.addComponent(middleleft)
        grid.setComponentAlignment(middleleft, Alignment(
            Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_LEFT))

        middlecenter = Button('Middle Center')
        grid.addComponent(middlecenter)
        grid.setComponentAlignment(middlecenter, Alignment(
            Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_HORIZONTAL_CENTER))

        middleright = Button('Middle Right')
        grid.addComponent(middleright)
        grid.setComponentAlignment(middleright, Alignment(
            Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_RIGHT))

        # Here we'll use the convenient string-shorthand:

        bottomleft = Button('Bottom Left')
        grid.addComponent(bottomleft)
        grid.setComponentAlignment(bottomleft, Alignment.BOTTOM_LEFT)

        bottomcenter = Button('Bottom Center')
        grid.addComponent(bottomcenter)
        grid.setComponentAlignment(bottomcenter, Alignment.BOTTOM_CENTER)

        bottomright = Button('Bottom Right')
        grid.addComponent(bottomright)
        grid.setComponentAlignment(bottomright, Alignment.BOTTOM_RIGHT)

        # Add the layout to the containing layout.
        self.addComponent(grid)

        # Align the grid itself within its container layout.
        self.setComponentAlignment(grid, Alignment.MIDDLE_CENTER)
    def init(self):
        mainWindow = Window('CodeMirror Sample Application')

        hl = GridLayout(2, 5)
        hl.setSpacing(True)
        mainWindow.addComponent(hl)

        # #1
        code = CodeMirror('Your Code', CodeMode.TEXT)
        code.setValue(self._SAMPLE_CODE)
        code.setWidth('500px')
        code.setHeight('350px')
        hl.addComponent(code)

        # #2
        code2 = CodeMirror('Your Code Too', CodeMode.PYTHON)
        code2.setValue(self._SAMPLE_CODE)
#        code2.setWidth('400px')
#        code2.setHeight('300px')
        hl.addComponent(code2)


        codeMode = Select('Select your mode')
        for cs in CodeMode.values():
            codeMode.addItem(cs)
        codeMode.setNewItemsAllowed(False)
        codeMode.setNullSelectionAllowed(False)
        codeMode.setImmediate(True)
        hl.addComponent(codeMode)

        l = CodeModeChangeListener(code, codeMode)
        codeMode.addListener(l, IValueChangeListener)
        codeMode.setValue(CodeMode.TEXT)

        codeMode = Select('Select your mode too')
        for cs in CodeMode.values():
            codeMode.addItem(cs)
        codeMode.setNewItemsAllowed(False)
        codeMode.setNullSelectionAllowed(False)
        codeMode.setImmediate(True)
        hl.addComponent(codeMode)

        l = CodeModeChangeListener(code2, codeMode)
        codeMode.addListener(l, IValueChangeListener)
        codeMode.setValue(CodeMode.PYTHON)


        codeTheme = Select('Select your theme')
        for ct in CodeTheme.values():
            codeTheme.addItem(ct)
        codeTheme.setNewItemsAllowed(False)
        codeTheme.setImmediate(True)
        hl.addComponent(codeTheme)

        l = CodeThemeChangeListener(code, codeTheme)
        codeTheme.addListener(l, IValueChangeListener)
        codeTheme.setValue(CodeTheme.DEFAULT)

        codeTheme = Select('Select your theme too')
        for ct in CodeTheme.values():
            codeTheme.addItem(ct)
        codeTheme.setNewItemsAllowed(False)
        codeTheme.setImmediate(True)
        hl.addComponent(codeTheme)

        l = CodeThemeChangeListener(code2, codeTheme)
        codeTheme.addListener(l, IValueChangeListener)
        codeTheme.setValue(CodeTheme.ECLIPSE)


        l = CopyClickListener(code, code2)
        hl.addComponent(Button('copy to -->', l))

        l = CopyClickListener(code2, code)
        hl.addComponent(Button('<- copy to', l))


        l = ShowLineNumbersListener(code)
        cb = CheckBox("Show line numbers", l)
        cb.setImmediate(True)
        hl.addComponent(cb)

        l = ShowLineNumbersListener(code2)
        cb = CheckBox("Show line numbers", l)
        cb.setImmediate(True)
        hl.addComponent(cb)


        self.setMainWindow(mainWindow)