1# vim: set fileencoding=utf-8 :
2
3# ***********************IMPORTANT NMAP LICENSE TERMS************************
4# *                                                                         *
5# * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap  *
6# * Project"). Nmap is also a registered trademark of the Nmap Project.     *
7# *                                                                         *
8# * This program is distributed under the terms of the Nmap Public Source   *
9# * License (NPSL). The exact license text applying to a particular Nmap    *
10# * release or source code control revision is contained in the LICENSE     *
11# * file distributed with that version of Nmap or source code control       *
12# * revision. More Nmap copyright/legal information is available from       *
13# * https://nmap.org/book/man-legal.html, and further information on the    *
14# * NPSL license itself can be found at https://nmap.org/npsl. This header  *
15# * summarizes some key points from the Nmap license, but is no substitute  *
16# * for the actual license text.                                            *
17# *                                                                         *
18# * Nmap is generally free for end users to download and use themselves,    *
19# * including commercial use. It is available from https://nmap.org.        *
20# *                                                                         *
21# * The Nmap license generally prohibits companies from using and           *
22# * redistributing Nmap in commercial products, but we sell a special Nmap  *
23# * OEM Edition with a more permissive license and special features for     *
24# * this purpose. See https://nmap.org/oem                                  *
25# *                                                                         *
26# * If you have received a written Nmap license agreement or contract       *
27# * stating terms other than these (such as an Nmap OEM license), you may   *
28# * choose to use and redistribute Nmap under those terms instead.          *
29# *                                                                         *
30# * The official Nmap Windows builds include the Npcap software             *
31# * (https://npcap.org) for packet capture and transmission. It is under    *
32# * separate license terms which forbid redistribution without special      *
33# * permission. So the official Nmap Windows builds may not be              *
34# * redistributed without special permission (such as an Nmap OEM           *
35# * license).                                                               *
36# *                                                                         *
37# * Source is provided to this software because we believe users have a     *
38# * right to know exactly what a program is going to do before they run it. *
39# * This also allows you to audit the software for security holes.          *
40# *                                                                         *
41# * Source code also allows you to port Nmap to new platforms, fix bugs,    *
42# * and add new features.  You are highly encouraged to submit your         *
43# * changes as a Github PR or by email to the dev@nmap.org mailing list     *
44# * for possible incorporation into the main distribution. Unless you       *
45# * specify otherwise, it is understood that you are offering us very       *
46# * broad rights to use your submissions as described in the Nmap Public    *
47# * Source License Contributor Agreement. This is important because we      *
48# * fund the project by selling licenses with various terms, and also       *
49# * because the inability to relicense code has caused devastating          *
50# * problems for other Free Software projects (such as KDE and NASM).       *
51# *                                                                         *
52# * The free version of Nmap is distributed in the hope that it will be     *
53# * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of  *
54# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties,        *
55# * indemnification and commercial support are all available through the    *
56# * Npcap OEM program--see https://nmap.org/oem.                            *
57# *                                                                         *
58# ***************************************************************************/
59
60import gtk
61
62__all__ = ('BWBox', 'BWHBox', 'BWVBox',
63        'BWStatusbar', 'BWTable', 'BWScrolledWindow')
64
65
66class BWBox(gtk.Box):
67    """
68    """
69    def bw_pack_start_expand_fill(self, widget, padding=0):
70        """
71        """
72        self.pack_start(widget, True, True, padding)
73
74    def bw_pack_start_expand_nofill(self, widget, padding=0):
75        """
76        """
77        self.pack_start(widget, True, False, padding)
78
79    def bw_pack_start_noexpand_nofill(self, widget, padding=0):
80        """
81        """
82        self.pack_start(widget, False, False, padding)
83
84    def bw_pack_end_expand_fill(self, widget, padding=0):
85        """
86        """
87        self.pack_end(widget, True, True, padding)
88
89    def bw_pack_end_expand_nofill(self, widget, padding=0):
90        """
91        """
92        self.pack_end(widget, True, False, padding)
93
94    def bw_pack_end_noexpand_nofill(self, widget, padding=0):
95        """
96        """
97        self.pack_end(widget, False, False, padding)
98
99
100class BWHBox(gtk.HBox, BWBox):
101    """
102    """
103    def __init__(self, homogeneous=False, spacing=12):
104        """
105        """
106        gtk.HBox.__init__(self, homogeneous, spacing)
107
108
109class BWVBox(gtk.VBox, BWBox):
110    """
111    """
112    def __init__(self, homogeneous=False, spacing=12):
113        """
114        """
115        gtk.VBox.__init__(self, homogeneous, spacing)
116
117
118class BWStatusbar(gtk.Statusbar, BWBox):
119    """
120    """
121    def __init__(self, homogeneous=False, spacing=12):
122        """
123        """
124        gtk.HBox.__init__(self, homogeneous, spacing)
125
126
127class BWTable(gtk.Table, BWBox):
128    """
129    """
130    def __init__(self, rows=1, columns=1, homogeneous=False):
131        """
132        """
133        gtk.Table.__init__(self, rows, columns, homogeneous)
134        self.bw_set_spacing(12)
135
136        self.__rows = rows
137        self.__columns = columns
138
139        self.__last_point = (0, 0)
140
141    def bw_set_spacing(self, spacing):
142        """
143        """
144        self.set_row_spacings(spacing)
145        self.set_col_spacings(spacing)
146
147    def bw_resize(self, rows, columns):
148        """
149        """
150        self.__rows = rows
151        self.__columns = columns
152
153        self.resize(rows, columns)
154
155    def bw_attach_next(self,
156                       child,
157                       xoptions=gtk.EXPAND | gtk.FILL,
158                       yoptions=gtk.EXPAND | gtk.FILL,
159                       xpadding=0,
160                       ypadding=0):
161        """
162        """
163        row, column = self.__last_point
164
165        if row != self.__rows:
166
167            self.attach(child,
168                        column,
169                        column + 1,
170                        row,
171                        row + 1,
172                        xoptions,
173                        yoptions,
174                        xpadding,
175                        ypadding)
176
177            if column + 1 == self.__columns:
178
179                column = 0
180                row += 1
181
182            else:
183                column += 1
184
185            self.__last_point = (row, column)
186
187
188class BWScrolledWindow(gtk.ScrolledWindow):
189    """
190    """
191    def __init__(self):
192        """
193        """
194        gtk.ScrolledWindow.__init__(self)
195        self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
196        self.set_shadow_type(gtk.SHADOW_NONE)
197        self.set_border_width(6)
198