def _load(self):
     """
     Load the treeview with database information
     """
     self.commands_node = self.insert("",
                                      "end",
                                      "commands",
                                      text="Commands",
                                      image=CommandView.getClassIcon())
     commands = Command.fetchObjects({})
     for command in commands:
         command_vw = CommandView(self, self.appli.commandsViewFrame,
                                  self.appli, CommandController(command))
         command_vw.addInTreeview()
     self.group_command_node = self.insert(
         "",
         "end",
         str("command_groups"),
         text="Command Groups",
         image=CommandGroupView.getClassIcon())
     command_groups = CommandGroup.fetchObjects({})
     for command_group in command_groups:
         command_group_vw = CommandGroupView(
             self, self.appli.commandsViewFrame, self.appli,
             CommandGroupController(command_group))
         command_group_vw.addInTreeview()
    def notify(self, db, collection, iid, action, parent):
        """
        Callback for the observer pattern implemented in mongo.py.

        Args:
            collection: the collection that has been modified
            iid: the mongo ObjectId _id that was modified/inserted/deleted
            action: update/insert/delete. It was the action performed on the iid
            parent: the mongo ObjectId of the parent. Only if action in an insert.
        """
        if db != "pollenisator":
            return
        # Delete
        mongoInstance = MongoCalendar.getInstance()
        if action == "delete":
            try:
                self.delete(ObjectId(iid))
            except tk.TclError:
                pass  # item was not inserted in the treeview

        # Insert
        if action == "insert":
            res = mongoInstance.findInDb(db, collection,
                                         {"_id": ObjectId(iid)}, False)
            if collection == "commands":
                view = CommandView(self, self.appli.commandsViewFrame,
                                   self.appli, CommandController(Command(res)))
                parent = None
            elif collection == "group_commands":
                view = CommandGroupView(
                    self, self.appli.commandsViewFrame, self.appli,
                    CommandGroupController(CommandGroup(res)))
                parent = None
            try:
                view.addInTreeview(parent)
                if view is not None:
                    view.insertReceived()
            except tk.TclError:
                pass

        if action == "update":
            try:
                view = self.getViewFromId(str(iid))
                if view is not None:
                    self.item(str(iid),
                              text=str(view.controller.getModelRepr()),
                              image=view.getIcon())
            except tk.TclError:
                if view is not None:
                    view.addInTreeview()
            if str(self.appli.openedViewFrameId) == str(iid):
                for widget in self.appli.viewframe.winfo_children():
                    widget.destroy()
                view.openModifyWindow()
            if view is not None:
                view.controller.actualize()
                view.updateReceived()
 def onTreeviewSelect(self, event=None):
     """Called when a line is selected on the treeview
     Open the selected object view on the view frame.
     Args:
         _event: not used but mandatory
     """
     selection = self.selection()
     if len(selection) == 1:
         item = super().onTreeviewSelect(event)
         if isinstance(item, str):
             mongoInstance = MongoCalendar.getInstance()
             self.saveState(mongoInstance.calendarName)
             if str(item) == "waves":
                 objView = WaveView(self, self.appli.viewframe, self.appli,
                                    WaveController(Wave()))
                 objView.openInsertWindow()
             elif str(item) == "commands":
                 objView = CommandView(
                     self, self.appli.viewframe, self.appli,
                     CommandController(
                         Command({"indb": mongoInstance.calendarName})))
                 objView.openInsertWindow()
             elif str(item) == "ips":
                 objView = MultipleIpView(self, self.appli.viewframe,
                                          self.appli, IpController(Ip()))
                 objView.openInsertWindow()
             elif "intervals" in str(item):
                 wave = Wave.fetchObject({
                     "_id":
                     ObjectId(IntervalView.treeviewListIdToDb(item))
                 })
                 objView = IntervalView(
                     self, self.appli.viewframe, self.appli,
                     IntervalController(Interval().initialize(wave.wave)))
                 objView.openInsertWindow()
             elif "scopes" in str(item):
                 wave = Wave.fetchObject(
                     {"_id": ObjectId(ScopeView.treeviewListIdToDb(item))})
                 objView = MultipleScopeView(
                     self, self.appli.viewframe, self.appli,
                     ScopeController(Scope().initialize(wave.wave)))
                 objView.openInsertWindow()
         else:
             self.openModifyWindowOf(item)
     elif len(selection) > 1:
         # Multi select:
         multiView = MultiSelectionView(self, self.appli.viewframe,
                                        self.appli)
         for widget in self.appli.viewframe.winfo_children():
             widget.destroy()
         multiView.form.clear()
         multiView.openModifyWindow()
 def onTreeviewSelect(self, event=None):
     """Called when a line is selected on the treeview
     Open the selected object view on the view frame.
     IF it's a parent commands or command_groups node, opens Insert
     ELSE open a modify window
     Args:
         event: filled with the callback, contains data about line clicked
     """
     item = super().onTreeviewSelect(event)
     if isinstance(item, str):
         if str(item) == "commands":
             objView = CommandView(self, self.appli.commandsViewFrame,
                                   self.appli, CommandController(Command()))
             objView.openInsertWindow()
         elif str(item) == "command_groups":
             objView = CommandGroupView(
                 self, self.appli.commandsViewFrame, self.appli,
                 CommandGroupController(CommandGroup()))
             objView.openInsertWindow()
     else:
         self.openModifyWindowOf(item)
