Exemplo n.º 1
0
    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.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, expand=True, fill=False)
        self.game_wrapper.pack_start(inner, expand=True, fill=False)

        # 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()
        control_panel.add(control_panel_box)

        spacer = gtk.Label()
        spacer.set_size_request(-1, 5)
        control_panel_box.pack_start(spacer, expand=False, fill=False)

        # ...

        # 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, expand=False, fill=False)
        #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, expand=False)





        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)

        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,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)

        # 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_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, 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.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, gtk.FILL, gtk.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, padding=8)
        vbox = gtk.VBox(False)
        vbox.pack_start(timer_hbox, padding=8)
        timer_box.add(vbox)
        inner_table.attach(timer_box, 1,2,1,2,gtk.FILL|gtk.EXPAND, gtk.FILL)
        #panel.pack_start(lang_box, expand=False, fill=False)

        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
Exemplo n.º 2
0
    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(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