示例#1
0
 def good_globe_position(self, context, text):
     size = config.canvas_grid_size
     screen = self.canvas.visible_rect()
     left_margin = self.get_pixel_x()
     right_margin = screen.width - (self.get_pixel_x() + size)
     top_margin = self.get_pixel_y()
     bottom_margin = screen.height - (self.get_pixel_y() + size)
     
     text_width, text_height = text_size(context, text)
     
     if left_margin < right_margin:
         origin_x = self.get_pixel_x() + size
         globe_x = origin_x + size/2
     else:
         origin_x = self.get_pixel_x()
         globe_x = origin_x - size/2 - text_width
     
     if top_margin < bottom_margin:
         origin_y = self.get_pixel_y() + size
         globe_y = origin_y + size/2
     else:
         origin_y = self.get_pixel_y()
         globe_y = origin_y - size - text_height
         
     return origin_x, origin_y, globe_x, globe_y
示例#2
0
 def __init__(self, question):
     super(AskLayout, self).__init__()
     path = os.path.join('gui', 'robot_empty.png')
     self.robot_image = cairo.ImageSurface.create_from_png(path)
     self.connect('expose_event', self.on_expose)
     self.question = question
     
     dummy_context = cairo.Context(cairo.ImageSurface(cairo.FORMAT_ARGB32, 0,0))
     width, height = text_size(dummy_context, self.question)
     
     width  += 100
     height += 50
     
     self.set_size_request(width, height)