Esempio n. 1
0
class InterfaceOptions(TabBox):

    def __init__(self, name):
        self.notebook = HIGNotebook()
        self.list_options_box = OptionList()
        self._proprieties = Proprieties()
        TabBox.__init__(self, name)
        self.__pack_widgets()
        self.__option_display()
        
    def _create_widgets(self):
        """
        Create widgets 
        """
        self.main_vbox = gtk.VBox()

        self.display_frame = HIGFrame()
        self.display_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.display_frame.set_border_width(6)

        self.hbox_edit = gtk.HBox()
        self.hspacer = gtk.HPaned()
        self.hspacer.set_border_width(0)
        self.vbox_right = HIGVBox()
        self.vbox_left = HIGVBox()

        self.notebook.set_scrollable(True)
        self.notebook.append_page(self.list_options_box, 
                                  HIGEntryLabel(_('Option List')))

        self.list_options_box.reload()
                
    def __pack_widgets(self):
        """
        Packing widgets of mainly windows 
        """
        #Pack widgets to main_box
        self.main_vbox.pack_start(self.hbox_edit, True, True)

        #Paned
        self.hbox_edit.pack_start(self.hspacer)
        self.hspacer.pack1(self.vbox_left, False, False)
        self.hspacer.set_position(480)
        self.hspacer.pack2(self.vbox_right, True, True)

        #Frame right 
        self.vbox_right.pack_start(self.notebook, True, True)

        self.pack_start(self.main_vbox, True, True)
        
    def __option_display(self):
        self.display_frame.set_label('Options')
        self.opt_display = OptionDisplayMainFrame()
        self.opt_display.set_options_list(self.list_options_box)
        self.list_options_box.set_option_display(self.opt_display)
        self.display_frame.add_with_properties(self.opt_display)
        self.vbox_left.pack_start(self.display_frame, False, False)
        
    def save(self):
        self.list_options_box.save()
