def __init__(self, designer, **kwargs):
     '''Builds the widget_menu for the first time, and this
     function is never called again. 
     While building all the widget nodes are saved in a list called
     'saved_nodes' (without any binding) for future use'''
     
     super(NewWidgetsMenu, self).__init__(**kwargs)
     self.designer = designer
     self.canvas_area = designer.canvas_area
     self.popup = None
     
     self.keys=[]
     self.layout_keys = []
     for cls in self.widget_list:
         if cls == "Camera":
             '''This is because there seems to be some bug in Gstreamer
             when we load a camera widget and don't use it '''
             continue
         try:
             factory_caller = getattr(Factory, str(cls))
             new_widget = factory_caller()
             if isinstance(new_widget, Layout):
                 self.layout_keys.append(cls)
                 continue
             if isinstance(new_widget, Widget):
                 self.keys.append(cls)
         except Exception as err:
             pass
             #self.status_bar.print_status(err.message)
     self.keys.append('Camera')
     self.keys.sort()
     self.layout_keys.sort()
     
     '''Adding all the widgets to the menu'''
     node = TreeViewLabel(text= " Widgets", bold = True, \
                          color=[.25, .5, .6, 1])
     self.treeview.add_node(node)
     self.saved_nodes.append(node)
     node = None
     for key in self.keys:
         text = '%s' % key
         node = TreeViewLabel(text=text)
         node_copy = copy.copy(node)
         self.saved_nodes.append(node_copy)
         node.bind(is_selected = self.add_new_widget)
         self.treeview.add_node(node)
         
     
     '''Adding all the Layouts to the menu'''
     node = TreeViewLabel(text= "Layouts ", bold = True, \
                          color=[.25, .5, .6, 1])
     self.treeview.add_node(node)
     self.saved_nodes.append(node)
     for key in self.layout_keys:
         text = '%s' % key
         node = TreeViewLabel(text = text)
         node_copy = copy.copy(node)
         self.saved_nodes.append(node_copy)
         node.bind(is_selected = self.add_new_widget)
         self.treeview.add_node(node)
Beispiel #2
0
    def _load_local_documents(self):
        for document in DocumentDao().list():
            document_label = TreeViewLabel(text="%s - %s" %
                                           (document.location, document.name))

            document_label.bind(on_touch_down=partial(
                self._open_document, document_location=document.location))
            self.add_node(document_label, parent=self.local_documents)
Beispiel #3
0
    def __init__(self, designer, **kwargs):
        '''Builds the widget_menu for the first time, and this
        function is never called again. 
        While building all the widget nodes are saved in a list called
        'saved_nodes' (without any binding) for future use'''

        super(NewWidgetsMenu, self).__init__(**kwargs)
        self.designer = designer
        self.canvas_area = designer.canvas_area
        self.popup = None

        self.keys = []
        self.layout_keys = []
        for cls in self.widget_list:
            if cls == "Camera":
                '''This is because there seems to be some bug in Gstreamer
                when we load a camera widget and don't use it '''
                continue
            try:
                factory_caller = getattr(Factory, str(cls))
                new_widget = factory_caller()
                if isinstance(new_widget, Layout):
                    self.layout_keys.append(cls)
                    continue
                if isinstance(new_widget, Widget):
                    self.keys.append(cls)
            except Exception as err:
                pass
                #self.status_bar.print_status(err.message)
        self.keys.append('Camera')
        self.keys.sort()
        self.layout_keys.sort()
        '''Adding all the widgets to the menu'''
        node = TreeViewLabel(text= " Widgets", bold = True, \
                             color=[.25, .5, .6, 1])
        self.treeview.add_node(node)
        self.saved_nodes.append(node)
        node = None
        for key in self.keys:
            text = '%s' % key
            node = TreeViewLabel(text=text)
            node_copy = copy.copy(node)
            self.saved_nodes.append(node_copy)
            node.bind(is_selected=self.add_new_widget)
            self.treeview.add_node(node)
        '''Adding all the Layouts to the menu'''
        node = TreeViewLabel(text= "Layouts ", bold = True, \
                             color=[.25, .5, .6, 1])
        self.treeview.add_node(node)
        self.saved_nodes.append(node)
        for key in self.layout_keys:
            text = '%s' % key
            node = TreeViewLabel(text=text)
            node_copy = copy.copy(node)
            self.saved_nodes.append(node_copy)
            node.bind(is_selected=self.add_new_widget)
            self.treeview.add_node(node)
