Changeset 11737:6377d02bd026 in orange


Ignore:
Timestamp:
10/17/13 14:38:42 (6 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Refactor feature tool tip functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeWidgets/OWItemModels.py

    r10947 r11737  
    11from __future__ import with_statement 
     2 
     3from xml.sax.saxutils import escape 
    24 
    35from PyQt4.QtCore import * 
     
    330332import cPickle 
    331333 
     334 
     335def feature_tooltip(feature): 
     336    if isinstance(feature, Orange.feature.Discrete): 
     337        return discrete_feature_tooltip(feature) 
     338    elif isinstance(feature, Orange.feature.Continuous): 
     339        return continuous_feature_toltip(feature) 
     340    elif isinstance(feature, Orange.feature.String): 
     341        return string_feature_tooltip(feature) 
     342    elif isinstance(feature, Orange.feature.Python): 
     343        return python_feature_tooltip(feature) 
     344    elif isinstance(feature, Orange.feature.Descriptor): 
     345        return generic_feature_tooltip(feature) 
     346    else: 
     347        raise TypeError("Expected an instance of 'Orange.feature.Descriptor'") 
     348 
     349 
     350def feature_labels_tooltip(feature): 
     351    text = "" 
     352    if feature.attributes: 
     353        items = feature.attributes.items() 
     354        items = [(escape(key), escape(value)) for key, value in items] 
     355        labels = map("%s = %s".__mod__, items) 
     356        text += "<br/>Feature Labels:<br/>" 
     357        text += "<br/>".join(labels) 
     358    return text 
     359 
     360 
     361def discrete_feature_tooltip(feature): 
     362    text = ("<b>%s</b><br/>Discrete with %i values: " % 
     363            (escape(feature.name), len(feature.values))) 
     364    text += ", ".join("%r" % escape(v) for v in feature.values) 
     365    text += feature_labels_tooltip(feature) 
     366    return text 
     367 
     368 
     369def continuous_feature_toltip(feature): 
     370    text = "<b>%s</b><br/>Continuous" % escape(feature.name) 
     371    text += feature_labels_tooltip(feature) 
     372    return text 
     373 
     374 
     375def string_feature_tooltip(feature): 
     376    text = "<b>%s</b><br/>String" % escape(feature.name) 
     377    text += feature_labels_tooltip(feature) 
     378    return text 
     379 
     380 
     381def python_feature_tooltip(feature): 
     382    text = "<b>%s</b><br/>Python" % escape(feature.name) 
     383    text += feature_labels_tooltip(feature) 
     384    return text 
     385 
     386 
     387def generic_feature_tooltip(feature): 
     388    text = "<b>%s</b><br/>%s" % (escape(feature.name), type(feature).__name__) 
     389    text += feature_labels_tooltip(feature) 
     390    return text 
     391 
     392 
    332393class VariableListModel(PyListModel): 
    333394 
     
    358419 
    359420    def variable_labels_tooltip(self, var): 
    360         text = "" 
    361         if var.attributes: 
    362             items = var.attributes.items() 
    363             items = [(safe_text(key), safe_text(value)) for key, value in items] 
    364             labels = map("%s = %s".__mod__, items) 
    365             text += "<br/>Variable Labels:<br/>" 
    366             text += "<br/>".join(labels) 
    367         return text 
     421        return feature_labels_tooltip(var) 
    368422 
    369423    def discrete_variable_tooltip(self, var): 
    370         text = "<b>%s</b><br/>Discrete with %i values: " % (safe_text(var.name), len(var.values)) 
    371         text += ", ".join("%r" % safe_text(v) for v in var.values) 
    372         text += self.variable_labels_tooltip(var) 
    373         return text 
     424        return discrete_feature_tooltip(var) 
    374425 
    375426    def continuous_variable_toltip(self, var): 
    376         text = "<b>%s</b><br/>Continuous" % safe_text(var.name) 
    377         text += self.variable_labels_tooltip(var) 
    378         return text 
     427        return continuous_feature_toltip(var) 
    379428 
    380429    def string_variable_tooltip(self, var): 
    381         text = "<b>%s</b><br/>String" % safe_text(var.name) 
    382         text += self.variable_labels_tooltip(var) 
    383         return text 
     430        return string_feature_tooltip(var) 
    384431 
    385432    def python_variable_tooltip(self, var): 
    386         text = "<b>%s</b><br/>Python" % safe_text(var.name) 
    387         text += self.variable_labels_tooltip(var) 
    388         return text 
     433        return python_feature_tooltip(var) 
     434 
    389435 
    390436_html_replace = [("<", "&lt;"), (">", "&gt;")] 
Note: See TracChangeset for help on using the changeset viewer.