... | ... |
@@ -46,9 +46,9 @@ Shortcuts: |
46 | 46 |
'inputfile', metavar='file', nargs='?', |
47 | 47 |
help='input file to be viewed') |
48 | 48 |
parser.add_argument( |
49 |
- '-f', '--filter', choices=['dot', 'neato', 'twopi', 'circo', 'fdp'], |
|
49 |
+ '-f', '--filter', action='store', |
|
50 | 50 |
dest='filter', default='dot', metavar='FILTER', |
51 |
- help='graphviz filter: dot, neato, twopi, circo, or fdp [default: %(default)s]') |
|
51 |
+ help='graphviz filter, e.g. dot, neato, twopi, circo, or fdp [default: %(default)s]') |
|
52 | 52 |
parser.add_argument( |
53 | 53 |
'-n', '--no-filter', |
54 | 54 |
action='store_const', const=None, dest='filter', |
... | ... |
@@ -56,6 +56,10 @@ Shortcuts: |
56 | 56 |
'-g', '--geometry', |
57 | 57 |
action='store', dest='geometry', |
58 | 58 |
help='default window size in form WxH') |
59 |
+ parser.add_argument( |
|
60 |
+ '--hide-toolbar', |
|
61 |
+ action='store_true', dest='hide_toolbar', |
|
62 |
+ help='Hides the toolbar on start.') |
|
59 | 63 |
|
60 | 64 |
options = parser.parse_args() |
61 | 65 |
inputfile = options.inputfile |
... | ... |
@@ -76,6 +80,9 @@ Shortcuts: |
76 | 80 |
else: |
77 | 81 |
win.open_file(inputfile) |
78 | 82 |
|
83 |
+ if options.hide_toolbar: |
|
84 |
+ win.uimanager.get_widget('/ToolBar').set_visible(False) |
|
85 |
+ |
|
79 | 86 |
if sys.platform != 'win32': |
80 | 87 |
# Reset KeyboardInterrupt SIGINT handler, so that glib loop can be stopped by it |
81 | 88 |
import signal |
Thanks to zxgio for suggesting the fix.
Fix https://github.com/jrfonseca/xdot.py/issues/45
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
#!/usr/bin/env python3 |
2 | 2 |
# |
3 |
-# Copyright 2008-2015 Jose Fonseca |
|
3 |
+# Copyright 2008-2017 Jose Fonseca |
|
4 | 4 |
# |
5 | 5 |
# This program is free software: you can redistribute it and/or modify it |
6 | 6 |
# under the terms of the GNU Lesser General Public License as published |
... | ... |
@@ -15,6 +15,7 @@ |
15 | 15 |
# You should have received a copy of the GNU Lesser General Public License |
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
# |
18 |
+ |
|
18 | 19 |
import argparse |
19 | 20 |
import sys |
20 | 21 |
|
... | ... |
@@ -74,6 +74,12 @@ Shortcuts: |
74 | 74 |
win.set_dotcode(sys.stdin.read()) |
75 | 75 |
else: |
76 | 76 |
win.open_file(inputfile) |
77 |
+ |
|
78 |
+ if sys.platform != 'win32': |
|
79 |
+ # Reset KeyboardInterrupt SIGINT handler, so that glib loop can be stopped by it |
|
80 |
+ import signal |
|
81 |
+ signal.signal(signal.SIGINT, signal.SIG_DFL) |
|
82 |
+ |
|
77 | 83 |
Gtk.main() |
78 | 84 |
|
79 | 85 |
if __name__ == '__main__': |
optparse is deprecated since 2.7/3.2
... | ... |
@@ -15,24 +15,17 @@ |
15 | 15 |
# You should have received a copy of the GNU Lesser General Public License |
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
# |
18 |
-import optparse |
|
18 |
+import argparse |
|
19 | 19 |
import sys |
20 | 20 |
|
21 | 21 |
from .ui.window import DotWindow, Gtk |
22 | 22 |
|
23 | 23 |
|
24 |
-class OptionParser(optparse.OptionParser): |
|
25 |
- |
|
26 |
- def format_epilog(self, formatter): |
|
27 |
- # Prevent stripping the newlines in epilog message |
|
28 |
- # http://stackoverflow.com/questions/1857346/python-optparse-how-to-include-additional-info-in-usage-output |
|
29 |
- return self.epilog |
|
30 |
- |
|
31 |
- |
|
32 | 24 |
def main(): |
33 | 25 |
|
34 |
- parser = OptionParser( |
|
35 |
- usage='\n\t%prog [file]', |
|
26 |
+ parser = argparse.ArgumentParser( |
|
27 |
+ description="xdot.py is an interactive viewer for graphs written in Graphviz's dot language.", |
|
28 |
+ formatter_class=argparse.RawDescriptionHelpFormatter, |
|
36 | 29 |
epilog=''' |
37 | 30 |
Shortcuts: |
38 | 31 |
Up, Down, Left, Right scroll |
... | ... |
@@ -47,23 +40,24 @@ Shortcuts: |
47 | 40 |
Shift-drag zooms an area |
48 | 41 |
''' |
49 | 42 |
) |
50 |
- parser.add_option( |
|
51 |
- '-f', '--filter', |
|
52 |
- type='choice', choices=('dot', 'neato', 'twopi', 'circo', 'fdp'), |
|
53 |
- dest='filter', default='dot', |
|
54 |
- help='graphviz filter: dot, neato, twopi, circo, or fdp [default: %default]') |
|
55 |
- parser.add_option( |
|
43 |
+ parser.add_argument( |
|
44 |
+ 'inputfile', metavar='file', nargs='?', |
|
45 |
+ help='input file to be viewed') |
|
46 |
+ parser.add_argument( |
|
47 |
+ '-f', '--filter', choices=['dot', 'neato', 'twopi', 'circo', 'fdp'], |
|
48 |
+ dest='filter', default='dot', metavar='FILTER', |
|
49 |
+ help='graphviz filter: dot, neato, twopi, circo, or fdp [default: %(default)s]') |
|
50 |
+ parser.add_argument( |
|
56 | 51 |
'-n', '--no-filter', |
57 | 52 |
action='store_const', const=None, dest='filter', |
58 | 53 |
help='assume input is already filtered into xdot format (use e.g. dot -Txdot)') |
59 |
- parser.add_option( |
|
60 |
- '-g', None, |
|
54 |
+ parser.add_argument( |
|
55 |
+ '-g', '--geometry', |
|
61 | 56 |
action='store', dest='geometry', |
62 | 57 |
help='default window size in form WxH') |
63 | 58 |
|
64 |
- (options, args) = parser.parse_args(sys.argv[1:]) |
|
65 |
- if len(args) > 1: |
|
66 |
- parser.error('incorrect number of arguments') |
|
59 |
+ options = parser.parse_args() |
|
60 |
+ inputfile = options.inputfile |
|
67 | 61 |
|
68 | 62 |
width = height = 512 |
69 | 63 |
if options.geometry: |
... | ... |
@@ -75,11 +69,11 @@ Shortcuts: |
75 | 69 |
win = DotWindow(width=width, height=height) |
76 | 70 |
win.connect('delete-event', Gtk.main_quit) |
77 | 71 |
win.set_filter(options.filter) |
78 |
- if len(args) >= 1: |
|
79 |
- if args[0] == '-': |
|
72 |
+ if inputfile and len(inputfile) >= 1: |
|
73 |
+ if inputfile == '-': |
|
80 | 74 |
win.set_dotcode(sys.stdin.read()) |
81 | 75 |
else: |
82 |
- win.open_file(args[0]) |
|
76 |
+ win.open_file(inputfile) |
|
83 | 77 |
Gtk.main() |
84 | 78 |
|
85 | 79 |
if __name__ == '__main__': |
... | ... |
@@ -68,7 +68,7 @@ Shortcuts: |
68 | 68 |
width = height = 512 |
69 | 69 |
if options.geometry: |
70 | 70 |
try: |
71 |
- width,height = (int(i) for i in options.geometry.split('x')) |
|
71 |
+ width, height = (int(i) for i in options.geometry.split('x')) |
|
72 | 72 |
except ValueError: |
73 | 73 |
parser.error('invalid window geometry') |
74 | 74 |
|
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,86 @@ |
1 |
+#!/usr/bin/env python3 |
|
2 |
+# |
|
3 |
+# Copyright 2008-2015 Jose Fonseca |
|
4 |
+# |
|
5 |
+# This program is free software: you can redistribute it and/or modify it |
|
6 |
+# under the terms of the GNU Lesser General Public License as published |
|
7 |
+# by the Free Software Foundation, either version 3 of the License, or |
|
8 |
+# (at your option) any later version. |
|
9 |
+# |
|
10 |
+# This program is distributed in the hope that it will be useful, |
|
11 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
+# GNU Lesser General Public License for more details. |
|
14 |
+# |
|
15 |
+# You should have received a copy of the GNU Lesser General Public License |
|
16 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
+# |
|
18 |
+import optparse |
|
19 |
+import sys |
|
20 |
+ |
|
21 |
+from .ui.window import DotWindow, Gtk |
|
22 |
+ |
|
23 |
+ |
|
24 |
+class OptionParser(optparse.OptionParser): |
|
25 |
+ |
|
26 |
+ def format_epilog(self, formatter): |
|
27 |
+ # Prevent stripping the newlines in epilog message |
|
28 |
+ # http://stackoverflow.com/questions/1857346/python-optparse-how-to-include-additional-info-in-usage-output |
|
29 |
+ return self.epilog |
|
30 |
+ |
|
31 |
+ |
|
32 |
+def main(): |
|
33 |
+ |
|
34 |
+ parser = OptionParser( |
|
35 |
+ usage='\n\t%prog [file]', |
|
36 |
+ epilog=''' |
|
37 |
+Shortcuts: |
|
38 |
+ Up, Down, Left, Right scroll |
|
39 |
+ PageUp, +, = zoom in |
|
40 |
+ PageDown, - zoom out |
|
41 |
+ R reload dot file |
|
42 |
+ F find |
|
43 |
+ Q quit |
|
44 |
+ P print |
|
45 |
+ Escape halt animation |
|
46 |
+ Ctrl-drag zoom in/out |
|
47 |
+ Shift-drag zooms an area |
|
48 |
+''' |
|
49 |
+ ) |
|
50 |
+ parser.add_option( |
|
51 |
+ '-f', '--filter', |
|
52 |
+ type='choice', choices=('dot', 'neato', 'twopi', 'circo', 'fdp'), |
|
53 |
+ dest='filter', default='dot', |
|
54 |
+ help='graphviz filter: dot, neato, twopi, circo, or fdp [default: %default]') |
|
55 |
+ parser.add_option( |
|
56 |
+ '-n', '--no-filter', |
|
57 |
+ action='store_const', const=None, dest='filter', |
|
58 |
+ help='assume input is already filtered into xdot format (use e.g. dot -Txdot)') |
|
59 |
+ parser.add_option( |
|
60 |
+ '-g', None, |
|
61 |
+ action='store', dest='geometry', |
|
62 |
+ help='default window size in form WxH') |
|
63 |
+ |
|
64 |
+ (options, args) = parser.parse_args(sys.argv[1:]) |
|
65 |
+ if len(args) > 1: |
|
66 |
+ parser.error('incorrect number of arguments') |
|
67 |
+ |
|
68 |
+ width = height = 512 |
|
69 |
+ if options.geometry: |
|
70 |
+ try: |
|
71 |
+ width,height = (int(i) for i in options.geometry.split('x')) |
|
72 |
+ except ValueError: |
|
73 |
+ parser.error('invalid window geometry') |
|
74 |
+ |
|
75 |
+ win = DotWindow(width=width, height=height) |
|
76 |
+ win.connect('delete-event', Gtk.main_quit) |
|
77 |
+ win.set_filter(options.filter) |
|
78 |
+ if len(args) >= 1: |
|
79 |
+ if args[0] == '-': |
|
80 |
+ win.set_dotcode(sys.stdin.read()) |
|
81 |
+ else: |
|
82 |
+ win.open_file(args[0]) |
|
83 |
+ Gtk.main() |
|
84 |
+ |
|
85 |
+if __name__ == '__main__': |
|
86 |
+ main() |