Beispiel #4
0
    def add_nkeys(self, tree, data, n):
        self.lock.acquire()
        self.clear_tree(self.values)

        for key in data:
            node = TreeViewLabel(text=key)
            node.bind(on_touch_down=self.suggestion_node_clicked)
            self.values.add_node(node)
            count = count + 1
        self.lock.release()
    def add_file_to_tree_view(self, _file):
        '''This function is used to insert py file given by it's path argument
           _file. It will also insert any directory node if not present.
        '''

        self.tree_view.root_options = dict(text='')
        dirname = os.path.dirname(_file)
        dirname = dirname.replace(self.proj_loader.proj_dir, '')
        # The way os.path.dirname works, there will never be '/' at the end
        # of a directory. So, there will always be '/' at the starting
        # of 'dirname' variable after removing proj_dir

        # This algorithm first breaks path into its components
        # and creates a list of these components.
        _dirname = dirname
        _basename = 'a'
        list_path_components = []
        while _basename != '':
            _split = os.path.split(_dirname)
            _dirname = _split[0]
            _basename = _split[1]
            list_path_components.insert(0, _split[1])

        if list_path_components[0] == '':
            del list_path_components[0]

        # Then it traverses from root_node to its children searching from
        # each component in the path. If it doesn't find any component
        # related with node then it creates it.
        node = self._root_node
        while list_path_components != []:
            found = False
            for _node in node.nodes:
                if _node.text == list_path_components[0]:
                    node = _node
                    found = True
                    break

            if not found:
                for component in list_path_components:
                    _node = TreeViewLabel(text=component)
                    self.tree_view.add_node(_node, node)
                    node = _node
                list_path_components = []
            else:
                del list_path_components[0]

        # Finally add file_node with node as parent.
        file_node = TreeViewLabel(text=os.path.basename(_file))
        file_node.bind(on_touch_down=self._file_node_clicked)
        self.tree_view.add_node(file_node, node)

        self.tree_view.root_options = dict(
            text=os.path.basename(self.proj_loader.proj_dir))
Beispiel #6
0
    def add_file_to_tree_view(self, _file):
        '''This function is used to insert py file given by it's path argument
           _file. It will also insert any directory node if not present.
        '''

        self.tree_view.root_options = dict(text='')
        dirname = os.path.dirname(_file)
        dirname = dirname.replace(self.proj_loader.proj_dir, '')
        #The way os.path.dirname works, there will never be '/' at the end
        #of a directory. So, there will always be '/' at the starting
        #of 'dirname' variable after removing proj_dir

        #This algorithm first breaks path into its components
        #and creates a list of these components.
        _dirname = dirname
        _basename = 'a'
        list_path_components = []
        while _basename != '':
            _split = os.path.split(_dirname)
            _dirname = _split[0]
            _basename = _split[1]
            list_path_components.insert(0, _split[1])

        if list_path_components[0] == '':
            del list_path_components[0]

        #Then it traverses from root_node to its children searching from
        #each component in the path. If it doesn't find any component
        #related with node then it creates it.
        node = self._root_node
        while list_path_components != []:
            found = False
            for _node in node.nodes:
                if _node.text == list_path_components[0]:
                    node = _node
                    found = True
                    break

            if not found:
                for component in list_path_components:
                    _node = TreeViewLabel(text=component)
                    self.tree_view.add_node(_node, node)
                    node = _node
                list_path_components = []
            else:
                del list_path_components[0]

        #Finally add file_node with node as parent.
        file_node = TreeViewLabel(text=os.path.basename(_file))
        file_node.bind(on_touch_down=self._file_node_clicked)
        self.tree_view.add_node(file_node, node)

        self.tree_view.root_options = dict(
            text=os.path.basename(self.proj_loader.proj_dir))
Beispiel #7
0
 def draw_tree(self, root, root_node):
     '''A recursive function to traverse the complete widget tree and
     build the WidgetTree.
     Here 'root' will be the widget in question, and 'root_node'
     a TreeViewLabel denoting the widget'''
     treeview = self.treeview
     for child in root.children:
         node = TreeViewLabel(text=child.__class__.__name__)
         node.bind(is_selected=partial(self.notify_canvas, child))
         self.widget_dict[node.uid] = child
         treeview.add_node(node, root_node)
         self.draw_tree(child, node)
