def __init__(self, name, description=''): # Contains the info about the level and the image self.container = Gtk.Grid() self.container.set_hexpand(True) self.container.props.margin = 20 # Info about the different settings self.title = Gtk.Label(_(name)) self.title.get_style_context().add_class('menu_intro_label') self.title.set_alignment(xalign=0, yalign=0) self.title.props.margin_top = 10 self.description = Gtk.Label(description) self.description.get_style_context().add_class('menu_custom_label') self.description.set_ellipsize(Pango.EllipsizeMode.END) self.description.set_size_request(130, 10) self.description.set_alignment(xalign=0, yalign=0) self.description.props.margin_bottom = 8 self.button = Gtk.Button() self.button.set_can_focus(False) cursor.attach_cursor_events(self.button) self.img = Gtk.Image() self.img.set_from_file(common.media + "/Icons/Icon-" + name + ".png") self.container.attach(self.title, 2, 0, 1, 1) self.container.attach(self.description, 2, 1, 1, 1) self.container.attach(self.img, 0, 0, 2, 2) self.container.set_row_spacing(2) self.container.set_column_spacing(20) self.container.props.valign = Gtk.Align.CENTER self.button.add(self.container)
def _create_button(self, identifier): '''Create a button with the styling needed for this widget. We can either pass the dictionary for the whole item, or feed in the individual arguments ''' button = Gtk.Button() button.set_size_request(self.item_width, self.item_height) path = self._parser.get_inactive_category_icon(identifier) icon = Gtk.Image.new_from_file(path) button.add(icon) attach_cursor_events(button) button.get_style_context().add_class('category_item') button.connect('clicked', self._select_button_wrapper, identifier) # Replace the grey icon with an orange on when the pointer # hovers over the button button.connect('enter-notify-event', self._add_selected_appearence_wrapper, identifier) button.connect('leave-notify-event', self._remove_selected_appearence_wrapper, identifier) return button
def __init__(self, app, window, apps_obj): Gtk.EventBox.__init__(self) self.props.valign = Gtk.Align.START self._apps = apps_obj self._app = app self._cmd = app['launch_command'] self._window = window self._entry = entry = Gtk.HBox() self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(app['colour'])) self._icon = get_app_icon(app['icon']) self._icon.props.margin = 21 entry.pack_start(self._icon, False, False, 0) texts = Gtk.VBox() # Initialise the app title label self._app_name = app_name = Gtk.Label("", halign=Gtk.Align.START, valign=Gtk.Align.CENTER, hexpand=True) app_name.get_style_context().add_class('app_name') app_name.props.margin_top = 28 texts.pack_start(app_name, False, False, 0) self._set_title(app) # Initialise the app desc label self._app_desc = app_desc = Gtk.Label("", halign=Gtk.Align.START, valign=Gtk.Align.START, hexpand=True) app_desc.get_style_context().add_class('app_desc') app_desc.props.margin_bottom = 25 texts.pack_start(app_desc, False, False, 0) self._set_tagline(app) entry.pack_start(texts, True, True, 0) self._update_btn = None if "_update" in self._app and self._app["_update"] is True: self._setup_update_button() self._more_btn = None if "description" in self._app: self._setup_desc_button() self._remove_btn = None if "removable" in self._app and self._app["removable"] is True: self._setup_remove_button() self._setup_desktop_button() self.add(entry) attach_cursor_events(self) self.connect("button-press-event", self._entry_click_cb)
def __init__(self, num_of_pages=3, selected_page=1, back_text=_("BACK"), next_text=_("NEXT")): Gtk.Alignment.__init__(self, xalign=0.5, xscale=0) self.num_of_pages = num_of_pages self.selected = selected_page self._box = Gtk.Box() self.add(self._box) # The back button has subtly different styling to the next button # When the back button is disabled, it goes invisible, while # the NEXT button goes grey. self._back_button = OrangeButton(back_text) self._back_button.connect('clicked', self.back_button_clicked) attach_cursor_events(self._back_button) self._next_button = OrangeButton(next_text) self._next_button.connect('clicked', self.next_button_clicked) attach_cursor_events(self._next_button) self.dot_box = Gtk.Box() self._create_progress_dots(self.selected) self._box.pack_start(self._back_button, False, False, 40) self._box.pack_start(self.dot_box, False, False, 0) self._box.pack_start(self._next_button, False, False, 40) if self.selected == 1: self._back_button.set_sensitive(False) if self.selected == self.num_of_pages: self._next_button.set_sensitive(False)
def __init__(self): Gtk.EventBox.__init__(self) self.get_style_context().add_class("drag_source") self.width = Gdk.Screen.width() / 2 self.height = Gdk.Screen.height() / 2 self.set_size_request(self.width, self.height) img_filename = os.path.join(MEDIA_DIR, "judoka-pointing.png") self.image = Gtk.Image.new_from_file(img_filename) self.eventbox = Gtk.EventBox() self.eventbox.add(self.image) attach_cursor_events(self.eventbox) self.bg_image = Gtk.Image() drag_bg_filename = os.path.join(MEDIA_DIR, "judoka-dragged-BG.png") self.bg_image.set_from_file(drag_bg_filename) self.label1 = Gtk.Label("I can show colors too - 16.7 million of them!") self.label1.get_style_context().add_class("drag_source_label") self.instruction = Gtk.Label("Click, hold, and drag me to the color.") self.instruction.get_style_context().add_class("drag_source_label_bold") # Mimic dimensions of the image so when the image is hidden, # event box does not change size self.eventbox.set_size_request(291, 350) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) box.pack_start(self.eventbox, False, False, 0) box.pack_start(self.label1, False, False, 0) box.pack_start(self.instruction, False, False, 0) self.align = Gtk.Alignment(xscale=0, yscale=0, xalign=0.5, yalign=0.5) self.align.add(box) self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.box.pack_start(self.align, True, True, 0) self.add(self.box) self.eventbox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.ASK) # To send image data self.eventbox.drag_source_add_image_targets() # The pixbuf is to set the dragging icon that follows the mouse drag_icon_filename = os.path.join(MEDIA_DIR, "judoka-dragged.png") self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(drag_icon_filename) self.eventbox.connect("drag-begin", self.on_drag_begin) self.eventbox.connect("drag-data-get", self.on_drag_data_get) self.eventbox.connect("drag-failed", self.on_drag_fail) self.eventbox.connect("drag-end", self.on_drag_end) self.eventbox.connect("drag-data-delete", self.on_drag_delete)
def __init__(self, win_width, quests): Gtk.EventBox.__init__(self) self.get_style_context().add_class('menu_bar_container') self.height = 110 self.width = win_width self.set_size_request(self.width, self.height) self._quests = quests hbox = Gtk.Box() self.add(hbox) self.buttons = {} self.selected = None # Home button self.home_button = HomeButton() self.home_button.connect('clicked', self.emit_home_signal) self.home_button.connect('clicked', self.set_selected_wrapper, _("CHARACTER")) hbox.pack_start(self.home_button, False, False, 0) close_button = self._create_cross_button() hbox.pack_end(close_button, False, False, 0) close_button.connect('clicked', self.close_window) name_array = [ MenuBar.BADGES_STR, MenuBar.CHARACTER_STR ] # TODO: add MenuBar.QUESTS_STR to enable for name in name_array: button = MenuButton(_(name), self._quests) button.connect('clicked', self.emit_menu_signal, name) button.connect('clicked', self.set_selected_wrapper, name) hbox.pack_end(button, False, False, 0) # add to the self.buttons dictionary self.buttons[name] = {} self.buttons[name]['button'] = button if name == MenuBar.QUESTS_STR: # check the notification image button.check_for_notification() # HACKY: avoiding packing the label divider after the last element if name != MenuBar.CHARACTER_STR: label = self._create_divider_label() hbox.pack_end(label, False, False, 0) attach_cursor_events(button) # initialise with the CHARACTER button selected self.set_selected(self.CHARACTER_STR)
def _create_cross_button(self): # Close button cross_icon = get_ui_icon("cross") box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) close_button = Gtk.Button() close_button.add(box) box.add(cross_icon) close_button.get_style_context().add_class("close_button") close_button.connect("clicked", self.close_window) attach_cursor_events(close_button) return close_button
def _create_cross_button(self): # Close button cross_icon = get_ui_icon('cross') box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) close_button = Gtk.Button() close_button.add(box) box.add(cross_icon) close_button.get_style_context().add_class('close_button') close_button.connect('clicked', self.close_window) attach_cursor_events(close_button) return close_button
def __init__(self, title, description, is_plug=False, back_btn=False): self.back_button = None css_path = os.path.join(css_dir, "heading.css") apply_styling_to_screen(css_path) title_hbox = None if is_plug: title_hbox = Gtk.Box() close_button = Gtk.Button() close_button.set_image(set_from_name('cross')) close_button.get_style_context().add_class('back_button') close_button.connect('clicked', Gtk.main_quit) close_button.set_margin_top(15) attach_cursor_events(close_button) title_hbox.pack_end(close_button, True, True, 0) if back_btn: self.back_button = Gtk.Button() attach_cursor_events(self.back_button) self.back_button.get_style_context().add_class('back_button') # TODO: get better back icon self.back_button.set_image(set_from_name('dark_left_arrow')) self.back_button.set_margin_top(15) title_hbox.pack_start(self.back_button, True, False, 0) else: empty_button = Gtk.Button(" ") empty_button.get_style_context().add_class('transparent') title_hbox.pack_start(empty_button, True, True, 0) self.title = Gtk.Label(title) self.title.get_style_context().add_class('title') self.title.set_justify(Gtk.Justification.CENTER) self.container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10) if is_plug: title_hbox.pack_start(self.title, True, True, 0) self.container.pack_start(title_hbox, False, False, 0) else: self.container.pack_start(self.title, False, False, 0) if description != "": self.description = Gtk.Label(description) self.description.set_justify(Gtk.Justification.CENTER) self.description.set_line_wrap(True) self.description_style = self.description.get_style_context() self.description_style.add_class('description') self.container.pack_start(self.description, False, False, 0)
def __init__(self, win): Gtk.EventBox.__init__(self) self._win = win icon_filename = os.path.join(media_dir, "images/icons/edit.png") self.cog_widget_icon = Gtk.Image.new_from_file(icon_filename) launch_char_creator_btn = Gtk.Button() attach_cursor_events(launch_char_creator_btn) hbox = Gtk.Box() edit_label = Gtk.Label(_("Edit").upper()) edit_label.set_margin_right(7) hbox.pack_start(self.cog_widget_icon, False, False, 0) hbox.pack_end(edit_label, False, False, 0) launch_char_creator_btn.connect('clicked', self.go_to_edit_character_screen) launch_char_creator_btn.connect('enter-notify-event', self.set_orange_cog) launch_char_creator_btn.connect('leave-notify-event', self.set_grey_cog) launch_char_creator_btn.get_style_context().add_class('character_cog') launch_char_creator_btn.add(hbox) # Pack this part of the screen into the window self._char_creator = self._win.char_creator # Get picture of character creator and pack it into the window path = self._char_creator.get_image_path() if not os.path.exists(path): # Usually we wouldn't be in this state, but just in case from kano_profile.profile import recreate_char, block_and_sync logger.warn("Character assets not there, will sync and recreate") block_and_sync() recreate_char(block=True) image = Gtk.Image.new_from_file(path) self.fixed = Gtk.Fixed() self.fixed.put(image, 0, 0) self.fixed.put(launch_char_creator_btn, 30, 30) self._win.pack_in_main_content(self.fixed) self._pack_progress_bar() self._win.show_all()
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 include_screenshot(self): ''' This is the box containing the filename of the screenshot, and the option to display it or remove it ''' if not hasattr(self, "screenshot"): # We pack the buttons into an event box with styling # so that we can have a container with a border radius # without having ugly gaps between the buttons. self.screenshot = Gtk.EventBox() self.screenshot.get_style_context().add_class("kano_button") self.screenshot.get_style_context().add_class("blue_background") remove_screenshot = Gtk.Button() attach_cursor_events(remove_screenshot) remove_icon = Gtk.Image.new_from_file( "/usr/share/kano-feedback/media/icons/close.png") remove_screenshot.add(remove_icon) remove_screenshot.connect("button-release-event", self.remove_screenshot) remove_screenshot.get_style_context().add_class("blue_background") show_screenshot = Gtk.Button() attach_cursor_events(show_screenshot) show_icon = Gtk.Image() show_icon.set_from_file( "/usr/share/kano-feedback/media/icons/preview.png") show_screenshot.add(show_icon) show_screenshot.connect("button-release-event", self.show_screenshot) show_screenshot.get_style_context().add_class("blue_background") label = Gtk.Label(SCREENSHOT_NAME.upper()) label.set_padding(10, 0) box = Gtk.Box() box.pack_start(label, False, False, 0) box.pack_end(remove_screenshot, False, False, 0) box.pack_end(show_screenshot, False, False, 0) self.screenshot.add(box) self.screenshot_box.remove(self._screenshot_button) self.screenshot_box.remove(self._attach_button) self.screenshot_box.pack_start(self.screenshot, False, False, 0)
def __init__(self, badge_info): Gtk.Button.__init__(self) self.badge_info = badge_info self.title = badge_info["title"] self.unlocked_description = badge_info["desc_unlocked"] self.locked_description = badge_info["desc_locked"] background_color = badge_info['bg_color'] self.locked = not badge_info['achieved'] # This is the dimensions of the actual item self.width = 243 self.height = 194 # Dimensions of the image self.img_width = 230 self.img_height = 180 # Dimensions of the hover over label. self.label_height = 44 self.get_style_context().add_class("badge_item") self.background_color = Gdk.RGBA() self.background_color.parse('#' + background_color) self.locked_background_color = Gdk.RGBA() self.locked_background_color.parse('#e7e7e7') self.create_hover_box() self.set_size_request(self.width, self.height) self.connect("enter-notify-event", self.add_hover_style, self.hover_box) self.connect("leave-notify-event", self.remove_hover_style, self.hover_box) self.fixed = Gtk.Fixed() self.add(self.fixed) self.fixed.set_size_request(self.width, self.height) self.pack_image(self.badge_info) cursor.attach_cursor_events(self) self.change_locked_style()
def __init__(self, stage, bg_path, bg_x_align, bg_y_align, text, text_margin, back_cb, fwd_cb): super(SlideScreen, self).__init__() self._stage = stage bg = Gtk.Image.new_from_file(bg_path) align = Gtk.Alignment.new(bg_x_align, bg_y_align, 0, 0) align.add(bg) self.add(align) back = Gtk.Button() back_arr = stage.media_path('navigation-arrow-left.png') back.add(Gtk.Image.new_from_file(back_arr)) back.set_halign(Gtk.Align.CENTER) back.set_valign(Gtk.Align.CENTER) back.set_margin_left(25) back.connect('clicked', self._cb_wrapper, back_cb) attach_cursor_events(back) fwd = Gtk.Button() fwd_arr = stage.media_path('navigation-arrow-right.png') fwd.add(Gtk.Image.new_from_file(fwd_arr)) fwd.set_halign(Gtk.Align.CENTER) fwd.set_valign(Gtk.Align.CENTER) fwd.set_margin_right(25) fwd.connect('clicked', self._cb_wrapper, fwd_cb) attach_cursor_events(fwd) help_text = Gtk.Label(text) add_class(help_text, 'console-screen-help-text') help_text.set_line_wrap(True) help_text.set_justify(Gtk.Justification.CENTER) help_text.set_valign(Gtk.Align.CENTER) help_text.set_halign(Gtk.Align.CENTER) help_text.set_margin_left(20) help_text.set_margin_right(20) help_text.set_margin_top(text_margin) hbox = Gtk.HBox(False, 0) hbox.pack_start(back, False, False, 0) hbox.pack_start(help_text, True, False, 0) hbox.pack_start(fwd, False, False, 0) self.add_overlay(hbox)
def __init__(self, win): img_path = os.path.join(MEDIA_DIR, "keyboard-click.gif") TutorialTemplate.__init__(self, img_path=img_path) self.win = win self.win.add(self) top = ButtonTemplate() top.set_content( img_path=os.path.join(MEDIA_DIR, "judoka-hanging.png"), label="But wait, I'm upside down! Click me to flip me over!", instruction="Left click the Judoka." ) top.connect("button-release-event", self.next) attach_cursor_events(top) self.box.pack_start(top, False, False, 0) self.win.show_all()
def __init__(self, badge_info): Gtk.Button.__init__(self) self.badge_info = badge_info self.title = badge_info['title'] self.unlocked_description = badge_info['desc_unlocked'] self.locked_description = badge_info['desc_locked'] background_color = badge_info['bg_color'] self.locked = not badge_info['achieved'] # This is the dimensions of the actual item self.width = 243 self.height = 194 # Dimensions of the image self.img_width = 230 self.img_height = 180 # Dimensions of the hover over label. self.label_height = 44 self.get_style_context().add_class('badge_item') self.background_color = unicodedata.normalize( 'NFKD', '#' + background_color ).encode('ascii', 'ignore') self.locked_background_color = '#e7e7e7' self.create_hover_box() self.set_size_request(self.width, self.height) self.connect('enter-notify-event', self.add_hover_style, self.hover_box) self.connect('leave-notify-event', self.remove_hover_style, self.hover_box) self.fixed = Gtk.Fixed() self.add(self.fixed) self.fixed.set_size_request(self.width, self.height) self.pack_image(self.badge_info) cursor.attach_cursor_events(self) self.change_locked_style()
def _create_button(self, obj_name): '''This places the image onto a Gtk.Fixed so we can overlay a padlock on top (if the item is locked) This is then put onto a Gtk.Button with the appropriate CSS class. Returns the button. Hopefully this can be simplified with new assets ''' # Create the container for the thumbnails fixed = Gtk.Fixed() path = self._parser.get_item_preview(obj_name) icon = Gtk.Image.new_from_file(path) # preview icon size (for all assets but the environment) is 41 by 41, # while the border is 42 by 42 fixed.put(icon, 1, 1) button = Gtk.Button() button.get_style_context().add_class('pop_up_menu_item') button.add(fixed) # only attach the event listeners if the asset is unlocked if self._parser.is_unlocked(obj_name): button.connect('clicked', self._on_clicking_item, obj_name) button.connect('enter-notify-event', self._add_hover_appearence_wrapper, obj_name) button.connect('leave-notify-event', self._remove_hover_appearence_wrapper, obj_name) attach_cursor_events(button) button.set_size_request(self.button_width, self.button_height) # set a margin all the way around it button.set_margin_right(3) button.set_margin_left(3) button.set_margin_bottom(3) button.set_margin_top(3) return button
def _create_refresh_button(self): '''Create the refresh button. This it quite involved as you have to pack an image into the button which need to change when the cursor hovers over it, and change the cursor to be a hand over it. ''' refresh_icon_filepath = os.path.join(img_dir, "refresh.png") refresh_icon = Gtk.Image.new_from_file(refresh_icon_filepath) refresh_btn = Gtk.Button() refresh_btn.get_style_context().add_class('refresh_btn') refresh_btn.set_image(refresh_icon) attach_cursor_events(refresh_btn) # These are here in case we want to change the icon on mouse over refresh_btn.connect('enter-notify-event', self._set_refresh_hover_icon) refresh_btn.connect('leave-notify-event', self._set_refresh_normal_icon) refresh_btn.connect('clicked', self._go_to_spinner_screen) return refresh_btn
def include_screenshot(self): ''' This is the box containing the filename of the screenshot, and the option to display it or remove it ''' if not hasattr(self, "screenshot"): # We pack the buttons into an event box with styling # so that we can have a container with a border radius # without having ugly gaps between the buttons. self.screenshot = Gtk.EventBox() self.screenshot.get_style_context().add_class("kano_button") self.screenshot.get_style_context().add_class("blue_background") remove_screenshot = Gtk.Button() attach_cursor_events(remove_screenshot) remove_icon = Gtk.Image.new_from_file("/usr/share/kano-feedback/media/icons/close.png") remove_screenshot.add(remove_icon) remove_screenshot.connect("button-release-event", self.remove_screenshot) remove_screenshot.get_style_context().add_class("blue_background") show_screenshot = Gtk.Button() attach_cursor_events(show_screenshot) show_icon = Gtk.Image() show_icon.set_from_file("/usr/share/kano-feedback/media/icons/preview.png") show_screenshot.add(show_icon) show_screenshot.connect("button-release-event", self.show_screenshot) show_screenshot.get_style_context().add_class("blue_background") label = Gtk.Label(SCREENSHOT_NAME.upper()) label.set_padding(10, 0) box = Gtk.Box() box.pack_start(label, False, False, 0) box.pack_end(remove_screenshot, False, False, 0) box.pack_end(show_screenshot, False, False, 0) self.screenshot.add(box) self.screenshot_box.remove(self._screenshot_button) self.screenshot_box.remove(self._attach_button) self.screenshot_box.pack_start(self.screenshot, False, False, 0)
def create_navigation_button(title, position='previous'): '''Position is either 'previous', 'middle' or 'end' This is to determine the position of the icon on the button. Returns a button widget with the title and the icon in the right place. ''' hbox = Gtk.Box() button = Gtk.Button() button.get_style_context().add_class('navigation_button') # If the button is at the end, the icon comes after the label if position == 'next': # next_icon_path is for forward pointing arrow next_icon_path = os.path.join(media_dir, "images/icons/next.png") icon = Gtk.Image.new_from_file(next_icon_path) button.get_style_context().add_class('next') label = Gtk.Label(title) hbox.pack_start(label, False, False, 0) hbox.pack_start(icon, False, False, 0) # Otherwise if the icon is at the middle or start, # the icon comes before the text else: if position == 'previous': # icon_path is for backwards pointing arrow icon_path = os.path.join(media_dir, "images/icons/previous.png") label = Gtk.Label(title) button.get_style_context().add_class('back') elif position == 'middle': # icon_path is for the grid icon icon_path = os.path.join(media_dir, "images/icons/grid.png") label = Gtk.Label(title) button.get_style_context().add_class('middle') icon = Gtk.Image.new_from_file(icon_path) hbox.pack_start(icon, False, False, 0) hbox.pack_start(label, False, False, 0) attach_cursor_events(button) button.add(hbox) return button
def __init__(self, text="", icon_filename=""): Gtk.Button.__init__(self) apply_colours_to_widget(self) self.internal_box = Gtk.Box(spacing=10) self.internal_box.props.halign = Gtk.Align.CENTER self.add(self.internal_box) if icon_filename: self.icon = Gtk.Image.new_from_file(icon_filename) self.internal_box.pack_start(self.icon, False, False, 0) self.label = Gtk.Label(text) self.internal_box.pack_start(self.label, False, False, 0) else: self.label = Gtk.Label(text) self.internal_box.add(self.label) cursor.attach_cursor_events(self)
def __init__(self, image, pixbuf, *hidden_elements): Gtk.EventBox.__init__(self) attach_cursor_events(self) self.image = image self.add(image) self.hidden_elements = hidden_elements # This follows the cursor when the item is being dragged self.pixbuf = pixbuf self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.ASK) # To send image data self.drag_source_add_image_targets() self.connect("drag-begin", self.on_drag_begin) self.connect("drag-data-get", self.on_drag_data_get) self.connect("drag-failed", self.on_drag_fail) self.connect("drag-end", self.on_drag_end) self.connect("drag-data-delete", self.on_drag_delete)
def __init__(self, text="", color="green", icon_filename=""): # Keep this updated - useful for set_color function self.available_colors = ["orange", "green", "red", "grey", "blue"] # Create button GenericButton.__init__(self, text, icon_filename) style_context = self.get_style_context() style_context.add_class("kano_button") style_context.add_class("kano_button_padding") style_context.add_class(color + "_background") self.align = None cursor.attach_cursor_events(self) self.add_spinner() widgets = [self, self.label] for w in widgets: apply_colours_to_widget(w) apply_styling_to_widget(w, self.BUTTON_CSS)
def __init__(self, project): self.background = Gtk.EventBox() self.background.get_style_context().add_class("white") self.button = Gtk.Button(_("Make").upper()) self.button.connect("clicked", self.load, project['app'], project['file'], project['data_dir']) self.button.get_style_context().add_class("project_make_button") cursor.attach_cursor_events(self.button) self.button_padding = Gtk.Alignment(xscale=1, yscale=1, xalign=0.5, yalign=0.5) self.button_padding.set_padding(25, 25, 10, 10) self.button_padding.add(self.button) # shorten project name to 20 characters long display_name = project["display_name"] if len(display_name) > 20: display_name = display_name[:20] + u'\N{HORIZONTAL ELLIPSIS}' self.title = Gtk.Label(display_name) self.title.get_style_context().add_class("project_item_title") self.title.set_alignment(xalign=0, yalign=1) self.label_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) self.label_container.pack_start(self.title, False, False, 0) self.label_align = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1, yscale=0) self.label_align.add(self.label_container) self.label_align.set_padding(0, 0, 10, 0) self.image = Gtk.Image() self.image.set_from_file(project["icon"]) self.container = Gtk.Box() self.container.pack_start(self.image, False, False, 0) self.container.pack_start(self.label_align, False, False, 0) self.container.pack_end(self.button_padding, False, False, 0) self.background.add(self.container)
def __init__(self): Gtk.Button.__init__(self) attach_cursor_events(self) self.get_style_context().add_class('home_button') # Get the username or kano world name # Get username here username = get_mixed_username() if len(username) > 12: username = username[:12] + u'\N{HORIZONTAL ELLIPSIS}' # Info about the different settings title_label = Gtk.Label(username, xalign=0) title_label.get_style_context().add_class('home_button_name') level, dummy, dummy = calculate_kano_level() level_label = Gtk.Label(_("Level {}").format(level), xalign=0) level_label.get_style_context().add_class('home_button_level') vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(title_label, False, False, 0) vbox.pack_start(level_label, False, False, 0) self.add(vbox)
def __init__(self): Gtk.Button.__init__(self) attach_cursor_events(self) self.get_style_context().add_class('home_button') # Get the username or kano world name # Get username here username = get_mixed_username() if len(username) > 12: username = username[:12] + u'\N{HORIZONTAL ELLIPSIS}' # Info about the different settings title_label = Gtk.Label(username, xalign=0) title_label.get_style_context().add_class("home_button_name") level, dummy, dummy = calculate_kano_level() level_label = Gtk.Label(_("Level {}").format(level), xalign=0) level_label.get_style_context().add_class("home_button_level") vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(title_label, False, False, 0) vbox.pack_start(level_label, False, False, 0) self.add(vbox)
def __init__(self, title, window_width=-1, has_buttons=True): Gtk.EventBox.__init__(self) self.has_buttons = has_buttons # Styling self.cssProvider = Gtk.CssProvider() top_bar_css = os.path.join(common_css_dir, 'top_bar.css') if not os.path.exists(top_bar_css): sys.exit('CSS file missing!') self.cssProvider.load_from_path(top_bar_css) styleContext = self.get_style_context() styleContext.add_provider(self.cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) self.set_size_request(window_width, TOP_BAR_HEIGHT) self.height = TOP_BAR_HEIGHT self.header = Gtk.Label(title, halign=Gtk.Align.CENTER) self.align_header = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0, yscale=0) self.align_header.add(self.header) self.cross = icons.set_from_name("cross") # Close button self.close_button = Gtk.Button() self.close_button.set_image(self.cross) self.close_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT) self.close_button.set_can_focus(False) self.add_style(self.close_button, "top_bar_button") # Container to mimic a button, so we can centre the header invisible = Gtk.Box() invisible.set_size_request(44, 44) # Main container holding everything self.box = Gtk.Box() if has_buttons: # Icons of the buttons self.pale_prev_arrow = icons.set_from_name("pale_left_arrow") self.pale_next_arrow = icons.set_from_name("pale_right_arrow") self.dark_prev_arrow = icons.set_from_name("dark_left_arrow") self.dark_next_arrow = icons.set_from_name("dark_right_arrow") # Prev Button self.prev_button = Gtk.Button() self.prev_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT) self.prev_button.set_can_focus(False) self.prev_button.set_image(self.pale_prev_arrow) # Next button self.next_button = Gtk.Button() self.next_button.set_size_request(TOP_BAR_HEIGHT, TOP_BAR_HEIGHT) self.next_button.set_can_focus(False) self.next_button.set_image(self.pale_next_arrow) self.box.pack_start(self.prev_button, False, False, 0) self.box.pack_start(self.next_button, False, False, 0) self.add_style(self.prev_button, "top_bar_button") self.add_style(self.next_button, "top_bar_button") # On start, disable the prev and next buttons self.disable_prev() self.disable_next() attach_cursor_events(self.prev_button) attach_cursor_events(self.next_button) attach_cursor_events(self.close_button) if has_buttons: self.box.pack_start(self.align_header, True, True, 0) self.box.pack_end(self.close_button, False, False, 0) self.box.pack_end(invisible, False, False, 0) else: self.box.pack_start(invisible, False, False, 0) self.box.pack_start(self.align_header, True, True, 0) self.box.pack_end(self.close_button, False, False, 0) self.box.set_size_request(window_width, 44) self.add(self.box) styleContext.add_class('top_bar_container') self.add_style(self.header, "top_bar_title")
def __init__(self, label=None, stock=None, use_underline=True): super(Button, self).__init__(label=label, stock=stock, use_underline=use_underline) attach_cursor_events(self)
def _create_network_box(self, network_list): '''Create the box containing the list of networks ''' # Setting up the box in which the network elements are to be positioned network_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) # Are these used anywhere? self._network_btns = [] network_connection = is_connected(self._wiface) # The network connection network_name = network_connection[0] connected = network_connection[3] image_path = os.path.join(img_dir, "padlock.png") # If the network list is empty, display a message to show it's not # broken if not len(network_list): no_networks_label = Gtk.Label(_("No networks detected!")) no_networks_label.get_style_context().add_class('no_networks_label') no_networks_label.set_margin_top(80) network_box.pack_start(no_networks_label, False, False, 0) return network_box # Otherwise, pack the networks into the scrolled window for network in network_list: # Network selection must be able to receive events network_btn = Gtk.Button() # Needs a box packed into it for the label and possibly # an icon box = Gtk.Box() network_btn.add(box) network_btn.get_style_context().add_class('network_btn') attach_cursor_events(network_btn) # Box must contain label of the network name label = Gtk.Label(network['essid']) box.pack_start(label, False, False, 0) # If the network name of the button matches the last attempted # connection, and we're connected to the internet, then # put a tick next to the name. # TODO: Since connected shows if you're connected to internet # you can be connected to ethernet and thus be shown to be # connected to the wrong network. if network['essid'] == network_name and \ connected: tick = tick_icon() box.pack_start(tick, False, False, 0) network_btn.connect( 'clicked', self._select_network, network, network_connection ) # Add padlock to the items that require a password if network['encryption'] != 'off': padlock_image = Gtk.Image.new_from_file(image_path) box.pack_end(padlock_image, False, False, 0) # Pack into the GUI for the networks network_box.pack_start(network_btn, False, False, 0) self._network_btns.append(network_btn) return network_box
def __init__(self, app, window, apps_obj): Gtk.EventBox.__init__(self) self.props.valign = Gtk.Align.START self._apps = apps_obj self._app = app self._cmd = app['launch_command'] self._window = window self._entry = entry = Gtk.HBox() self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(app['colour'])) self._icon = get_app_icon(app['icon']) self._icon.props.margin = 21 entry.pack_start(self._icon, False, False, 0) texts = Gtk.VBox() # Initialise the app title label self._app_name = app_name = Gtk.Label( "", halign=Gtk.Align.START, valign=Gtk.Align.CENTER, hexpand=True ) app_name.get_style_context().add_class('app_name') app_name.props.margin_top = 28 texts.pack_start(app_name, False, False, 0) self._set_title(app) # Initialise the app desc label self._app_desc = app_desc = Gtk.Label( "", halign=Gtk.Align.START, valign=Gtk.Align.START, hexpand=True ) app_desc.get_style_context().add_class('app_desc') app_desc.props.margin_bottom = 25 texts.pack_start(app_desc, False, False, 0) self._set_tagline(app) entry.pack_start(texts, True, True, 0) self._update_btn = None if "_update" in self._app and self._app["_update"] is True: self._setup_update_button() self._more_btn = None if "description" in self._app: self._setup_desc_button() self._remove_btn = None if "removable" in self._app and self._app["removable"] is True: self._setup_remove_button() self._setup_desktop_button() self.add(entry) attach_cursor_events(self) self.connect("button-press-event", self._entry_click_cb)
def add_widget(self, widget, p43, p169, clicked_cb=None, key=None, name=None, modal=False): placement = p43 if self._screen_ratio == self.RATIO_4_3 else p169 final_scale = placement.scale * self._scale_factor if final_scale != 1 and placement.scale != 0: if widget.__class__.__name__ == 'Image': if widget.get_animation(): widget = scale_gif(widget, final_scale) else: widget = scale_image(widget, final_scale) elif issubclass(widget.__class__, ActiveImage): widget.scale(final_scale) else: if placement.scale != 1.0: raise RuntimeError('Can\'t scale regular widgets!') if issubclass(widget.__class__, ActiveImage): root_widget = widget.get_widget() else: root_widget = widget if clicked_cb: # ActiveImage already comes in a button wrapper if not issubclass(widget.__class__, ActiveImage): button_wrapper = Gtk.Button() button_wrapper.add(root_widget) root_widget = button_wrapper attach_cursor_events(root_widget) if isinstance(clicked_cb, (list, tuple)): root_widget.connect('clicked', self._clicked_cb_wrapper, clicked_cb[0], *clicked_cb[1:]) else: root_widget.connect('clicked', self._clicked_cb_wrapper, clicked_cb) if key is not None: if not hasattr(self, '_keys'): msg = 'Scene must be initialised with main_window to ' + \ 'be able to receive key events.' raise RuntimeError(msg) cbs = {'action': clicked_cb} if issubclass(widget.__class__, ActiveImage): cbs['down'] = widget.down cbs['up'] = widget.up self._keys[key] = cbs align = Gtk.Alignment.new(placement.x, placement.y, 0, 0) align.add(root_widget) align.set_size_request(self._w, self._h) wrapper = align if modal: wrapper = Gtk.EventBox() add_class(wrapper, 'modal') wrapper.add(align) wrapper.show_all() self._fixed.put(wrapper, 0, 0) if name is not None: self._widgets[name] = wrapper
def _setup_fourth_scene(self): scene = Scene(self._ctl.main_window) scene.set_background(common_media_path('blueprint-bg-4-3.png'), common_media_path('blueprint-bg-16-9.png')) # Pass the callback of what we want to launch in the profile icon self._add_profile_icon(scene) self._add_world_icon(scene, offline=(not is_registered())) self._add_taskbar(scene) # Go through all the desktop icons and add them to the desktop # Either go through all files in a folder with a specific pattern, or # just list them in an array # All icons are in /usr/share/icons/Kano/88x88/apps # or /usr/share/kano-desktop/icons parent_dir = "/usr/share/kano-desktop/icons" parent_dir_2 = "/usr/share/icons/Kano/88x88/apps" self._apps_next_button_shown = False # Order the icons needed icon_info = [ ("snake", os.path.join(parent_dir, "snake.png")), ("pong", os.path.join(parent_dir, "pong.png")), ("minecraft", os.path.join(parent_dir, "make-minecraft.png")), ("music", os.path.join(parent_dir, "sonicpi.png")), ("internet", os.path.join(parent_dir, "internet-desktop.png")), ("apps", os.path.join(parent_dir, "apps.png")), ("home", os.path.join(parent_dir, "kano-homefolder.png")), ("art", os.path.join(parent_dir_2, "kano-draw.png")), ("terminal-quest", os.path.join(parent_dir_2, "linux-story.png")), ("scratch", os.path.join(parent_dir, "scratch.png")), ("video", os.path.join(parent_dir_2, "video.png")) #("plus", os.path.join(parent_dir, "plus-icon.png")) ] self._desktop_icons = { "snake": { "text": "Customize your own Snake game,\n" + "and share special gameboards.", "position": [0, 340], "source_align": 0.1 }, "pong": { "text": "You can make this classic game yourself,\n" + "with new rules, cheats, and powers.", "position": [0, 340], "source_align": 0.42 }, "minecraft": { "text": "Normal people play Minecraft.\n" + "On Kano, you can hack the game with code.", "position": [95, 340], "source_align": 0.5 }, "terminal-quest": { "text": "The Terminal talks to the computer's\n" + "brain directly. Use its powers to go on a quest.", "position": [0, 210], "source_align": 0.37 }, "music": { "text": "You can make sounds, beats, loops,\n" + "and songs on Kano.", "position": [290, 340], "source_align": 0.5 }, "art": { "text": "Ever drawn or painted?\n" + "You can create incredible artworks with code.", "position": [0, 210], "source_align": 0.07 }, "internet": { "text": "You can browse the web.", "position": [490, 360], "source_align": 0.5 }, "scratch": { "text": "You can play with code blocks.", "position": [167, 210], "source_align": 0.5 }, "home": { "text": "Look at your files and folders here.", "position": [550, 360], "source_align": 1.0 }, "apps": { "text": "Find even more apps here.", "position": [620, 360], "source_align": 0.5 }, "video": { "text": "YouTube", "position": [435, 250], "source_align": 0.5 } } fixed = Gtk.Fixed() fixed.set_size_request(1024, 720) scene.add_widget(fixed, Placement(0.5, 1.0, 0), Placement(0.5, 1.0, 0), name="icon_grid_fixed") icon_grid = Gtk.Grid() icon_grid.set_row_spacing(35) icon_grid.set_column_spacing(35) row = 1 column = 0 for info in icon_info: (name, f) = info icon = Gtk.Button() self._desktop_icons[name]['icon'] = Gtk.Image.new_from_file(f) self._desktop_icons[name]['bwicon'] = desaturate_image( Gtk.Image.new_from_file(f)) icon.set_image(self._desktop_icons[name]['bwicon']) attach_cursor_events(icon) icon.connect("clicked", self._change_apps_speechbubble_text, name, scene) icon_grid.attach(icon, column, row, 1, 1) column += 1 if column >= 7: column = 0 row -= 1 fixed.put(icon_grid, 40, 380) # Pack the speechbubble into a fixed so it the same distance from # apps for all resolutions. speechbubble_fixed = Gtk.Fixed() speechbubble_fixed.set_size_request(1024, 720) speechbubble_fixed.put( SpeechBubble(text='These are your Apps!\n' + 'You can make games, songs,\n' + 'artworks and more,\n' + 'then share them to World.', source=SpeechBubble.BOTTOM), 300, 100) scene.add_widget(speechbubble_fixed, Placement(0.5, 1), Placement(0.5, 1), name="app_speechbubble") return scene