コード例 #1
0
    def __init__(self, win, age):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
        self.win = win
        self.win.set_main_widget(self)

        self.page_control = self.win.create_page_control(3, _("Back").upper(),
                                                         _("Continue").upper())
        self.page_control.disable_next()
        self.pack_end(self.page_control, False, False, 0)
        self.page_control.connect("next-button-clicked", self.register_handler)
        self.page_control.connect("back-button-clicked", self.prev_page)

        title = Heading(_('Character creator'), _('Sign up with your email'))
        self.pack_start(title.container, False, False, 0)

        image_viewer = ImageView(self)
        self.pack_start(image_viewer, False, False, 0)

        # Get character image
        filename = os.path.join(AVATAR_DEFAULT_LOC, AVATAR_ENV_SHIFTED)
        image_viewer.set_image(filename)

        # Pass age into the Data screen - decide whether to ask for
        # Guardian's email
        self.data_screen = GetData3(age)
        self.data_screen.connect("widgets-filled", self.enable_next)
        self.data_screen.connect("widgets-empty", self.disable_next)

        # Put it with the same y coordinate as the menu
        image_viewer.put(self.data_screen, 400, 30)

        self.show_all()
コード例 #2
0
    def __init__(self, win):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
        self.win = win
        self.win.set_main_widget(self)

        self.page_control = self.win.create_page_control(2, _("Back").upper(),
                                                         _("Next").upper())
        self.page_control.next_button.set_sensitive(False)
        self.pack_end(self.page_control, False, False, 0)
        self.page_control.connect("next-button-clicked", self.next_page)
        self.page_control.connect("back-button-clicked", self.prev_page)

        title = Heading(
            _('Character creator'),
            _('Choose a cool name and secure password')
        )

        self.pack_start(title.container, False, False, 0)

        # This time we need the picture with the login screen to one side.
        image_viewer = ImageView(self)
        self.pack_start(image_viewer, False, False, 0)

        filename = os.path.join(AVATAR_DEFAULT_LOC, AVATAR_ENV_SHIFTED)
        image_viewer.set_image(filename)
        self.data_screen = GetData2()
        self.data_screen.connect("widgets-filled", self.enable_next)
        self.data_screen.connect("widgets-empty", self.disable_next)

        # Put it with the same y-coordinate as the menu
        image_viewer.put(self.data_screen, 400, 30)
        self.win.show_all()
