def main (): global stage stage_color = clutter.Color(0, 0, 0, 255) # Black # Create the window and add some child widgets window = gtk.Window(gtk.WINDOW_TOPLEVEL) vbox = gtk.VBox(False, 6) window.add(vbox) vbox.show() button = gtk.Button("Change Color") vbox.pack_end(button, False, False, 0) button.show() button.connect('clicked', on_button_clicked) # Stop the application when the window is closed window.connect('hide', gtk.main_quit) # Create the clutter widget clutter_widget = cluttergtk.Embed() vbox.pack_start(clutter_widget, True, True, 0) clutter_widget.show() # Set the size of the widget, # because we should not set the size of its stage when using GtkClutterEmbed. clutter_widget.set_size_request(200, 200) # Get the stage and set its size and color stage = clutter_widget.get_stage() stage.set_color(stage_color) # Show the stage stage.show() # Connect a signal handler to handle mouse clicks and key presses on the stage stage.connect("button-press-event", on_stage_button_press) # Show the window window.show() # Start the main loop, so we can respond to events: gtk.main() return 0
def __init__(self, mieru, type, size): gtk_gui.GTKGUI.__init__(self, mieru, type, size) # get the Clutter embed and add it to the window self.embed = cluttergtk.Embed() self.vbox.pack_start(self.embed) self.vbox.show_all() # we need to realize the widget before we get the stage self.embed.realize() self.embed.show() self.embed.connect('key-press-event', self._onKeyPressEvent) # get the stage self.stage = self.embed.get_stage() self.stage.connect('allocation-changed', self._handleResize) self.stage.realize() self.stage.set_color("White") # activate clutter based buttons self.buttons = buttons.ClutterButtons(self.mieru, self) # create the manga layer self.mangaLayer = clutter.Group() # stick it under the button layer self.stage.add(self.mangaLayer) self.stage.lower_child(self.mangaLayer, self.buttons.getLayer()) # This packs the button into the window (a GTK container). self.embed.show() # setup page turning self._setupPageTurning() self.activePage = None # page preview self.previewBox = None self.previewBoxStartingPoint = (0, 0) # and show the window self.window.show_all()
def __init__(self): # GTK window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("Toon Player") self.window.connect("delete-event", self.destroy_app) self.window.connect("key-press-event", self.keypress) self.window.set_default_size(WIDTH, HEIGHT) # Vertical Box vbox = gtk.VBox(False) self.window.add(vbox) # The clutter embed self.embed = cluttergtk.Embed() stage = self.embed.get_stage() self.scene = Scene(stage) vbox.pack_start(self.embed, True, True) self.window.show_all() self.is_fullscreen = False
def __make_embed(self): self.embed = cluttergtk.Embed() self.embed.set_size_request(700, 700)
def __init__(self, image_library, music_library, video_library, quit_client_callback): self.quit_client_callback = quit_client_callback self.config = Configuration() # Store the dimensions in case users want to return to window mode self.old_width = self.config.stage_width self.old_height = self.config.stage_height self.logger = Logger().getLogger('client.gui.UserInterface') self.window = gtk.Window() self.window.connect('destroy', self.destroy_callback) self.window.set_title('Entertainer') # Set the window icon icon_theme = gtk.icon_theme_get_default() try: icon = icon_theme.load_icon('entertainer', 48, 0) self.window.set_icon(icon) except gobject.GError: # Must not be installed from a package, get icon from the branch file_dir = os.path.dirname(__file__) icon_path = os.path.join(file_dir, '..', '..', 'icons', 'hicolor', '48x48', 'apps', 'entertainer.png') icon = gtk.gdk.pixbuf_new_from_file(icon_path) self.window.set_icon(icon) # cluttergtk.Embed contains the stage that is the canvas for the GUI embed = cluttergtk.Embed() # Enforce a minimum size to prevent weird widget bugs embed.set_size_request( self.config.stage_width, self.config.stage_height) self.window.add(embed) # The embed widget must be realized before you can get the stage. embed.realize() self.stage = embed.get_stage() self._hide_cursor_timeout_key = None self.stage.connect('key-press-event', self.handle_keyboard_event) self.stage.connect('motion-event', self._handle_motion_event) self.stage.set_color(self.config.theme.get_color("background")) self.stage.set_size(self.config.stage_width, self.config.stage_height) self.stage.set_title("Entertainer") if self.config.start_in_fullscreen: self._fullscreen() self.is_fullscreen = True else: self.is_fullscreen = False # Initialize Screen history (allows user to navigate "back") self.history = ScreenHistory(self._remove_from_stage) self.player = MediaPlayer(self.stage, self.config.stage_width, self.config.stage_height) self.player.connect('volume-changed', self._on_volume_changed) # Initialize menu overlay texture self.is_overlay = False self.menu_overlay = MenuOverlay(self.config.theme) self.menu_overlay.set_opacity(0) self.menu_overlay.set_size( self.config.stage_width, self.config.stage_height) self.stage.add(self.menu_overlay) self.volume_indicator = VolumeIndicator() self.stage.add(self.volume_indicator) self.volume_indicator.connect('hiding', self._on_volume_indicator_hiding) self.fade_screen_timeline = clutter.Timeline(200) alpha = clutter.Alpha(self.fade_screen_timeline, clutter.EASE_IN_OUT_SINE) self.fade_screen_behaviour = clutter.BehaviourOpacity(255, 0, alpha) # Transition object. Handles effects between screen changes. transition_factory = TransitionFactory(self._remove_from_stage) self.transition = transition_factory.generate_transition() # Screen factory to create new screens self.screen_factory = ScreenFactory( image_library, music_library, video_library, self.player, self.move_to_new_screen, self.move_to_previous_screen) def default_key_to_user_event(): '''Return the default user event provided by an unmapped keyboard event.''' return UserEvent.DEFAULT_EVENT # Dictionary for keyboard event handling self.key_to_user_event = defaultdict(default_key_to_user_event, { clutter.keysyms.Return : UserEvent.NAVIGATE_SELECT, clutter.keysyms.Up : UserEvent.NAVIGATE_UP, clutter.keysyms.Down : UserEvent.NAVIGATE_DOWN, clutter.keysyms.Left : UserEvent.NAVIGATE_LEFT, clutter.keysyms.Right : UserEvent.NAVIGATE_RIGHT, clutter.keysyms.BackSpace : UserEvent.NAVIGATE_BACK, clutter.keysyms.h : UserEvent.NAVIGATE_HOME, clutter.keysyms.w : UserEvent.NAVIGATE_FIRST_PAGE, clutter.keysyms.e : UserEvent.NAVIGATE_PREVIOUS_PAGE, clutter.keysyms.r : UserEvent.NAVIGATE_NEXT_PAGE, clutter.keysyms.t : UserEvent.NAVIGATE_LAST_PAGE, clutter.keysyms.f : UserEvent.TOGGLE_FULLSCREEN, clutter.keysyms.p : UserEvent.PLAYER_PLAY_PAUSE, clutter.keysyms.s : UserEvent.PLAYER_STOP, clutter.keysyms._1 : UserEvent.USE_ASPECT_RATIO_1, clutter.keysyms._2 : UserEvent.USE_ASPECT_RATIO_2, clutter.keysyms._3 : UserEvent.USE_ASPECT_RATIO_3, clutter.keysyms._4 : UserEvent.USE_ASPECT_RATIO_4, clutter.keysyms.x : UserEvent.PLAYER_SKIP_BACKWARD, clutter.keysyms.c : UserEvent.PLAYER_SKIP_FORWARD, clutter.keysyms.z : UserEvent.PLAYER_PREVIOUS, clutter.keysyms.v : UserEvent.PLAYER_NEXT, clutter.keysyms.m : UserEvent.PLAYER_VOLUME_UP, clutter.keysyms.l : UserEvent.PLAYER_VOLUME_DOWN, clutter.keysyms.q : UserEvent.QUIT, clutter.keysyms.Escape : UserEvent.QUIT }) self.event_handlers = { UserEvent.DEFAULT_EVENT : self._handle_default, UserEvent.NAVIGATE_SELECT : self._handle_default, UserEvent.NAVIGATE_UP : self._handle_default, UserEvent.NAVIGATE_DOWN : self._handle_default, UserEvent.NAVIGATE_LEFT : self._handle_default, UserEvent.NAVIGATE_RIGHT : self._handle_default, UserEvent.NAVIGATE_BACK : self._handle_navigate_back, UserEvent.NAVIGATE_HOME : self._handle_navigate_home, UserEvent.NAVIGATE_FIRST_PAGE : self._handle_default, UserEvent.NAVIGATE_PREVIOUS_PAGE : self._handle_default, UserEvent.NAVIGATE_NEXT_PAGE : self._handle_default, UserEvent.NAVIGATE_LAST_PAGE : self._handle_default, UserEvent.TOGGLE_FULLSCREEN : self._handle_toggle_fullscreen, UserEvent.PLAYER_PLAY_PAUSE : self._handle_player_play_pause, UserEvent.PLAYER_STOP : self._handle_player_stop, UserEvent.USE_ASPECT_RATIO_1 : self._handle_aspect_ratio, UserEvent.USE_ASPECT_RATIO_2 : self._handle_aspect_ratio, UserEvent.USE_ASPECT_RATIO_3 : self._handle_aspect_ratio, UserEvent.USE_ASPECT_RATIO_4 : self._handle_aspect_ratio, UserEvent.PLAYER_SKIP_BACKWARD : self._handle_player_skip_backward, UserEvent.PLAYER_SKIP_FORWARD : self._handle_player_skip_forward, UserEvent.PLAYER_PREVIOUS : self._handle_player_previous, UserEvent.PLAYER_NEXT : self._handle_player_next, UserEvent.PLAYER_VOLUME_UP : self._handle_player_volume_up, UserEvent.PLAYER_VOLUME_DOWN : self._handle_player_volume_down, UserEvent.QUIT : self._handle_quit_client } self.logger.debug("Frontend GUI initialized succesfully")
def __init__(self): if len(sys.argv) != 2: #TODO: move to ... or remove raise SystemExit("Usage: python main.py <image file>") # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete-event", self.delete_event) self.window.connect("destroy", self.destroy) # Sets the border width of the window. self.window.set_title('BNF Viewer') self.window.set_border_width(10) #self.window.set_size_request(200,100) self.window.set_default_size(640, 400) self.vbox = gtk.VBox() #False, 0 #self.box1.pack_start(self.button1, True, True, 0) self.toolbar = gtk.Toolbar() self.toolbar.set_style(gtk.TOOLBAR_TEXT) self.toolbar.append_item('Rules', 'Show Rules', 'private text', None, self.on_button_clicked) self.toolbar.append_space() self.vbox.add(self.toolbar) self.table = gtk.Table(2, 2, False) self.clutter_widget = cluttergtk.Embed() self.clutter_widget.set_size_request(200, 200) self.table.attach(self.clutter_widget, 0, 1, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0) self.vbox.add( self.table) # pack_end(self.clutter_widget, True, True, 0) self.stage_color = clutter.Color(0, 0, 0, 255) # Black self.actor_color = clutter.Color(255, 255, 255, 153) self.stage = self.clutter_widget.get_stage() self.stage.set_color(self.stage_color) self.stage.set_size(640, 480) # Create a viewport actor to be able to scroll actor. By passing NULL it # will create new GtkAdjustments self.viewport = cluttergtk.Viewport() self.stage.add(self.viewport) self.viewport.set_size(640, 480) # Load image from first command line argument and add it to viewport self.texture = clutter.Texture(sys.argv[1]) self.viewport_group = clutter.Group() self.viewport_group.add(self.texture) self.viewport.add(self.viewport_group) self.texture.set_position(0, 0) # Create scrollbars and connect them to viewport self.h_adjustment, self.v_adjustment = self.viewport.get_adjustments() self.scrollbar = gtk.VScrollbar(self.v_adjustment) self.table.attach(self.scrollbar, 1, 2, 0, 1, 0, gtk.EXPAND | gtk.FILL, 0, 0) self.scrollbar = gtk.HScrollbar(self.h_adjustment) self.table.attach(self.scrollbar, 0, 1, 1, 2, gtk.EXPAND | gtk.FILL, 0, 0, 0) # Connect a signal handler to handle mouse clicks and key presses on the stage self.stage.connect("button-press-event", self.on_stage_button_pressed) # Add a group to the stage self.group = clutter.Group() self.group.set_position(40, 40) self.viewport_group.add(self.group) # Add a rectangle to the stage self.rect = clutter.Rectangle(self.actor_color) self.rect.set_size(100, 400) self.rect.set_position(20, 20) self.group.add(self.rect) #self.rect.show() # Add a label to the stage self.label = clutter.Text("Sans 12", "Some Text", self.actor_color) self.label.set_size(500, 500) self.label.set_position(20, 15) self.group.add(self.label) #label.show() # This packs the button into the window (which is a container). self.window.add(self.vbox) # Show the window and the button self.window.show_all()
def on_contextmenu_tag_location(self, widget, plugin_api): wTree = gtk.glade.XML(self.glade_file, "TagLocation") dialog = wTree.get_widget("TagLocation") plugin_api.set_parent_window(dialog) btn_zoom_in = wTree.get_widget("btn_zoom_in") btn_zoom_out = wTree.get_widget("btn_zoom_out") vbox_map = wTree.get_widget("vbox_map") tag = plugin_api.get_tagpopup_tag() dialog.set_title(tag.get_attribute("name") + "'s Location") # get the tag's location try: tag_location = eval(tag.get_attribute("location")) except: tag_location = None # get the tag's color try: tag_color = self.HTMLColorToRGB(tag.get_attribute("color")) except: tag_color = None champlain_view = champlain.View() champlain_view.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC) layer = MarkerLayer() marker_tag = None if tag_location: marker_tag = layer.add_marker(tag.get_attribute("name"), tag_location[0], tag_location[1], tag_color) else: try: if self.location['longitude'] and self.location['latitude']: marker_tag = layer.add_marker(tag.get_attribute("name"), self.location['latitude'], self.location['longitude'], tag_color) except: marker_tag = layer.add_marker(tag.get_attribute("name"), None, None) champlain_view.add_layer(layer) embed = cluttergtk.Embed() embed.set_size_request(400, 300) champlain_view.set_reactive(True) champlain_view.connect("button-release-event", self.champlain__tag_change_marker, champlain_view, marker_tag) layer.show_all() if tag_location: champlain_view.set_property("zoom-level", 9) elif self.location: champlain_view.set_property("zoom-level", 5) else: champlain_view.set_property("zoom-level", 1) vbox_map.add(embed) embed.realize() stage = embed.get_stage() champlain_view.set_size(400, 300) stage.add(champlain_view) # connect the toolbar buttons for zoom btn_zoom_in.connect("clicked", self.zoom_in, champlain_view) btn_zoom_out.connect("clicked", self.zoom_out, champlain_view) dialog.connect("response", self.tag_location_close, tag, marker_tag) dialog.show_all() if tag_location: champlain_view.center_on(marker_tag.get_property('latitude'), marker_tag.get_property('longitude')) else: try: if self.location['longitude'] and self.location['latitude']: champlain_view.center_on(self.location['latitude'], self.location['longitude']) except: pass
def set_task_location(self, widget, plugin_api, location=None): wTree = gtk.glade.XML(self.glade_file, "SetTaskLocation") dialog = wTree.get_widget("SetTaskLocation") plugin_api.set_parent_window(dialog) btn_zoom_in = wTree.get_widget("btn_zoom_in") btn_zoom_out = wTree.get_widget("btn_zoom_out") dialog_action_area_btn = wTree.get_widget("dialog_action_area_btn") btn_ok = wTree.get_widget("btn_ok") btn_cancel = wTree.get_widget("btn_cancel") btn_close = wTree.get_widget("btn_close") self.radiobutton1 = wTree.get_widget("radiobutton1") self.radiobutton2 = wTree.get_widget("radiobutton2") self.txt_new_tag = wTree.get_widget("txt_new_tag") self.cmb_existing_tag = wTree.get_widget("cmb_existing_tag") tabela = wTree.get_widget("tabela_set_task") vbox_map = wTree.get_widget("vbox_map") vbox_opt = wTree.get_widget("vbox_opt") champlain_view = champlain.View() champlain_view.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC) # champlain_view.set_property("zoom-on-double-click", False) # create a list of the tags and their attributes tag_list = [] for tag in plugin_api.get_tags(): tmp_tag = {} for attr in tag.get_all_attributes(): if attr == "color": color = self.HTMLColorToRGB(tag.get_attribute(attr)) tmp_tag[attr] = color tmp_tag['has_color'] = "yes" elif attr == "location": tmp_tag[attr] = eval(tag.get_attribute(attr)) else: tmp_tag[attr] = tag.get_attribute(attr) tag_list.append(tmp_tag) # checks if there is one tag with a location task_has_location = False for tag in tag_list: for key, item in tag.items(): if key == "location": task_has_location = True break # set the markers layer = MarkerLayer() self.marker_list = [] if task_has_location: for tag in tag_list: for key, item in tag.items(): if key == "location": color = None try: if tag['has_color'] == "yes": color = tag['color'] except: # PROBLEM: the tag doesn't have color # Possibility, use a color from another tag pass self.marker_list.append( layer.add_marker(plugin_api.get_task_title(), tag['location'][0], tag['location'][1], color)) else: try: if self.location['longitude'] and self.location['latitude']: self.marker_list.append( layer.add_marker(plugin_api.get_task_title(), self.location['latitude'], self.location['longitude'])) except: self.marker_list.append( layer.add_marker(plugin_api.get_task_title(), None, None)) champlain_view.add_layer(layer) embed = cluttergtk.Embed() embed.set_size_request(400, 300) if not task_has_location: # method that will change the marker's position champlain_view.set_reactive(True) champlain_view.connect("button-release-event", self.champlain_change_marker, champlain_view) layer.show_all() if task_has_location: champlain_view.set_property("zoom-level", 9) elif self.location: champlain_view.set_property("zoom-level", 5) else: champlain_view.set_property("zoom-level", 1) vbox_map.add(embed) embed.realize() stage = embed.get_stage() champlain_view.set_size(400, 300) stage.add(champlain_view) # connect the toolbar buttons for zoom btn_zoom_in.connect("clicked", self.zoom_in, champlain_view) btn_zoom_out.connect("clicked", self.zoom_out, champlain_view) if task_has_location: dialog_action_area_btn.remove(btn_ok) dialog_action_area_btn.remove(btn_cancel) dialog.connect("response", self.task_location_close) else: dialog_action_area_btn.remove(btn_close) # show a close button or the ok/cancel dialog.connect("response", self.set_task_location_close, plugin_api) # if there is no location set, we want to set it if not task_has_location: self.location_defined = False if len(plugin_api.get_tags()) > 0: liststore = gtk.ListStore(str) self.cmb_existing_tag.set_model(liststore) for tag in plugin_api.get_tags(): liststore.append([tag.get_attribute("name")]) self.cmb_existing_tag.set_text_column(0) self.cmb_existing_tag.set_active(0) else: # remove radiobutton2 and the comboboxentry tabela.remove(self.radiobutton1) tabela.remove(self.radiobutton2) tabela.remove(self.cmb_existing_tag) label = gtk.Label() label.set_text("Associate with new tag: ") tabela.attach(label, 0, 1, 0, 1) label.show() else: self.location_defined = True vbox_opt.remove(tabela) dialog.set_title("View the task's location") dialog.show_all() if task_has_location: champlain_view.center_on( self.marker_list[0].get_property('latitude'), self.marker_list[0].get_property('longitude')) else: try: if self.location['longitude'] and self.location['latitude']: champlain_view.center_on(self.location['latitude'], self.location['longitude']) except: pass