Beispiel #8
0
 def draw_tree(self, root, root_node):
     '''A recursive function to traverse the complete widget tree and
     build the WidgetTree.
     Here 'root' will be the widget in question, and 'root_node'
     a TreeViewLabel denoting the widget'''
     treeview = self.treeview
     for child in root.children:
         node = TreeViewLabel(text = child.__class__.__name__)
         node.bind(is_selected = partial(self.notify_canvas, child))
         self.widget_dict[node.uid] = child 
         treeview.add_node(node, root_node)
         self.draw_tree(child, node)
Beispiel #9
0
 def on_entries(self, instance, value):
     if "viewlist" not in self.ids:
         return
     viewlist = self.ids["viewlist"]
     viewlist.clear_widgets()
     for elem in self.entries:
         lab = TreeViewLabel(text=elem[0])
         lab.color = elem[1]
         if len(elem) == 3:
             lab.message = elem[2]
         else:
             lab.message = elem[0]
         lab.bind(on_touch_down=self._call2)
         viewlist.add_node(lab)
 def build_menu(self, parent = None):
     '''This is a general purpose function that builds the
     main menu at anytime. Note that it binds each node to 
     self.add_new_widget. 
     I should really aim at making a build_menu function that 
     accepts a partial object as its argument and 
     binds it to each node. But currently the unbinding is too
     messy to spend time on as I am not using it anywhere else.
     
     This function's main use case is to display addable widgets and 
     layouts to a selected layout in canvas_area.
     It is called from Designer.rebuild_menu() '''
     
     treeview = self.treeview
     #Copy all current nodes in a temp list
     temp = list(treeview.iterate_all_nodes())
     #Delete them.
     for node in temp:
         treeview.remove_node(node)
     keys = self.keys
     layout_keys = self.layout_keys    
     
     '''Adding all the widgets to the menu'''
     node = TreeViewLabel(text= " Widgets", bold = True, \
                          color=[.25, .5, .6, 1])
     self.treeview.add_node(node)
     for key in keys:
         text = '%s' % key
         node = TreeViewLabel(text=text)
         node.bind(is_selected = partial(self.add_new_widget, parent = parent))
         self.treeview.add_node(node)
         
     
     '''Adding all the Layouts to the menu'''
     node = TreeViewLabel(text= "Layouts ", bold = True, \
                          color=[.25, .5, .6, 1])
     self.treeview.add_node(node)
     for key in layout_keys:
         text = '%s' % key
         node = TreeViewLabel(text = text)
         node.bind(is_selected = partial(self.add_new_widget, parent = parent))
         self.treeview.add_node(node)
Beispiel #11
0
    def build_menu(self, parent=None):
        '''This is a general purpose function that builds the
        main menu at anytime. Note that it binds each node to 
        self.add_new_widget. 
        I should really aim at making a build_menu function that 
        accepts a partial object as its argument and 
        binds it to each node. But currently the unbinding is too
        messy to spend time on as I am not using it anywhere else.
        
        This function's main use case is to display addable widgets and 
        layouts to a selected layout in canvas_area.
        It is called from Designer.rebuild_menu() '''

        treeview = self.treeview
        #Copy all current nodes in a temp list
        temp = list(treeview.iterate_all_nodes())
        #Delete them.
        for node in temp:
            treeview.remove_node(node)
        keys = self.keys
        layout_keys = self.layout_keys
        '''Adding all the widgets to the menu'''
        node = TreeViewLabel(text= " Widgets", bold = True, \
                             color=[.25, .5, .6, 1])
        self.treeview.add_node(node)
        for key in keys:
            text = '%s' % key
            node = TreeViewLabel(text=text)
            node.bind(is_selected=partial(self.add_new_widget, parent=parent))
            self.treeview.add_node(node)
        '''Adding all the Layouts to the menu'''
        node = TreeViewLabel(text= "Layouts ", bold = True, \
                             color=[.25, .5, .6, 1])
        self.treeview.add_node(node)
        for key in layout_keys:
            text = '%s' % key
            node = TreeViewLabel(text=text)
            node.bind(is_selected=partial(self.add_new_widget, parent=parent))
            self.treeview.add_node(node)
