I hope I understood correctly what is this: it's automatically changed by the build...
[guess.git] / scripts / dockexample2.py
blobf60221ca1303ddcdb081576e574edae5c5f6af91
1 # adds a slider that controls the visibility of edges based on
2 # the "freq" attribute
3 #
4 # to execute do:
5 # load up the sample.gdf
6 # execfile("scripts/dockexample2.py")
7 # dockexample2()
9 import java
10 import javax.swing
11 import com
13 class dockexample2(com.hp.hpl.guess.ui.DockableAdapter):
15 testSlider = JSlider()
16 label = JLabel("Frequency threshold (0) ")
18 def __init__(self):
19 # set up the slider limits
20 self.testSlider.setMinimum(freq.min)
21 self.testSlider.setMaximum(freq.max + 1)
23 # set up the slider visual properties
24 self.testSlider.setMajorTickSpacing(50)
25 self.testSlider.setMinorTickSpacing(10)
26 self.testSlider.setPaintTicks(true)
27 self.testSlider.setPaintLabels(true)
28 self.testSlider.setValue(freq.min) # default value
30 # every time the mouse is released call the "sc" event
31 self.testSlider.mouseReleased = self.sc
33 # add the label and slider to the UI
34 self.add(self.label)
35 self.add(self.testSlider)
37 # dock the new panel into the UI
38 ui.dock(self)
40 # call the event function once so that the
41 # display matches the slider value
42 self.sc(None)
44 def getTitle(self):
45 return("dockexample2")
47 def sc(self,evt):
48 # get the value
49 val = self.testSlider.getValue()
51 # show all the nodes
52 g.nodes.visible = 1
54 # hide all edges under value and show all over
55 (freq < val).visible = 0
56 (freq >= val).visible = 1
58 # hide nodes not connected to visible edges
59 self.hideDisconnectedNodes()
61 # set the label text
62 self.label.setText("Frequency threshold ("+str(val)+")")
64 def hideDisconnectedNodes(self):
65 # keep a list of nodes to hide
66 toHide = []
69 for nod in g.nodes: # for all nodes
70 vis = 0 # default to invisble
72 # for all edges connected to this node
73 # if there is any visible edge
74 # keep this node visible
75 for ed in nod.getOutEdges():
76 if (ed.visible == 1):
77 vis = 1
78 break
80 if (vis == 0): # should we hide the node?
81 toHide += [nod]
83 # hide all the nodes we put in our list
84 toHide.visible = 0
87 dockexample2()