Skip to content

Commit 00173bf

Browse files
committed
- Note dimensions always absolute
- UI updates for better OpenGL rendering - update to preferences handling
1 parent efeac55 commit 00173bf

File tree

13 files changed

+324
-157
lines changed

13 files changed

+324
-157
lines changed

bin/SceneGraph

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,54 @@ from optparse import OptionParser
66

77

88
if __name__ == "__main__":
9-
parser = OptionParser()
10-
parser.add_option("-f", "--filename", action="store", dest="filename")
11-
parser.add_option("-g", "--opengl", action="store_true", dest="opengl", default=False)
12-
(options, args) = parser.parse_args()
139
from SceneGraph import scenegraph
14-
app = QtGui.QApplication(sys.argv)
10+
from SceneGraph.options import PACKAGE, PLATFORM, EDGE_TYPES, VIEWPORT_MODES
11+
12+
APP_STYLES = [s.lower() for s in QtGui.QStyleFactory.keys()]
1513

16-
if sys.platform == 'darwin':
17-
app.setStyle('cleanlooks')
14+
filename = None
15+
args = sys.argv
16+
if len(args)>1:
17+
if os.path.exists(args[1]):
18+
filename = args[1]
19+
20+
parser = OptionParser()
21+
parser.add_option("-g", "--use_gl", action="store_true", dest="use_gl", default=False, help='use OpenGL renderer.')
22+
parser.add_option("--fx", action="store_true", dest="render_fx", default=True, help='render node dropshadow & glow effects.')
23+
parser.add_option("-m", action="store", dest="viewport_mode", help='set the Qt viewport mode (ie. "full", "smart", "minimal").')
24+
parser.add_option("-e", action="store", dest="edge_type", help='node edge style (ie. "bezier", "polygon").')
25+
parser.add_option("-s", action="store", dest="app_style", help='Qt application style (ie. "%s").' % '", "'.join(APP_STYLES))
1826

1927
# oxygen looks better in linux overall, but plastique groupBoxes look better
2028
# Designer previews in GTK+
21-
if 'linux' in sys.platform:
22-
app.setStyle("oxygen")
29+
if PLATFORM == 'Linux':
30+
parser.set_default('app_style', 'oxygen')
31+
32+
if PLATFORM == 'MacOSX':
33+
parser.set_default('app_style', 'cleanlooks')
34+
35+
(options, args) = parser.parse_args()
36+
app = QtGui.QApplication(sys.argv)
37+
38+
# set the application style
39+
if options.app_style:
40+
if options.app_style.lower() in APP_STYLES:
41+
print '[%s]: INFO: setting Qt style: "%s".' % (PACKAGE, options.app_style)
42+
app.setStyle(options.app_style)
43+
44+
# update prefs
45+
prefs = dict()
46+
if options.viewport_mode:
47+
if options.viewport_mode.lower() in VIEWPORT_MODES:
48+
prefs.update(viewport_mode=options.viewport_mode.lower())
2349

50+
if options.edge_type:
51+
if options.edge_type.lower() in EDGE_TYPES:
52+
prefs.update(edge_type=options.edge_type.lower())
2453

25-
#app.setStyle("gtk") # gtk is default
26-
sgui = scenegraph.SceneGraphUI(opengl=options.opengl)
54+
sgui = scenegraph.SceneGraphUI(use_gl=options.use_gl, render_fx=options.render_fx, **prefs)
2755
sgui.show()
2856

29-
if options.filename:
30-
sgui.readGraph(options.filename)
57+
if filename:
58+
sgui.readGraph(filename)
3159
sys.exit(app.exec_())

bin/TestGraph

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from optparse import OptionParser
88
if __name__ == "__main__":
99
parser = OptionParser()
1010
parser.add_option("-f", "--filename", action="store", dest="filename")
11-
parser.add_option("-g", "--opengl", action="store_true", dest="opengl", default=False)
11+
parser.add_option("-g", "--use_gl", action="store_true", dest="use_gl", default=False)
1212
parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False)
1313
(options, args) = parser.parse_args()
1414
from SceneGraph.test import test
@@ -22,7 +22,7 @@ if __name__ == "__main__":
2222
app.setStyle("oxygen")
2323