Beispiel #12
0
    def __init__(self, designer, **kwargs):
        super(PropertiesMenu, self).__init__(**kwargs)
        self.designer = designer
        self.status_bar = designer.status_bar
        widget = designer.widget
        designer.status_bar.print_status("Focussed on %s" % (str(widget)), t=6)

        self.numeric_keys, self.boolean_keys, self.string_keys,\
         self.remaining_keys = ([] for i in range(4))

        treeview = self.treeview
        '''Adding a back button'''
        treeview.height = 30
        node = TreeViewLabel(text="< BACK TO ADD MORE WIDGETS", \
                             color=[1, 1, 0, 1], bold=True)
        node.bind(is_selected=self.designer.rebuild_menu)
        node.bind(is_selected=self.designer.clear_selection)
        #Is this the right way to call 2 functions from a property change?
        treeview.add_node(node)
        '''If the widget is a layout, we need to provide
       an option to add more widgets to this layout'''
        if isinstance(widget, Layout):
            treeview.height = 30
            node = TreeViewLabel(text="Add widgets to this Layout", \
                                 color=[.4, 1, 0, 1])
            node.bind(
                is_selected=partial(designer.rebuild_menu, parent=widget))
            # Fix-this : Above's parent argument is not being passed :(
            treeview.add_node(node)
        '''Adding a delete button'''
        node = TreeViewLabel(text= "Delete this widget",\
                             color=[1, 0, 0, 1])
        node.bind(is_selected=self.designer.delete_item)
        treeview.add_node(node)

        treeview.height = 25
        keys = widget.properties().keys()
        #Here we sort out the keys into different types
        keys.sort()
        for key in keys:
            if isinstance(widget.property(key), NumericProperty):
                self.numeric_keys.append(key)
            elif isinstance(widget.property(key), StringProperty):
                self.string_keys.append(key)
            elif isinstance(widget.property(key), BooleanProperty):
                self.boolean_keys.append(key)
            elif isinstance(widget.property(key), AliasProperty):
                value = getattr(widget, key)
                if type(value) in (unicode, str):
                    self.string_keys.append(key)
                elif type(value) in (int, float):
                    self.numeric_keys.append(key)
                else:
                    self.remaining_keys.append(key)
            else:
                self.remaining_keys.append(key)

        wk_widget = weakref.ref(widget)
        # Adding all the Boolean keys
        if self.boolean_keys:
            node = TreeViewLabel(text="Boolean properties", \
                                 bold = True, color=[.25, .5, .6, 1])
            treeview.add_node(node)
            for key in self.boolean_keys:
                node = TreeViewPropertyBoolean(key=key, widget_ref=wk_widget)
                node.toggle.bind(state=partial(self.save_properties, \
                                               widget, key))
                treeview.add_node(node)

        #Adding all the Numeric keys
        if self.numeric_keys:
            node = TreeViewLabel(text="Numeric properties", \
                                 bold = True, color=[.25, .5, .6, 1])
            treeview.add_node(node)
            for key in self.numeric_keys:
                node = TreeViewPropertyText(key=key, \
                                                widget_ref=wk_widget)
                node.textbox.bind(text=partial(self.save_properties,\
                                               widget, key))
                treeview.add_node(node)

        #Adding all String keys
        if self.string_keys:
            node = TreeViewLabel(text="String properties", \
                                 bold = True, color=[.25, .5, .6, 1])
            treeview.add_node(node)
            for key in self.string_keys:
                node = TreeViewPropertyText(key=key, \
                                                widget_ref=wk_widget)
                node.textbox.bind(text=partial(self.save_properties,\
                                               widget, key))
                treeview.add_node(node)

        #Adding the remaining keys
        if self.remaining_keys:
            node = TreeViewLabel(text="Other properties", \
                                 bold = True, color=[.25, .5, .6, 1])
            treeview.add_node(node)
            for key in self.remaining_keys:
                node = TreeViewPropertyText(key=key, \
                                                widget_ref=wk_widget)
                node.textbox.bind(text=partial(self.save_properties,\
                                               widget, key))
                treeview.add_node(node)