def __init__(self, parent): super(SliderPuzzleUI, self).__init__(3, 3, False) self._parent = parent # We want the translatables to be detected but not yet translated global _ _ = lambda x: x self.labels_to_translate = [] self._state = GAME_IDLE inner_table = Gtk.Table(2, 2, False) self.add(inner_table) self.from_journal = True self.game = SliderPuzzleWidget(9, GAME_SIZE, GAME_SIZE) self.game.connect("solved", self.do_solve) self.game.connect("moved", self.slider_move_cb) self._parent.connect("key_press_event", self.game.process_key) self._parent.connect("key_press_event", self.process_key) self.game.show() desktop = BorderFrame(border_color=COLOR_FRAME_CONTROLS) desktop.show() desktop.add(self.game) self.game_wrapper = Gtk.VBox() self.game_wrapper.show() inner = Gtk.HBox() inner.show() #BorderFrame(border=BORDER_ALL_BUT_BOTTOM, # border_color=COLOR_FRAME_CONTROLS, # bg_color=COLOR_BG_CONTROLS) inner.pack_start(desktop, True, False, 0) self.game_wrapper.pack_start(inner, True, False, 0) # panel is a holder for everything on the left side down to (not inclusive) the language dropdown panel = Gtk.VBox() # Logo image img_logo = Gtk.Image() img_logo.set_from_file("icons/logo.png") img_logo.show() panel.pack_start(img_logo, False, False, 0) # Control panel has the image controls control_panel = BorderFrame(border=BORDER_ALL_BUT_BOTTOM, border_color=COLOR_FRAME_CONTROLS, bg_color=COLOR_BG_CONTROLS) control_panel_box = Gtk.VBox() control_panel.add(control_panel_box) spacer = Gtk.Label() spacer.set_size_request(-1, 5) control_panel_box.pack_start(spacer, False, False, 0) # ... # Slice buttons #btn_box = Gtk.Table(1,5,False) #btn_box.set_col_spacings(5) #btn_box.set_row_spacings(5) #btn_box.attach(Gtk.Label(), 0,1,0,2) #spacer = Gtk.Label() #spacer.set_size_request(-1, 15) #control_panel_box.pack_start(spacer, False, False, 0) #cutter = Gtk.HBox(False, 8) #cutter.pack_start(Gtk.Label(), True) #self.btn_9 = prepare_btn(Gtk.ToggleButton("9"),SLICE_BTN_WIDTH) #self.btn_9.set_active(True) #self.btn_9.connect("clicked", self.set_nr_pieces, 9) #btn_box.attach(self.btn_9, 1,2,0,1,0,0) #cutter.pack_start(self.btn_9, False, False) #self.btn_12 = prepare_btn(Gtk.ToggleButton("12"), SLICE_BTN_WIDTH) #self.btn_12.connect("clicked", self.set_nr_pieces, 12) #btn_box.attach(self.btn_12, 2,3,0,1,0,0) #cutter.pack_start(self.btn_12, False, False) #self.btn_16 = prepare_btn(Gtk.ToggleButton("16"), SLICE_BTN_WIDTH) #self.btn_16.connect("clicked", self.set_nr_pieces, 16) #btn_box.attach(self.btn_16, 3,4,0,1,0,0) #cutter.pack_start(self.btn_16, False, False) #cutter.pack_start(Gtk.Label(), True) #control_panel_box.pack_start(cutter, True) #spacer = Gtk.Label() #spacer.set_size_request(-1, 10) #control_panel_box.pack_start(spacer, False) #btn_box.attach(Gtk.Label(), 4,5,0,1) #control_panel_box.pack_start(btn_box, False, True, 0) self.thumb = ImageSelectorWidget(self._parent, frame_color=COLOR_FRAME_THUMB, prepare_btn_cb=prepare_btn, image_dir='images') #self.thumb.connect("category_press", self.do_select_category) #self.thumb.connect("image_press", self.set_nr_pieces) #control_panel_box.pack_start(self.thumb, False, True, 0) spacer = Gtk.Label() spacer.set_size_request(-1, 5) control_panel_box.pack_start(spacer, False, False, 0) # The game control buttons #btn_box = Gtk.Table(3,3,False) #btn_box.set_row_spacings(2) #btn_box.attach(Gtk.Label(), 0,1,0,3) #btn_box.attach(Gtk.Label(), 2,3,0,3) #self.btn_solve = prepare_btn(Gtk.Button(" "), 200) #self.labels_to_translate.append([self.btn_solve, _("Solve")]) #self.btn_solve.connect("clicked", self.do_solve) #btn_box.attach(self.btn_solve, 1,2,0,1,0,0) #self.btn_shuffle = prepare_btn(Gtk.Button(" "), 200) #self.labels_to_translate.append([self.btn_shuffle, _("Shuffle")]) #self.btn_shuffle.connect("clicked", self.do_shuffle) #btn_box.attach(self.btn_shuffle, 1,2,1,2,0,0) #self.btn_add = prepare_btn(Gtk.Button(" "), 200) #self.labels_to_translate.append([self.btn_add, _("My Picture")]) #self.btn_add.connect("clicked", self.do_add_image) #btn_box.attach(self.btn_add, 1,2,2,3,0,0) #control_panel_box.pack_start(btn_box, False, True, 0) # Control panel end panel.pack_start(control_panel, True, True, 0) inner_table.attach(panel, 0, 1, 0, 1, 0) self.game_box = BorderFrame(border_color=COLOR_FRAME_GAME) self.game_box.add(self.game_wrapper) lang_combo = prepare_btn( LanguageComboBox('org.worldwideworkshop.olpc.SliderPuzzle')) lang_combo.connect('changed', self.do_select_language) # Push the gettext translator into the global namespace del _ lang_combo.install() lang_box = BorderFrame(bg_color=COLOR_BG_CONTROLS, border_color=COLOR_FRAME_CONTROLS) hbox = Gtk.HBox(False) vbox = Gtk.VBox(False) vbox.pack_start(lang_combo, True, True, 8) hbox.pack_start(vbox, True, True, 8) lang_box.add(hbox) inner_table.attach(lang_box, 0, 1, 1, 2, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL) timer_box = BorderFrame(border=BORDER_ALL_BUT_LEFT, bg_color=COLOR_BG_CONTROLS, border_color=COLOR_FRAME_CONTROLS) timer_hbox = Gtk.HBox(False) self.timer = TimerWidget(bg_color=COLOR_BG_BUTTONS[0][1], fg_color=COLOR_FG_BUTTONS[0][1], lbl_color=COLOR_BG_BUTTONS[1][1]) self.timer.set_sensitive(False) self.timer.set_border_width(3) self.labels_to_translate.append((self.timer, _("Time: "))) timer_hbox.pack_start(self.timer, False, True, 8) self.timer.connect('timer_toggle', self.timer_toggle_cb) self.msg_label = Gtk.Label() self.msg_label.show() timer_hbox.pack_start(self.msg_label, True, True, 0) self.notebook = Gtk.Notebook() self.notebook.show() self.notebook.props.show_border = False self.notebook.props.show_tabs = False self.notebook.append_page(self.game_box, None) inner_table.attach(self.notebook, 1, 2, 0, 1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL) self.btn_lesson = prepare_btn(Gtk.Button(" ")) self.labels_to_translate.append([self.btn_lesson, _("Lesson Plans")]) self.btn_lesson.connect("clicked", self.do_lesson_plan) timer_hbox.pack_start(self.btn_lesson, False, True, 8) vbox = Gtk.VBox(False) vbox.pack_start(timer_hbox, True, True, 8) timer_box.add(vbox) inner_table.attach(timer_box, 1, 2, 1, 2, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.FILL) panel.pack_start(lang_box, False, False, 0) self.do_select_language(lang_combo) self.buddy_panel = BuddyPanel() self.buddy_panel.show() if not parent.shared_activity: self.do_select_category(self) else: self.set_message(_("Waiting for remote game...")) # Contest mode flags self.set_contest_mode(False) self._on_lesson_plan = False
def __init__(self, parent): super(JigsawPuzzleUI, self).__init__(border_color=COLOR_FRAME_OUTER) self._shuffling = False self._parent = parent # We want the translatables to be detected but not yet translated global _ _ = lambda x: x self.labels_to_translate = [] self._state = GAME_IDLE self._readonly = False self._join_time = 0 inner_table = gtk.Table(2, 2, False) self.add(inner_table) self.game = JigsawPuzzleWidget() self.game.connect('picked', self.piece_pick_cb, False) self.game.connect('dropped', self.piece_drop_cb) self.game.connect('solved', self.do_solve) self.game.connect('cutter-changed', self.cutter_change_cb) self.game.show() # panel is a holder for everything on the left side down to (not inclusive) the language dropdown panel = gtk.VBox() # Logo image img_logo = gtk.Image() img_logo.set_from_file("icons/logo.png") img_logo.show() panel.pack_start(img_logo, expand=False, fill=False) # Control panel has the image controls control_panel = BorderFrame(border=BORDER_ALL_BUT_BOTTOM, border_color=COLOR_FRAME_CONTROLS, bg_color=COLOR_BG_CONTROLS) control_panel_box = gtk.VBox() scrolled = gtk.ScrolledWindow() scrolled.props.hscrollbar_policy = gtk.POLICY_NEVER scrolled.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC scrolled.show() scrolled.add_with_viewport(control_panel_box) scrolled.child.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(COLOR_BG_CONTROLS)) control_panel.add(scrolled) spacer = gtk.Label() spacer.set_size_request(-1, 5) control_panel_box.pack_start(spacer, expand=False, fill=False) btn_box = gtk.Table(2, 5, False) btn_box.set_col_spacings(5) btn_box.set_row_spacings(5) btn_box.attach(gtk.Label(), 0, 1, 0, 2) # Cut type buttons self.btn_basic_cut = gtk.ToggleButton() i = gtk.Image() i.set_from_pixbuf( utils.load_image(os.path.join('icons', 'cut_basic.svg'))) self.btn_basic_cut.set_image(i) btn_box.attach(prepare_btn(self.btn_basic_cut), 1, 2, 0, 1, 0, 0) self.btn_simple_cut = gtk.ToggleButton() i = gtk.Image() i.set_from_pixbuf( utils.load_image(os.path.join('icons', 'cut_simple.svg'))) self.btn_simple_cut.set_image(i) btn_box.attach(prepare_btn(self.btn_simple_cut), 2, 3, 0, 1, 0, 0) self.btn_classic_cut = gtk.ToggleButton() i = gtk.Image() i.set_from_pixbuf( utils.load_image(os.path.join('icons', 'cut_classic.svg'))) self.btn_classic_cut.set_image(i) # Link cutter buttons with cutter styles self.btn_cut_mapping = { 'basic': self.btn_basic_cut, 'simple': self.btn_simple_cut, 'classic': self.btn_classic_cut, } for k, v in self.btn_cut_mapping.items(): v.connect("released", self.set_piece_cut, k) btn_box.attach(prepare_btn(self.btn_classic_cut), 3, 4, 0, 1, 0, 0) # Difficulty level buttons self.btn_easy_level = gtk.ToggleButton() i = gtk.Image() i.set_from_pixbuf( utils.load_image(os.path.join('icons', 'level_easy.svg'))) self.btn_easy_level.set_active(True) self.btn_easy_level.set_image(i) btn_box.attach(prepare_btn(self.btn_easy_level), 1, 2, 1, 2, 0, 0) self.btn_normal_level = gtk.ToggleButton() i = gtk.Image() i.set_from_pixbuf( utils.load_image(os.path.join('icons', 'level_normal.svg'))) self.btn_normal_level.set_image(i) btn_box.attach(prepare_btn(self.btn_normal_level), 2, 3, 1, 2, 0, 0) self.btn_hard_level = gtk.ToggleButton() i = gtk.Image() i.set_from_pixbuf( utils.load_image(os.path.join('icons', 'level_hard.svg'))) self.btn_hard_level.set_image(i) # Link level buttons with levels self.btn_level_mapping = { 3: self.btn_easy_level, 5: self.btn_normal_level, 8: self.btn_hard_level, } for k, v in self.btn_level_mapping.items(): v.connect("released", self.set_level, k) btn_box.attach(prepare_btn(self.btn_hard_level), 3, 4, 1, 2, 0, 0) btn_box.attach(gtk.Label(), 4, 5, 0, 2) control_panel_box.pack_start(btn_box, expand=False) self.thumb = ImageSelectorWidget(frame_color=COLOR_FRAME_THUMB, prepare_btn_cb=prepare_btn, method=utils.RESIZE_PAD, image_dir="images", parent=self._parent) self.thumb.connect("category_press", self.do_select_category) self.thumb.connect("image_press", self.do_shuffle) control_panel_box.pack_start(self.thumb, expand=False) spacer = gtk.Label() spacer.set_size_request(-1, 5) control_panel_box.pack_start(spacer, expand=False, fill=False) # The game control buttons btn_box = gtk.Table(3, 4, False) btn_box.set_row_spacings(2) btn_box.attach(gtk.Label(), 0, 1, 0, 4) btn_box.attach(gtk.Label(), 2, 3, 0, 4) self.btn_solve = prepare_btn(gtk.Button(" "), 200) self.labels_to_translate.append([self.btn_solve, _("Solve")]) self.btn_solve.connect("clicked", self.do_solve) btn_box.attach(self.btn_solve, 1, 2, 0, 1, 0, 0) self.btn_shuffle = prepare_btn(gtk.Button(" "), 200) self.labels_to_translate.append([self.btn_shuffle, _("Shuffle")]) self.btn_shuffle.connect("clicked", self.do_shuffle) btn_box.attach(self.btn_shuffle, 1, 2, 1, 2, 0, 0) self.btn_add = prepare_btn(gtk.Button(" "), 200) self.labels_to_translate.append([self.btn_add, _("My Picture")]) self.btn_add.connect("clicked", self.do_add_image) btn_box.attach(self.btn_add, 1, 2, 2, 3, 0, 0) self.btn_hint = prepare_btn(gtk.ToggleButton(" "), 200) self.labels_to_translate.append([self.btn_hint, _("Board Hint")]) self.btn_hint.connect("clicked", self.do_show_hint) btn_box.attach(self.btn_hint, 1, 2, 3, 4, 0, 0) control_panel_box.pack_start(btn_box, False) self.control_panel_box = control_panel_box # Control panel end panel.pack_start(control_panel, expand=True, fill=True) inner_table.attach(panel, 0, 1, 0, 1, 0) self.game_box = BorderFrame(border_color=COLOR_FRAME_GAME) self.game_box.add(self.game) self.notebook = gtk.Notebook() self.notebook.show() self.notebook.props.show_border = False self.notebook.props.show_tabs = False self.notebook.append_page(self.game_box) inner_table.attach(self.notebook, 1, 2, 0, 1) lang_combo = prepare_btn( LanguageComboBox('org.worldwideworkshop.olpc.JigsawPuzzle')) lang_combo.connect('changed', self.do_select_language) # Push the gettext translator into the global namespace del _ lang_combo.install() lang_box = BorderFrame(bg_color=COLOR_BG_CONTROLS, border_color=COLOR_FRAME_CONTROLS) hbox = gtk.HBox(False) vbox = gtk.VBox(False) vbox.pack_start(lang_combo, padding=8) hbox.pack_start(vbox, padding=8) lang_box.add(hbox) inner_table.attach(lang_box, 0, 1, 1, 2, gtk.FILL, gtk.FILL) timer_box = BorderFrame(border=BORDER_ALL_BUT_LEFT, bg_color=COLOR_BG_CONTROLS, border_color=COLOR_FRAME_CONTROLS) timer_hbox = gtk.HBox(False) self.timer = TimerWidget(bg_color=COLOR_BG_BUTTONS[0][1], fg_color=COLOR_FG_BUTTONS[0][1], lbl_color=COLOR_BG_BUTTONS[1][1]) self.timer.set_sensitive(False) self.timer.set_border_width(3) self.labels_to_translate.append((self.timer, _("Time: "))) timer_hbox.pack_start(self.timer, False, padding=8) self.timer.connect('timer_toggle', self.timer_toggle_cb) self.msg_label = gtk.Label() self.msg_label.show() timer_hbox.pack_start(self.msg_label, True) self.do_select_language(lang_combo) self.buddy_panel = BuddyPanel(BUDDYMODE_COLLABORATION) self.buddy_panel.show() if not parent._shared_activity: self.do_select_category(self) self.set_contest_mode(False) # Assert consistent state self.cutter_change_cb(None, self.game.get_cutter(), self.game.get_target_pieces_per_line())
def __init__(self, parent): super(SliderPuzzleUI, self).__init__(3, 3, False) self._parent = parent # We want the translatables to be detected but not yet translated global _ def _(x): return x self.labels_to_translate = [] self._state = GAME_IDLE inner_table = Gtk.Table(2, 2, False) self.add(inner_table) self.from_journal = False self.game = SliderPuzzleWidget(9, GAME_SIZE, GAME_SIZE) self.game.connect("solved", self.do_solve) self.game.connect("moved", self.slider_move_cb) self._parent.connect("key_press_event", self.game.process_key) self._parent.connect("key_press_event", self.process_key) self.game.show() desktop = BorderFrame(border_color=COLOR_FRAME_CONTROLS) desktop.show() desktop.add(self.game) self.game_wrapper = Gtk.VBox() self.game_wrapper.show() inner = Gtk.HBox() inner.show() inner.pack_start(desktop, True, False, 0) self.game_wrapper.pack_start(inner, True, False, 0) # panel is a holder for everything on the left side down to (not inclusive) the language dropdown panel = Gtk.VBox() # Logo image img_logo = Gtk.Image() img_logo.set_from_file("icons/logo.png") img_logo.show() panel.pack_start(img_logo, False, False, 0) # Control panel has the image controls control_panel = BorderFrame(border=BORDER_ALL_BUT_BOTTOM, border_color=COLOR_FRAME_CONTROLS, bg_color=COLOR_BG_CONTROLS) control_panel_box = Gtk.VBox() control_panel.add(control_panel_box) spacer = Gtk.Label() spacer.set_size_request(-1, 5) control_panel_box.pack_start(spacer, False, False, 0) self.thumb = ImageSelectorWidget(self._parent, frame_color=COLOR_FRAME_THUMB, prepare_btn_cb=prepare_btn, image_dir='images') control_panel_box.pack_start(self.thumb, False, True, 0) spacer = Gtk.Label() spacer.set_size_request(-1, 5) control_panel_box.pack_start(spacer, False, False, 0) # Control panel end panel.pack_start(control_panel, True, True, 0) inner_table.attach(panel, 0, 1, 0, 1, 0) self.game_box = BorderFrame(border_color=COLOR_FRAME_GAME) self.game_box.add(self.game_wrapper) lang_combo = prepare_btn( LanguageComboBox('org.worldwideworkshop.olpc.SliderPuzzle')) del _ lang_combo.install() lang_box = BorderFrame(bg_color=COLOR_BG_CONTROLS, border_color=COLOR_FRAME_CONTROLS) hbox = Gtk.HBox(False) vbox = Gtk.VBox(False) vbox.pack_start(lang_combo, True, True, 8) hbox.pack_start(vbox, True, True, 8) lang_box.add(hbox) timer_box = BorderFrame(border=BORDER_ALL_BUT_LEFT, bg_color=COLOR_BG_CONTROLS, border_color=COLOR_FRAME_CONTROLS) timer_hbox = Gtk.HBox(False) self.timer = TimerWidget(bg_color=COLOR_BG_BUTTONS[0][1], fg_color=COLOR_FG_BUTTONS[0][1], lbl_color=COLOR_BG_BUTTONS[1][1]) self.timer.set_sensitive(False) self.timer.set_border_width(3) self.labels_to_translate.append((self.timer, _("Time: "))) timer_hbox.pack_start(self.timer, False, True, 8) self.timer.connect('timer_toggle', self.timer_toggle_cb) self.msg_label = Gtk.Label() self.msg_label.show() timer_hbox.pack_start(self.msg_label, True, True, 0) self.notebook = Gtk.Notebook() self.notebook.show() self.notebook.props.show_border = False self.notebook.props.show_tabs = False self.notebook.append_page(self.game_box, None) inner_table.attach(self.notebook, 1, 2, 0, 1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL) vbox = Gtk.VBox(False) vbox.pack_start(timer_hbox, True, True, 8) timer_box.add(vbox) inner_table.attach(timer_box, 1, 2, 1, 2, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.FILL) self.buddy_panel = BuddyPanel() self.buddy_panel.show() # Contest mode flags self.set_contest_mode(False) self.initial_path = os.path.join(get_bundle_path(), 'images', 'image_aisc_h250_w313_lg.gif') self.set_nr_pieces(nr_pieces=9, path=self.initial_path) self.pre_path = self.initial_path self._on_lesson_plan = False