source: modules/mod_notification.py @ ec56a8a

Last change on this file since ec56a8a was ec56a8a, checked in by xkolman2 <xkolman2@…>, 4 years ago

replace active tracklog index by active tracklog path variable
-> fix the mess resulting from inconsistent indexes
make all modules load the tracklogs throught a method, not directly
-> safer, more transparent

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@156 0858a4d0-ffff-46e5-938e-62b5ecb34222

  • Property mode set to 100644
File size: 3.8 KB
Line 
1#!/usr/bin/python
2#----------------------------------------------------------------------------
3# This module provides notification support.
4#----------------------------------------------------------------------------
5# Copyright 2007, Oliver White
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#---------------------------------------------------------------------------
20from base_module import ranaModule
21import time
22
23def getModule(m,d):
24  return(notification(m,d))
25
26class notification(ranaModule):
27  """This module provides notification support."""
28 
29  def __init__(self, m, d):
30    ranaModule.__init__(self, m, d)
31    self.notificationText = ""
32    self.timeout = 5
33    self.position = 'middle'
34    self.expirationTimestamp = time.time()
35    self.draw = False
36    self.redrawn = None
37
38   
39  def update(self):
40#    # Get and set functions are used to access global data
41#    self.set('num_updates', self.get('num_updates', 0) + 1)
42#    #print "Updated %d times" % (self.get('num_updates'))
43    self.set('num_updates', self.get('num_updates', 0) + 1)
44
45  def handleMessage(self, message):
46    """the first part is the message, that will be displayed,
47       there can also by some parameters, delimited by #"""
48    list = message.split('#')
49    # TODO: support setting timeout and position
50    timeout = self.timeout
51    self.position = 'middle'
52    self.notificationText = list[0]
53    self.draw = True # enable drawing of notifications
54    if len(list) == 2:
55      try:
56        timeout = int(list[1]) # override the default timeout
57      except:
58        print "notification: wrong timeout, using default 5 secconds"
59    self.expirationTimestamp = time.time() + timeout
60    self.set('needRedraw', True) # make sure the notification is displayed
61
62
63  def drawMenu(self,cr,menuName):
64    """We want the notification to work even over the menu."""
65    if self.draw == True:
66      self.drawNotification(cr)
67
68  def drawScreenOverlay(self, cr):
69    """We want the notification to work even over the map."""
70    if self.draw == True:
71      try:
72        self.drawNotification(cr)
73      except:
74        print "notification: drawing notification failed"
75
76  def drawNotification(self, cr):
77    """Draw the notifications on the screen on top of everything."""
78    timestamp = time.time()
79    expirationTimestamp = self.expirationTimestamp
80    if timestamp <= expirationTimestamp:
81      proj = self.m.get('projection', None)
82      (x1,y1) = proj.screenPos(0.5, 0.5) # middle fo the screen
83      cr.set_font_size(30)
84      text = self.notificationText
85      cr.set_source_rgba(0, 0, 1, 0.45) # trasparent blue
86      extents = cr.text_extents(text)
87      (w,h) = (extents[2], extents[3])
88      (x,y) = (x1-w/2.0,y1-h/2.0)
89      cr.set_line_width(2)
90      cr.set_source_rgba(0, 0, 1, 0.45) # trasparent blue
91      (rx,ry,rw,rh) = (x-0.25*w, y-h*1.5, w*1.5, (h*2))
92      cr.rectangle(rx,ry,rw,rh) # create the transparent background rectangle
93      cr.fill()
94      cr.set_source_rgba(1, 1, 1, 0.95) # slightly trasparent white
95      cr.move_to(x+10,y)
96      cr.show_text(text) # show the trasparent notification text
97      cr.stroke()
98      cr.fill()
99    else:
100      self.draw = False # we are finished, disable drawing notifications
101
102
103
104
105
106
107
108
109
110if(__name__ == "__main__"):
111  a = example({}, {})
112  a.update()
113  a.update()
114  a.update()
Note: See TracBrowser for help on using the repository browser.