2424
#app.setStyle("gtk") # gtk is default
25-
sgui = test.TestGraph(opengl=options.opengl, debug=options.debug)
25+
sgui = test.TestGraph(use_gl=options.use_gl, debug=options.debug)
2626
sgui.show()
2727

2828
if options.filename:

core/graph.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def add_edge(self, src, dest, **kwargs):
422422
src_attr = kwargs.pop('src_attr', 'output')
423423
dest_attr = kwargs.pop('dest_attr', 'input')
424424
weight = kwargs.pop('weight', 1.0)
425+
edge_type = kwargs.pop('edge_type', 'bezier')
425426

426427
if src is None or dest is None:
427428
log.warning('none type passed.')
@@ -440,18 +441,14 @@ def add_edge(self, src, dest, **kwargs):
440441
if conn_str in self.connections():
441442
log.warning('connection already exists: %s' % conn_str)
442443
return
443-
444-
edge_attrs = dict(src_id=src.id, dest_id=dest.id, src_attr=src_attr, dest_attr=dest_attr)
444+
445+
# edge attributes for nx graph
446+
edge_attrs = dict(src_id=src.id, dest_id=dest.id, src_attr=src_attr, dest_attr=dest_attr, edge_type=edge_type)
445447

446448
src_conn = src.get_connection(src_attr)
447449
dest_conn = dest.get_connection(dest_attr)
448450
edge_id_str = '(%s,%s)' % (src.id, dest.id)
449-
'''
450-
print '# source dag: ', src.name
451-
print '# dest dag: ', dest.name
452-
print '# source conn: ', src_conn, src_attr
453-
print '# dest conn: ', dest_conn, dest_attr
454-
'''
451+
455452
if edge_id_str not in src_conn._edges and edge_id_str not in dest_conn._edges:
456453
# add the nx edge
457454
self.network.add_edge(src.id, dest.id, key='attributes', weight=weight, attr_dict=edge_attrs)

options.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,28 @@
9999
}
100100

101101

102+
EDGE_TYPES = ['bezier', 'polygon']
103+
104+
105+
VIEWPORT_MODES = dict(
106+
full = 'QtGui.QGraphicsView.FullViewportUpdate',
107+
smart = 'QtGui.QGraphicsView.SmartViewportUpdate',
108+
minimal = 'QtGui.QGraphicsView.MinimalViewportUpdate',
109+
bounding = 'QtGui.QGraphicsView.BoundingRectViewportUpdate'
110+
)
102111

103112
def setup_platform_defaults():
104113
"""
105114
Setup globals for a specific platform.
106115
"""
107116
import sys
108-
plaform = 'Windows'
117+
platform = 'Windows'
109118
if 'linux' in sys.platform:
110-
plaform = 'Linux'
119+
platform = 'Linux'
111120

112121
if sys.platform == 'darwin':
113-
plaform = 'MacOSX'
114-
return plaform
122+
platform = 'MacOSX'
123+
return platform
115124

116125

117126
def setup_fonts(font='SansSerif', size=8, platform=None):

plugins/note.mtd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@
2323
[attr force_expand]
2424
default BOOL false
2525
label STRING "Expand Node"
26-
private BOOL true
26+
private BOOL true
27+
28+
[attr show_name]
29+
default BOOL false
30+
label STRING "Show name"

plugins/note.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ def __init__(self, name=None, **kwargs):
1717

1818
self.corner_loc = 'top'
1919
self.base_height = 75
20-
self.doc_text = kwargs.get('doc_text', "Sample note text.")
2120
self.font_size = 6
21+
self.show_name = kwargs.get('show_name', False)
22+
self.doc_text = kwargs.get('doc_text', "Sample note text.")
2223

2324
@property
2425
def data(self):
@@ -29,5 +30,5 @@ def data(self):
2930
for attr in self.REQUIRED:
3031
if hasattr(self, attr):
3132
data[attr] = getattr(self, attr)
32-
data.update(doc_text=self.doc_text, corner_loc=self.corner_loc, font_size=self.font_size)
33+
data.update(doc_text=self.doc_text, corner_loc=self.corner_loc, font_size=self.font_size, show_name=self.show_name)
3334
return data

