Changeset 8513:9e77b1b3af7e in orange


Ignore:
Timestamp:
07/28/11 14:26:42 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
5a1c999e6b2d389d6660e099f6989c446f20a2fe
Message:

Set labels, renamed some functions.

Location:
orange/OrangeWidgets/Prototypes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWNxCanvasQt.py

    r8485 r8513  
    4040      self.showEdgeLabels = 0 
    4141       
    42   def set_node_size(self, values={}, min_size=0, max_size=0): 
    43       orangeplot.NetworkCurve.set_node_size(self, values, min_size, max_size) 
     42  def set_node_sizes(self, values={}, min_size=0, max_size=0): 
     43      orangeplot.NetworkCurve.set_node_sizes(self, values, min_size, max_size) 
    4444       
    4545  def move_selected_nodes(self, dx, dy): 
     
    194194        self.master = master 
    195195        self.parent = parent 
    196         self.labelText = [] 
     196        self.label_attributes = [] 
    197197        self.tooltipText = [] 
    198198        #self.vertices_old = {}         # distionary of nodes (orngIndex: vertex_objekt) 
     
    545545                    
    546546    def drawLabels(self): 
    547         if len(self.labelText) > 0: 
     547        if len(self.label_attributes) > 0: 
    548548            for vertex in self.networkCurve.vertices.itervalues(): 
    549549                if not vertex.show: 
     
    558558                values = self.items[vertex.index] 
    559559                if self.showMissingValues: 
    560                     lbl = ", ".join([str(values[ndx]) for ndx in self.labelText]) 
     560                    lbl = ", ".join([str(values[ndx]) for ndx in self.label_attributes]) 
    561561                else: 
    562                     lbl = ", ".join([str(values[ndx]) for ndx in self.labelText if str(values[ndx]) != '?']) 
     562                    lbl = ", ".join([str(values[ndx]) for ndx in self.label_attributes if str(values[ndx]) != '?']) 
    563563                #if not self.showMissingValues and lbl == '': 
    564564                #    continue  
     
    672672#                      self.networkCurve.set_edge_color(index, newColor) 
    673673     
    674     def set_node_color(self, attribute, nodes=None): 
     674    def set_node_colors(self, attribute, nodes=None): 
    675675        if self.graph is None: 
    676676            return 
     
    696696            colors.update((node, self.discPalette[0]) for node in nodes) 
    697697         
    698         self.networkCurve.set_node_color(colors) 
     698        self.networkCurve.set_node_colors(colors) 
    699699        self.replot() 
    700700         
    701     def setLabelText(self, attributes): 
    702         self.labelText = [] 
    703         if self.layout is None or self.graph is None or self.items is None: 
     701    def set_label_attributes(self, attributes): 
     702        self.label_attributes = [] 
     703        if self.graph is None or self.items is None or \ 
     704           not isinstance(self.items, orange.ExampleTable): 
    704705            return 
    705706         
    706         if isinstance(self.items, orange.ExampleTable): 
    707             data = self.items 
    708             for att in attributes: 
    709                 for i in range(len(data.domain)): 
    710                     if data.domain[i].name == att: 
    711                         self.labelText.append(i) 
    712                          
    713                 if self.items.domain.hasmeta(att): 
    714                         self.labelText.append(self.items.domain.metaid(att)) 
    715      
     707        self.label_attributes = [self.items.domain[att] for att in \ 
     708                                 attributes if att in self.items.domain] 
     709        self.networkCurve.set_node_labels(dict((node, '\n'.join(str( \ 
     710                    self.items[node][att]) for att in self.label_attributes)) \ 
     711                                                        for node in self.graph))     
     712        self.replot() 
     713         
    716714    def setTooltipText(self, attributes): 
    717715        self.tooltipText = [] 
     
    915913#                edge.pen.setCapStyle(Qt.RoundCap) 
    916914        pass     
     915     
     916    def update_animations(self): 
     917        OWPlot.use_animations(self) 
     918        self.networkCurve.set_use_animations(True) 
    917919                     
    918920    def replot(self): 
    919921        OWPlot.replot(self) 
    920          
    921922        if hasattr(self, 'networkCurve') and self.networkCurve is not None: 
    922923            self.networkCurve.update() 
  • orange/OrangeWidgets/Prototypes/OWNxExplorerQt.py

    r8499 r8513  
    3131class OWNxExplorerQt(OWWidget): 
    3232    settingsList = ["autoSendSelection", "spinExplicit", "spinPercentage", 
    33     "maxLinkSize", "minVertexSize", "maxVertexSize", "networkCanvas.use_antialiasing", 
     33    "maxLinkSize", "minVertexSize", "maxVertexSize", "networkCanvas.use_antialiasing", "networkCanvas.use_animations", 
    3434    "invertSize", "optMethod", "lastVertexSizeColumn", "lastColorColumn", 
    3535    "lastNameComponentAttribute", "lastLabelColumns", "lastTooltipColumns", 
     
    169169        OWGUI.button(colorBox, self, "Set vertex color palette", self.setColors, tooltip = "Set vertex color palette", debuggingEnabled = 0) 
    170170         
    171         self.vertexSizeCombo = OWGUI.comboBox(self.verticesTab, self, "vertexSize", box = "Vertex size attribute", callback=self.set_vertex_size) 
     171        ib = OWGUI.widgetBox(self.verticesTab, "Vertex size attribute", orientation="vertical", addSpace = False) 
     172        hb = OWGUI.widgetBox(ib, orientation="horizontal", addSpace = False) 
     173        OWGUI.checkBox(hb, self, "invertSize", "Invert size", callback = self.set_vertex_size) 
     174        OWGUI.spin(hb, self, "minVertexSize", 5, 200, 1, label="Min:", callback=self.set_vertex_size) 
     175        OWGUI.spin(hb, self, "maxVertexSize", 5, 200, 1, label="Max:", callback=self.set_vertex_size) 
     176        self.vertexSizeCombo = OWGUI.comboBox(ib, self, "vertexSize", callback=self.set_vertex_size) 
    172177        self.vertexSizeCombo.addItem("(none)") 
    173178         
    174         OWGUI.spin(self.vertexSizeCombo.box, self, "minVertexSize", 5, 200, 1, label="Min vertex size:", callback=self.set_vertex_size) 
    175         OWGUI.spin(self.vertexSizeCombo.box, self, "maxVertexSize", 5, 200, 1, label="Max vertex size:", callback=self.set_vertex_size) 
    176         OWGUI.checkBox(self.vertexSizeCombo.box, self, "invertSize", "Invert vertex size", callback = self.set_vertex_size) 
    177          
    178         colorBox = OWGUI.widgetBox(self.edgesTab, "Edge color attribute", orientation="horizontal", addSpace = False) 
    179         self.edgeColorCombo = OWGUI.comboBox(colorBox, self, "edgeColor", callback=self.setEdgeColor) 
    180         self.edgeColorCombo.addItem("(same color)") 
    181         OWGUI.button(colorBox, self, "Set edge color palette", self.setEdgeColorPalette, tooltip = "Set edge color palette", debuggingEnabled = 0) 
    182          
    183         self.attBox = OWGUI.widgetBox(self.verticesTab, "Vertex labels | tooltips", orientation="vertical", addSpace = False) 
    184         OWGUI.spin(self.attBox, self, "fontSize", 4, 30, 1, label="Set font size:", callback = self.setFontSize) 
    185          
    186         self.attBox = OWGUI.widgetBox(self.attBox, orientation="horizontal", addSpace = False) 
    187         self.attListBox = OWGUI.listBox(self.attBox, self, "markerAttributes", "attributes", selectionMode=QListWidget.MultiSelection, callback=self.clickedAttLstBox) 
    188         self.tooltipListBox = OWGUI.listBox(self.attBox, self, "tooltipAttributes", "attributes", selectionMode=QListWidget.MultiSelection, callback=self.clickedTooltipLstBox) 
    189          
    190         self.edgeLabelBox = OWGUI.widgetBox(self.edgesTab, "Edge labels", addSpace = False) 
    191         self.edgeLabelListBox = OWGUI.listBox(self.edgeLabelBox, self, "edgeLabelAttributes", "edgeAttributes", selectionMode=QListWidget.MultiSelection, callback=self.clickedEdgeLabelListBox) 
    192         self.edgeLabelBox.setEnabled(False) 
     179        ib = OWGUI.widgetBox(self.verticesTab, "Vertex labels | tooltips", orientation="vertical", addSpace = False) 
     180        OWGUI.spin(ib, self, "fontSize", 4, 30, 1, label="Set font size:", callback = self.setFontSize) 
     181        hb = OWGUI.widgetBox(ib, orientation="horizontal", addSpace = False) 
     182        self.attListBox = OWGUI.listBox(hb, self, "markerAttributes", "attributes", selectionMode=QListWidget.MultiSelection, callback=self.clickedAttLstBox) 
     183        self.tooltipListBox = OWGUI.listBox(hb, self, "tooltipAttributes", "attributes", selectionMode=QListWidget.MultiSelection, callback=self.clickedTooltipLstBox) 
    193184         
    194185        ib = OWGUI.widgetBox(self.edgesTab, "General", orientation="vertical") 
     
    198189        self.showDistancesCheckBox = OWGUI.checkBox(ib, self, 'showDistances', 'Explore vertex distances', callback=(lambda: self._set_canvas_attr('showDistances', self.showDistances)), disabled=1) 
    199190         
     191        colorBox = OWGUI.widgetBox(self.edgesTab, "Edge color attribute", orientation="horizontal", addSpace = False) 
     192        self.edgeColorCombo = OWGUI.comboBox(colorBox, self, "edgeColor", callback=self.setEdgeColor) 
     193        self.edgeColorCombo.addItem("(same color)") 
     194        OWGUI.button(colorBox, self, "Set edge color palette", self.setEdgeColorPalette, tooltip = "Set edge color palette", debuggingEnabled = 0) 
     195         
     196        self.edgeLabelBox = OWGUI.widgetBox(self.edgesTab, "Edge labels", addSpace = False) 
     197        self.edgeLabelListBox = OWGUI.listBox(self.edgeLabelBox, self, "edgeLabelAttributes", "edgeAttributes", selectionMode=QListWidget.MultiSelection, callback=self.clickedEdgeLabelListBox) 
     198        self.edgeLabelBox.setEnabled(False) 
     199         
    200200        ib = OWGUI.widgetBox(self.verticesTab, "General", orientation="vertical") 
    201201        OWGUI.checkBox(ib, self, 'showIndexes', 'Show indexes', callback=(lambda: self._set_canvas_attr('showIndexes', self.showIndexes))) 
    202202        OWGUI.checkBox(ib, self, 'labelsOnMarkedOnly', 'Show labels on marked vertices only', callback=(lambda: self._set_canvas_attr('labelsOnMarkedOnly', self.labelsOnMarkedOnly))) 
    203203        self.networkCanvas.gui.antialiasing_check_box(ib) 
    204         self.insideView = 0 
    205         self.insideViewNeighbours = 2 
    206         OWGUI.spin(ib, self, "insideViewNeighbours", 1, 6, 1, label="Inside view (neighbours): ", checked = "insideView", checkCallback = self.insideview, callback = self.insideviewneighbours) 
     204        self.networkCanvas.gui.animations_check_box(ib) 
    207205        OWGUI.checkBox(ib, self, 'showMissingValues', 'Show missing values', callback=(lambda: self._set_canvas_attr('showMissingValues', self.showMissingValues))) 
    208206         
     
    599597         
    600598        self.send("Marked Items", None) 
    601          
    602     def insideviewneighbours(self): 
    603         if self.networkCanvas.insideview == 1: 
    604             self.networkCanvas.insideviewNeighbours = self.insideViewNeighbours 
    605             self.optButton.setChecked(True) 
    606             self.graph_layout_fr(False) 
    607          
    608     def insideview(self): 
    609         print self.networkCanvas.getSelectedVertices() 
    610         if len(self.networkCanvas.getSelectedVertices()) == 1: 
    611             if self.networkCanvas.insideview == 1: 
    612                 print "insideview: 1" 
    613                 self.networkCanvas.insideview = 0 
    614                 self.networkCanvas.showAllVertices() 
    615                 self.networkCanvas.updateCanvas() 
    616             else: 
    617                 print "insideview: 0" 
    618                 self.networkCanvas.insideview = 1 
    619                 self.networkCanvas.insideviewNeighbors = self.insideViewNeighbours 
    620                 self.optButton.setChecked(True) 
    621                 self.graph_layout_fr(False) 
    622      
    623         else: 
    624             print "One node must be selected!" 
    625          
     599             
    626600    def showComponents(self): 
    627601        if self.graph is None or self.graph_base.items() is None: 
     
    12751249        if self.frSteps < 10: 
    12761250            self.networkCanvas.use_antialiasing = 0 
     1251            self.networkCanvas.use_animations = 0 
    12771252            self.minVertexSize = 5 
    12781253            self.maxVertexSize = 5 
     
    13851360        if self.frSteps < 10: 
    13861361            self.networkCanvas.use_antialiasing = 0 
     1362            self.networkCanvas.use_animations = 0 
    13871363            self.minVertexSize = 5 
    13881364            self.maxVertexSize = 5 
     
    14231399         
    14241400        self.set_vertex_size() 
     1401        self.networkCanvas.items = items 
    14251402        self.networkCanvas.showIndexes = self.showIndexes 
    14261403        self.networkCanvas.showWeights = self.showWeights 
     
    17071684         
    17081685        self.lastLabelColumns = set([self.attributes[i][0] for i in self.markerAttributes]) 
    1709         self.networkCanvas.setLabelText(self.lastLabelColumns) 
     1686        self.networkCanvas.set_label_attributes(self.lastLabelColumns) 
    17101687        self.networkCanvas.updateData() 
    17111688        self.networkCanvas.replot() 
     
    17331710            return 
    17341711         
    1735         self.networkCanvas.set_node_color(self.colorCombo.currentText()) 
     1712        self.networkCanvas.set_node_colors(self.colorCombo.currentText()) 
    17361713        self.lastColorColumn = self.colorCombo.currentText() 
    17371714         
     
    17821759            maxval = max(values.itervalues()) 
    17831760            values.update((key, maxval-val) for key, val in values.iteritems()) 
    1784             self.networkCanvas.networkCurve.set_node_size(values, min_size=self.minVertexSize, max_size=self.maxVertexSize) 
     1761            self.networkCanvas.networkCurve.set_node_sizes(values, min_size=self.minVertexSize, max_size=self.maxVertexSize) 
    17851762        else: 
    1786             self.networkCanvas.networkCurve.set_node_size(values, min_size=self.minVertexSize, max_size=self.maxVertexSize) 
     1763            self.networkCanvas.networkCurve.set_node_sizes(values, min_size=self.minVertexSize, max_size=self.maxVertexSize) 
    17871764         
    17881765            self.networkCanvas.replot() 
Note: See TracChangeset for help on using the changeset viewer.