class InventoryViewer(HIGMainWindow):
    """
    UMIT Network Inventory, Main Window.
    """
    def __init__(self, daddy=None):
        HIGMainWindow.__init__(self)

        self.daddy = daddy

        self.tip_timer = -1
        self.main_accel_group = gtk.AccelGroup()
        self.add_accel_group(self.main_accel_group)

        self.viewernb = HIGNotebook()

        self.invsearch = SearchDB(umitdb)
        self.invdb = ConnectInventoryDB(umitdb)
        self.invtree = InventoryTree(self)
        self.invnb = HIGNotebook()
        self.invnb_close_btn = startup_options()["tabs_close_btn"]
        self.invnbpages_titles = []
        self.invnbpages_objects = []

        # timeline tab
        self.timeline = TLHolder()

        # statusbars
        self.std_statusbar = gtk.Statusbar()
        self.std_sb = self.std_statusbar.get_context_id("stdbar")
        self._write_statusbar("                              ")

        self.tip_statusbar = gtk.Statusbar()
        self.tip_statusbar.set_has_resize_grip(False)
        self.tip_sb = self.tip_statusbar.get_context_id("tipbar")
        self.write_tips = startup_options()["tips"]

        # timer for checking updates
        self.db_stat = os.stat(umitdb).st_mtime
        self.schema_stat = os.stat(Path.sched_schemas).st_mtime
        self.timer_updater = gobject.timeout_add(
            4200,  # nice number
            self.__check_for_updates)

        # gui scheduler controller
        self.schedctrl = SchedControl(self)

        self.inventories = self.invtree.fill_tree()
        self._create_ui_manager()
        self.__set_props()
        self.__do_layout()

        self.connect('inventory-activated', self._inventory_activated)
        self.connect('delete-event', self._exit_ni)
        self.connect('realize', self.on_realize)

    def on_realize(self, event):
        """
        After realizing, change to first page in main notebook (Historic page).
        """
        self.viewernb.set_current_page(0)

    def _close_current_hosttab(self, event):
        """
        Closes current active Host tab.
        """
        holder = self.invnb.get_nth_page(self.invnb.get_current_page())
        if holder:
            title = self.invnb.get_tab_label_text(holder)
            p = self.invnbpages_objects[self.invnbpages_titles.index(title)]

            if len(p.pages):
                tab_label = p.pages[p.get_current_page()]
                content = p.get_nth_page(p.get_current_page())
                p.remove_page(None, content, tab_label)

    def _close_current_invtab(self, event):
        """
        Closes current active inventory notebook.
        """
        holder = self.invnb.get_nth_page(self.invnb.get_current_page())
        if holder:
            label = self.invnb.get_tab_label_text(holder)
            del_index = self.invnbpages_titles.index(label)

            page = self.invnbpages_objects[del_index]
            for p in xrange(page.get_n_pages() - 1):
                tab_label = page.pages[p]
                content = page.get_nth_page(p)
                page.remove_page(None, content, tab_label)
            self._delete_inventory_page()

    def _delete_inventory_page(self):
        """
        Removed last page from an Inventory notebook, now remove the Inventory
        notebook.
        """
        cur_page = self.invnb.get_current_page()
        page = self.invnb.get_nth_page(cur_page)
        page_label = self.invnb.get_tab_label_text(page)
        del_index = self.invnbpages_titles.index(page_label)
        del self.invnbpages_titles[del_index]
        del self.invnbpages_objects[del_index]

        self.invnb.remove_page(cur_page)

    def _inventory_activated(self, event, data):
        """
        Activated some item on Inventory tree.
        """
        if not data['host_addr']:  # empty inventory was selected
            # clicked on Inventory title, dont do nothing
            return

        title = data["root"]  # inventory name

        # check if activated inventory isnt open already
        if not title in self.invnbpages_titles:
            # create new notebook to hold this Inventory
            newinvnb = InventoryNB(self)
            self.invnb.append_page(newinvnb, gtk.Label(title))

            self.invnbpages_titles.append(title)
            self.invnbpages_objects.append(newinvnb)

            # check if a host was activated
            if data["host_addr"][0] != inventory_info:
                box = self._load_inventory_host_data(title,
                                                     data["host_addr"][1])
                newinvnb.append_host(data["host_addr"][0], box)
            else:
                # inventory info
                box = self._load_inventory_data(title)
                if box:
                    newinvnb.append_inv(box=box)

        else:
            # get Inventory notebook
            p = self.invnbpages_objects[self.invnbpages_titles.index(title)]

            # check if a host was activated
            if data["host_addr"][0] != inventory_info and \
                not p.page_exists(data["host_addr"]):
                box = self._load_inventory_host_data(title,
                                                     data["host_addr"][1])
                p.append_host(data["host_addr"][0], box)

            # if it is not a host, it was inventory info
            elif data["host_addr"][0] == inventory_info:
                box = self._load_inventory_data(title)
                if box:
                    p.append_inv(box=box)

    def _load_inventory_data(self, inventory_name):
        """
        Load data for activated Inventory.
        """
        fk_inventory = self.invdb.get_inventory_id_for_name(inventory_name)
        scans = self.invdb.get_scans_id_for_inventory(fk_inventory)
        last_scan_id = scans[len(scans) - 1][0]
        hosts = self.invtree.invdata[inventory_name]

        box = gtk.VBox()

        # scan info
        hb = gtk.HBox()
        hb.pack_start(gtk.Label(_("Scan count:") + (" %d" % len(scans))),
                      False, False, 0)
        box.pack_start(hb, False, False, 0)

        hb = gtk.HBox()
        last_scan_date = self.invdb.get_finish_timestamp_for_scan_from_db(
            last_scan_id)
        hb.pack_start(
            gtk.Label(_("Last scan date:") + (" %s" % last_scan_date)), False,
            False, 0)
        box.pack_start(hb, False, False, 0)

        details = self.invdb.get_scan_details_for_scan_from_db(scans[0][0])
        detc = [
            _("Scan args"),
            _("XML output version"),
            _("Verbose"),
            _("Debugging"),
            _("Scanner name"),
            _("Scanner version")
        ]
        for indx, item in enumerate(details):
            hb = gtk.HBox()
            hb.pack_start(gtk.Label("%s: %s" % (detc[indx], item)), False,
                          False, 0)
            box.pack_start(hb, False, False, 0)

        # "separator"
        box.pack_start(gtk.HSeparator(), False, False, 6)

        # hosts info
        hb = gtk.HBox()
        hb.pack_start(
            gtk.Label(_("Hosts: ") + ', '.join([host[0] for host in hosts])),
            False, False, 0)
        box.pack_start(hb, False, False, 0)

        hb = gtk.HBox()
        hb.pack_start(gtk.Label(_("Host count:") + (" %s" % len(hosts))),
                      False, False, 0)
        box.pack_start(hb, False, False, 0)

        sw = gtk.ScrolledWindow()
        sw.add_with_viewport(box)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.show_all()

        return sw

    def _load_inventory_host_data(self, inventory_name, host_addr):
        """
        Load data for a host in an inventory.
        """
        changesd = ChangesDiff(self.invdb)
        changesl = ChangesList(self,
                               self.invdb,
                               changesd,
                               data={-1: (inventory_name, host_addr)})

        paned = gtk.VPaned()
        paned.add1(changesl)
        paned.add2(changesd)

        return paned

    def _write_statusbar(self, msg):
        """
        Write some message at standard statusbar.
        """
        self.std_statusbar.pop(self.std_sb)
        self.std_statusbar.push(self.std_sb, msg)

    def _clear_statusbar(self):
        """
        Clear standard statusbar.
        """
        self.std_statusbar.pop(self.std_sb)

    def _write_statusbar_tip(self, tipmsg, timeout=True):
        """
        Write a tip at statusbar.
        """
        if not self.write_tips:
            # tips disabled
            return

        if not self.window:  # widget being destroyed
            gobject.source_remove(self.tip_timer)
            return

        self.tip_statusbar.pop(self.tip_sb)
        self.tip_statusbar.push(self.tip_sb, tipmsg)

        if self.tip_timer != -1:
            gobject.source_remove(self.tip_timer)

        if timeout:
            # remove tip after 15 seconds
            self.tip_timer = gobject.timeout_add(15000,
                                                 self._clear_tip_statusbar)

    def _clear_tip_statusbar(self):
        """
        Clear statusbar.
        """
        self.tip_statusbar.pop(self.tip_sb)
        gobject.source_remove(self.tip_timer)
        self.tip_timer = -1

        return False

    def _update_viewer(self):
        """
        Call this when needed to update Network Inventory Viewer.
        """
        inventories = self.invtree.fill_tree()

        # update Edit Inventories menu
        new_inventories = set(inventories).difference(set(self.inventories))
        self.inventories = inventories

        for inv in new_inventories:
            self.main_action_group.add_actions([("_" + inv, None, inv, None,
                                                 inv, self._edit_inventory)])

            self.ui_manager.add_ui(self.ui_manager.new_merge_id(),
                                   "/menubar/Edit/Inventory", inv, "_" + inv,
                                   "menuitem", False)

    def _build_results_view(self, query, returned, buildnow=False):
        """
        Build a TreeView with returned results from search or perform search
        and then Build TreeView.
        """
        def close_page(widget, data):
            """
            Close search page.
            """
            page_num = self.viewernb.page_num(data)
            self.viewernb.remove_page(page_num)

        def row_activated(tv, path, tvcolumn):
            """
            Activated some row in results treeview.
            """
            # create page at "Inventory"
            model = tv.get_model()
            tv_iter = model.get_iter(path)
            host_addr = model.get_value(tv_iter, 1)

            data = {}
            root = model[path[0]][0]
            data["root"] = root
            data["host_addr"] = (host_addr, host_addr)  # new format

            self.emit('inventory-activated', data)

            # write tip to statusbar
            self._write_statusbar_tip(_("A page was open at Historic tab!"))

        def buildtv(*args):
            """
            Build treeview and append results.
            """
            lsmodel = gtk.ListStore(str, str, str, str)
            tview = gtk.TreeView(lsmodel)
            columns = 4
            columns_text = (_("Inventory"), _("Host"),
                            _("First Matched Category"), _("Entry Date"))
            tview.columns = [None] * columns

            for n in range(columns):
                tview.columns[n] = gtk.TreeViewColumn(columns_text[n])
                tview.columns[n].cell = gtk.CellRendererText()
                tview.columns[n].pack_start(tview.columns[n].cell, True)
                tview.columns[n].set_attributes(tview.columns[n].cell, text=n)

                tview.append_column(tview.columns[n])

            tview.connect('row-activated', row_activated)

            # layout
            matches = len(args[1])
            word = append_s(_("result"), matches)
            upper_title = gtk.Label()
            upper_title.set_markup(("<b>%d " % matches) + word + _(" found.") +
                                   "</b>")
            hutbox = HIGHBox()
            hutbox._pack_noexpand_nofill(upper_title)
            sw = HIGScrolledWindow()
            sw.add(tview)
            vbox = gtk.VBox()
            vbox.pack_start(hutbox, False, False, 3)
            vbox.pack_start(sw, True, True, 0)

            vbox.show_all()

            # append results to treeview
            results = args[1]

            for res, date in results.items():
                invname = self.invdb.get_inventory_name_for_id(res[0])
                lsmodel.append((invname, res[1], res[2], str(date)))

            title = _("Search: %s") % args[0]
            tab_label = HIGAnimatedTabLabel(title)
            tab_label.connect("close-clicked", close_page, vbox)
            self.viewernb.append_page(vbox, tab_label)

        if buildnow:
            # uhm.. nice, we already have the results.
            buildtv(query, returned)

        else:
            # no results yet, will get them now!
            host_matches = {}

            for key, values in returned.items():
                host_id = key
                inv_id = values[0]
                host_addr = values[1]
                date = values[2]
                res = self.invsearch.search(host_id, query)
                if res:  # res = category returned
                    host_matches[(inv_id, host_addr, res)] = date

            # build treeview now
            buildtv(query, host_matches)

    def _create_ui_manager(self):
        """
        Set up user interface.
        """
        self.ui_manager = gtk.UIManager()
        self.main_action_group = gtk.ActionGroup("MainActionGroup")

        about_icon = None
        try:
            about_icon = gtk.STOCK_ABOUT
        except:
            pass

        main_actions = [ \
            ("File", None, _("_File"), None),
            ("Edit", None, _("_Edit"), None),
            ("Scheduler", None, _("_Scheduler"), None),
            ("Help", None, _("_Help"), None),

            ("ToolbarOpt", None, _("Tool_bar"), None),
            ("InvTabs", None, _("Devices _tab"), None),
            ("Inventory", None, _("_Inventories"), None),

            # File
            ("New",
             gtk.STOCK_NEW, _("_New Inventory"),
             None, _("Create new Inventory"),
             self._create_new),

            ("CloseHostTab",
             None, _("Close Device tab"),
             "<Control>W", _("Close current host tab"),
             self._close_current_hosttab),

            ("CloseInvTab",
             None, _("Close Inventory tab"),
             "<Shift><Control>W", _("Close current Inventory tab"),
             self._close_current_invtab),

            ("Quit",
             gtk.STOCK_QUIT, _("_Quit"),
             None, _("Close Network Inventory"),
             self._exit_ni),

            # Edit
            ('Control Data Removal',
             None, _("Data Removal"),
             None, _("Data Removal"),
             self._edit_data_removal),

            ('Startup',
             None, _("Startup settings"),
             None, _("Startup settings"),
             self._edit_startup),

            # Scheduler
            # Scheduler log
            ('Sched Log',
             None, _("Scheduler log"),
             None, _("View Scheduler log"),
             self._open_sched_log),

            # Scheduler status
            ('Sched Control',
             self.schedctrl.stock_icon, self.schedctrl.status_text,
             None, self.schedctrl.status_text,
             self.schedctrl._scheduler_control),

            # Help
            ('Show Help',
             gtk.STOCK_HELP, _('_Help'),
             None, _('Shows the application help'),
             self._show_help),

            ('Report a bug',
             gtk.STOCK_DIALOG_INFO, _('_Report a bug'),
             '<Control>b', _("Report a bug"),
             self._show_bug_report),

            ('About',
             about_icon, _("_About"),
             '<Control>a', _("About UMIT Network Inventory"),
             self._show_about)

        ]

        toggle_actions = [
            # Edit
            ("ShowTips", None, _("Show ti_ps"), None,
             _("Enable disable tip showing"),
             lambda c: self.set_write_tips(not self.write_tips),
             self.write_tips),

            # Edit/Notebooks
            ("TabCloseBtn", None, _("Place close button"), None,
             _("Place a close button upon tab creation"),
             lambda c: self.set_invnb_cbtn(not self.invnb_close_btn),
             self.invnb_close_btn)
        ]

        default_ui = """
            <menubar>
                <menu action='File'>
                    <menuitem action='New' />
                    <separator />
                    <menuitem action='CloseHostTab' />
                    <menuitem action='CloseInvTab' />
                    <menuitem action='Quit' />
                </menu>
                <menu action='Edit'>
                    <menu action='InvTabs'>
                         <menuitem action='TabCloseBtn' />
                    </menu>
                    <menu action='Inventory'>
                    </menu>
                    <menuitem action='ShowTips' />
                    <menuitem action='Control Data Removal' />
                    <menuitem action='Startup' />
                </menu>
                <menu action='Scheduler'>
                    <menuitem action='Sched Log' />
                    <menuitem action='Sched Control' />
                </menu>
                <menu action='Help'>
                    <menuitem action='Show Help' />
                    <menuitem action='Report a bug' />
                    <menuitem action='About' />
                </menu>
            </menubar>
            <toolbar>
                <toolitem action='Sched Control' />
                <separator />
            </toolbar>
            """

        self.main_action_group.add_actions(main_actions)
        self.main_action_group.add_toggle_actions(toggle_actions)

        for action in self.main_action_group.list_actions():
            action.set_accel_group(self.main_accel_group)
            action.connect_accelerator()

        self.ui_manager.insert_action_group(self.main_action_group, 0)
        self.ui_manager.add_ui_from_string(default_ui)

        self.schedctrl.ui_action = self.main_action_group.get_action(
            'Sched Control')

        # add Inventories to edit menu
        for inv in self.inventories:
            self.main_action_group.add_actions([("_" + inv, None, inv, None,
                                                 inv, self._edit_inventory)])

            self.ui_manager.add_ui(self.ui_manager.new_merge_id(),
                                   "/menubar/Edit/Inventory", inv, "_" + inv,
                                   "menuitem", False)

    def _edit_data_removal(self, event):
        """
        Open window for editing data removal for Inventories.
        """
        w = ConfigureDataRemoval()
        w.show_all()

    def _edit_inventory(self, event):
        """
        Open inventory for editing.
        """
        try:
            w = NewInventory(event.get_name()[1:], edit_mode=True)
        except NoInventory:
            return
        w.show_all()

    def _create_new(self, event):
        """
        Open dialog for creating New Inventory.
        """
        w = NewInventory()
        w.show_all()

    def _open_sched_log(self, event):
        """
        Open scheduler log.
        """
        winlog = SchedLog()
        winlog.show_all()

    def _edit_startup(self, event):
        """
        Open window for editing startup settings.
        """
        settwin = NISettings()
        settwin.show_all()

    def _show_help(self, event):
        """
        Open help manual.
        """
        show_help(self, "index.html")

    def _show_bug_report(self, event):
        """
        Open bug report window.
        """
        bug = BugReport()
        bug.show_all()

    def _show_about(self, event):
        """
        Open about window.
        """
        awin = About()
        awin.show_all()

    def _exit_ni(self, *args):
        """
        Do necessary cleanup before destroying window.
        """
        # remove tip timer if still running
        if self.tip_timer != -1:
            gobject.source_remove(self.tip_timer)
            self._clear_tip_statusbar()

        # stop updater timer
        gobject.source_remove(self.timer_updater)

        self.hide()

        # remove old data
        if get_decays()[1]:
            win = RemoveOldData()
            win.show_all()
            win.connect('destroy', self.__leave_ni)
        else:
            self.__leave_ni()

    def __leave_ni(self, *args):
        """
        If you are here, Network Inventory has been cleanedup succesfully.
        """
        if self.daddy:
            self.daddy.running_ni = False
            self.destroy()
        else:
            gtk.main_quit()

    def __check_for_updates(self):
        """
        Check for some possible visual update needed to be done.
        """
        do_update = False

        # check for database changes
        prev_stat = self.db_stat
        try:
            possibly_new = os.stat(umitdb).st_mtime
        except OSError:
            return True

        if prev_stat != possibly_new:
            do_update = True
            self.db_stat = possibly_new

        # check for changes in schemas
        prev_state = self.schema_stat
        try:
            possibly_new = os.stat(Path.sched_schemas).st_mtime
        except OSError:
            return True

        if prev_state != possibly_new:
            do_update = True
            self.schema_stat = possibly_new

        if do_update:
            self._update_viewer()

        return True

    def __set_props(self):
        """
        Set window properties.
        """
        self.set_title(_("UMIT Network Inventory"))
        self.invnb.set_scrollable(True)
        self.viewernb.set_scrollable(True)
        # a size for testing
        self.set_position(gtk.WIN_POS_CENTER)
        width, height = gtk.gdk.get_default_root_window().get_size()
        self.set_default_size((width * 3) / 4, (height * 3) / 4)

    def __do_layout(self):
        """
        Layout window widgets.
        """
        main_vbox = gtk.VBox()
        main_hpaned = gtk.HPaned()
        nb_tl_hpaned = gtk.HPaned()

        menubar = self.ui_manager.get_widget('/menubar')
        main_vbox.pack_start(menubar, False, False, 0)

        schedbar = self.ui_manager.get_widget('/toolbar')
        schedbar.set_show_arrow(False)
        schedbar.set_style(gtk.TOOLBAR_ICONS)
        toolbar = SearchBar(self, self.invdb)

        toolbar_box = gtk.HBox()
        toolbar_box.pack_start(schedbar, False, False, 0)
        toolbar_box.pack_start(toolbar, True, True, 0)
        main_vbox.pack_start(toolbar_box, False, False, 0)

        left_pane_box = gtk.VBox()
        left_pane_box.pack_start(self.invtree, True, True, 0)

        main_hpaned.add1(left_pane_box)
        main_hpaned.add2(nb_tl_hpaned)

        # inventories notebook
        nb_tl_hpaned.pack1(self.invnb, True, False)

        self.viewernb.append_page(main_hpaned, gtk.Label(_(" Historic ")))
        self.viewernb.append_page(self.timeline, gtk.Label(_(" Timeline ")))

        self.timeline.show_all()

        main_vbox.pack_start(self.viewernb, True, True, 0)

        sbs_box = gtk.HBox()
        sbs_box.add(self.tip_statusbar)
        sbs_box.add(self.std_statusbar)
        main_vbox.pack_end(sbs_box, False, False, 0)

        self.add(main_vbox)

    def get_write_tips(self):
        """
        Returns True if tips should be written at statusbar, otherwise, False.
        """
        return self.__wtips

    def set_write_tips(self, write):
        """
        Sets to write tips or not at statusbar.
        """
        self.__wtips = write
        if not self.write_tips:
            self.tip_statusbar.pop(self.tip_sb)

    def get_invnb_cbtn(self):
        """
        Returns True if Inventory tabs have a close button placed on them.
        """
        return self.__invcbtn

    def set_invnb_cbtn(self, enable):
        """
        Sets to show or not close button in each Inventory tab.
        """
        self.__invcbtn = enable

    # Properties
    write_tips = property(get_write_tips, set_write_tips)
    invnb_close_btn = property(get_invnb_cbtn, set_invnb_cbtn)
