Ignore:
Timestamp:
07/07/12 12:23:21 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Using icons instead of a drawing for the connection state

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/statusbar.py

    r116 r281  
    1515class Statusbar(gtk.Frame, FlightStatusHandler):
    1616    """A status bar for the logger."""
    17     def __init__(self):
     17    def __init__(self, iconDirectory):
    1818        """Construct the status bar."""
    1919        gtk.Frame.__init__(self)
     
    3535        frameAlignment.add(statusBox)
    3636
     37        iconPath = os.path.join(iconDirectory, "conn_grey.png")
     38        self._connGreyIcon = pixbuf_new_from_file(iconPath)
     39
     40        iconPath = os.path.join(iconDirectory, "conn_red.png")
     41        self._connRedIcon = pixbuf_new_from_file(iconPath)
     42
     43        iconPath = os.path.join(iconDirectory, "conn_green.png")
     44        self._connGreenIcon = pixbuf_new_from_file(iconPath)
     45
    3746        self._connStateArea = gtk.DrawingArea()
    38         self._connStateArea.set_size_request(16, 16)
     47        self._connStateArea.set_size_request(18, 18)
    3948        self._connStateArea.set_tooltip_markup(xstr("statusbar_conn_tooltip"))
    4049
     
    105114
    106115    def _drawConnState(self, connStateArea, eventOrContext):
    107         """Draw the connection state."""       
    108         context = eventOrContext if pygobject else connStateArea.window.cairo_create()
    109 
     116        """Draw the connection state."""
    110117        if self._connecting:
    111118            if self._connected:
    112                 context.set_source_rgb(0.0, 1.0, 0.0)
     119                icon = self._connGreenIcon
    113120            else:
    114                 context.set_source_rgb(1.0, 0.0, 0.0)
     121                icon = self._connRedIcon
    115122        else:
    116             context.set_source_rgb(0.75, 0.75, 0.75)
     123            icon = self._connGreyIcon
    117124
    118         width = connStateArea.get_allocated_width() if pygobject \
    119                 else connStateArea.allocation.width
    120         height = connStateArea.get_allocated_height() if pygobject \
    121                  else connStateArea.allocation.height
    122         context.arc(width/2, height/2, width/2, 0, 2*math.pi)
    123 
    124         context.fill()
     125        if pygobject:
     126            gdk.cairo_set_source_pixbuf(eventOrContext, icon, 0, 0)
     127            eventOrContext.paint()
     128        else:
     129            gc = connStateArea.get_style().fg_gc[gtk.STATE_NORMAL]
     130            drawable = connStateArea.get_window()
     131            drawable.draw_pixbuf(gc, icon, 0, 0, 0, 0)
    125132
    126133    def _updateFlightStatus(self):
Note: See TracChangeset for help on using the changeset viewer.