def size_allocate_cb(self, widget, event): """ Builds the tag star around the center where the selected category is shown. """ self._logger.debug('size_allocate_cb()') x, y, width, height = self.fixed.get_allocation() self._logger.debug('x: %s, y: %s, w: %s, h: %s', x, y, width, height) self.set_size_request(width, height) ###################################################################### # place togglebuttons around the current position in a radio group color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() button_width, button_height = self.BUTTON_SIZE cat_names = get_categories() radius = 300 # px x_center = width / 2 - 40 y_center = height / 2 - 40 step_angle = math.radians(360 / (len(cat_names) + 1)) # plus reset btn # add a reset button self.reset_selected_btn = RadioToolButton() img_name = os.path.join(GeoTag.ICONS_PATH, 'reset.svg') icon = gtk.image_new_from_pixbuf(utils.load_svg_image(img_name, color_stroke, color_fill, self.IMG_SIZE)) self.reset_selected_btn.set_icon_widget(icon) self.reset_selected_btn.set_tooltip(_('Reset selected tag.')) self.reset_selected_btn.connect('clicked', self.reset_toggled) self.reset_selected_btn.show_all() self.reset_selected_btn.set_size_request(button_width, button_height) self.fixed.put(self.reset_selected_btn, x_center, # + int(radius * math.sin(i * step_angle)), y_center + radius) # + int(radius * math.cos(i * step_angle))) self.reset_selected_btn.set_active(False) # read all available categories dynamically for i, category in enumerate(cat_names): button = RadioToolButton(group=self.reset_selected_btn) img_name = os.path.join(GeoTag.ICONS_PATH, category) icon = get_gtkimage_from_plugin(img_name, color_stroke, color_fill, self.IMG_SIZE) button.set_icon_widget(icon) button.set_tooltip(_('Tag some %s.' % category)) # XXX check translation here!! button.connect('clicked', self.set_toggled, category) button.show_all() button.set_size_request(button_width, button_height) self.fixed.put(button, x_center + int(radius * math.sin((i + 1) * step_angle)), y_center + int(radius * math.cos((i + 1) * step_angle))) button.set_active(False) img_name = os.path.join(GeoTag.ICONS_PATH, NONE_CATEGORY) self._set_selected(get_gtkimage_from_plugin(img_name, color_stroke,color_fill, self.IMG_SIZE)) ################################################################### self._logger.debug("size_allocation done") self.disconnect(self.size_cb) ## use only once
class TagStar(gtk.HBox): """ A L{gtk.HBox} which arranges togglebuttons around the current position within a L{gtk.Fixed} widget. This is the central tag element, where a user can either tag his current position with a category specified in L{geotagplugin.ECategory}. If one of the user's already tagged features is selected in the tree, the made change action will be handled as an edit. """ IMG_SIZE = (100, 100) BUTTON_SIZE = (100, 100) EMPTY_LIST_STORE = gtk.ListStore(gobject.TYPE_STRING) toggled = NONE_CATEGORY # selected category selected = None # gtk.Image displaying selected category def __init__(self, toolbar, control): gtk.HBox.__init__(self) self._logger = logging.getLogger('TagStar') self._logger.setLevel(constants.LOG_LEVEL) self.toolbar = toolbar self.control = control self.size_cb = self.connect('size_allocate', self.size_allocate_cb) self.fixed = gtk.Fixed() self.pack_start(self.fixed) self.show_all() def size_allocate_cb(self, widget, event): """ Builds the tag star around the center where the selected category is shown. """ self._logger.debug('size_allocate_cb()') x, y, width, height = self.fixed.get_allocation() self._logger.debug('x: %s, y: %s, w: %s, h: %s', x, y, width, height) self.set_size_request(width, height) ###################################################################### # place togglebuttons around the current position in a radio group color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() button_width, button_height = self.BUTTON_SIZE cat_names = get_categories() radius = 300 # px x_center = width / 2 - 40 y_center = height / 2 - 40 step_angle = math.radians(360 / (len(cat_names) + 1)) # plus reset btn # add a reset button self.reset_selected_btn = RadioToolButton() img_name = os.path.join(GeoTag.ICONS_PATH, 'reset.svg') icon = gtk.image_new_from_pixbuf(utils.load_svg_image(img_name, color_stroke, color_fill, self.IMG_SIZE)) self.reset_selected_btn.set_icon_widget(icon) self.reset_selected_btn.set_tooltip(_('Reset selected tag.')) self.reset_selected_btn.connect('clicked', self.reset_toggled) self.reset_selected_btn.show_all() self.reset_selected_btn.set_size_request(button_width, button_height) self.fixed.put(self.reset_selected_btn, x_center, # + int(radius * math.sin(i * step_angle)), y_center + radius) # + int(radius * math.cos(i * step_angle))) self.reset_selected_btn.set_active(False) # read all available categories dynamically for i, category in enumerate(cat_names): button = RadioToolButton(group=self.reset_selected_btn) img_name = os.path.join(GeoTag.ICONS_PATH, category) icon = get_gtkimage_from_plugin(img_name, color_stroke, color_fill, self.IMG_SIZE) button.set_icon_widget(icon) button.set_tooltip(_('Tag some %s.' % category)) # XXX check translation here!! button.connect('clicked', self.set_toggled, category) button.show_all() button.set_size_request(button_width, button_height) self.fixed.put(button, x_center + int(radius * math.sin((i + 1) * step_angle)), y_center + int(radius * math.cos((i + 1) * step_angle))) button.set_active(False) img_name = os.path.join(GeoTag.ICONS_PATH, NONE_CATEGORY) self._set_selected(get_gtkimage_from_plugin(img_name, color_stroke,color_fill, self.IMG_SIZE)) ################################################################### self._logger.debug("size_allocation done") self.disconnect(self.size_cb) ## use only once def reset_toggled(self, button): """ Resets toggled property and combobox liststore. @param button: The reset button (can be omitted by passing None). @note: If a tag was selected within the L{geotagmodel.GeotagModel}, the tag will be deleted. """ self.toggled = NONE_CATEGORY # reset liststore combo = self.toolbar.combobox combo.set_model(self.EMPTY_LIST_STORE) # reset selected widget color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() self._set_selected(get_gtkimage_from_plugin(NONE_CATEGORY, color_stroke, color_fill, self.IMG_SIZE)) self.reset_selected_btn.set_active(True) self.selected.queue_draw() combo.queue_draw() def set_toggled(self, button, category): """ Switches the empty Button and the tagged category button clicked. Also, sets the appropriate liststore for the combobox. @param button: Toggled button (can be omittted). @param category: The corresponding category to set. """ self._logger.debug("set_toggled()") self.toggled = category # set liststore combo = self.toolbar.combobox combo.set_model(self.toolbar.description_sets[category]) color_fill = profile.get_color().get_fill_color() color_stroke = profile.get_color().get_stroke_color() # self._logger.debug("storage type: %s", self.selected.get_property("storage-type")) self._set_selected(get_gtkimage_from_plugin(category, color_stroke, color_fill, self.IMG_SIZE)) combo.queue_draw() def _set_selected(self, widget): """ Sets the widget as the currently selected tag category. @param widget: The L{gtk.Image} to set. """ x, y, width, height = self.fixed.get_allocation() x_center = width / 2 - 40 y_center = height / 2 - 40 if self.selected: self.selected.clear() button_width, button_height = self.BUTTON_SIZE widget.set_size_request(button_width, button_height) widget.show_all() self.selected = widget self.selected.queue_draw() self.fixed.put(self.selected, x_center, y_center)