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)
Пример #2
0
    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 __create_widgets(self):
        self.main_vbox = HIGVBox()

        self.command_expander = HIGExpander('<b>' + _('Command') + '</b>')
        self.command_expander.set_expanded(True)
        self.command_entry = gtk.Entry()

        self.notebook = gtk.Notebook()

        # Profile info page
        self.profile_info_vbox = HIGVBox()
        self.profile_info_label = HIGSectionLabel(_('Profile Information'))
        self.profile_name_label = HIGEntryLabel(_('Profile name'))
        self.profile_name_entry = gtk.Entry()
        self.profile_hint_label = HIGEntryLabel(_('Hint'))
        self.profile_hint_entry = gtk.Entry()
        self.profile_description_label = HIGEntryLabel(_('Description'))
        #self.profile_description_label = HIGHBox()
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_text = HIGTextView()
        self.profile_annotation_label = HIGEntryLabel(_('Annotation'))
        #self.profile_annotation_label = HIGHBox()
        self.profile_annotation_scroll = HIGScrolledWindow()
        self.profile_annotation_text = HIGTextView()

        # Buttons
        self.buttons_hbox = HIGHBox()

        self.help_button = HIGButton(stock=gtk.STOCK_HELP)
        self.help_button.connect('clicked', self.help)

        #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        #self.delete_button.connect('clicked', self.delete_profile)

        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel_button.connect('clicked', self.quit_without_saving)

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)
Пример #4
0
    def __create_widgets(self):
        self.main_vbox = HIGVBox()



        self.command_expander = HIGExpander('<b>'+_('Command')+'</b>')
        self.command_expander.set_expanded(True)
        self.command_entry = gtk.Entry()

        self.notebook = gtk.Notebook()

        # Profile info page
        self.profile_info_vbox = HIGVBox()
        self.profile_info_label = HIGSectionLabel(_('Profile Information'))
        self.profile_name_label = HIGEntryLabel(_('Profile name'))
        self.profile_name_entry = gtk.Entry()
        self.profile_hint_label = HIGEntryLabel(_('Hint'))
        self.profile_hint_entry = gtk.Entry()
        self.profile_description_label = HIGEntryLabel(_('Description'))
        #self.profile_description_label = HIGHBox() 
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_text = HIGTextView()
        self.profile_annotation_label = HIGEntryLabel(_('Annotation'))
        #self.profile_annotation_label = HIGHBox() 
        self.profile_annotation_scroll = HIGScrolledWindow()
        self.profile_annotation_text = HIGTextView()

        # Buttons
        self.buttons_hbox = HIGHBox()

        self.help_button = HIGButton(stock=gtk.STOCK_HELP)
        self.help_button.connect('clicked', self.help)

        #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        #self.delete_button.connect('clicked', self.delete_profile)

        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel_button.connect('clicked', self.quit_without_saving)

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)
class ProfileEditor(HIGWindow):
    def __init__(self, profile_name=None, delete=False):
        HIGWindow.__init__(self)
        self.set_title(_('Profile Editor'))
        self.set_position(gtk.WIN_POS_CENTER)
        self.profile_name = profile_name
        self.__create_widgets()
        self.__pack_widgets()

        self.scan_notebook = None
        self.profilemanager = None

        self.profile = CommandProfile()

        self.deleted = False
        options_used = {}

        if profile_name:
            log.debug("Showing profile %s" % profile_name)
            prof = self.profile.get_profile(profile_name)
            options_used = prof['options']

            # Interface settings
            self.profile_name_entry.set_text(profile_name)
            self.profile_hint_entry.set_text(prof['hint'])
            self.profile_description_text.get_buffer().set_text(
                prof['description'])
            self.profile_annotation_text.get_buffer().set_text(
                prof['annotation'])

            if delete:
                # Removing profile. It must be saved again
                self.remove_profile()

        self.constructor = CommandConstructor(options_used)
        self.options = OptionBuilder(profile_editor_file, self.constructor,
                                     self.update_command)
        log.debug("Option groups: %s" % str(self.options.groups))
        log.debug("Option section names: %s" % str(self.options.section_names))
        #log.debug("Option tabs: %s" % str(self.options.tabs))

        for tab in self.options.groups:
            self.__create_tab(tab, self.options.section_names[tab],
                              self.options.tabs[tab])

        self.update_command()

    def update_command(self):
        """Regenerate command with target '<target>' and set the value for the command entry"""
        self.command_entry.set_text(self.constructor.get_command('<target>'))

    def help(self, widget):
        """
        Show help documentation of Profile Editor
        """
        show_help(self, "profile_editor.html#introduction")

    def __create_widgets(self):
        self.main_vbox = HIGVBox()

        self.command_expander = HIGExpander('<b>' + _('Command') + '</b>')
        self.command_expander.set_expanded(True)
        self.command_entry = gtk.Entry()

        self.notebook = gtk.Notebook()

        # Profile info page
        self.profile_info_vbox = HIGVBox()
        self.profile_info_label = HIGSectionLabel(_('Profile Information'))
        self.profile_name_label = HIGEntryLabel(_('Profile name'))
        self.profile_name_entry = gtk.Entry()
        self.profile_hint_label = HIGEntryLabel(_('Hint'))
        self.profile_hint_entry = gtk.Entry()
        self.profile_description_label = HIGEntryLabel(_('Description'))
        #self.profile_description_label = HIGHBox()
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_text = HIGTextView()
        self.profile_annotation_label = HIGEntryLabel(_('Annotation'))
        #self.profile_annotation_label = HIGHBox()
        self.profile_annotation_scroll = HIGScrolledWindow()
        self.profile_annotation_text = HIGTextView()

        # Buttons
        self.buttons_hbox = HIGHBox()

        self.help_button = HIGButton(stock=gtk.STOCK_HELP)
        self.help_button.connect('clicked', self.help)

        #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        #self.delete_button.connect('clicked', self.delete_profile)

        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel_button.connect('clicked', self.quit_without_saving)

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)

    def __pack_widgets(self):
        self.add(self.main_vbox)

        # Packing widgets to main_vbox

        self.main_vbox._pack_noexpand_nofill(self.command_expander)
        self.main_vbox._pack_expand_fill(self.notebook)
        self.main_vbox._pack_noexpand_nofill(self.buttons_hbox)

        # Packing command_entry on command_expander
        self.command_expander.hbox.pack_start(self.command_entry)

        # Packing profile information tab on notebook
        self.notebook.append_page(self.profile_info_vbox,
                                  gtk.Label(_('Profile')))
        self.profile_info_vbox.set_border_width(5)
        table = HIGTable()
        self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label)
        self.profile_info_vbox._pack_noexpand_nofill(HIGSpacer(table))

        self.profile_annotation_scroll.add(self.profile_annotation_text)
        self.profile_description_scroll.add(self.profile_description_text)

        vbox_desc = HIGVBox()
        vbox_desc._pack_noexpand_nofill(self.profile_description_label)
        vbox_desc._pack_expand_fill(hig_box_space_holder())

        vbox_ann = HIGVBox()
        vbox_ann._pack_noexpand_nofill(self.profile_annotation_label)
        vbox_ann._pack_expand_fill(hig_box_space_holder())
        table.attach(self.profile_name_label, 0, 1, 0, 1)
        table.attach(self.profile_name_entry, 1, 2, 0, 1)
        #table.attach(self.profile_hint_label,0,1,1,2,xoptions=0)
        table.attach(self.profile_hint_label, 0, 1, 1, 2)
        table.attach(self.profile_hint_entry, 1, 2, 1, 2)
        table.attach(vbox_desc, 0, 1, 2, 3)
        table.attach(self.profile_description_scroll, 1, 2, 2, 3)
        table.attach(vbox_ann, 0, 1, 3, 4)
        table.attach(self.profile_annotation_scroll, 1, 2, 3, 4)

        # Packing buttons on button_hbox
        self.buttons_hbox.pack_start(self.help_button)
        #self.buttons_hbox.pack_start(self.delete_button)
        self.buttons_hbox.pack_start(self.cancel_button)
        self.buttons_hbox.pack_start(self.ok_button)

        self.buttons_hbox.set_border_width(5)
        self.buttons_hbox.set_spacing(6)

    def __create_tab(self, tab_name, section_name, tab):
        log.debug(">>> Tab name: %s" % tab_name)
        log.debug(">>>Creating profile editor section: %s" % section_name)

        vbox = HIGVBox()
        table = HIGTable()
        section = HIGSectionLabel(section_name)

        vbox._pack_noexpand_nofill(section)
        vbox._pack_noexpand_nofill(HIGSpacer(table))
        vbox.set_border_width(6)

        tab.fill_table(table, True)
        self.scrollwindow = HIGScrolledWindow()
        self.scrollwindow.set_size_request(600, 300)
        vp = gtk.Viewport()
        vp.add(vbox)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self.scrollwindow.add(vp)

        vbox_tmp = HIGVBox()
        vbox_tmp.set_border_width(6)
        vbox_tmp.set_spacing(12)
        vbox_tmp.pack_start(self.scrollwindow)

        self.notebook.append_page(vbox_tmp, gtk.Label(tab_name))

    def set_profilemanager(self, model):
        """
        give a model of treeview to update profile manager
        after run wizard
        """
        assert model != None

        self.model = model
        self.profilemanager = True

    def update_profilemanager(self):
        """
        Update treeview of ProfileManager"
        """
        assert self.profilemanager

        profiles = self.profile.sections()
        profiles.sort()
        self.model.clear()

        for command in profiles:
            myiter = self.model.insert_before(None, None)
            self.model.set_value(myiter, 0, command)
            self.model.set_value(myiter, 1, self.profile.get_hint(command))

    def save_profile(self, widget):
        profile_name = self.profile_name_entry.get_text()

        if profile_name == '':
            alert = HIGAlertDialog(message_format=_('Unnamed profile'),\
                                   secondary_text=_('You must provide a name \
for this profile.'                  ))

        elif profile_name.lower() == 'default':
            alert = HIGAlertDialog(message_format=_('Reserved profile name'),\
                                   secondary_text=_('Cannot assign "default" \
name to this profile. Please rename it and retry.'                                                  ))
        else:
            alert = None

        if alert:
            alert.run()
            alert.destroy()

            self.notebook.set_current_page(0)
            self.profile_name_entry.grab_focus()

            return None

        if not self.deleted:
            self.remove_profile()

        command = self.constructor.get_command('%s')
        hint = self.profile_hint_entry.get_text()

        buf = self.profile_description_text.get_buffer()
        description = buf.get_text(buf.get_start_iter(),\
                                   buf.get_end_iter())

        buf = self.profile_annotation_text.get_buffer()
        annotation = buf.get_text(buf.get_start_iter(),\
                                  buf.get_end_iter())
        self.profile.add_profile(profile_name,\
                                 command=command,\
                                 hint=hint,\
                                 description=description,\
                                 annotation=annotation,\
                                 tool='nmap',\
                                 options=self.constructor.get_options())
        self.deleted = False
        if self.profilemanager:
            self.update_profilemanager()

        self.quit()

    def clean_profile_info(self):
        self.profile_name_entry.set_text('')
        self.profile_hint_entry.set_text('')
        self.profile_description_text.get_buffer().set_text('')
        self.profile_annotation_text.get_buffer().set_text('')

    def set_notebook(self, notebook):
        self.scan_notebook = notebook

    def quit(self, widget=None, extra=None):
        if self.deleted:
            dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                        gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
            alert = HIGEntryLabel('<b>' + _("Deleting Profile") + '</b>')
            text = HIGEntryLabel(
                _('Your profile is going to be deleted! Click\
                                   Ok to continue, or Cancel to go back to Profile Editor.'
                  ))
            hbox = HIGHBox()
            hbox.set_border_width(5)
            hbox.set_spacing(12)

            vbox = HIGVBox()
            vbox.set_border_width(5)
            vbox.set_spacing(12)

            image = gtk.Image()
            image.set_from_stock(gtk.STOCK_DIALOG_WARNING,
                                 gtk.ICON_SIZE_DIALOG)

            vbox.pack_start(alert)
            vbox.pack_start(text)
            hbox.pack_start(image)
            hbox.pack_start(vbox)

            dialog.vbox.pack_start(hbox)
            dialog.vbox.show_all()

            response = dialog.run()
            dialog.destroy()

            if response == gtk.RESPONSE_CANCEL:
                return None
        self.destroy()
        if self.scan_notebook != None:

            for i in xrange(self.scan_notebook.get_n_pages()):
                page = self.scan_notebook.get_nth_page(i)
                page.toolbar.profile_entry.update()

        #page.toolbar.scan_profile.profile_entry.child.\
        #    set_text(self.profile_name_entry.get_text())
    def quit_without_saving(self, widget=None):
        self.deleted = False
        self.quit()

    def on_delete(self, widget=None):
        if not self.profile_name:
            return self.on_cancel()

        dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
        alert = HIGEntryLabel('<b>' + _("Deleting Profile") + '</b>')
        text = HIGEntryLabel(
            _('Your profile is going to be deleted! Click \
Ok to continue, or Cancel to go back to Profile Editor.'))
        hbox = HIGHBox()
        hbox.set_border_width(5)
        hbox.set_spacing(12)

        vbox = HIGVBox()
        vbox.set_border_width(5)
        vbox.set_spacing(12)

        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)

        vbox.pack_start(alert)
        vbox.pack_start(text)
        hbox.pack_start(image)
        hbox.pack_start(vbox)

        dialog.vbox.pack_start(hbox)
        dialog.vbox.show_all()

        response = dialog.run()
        dialog.destroy()

        if response == gtk.RESPONSE_CANCEL:
            return None

        self.deleted = True
        self.profile.remove_profile(self.profile_name)
        self.on_cancel()

    def on_cancel(self, widget=None):
        self.destroy()
        self.update_profile_entry()

    def update_profile_entry(self):
        page = None
        for i in xrange(self.scan_notebook.get_n_pages()):
            page = self.scan_notebook.get_nth_page(i)

            page.toolbar.profile_entry.update(\
                self.profile_name_entry.get_text())

            list = page.toolbar.profile_entry.get_model()
            length = len(list)
            if self.deleted and length > 0:
                page.toolbar.profile_entry.set_active(0)
            elif self.deleted and length == 0:
                page.toolbar.profile_entry.child.set_text("")

        if page is not None:
            page.toolbar.profile_entry.update()

    def remove_profile(self, profile_name=None):
        '''
        Remove current profile 
        '''
        if not profile_name:
            profile_name = self.profile_name
        self.profile.remove_profile(profile_name)
        self.deleted = True

    def delete_profile(self, widget=None):
        """
        delete profile
        """
        self.remove_profile()
        self.deleted = False
        self.quit()
    def __init__(self, label):
        HIGExpander.__init__(self, label)

        self.host_details = HostDetails()
        self.hbox._pack_expand_fill(self.host_details)
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()
Пример #8
0
class ProfileEditor(HIGWindow):

    def __init__(self, profile_name=None, delete=False):
        HIGWindow.__init__(self)
        self.set_title(_('Profile Editor'))
        self.set_position(gtk.WIN_POS_CENTER)
        self.profile_name=profile_name
        self.__create_widgets()
        self.__pack_widgets()

        self.scan_notebook = None
        self.profilemanager = None

        self.profile = CommandProfile()

        self.deleted = False
        options_used = {}

        if profile_name:
            log.debug("Showing profile %s" % profile_name)
            prof = self.profile.get_profile(profile_name)
            options_used = prof['options']

            # Interface settings
            self.profile_name_entry.set_text(profile_name)
            self.profile_hint_entry.set_text(prof['hint'])
            self.profile_description_text.get_buffer().set_text(prof['description'])
            self.profile_annotation_text.get_buffer().set_text(prof['annotation'])

            if delete:
                # Removing profile. It must be saved again
                self.remove_profile()

        self.constructor = CommandConstructor(options_used)
        self.options = OptionBuilder(profile_editor_file, self.constructor, self.update_command)
        log.debug("Option groups: %s" % str(self.options.groups))
        log.debug("Option section names: %s" % str(self.options.section_names))
        #log.debug("Option tabs: %s" % str(self.options.tabs))

        for tab in self.options.groups:
            self.__create_tab(tab, self.options.section_names[tab], self.options.tabs[tab])

        self.update_command()

    def update_command(self):
        """Regenerate command with target '<target>' and set the value for the command entry"""
        self.command_entry.set_text(self.constructor.get_command('<target>'))

    def help(self, widget):
        """
        Show help documentation of Profile Editor
        """
        show_help(self,"profile_editor.html#introduction")

    def __create_widgets(self):
        self.main_vbox = HIGVBox()



        self.command_expander = HIGExpander('<b>'+_('Command')+'</b>')
        self.command_expander.set_expanded(True)
        self.command_entry = gtk.Entry()

        self.notebook = gtk.Notebook()

        # Profile info page
        self.profile_info_vbox = HIGVBox()
        self.profile_info_label = HIGSectionLabel(_('Profile Information'))
        self.profile_name_label = HIGEntryLabel(_('Profile name'))
        self.profile_name_entry = gtk.Entry()
        self.profile_hint_label = HIGEntryLabel(_('Hint'))
        self.profile_hint_entry = gtk.Entry()
        self.profile_description_label = HIGEntryLabel(_('Description'))
        #self.profile_description_label = HIGHBox() 
        self.profile_description_scroll = HIGScrolledWindow()
        self.profile_description_text = HIGTextView()
        self.profile_annotation_label = HIGEntryLabel(_('Annotation'))
        #self.profile_annotation_label = HIGHBox() 
        self.profile_annotation_scroll = HIGScrolledWindow()
        self.profile_annotation_text = HIGTextView()

        # Buttons
        self.buttons_hbox = HIGHBox()

        self.help_button = HIGButton(stock=gtk.STOCK_HELP)
        self.help_button.connect('clicked', self.help)

        #self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        #self.delete_button.connect('clicked', self.delete_profile)

        self.cancel_button = HIGButton(stock=gtk.STOCK_CANCEL)
        self.cancel_button.connect('clicked', self.quit_without_saving)

        self.ok_button = HIGButton(stock=gtk.STOCK_OK)
        self.ok_button.connect('clicked', self.save_profile)

    def __pack_widgets(self):
        self.add(self.main_vbox)

        # Packing widgets to main_vbox

        self.main_vbox._pack_noexpand_nofill(self.command_expander)
        self.main_vbox._pack_expand_fill(self.notebook)
        self.main_vbox._pack_noexpand_nofill(self.buttons_hbox)

        # Packing command_entry on command_expander
        self.command_expander.hbox.pack_start(self.command_entry)

        # Packing profile information tab on notebook
        self.notebook.append_page(self.profile_info_vbox, gtk.Label(_('Profile')))
        self.profile_info_vbox.set_border_width(5)
        table = HIGTable()
        self.profile_info_vbox._pack_noexpand_nofill(self.profile_info_label)
        self.profile_info_vbox._pack_noexpand_nofill(HIGSpacer(table))

        self.profile_annotation_scroll.add(self.profile_annotation_text)
        self.profile_description_scroll.add(self.profile_description_text)

        vbox_desc = HIGVBox()
        vbox_desc._pack_noexpand_nofill(self.profile_description_label)
        vbox_desc._pack_expand_fill(hig_box_space_holder())

        vbox_ann = HIGVBox()
        vbox_ann._pack_noexpand_nofill(self.profile_annotation_label)
        vbox_ann._pack_expand_fill(hig_box_space_holder())
        table.attach(self.profile_name_label,0,1,0,1)
        table.attach(self.profile_name_entry,1,2,0,1)
        #table.attach(self.profile_hint_label,0,1,1,2,xoptions=0)
        table.attach(self.profile_hint_label,0,1,1,2)
        table.attach(self.profile_hint_entry,1,2,1,2)
        table.attach(vbox_desc,0,1,2,3)
        table.attach(self.profile_description_scroll,1,2,2,3)
        table.attach(vbox_ann,0,1,3,4)
        table.attach(self.profile_annotation_scroll,1,2,3,4)

        # Packing buttons on button_hbox
        self.buttons_hbox.pack_start(self.help_button)
        #self.buttons_hbox.pack_start(self.delete_button)
        self.buttons_hbox.pack_start(self.cancel_button)
        self.buttons_hbox.pack_start(self.ok_button)

        self.buttons_hbox.set_border_width(5)
        self.buttons_hbox.set_spacing(6)

    def __create_tab(self, tab_name, section_name, tab):
        log.debug(">>> Tab name: %s" % tab_name)
        log.debug(">>>Creating profile editor section: %s" % section_name)

        vbox = HIGVBox()
        table = HIGTable()
        section = HIGSectionLabel(section_name)

        vbox._pack_noexpand_nofill(section)
        vbox._pack_noexpand_nofill(HIGSpacer(table))
        vbox.set_border_width(6)

        tab.fill_table(table, True)
        self.scrollwindow = HIGScrolledWindow()
        self.scrollwindow.set_size_request(600,300)
        vp = gtk.Viewport()
        vp.add(vbox)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self.scrollwindow.add(vp)

        vbox_tmp = HIGVBox()
        vbox_tmp.set_border_width(6)
        vbox_tmp.set_spacing(12)
        vbox_tmp.pack_start(self.scrollwindow)


        self.notebook.append_page(vbox_tmp, gtk.Label(tab_name))
    def set_profilemanager(self, model):
        """
        give a model of treeview to update profile manager
        after run wizard
        """
        assert model != None

        self.model = model 
        self.profilemanager = True 

    def update_profilemanager(self):
        """
        Update treeview of ProfileManager"
        """
        assert self.profilemanager;

        profiles = self.profile.sections()
        profiles.sort()
        self.model.clear()


        for command in profiles:
            myiter = self.model.insert_before(None, None)
            self.model.set_value(myiter, 0, command)
            self.model.set_value(myiter,1, self.profile.get_hint(command))


    def save_profile(self, widget):
        profile_name = self.profile_name_entry.get_text()

        if profile_name == '':
            alert = HIGAlertDialog(message_format=_('Unnamed profile'),\
                                   secondary_text=_('You must provide a name \
for this profile.'))

        elif profile_name.lower() == 'default':
            alert = HIGAlertDialog(message_format=_('Reserved profile name'),\
                                   secondary_text=_('Cannot assign "default" \
name to this profile. Please rename it and retry.'))
        else:
            alert = None

        if alert:
            alert.run()
            alert.destroy()

            self.notebook.set_current_page(0)
            self.profile_name_entry.grab_focus()

            return None

        if not self.deleted:
            self.remove_profile()

        command = self.constructor.get_command('%s')
        hint = self.profile_hint_entry.get_text()

        buf = self.profile_description_text.get_buffer()
        description = buf.get_text(buf.get_start_iter(),\
                                   buf.get_end_iter())

        buf = self.profile_annotation_text.get_buffer()
        annotation = buf.get_text(buf.get_start_iter(),\
                                  buf.get_end_iter())
        self.profile.add_profile(profile_name,\
                                 command=command,\
                                 hint=hint,\
                                 description=description,\
                                 annotation=annotation,\
                                 tool='nmap',\
                                 options=self.constructor.get_options())
        self.deleted = False
        if self.profilemanager:
            self.update_profilemanager()

        self.quit()


    def clean_profile_info(self):
        self.profile_name_entry.set_text('')
        self.profile_hint_entry.set_text('')
        self.profile_description_text.get_buffer().set_text('')
        self.profile_annotation_text.get_buffer().set_text('')

    def set_notebook(self, notebook):
        self.scan_notebook = notebook

    def quit(self, widget=None, extra=None):
        if self.deleted:
            dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                        gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
            alert = HIGEntryLabel('<b>'+_("Deleting Profile")+'</b>')
            text = HIGEntryLabel(_('Your profile is going to be deleted! Click\
                                   Ok to continue, or Cancel to go back to Profile Editor.'))
            hbox = HIGHBox()
            hbox.set_border_width(5)
            hbox.set_spacing(12)

            vbox = HIGVBox()
            vbox.set_border_width(5)
            vbox.set_spacing(12)

            image = gtk.Image()
            image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)

            vbox.pack_start(alert)
            vbox.pack_start(text)
            hbox.pack_start(image)
            hbox.pack_start(vbox)

            dialog.vbox.pack_start(hbox)
            dialog.vbox.show_all()

            response = dialog.run()
            dialog.destroy()

            if response == gtk.RESPONSE_CANCEL:
                return None
        self.destroy()       
        if self.scan_notebook != None:

            for i in xrange(self.scan_notebook.get_n_pages()):
                page = self.scan_notebook.get_nth_page(i)
                page.toolbar.profile_entry.update()

        #page.toolbar.scan_profile.profile_entry.child.\
        #    set_text(self.profile_name_entry.get_text())
    def quit_without_saving(self, widget=None):
        self.deleted=False
        self.quit()

    def on_delete(self, widget=None):
        if not self.profile_name:
            return self.on_cancel()

        dialog = HIGDialog(buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
        alert = HIGEntryLabel('<b>'+_("Deleting Profile")+'</b>')
        text = HIGEntryLabel(_('Your profile is going to be deleted! Click \
Ok to continue, or Cancel to go back to Profile Editor.'))
        hbox = HIGHBox()
        hbox.set_border_width(5)
        hbox.set_spacing(12)

        vbox = HIGVBox()
        vbox.set_border_width(5)
        vbox.set_spacing(12)

        image = gtk.Image()
        image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)

        vbox.pack_start(alert)
        vbox.pack_start(text)
        hbox.pack_start(image)
        hbox.pack_start(vbox)

        dialog.vbox.pack_start(hbox)
        dialog.vbox.show_all()

        response = dialog.run()
        dialog.destroy()

        if response == gtk.RESPONSE_CANCEL:
            return None

        self.deleted = True
        self.profile.remove_profile(self.profile_name)
        self.on_cancel()


    def on_cancel(self, widget=None):
        self.destroy()
        self.update_profile_entry()

    def update_profile_entry(self):
        page = None
        for i in xrange(self.scan_notebook.get_n_pages()):
            page = self.scan_notebook.get_nth_page(i)

            page.toolbar.profile_entry.update(\
                self.profile_name_entry.get_text())

            list = page.toolbar.profile_entry.get_model()
            length = len(list)
            if self.deleted and length > 0 :
                page.toolbar.profile_entry.set_active(0)
            elif self.deleted and length == 0:
                page.toolbar.profile_entry.child.set_text("")

        if page is not None:
            page.toolbar.profile_entry.update()



    def remove_profile(self,profile_name=None):
        '''
        Remove current profile 
        '''
        if not profile_name:
            profile_name = self.profile_name
        self.profile.remove_profile(profile_name)
        self.deleted = True        

    def delete_profile(self, widget=None):
        """
        delete profile
        """
        self.remove_profile()
        self.deleted=False        
        self.quit()
Пример #9
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()
Пример #10
0
 def __init__(self, label):
     HIGExpander.__init__(self, label)
     
     self.host_details = HostDetails()
     self.hbox._pack_expand_fill(self.host_details)