def __init__(self): super(ClockWidget, self).__init__() self.set_size_request(100, 100) aspect = Gtk.AspectFrame(label=None, xalign=0.5, yalign=0.5, ratio=1, vexpand=True) self.add(aspect) self.drawingarea = Gtk.DrawingArea() self.drawingarea.connect('draw', self._draw) aspect.add(self.drawingarea) # get local time and translate it to angles timeinfo = datetime.datetime.now().time() self.hours_hand = (timeinfo.hour % 12) * 5 self.minutes_hand = timeinfo.minute self.seconds_hand = timeinfo.second GLib.timeout_add( priority=GLib.PRIORITY_DEFAULT, interval=1000, function=self.tick, )
def create_emoji_results(self, emojis, for_category=False): self.current_emojis = emojis if len(emojis) > 0: self.target_emoji = self.get_skintone_char(emojis[0]) self.reset_emoji_preview() results_grid = Gtk.Grid( orientation=Gtk.Orientation.VERTICAL, margin=GRID_SIZE, margin_bottom=0, margin_top=GRID_SIZE if for_category else 0, ) results_grid.set_row_homogeneous(True) results_grid.set_column_homogeneous(True) row = 0 for emoji_row in grouper(emojis, EMOJIS_PER_ROW, None): row += 1 column = 0 for emoji in emoji_row: column += 1 if emoji is None: btn = Gtk.Button( label=" ", name="emoji_button", can_focus=False, relief=Gtk.ReliefStyle.NONE, sensitive=False, ) else: btn = Gtk.Button( label=self.get_skintone_char(emoji), name="emoji_button", relief=Gtk.ReliefStyle.NONE, ) btn.connect("event", self.on_emoji_btn_event) if row == 1 and column == 1: self.first_emoji_widget = btn btn.set_size_request(10, 10) btn_af = Gtk.AspectFrame(xalign=0.5, yalign=0.5, ratio=1.0, name="emoji_button_af") btn_af.add(btn) results_grid.attach(btn_af, column, row, 1, 1) return results_grid
def __init__(self, parent, target): super(HCYMaskTemplateDialog, self).__init__( title=C_( u"HCY Gamut Mask new-from-template dialog: window title", "New Gamut Mask from Template", ), transient_for=parent, modal=True, destroy_with_parent=True, window_position=Gtk.WindowPosition.MOUSE, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT), ) target_mgr = target.get_color_manager() prefs_ro = deepcopy(target_mgr.get_prefs()) datapath = target_mgr.get_data_path() mgr = ColorManager(prefs=prefs_ro, datapath=datapath) mgr.set_wheel_type(target_mgr.get_wheel_type()) self.target = target for name, desc, mask_shapes_float in self.__templates: mask = [] for mask_shape_float in mask_shapes_float: shape = [] for h, c, y in mask_shape_float: h = mgr.undistort_hue(h) shape.append(HCYColor(h, c, y)) mask.append(shape) label = Gtk.Label() label.set_markup("<b>%s</b>\n\n%s" % (name, desc)) label.set_size_request(375, -1) label.set_line_wrap(True) label.set_alignment(0, 0.5) preview = HCYMaskPreview() preview.set_color_manager(mgr) preview.set_mask(mask) preview_frame = Gtk.AspectFrame(obey_child=True) preview_frame.add(preview) preview_frame.set_shadow_type(Gtk.ShadowType.NONE) hbox = Gtk.HBox() hbox.set_spacing(6) hbox.pack_start(preview_frame, False, False, 0) hbox.pack_start(label, True, True, 0) button = Gtk.Button() button.add(hbox) button.set_relief(Gtk.ReliefStyle.NONE) button.connect("clicked", self.__button_clicked_cb, mask) self.vbox.pack_start(button, True, True, 0) self.connect("response", self.__response_cb) self.connect("show", self.__show_cb) for w in self.vbox: w.show_all() ref_color = target.get_managed_color() mgr.set_color(ref_color)
def __init__(self): super(HSVSquare, self).__init__() self._faces = ['h', 's', 'v'] self.__square = _HSVSquareInnerSquare(self) self.__ring = _HSVSquareOuterRing(self) s_align = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.54, yscale=0.54) plz_be_square = Gtk.AspectFrame() plz_be_square.set_shadow_type(Gtk.ShadowType.NONE) s_align.add(plz_be_square) plz_be_square.add(self.__square) self.__ring.add(s_align) self.pack_start(self.__ring, True, True, 0)
def __init__(self): Gtk.Window.__init__(self) self.set_title("AspectFrame") self.set_default_size(200, 200) self.set_border_width(5) self.connect("destroy", Gtk.main_quit) frame = Gtk.AspectFrame(label="AspectFrame", xalign=0.5, yalign=0.5, ratio=1, obey_child=False) self.add(frame) label = Gtk.Label("Label in an AspectFrame") frame.add(label)
def init_komadai_square(self, y, label, side, komgrid): hb = Gtk.HBox(False, 0) hb.show() event_box = self.keb[side][y] event_box.set_vexpand(True) event_box.set_hexpand(True) aspect_frame = Gtk.AspectFrame(label=None, xalign=0.5, yalign=0.5, ratio=1.0, obey_child=False) aspect_frame.set_shadow_type(Gtk.ShadowType.NONE) aspect_frame.add(event_box) event_box.connect("draw", self.draw_komadai_square, y, side) fontdesc = Pango.FontDescription("Monospace 15") label.modify_font(fontdesc) label.show() if side == WHITE: hb.pack_start(label, False, False, 0) hb.pack_start(aspect_frame, True, True, 0) komgrid.attach(hb, 0, y, 1, 1) event_box.set_name("wcap_eb") else: hb.pack_end(label, False, False, 0) hb.pack_end(aspect_frame, True, True, 0) komgrid.attach(hb, 0, y, 1, 1) event_box.set_name("bcap_eb") event_box.show() aspect_frame.show() #event_box.set_border_width(5) event_box.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) x = 0 data = (x, y, side) event_box.connect("button_press_event", gv.gshogi.cap_square_clicked, data) self.targets = [("text/plain", Gtk.TargetFlags.SAME_APP, TARGET_TYPE_TEXT)] event_box.connect("drag_data_get", self.drag_and_drop.sendCallback) event_box.connect_after("drag_begin", self.drag_and_drop.drag_begin, (x, y)) event_box.connect_after("drag_end", self.drag_and_drop.drag_end)
def draw_renderers(self, prog_list): # first of all delete all previous renderers self.remove_renderers() # add renderers to grid for stream in prog_list: stream_id = stream[0] for prog in stream[1]: prog_name = prog[1] prog_type = 0 prog_id = int(prog[0]) video_pid = None audio_pid = None for pid in prog[4]: if pid[2].split('-')[0] == 'video': video_pid = int(pid[0]) # FIXME: & VIDEO prog_type = prog_type | 0x01 elif pid[2].split('-')[0] == 'audio': audio_pid = int(pid[0]) # FIXME: & AUDIO prog_type = prog_type | 0x02 # create renderer renderer = Renderer(stream_id, prog_id, prog_name, prog_type, video_pid, audio_pid) self.rend_arr.append(renderer) # connect renderer to volume changed signal renderer.connect(CustomMessages.VOLUME_CHANGED, self.on_volume_changed) af = Gtk.AspectFrame(hexpand=True, vexpand=True) af.set(0.5, 0.5, 4.0 / 3.0, False) af.add(renderer) # insert renderer to flow box self.insert(af, -1) # set filter function self.set_filter_func((lambda x, y: True), None) # show all renderers self.show_all()
def get_page_widget(self): frame = Gtk.AspectFrame(obey_child=True) frame.set_shadow_type(Gtk.ShadowType.NONE) frame.add(self.__table) return frame
#!/usr/bin/env python from gi.repository import Gtk window = Gtk.Window() window.connect("destroy", lambda q: Gtk.main_quit()) aspectframe = Gtk.AspectFrame(label="Aspect Frame", xalign=0.5, yalign=0.5, ratio=1.0, obey_child=False) window.add(aspectframe) image = Gtk.Image() image.set_from_file("gtk.png") aspectframe.add(image) window.show_all() Gtk.main()
def _createUi(self): """ Creates the Viewer GUI """ # Drawing area # The aspect ratio gets overridden on startup by setDisplayAspectRatio self.aframe = Gtk.AspectFrame(xalign=0.5, yalign=1.0, ratio=4.0 / 3.0, obey_child=False) self.internal = ViewerWidget(self.app.settings) self.internal.init_transformation_events() self.internal.show() self.aframe.add(self.internal) self.pack_start(self.aframe, True, True, 0) self.external_window = Gtk.Window() vbox = Gtk.VBox() vbox.set_spacing(SPACING) self.external_window.add(vbox) self.external = ViewerWidget(self.app.settings) vbox.pack_start(self.external, True, True, 0) self.external_window.connect("delete-event", self._externalWindowDeleteCb) self.external_window.connect("configure-event", self._externalWindowConfigureCb) self.external_vbox = vbox self.external_vbox.show_all() # Buttons/Controls bbox = Gtk.HBox() boxalign = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) boxalign.add(bbox) self.pack_start(boxalign, False, True, 0) self.goToStart_button = Gtk.ToolButton(Gtk.STOCK_MEDIA_PREVIOUS) self.goToStart_button.connect("clicked", self._goToStartCb) self.goToStart_button.set_tooltip_text(_("Go to the beginning of the timeline")) self.goToStart_button.set_sensitive(False) bbox.pack_start(self.goToStart_button, False, True, 0) self.back_button = Gtk.ToolButton(Gtk.STOCK_MEDIA_REWIND) self.back_button.connect("clicked", self._backCb) self.back_button.set_tooltip_text(_("Go back one second")) self.back_button.set_sensitive(False) bbox.pack_start(self.back_button, False, True, 0) self.playpause_button = PlayPauseButton() self.playpause_button.connect("play", self._playButtonCb) bbox.pack_start(self.playpause_button, False, True, 0) self.playpause_button.set_sensitive(False) self.forward_button = Gtk.ToolButton(Gtk.STOCK_MEDIA_FORWARD) self.forward_button.connect("clicked", self._forwardCb) self.forward_button.set_tooltip_text(_("Go forward one second")) self.forward_button.set_sensitive(False) bbox.pack_start(self.forward_button, False, True, 0) self.goToEnd_button = Gtk.ToolButton(Gtk.STOCK_MEDIA_NEXT) self.goToEnd_button.connect("clicked", self._goToEndCb) self.goToEnd_button.set_tooltip_text(_("Go to the end of the timeline")) self.goToEnd_button.set_sensitive(False) bbox.pack_start(self.goToEnd_button, False, True, 0) # current time self.timecode_entry = TimeWidget() self.timecode_entry.setWidgetValue(0) self.timecode_entry.set_tooltip_text(_('Enter a timecode or frame number\nand press "Enter" to go to that position')) self.timecode_entry.connectActivateEvent(self._entryActivateCb) self.timecode_entry.connectFocusEvents(self._entryFocusInCb, self._entryFocusOutCb) bbox.pack_start(self.timecode_entry, False, 10, 0) self._haveUI = True # Identify widgets for AT-SPI, making our test suite easier to develop # These will show up in sniff, accerciser, etc. self.goToStart_button.get_accessible().set_name("goToStart_button") self.back_button.get_accessible().set_name("back_button") self.playpause_button.get_accessible().set_name("playpause_button") self.forward_button.get_accessible().set_name("forward_button") self.goToEnd_button.get_accessible().set_name("goToEnd_button") self.timecode_entry.get_accessible().set_name("timecode_entry") screen = Gdk.Screen.get_default() height = screen.get_height() if height >= 800: # show the controls and force the aspect frame to have at least the same # width (+110, which is a magic number to minimize dead padding). bbox.show_all() req = bbox.size_request() width = req.width height = req.height width += 110 height = int(width / self.aframe.props.ratio) self.aframe.set_size_request(width, height) self.show_all() self.buttons = bbox self.buttons_container = boxalign
def __init__(self, cabecera, poll, current_vote, view_answer, previewing): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self._poll = poll self.cabecera = Gtk.Label() self.cabecera.set_markup('<big><b>%s</b></big>' % _(cabecera)) self.pack_start(self.cabecera, False, False, 10) self.title = Gtk.Label(poll.title) self.title.set_alignment(0.01, 0.5) self.pack_start(self.title, False, False, 10) self.question = Gtk.Label(poll.question) self.question.set_alignment(0.01, 0.5) self.pack_start(self.question, False, False, 10) frame = Gtk.AspectFrame() tabla = Gtk.Table(rows=6, columns=6) tabla.set_border_width(20) frame.add(tabla) eventbox = Gtk.EventBox() eventbox.set_border_width(20) eventbox.modify_bg(0, Gdk.Color(65000, 65000, 65000)) eventbox.add(frame) scroll = Gtk.ScrolledWindow() scroll.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scroll.add_with_viewport(eventbox) self.pack_start(scroll, True, True, 10) group = Gtk.RadioButton() xo_color = profile.get_color() row = 0 for choice in range(poll.number_of_options): button = Gtk.RadioButton.new_with_label_from_widget( group, poll.options[choice]) button.connect('toggled', poll.activity.vote_choice_radio_button, choice) if poll.active: button.set_sensitive(True) else: button.set_sensitive(False) tabla.attach(button, 0, 1, row, row+1) if choice == current_vote: button.set_active(True) if not poll.images[int(choice)] == '': image = Gtk.Image() image.set_from_pixbuf(poll.images[choice]) tabla.attach(image, 1, 2, row, row + 1) if view_answer or not poll.active: if poll.vote_count > 0: ### Total de votos label = Gtk.Label(poll.data[choice]) label.set_size_request(100, -1) tabla.attach(label, 3, 4, row, row + 1) eventbox = Gtk.EventBox() eventbox.set_size_request(300, -1) tabla.attach(eventbox, 4, 5, row, row + 1) eventbox.connect("draw", self.__draw_bar, poll.data[choice], poll.vote_count, xo_color) row += 1 if view_answer or not poll.active: if poll.vote_count > 0: ### Barra para total separator = Gtk.HSeparator() tabla.attach(separator, 3, 5, row, row + 1) row += 1 if view_answer or not poll.active: if poll.vote_count > 0: label = Gtk.Label("%s %s %s %s" % (str(poll.vote_count), _('votes'), _('(votes left to collect)'), poll.maxvoters - poll.vote_count)) tabla.attach(label, 3, 5, row, row + 1) row += 1 # Button area if poll.active and not previewing: button = Gtk.Button(_("Vote")) button.connect('clicked', poll.activity.button_vote_cb) button.props.margin = 10 tabla.attach(button, 0, 1, row, row + 1) elif previewing: button = Gtk.Button(_("Edit Poll")) button.connect('clicked', poll.activity.button_edit_clicked) button.props.margin = 10 tabla.attach(button, 0, 1, row, row + 1) button = Gtk.Button(_("Save Poll")) button.connect('clicked', self._button_save_cb) button.props.margin = 10 tabla.attach(button, 1, 2, row, row + 1) self.show_all()
def __init__(self): self.xid = None self.current_position = 0 self.on_pause_and_slide_change_func = None self.overlay = None self.draw_area = Gtk.DrawingArea() self.draw_area.connect('size-allocate', self._get_size) self.draw_area.connect('realize', self.on_realize) self.event_box = Gtk.EventBox() self.event_box.add(self.draw_area) self.aspect_frame = Gtk.AspectFrame(label=None, xalign=0, yalign=0, ratio=1, obey_child=False) self.aspect_frame.add(self.event_box) self.aspect_frame.set_hexpand(False) self.aspect_frame.set_vexpand(False) self.scrolled_window = Gtk.ScrolledWindow() self.scrolled_window.add(self.aspect_frame) self.size = (100, 100) self.video_size = None self.fps = None self.signals = DrawSignals() self.pipeline = None self.bus = None self.duration = None self.player_paused = True self.is_player_active = False self.last_play_rate_state = 'normal' self.playback_button = Gtk.Button() self.play_image = self._set_button_image(self.playback_button, 'media-playback-start') self.pause_image = Gtk.Image.new_from_icon_name( 'media-playback-pause', Gtk.IconSize.MENU) self.stop_button = Gtk.Button() self._set_button_image(self.stop_button, 'media-playback-stop') self.next_frame_button = Gtk.Button() self._set_button_image(self.next_frame_button, 'media-skip-forward') self.previous_frame_button = Gtk.Button() self._set_button_image(self.previous_frame_button, 'media-skip-backward') self.normal_forward_button = Gtk.RadioButton.new_from_widget(None) self.normal_forward_button.set_label('x1') self.normal_forward_button.set_mode(False) self.fast_forward_button = Gtk.RadioButton.new_from_widget( self.normal_forward_button) self.fast_forward_button.set_label('x5') self.fast_forward_button.set_mode(False) self.slow_forward_button = Gtk.RadioButton.new_from_widget( self.normal_forward_button) self.slow_forward_button.set_label('x1/2') self.slow_forward_button.set_mode(False) self.zoom_spinner = Gtk.SpinButton() zoom_adjustment = Gtk.Adjustment(value=25, lower=10, upper=200, step_increment=5, page_increment=25, page_size=0) self.zoom_spinner.set_adjustment(zoom_adjustment) self.zoom_spinner.set_numeric(True) self.zoom_spinner.set_update_policy( Gtk.SpinButtonUpdatePolicy.IF_VALID) self.zoom_spinner.set_snap_to_ticks(True) self.frame_slider = Gtk.Scale() self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self._setup_controls()
def build_gui(self): self.gobactive = False self.engine_debug = engine_debug.get_ref() self.engine_output = engine_output.get_ref() self.move_list = move_list.get_ref() self.gamelist = gamelist.get_ref() self.set_board_colours = set_board_colours.get_ref() self.drag_and_drop = drag_and_drop.get_ref() self.enable_dnd = True self.load_save = load_save.get_ref() self.show_coords = True self.highlight_moves = True # Create Main Window glade_dir = gv.gshogi.get_glade_dir() self.glade_file = os.path.join(glade_dir, "main_window.glade") self.glade_file_preferences = os.path.join(glade_dir, "preferences.glade") self.builder = Gtk.Builder() self.builder.add_from_file(self.glade_file) self.builder.connect_signals(self) self.window = self.builder.get_object("main_window") screen = self.window.get_screen() self.screen_width = screen.get_width() self.screen_height = screen.get_height() self.set_window_size() # self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL) self.window.set_title(NAME + " " + VERSION) # 1 eventbox per board square self.eb = [[Gtk.EventBox() for x in range(9)] for x in range(9)] # 1 eventbox per komadai board square self.keb = [[Gtk.EventBox() for x in range(7)] for x in range(2)] # Set a handler for delete_event that immediately exits GTK. self.window.connect("delete_event", gv.gshogi.delete_event) main_vbox = self.builder.get_object("main_vbox") main_vbox.show() # menu # Create a UIManager instance uimanager = Gtk.UIManager() # Add the accelerator group to the toplevel window accelgroup = uimanager.get_accel_group() self.window.add_accel_group(accelgroup) # main action group actiongroup = Gtk.ActionGroup("UIManagerAG") self.actiongroup = actiongroup # action group for toggleactions ta_action_group = Gtk.ActionGroup("AGPromoteMode") ta_action_group.add_toggle_actions([ ("promotemode", None, "_Ask Before Promoting", None, None, self.promote_mode) ]) self.ta_action_group = ta_action_group # Create actions actiongroup.add_actions([ # NewGame and the handicap names are used in gshogi.py NewGame # routine. don't change them. ("NewGame", Gtk.STOCK_NEW, "_New Game", None, "New Game", gv.gshogi.new_game_cb), ("LanceHandicap", None, "_Lance", None, "Lance Handicap", gv.gshogi.new_game_cb), ("BishopHandicap", None, "_Bishop", None, "Bishop Handicap", gv.gshogi.new_game_cb), ("RookHandicap", None, "_Rook", None, "Rook Handicap", gv.gshogi.new_game_cb), ("RookandLanceHandicap", None, "_Rook and Lance", None, "Rook and Lance Handicap", gv.gshogi.new_game_cb), ("TwoPieceHandicap", None, "_2 Pieces", None, "Two Piece Handicap", gv.gshogi.new_game_cb), ("FourPieceHandicap", None, "_4 Pieces", None, "Four Piece Handicap", gv.gshogi.new_game_cb), ("SixPieceHandicap", None, "_6 Pieces", None, "Six Piece Handicap", gv.gshogi.new_game_cb), ("EightPieceHandicap", None, "_8 Pieces", None, "Eight Piece Handicap", gv.gshogi.new_game_cb), ("TenPieceHandicap", None, "_10 Pieces", None, "Ten Piece Handicap", gv.gshogi.new_game_cb), ("NewHandicapGame", None, "_New Handicap Game"), # ("Quit", Gtk.STOCK_QUIT, "_Quit", None, "Quit the Program", gv.gshogi.quit_game), ("LoadGame", Gtk.STOCK_OPEN, "_Load Game", None, "Load Game", self.load_save.load_game), ("SaveGame", Gtk.STOCK_SAVE, "_Save Game", None, "Save Game", self.load_save.save_game), ("File", None, "_File"), ("Edit", None, "_Edit"), ("Undo", Gtk.STOCK_UNDO, "_Undo Move", "<Control>U", "Undo Move", gv.gshogi.undo_single_move), ("Redo", Gtk.STOCK_REDO, "_Redo Move", "<Control>R", "Redo Move", gv.gshogi.redo_single_move), ("MoveNow", None, "_Move Now", "<Control>M", "Move Now", gv.gshogi.move_now), ("SetBoardColours", None, "_Set Board Colours", None, "Set Board Colours", self.set_board_colours.show_dialog), ("SetPieces", None, "_Set Pieces", None, "Set Pieces", self.set_board_colours.show_pieces_dialog), ("TimeControl", None, "_Time Control", None, "Time Control", gv.tc.time_control), # ConfigureEngine1 - this name is used in engine_manager. # don't change it. ("ConfigureEngine1", None, "_Configure Engine 1", None, "Configure Engine 1", gv.engine_manager.configure_engine), ("ConfigureEngine2", None, "_Configure Engine 2", None, "Configure Engine 2", gv.engine_manager.configure_engine), ("Players", None, "_Players", None, "Players", gv.gshogi.set_players), ("Engines", None, "_Engines", None, "Engines", gv.engine_manager.engines), ("CommonEngineSettings", None, "_Common Engine Settings", None, "Common Engine Settings", gv.engine_manager.common_settings), ("MoveList", None, "_Move List", None, "Move List", self.move_list.show_movelist_window), ("GameList", None, "_Game List", None, "Game List", self.gamelist.show_gamelist_window_cb), ("EngineOutput", None, "_Engine Output", None, "Engine Output", self.engine_output.show_engine_output_window), ("EngineDebug", None, "_Engine Debug", None, "Engine Debug", self.engine_debug.show_debug_window), ("Options", None, "_Options"), ("View", None, "_View"), ("About", Gtk.STOCK_ABOUT, "_About", None, "Show About Box", self.about_box), ("Help", None, "_Help"), ("CopyPosition", None, "_Copy Position", None, "Copy Position", utils.copy_SFEN_to_clipboard), ("PastePosition", None, "_Paste Position", None, "Paste Position", utils.paste_clipboard_to_SFEN), ("CopyGame", None, "_Copy Game", None, "Copy Game", utils.copy_game_to_clipboard), ("PasteGame", None, "_Paste Game", None, "Paste Game", utils.paste_game_from_clipboard), ("EditPosition", None, "_Edit Position", None, "Edit Position", self.enable_edit_mode), ("Preferences", None, "_Preferences", None, "Preferences", self.preferences), ]) # Add the actiongroups to the uimanager uimanager.insert_action_group(actiongroup, 0) uimanager.insert_action_group(ta_action_group, 1) ui = """<ui> <menubar name="MenuBar"> <menu action="File"> <menuitem action="NewGame"/> <menu action="NewHandicapGame"> <menuitem action="LanceHandicap"/> <menuitem action="BishopHandicap"/> <menuitem action="RookHandicap"/> <menuitem action="RookandLanceHandicap"/> <menuitem action="TwoPieceHandicap"/> <menuitem action="FourPieceHandicap"/> <menuitem action="SixPieceHandicap"/> <menuitem action="EightPieceHandicap"/> <menuitem action="TenPieceHandicap"/> </menu> <separator/> <menuitem action="LoadGame"/> <menuitem action="SaveGame"/> <separator/> <menuitem action="Quit"/> </menu> <menu action="Edit"> <menuitem action="CopyPosition"/> <menuitem action="PastePosition"/> <separator/> <menuitem action="CopyGame"/> <menuitem action="PasteGame"/> <separator/> <menuitem action="EditPosition"/> <separator/> <menuitem action="Preferences"/> </menu> <menu action="Options"> <menuitem action="Undo"/> <menuitem action="Redo"/> <menuitem action="MoveNow"/> <separator/> <menuitem action="promotemode"/> <menuitem action="SetBoardColours"/> <menuitem action="SetPieces"/> <separator/> <menuitem action="TimeControl"/> <menuitem action="ConfigureEngine1"/> <menuitem action="ConfigureEngine2"/> <menuitem action="Players"/> <menuitem action="Engines"/> <menuitem action="CommonEngineSettings"/> </menu> <menu action="View"> <menuitem action="MoveList"/> <menuitem action="GameList"/> <menuitem action="EngineOutput"/> <menuitem action="EngineDebug"/> </menu> <menu action="Help"> <menuitem action="About"/> </menu> </menubar> </ui>""" # Add a UI description uimanager.add_ui_from_string(ui) # Use an event box and set its background colour. # This was needed on Ubuntu 12.04 to set the toolbar bg colour. # Otherwise ubuntu uses the window bg colour which is not # correct. # don't need this on Fedora though. eb_1 = self.builder.get_object("eb_1") # eb_1 = Gtk.EventBox() vbox2 = Gtk.VBox(False, 0) # main_vbox.pack_start(vbox2, False) # main_vbox.pack_start(eb_1, False) eb_1.add(vbox2) eb_1.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EDECEB")) # Create a MenuBar menubar = uimanager.get_widget("/MenuBar") vbox2.pack_start(menubar, False, True, 0) # create a toolbar toolbar = Gtk.Toolbar() vbox2.pack_start(toolbar, False, True, 0) # populate toolbar toolitem = Gtk.ToolItem() # 2 rows, 4 columns, not homogeneous tb = Gtk.Table(2, 5, False) # Gtk.ShadowType.NONE, SHADOW_IN, SHADOW_OUT, SHADOW_ETCHED_IN, # SHADOW_ETCHED_OUT self.side_to_move = [ Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.ETCHED_IN), Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.ETCHED_IN) ] self.side_to_move[BLACK].set_alignment(0.5, 0.4) self.side_to_move[WHITE].set_alignment(0.5, 0.4) tb.attach(self.side_to_move[WHITE], 0, 1, 0, 1) tb.attach(self.side_to_move[BLACK], 0, 1, 1, 2) lw = Gtk.Label(label="White: ") lb = Gtk.Label(label="Black: ") lw.set_alignment(0, 0.5) lb.set_alignment(0, 0.5) tb.attach(lw, 1, 2, 0, 1) tb.attach(lb, 1, 2, 1, 2) self.engines_lblw = Gtk.Label(label="gshogi") self.engines_lblw.set_use_markup(True) self.engines_lblw.set_alignment(0, 0.5) self.engines_lblb = Gtk.Label(label="human") self.engines_lblb.set_use_markup(True) self.engines_lblb.set_alignment(0, 0.5) tb.attach(self.engines_lblw, 2, 3, 0, 1) tb.attach(self.engines_lblb, 2, 3, 1, 2) # time control self.tc_lbl = [ Gtk.Label(label="00:45:00 00/10"), Gtk.Label(label="00:45:00 00/10") ] self.tc_lbl[BLACK].set_alignment(0, 0.5) self.tc_lbl[WHITE].set_alignment(0, 0.5) tb.attach(self.tc_lbl[WHITE], 3, 4, 0, 1) tb.attach(self.tc_lbl[BLACK], 3, 4, 1, 2) toolitem.add(tb) toolbar.insert(toolitem, -1) # add a vertical separator hb = Gtk.HBox(False, 0) toolitem = Gtk.ToolItem() vsep = Gtk.VSeparator() hb.pack_start(vsep, True, True, 10) toolitem.add(hb) toolbar.insert(toolitem, -1) # stop/go buttons hb = Gtk.HBox(False, 0) self.gobutton = Gtk.ToolButton(Gtk.STOCK_YES) self.gobutton.connect("clicked", gv.gshogi.go_clicked) self.stopbutton = Gtk.ToolButton(Gtk.STOCK_NO) self.stopbutton.connect("clicked", gv.gshogi.stop_clicked) self.gobutton.set_tooltip_text("go") self.stopbutton.set_tooltip_text("stop") hb.pack_start(self.stopbutton, False, True, 0) hb.pack_start(self.gobutton, False, True, 0) toolitem = Gtk.ToolItem() toolitem.add(hb) toolbar.insert(toolitem, -1) # add a vertical separator hb = Gtk.HBox(False, 0) toolitem = Gtk.ToolItem() vsep = Gtk.VSeparator() hb.pack_start(vsep, True, True, 10) toolitem.add(hb) toolbar.insert(toolitem, -1) # game review buttons hb = Gtk.HBox(False, 0) self.go_first = Gtk.ToolButton(Gtk.STOCK_GOTO_FIRST) self.go_first.connect("clicked", gv.gshogi.undo_all) self.go_back = Gtk.ToolButton(Gtk.STOCK_GO_BACK) self.go_back.connect("clicked", gv.gshogi.undo_single_move) self.go_forward = Gtk.ToolButton(Gtk.STOCK_GO_FORWARD) self.go_forward.connect("clicked", gv.gshogi.redo_single_move) self.go_last = Gtk.ToolButton(Gtk.STOCK_GOTO_LAST) self.go_last.connect("clicked", gv.gshogi.redo_all) hb.pack_start(self.go_first, False, True, 0) hb.pack_start(self.go_back, False, True, 0) hb.pack_start(self.go_forward, False, True, 0) hb.pack_start(self.go_last, False, True, 0) toolitem = Gtk.ToolItem() toolitem.add(hb) toolbar.insert(toolitem, -1) # add a vertical separator hb = Gtk.HBox(False, 0) toolitem = Gtk.ToolItem() vsep = Gtk.VSeparator() hb.pack_start(vsep, True, True, 10) toolitem.add(hb) toolbar.insert(toolitem, -1) main_grid = self.builder.get_object("grid1") main_grid.set_row_homogeneous(True) main_grid.set_column_homogeneous(True) # main_hbox = Gtk.HBox(False, 0) # Create komadai grids for captured pieces self.setup_komadai(WHITE, main_grid) self.setup_komadai(BLACK, main_grid) # Create a 9x9 table for the main board self.boardgrid = Gtk.Grid.new() self.boardgrid.set_row_homogeneous(True) self.boardgrid.set_column_homogeneous(True) self.boardgrid.set_border_width(1) # # init board squares (add event box, set up drag and drop, # button clicks) # x, y = 0, 0 is the top left square of the board # for x in range(9): for y in range(9): self.init_board_square(x, y) eb2 = Gtk.EventBox() eb2.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black")) eb2.add(self.boardgrid) eb = Gtk.EventBox() eb.add(eb2) eb.show() aspect_frame = Gtk.AspectFrame(label=None, xalign=0.5, yalign=0.5, ratio=1.0, obey_child=False) aspect_frame.add(eb) eb2.set_border_width(20) self.grid_eb = eb2 main_grid.attach(aspect_frame, 6, 0, 20, 20) aspect_frame.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black")) eb.connect_after("draw", self.draw_coords) self.border_eb = eb # status bar self.status_bar = self.builder.get_object("status_bar") # set status bar bg color # Use an event box and set its background colour. # This was needed on Fedora 19 to set the statusbar bg colour. # Otherwise it uses the window bg colour which is not # correct. This was not needed on F17. eb_2 = self.builder.get_object("eb_2") eb_2.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EDECEB")) # self.status_bar = Gtk.Statusbar() # main_vbox.pack_start(self.status_bar, False, False, 0) self.context_id = self.status_bar.get_context_id("gshogi statusbar") self.actiongroup.get_action("MoveNow").set_sensitive(False) self.window.show_all() self.side_to_move[WHITE].hide() self.gobutton.set_sensitive(False) self.stopbutton.set_sensitive(False) # mask = Gdk.WindowHints.BASE_SIZE| # Gdk.WindowHints.MIN_SIZE| # Gdk.WindowHints.MAX_SIZE| # Gdk.WindowHints.RESIZE_INC|Gdk.WindowHints.ASPECT #mask = Gdk.WindowHints.MIN_SIZE | Gdk.WindowHints.MAX_SIZE mask = Gdk.WindowHints.MIN_SIZE geometry = Gdk.Geometry() # geometry.base_width = -1 # geometry.base_height = -1 # geometry.max_width = -1 # geometry.max_height = -1 geometry.min_width = 378 geometry.min_height = 378 # geometry.width_inc = -1 # geometry.height_inc = -1 # geometry.min_aspect = -1.0 # geometry.max_aspect = -1.0 #self.window.set_geometry_hints(self.window, geometry, mask) # self.window.set_geometry_hints( # self.window, min_width=378, min_height=378, max_width=-1, # max_height=-1, base_width=-1, base_height=-1, width_inc=-1, # height_inc=-1, min_aspect=-1.0, max_aspect=-1.0) self.build_edit_popup()
def build_gui(self): # Create Main Window self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL) #self.window.set_resizable(False) self.window.set_title(NAME + " " + VERSION) self.window.set_default_size(550, 550) # startup size self.window.set_size_request(400, 400) # minimum size # Set a handler for delete_event that immediately # exits GTK. self.window.connect("delete_event", self.game.delete_event) self.window.connect("key_press_event", self.game.key_press_event) self.window.connect("configure_event", self.configure_event) main_vbox = Gtk.VBox(False, 0) self.window.add(main_vbox) main_vbox.show() # 1 eventbox per board square self.eb = [ \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ [Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox(), Gtk.EventBox()], \ ] # menu # Create a UIManager instance uimanager = Gtk.UIManager() # Add the accelerator group to the toplevel window accelgroup = uimanager.get_accel_group() self.window.add_accel_group(accelgroup) # Create ActionGroups # main action group actiongroup = Gtk.ActionGroup('UIManagerAG') self.actiongroup = actiongroup # action group for setting search depth level search_depth_actiongroup = Gtk.ActionGroup('AGSearchDepth') search_depth_actiongroup.add_radio_actions([ ('Beginner', None, _('Beginner'), None, None, 0), ('Advanced', None, _('Advanced'), None, None, 1), ('Expert', None, _('Expert'), None, None, 2), ('Custom', None, _('User-defined'), None, None, 3), ], 0, self.game.set_level) # action group for showing/hiding panel panel_action_group = Gtk.ActionGroup('AGPanel') panel_action_group.add_toggle_actions([('showpanel', None, _('Information Panel'), None, None, self.set_info_panel)]) panel_action_group.add_toggle_actions([('statusbar', None, _('Status Bar'), None, None, self.set_status_bar)]) self.panel_action_group = panel_action_group # Computer Player computer_player_action_group = Gtk.ActionGroup('ComputerPlayer') computer_player_action_group.add_radio_actions([ ('ComputerPlaysWhite', None, _('Computer Plays White'), None, None, 0), ('ComputerPlaysRed', None, _('Computer Plays Red'), None, None, 1), ('ComputerPlaysWhiteAndRed', None, _('Computer Plays White and Red'), None, None, 2), ('ComputerOff', None, _('Computer Off'), None, None, 3), ], 0, self.game.set_computer_player) self.computer_player_action_group = computer_player_action_group # Create a ToggleAction for flipping the board flip_the_board_action_group = Gtk.ActionGroup('FlipTheBoard') flip_the_board_action_group.add_toggle_actions([ ('FlipTheBoard', None, _('Flip the Board'), None, _('Flip the Board'), self.game.flip_the_board) ]) self.flip_the_board_action_group = flip_the_board_action_group # Create actions actiongroup.add_actions([('Quit', Gtk.STOCK_QUIT, _('Quit'), None, _('Quit the Program'), self.game.quit_game), ('NewGame', Gtk.STOCK_NEW, _('New Game'), None, _('New Game'), self.game.new_game), ('LoadGame', Gtk.STOCK_OPEN, _('Load Game'), None, _('Load Game'), self.game.load_game), ('SaveGame', Gtk.STOCK_SAVE, _('Save Game'), None, _('Save Game'), self.game.save_game), ('MoveNow', None, _('Move Now (m)'), None, _('Move Now'), self.game.move_now), ('Game', None, _('Game')), ('PositionEdit', None, _('Position Edit'), None, _('Position Edit'), \ self.board.position_edit_init), ('CopyFenToCB', None, _('Copy FEN to clipboard'), None, _('Copy FEN to clipboard'), \ self.game.copy_FEN_to_clipboard), ('PasteFenFromCB', None, _('Paste FEN from clipboard'), None, _('Paste FEN from clipboard'), \ self.game.paste_FEN_from_clipboard), ('CopyPDNToCB', Gtk.STOCK_COPY, _('Copy PDN to clipboard'), None, _('Copy PDN to clipboard'), \ self.game.copy_PDN_to_clipboard), ('PastePDNFromCB', Gtk.STOCK_PASTE, _('Paste PDN from clipboard'), None, _('Paste PDN from clipboard'), \ self.game.paste_PDN_from_clipboard), ('Edit', None, _('Edit')), ('SetCustomLevelDepth', None, _('Set User-Defined Level'), None, _('Set Custom Level Depth'), \ self.game.set_custom_search_depth), ('Level', None, _('Level')), ('Options', None, _('Options')), ('About', Gtk.STOCK_ABOUT, _('About'), None, _('Show About Box'), self.about_box), ('samhelp', Gtk.STOCK_HELP, _('Help (online)'), None, _('Samuel Help (Online)'), \ self.game.open_help), ('Help', None, _('Help')), ]) actiongroup.get_action('Quit').set_property('short-label', _('Quit')) actiongroup.get_action('MoveNow').set_sensitive(False) # Add the actiongroups to the uimanager uimanager.insert_action_group(actiongroup, 0) uimanager.insert_action_group(search_depth_actiongroup, 1) uimanager.insert_action_group(panel_action_group, 2) uimanager.insert_action_group(computer_player_action_group, 3) uimanager.insert_action_group(flip_the_board_action_group, 4) # Action groups that need settings to be saved/restored on program exit/startup self.save_action_groups = [search_depth_actiongroup, panel_action_group, flip_the_board_action_group, \ computer_player_action_group] ui = '''<ui> <menubar name="MenuBar"> <menu action="Game"> <menuitem action="NewGame"/> <separator/> <menuitem action="LoadGame"/> <menuitem action="SaveGame"/> <separator/> <menuitem action="MoveNow"/> <separator/> <menuitem action="Quit"/> </menu> <menu action="Edit"> <menuitem action="PositionEdit"/> <separator/> <menuitem action="CopyFenToCB"/> <menuitem action="PasteFenFromCB"/> <separator/> <menuitem action="CopyPDNToCB"/> <menuitem action="PastePDNFromCB"/> </menu> <menu action="Level"> <menuitem action="Beginner"/> <menuitem action="Advanced"/> <menuitem action="Expert"/> <menuitem action="Custom"/> <separator/> <menuitem action="SetCustomLevelDepth"/> <separator/> </menu> <menu action="Options"> <menuitem action="ComputerPlaysWhite"/> <menuitem action="ComputerPlaysRed"/> <menuitem action="ComputerPlaysWhiteAndRed"/> <menuitem action="ComputerOff"/> <separator/> <menuitem action="showpanel"/> <menuitem action="statusbar"/> <separator/> <menuitem action="FlipTheBoard"/> </menu> <menu action="Help"> <menuitem action="samhelp"/> <separator/> <menuitem action="About"/> </menu> </menubar> </ui>''' # Add a UI description uimanager.add_ui_from_string(ui) # Create a MenuBar menubar = uimanager.get_widget('/MenuBar') main_vbox.pack_start(menubar, False, True, 0) self.load_images() # Create a 8x8 table self.table = Gtk.Table(8, 8, True) self.table.set_border_width(25) aspect_frame = Gtk.AspectFrame(label=None, xalign=0.5, yalign=0.5, ratio=1.0, obey_child=False) aspect_frame.add(self.table) eb = Gtk.EventBox() #eb.add(self.table) eb.add(aspect_frame) eb.show() eb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("darkslategrey")) main_vbox.pack_start(eb, True, True, 0) bot_hbox = Gtk.HBox(False, 0) main_vbox.pack_start(bot_hbox, False, True, 7) bot_hbox.show() vbox = Gtk.VBox(False, 0) bot_hbox.pack_end(vbox, False, False, 5) hbox1 = Gtk.HBox(False, 0) vbox.pack_start(hbox1, True, False, 0) hbox2 = Gtk.HBox(False, 0) vbox.pack_start(hbox2, True, False, 7) frame = Gtk.Frame() frame.set_shadow_type(Gtk.ShadowType.IN) frame.show() vp = Gtk.Viewport() vp.add(frame) vp.show() vp.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#EDECEB')) bot_hbox.pack_end(vp, True, True, 7) self.bot_hbox = bot_hbox self.infolabel = Gtk.Label() self.infolabel.modify_font(Pango.FontDescription("monospace 8")) frame.add(self.infolabel) self.infolabel.show() # get positions loaded msg msg = engine.rdisp() self.infolabel.set_text(msg) # go button self.go_button = Gtk.Button(_("Go")) self.go_button.connect("clicked", self.game.callback, 'Go') hbox1.pack_start(self.go_button, True, False, 0) self.go_button.show() # retract button self.retract_button = Gtk.Button(_("Retract")) self.retract_button.connect("clicked", self.game.callback, 'Retract') hbox1.pack_start(self.retract_button, True, False, 0) self.retract_button.show() # rewind to start button self.rts_button = Gtk.Button("<|") self.rts_button.connect("clicked", self.game.callback, '<|') hbox2.pack_start(self.rts_button, True, False, 0) self.rts_button.show() # rewind 1 move buttton self.rom_button = Gtk.Button("<") self.rom_button.connect("clicked", self.game.callback, '<') hbox2.pack_start(self.rom_button, True, False, 0) self.rom_button.show() # forward 1 move buttton self.fom_button = Gtk.Button(">") self.fom_button.connect("clicked", self.game.callback, '>') hbox2.pack_start(self.fom_button, True, False, 0) self.fom_button.show() # forward to end of game button self.fteog_button = Gtk.Button("|>") self.fteog_button.connect("clicked", self.game.callback, '|>') hbox2.pack_start(self.fteog_button, True, False, 0) self.fteog_button.show() vbox.show() hbox1.show() hbox2.show() # # widgets for position edit # self.posedit_hbox = Gtk.HBox(False, 0) main_vbox.pack_start(self.posedit_hbox, False, True, 7) vbox = Gtk.VBox(False, 0) self.posedit_hbox.pack_end(vbox, False, False, 5) hbox1 = Gtk.HBox(False, 0) vbox.pack_start(hbox1, True, False, 0) label = Gtk.Label() label.set_text(_("Side to Move")) label.show() vbox.pack_start(label, True, False, 7) hbox2 = Gtk.HBox(False, 0) vbox.pack_start(hbox2, True, False, 0) frame = Gtk.Frame() frame.set_shadow_type(Gtk.ShadowType.IN) frame.show() vp = Gtk.Viewport() vp.add(frame) vp.show() vp.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#EDECEB')) self.posedit_hbox.pack_end(vp, True, True, 7) self.infolabel2 = Gtk.Label() self.infolabel2.modify_font(Pango.FontDescription("monospace 8")) frame.add(self.infolabel2) self.infolabel2.show() self.cancel_button = Gtk.Button(_("Cancel")) self.cancel_button.connect("clicked", self.game.callback, 'Cancel') hbox1.pack_start(self.cancel_button, True, False, 0) self.cancel_button.show() button = Gtk.Button(_("OK")) button.connect("clicked", self.game.callback, 'OK') hbox1.pack_start(button, True, False, 0) button.show() self.radio_button_red = Gtk.RadioButton.new_with_label_from_widget( None, _("Red")) hbox2.pack_start(self.radio_button_red, True, False, 0) self.radio_button_red.show() self.radio_button_white = Gtk.RadioButton.new_with_label_from_widget( self.radio_button_red, _("White")) hbox2.pack_start(self.radio_button_white, True, False, 0) self.radio_button_white.show() vbox.show() hbox1.show() hbox2.show() # status bar self.status_bar = Gtk.Statusbar() main_vbox.pack_start(self.status_bar, False, False, 0) self.context_id = self.status_bar.get_context_id("samuel statusbar") self.set_status_bar_msg(_("Red to Move")) self.window.show_all() self.posedit_hbox.hide() panel_action_group.get_action('showpanel').set_active(True) panel_action_group.get_action('statusbar').set_active(True)