Browse code

Remove --filter restriction

Robert Cranston authored on 15/07/2022 11:02:40
Showing 1 changed files
... ...
@@ -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',
Browse code

Introduce "Export to other format" feature

Meier, Moritz authored on 08/10/2021 16:42:39 • José Fonseca committed on 27/11/2021 15:12:34
Showing 1 changed files
... ...
@@ -36,6 +36,7 @@ Shortcuts:
36 36
   F                         find
37 37
   Q                         quit
38 38
   P                         print
39
+  T                         toggle show/hide toolbar
39 40
   Escape                    halt animation
40 41
   Ctrl-drag                 zoom in/out
41 42
   Shift-drag                zooms an area
Browse code

Add toggle-toolbar feature and hide-toolbar commandline parameter.

Moritz Meier authored on 20/05/2020 21:21:59 • José Fonseca committed on 11/07/2020 11:53:07
Showing 1 changed files
... ...
@@ -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
Browse code

History support

iamahuman authored on 04/12/2018 09:57:06 • Jose Fonseca committed on 25/03/2019 06:54:06
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ Shortcuts:
60 60
     options = parser.parse_args()
61 61
     inputfile = options.inputfile
62 62
 
63
-    width = height = 512
63
+    width, height = 610, 610
64 64
     if options.geometry:
65 65
         try:
66 66
             width, height = (int(i) for i in options.geometry.split('x'))
Browse code

Fix reading dot graphs from standard input (fixes #60)

Thanks to zxgio for suggesting the fix.

Jonas Hörsch authored on 29/08/2018 09:03:33 • José Fonseca committed on 30/08/2018 09:29:24
Showing 1 changed files
... ...
@@ -72,7 +72,7 @@ Shortcuts:
72 72
     win.set_filter(options.filter)
73 73
     if inputfile and len(inputfile) >= 1:
74 74
         if inputfile == '-':
75
-            win.set_dotcode(sys.stdin.read())
75
+            win.set_dotcode(sys.stdin.buffer.read())
76 76
         else:
77 77
             win.open_file(inputfile)
78 78
 
Browse code

Assert only Python 3 is used.

Fix https://github.com/jrfonseca/xdot.py/issues/45

Jose Fonseca authored on 16/05/2017 09:13:59
Showing 1 changed files
... ...
@@ -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
 
Browse code

Restore default SIGINT handler so that xdot terminates on Ctrl-C.

Mike Kazantsev authored on 18/11/2016 10:37:06 • Jose Fonseca committed on 21/11/2016 10:59:43
Showing 1 changed files
... ...
@@ -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__':
Browse code

Switch to argparse instead of optparse

optparse is deprecated since 2.7/3.2

Peter Hill authored on 02/07/2016 14:36:19 • Jose Fonseca committed on 10/07/2016 17:03:51
Showing 1 changed files
... ...
@@ -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__':
Browse code

Fix most flake8 errors

Peter Hill authored on 02/07/2016 10:27:27 • Jose Fonseca committed on 10/07/2016 08:40:15
Showing 1 changed files
... ...
@@ -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
 
Browse code

Cleaner splitting into separate modules

Peter Hill authored on 02/07/2016 09:45:05 • Jose Fonseca committed on 10/07/2016 08:40:15
Showing 1 changed files
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()