Esempio n. 3
0
class InterfaceWizard(TabBox):

    def __init__(self, name):
        self.wizard_box = None
        self._tooldesign = None
        self.notebook = HIGNotebook()
        self.list_options_box = OptionList()
        self._proprieties = Proprieties()
        self.create_wizard_edit()
        TabBox.__init__(self, name)
        self.__pack_widgets()
        self.vbox_left.pack_start(self.wizard_box, True, True)
        self._create_tooldesign()
        
    def create_wizard_edit(self):
        if self.wizard_box != None:
            self.wizard_box.set_proprieties(self._proprieties)
        if self.wizard_box ==None :
            self.wizard_box = WizardEdit(self.list_options_box.get_list_option())
            
        self.wizard_box.set_notebook(self.notebook)
        
    def _create_widgets(self):
        """
        Create widgets 
        """
        self.main_vbox = gtk.VBox()

        self.display_frame = HIGFrame()
        self.display_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.display_frame.set_border_width(6)

        self.hbox_edit = gtk.HBox()
        self.hspacer = gtk.HPaned()
        self.hspacer.set_border_width(0)
        self.vbox_right = HIGVBox()
        self.vbox_left = HIGVBox()

        self.notebook.set_scrollable(True)

        self.list_options_box.reload()
                
    def __pack_widgets(self):
        """
        Packing widgets of mainly windows 
        """
        #Pack widgets to main_box
        self.main_vbox.pack_start(self.hbox_edit, True, True)

        #Paned
        self.hbox_edit.pack_start(self.hspacer)
        self.hspacer.pack1(self.vbox_left, False, False)
        self.hspacer.set_position(480)
        self.hspacer.pack2(self.vbox_right, True, True)

        #Frame right 
        self.vbox_right.pack_start(self.notebook, True, True)

        self.pack_start(self.main_vbox, True, True)
                
    def _create_tooldesign(self):
        '''
        create tooldesign that contains widgets to put 
        in work area of edit profile
        '''
        if self._tooldesign == None :     
            self._tooldesign = ToolDesign()

        if self._proprieties == None :
            self._proprieties = Proprieties()
        if self.notebook.get_n_pages() < 2:
            self.notebook.append_page(self._tooldesign, 
                                      HIGEntryLabel(_('Design')))
            self.notebook.append_page(self._proprieties, 
                                      HIGEntryLabel(_('Proprieties')))
        self.notebook.show_all()
        obj = self.wizard_box
        obj.set_proprieties(self._proprieties)
        profilecore = obj.get_profilecore()
        self._proprieties.set_profilecore(profilecore)
        
    def save(self):
        self.wizard_box.save()
