root/branch/k0p/umitGUI/ProfileManager.py @ 894

Revision 894, 7.9 kB (checked in by kop-labs, 6 years ago)

delete button

Line 
1#!/usr/bin/env python
2# Copyright (C) 2005 Insecure.Com LLC.
3#
4# Author: Luis A. Bastiao Silva <luis.kop@gmail.com>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20import gtk
21
22from higwidgets.higwindows import HIGWindow
23from higwidgets.higboxes import HIGVBox, HIGHBox
24from higwidgets.higscrollers import HIGScrolledWindow
25from higwidgets.higbuttons import HIGButton
26from higwidgets.higlabels import HIGSectionLabel, HIGEntryLabel, HIGDialogLabel
27from higwidgets.higentries import HIGTextEntry
28from higwidgets.higframe import HIGFrame
29from higwidgets.higdialogs import HIGDialog
30
31from umitGUI.Wizard import Wizard
32
33# Testing at devel
34from os.path import split, join
35
36from umitCore.Paths import Path
37Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf'))
38#END DEV TEST
39
40from ProfileEditor import ProfileEditor
41from umitCore.UmitConf import CommandProfile
42from umitCore.I18N import _
43
44import gobject
45
46profile_editor = Path.profile_editor
47
48class ProfileManager(HIGWindow):
49    """
50    Create a Profile Manager
51    """
52    def __init__(self):
53        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
54        self.set_title('Profile Manager')
55        self.set_position(gtk.WIN_POS_CENTER)
56        self.__create_widgets()
57        self.add(self.vbox_main)
58        self.__fill_widgets()
59        self.__pack_widgets()
60
61   
62    def __create_widgets(self):
63       
64        self.vbox_main = HIGVBox()
65       
66        self.main_frame = HIGFrame("Profiles")
67        self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
68       
69       
70        self.vbox = HIGVBox()
71        self.profiles_sw = HIGScrolledWindow()
72        #TreeView
73        self.hbox_aux_tv = HIGHBox()
74        self.model = gtk.TreeStore(gobject.TYPE_STRING)
75        self.profiles_tv = gtk.TreeView(self.model)
76        renderer = gtk.CellRendererText()
77        column = gtk.TreeViewColumn("Name", renderer, text=0)
78        self.profiles_tv.append_column(column)
79       
80
81        #Info
82        self.hbox_info = HIGHBox()
83        self.command_label = HIGEntryLabel('Command: ')
84        self.command_entry = HIGTextEntry()
85        self.command_entry.set_editable(False)
86       
87        #Buttons
88        self.hbox_buttons = HIGHBox()
89        self.edit_button = HIGButton(stock='gtk-edit')
90        self.edit_button.connect("clicked", self.open_peditor)
91        self.new_button = HIGButton(stock='gtk-new')
92        self.new_button.connect("clicked", self.new_wiz)
93        self.copy_button = HIGButton(stock='gtk-copy')
94        self.copy_button.connect("clicked", self.copy_profiles)
95        self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
96        self.delete_button.connect('clicked', self.delete_profile)     
97       
98        #Apply Buttons
99        self.hbox_apply = HIGHBox()
100        self.cancel_button = HIGButton(stock='gtk-cancel')
101        self.cancel_button.connect("clicked", self.quit)
102        self.ok_button = HIGButton(stock='gtk-ok')
103
104    def __fill_widgets(self):
105
106               
107        self.profiles = CommandProfile()
108        profiles = self.profiles.sections()
109        profiles.sort()
110       
111       
112        for command in profiles:
113            myiter = self.model.insert_after(None, None)
114            self.model.set_value(myiter, 0, command)
115           
116        #selection = self.profiles_tv.get_selection()
117        #selection.connect("changed", self.change_nmap_command)
118        self.profiles_tv.connect("cursor-changed", self.change_nmap_command)
119
120       
121
122    def __pack_widgets(self):
123        """
124        Pack all widgets of windows
125        """
126        self.vbox_main.pack_start(self.main_frame)
127        self.main_frame.add(self.vbox)
128       
129        self.vbox.pack_start(self.profiles_sw, True, True, 0)
130
131        self.hbox_info.pack_start(self.command_label, False,False,0)
132        self.hbox_info.pack_start(self.command_entry, True, True, 0)
133        self.vbox.pack_start(self.hbox_info, True, True,0)
134       
135        self.vbox.pack_start(self.hbox_buttons, False, True, 0)
136       
137        self.hbox_buttons.pack_end(self.copy_button, False, True)
138        self.hbox_buttons.pack_end(self.edit_button, False, True)
139        self.hbox_buttons.pack_end(self.delete_button, False, True)
140        self.hbox_buttons.pack_end(self.new_button, False, True)
141
142       
143        #self.hbox_aux_tv .pack_start(self.profiles_tv,False, False)
144        self.profiles_sw.set_size_request(400,170)
145        self.profiles_sw.add_with_viewport(self.profiles_tv) 
146
147        self.hbox_apply.pack_end(self.ok_button)
148        self.hbox_apply.pack_end(self.cancel_button)
149        self.vbox_main.pack_start(self.hbox_apply)
150       
151    def get_selected_profile(self):
152        """
153        Returns the string with name of selected profile
154        """
155        treeselection = self.profiles_tv.get_selection()
156        (model,iter) = treeselection.get_selected()
157        return model.get_value(iter,0)
158       
159       
160    def change_nmap_command(self,widget_tv):
161        """
162        Change a nmap command at command entry
163        """
164        assert widget_tv != None
165       
166        self.command_entry.set_text(self.profiles.get_command(self.get_selected_profile()))     
167   
168    def new_wiz(self,widget):
169        w = Wizard()
170        w.set_notebook(None)
171       
172        w.show_all()
173
174    def open_peditor(self, widget):
175        """
176        Open Profile Editor with a Selected or Non-Selected(New) Item
177        """
178        assert widget != None
179       
180        #widget = HIGButton()
181       
182        if widget.get_label() == "gtk-edit":
183            # Edit profile selected   
184           
185            pe = ProfileEditor(self.get_selected_profile())
186            pe.show_all()
187        else:
188            # New Profile
189            pe = ProfileEditor()
190            pe.show_all()
191   
192    def copy_profiles(self, widget):
193        """
194        Copy selected Profile
195        """
196        d = ProfileName(_("Insert a profile name"))
197
198    def delete_profile(self, widget=None):
199        """
200        delete profile only at treeview
201        """
202        #self.profiles.remove_profile()
203        #Update treeview
204        treeselection = self.profiles_tv.get_selection()
205        (model,iter) = treeselection.get_selected()
206        model.remove(iter)     
207       
208       
209   
210    def quit(self, widget):
211        self.destroy()
212       
213class ProfileName:
214    def __init__(self, text):
215        d = HIGDialog(title=_('Profile\'s Name'),
216                      buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
217        dialog_label = HIGDialogLabel(text)
218        dialog_label.show()
219        d.vbox.pack_start(dialog_label)
220
221        entry_text = HIGTextEntry()
222        entry_text.show()
223        d.vbox.pack_start(entry_text)
224       
225        d.run()
226       
227        d.destroy()
228       
229class ProfileChosse(HIGHBox):
230    def __init__(self):
231        HIGHBox.__init__(self)       
232        self._create_profile()
233       
234    #def _create_profile(self):
235    def __init__(self):
236        HIGHBox.__init__(self)
237
238        self._create_profile()
239       
240        self.change_button = gtk.Button(_("Change"))
241       
242        self._pack_noexpand_nofill(self.profile_label)
243        self._pack_expand_fill(self.profile_entry)
244       
245        self._pack_noexpand_nofill(self.change_button)
246
247        self.profile_entry.set_focus_child(self.profile_entry.child)
248
249        # Events
250        self.profile_entry.child.connect('activate',
251                        lambda x: self.change_button.clicked())
252
253    def _create_profile(self):
254        self.profile_label = HIGEntryLabel(_('Profile:'))
255        self.profile_entry = ProfileCombo()
256        self.update()
257    def update(self):
258        self.update_profile()
259    def update_profile(self):
260        self.profile_entry.update()
261       
262       
263       
264       
265if __name__=="__main__":
266    pm = ProfileManager()
267    pm.show_all()
268    gtk.main()
269   
270       
271       
Note: See TracBrowser for help on using the browser.