(self, layoutname)
Create all the parts necessary to satisfy the specified layout
Create all the parts necessary to satisfy the specified layout
Create all the parts necessary to satisfy the specified layout
def create_layout(self, layoutname):
        """Create all the parts necessary to satisfy the specified layout"""
        layout = None
        objects = {}

        self.doing_layout = True
        self.last_active_window = None
        self.prelayout_windows = self.windows[:]

        layout = copy.deepcopy(self.config.layout_get_config(layoutname))
        if not layout:
            # User specified a non-existent layout. default to one Terminal
            err('layout %s not defined' % layout)
            self.new_window()
            return

        # Wind the flat objects into a hierarchy
        hierarchy = {}
        count = 0
        # Loop over the layout until we have consumed it, or hit 1000 loops.
        # This is a stupid artificial limit, but it's safe.
        while len(layout) > 0 and count < 1000:
            count = count + 1
            if count == 1000:
                err('hit maximum loop boundary. THIS IS VERY LIKELY A BUG')
            for obj in list(layout.keys()):
                if layout[obj]['type'].lower() == 'window':
                    hierarchy[obj] = {}
                    hierarchy[obj]['type'] = 'Window'
                    hierarchy[obj]['children'] = {}

                    # Copy any additional keys
                    for objkey in list(layout[obj].keys()):
                        if layout[obj][objkey] != '' and objkey not in hierarchy[obj]:
                            hierarchy[obj][objkey] = layout[obj][objkey]

                    objects[obj] = hierarchy[obj]
                    del(layout[obj])
                else:
                    # Now examine children to see if their parents exist yet
                    if 'parent' not in layout[obj]:
                        err('Invalid object: %s' % obj)
                        del(layout[obj])
                        continue
                    if layout[obj]['parent'] in objects:
                        # Our parent has been created, add ourselves
                        childobj = {}
                        childobj['type'] = layout[obj]['type']
                        childobj['children'] = {}

                        # Copy over any additional object keys
                        for objkey in list(layout[obj].keys()):
                            if objkey not in childobj:
                                childobj[objkey] = layout[obj][objkey]

                        objects[layout[obj]['parent']]['children'][obj] = childobj
                        objects[obj] = childobj
                        del(layout[obj])

        layout = hierarchy

        for windef in layout:
            if layout[windef]['type'] != 'Window':
                err('invalid layout format. %s' % layout)
                raise(ValueError)
            dbg('Creating a window')
            window, terminal = self.new_window()
            if 'position' in layout[windef]:
                parts = layout[windef]['position'].split(':')
                if len(parts) == 2:
                    window.move(int(parts[0]), int(parts[1]))
            if 'size' in layout[windef]:
                parts = layout[windef]['size']
                winx = int(parts[0])
                winy = int(parts[1])
                if winx > 1 and winy > 1:
                    window.resize(winx, winy)
            if 'title' in layout[windef]:
                window.title.force_title(layout[windef]['title'])
            if 'maximised' in layout[windef]:
                if layout[windef]['maximised'] == 'True':
                    window.ismaximised = True
                else:
                    window.ismaximised = False
                window.set_maximised(window.ismaximised)
            if 'fullscreen' in layout[windef]:
                if layout[windef]['fullscreen'] == 'True':
                    window.isfullscreen = True
                else:
                    window.isfullscreen = False
                window.set_fullscreen(window.isfullscreen)
            window.create_layout(layout[windef])

        self.layoutname = layoutname
def create_layout ( self , layoutname ) : layout = None objects = { } self . doing_layout = True self . last_active_window = None self . prelayout_windows = self . windows [ : ] layout = copy . deepcopy ( self . config . layout_get_config ( layoutname ) ) if not layout : # User specified a non-existent layout. default to one Terminal err ( 'layout %s not defined' % layout ) self . new_window ( ) return # Wind the flat objects into a hierarchy hierarchy = { } count = 0 # Loop over the layout until we have consumed it, or hit 1000 loops. # This is a stupid artificial limit, but it's safe. while len ( layout ) > 0 and count < 1000 : count = count + 1 if count == 1000 : err ( 'hit maximum loop boundary. THIS IS VERY LIKELY A BUG' ) for obj in list ( layout . keys ( ) ) : if layout [ obj ] [ 'type' ] . lower ( ) == 'window' : hierarchy [ obj ] = { } hierarchy [ obj ] [ 'type' ] = 'Window' hierarchy [ obj ] [ 'children' ] = { } # Copy any additional keys for objkey in list ( layout [ obj ] . keys ( ) ) : if layout [ obj ] [ objkey ] != '' and objkey not in hierarchy [ obj ] : hierarchy [ obj ] [ objkey ] = layout [ obj ] [ objkey ] objects [ obj ] = hierarchy [ obj ] del ( layout [ obj ] ) else : # Now examine children to see if their parents exist yet if 'parent' not in layout [ obj ] : err ( 'Invalid object: %s' % obj ) del ( layout [ obj ] ) continue if layout [ obj ] [ 'parent' ] in objects : # Our parent has been created, add ourselves childobj = { } childobj [ 'type' ] = layout [ obj ] [ 'type' ] childobj [ 'children' ] = { } # Copy over any additional object keys for objkey in list ( layout [ obj ] . keys ( ) ) : if objkey not in childobj : childobj [ objkey ] = layout [ obj ] [ objkey ] objects [ layout [ obj ] [ 'parent' ] ] [ 'children' ] [ obj ] = childobj objects [ obj ] = childobj del ( layout [ obj ] ) layout = hierarchy for windef in layout : if layout [ windef ] [ 'type' ] != 'Window' : err ( 'invalid layout format. %s' % layout ) raise ( ValueError ) dbg ( 'Creating a window' ) window , terminal = self . new_window ( ) if 'position' in layout [ windef ] : parts = layout [ windef ] [ 'position' ] . split ( ':' ) if len ( parts ) == 2 : window . move ( int ( parts [ 0 ] ) , int ( parts [ 1 ] ) ) if 'size' in layout [ windef ] : parts = layout [ windef ] [ 'size' ] winx = int ( parts [ 0 ] ) winy = int ( parts [ 1 ] ) if winx > 1 and winy > 1 : window . resize ( winx , winy ) if 'title' in layout [ windef ] : window . title . force_title ( layout [ windef ] [ 'title' ] ) if 'maximised' in layout [ windef ] : if layout [ windef ] [ 'maximised' ] == 'True' : window . ismaximised = True else : window . ismaximised = False window . set_maximised ( window . ismaximised ) if 'fullscreen' in layout [ windef ] : if layout [ windef ] [ 'fullscreen' ] == 'True' : window . isfullscreen = True else : window . isfullscreen = False window . set_fullscreen ( window . isfullscreen ) window . create_layout ( layout [ windef ] ) self . layoutname = layoutname