class InterfaceEditor(HIGMainWindow):
    def __init__(self, daddy=None):
        HIGMainWindow.__init__(self)
        self._proprieties = None
        self.profile_box = None
        self.wizard_box = None
        self._current_edit_mode = None
        self._tooldesign = None
        self.profile_box_b = None
        self.wizard_box_b = None
        self.edit_mode_opt = None
        self._show_bar = True
        self.set_title(_('Interface Editor'))
        self.set_size_request(800, 400)
        self.set_position(gtk.WIN_POS_CENTER)
        #self.maximize()
        self.list_options_box = OptionList()
        self.notebook = HIGNotebook()
        self._proprieties = Proprieties()
        self.create_profile_edit()
        self.create_wizard_edit()
        self.obj = self.profile_box
        #Create Widgets
        self.__create_widgets()
        #Packing - Group of widgets
        self.__pack_widgets()
        self.__option_display()
        self.edit_mode_opt = "Options"

        self.connect("delete_event", self._destroy)

        self.opt_display.set_profile(self.profile_box)
        self.opt_display.set_wizard(self.wizard_box)
        self.profile_box.notebook.connect_after('need-save',
                                                self._update_menu_s)
        self.wizard_box.notebook.connect_after('need-save',
                                               self._update_menu_s)
        self.profile_box.notebook.connect_after('changed', self._update_menu)
        self.wizard_box.notebook.connect_after('changed', self._update_menu)
        self.opt_display.connect_after('need-save', self._update_menu_s)

        self.daddy = daddy

    def _update_menu(self, actions, others, page):
        obj = None
        if self.edit_mode_opt == "Profile":
            obj = self.profile_box
        elif self.edit_mode_opt == "Wizard":
            obj = self.wizard_box
        if obj == None:
            return
        #Check if there is something selected:
        current_page = obj.notebook.get_nth_page(
            obj.notebook.get_current_page())
        if obj.notebook._old_select != None:
            #Section is Selected
            log.debug('Section is selected << updating toolbar')

            pass
        elif current_page._old_selected != None:
            #Item Selected
            log.debug('Item is selected << updating toolbar')
            pass

    def _update_menu_s(self, action, others, page):
        log.debug('<<< Update Main menubar ')
        save = self.main_action_group.get_action('Save')
        save_all = False
        if self.edit_mode_opt == "Profile":
            log.debug('profile updating menubar save')
            value = self.profile_box.is_changed()
            save.set_sensitive(value)
        elif self.edit_mode_opt == "Wizard":
            log.debug('wizard updating menubar save')
            value = self.wizard_box.is_changed()
            save.set_sensitive(value)

        elif self.edit_mode_opt == 'Options':
            log.debug('options updating menubar save')
            value = self.opt_display.is_changed()
            save.set_sensitive(value)

        save_all = self.opt_display.is_changed() or \
                 self.wizard_box.is_changed() or self.profile_box.is_changed()
        self.main_action_group.get_action('Save all').set_sensitive(save_all)

    def _destroy(self, widget, event):
        self.quit(widget)

    def create_wizard_edit(self):
        '''
        create a profile area editing 
        and connect to Undo Redo Manager to update the buttons 
        '''
        if self.wizard_box != None:
            self.wizard_box.set_proprieties(self._proprieties)
        if self.wizard_box == None:
            self.wizard_box = WizardEdit(
                self.list_options_box.get_list_option())

        self.wizard_box.set_notebook(self.notebook)

    def create_profile_edit(self):
        '''
        create a profile area editing 
        and connect to Undo Redo Manager to update the buttons 
        '''
        if self.profile_box != None:
            self.profile_box.set_proprieties(self._proprieties)

        if self.profile_box == None:
            self.profile_box = ProfileEdit(
                self.list_options_box.get_list_option())

        command_manager.connect_after('changed', self._update_undo_redo_cb)
        self.profile_box.set_notebook(self.notebook)

    def _update_undo_redo_cb(self, action, other):
        '''
        Verify if exists undo and redo
        and update the buttons on the toolbar/menubar
        #DO:
        - sensitive -> True/False
        - Ajust tips 
        ####
        '''

        can_undo = command_manager.can_undo()
        can_redo = command_manager.can_redo()
        self.main_action_group.get_action('Undo').set_sensitive(can_undo)
        self.main_action_group.get_action('Redo').set_sensitive(can_redo)
        if can_undo:
            self.main_action_group.get_action('Undo').tooltip = 'sss'
            self.main_action_group.get_action('Undo').create_menu_item()

    def __create_widgets(self):
        """
        Create widgets 
        """
        self.main_vbox = gtk.VBox()
        self.widgets = {}

        #UI Manager
        self.__create_ui_manager()
        #Table - contains menubar and toolbar

        #Menubar
        self.__create_menubar()
        #Toolbar
        self.__create_toolbar()

        self.display_frame = HIGFrame()
        self.display_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.display_frame.set_border_width(6)

        self.hbox_edit = gtk.HBox()
        self.hspacer = gtk.HPaned()
        self.hspacer.set_border_width(0)
        self.vbox_right = HIGVBox()
        self.vbox_left = HIGVBox()

        self.edit_mode_exp = gtk.Expander(_('Edit Modes'))
        self.edit_mode_box = self.create_edit_mode()

        self.notebook.set_scrollable(True)
        self.notebook.append_page(self.list_options_box,
                                  HIGEntryLabel(_('Option List')))

        self.list_options_box.reload()

        self.__create_status_bar()

    def __option_display(self):

        self.display_frame.set_label('Options')
        self.opt_display = OptionDisplayMainFrame()
        self.opt_display.set_options_list(self.list_options_box)
        self.list_options_box.set_option_display(self.opt_display)
        self.display_frame.add_with_properties(self.opt_display)
        self.vbox_left.pack_start(self.display_frame, False, False)

    def __pack_widgets(self):
        """
        Packing widgets of mainly windows 
        """

        self.add(self.main_vbox)

        #Pack widgets to main_box

        self.main_vbox.pack_start(self.hbox_edit, True, True)

        #Paned
        self.hbox_edit.pack_start(self.hspacer)
        separator = gtk.VSeparator()
        self.hspacer.pack1(self.vbox_left, False, False)
        self.hspacer.set_position(580)
        self.hspacer.pack2(self.vbox_right, False, True)

        #Edit Mode
        self.edit_mode_exp.add(self.edit_mode_box)
        self.edit_mode_exp.set_expanded(True)

        #Frame right
        self.vbox_right.pack_start(self.edit_mode_exp, False, False)
        self.vbox_right.pack_end(self.notebook, True, True)

        #Status bar
        self.main_vbox.pack_start(self.statusbar, False, False)

    def create_edit_mode(self):
        """
        Create a treeview that contains a three edit modes 
        returns vbox contains a treeview

        @return: returns the treeview with list of edit modes 
        @rtype: vbox
        """

        model = gtk.TreeStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
        self.edit_mode_tv = gtk.TreeView(model)
        self.edit_mode_tv.set_headers_visible(False)
        renderer = gtk.CellRendererText()
        cell_renderer_pix = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn()
        column.set_title(_('Name'))
        column.pack_start(cell_renderer_pix, False)
        column.add_attribute(cell_renderer_pix, 'pixbuf', 0)
        column.pack_start(renderer, True)
        column.add_attribute(renderer, 'text', 1)

        self.edit_mode_tv.append_column(column)
        myiter = model.insert_before(None, None)
        icon = gtk.Image()
        icon = icon.render_icon('gtk-edit', gtk.ICON_SIZE_MENU)
        model.set_value(myiter, 0, icon)
        model.set_value(myiter, 1, "Profile")
        myiter = model.insert_before(None, None)
        icon = gtk.Image()
        icon = icon.render_icon('gtk-convert', gtk.ICON_SIZE_MENU)
        model.set_value(myiter, 0, icon)
        model.set_value(myiter, 1, "Wizard")
        myiter = model.insert_before(None, None)
        icon = gtk.Image()

        icon = icon.render_icon(gtk.STOCK_DND_MULTIPLE, gtk.ICON_SIZE_MENU)
        model.set_value(myiter, 0, icon)
        model.set_value(myiter, 1, "Options")
        selection = self.edit_mode_tv.get_selection()
        selection.select_iter(myiter)
        self.edit_mode_tv.connect("cursor-changed", self.change_edit_mode)
        vbox = HIGVBox()
        vbox.pack_start(self.edit_mode_tv, False, False)
        return vbox

    def change_edit_mode(self, widget):
        """
        Change box of main screen and others changes at toolbar
        """
        selection = self.edit_mode_tv.get_selection()
        (model, iter) = selection.get_selected()
        edit = model.get_value(iter, 1)
        if edit == "Options" and not self.edit_mode_opt == "Options":
            self._remove_previews()
            self.edit_mode_opt = "Options"
            self.display_frame.show_all()
            if self.notebook.get_n_pages > 1:
                self.notebook.remove_page(-1)
                self.notebook.remove_page(-1)
            self._set_menus_editor(False)

        elif edit == "Profile" and not self.edit_mode_opt == "Profile":
            self._remove_previews()
            self.edit_mode_opt = "Profile"
            bool = self.profile_box_b == None
            self.create_profile_edit()
            if bool:
                self.vbox_left.pack_start(self.profile_box, True, True)
                self.profile_box_b = True
            log.debug('<<< show :: Profile Edit Mode :: ')
            self.profile_box.show_all()
            self.profile_box.notebook.put_on_page()
            self._create_tooldesign()
            self._set_menus_editor(True)
            self.profile_box.show()
            self.obj = self.profile_box
        elif edit == "Wizard" and not self.edit_mode_opt == "Wizard":
            log.debug('<<< show :: Wizard Edit Mode - basic mode ')
            self._remove_previews()
            self.edit_mode_opt = "Wizard"
            self._set_menus_editor(True)
            bool = self.wizard_box_b == None
            self.create_wizard_edit()
            if bool:
                self.vbox_left.pack_start(self.wizard_box, True, True)
                self.wizard_box_b = True

            self.wizard_box.show_all()
            self.wizard_box.notebook.put_on_page()
            self._create_tooldesign()
            self.wizard_box.show()
            self.obj = self.wizard_box

    def _remove_previews(self):
        '''
        Remove the previews Edit mode
        '''
        #XXX Lack the toolbars and some ajusts
        if self.edit_mode_opt == "Profile":
            #self.vbox_left.remove(self.profile_box)
            self.profile_box.hide_all()
        elif self.edit_mode_opt == "Options":
            #self.vbox_left.remove(self.display_frame)
            self.display_frame.hide_all()
        elif self.edit_mode_opt == "Wizard":
            self.wizard_box.hide_all()

    def _create_tooldesign(self):
        '''
        create tooldesign that contains widgets to put 
        in work area of edit profile
        '''
        if self._tooldesign == None:
            self._tooldesign = ToolDesign()

        if self._proprieties == None:
            self._proprieties = Proprieties()
        if self.notebook.get_n_pages() < 2:
            self.notebook.append_page(self._tooldesign,
                                      HIGEntryLabel(_('Design')))
            self.notebook.append_page(self._proprieties,
                                      HIGEntryLabel(_('Proprieties')))
        self.notebook.show_all()
        if self.edit_mode_opt == "Profile":
            obj = self.profile_box
        elif self.edit_mode_opt == "Wizard":
            obj = self.wizard_box
        obj.set_proprieties(self._proprieties)
        profilecore = obj.get_profilecore()
        self._proprieties.set_profilecore(profilecore)

    def __optinlist_from_group(self):
        """
        After Select a Option from a group this treeview refresh options lists
        that each group contains
        """
        model = gtk.TreeStore(gobject.TYPE_STRING)
        self.profile_optionlist_tvw = gtk.TreeView(model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name", renderer, text=0)
        self.profile_optionlist_tvw.append_column(column)

        self.wizard_file = PWOptions(profile_editor)
        group_list = self.wizard_file.read("group", "name", "group")
        for i, v in group_list:
            myiter = model.insert_after(None, None)
            model.set_value(myiter, 0, i)

    def __proprieties(self):
        """
        Create a editable options - Proprieties of Options
        """
        #Create a listview with options
        self.prop_frame_option = gtk.Frame()
        self.prop_frame_option.set_label("List Options")
        self.prop_frame_option.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        prop_sw = HIGScrolledWindow()
        prop_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        prop_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        model = gtk.TreeStore(gobject.TYPE_STRING)
        treeview = gtk.TreeView(model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name", renderer, text=0)
        treeview.append_column(column)
        self.prop_frame_option.add(treeview)
        self.prop_frame_option.add(prop_sw)
        """
        Box Edit 
        """

        #Frame
        self.prop_frame = gtk.Frame()
        self.prop_frame.set_label("Edit Option")
        self.prop_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.prop_exp = HIGExpander("Proprieties")

        label = gtk.Label('s')
        self.prop_exp.add(label)
        self.prop_frame.add(self.prop_exp)

    def __grouplist(self):
        """
        Group List, Tree view 
        """

        model = gtk.TreeStore(gobject.TYPE_STRING)
        self.treeview = gtk.TreeView(model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name", renderer, text=0)
        self.treeview.append_column(column)

        self.wizard_file = PWOptions(profile_editor)
        group_list = self.wizard_file.read("group", "name", "group")
        for i, v in group_list:
            myiter = model.insert_after(None, None)
            model.set_value(myiter, 0, i)

    def __create_toolbar(self):
        """
        Create a Main Toolbar of Profile Wizard Editor
        """

        self.toolbar = self.ui_manager.get_widget('/toolbar')
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        self.main_vbox.pack_start(self.toolbar, False, True, 0)
        self.toolbar.show_all()

    def save_all(self, widget):
        #if self.opt_display.is_changed():
        #XXX BUG (is_changed method is in OptionList)
        self.list_options_box.save()
        if self.profile_box.is_changed():
            self.profile_box.save()
        if self.wizard_box.is_changed():
            self.wizard_box.save()

    def _set_menus_editor(self, value):
        self.main_action_group.get_action('Items').set_sensitive(value)
        self.main_action_group.get_action('Section').set_sensitive(value)
        if self.edit_mode_opt != None:
            self._update_menu_s(None, None, None)

    def save(self, widget):
        if self.edit_mode_opt == 'Options':
            obj = self.list_options_box
        elif self.edit_mode_opt == 'Profile':
            obj = self.profile_box
        elif self.edit_mode_opt == 'Wizard':
            obj = self.wizard_box

        obj.save()

    def quit(self, widget):
        """
        Leaving of Interface Editor
        """
        if self.daddy:  # Run from Umit Network Scanner by menus
            self.daddy.running_ie = False
            self.destroy()
        else:  # Run from command line directly
            gtk.main_quit()

    def np(self, widget):
        print "Don't work yet"

    def __create_ui_manager(self):
        """
        Create a UI Manager
        """
        self.ui_manager = gtk.UIManager()
        self.main_action_group = gtk.ActionGroup('MainActionGroup')
        self.main_actions = [ \
            ('File', None, _('_File'), None),
            ('Save', gtk.STOCK_SAVE, _('_Save'), None, _('Save'), self.save),
            ('Save all', gtk.STOCK_SAVE, _('_Save all'), None, _('Save all'),
             self.save_all),
            ('Quit', gtk.STOCK_QUIT, _('_Quit'), None, _('Quit'), self.quit),
            ('Edit', None, _('Edit'), None),
            ('Undo', gtk.STOCK_UNDO, _('_Undo'), '<Control>z', _('Undo'), self._undo_cb),
            ('Redo', gtk.STOCK_REDO, _('_Redo'), '<Control>r', _('Redo'), self._redo_cb),
            ('View', None, _('View'), None),
            ('Right Bar', None, _('_Right Bar'), None,
             _('Right Bar'), self._hide_right),
            ('Tools', None, _('Tools'), None),
            ('Section', None, _('Section'), None),
            ('Items', None, _('Items'), None),
            ('Insert label', None, _('_Label'), None,
             _('Insert label'), self.np),
            ('New Section', None, _('_New Section'), None,
             _('New Section'), self._add_section),
            ('Remove Section Label', None, _('_Remove Section Label'), None,
             _('Remove Section Label'), self._remove_section),
            ('Remove Section', None, _('_Remove Section'), None,
             _('Remove Section'), self._remove_section),
            ('Add new voidplace', None, _('_Add new voidplace'), None,
             _('Add new voidplace'), self._add_place),
            ('Remove option', None, _('_Remove Option'), None,
             _('Remove option'), self._remove_option),
            ('Remove voidplace', None, _('_Remove voidplace'), None,
             _('Remove voidplace'), self._remove_option),
            ('Add option selected', None, _('_Add option selected'), None,
             _('Add option selected'), self.np),
            ('Move Section Left', None, _('_Move Section Left'), None,
             _('Move Section Left'), self._move_section_left),
            ('Move Section Right', None, _('_Move Section Right'), None,
             _('Move Section Right'), self._move_section_right),
            ('Move Item Down', None, _('_Move Item Down'), None,
             _('Move Item Down'), self._move_item_down),
            ('Move Item Up', None, _('_Move Item Up'), None,
             _('Move Item Up'), self._move_item_up),
            ('Help', None, _('Help'), None),
            ('About', gtk.STOCK_PASTE, _('_About'), None, _('About'), self.np),

        ]

        self.ui_info = """
            <menubar>
            <menu action='File'>
            <menuitem action='Save'/>
            <menuitem action='Save all'/>
            <separator/>
            <menuitem action='Quit'/>
            </menu>
            <menu action='Edit'>
            <menuitem action='Undo'/>
            <menuitem action='Redo'/>
            </menu>
            <menu action='View'>
            <menuitem action='Right Bar'/>
            </menu>
            <menu action='Section'>
            <menuitem action='Insert label'/>
            <menuitem action='New Section'/>
            <menuitem action='Remove Section Label'/>
            <menuitem action='Remove Section'/>
            <menuitem action='Move Section Left'/>
            <menuitem action='Move Section Right'/>
            </menu>
            <menu action='Items'>
            <menuitem action='Add new voidplace'/>
            <menuitem action='Remove option'/>
            <menuitem action='Remove voidplace'/>
            <menuitem action='Move Item Up'/>
            <menuitem action='Move Item Down'/>
            </menu>

            </menubar>
            <toolbar>
            <toolitem action='Save'/>
            <toolitem action='Save all'/>
            <separator/>
            <toolitem action='Undo'/>
            <toolitem action='Redo'/>

            <separator/>
            <toolitem action='Quit'/>
            </toolbar>
            """

        self.main_action_group.add_actions(self.main_actions)
        self.main_accel_group = gtk.AccelGroup()
        for action in self.main_action_group.list_actions():

            action.set_accel_group(self.main_accel_group)
            action.connect_accelerator()

        #ENABLE = FALSE
        self.main_action_group.get_action('Save all').set_sensitive(False)
        self.main_action_group.get_action('Save').set_sensitive(False)
        self.main_action_group.get_action('Undo').set_sensitive(False)
        self.main_action_group.get_action('Redo').set_sensitive(False)

        self._set_menus_editor(False)
        #END ENABLE

        self.ui_manager.insert_action_group(self.main_action_group, 0)
        self.ui_manager.add_ui_from_string(self.ui_info)
        self.add_accel_group(self.main_accel_group)

    # ACTIONS
    def _add_section(self, widget):
        self.obj._toolbar._add_section(widget)

    def _remove_section(self, widget):
        self.obj._toolbar._remove_section(widget)

    def _add_place(self, widget):
        self.obj._toolbar._add_place(widget)

    def _move_item_up(self, widget):
        self.obj._toolbar._move_item_down(widget)

    def _move_item_down(self, widget):
        self.obj._toolbar._move_item_down(widget)

    def _move_section_left(self, widget):
        self.obj._toolbar._move_section_left(widget)

    def _move_section_right(self, widget):
        self.obj._toolbar._move_section_right(widget)

    def _remove_option(self, widget):
        self.obj._toolbar._remove_option(widget)

    def _hide_right(self, widget):
        if self._show_bar:
            self.vbox_right.hide_all()
        else:
            self.vbox_right.show_all()
        self._show_bar = not self._show_bar

    def _undo_cb(self, widget):
        command_manager.do_undo()

    def _redo_cb(self, widget):
        command_manager.do_redo()

    def __create_menubar(self):
        """
        Create a menubar 
        """

        self.menubar = self.ui_manager.get_widget('/menubar')

        self.main_vbox.pack_start(self.menubar, False, True, 0)

        self.menubar.show_all()

    def __create_status_bar(self):
        '''
        create status bar 
        '''
        self.statusbar = gtk.Statusbar()

        context_id = self.statusbar.push(1, " ")
        self.statusbar.show()
Esempio n. 5
0
class InventoryViewer(HIGMainWindow):
    """
    UMIT Network Inventory, Main Window.
    """

    def __init__(self, daddy=None):
        HIGMainWindow.__init__(self)

        self.daddy = daddy

        self.tip_timer = -1
        self.main_accel_group = gtk.AccelGroup()
        self.add_accel_group(self.main_accel_group)

        self.viewernb = HIGNotebook()

        self.invsearch = SearchDB(umitdb)
        self.invdb = ConnectInventoryDB(umitdb)
        self.invtree = InventoryTree(self)
        self.invnb = HIGNotebook()
        self.invnb_close_btn = startup_options()["tabs_close_btn"]
        self.invnbpages_titles = [ ]
        self.invnbpages_objects = [ ]

        # timeline tab
        self.timeline = TLHolder()

        # statusbars
        self.std_statusbar = gtk.Statusbar()
        self.std_sb = self.std_statusbar.get_context_id("stdbar")
        self._write_statusbar("                              ")

        self.tip_statusbar = gtk.Statusbar()
        self.tip_statusbar.set_has_resize_grip(False)
        self.tip_sb = self.tip_statusbar.get_context_id("tipbar")
        self.write_tips = startup_options()["tips"]

        # timer for checking updates
        self.db_stat = os.stat(umitdb).st_mtime
        self.schema_stat = os.stat(Path.sched_schemas).st_mtime
        self.timer_updater = gobject.timeout_add(4200, # nice number
            self.__check_for_updates)

        # gui scheduler controller
        self.schedctrl = SchedControl(self)


        self.inventories = self.invtree.fill_tree()
        self._create_ui_manager()
        self.__set_props()
        self.__do_layout()

        self.connect('inventory-activated', self._inventory_activated)
        self.connect('delete-event', self._exit_ni)
        self.connect('realize', self.on_realize)


    def on_realize(self, event):
        """
        After realizing, change to first page in main notebook (Historic page).
        """
        self.viewernb.set_current_page(0)


    def _close_current_hosttab(self, event):
        """
        Closes current active Host tab.
        """
        holder = self.invnb.get_nth_page(self.invnb.get_current_page())
        if holder:
            title = self.invnb.get_tab_label_text(holder)
            p = self.invnbpages_objects[self.invnbpages_titles.index(title)]

            if len(p.pages):
                tab_label = p.pages[p.get_current_page()]
                content = p.get_nth_page(p.get_current_page())
                p.remove_page(None, content, tab_label)


    def _close_current_invtab(self, event):
        """
        Closes current active inventory notebook.
        """
        holder = self.invnb.get_nth_page(self.invnb.get_current_page())
        if holder:
            label = self.invnb.get_tab_label_text(holder)
            del_index = self.invnbpages_titles.index(label)

            page = self.invnbpages_objects[del_index]
            for p in xrange(page.get_n_pages()-1):
                tab_label = page.pages[p]
                content = page.get_nth_page(p)
                page.remove_page(None, content, tab_label)
            self._delete_inventory_page()


    def _delete_inventory_page(self):
        """
        Removed last page from an Inventory notebook, now remove the Inventory
        notebook.
        """
        cur_page = self.invnb.get_current_page()
        page = self.invnb.get_nth_page(cur_page)
        page_label = self.invnb.get_tab_label_text(page)
        del_index = self.invnbpages_titles.index(page_label)
        del self.invnbpages_titles[del_index]
        del self.invnbpages_objects[del_index]

        self.invnb.remove_page(cur_page)


    def _inventory_activated(self, event, data):
        """
        Activated some item on Inventory tree.
        """
        if not data['host_addr']: # empty inventory was selected
            # clicked on Inventory title, dont do nothing
            return

        title = data["root"] # inventory name

        # check if activated inventory isnt open already
        if not title in self.invnbpages_titles:
            # create new notebook to hold this Inventory
            newinvnb = InventoryNB(self)
            self.invnb.append_page(newinvnb, gtk.Label(title))

            self.invnbpages_titles.append(title)
            self.invnbpages_objects.append(newinvnb)

            # check if a host was activated
            if data["host_addr"][0] != inventory_info:
                box = self._load_inventory_host_data(title,
                    data["host_addr"][1])
                newinvnb.append_host(data["host_addr"][0], box)
            else:
                # inventory info
                box = self._load_inventory_data(title)
                if box:
                    newinvnb.append_inv(box=box)

        else:
            # get Inventory notebook
            p = self.invnbpages_objects[self.invnbpages_titles.index(title)]

            # check if a host was activated
            if data["host_addr"][0] != inventory_info and \
                not p.page_exists(data["host_addr"]):
                box = self._load_inventory_host_data(title,
                    data["host_addr"][1])
                p.append_host(data["host_addr"][0], box)

            # if it is not a host, it was inventory info
            elif data["host_addr"][0] == inventory_info:
                box = self._load_inventory_data(title)
                if box:
                    p.append_inv(box=box)


    def _load_inventory_data(self, inventory_name):
        """
        Load data for activated Inventory.
        """
        fk_inventory = self.invdb.get_inventory_id_for_name(inventory_name)
        scans = self.invdb.get_scans_id_for_inventory(fk_inventory)
        last_scan_id = scans[len(scans)-1][0]
        hosts = self.invtree.invdata[inventory_name]

        box = gtk.VBox()

        # scan info
        hb = gtk.HBox()
        hb.pack_start(gtk.Label(_("Scan count:") + (" %d" % len(scans))),
                False, False, 0)
        box.pack_start(hb, False, False, 0)

        hb = gtk.HBox()
        last_scan_date = self.invdb.get_finish_timestamp_for_scan_from_db(
                last_scan_id)
        hb.pack_start(
                gtk.Label(_("Last scan date:") + (" %s" % last_scan_date)),
                False, False, 0)
        box.pack_start(hb, False, False, 0)

        details = self.invdb.get_scan_details_for_scan_from_db(scans[0][0])
        detc = [
            _("Scan args"), _("XML output version"), _("Verbose"),
            _("Debugging"), _("Scanner name"), _("Scanner version")
            ]
        for indx, item in enumerate(details):
            hb = gtk.HBox()
            hb.pack_start(gtk.Label("%s: %s" % (detc[indx], item)), False,
                False, 0)
            box.pack_start(hb, False, False, 0)

        # "separator"
        box.pack_start(gtk.HSeparator(), False, False, 6)

        # hosts info
        hb = gtk.HBox()
        hb.pack_start(gtk.Label(
            _("Hosts: ") +
            ', '.join([host[0] for host in hosts])), False, False, 0)
        box.pack_start(hb, False, False, 0)

        hb = gtk.HBox()
        hb.pack_start(gtk.Label(_("Host count:") + (" %s" % len(hosts))),
                False, False, 0)
        box.pack_start(hb, False, False, 0)

        sw = gtk.ScrolledWindow()
        sw.add_with_viewport(box)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.show_all()

        return sw


    def _load_inventory_host_data(self, inventory_name, host_addr):
        """
        Load data for a host in an inventory.
        """
        changesd = ChangesDiff(self.invdb)
        changesl = ChangesList(self, self.invdb, changesd,
            data={-1: (inventory_name, host_addr)})

        paned = gtk.VPaned()
        paned.add1(changesl)
        paned.add2(changesd)

        return paned


    def _write_statusbar(self, msg):
        """
        Write some message at standard statusbar.
        """
        self.std_statusbar.pop(self.std_sb)
        self.std_statusbar.push(self.std_sb, msg)


    def _clear_statusbar(self):
        """
        Clear standard statusbar.
        """
        self.std_statusbar.pop(self.std_sb)


    def _write_statusbar_tip(self, tipmsg, timeout=True):
        """
        Write a tip at statusbar.
        """
        if not self.write_tips:
            # tips disabled
            return

        if not self.window: # widget being destroyed
            gobject.source_remove(self.tip_timer)
            return

        self.tip_statusbar.pop(self.tip_sb)
        self.tip_statusbar.push(self.tip_sb, tipmsg)

        if self.tip_timer != -1:
            gobject.source_remove(self.tip_timer)

        if timeout:
            # remove tip after 15 seconds
            self.tip_timer = gobject.timeout_add(15000,
                self._clear_tip_statusbar)


    def _clear_tip_statusbar(self):
        """
        Clear statusbar.
        """
        self.tip_statusbar.pop(self.tip_sb)
        gobject.source_remove(self.tip_timer)
        self.tip_timer = -1

        return False


    def _update_viewer(self):
        """
        Call this when needed to update Network Inventory Viewer.
        """
        inventories = self.invtree.fill_tree()

        # update Edit Inventories menu
        new_inventories = set(inventories).difference(set(self.inventories))
        self.inventories = inventories

        for inv in new_inventories:
            self.main_action_group.add_actions([("_" + inv, None, inv,
                None, inv, self._edit_inventory)])

            self.ui_manager.add_ui(self.ui_manager.new_merge_id(),
                "/menubar/Edit/Inventory", inv, "_" + inv, "menuitem", False)


    def _build_results_view(self, query, returned, buildnow=False):
        """
        Build a TreeView with returned results from search or perform search
        and then Build TreeView.
        """
        def close_page(widget, data):
            """
            Close search page.
            """
            page_num = self.viewernb.page_num(data)
            self.viewernb.remove_page(page_num)


        def row_activated(tv, path, tvcolumn):
            """
            Activated some row in results treeview.
            """
            # create page at "Inventory"
            model = tv.get_model()
            tv_iter = model.get_iter(path)
            host_addr = model.get_value(tv_iter, 1)

            data = { }
            root = model[path[0]][0]
            data["root"] = root
            data["host_addr"] = (host_addr, host_addr) # new format

            self.emit('inventory-activated', data)

            # write tip to statusbar
            self._write_statusbar_tip(_("A page was open at Historic tab!"))


        def buildtv(*args):
            """
            Build treeview and append results.
            """
            lsmodel = gtk.ListStore(str, str, str, str)
            tview = gtk.TreeView(lsmodel)
            columns = 4
            columns_text = (
                _("Inventory"), _("Host"),
                _("First Matched Category"), _("Entry Date")
                )
            tview.columns = [None]*columns

            for n in range(columns):
                tview.columns[n] = gtk.TreeViewColumn(columns_text[n])
                tview.columns[n].cell = gtk.CellRendererText()
                tview.columns[n].pack_start(tview.columns[n].cell, True)
                tview.columns[n].set_attributes(tview.columns[n].cell, text=n)

                tview.append_column(tview.columns[n])

            tview.connect('row-activated', row_activated)

            # layout
            matches = len(args[1])
            word = append_s(_("result"), matches)
            upper_title = gtk.Label()
            upper_title.set_markup(
                    ("<b>%d " % matches) + word + _(" found.") +
                    "</b>")
            hutbox = HIGHBox()
            hutbox._pack_noexpand_nofill(upper_title)
            sw = HIGScrolledWindow()
            sw.add(tview)
            vbox = gtk.VBox()
            vbox.pack_start(hutbox, False, False, 3)
            vbox.pack_start(sw, True, True, 0)

            vbox.show_all()

            # append results to treeview
            results = args[1]

            for res, date in results.items():
                invname = self.invdb.get_inventory_name_for_id(res[0])
                lsmodel.append((invname, res[1], res[2], str(date)))

            title = _("Search: %s") % args[0]
            tab_label = HIGAnimatedTabLabel(title)
            tab_label.connect("close-clicked", close_page, vbox)
            self.viewernb.append_page(vbox, tab_label)


        if buildnow:
            # uhm.. nice, we already have the results.
            buildtv(query, returned)

        else:
            # no results yet, will get them now!
            host_matches = { }

            for key, values in returned.items():
                host_id = key
                inv_id = values[0]
                host_addr = values[1]
                date = values[2]
                res = self.invsearch.search(host_id, query)
                if res: # res = category returned
                    host_matches[(inv_id, host_addr, res)] = date

            # build treeview now
            buildtv(query, host_matches)


    def _create_ui_manager(self):
        """
        Set up user interface.
        """
        self.ui_manager = gtk.UIManager()
        self.main_action_group = gtk.ActionGroup("MainActionGroup")

        about_icon = None
        try: about_icon = gtk.STOCK_ABOUT
        except: pass

        main_actions = [ \
            ("File", None, _("_File"), None),
            ("Edit", None, _("_Edit"), None),
            ("Scheduler", None, _("_Scheduler"), None),
            ("Help", None, _("_Help"), None),

            ("ToolbarOpt", None, _("Tool_bar"), None),
            ("InvTabs", None, _("Devices _tab"), None),
            ("Inventory", None, _("_Inventories"), None),

            # File
            ("New",
             gtk.STOCK_NEW, _("_New Inventory"),
             None, _("Create new Inventory"),
             self._create_new),

            ("CloseHostTab",
             None, _("Close Device tab"),
             "<Control>W", _("Close current host tab"),
             self._close_current_hosttab),

            ("CloseInvTab",
             None, _("Close Inventory tab"),
             "<Shift><Control>W", _("Close current Inventory tab"),
             self._close_current_invtab),

            ("Quit",
             gtk.STOCK_QUIT, _("_Quit"),
             None, _("Close Network Inventory"),
             self._exit_ni),

            # Edit
            ('Control Data Removal',
             None, _("Data Removal"),
             None, _("Data Removal"),
             self._edit_data_removal),

            ('Startup',
             None, _("Startup settings"),
             None, _("Startup settings"),
             self._edit_startup),

            # Scheduler
            # Scheduler log
            ('Sched Log',
             None, _("Scheduler log"),
             None, _("View Scheduler log"),
             self._open_sched_log),

            # Scheduler status
            ('Sched Control',
             self.schedctrl.stock_icon, self.schedctrl.status_text,
             None, self.schedctrl.status_text,
             self.schedctrl._scheduler_control),

            # Help
            ('Show Help',
             gtk.STOCK_HELP, _('_Help'),
             None, _('Shows the application help'),
             self._show_help),

            ('Report a bug',
             gtk.STOCK_DIALOG_INFO, _('_Report a bug'),
             '<Control>b', _("Report a bug"),
             self._show_bug_report),

            ('About',
             about_icon, _("_About"),
             '<Control>a', _("About UMIT Network Inventory"),
             self._show_about)

        ]

        toggle_actions = [
            # Edit
            ("ShowTips",
             None, _("Show ti_ps"),
             None, _("Enable disable tip showing"),
             lambda c: self.set_write_tips(not self.write_tips),
             self.write_tips),

            # Edit/Notebooks
            ("TabCloseBtn",
             None, _("Place close button"),
             None, _("Place a close button upon tab creation"),
             lambda c: self.set_invnb_cbtn(not self.invnb_close_btn),
             self.invnb_close_btn)
        ]

        default_ui = """
            <menubar>
                <menu action='File'>
                    <menuitem action='New' />
                    <separator />
                    <menuitem action='CloseHostTab' />
                    <menuitem action='CloseInvTab' />
                    <menuitem action='Quit' />
                </menu>
                <menu action='Edit'>
                    <menu action='InvTabs'>
                         <menuitem action='TabCloseBtn' />
                    </menu>
                    <menu action='Inventory'>
                    </menu>
                    <menuitem action='ShowTips' />
                    <menuitem action='Control Data Removal' />
                    <menuitem action='Startup' />
                </menu>
                <menu action='Scheduler'>
                    <menuitem action='Sched Log' />
                    <menuitem action='Sched Control' />
                </menu>
                <menu action='Help'>
                    <menuitem action='Show Help' />
                    <menuitem action='Report a bug' />
                    <menuitem action='About' />
                </menu>
            </menubar>
            <toolbar>
                <toolitem action='Sched Control' />
                <separator />
            </toolbar>
            """

        self.main_action_group.add_actions(main_actions)
        self.main_action_group.add_toggle_actions(toggle_actions)

        for action in self.main_action_group.list_actions():
            action.set_accel_group(self.main_accel_group)
            action.connect_accelerator()

        self.ui_manager.insert_action_group(self.main_action_group, 0)
        self.ui_manager.add_ui_from_string(default_ui)

        self.schedctrl.ui_action = self.main_action_group.get_action(
            'Sched Control')

        # add Inventories to edit menu
        for inv in self.inventories:
            self.main_action_group.add_actions([("_" + inv, None, inv,
                None, inv, self._edit_inventory)])

            self.ui_manager.add_ui(self.ui_manager.new_merge_id(),
                "/menubar/Edit/Inventory", inv, "_" + inv, "menuitem", False)


    def _edit_data_removal(self, event):
        """
        Open window for editing data removal for Inventories.
        """
        w = ConfigureDataRemoval()
        w.show_all()


    def _edit_inventory(self, event):
        """
        Open inventory for editing.
        """
        try:
            w = NewInventory(event.get_name()[1:], edit_mode=True)
        except NoInventory:
            return
        w.show_all()


    def _create_new(self, event):
        """
        Open dialog for creating New Inventory.
        """
        w = NewInventory()
        w.show_all()


    def _open_sched_log(self, event):
        """
        Open scheduler log.
        """
        winlog = SchedLog()
        winlog.show_all()


    def _edit_startup(self, event):
        """
        Open window for editing startup settings.
        """
        settwin = NISettings()
        settwin.show_all()


    def _show_help(self, event):
        """
        Open help manual.
        """
        show_help(self,"index.html")


    def _show_bug_report(self, event):
        """
        Open bug report window.
        """
        bug = BugReport()
        bug.show_all()


    def _show_about(self, event):
        """
        Open about window.
        """
        awin = About()
        awin.show_all()


    def _exit_ni(self, *args):
        """
        Do necessary cleanup before destroying window.
        """
        # remove tip timer if still running
        if self.tip_timer != -1:
            gobject.source_remove(self.tip_timer)
            self._clear_tip_statusbar()

        # stop updater timer
        gobject.source_remove(self.timer_updater)

        self.hide()

        # remove old data
        if get_decays()[1]:
            win = RemoveOldData()
            win.show_all()
            win.connect('destroy', self.__leave_ni)
        else:
            self.__leave_ni()


    def __leave_ni(self, *args):
        """
        If you are here, Network Inventory has been cleanedup succesfully.
        """
        if self.daddy:
            self.daddy.running_ni = False
            self.destroy()
        else:
            gtk.main_quit()


    def __check_for_updates(self):
        """
        Check for some possible visual update needed to be done.
        """
        do_update = False

        # check for database changes
        prev_stat = self.db_stat
        try:
            possibly_new = os.stat(umitdb).st_mtime
        except OSError:
            return True

        if prev_stat != possibly_new:
            do_update = True
            self.db_stat = possibly_new

        # check for changes in schemas
        prev_state = self.schema_stat
        try:
            possibly_new = os.stat(Path.sched_schemas).st_mtime
        except OSError:
            return True

        if prev_state != possibly_new:
            do_update = True
            self.schema_stat = possibly_new


        if do_update:
            self._update_viewer()

        return True


    def __set_props(self):
        """
        Set window properties.
        """
        self.set_title(_("UMIT Network Inventory"))
        self.invnb.set_scrollable(True)
        self.viewernb.set_scrollable(True)
        # a size for testing
        self.set_position(gtk.WIN_POS_CENTER)
        width, height = gtk.gdk.get_default_root_window().get_size()
        self.set_default_size((width * 3) / 4, (height * 3) / 4)


    def __do_layout(self):
        """
        Layout window widgets.
        """
        main_vbox = gtk.VBox()
        main_hpaned = gtk.HPaned()
        nb_tl_hpaned = gtk.HPaned()

        menubar = self.ui_manager.get_widget('/menubar')
        main_vbox.pack_start(menubar, False, False, 0)

        schedbar = self.ui_manager.get_widget('/toolbar')
        schedbar.set_show_arrow(False)
        schedbar.set_style(gtk.TOOLBAR_ICONS)
        toolbar = SearchBar(self, self.invdb)

        toolbar_box = gtk.HBox()
        toolbar_box.pack_start(schedbar, False, False, 0)
        toolbar_box.pack_start(toolbar, True, True, 0)
        main_vbox.pack_start(toolbar_box, False, False, 0)

        left_pane_box = gtk.VBox()
        left_pane_box.pack_start(self.invtree, True, True, 0)

        main_hpaned.add1(left_pane_box)
        main_hpaned.add2(nb_tl_hpaned)

        # inventories notebook
        nb_tl_hpaned.pack1(self.invnb, True, False)

        self.viewernb.append_page(main_hpaned, gtk.Label(_(" Historic ")))
        self.viewernb.append_page(self.timeline, gtk.Label(_(" Timeline ")))

        self.timeline.show_all()

        main_vbox.pack_start(self.viewernb, True, True, 0)

        sbs_box = gtk.HBox()
        sbs_box.add(self.tip_statusbar)
        sbs_box.add(self.std_statusbar)
        main_vbox.pack_end(sbs_box, False, False, 0)

        self.add(main_vbox)


    def get_write_tips(self):
        """
        Returns True if tips should be written at statusbar, otherwise, False.
        """
        return self.__wtips


    def set_write_tips(self, write):
        """
        Sets to write tips or not at statusbar.
        """
        self.__wtips = write
        if not self.write_tips:
            self.tip_statusbar.pop(self.tip_sb)


    def get_invnb_cbtn(self):
        """
        Returns True if Inventory tabs have a close button placed on them.
        """
        return self.__invcbtn


    def set_invnb_cbtn(self, enable):
        """
        Sets to show or not close button in each Inventory tab.
        """
        self.__invcbtn = enable


    # Properties
    write_tips = property(get_write_tips, set_write_tips)
    invnb_close_btn = property(get_invnb_cbtn, set_invnb_cbtn)
Esempio n. 6
0
class InterfaceEditor(HIGMainWindow):
    def __init__(self, daddy=None):
        HIGMainWindow.__init__(self)
        self._proprieties = None
        self.profile_box = None
        self.wizard_box = None
        self._current_edit_mode = None
        self._tooldesign = None
        self.profile_box_b = None
        self.wizard_box_b = None
        self.edit_mode_opt = None
        self._show_bar = True
        self.set_title(_("Interface Editor"))
        self.set_size_request(800, 400)
        self.set_position(gtk.WIN_POS_CENTER)
        # self.maximize()
        self.list_options_box = OptionList()
        self.notebook = HIGNotebook()
        self._proprieties = Proprieties()
        self.create_profile_edit()
        self.create_wizard_edit()
        self.obj = self.profile_box
        # Create Widgets
        self.__create_widgets()
        # Packing - Group of widgets
        self.__pack_widgets()
        self.__option_display()
        self.edit_mode_opt = "Options"

        self.connect("delete_event", self._destroy)

        self.opt_display.set_profile(self.profile_box)
        self.opt_display.set_wizard(self.wizard_box)
        self.profile_box.notebook.connect_after("need-save", self._update_menu_s)
        self.wizard_box.notebook.connect_after("need-save", self._update_menu_s)
        self.profile_box.notebook.connect_after("changed", self._update_menu)
        self.wizard_box.notebook.connect_after("changed", self._update_menu)
        self.opt_display.connect_after("need-save", self._update_menu_s)

        self.daddy = daddy

    def _update_menu(self, actions, others, page):
        obj = None
        if self.edit_mode_opt == "Profile":
            obj = self.profile_box
        elif self.edit_mode_opt == "Wizard":
            obj = self.wizard_box
        if obj == None:
            return
        # Check if there is something selected:
        current_page = obj.notebook.get_nth_page(obj.notebook.get_current_page())
        if obj.notebook._old_select != None:
            # Section is Selected
            log.debug("Section is selected << updating toolbar")

            pass
        elif current_page._old_selected != None:
            # Item Selected
            log.debug("Item is selected << updating toolbar")
            pass

    def _update_menu_s(self, action, others, page):
        log.debug("<<< Update Main menubar ")
        save = self.main_action_group.get_action("Save")
        save_all = False
        if self.edit_mode_opt == "Profile":
            log.debug("profile updating menubar save")
            value = self.profile_box.is_changed()
            save.set_sensitive(value)
        elif self.edit_mode_opt == "Wizard":
            log.debug("wizard updating menubar save")
            value = self.wizard_box.is_changed()
            save.set_sensitive(value)

        elif self.edit_mode_opt == "Options":
            log.debug("options updating menubar save")
            value = self.opt_display.is_changed()
            save.set_sensitive(value)

        save_all = self.opt_display.is_changed() or self.wizard_box.is_changed() or self.profile_box.is_changed()
        self.main_action_group.get_action("Save all").set_sensitive(save_all)

    def _destroy(self, widget, event):
        self.quit(widget)

    def create_wizard_edit(self):
        """
        create a profile area editing 
        and connect to Undo Redo Manager to update the buttons 
        """
        if self.wizard_box != None:
            self.wizard_box.set_proprieties(self._proprieties)
        if self.wizard_box == None:
            self.wizard_box = WizardEdit(self.list_options_box.get_list_option())

        self.wizard_box.set_notebook(self.notebook)

    def create_profile_edit(self):
        """
        create a profile area editing 
        and connect to Undo Redo Manager to update the buttons 
        """
        if self.profile_box != None:
            self.profile_box.set_proprieties(self._proprieties)

        if self.profile_box == None:
            self.profile_box = ProfileEdit(self.list_options_box.get_list_option())

        command_manager.connect_after("changed", self._update_undo_redo_cb)
        self.profile_box.set_notebook(self.notebook)

    def _update_undo_redo_cb(self, action, other):
        """
        Verify if exists undo and redo
        and update the buttons on the toolbar/menubar
        #DO:
        - sensitive -> True/False
        - Ajust tips 
        ####
        """

        can_undo = command_manager.can_undo()
        can_redo = command_manager.can_redo()
        self.main_action_group.get_action("Undo").set_sensitive(can_undo)
        self.main_action_group.get_action("Redo").set_sensitive(can_redo)
        if can_undo:
            self.main_action_group.get_action("Undo").tooltip = "sss"
            self.main_action_group.get_action("Undo").create_menu_item()

    def __create_widgets(self):
        """
        Create widgets 
        """
        self.main_vbox = gtk.VBox()
        self.widgets = {}

        # UI Manager
        self.__create_ui_manager()
        # Table - contains menubar and toolbar

        # Menubar
        self.__create_menubar()
        # Toolbar
        self.__create_toolbar()

        self.display_frame = HIGFrame()
        self.display_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.display_frame.set_border_width(6)

        self.hbox_edit = gtk.HBox()
        self.hspacer = gtk.HPaned()
        self.hspacer.set_border_width(0)
        self.vbox_right = HIGVBox()
        self.vbox_left = HIGVBox()

        self.edit_mode_exp = gtk.Expander(_("Edit Modes"))
        self.edit_mode_box = self.create_edit_mode()

        self.notebook.set_scrollable(True)
        self.notebook.append_page(self.list_options_box, HIGEntryLabel(_("Option List")))

        self.list_options_box.reload()

        self.__create_status_bar()

    def __option_display(self):

        self.display_frame.set_label("Options")
        self.opt_display = OptionDisplayMainFrame()
        self.opt_display.set_options_list(self.list_options_box)
        self.list_options_box.set_option_display(self.opt_display)
        self.display_frame.add_with_properties(self.opt_display)
        self.vbox_left.pack_start(self.display_frame, False, False)

    def __pack_widgets(self):
        """
        Packing widgets of mainly windows 
        """

        self.add(self.main_vbox)

        # Pack widgets to main_box

        self.main_vbox.pack_start(self.hbox_edit, True, True)

        # Paned
        self.hbox_edit.pack_start(self.hspacer)
        separator = gtk.VSeparator()
        self.hspacer.pack1(self.vbox_left, False, False)
        self.hspacer.set_position(580)
        self.hspacer.pack2(self.vbox_right, False, True)

        # Edit Mode
        self.edit_mode_exp.add(self.edit_mode_box)
        self.edit_mode_exp.set_expanded(True)

        # Frame right
        self.vbox_right.pack_start(self.edit_mode_exp, False, False)
        self.vbox_right.pack_end(self.notebook, True, True)

        # Status bar
        self.main_vbox.pack_start(self.statusbar, False, False)

    def create_edit_mode(self):
        """
        Create a treeview that contains a three edit modes 
        returns vbox contains a treeview

        @return: returns the treeview with list of edit modes 
        @rtype: vbox
        """

        model = gtk.TreeStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
        self.edit_mode_tv = gtk.TreeView(model)
        self.edit_mode_tv.set_headers_visible(False)
        renderer = gtk.CellRendererText()
        cell_renderer_pix = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn()
        column.set_title(_("Name"))
        column.pack_start(cell_renderer_pix, False)
        column.add_attribute(cell_renderer_pix, "pixbuf", 0)
        column.pack_start(renderer, True)
        column.add_attribute(renderer, "text", 1)

        self.edit_mode_tv.append_column(column)
        myiter = model.insert_before(None, None)
        icon = gtk.Image()
        icon = icon.render_icon("gtk-edit", gtk.ICON_SIZE_MENU)
        model.set_value(myiter, 0, icon)
        model.set_value(myiter, 1, "Profile")
        myiter = model.insert_before(None, None)
        icon = gtk.Image()
        icon = icon.render_icon("gtk-convert", gtk.ICON_SIZE_MENU)
        model.set_value(myiter, 0, icon)
        model.set_value(myiter, 1, "Wizard")
        myiter = model.insert_before(None, None)
        icon = gtk.Image()

        icon = icon.render_icon(gtk.STOCK_DND_MULTIPLE, gtk.ICON_SIZE_MENU)
        model.set_value(myiter, 0, icon)
        model.set_value(myiter, 1, "Options")
        selection = self.edit_mode_tv.get_selection()
        selection.select_iter(myiter)
        self.edit_mode_tv.connect("cursor-changed", self.change_edit_mode)
        vbox = HIGVBox()
        vbox.pack_start(self.edit_mode_tv, False, False)
        return vbox

    def change_edit_mode(self, widget):
        """
        Change box of main screen and others changes at toolbar
        """
        selection = self.edit_mode_tv.get_selection()
        (model, iter) = selection.get_selected()
        edit = model.get_value(iter, 1)
        if edit == "Options" and not self.edit_mode_opt == "Options":
            self._remove_previews()
            self.edit_mode_opt = "Options"
            self.display_frame.show_all()
            if self.notebook.get_n_pages > 1:
                self.notebook.remove_page(-1)
                self.notebook.remove_page(-1)
            self._set_menus_editor(False)

        elif edit == "Profile" and not self.edit_mode_opt == "Profile":
            self._remove_previews()
            self.edit_mode_opt = "Profile"
            bool = self.profile_box_b == None
            self.create_profile_edit()
            if bool:
                self.vbox_left.pack_start(self.profile_box, True, True)
                self.profile_box_b = True
            log.debug("<<< show :: Profile Edit Mode :: ")
            self.profile_box.show_all()
            self.profile_box.notebook.put_on_page()
            self._create_tooldesign()
            self._set_menus_editor(True)
            self.profile_box.show()
            self.obj = self.profile_box
        elif edit == "Wizard" and not self.edit_mode_opt == "Wizard":
            log.debug("<<< show :: Wizard Edit Mode - basic mode ")
            self._remove_previews()
            self.edit_mode_opt = "Wizard"
            self._set_menus_editor(True)
            bool = self.wizard_box_b == None
            self.create_wizard_edit()
            if bool:
                self.vbox_left.pack_start(self.wizard_box, True, True)
                self.wizard_box_b = True

            self.wizard_box.show_all()
            self.wizard_box.notebook.put_on_page()
            self._create_tooldesign()
            self.wizard_box.show()
            self.obj = self.wizard_box

    def _remove_previews(self):
        """
        Remove the previews Edit mode
        """
        # XXX Lack the toolbars and some ajusts
        if self.edit_mode_opt == "Profile":
            # self.vbox_left.remove(self.profile_box)
            self.profile_box.hide_all()
        elif self.edit_mode_opt == "Options":
            # self.vbox_left.remove(self.display_frame)
            self.display_frame.hide_all()
        elif self.edit_mode_opt == "Wizard":
            self.wizard_box.hide_all()

    def _create_tooldesign(self):
        """
        create tooldesign that contains widgets to put 
        in work area of edit profile
        """
        if self._tooldesign == None:
            self._tooldesign = ToolDesign()

        if self._proprieties == None:
            self._proprieties = Proprieties()
        if self.notebook.get_n_pages() < 2:
            self.notebook.append_page(self._tooldesign, HIGEntryLabel(_("Design")))
            self.notebook.append_page(self._proprieties, HIGEntryLabel(_("Proprieties")))
        self.notebook.show_all()
        if self.edit_mode_opt == "Profile":
            obj = self.profile_box
        elif self.edit_mode_opt == "Wizard":
            obj = self.wizard_box
        obj.set_proprieties(self._proprieties)
        profilecore = obj.get_profilecore()
        self._proprieties.set_profilecore(profilecore)

    def __optinlist_from_group(self):
        """
        After Select a Option from a group this treeview refresh options lists
        that each group contains
        """
        model = gtk.TreeStore(gobject.TYPE_STRING)
        self.profile_optionlist_tvw = gtk.TreeView(model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name", renderer, text=0)
        self.profile_optionlist_tvw.append_column(column)

        self.wizard_file = PWOptions(profile_editor)
        group_list = self.wizard_file.read("group", "name", "group")
        for i, v in group_list:
            myiter = model.insert_after(None, None)
            model.set_value(myiter, 0, i)

    def __proprieties(self):
        """
        Create a editable options - Proprieties of Options
        """
        # Create a listview with options
        self.prop_frame_option = gtk.Frame()
        self.prop_frame_option.set_label("List Options")
        self.prop_frame_option.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        prop_sw = HIGScrolledWindow()
        prop_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        prop_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        model = gtk.TreeStore(gobject.TYPE_STRING)
        treeview = gtk.TreeView(model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name", renderer, text=0)
        treeview.append_column(column)
        self.prop_frame_option.add(treeview)
        self.prop_frame_option.add(prop_sw)

        """
        Box Edit 
        """

        # Frame
        self.prop_frame = gtk.Frame()
        self.prop_frame.set_label("Edit Option")
        self.prop_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.prop_exp = HIGExpander("Proprieties")

        label = gtk.Label("s")
        self.prop_exp.add(label)
        self.prop_frame.add(self.prop_exp)

    def __grouplist(self):
        """
        Group List, Tree view 
        """

        model = gtk.TreeStore(gobject.TYPE_STRING)
        self.treeview = gtk.TreeView(model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name", renderer, text=0)
        self.treeview.append_column(column)

        self.wizard_file = PWOptions(profile_editor)
        group_list = self.wizard_file.read("group", "name", "group")
        for i, v in group_list:
            myiter = model.insert_after(None, None)
            model.set_value(myiter, 0, i)

    def __create_toolbar(self):
        """
        Create a Main Toolbar of Profile Wizard Editor
        """

        self.toolbar = self.ui_manager.get_widget("/toolbar")
        self.toolbar.set_style(gtk.TOOLBAR_BOTH)

        self.main_vbox.pack_start(self.toolbar, False, True, 0)
        self.toolbar.show_all()

    def save_all(self, widget):
        # if self.opt_display.is_changed():
        # XXX BUG (is_changed method is in OptionList)
        self.list_options_box.save()
        if self.profile_box.is_changed():
            self.profile_box.save()
        if self.wizard_box.is_changed():
            self.wizard_box.save()

    def _set_menus_editor(self, value):
        self.main_action_group.get_action("Items").set_sensitive(value)
        self.main_action_group.get_action("Section").set_sensitive(value)
        if self.edit_mode_opt != None:
            self._update_menu_s(None, None, None)

    def save(self, widget):
        if self.edit_mode_opt == "Options":
            obj = self.list_options_box
        elif self.edit_mode_opt == "Profile":
            obj = self.profile_box
        elif self.edit_mode_opt == "Wizard":
            obj = self.wizard_box

        obj.save()

    def quit(self, widget):
        """
        Leaving of Interface Editor
        """
        if self.daddy:  # Run from Umit Network Scanner by menus
            self.daddy.running_ie = False
            self.destroy()
        else:  # Run from command line directly
            gtk.main_quit()

    def np(self, widget):
        print "Don't work yet"

    def __create_ui_manager(self):
        """
        Create a UI Manager
        """
        self.ui_manager = gtk.UIManager()
        self.main_action_group = gtk.ActionGroup("MainActionGroup")
        self.main_actions = [
            ("File", None, _("_File"), None),
            ("Save", gtk.STOCK_SAVE, _("_Save"), None, _("Save"), self.save),
            ("Save all", gtk.STOCK_SAVE, _("_Save all"), None, _("Save all"), self.save_all),
            ("Quit", gtk.STOCK_QUIT, _("_Quit"), None, _("Quit"), self.quit),
            ("Edit", None, _("Edit"), None),
            ("Undo", gtk.STOCK_UNDO, _("_Undo"), "<Control>z", _("Undo"), self._undo_cb),
            ("Redo", gtk.STOCK_REDO, _("_Redo"), "<Control>r", _("Redo"), self._redo_cb),
            ("View", None, _("View"), None),
            ("Right Bar", None, _("_Right Bar"), None, _("Right Bar"), self._hide_right),
            ("Tools", None, _("Tools"), None),
            ("Section", None, _("Section"), None),
            ("Items", None, _("Items"), None),
            ("Insert label", None, _("_Label"), None, _("Insert label"), self.np),
            ("New Section", None, _("_New Section"), None, _("New Section"), self._add_section),
            (
                "Remove Section Label",
                None,
                _("_Remove Section Label"),
                None,
                _("Remove Section Label"),
                self._remove_section,
            ),
            ("Remove Section", None, _("_Remove Section"), None, _("Remove Section"), self._remove_section),
            ("Add new voidplace", None, _("_Add new voidplace"), None, _("Add new voidplace"), self._add_place),
            ("Remove option", None, _("_Remove Option"), None, _("Remove option"), self._remove_option),
            ("Remove voidplace", None, _("_Remove voidplace"), None, _("Remove voidplace"), self._remove_option),
            ("Add option selected", None, _("_Add option selected"), None, _("Add option selected"), self.np),
            ("Move Section Left", None, _("_Move Section Left"), None, _("Move Section Left"), self._move_section_left),
            (
                "Move Section Right",
                None,
                _("_Move Section Right"),
                None,
                _("Move Section Right"),
                self._move_section_right,
            ),
            ("Move Item Down", None, _("_Move Item Down"), None, _("Move Item Down"), self._move_item_down),
            ("Move Item Up", None, _("_Move Item Up"), None, _("Move Item Up"), self._move_item_up),
            ("Help", None, _("Help"), None),
            ("About", gtk.STOCK_PASTE, _("_About"), None, _("About"), self.np),
        ]

        self.ui_info = """
            <menubar>
            <menu action='File'>
            <menuitem action='Save'/>
            <menuitem action='Save all'/>
            <separator/>
            <menuitem action='Quit'/>
            </menu>
            <menu action='Edit'>
            <menuitem action='Undo'/>
            <menuitem action='Redo'/>
            </menu>
            <menu action='View'>
            <menuitem action='Right Bar'/>
            </menu>
            <menu action='Section'>
            <menuitem action='Insert label'/>
            <menuitem action='New Section'/>
            <menuitem action='Remove Section Label'/>
            <menuitem action='Remove Section'/>
            <menuitem action='Move Section Left'/>
            <menuitem action='Move Section Right'/>
            </menu>
            <menu action='Items'>
            <menuitem action='Add new voidplace'/>
            <menuitem action='Remove option'/>
            <menuitem action='Remove voidplace'/>
            <menuitem action='Move Item Up'/>
            <menuitem action='Move Item Down'/>
            </menu>

            </menubar>
            <toolbar>
            <toolitem action='Save'/>
            <toolitem action='Save all'/>
            <separator/>
            <toolitem action='Undo'/>
            <toolitem action='Redo'/>

            <separator/>
            <toolitem action='Quit'/>
            </toolbar>
            """

        self.main_action_group.add_actions(self.main_actions)
        self.main_accel_group = gtk.AccelGroup()
        for action in self.main_action_group.list_actions():

            action.set_accel_group(self.main_accel_group)
            action.connect_accelerator()

        # ENABLE = FALSE
        self.main_action_group.get_action("Save all").set_sensitive(False)
        self.main_action_group.get_action("Save").set_sensitive(False)
        self.main_action_group.get_action("Undo").set_sensitive(False)
        self.main_action_group.get_action("Redo").set_sensitive(False)

        self._set_menus_editor(False)
        # END ENABLE

        self.ui_manager.insert_action_group(self.main_action_group, 0)
        self.ui_manager.add_ui_from_string(self.ui_info)
        self.add_accel_group(self.main_accel_group)

    # ACTIONS
    def _add_section(self, widget):
        self.obj._toolbar._add_section(widget)

    def _remove_section(self, widget):
        self.obj._toolbar._remove_section(widget)

    def _add_place(self, widget):
        self.obj._toolbar._add_place(widget)

    def _move_item_up(self, widget):
        self.obj._toolbar._move_item_down(widget)

    def _move_item_down(self, widget):
        self.obj._toolbar._move_item_down(widget)

    def _move_section_left(self, widget):
        self.obj._toolbar._move_section_left(widget)

    def _move_section_right(self, widget):
        self.obj._toolbar._move_section_right(widget)

    def _remove_option(self, widget):
        self.obj._toolbar._remove_option(widget)

    def _hide_right(self, widget):
        if self._show_bar:
            self.vbox_right.hide_all()
        else:
            self.vbox_right.show_all()
        self._show_bar = not self._show_bar

    def _undo_cb(self, widget):
        command_manager.do_undo()

    def _redo_cb(self, widget):
        command_manager.do_redo()

    def __create_menubar(self):
        """
        Create a menubar 
        """

        self.menubar = self.ui_manager.get_widget("/menubar")

        self.main_vbox.pack_start(self.menubar, False, True, 0)

        self.menubar.show_all()

    def __create_status_bar(self):
        """
        create status bar 
        """
        self.statusbar = gtk.Statusbar()

        context_id = self.statusbar.push(1, " ")
        self.statusbar.show()