def __init__(self, width, height, texture): MenuItem.__init__(self) item_width = self.get_abs_x(width) item_height = self.get_abs_y(height) self.original_ratio = float(texture.get_width()) self.original_ratio /= texture.get_height() item_ratio = float(item_width) / float(item_height) margin = 0.95 if item_ratio >= self.original_ratio: texture_width = self.original_ratio * item_height texture_height = item_height texture_width *= margin texture_height *= margin delta_width = item_width - texture_width delta_height = item_height - texture_height else: texture_width = item_width texture_height = item_width / self.original_ratio texture_width *= margin texture_height *= margin delta_width = item_width - texture_width delta_height = item_height - texture_height item_x = delta_width / 2.0 item_y = delta_height / 2.0 texture.set_position(int(item_x), int(item_y)) texture.set_size(int(texture_width), int(texture_height)) self.add(texture)
def setUp(self): '''Set up the test.''' EntertainerTest.setUp(self) self.menu = GridMenu(0, 0) self.cursor = clutter.Rectangle() self.item = MenuItem() self.item.userdata = "foo" self.menu.raw_add_item(MenuItem()) self.menu.raw_add_item(MenuItem()) self.menu.raw_add_item(self.item) self.menu.raw_add_item(MenuItem()) self.menu.items_per_row = 2 self.menu.items_per_col = 2 self.menu.visible_rows = 2 self.menu.visible_cols = 2
def __init__(self, width, height, text, extra_text=None): MenuItem.__init__(self) self.width = width self.height = height self.theme = self.config.theme self.text = text self.extra_text = extra_text self.color = "menuitem_inactive" self.font_size = 0.03 self.label = Label(self.font_size, self.color, 0, 0, "", "text_label") self.add(self.label) # Set extra text self.extra_label = None if extra_text is not None: self.extra_label = Label(self.font_size, self.color, 0, 0, "", "text_label") self.add(self.extra_label) self.update(text, extra_text)
def setUp(self): '''Set up the test.''' EntertainerTest.setUp(self) self.item = MenuItem()