コード例 #3
0
class CharacterCreator(Gtk.EventBox):
    configuration = get_avatar_conf()
    avatar_cr = AvatarCreator(configuration)
    meny_y_pos = 20

    __gsignals__ = {
        'character_changed': (GObject.SIGNAL_RUN_FIRST, None, ())
    }

    def __init__(self, randomise=False, no_sync=False):
        Gtk.EventBox.__init__(self)

        # This is the avatar specific styling
        css_path = os.path.join(media_dir, "CSS/avatar_generator.css")
        apply_styling_to_screen(css_path)

        self.fixed = Gtk.Fixed()
        self.add(self.fixed)

        # Check profile information and load up either the created avatar or
        # the default
        self._create_menu(no_sync=no_sync)
        self._create_img_box(self.get_image_path())

        # This needs to be called after _create_menu()
        self._get_obj_data()

        self.width = self._imgbox.width
        self.height = self._imgbox.height
        self.set_size_request(self.width, self.height)

        self.fixed.put(self._imgbox, 0, 0)
        self.fixed.put(self._menu, 20, self.meny_y_pos)

        if randomise:
            # Create random button
            self.randomise_button = self._create_random_button()
            self.fixed.put(self.randomise_button, 645, self.meny_y_pos)

        self.connect('button-press-event', self._hide_pop_ups)
        self._update_img(None, None)

    def select_category_button(self, identifier):
        self._menu.select_category_button(identifier)

    def show_pop_up_menu_for_category(self, category):
        self._menu.launch_pop_up_menu(None, category)

    def get_image_path(self):
        img_path = self.avatar_cr.get_default_final_image_path()
        return img_path

    def update_from_saved_image(self):
        self._imgbox.set_image(self.get_image_path())

    def get_avatar_save_path(self):
        return os.path.abspath(
            os.path.expanduser(
                os.path.join(AVATAR_DEFAULT_LOC, AVATAR_DEFAULT_NAME)))

    def _create_random_button(self):
        random_button = Gtk.Button()
        width = 40
        height = 40

        icon_path = os.path.join(media_dir, "images/icons/random.png")
        icon = Gtk.Image.new_from_file(icon_path)
        random_button.set_image(icon)
        random_button.get_style_context().add_class('random_button')
        random_button.set_size_request(width, height)
        random_button.connect('clicked', self._randomise_avatar_wrapper)
        random_button.connect('enter-notify-event',
                              self._set_random_orange_icon)
        random_button.connect('leave-notify-event', self._set_random_grey_icon)
        attach_cursor_events(random_button)

        return random_button

    def _set_random_orange_icon(self, random_btn, event):
        icon_path = os.path.join(media_dir, "images/icons/random-active.png")
        icon = Gtk.Image.new_from_file(icon_path)
        random_btn.set_image(icon)

    def _set_random_grey_icon(self, random_btn, event):
        icon_path = os.path.join(media_dir, "images/icons/random.png")
        icon = Gtk.Image.new_from_file(icon_path)
        random_btn.set_image(icon)

    def _randomise_avatar_wrapper(self, button):
        self.randomise_avatar()

    def randomise_avatar(self):
        selected_item_dict = self.avatar_cr.randomise_all_items()
        filepath = self.avatar_cr.create_avatar()
        self._imgbox.set_image(filepath)
        self._menu.select_pop_up_items(selected_item_dict)

        # Emit the character changed signal when the image is randomised
        self.emit('character_changed')

    def reset_selected_menu_items(self):
        self._menu.reset_selected_menu_items()

    def _hide_pop_ups(self, widget=None, event=None):
        self._menu.hide_pop_ups()
        self._menu.unselect_categories()

    def _create_menu(self, no_sync=False):
        self._menu = Menu(self.avatar_cr, no_sync=no_sync)
        self._menu.connect('asset_selected', self._update_img)
        self._menu.connect('randomise_all', self._randomise_avatar_wrapper)

    def _get_obj_data(self):
        self._list_of_categories = self.avatar_cr.list_available_categories()

    def _create_img_box(self, img_name):
        self._imgbox = ImageView(self)
        self._imgbox.set_image(img_name)

    def _update_img(self, widget, selected):
        list_of_objs = self._menu.get_all_selected_objs()
        rc = self.avatar_cr.obj_select(list_of_objs)
        if not rc:
            logger.error("Error processing the list {}".format(list_of_objs))
        else:
            displ_img = self.avatar_cr.create_avatar()
            self._imgbox.set_image(displ_img)

        # Emit the character changed signal when the image is updated
        self.emit('character_changed')

    def disable_buttons(self):
        self._menu.disable_all_buttons()
        self.randomise_button.set_sensitive(False)

    def enable_buttons(self):
        self._menu.enable_all_buttons()
        self.randomise_button.set_sensitive(True)

    # Public function so external buttons can access it.
    def save(self):
        '''When saving character, we save all the images in kano-profile
        and move the img filename to a place we can share it from.
        '''
        logger.debug("Saving data")

        # Disable the buttons so when the user is saving, they don't accidently
        # change the character as it's being saved.
        self.disable_buttons()

        self._menu.saved_selected_list = \
            self.avatar_cr.selected_items_per_cat()
        self._menu.saved_selected_list[self.avatar_cr.char_label] = \
            self.avatar_cr.selected_char()
        saved_path = self.get_avatar_save_path()
        self.avatar_cr.save_final_assets(saved_path)
        logger.debug("Saving generated avatar image to {}".format(saved_path))

        # Enable the buttons again so the user can change the character again.
        self.enable_buttons()
コード例 #4
0
 def _create_img_box(self, img_name):
     self._imgbox = ImageView(self)
     self._imgbox.set_image(img_name)