plugins/note_widget.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def __init__(self, dagnode, parent=None):
3131
self.bufferX = 3
3232
self.bufferY = 3
3333
self.pen_width = 1.5 # pen width for NoteBackground
34-
34+
self.handle_size = 6 # size of the resize handle
35+
3536
# fonts
3637
self._font = 'SansSerif'
3738
self._font_size = self.dagnode.font_size
@@ -53,6 +54,8 @@ def __init__(self, dagnode, parent=None):
5354
# temp resizing attributes
5455
self.top_left = ()
5556
self.btm_right = ()
57+
self.min_width = 75 # widget minimum size
58+
self.min_height = 60 # widget minimum size
5659

5760
# label
5861
self._evaluate_tag = False # indicates the node is set to "evaluate" (a la Houdini)
@@ -168,8 +171,8 @@ def mouseMoveEvent(self, event):
168171
self.btm_right = (scene_pos.x(), scene_pos.y())
169172
# create a temporary rectangle with the current selection
170173
rect = QtCore.QRectF(QtCore.QPointF(*self.top_left), QtCore.QPointF(*self.btm_right))
171-
self.dagnode.width = rect.width()
172-
self.dagnode.height = rect.height()
174+
self.dagnode.width = abs(rect.width())
175+
self.dagnode.height = abs(rect.height())
173176

174177
def mousePressEvent(self, event):
175178
"""
@@ -193,7 +196,13 @@ def mouseReleaseEvent(self, event):
193196
self.handle_selected = False
194197
#self.setPos(cpos.x(), cpos.y())
195198
QtGui.QGraphicsItem.mouseReleaseEvent(self, event)
196-
199+
200+
# tidy up
201+
if self.dagnode.width < self.min_width:
202+
self.dagnode.width = self.min_width
203+
204+
if self.dagnode.height < self.min_height:
205+
self.dagnode.height = self.min_height
197206

198207
def dagnodeUpdated(self, *args, **kwargs):
199208
"""
@@ -357,12 +366,11 @@ def handleRect(self):
357366
* testing
358367
"""
359368
rect = self.boundingRect()
360-
size = 6
361-
buffer = 2
362-
p1 = rect.bottomRight() # need as p1
363-
p2 = QtCore.QPointF(p1.x() - (size+buffer), p1.y())
364-
topLeft = QtCore.QPointF(p2.x(), p2.y() - (size+buffer))
365-
return QtCore.QRectF(topLeft, QtCore.QSize(size, size))
369+
hbuffer = self.handle_size/3.0
370+
p1 = rect.bottomRight()
371+
p2 = QtCore.QPointF(abs(p1.x()) - (self.handle_size + hbuffer), p1.y())
372+
topLeft = QtCore.QPointF(p2.x(), p2.y() - (self.handle_size + hbuffer))
373+
return QtCore.QRectF(topLeft, QtCore.QSize(self.handle_size, self.handle_size))
366374

367375
def paint(self, painter, option, widget):
368376
"""
@@ -452,11 +460,16 @@ def paint(self, painter, option, widget):
452460
painter.setBrush(qbrush)
453461

454462
# draw background
455-
painter.drawPolygon(note_shape)
463+
if not self.handle_selected:
464+
painter.drawPolygon(note_shape)
465+
else:
466+
painter.drawRect(self.boundingRect())
456467
painter.setBrush(cbrush)
457468
painter.setPen(cpen)
469+
458470
# draw corner
459-
painter.drawPolygon(corner_shape)
471+
if not self.handle_selected:
472+
painter.drawPolygon(corner_shape)
460473

461474
self.center_label.hide()
462475
cpos = self.mapToScene(self.boundingRect().center())
@@ -472,7 +485,7 @@ def paint(self, painter, option, widget):
472485
if self._debug:
473486
self.center_label.show()
474487
self.center_label.setPos(0,0)
475-
self.setPos(cpos.x(),cpos.y())
488+
self.setPos(cpos.x(),cpos.y())
476489
self.resize_handle.setRect(self.handleRect())
477490

478491
def setDebug(self, val):

0 commit comments

Comments
 (0)