Beispiel #5
0
    def _load(self):
        """
        Load the treeview with database information
        """
        mongoInstance = MongoCalendar.getInstance()
        dialog = ChildDialogProgress(self.appli, "Loading "+str(
            mongoInstance.calendarName), "Opening "+str(mongoInstance.calendarName) + ". Please wait for a few seconds.", 200, "determinate")
        step = 0
        dialog.show(100)
        nbObjects = mongoInstance.find("waves").count()
        nbObjects += mongoInstance.find("scopes").count()
        nbObjects += mongoInstance.find("intervals").count()
        nbObjects += mongoInstance.find("scopes").count()
        nbObjects += mongoInstance.find("ips").count()
        nbObjects += mongoInstance.find("ports").count()
        nbObjects += mongoInstance.find("tools").count()
        nbObjects += mongoInstance.find("commands").count()
        onePercentNbObject = nbObjects//100 if nbObjects > 100 else 1
        nbObjectTreated = 0
        for child in self.get_children():
            self.delete(child)
        self._hidden = []
        self._detached = []
        self.waves_node = self.insert("", "end", str(
            "waves"), text="Waves", image=WaveView.getClassIcon())
        # Loading every category separatly is faster than recursivly.
        # This is due to cursor.next function calls in pymongo
        # Adding wave objects

        self.commands_node = self.insert(
            "", "end", "commands", text="Commands", image=CommandView.getClassIcon())
        commands = Command.fetchObjects({}, mongoInstance.calendarName)
        for command in commands:
            command_vw = CommandView(
                self, self.appli.viewframe, self.appli, CommandController(command))
            command_vw.addInTreeview()

        waves = Wave.fetchObjects({})
        for wave in waves:
            wave_o = WaveController(wave)
            wave_vw = WaveView(self, self.appli.viewframe, self.appli, wave_o)
            wave_vw.addInTreeview(self.waves_node, False)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        scopes = Scope.fetchObjects({})
        for scope in scopes:
            scope_o = ScopeController(scope)
            scope_vw = ScopeView(self, self.appli.viewframe, self.appli, scope_o)
            scope_vw.addInTreeview(None, False)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        intervals = Interval.fetchObjects({})
        for interval in intervals:
            interval_o = IntervalController(interval)
            interval_vw = IntervalView(self, self.appli.viewframe, self.appli, interval_o)
            interval_vw.addInTreeview(None, False)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding ip objects
        self.ips_node = self.insert("", "end", str(
            "ips"), text="IPs", image=IpView.getClassIcon())
        ips = Ip.fetchObjects({})
        for ip in ips:
            ip_o = IpController(ip)
            ip_vw = IpView(self, self.appli.viewframe, self.appli, ip_o)
            ip_vw.addInTreeview(None, False)
            self.appli.statusbar.notify(ip_vw.controller.getTags())
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding port objects
        ports = Port.fetchObjects({})
        for port in ports:
            port_o = PortController(port)
            port_vw = PortView(self, self.appli.viewframe, self.appli, port_o)
            port_vw.addInTreeview(None, False)
            self.appli.statusbar.notify(port_vw.controller.getTags())
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding defect objects
        defects = Defect.fetchObjects({"ip":{"$ne":""}})
        for defect in defects:
            defect_o = DefectController(defect)
            defect_vw = DefectView(
                self, self.appli.viewframe, self.appli, defect_o)
            defect_vw.addInTreeview(None)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding tool objects
        tools = Tool.fetchObjects({})
        for tool in tools:
            tool_o = ToolController(tool)
            tool_vw = ToolView(self, self.appli.viewframe, self.appli, tool_o)
            tool_vw.addInTreeview(None, False)
            self.appli.statusbar.notify(tool_vw.controller.getTags())
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        self.sort(self.ips_node)
        self.appli.statusbar.update()
        dialog.destroy()