コード例 #5
0
class CharacterCreator(Gtk.EventBox):
    configuration = get_avatar_conf()
    avatar_cr = AvatarCreator(configuration)
    meny_y_pos = 20

    __gsignals__ = {'character_changed': (GObject.SIGNAL_RUN_FIRST, None, ())}

    def __init__(self, randomise=False, no_sync=False):
        Gtk.EventBox.__init__(self)

        # This is the avatar specific styling
        css_path = os.path.join(media_dir, "CSS/avatar_generator.css")
        apply_styling_to_screen(css_path)

        self.fixed = Gtk.Fixed()
        self.add(self.fixed)

        # Check profile information and load up either the created avatar or
        # the default
        self._create_menu(no_sync=no_sync)
        self._create_img_box(self.get_image_path())

        # This needs to be called after _create_menu()
        self._get_obj_data()

        self.width = self._imgbox.width
        self.height = self._imgbox.height
        self.set_size_request(self.width, self.height)

        self.fixed.put(self._imgbox, 0, 0)
        self.fixed.put(self._menu, 20, self.meny_y_pos)

        if randomise:
            # Create random button
            self.randomise_button = self._create_random_button()
            self.fixed.put(self.randomise_button, 645, self.meny_y_pos)

        self.connect('button-press-event', self._hide_pop_ups)
        self._update_img(None, None)

    def select_category_button(self, identifier):
        self._menu.select_category_button(identifier)

    def show_pop_up_menu_for_category(self, category):
        self._menu.launch_pop_up_menu(None, category)

    def get_image_path(self):
        img_path = self.avatar_cr.get_default_final_image_path()
        return img_path

    def update_from_saved_image(self):
        self._imgbox.set_image(self.get_image_path())

    def get_avatar_save_path(self):
        return os.path.abspath(
            os.path.expanduser(
                os.path.join(AVATAR_DEFAULT_LOC, AVATAR_DEFAULT_NAME)))

    def _create_random_button(self):
        random_button = Gtk.Button()
        width = 40
        height = 40

        icon_path = os.path.join(media_dir, "images/icons/random.png")
        icon = Gtk.Image.new_from_file(icon_path)
        random_button.set_image(icon)
        random_button.get_style_context().add_class('random_button')
        random_button.set_size_request(width, height)
        random_button.connect('clicked', self._randomise_avatar_wrapper)
        random_button.connect('enter-notify-event',
                              self._set_random_orange_icon)
        random_button.connect('leave-notify-event', self._set_random_grey_icon)
        attach_cursor_events(random_button)

        return random_button

    def _set_random_orange_icon(self, random_btn, event):
        icon_path = os.path.join(media_dir, "images/icons/random-active.png")
        icon = Gtk.Image.new_from_file(icon_path)
        random_btn.set_image(icon)

    def _set_random_grey_icon(self, random_btn, event):
        icon_path = os.path.join(media_dir, "images/icons/random.png")
        icon = Gtk.Image.new_from_file(icon_path)
        random_btn.set_image(icon)

    def _randomise_avatar_wrapper(self, button):
        self.randomise_avatar()

    def randomise_avatar(self):
        selected_item_dict = self.avatar_cr.randomise_all_items()
        filepath = self.avatar_cr.create_avatar()
        self._imgbox.set_image(filepath)
        self._menu.select_pop_up_items(selected_item_dict)

        # Emit the character changed signal when the image is randomised
        self.emit('character_changed')

    def reset_selected_menu_items(self):
        self._menu.reset_selected_menu_items()

    def _hide_pop_ups(self, widget=None, event=None):
        self._menu.hide_pop_ups()
        self._menu.unselect_categories()

    def _create_menu(self, no_sync=False):
        self._menu = Menu(self.avatar_cr, no_sync=no_sync)
        self._menu.connect('asset_selected', self._update_img)
        self._menu.connect('randomise_all', self._randomise_avatar_wrapper)

    def _get_obj_data(self):
        self._list_of_categories = self.avatar_cr.list_available_categories()

    def _create_img_box(self, img_name):
        self._imgbox = ImageView(self)
        self._imgbox.set_image(img_name)

    def _update_img(self, widget, selected):
        list_of_objs = self._menu.get_all_selected_objs()
        rc = self.avatar_cr.obj_select(list_of_objs)
        if not rc:
            logger.error("Error processing the list {}".format(list_of_objs))
        else:
            displ_img = self.avatar_cr.create_avatar()
            self._imgbox.set_image(displ_img)

        # Emit the character changed signal when the image is updated
        self.emit('character_changed')

    def disable_buttons(self):
        self._menu.disable_all_buttons()
        self.randomise_button.set_sensitive(False)

    def enable_buttons(self):
        self._menu.enable_all_buttons()
        self.randomise_button.set_sensitive(True)

    # Public function so external buttons can access it.
    def save(self):
        '''When saving character, we save all the images in kano-profile
        and move the img filename to a place we can share it from.
        '''
        logger.debug("Saving data")

        # Disable the buttons so when the user is saving, they don't accidently
        # change the character as it's being saved.
        self.disable_buttons()

        self._menu.saved_selected_list = \
            self.avatar_cr.selected_items_per_cat()
        self._menu.saved_selected_list[self.avatar_cr.char_label] = \
            self.avatar_cr.selected_char()
        saved_path = self.get_avatar_save_path()
        self.avatar_cr.save_final_assets(saved_path)
        logger.debug("Saving generated avatar image to {}".format(saved_path))

        # Enable the buttons again so the user can change the character again.
        self.enable_buttons()
コード例 #6
0
 def _create_img_box(self, img_name):
     self._imgbox = ImageView(self)
     self._imgbox.set_image(img_name)