Beispiel #6
0
    def notify(self, db, collection, iid, action, _parent):
        """
        Callback for the observer implemented in mongo.py.
        Each time an object is inserted, updated or deleted the standard way, this function will be called.

        Args:
            collection: the collection that has been modified
            iid: the mongo ObjectId _id that was modified/inserted/deleted
            action: string "update" or "insert" or "delete". It was the action performed on the iid
            _parent: Not used. the mongo ObjectId of the parent. Only if action in an insert. Not used anymore
        """
        mongoInstance = MongoCalendar.getInstance()
        if not mongoInstance.hasACalendarOpen():
            return
        if mongoInstance.calendarName != db:
            return
        # Delete
        if action == "delete":
            if collection == "defects":
                view = self.getViewFromId(str(iid))
                if view is not None:
                    view.beforeDelete()
                    self.appli.statusbar.notify([],view.controller.getTags())
            try:
                self.delete(ObjectId(iid))
            except tk.TclError:
                pass  # item was not inserted in the treeview

        # Insert
        if action == "insert":
            view = None
            res = mongoInstance.find(collection, {"_id": ObjectId(iid)}, False)
            if collection == "tools":
                view = ToolView(self, self.appli.viewframe,
                                self.appli, ToolController(Tool(res)))
            elif collection == "waves":
                view = WaveView(self, self.appli.viewframe,
                                self.appli, WaveController(Wave(res)))
            elif collection == "scopes":
                view = ScopeView(self, self.appli.viewframe,
                                 self.appli, ScopeController(Scope(res)))
            elif collection == "ports":
                view = PortView(self, self.appli.viewframe,
                                self.appli, PortController(Port(res)))
            elif collection == "ips":
                view = IpView(self, self.appli.viewframe,
                              self.appli, IpController(Ip(res)))
            elif collection == "intervals":
                view = IntervalView(self, self.appli.viewframe,
                                    self.appli, IntervalController(Interval(res)))
            elif collection == "defects":
                view = DefectView(self, self.appli.viewframe,
                                self.appli, DefectController(Defect(res)))
            elif collection == "commands":
                view = CommandView(self, self.appli.viewframe,
                                self.appli, CommandController(Command(res)))
            try:
                if view is not None:
                    view.addInTreeview()
                    view.insertReceived()
                    self.appli.statusbar.notify(view.controller.getTags())
            except tk.TclError:
                pass

        if action == "update":
            try:
                view = self.getViewFromId(str(iid))
                if view is not None:
                    oldTags = self.item(str(iid))["tags"]
                    view.controller.actualize()
                    self.appli.statusbar.notify(view.controller.getTags(), oldTags)
                    self.item(str(iid), text=str(
                        view.controller.getModelRepr()), image=view.getIcon())
            except tk.TclError:
                if view is not None:
                    view.addInTreeview()
            if str(self.appli.openedViewFrameId) == str(iid):
                for widget in self.appli.viewframe.winfo_children():
                    widget.destroy()
                view.openModifyWindow()
            if view is not None:
                view.updateReceived()
        self.appli.statusbar.update()