Exemplo n.º 1
0
    def __init__(self):
        # Translators: "New" refers to a world clock
        Clock.__init__(self, _("World"), _("New"), True)

        self.liststore = Gtk.ListStore(bool,
                                       GdkPixbuf.Pixbuf,
                                       str,
                                       GObject.TYPE_PYOBJECT)

        self.iconview = SelectableIconView(self.liststore, 0, 1, 2)

        contentview = ContentView(self.iconview,
                "document-open-recent-symbolic",
                 _("Select <b>New</b> to add a world clock"))

        self.timeview = TimeAdjustingView(contentview)
        self.add(self.timeview)

        self._update_source_id = None

        self.timeview.connect("time-changed", self._on_timeview_time_changed)
        self.iconview.connect("item-activated", self._on_item_activated)
        self.iconview.connect("selection-changed", self._on_selection_changed)

        self.storage = WorldClockStorage()
        self.clocks = []
        self.load_clocks()
        self.show_all()

        self.timeout_id = GObject.timeout_add(1000, self._update_clocks)
Exemplo n.º 2
0
    def __init__(self):

        with open("config.json") as cfg_file:
            game_cfg = load_json(cfg_file)

        if not glfw.init():
            raise RuntimeError("Failed to initialise GLFW")

        GlfwWindow.hint(samples=game_cfg["aaSamples"])
        GlfwWindow.hint(context_ver_major=3)
        GlfwWindow.hint(context_ver_minor=3)
        GlfwWindow.hint(forward_compat=True)
        GlfwWindow.hint(resizable=True)
        GlfwWindow.hint(opengl_profile=GlfwWindow.CORE_PROFILE)

        primary_monitor = None
        if game_cfg["fullscreen"]:
            primary_monitor = glfw.get_primary_monitor()

        self.window = GlfwWindow(game_cfg["screenWidth"],
                                 game_cfg["screenHeight"], "Tutorial",
                                 primary_monitor)
        if not self.window:
            raise RuntimeError("Failed to initialise window.")

        self.window.make_current()

        self.clock = Clock()

        self.dispatchTable = DispatchTable(self.window)

        # setup keyboard and mouse controls
        self.dispatchTable.registerKey(glfw.Keys.ESCAPE, self.escape)
        self.dispatchTable.registerKey(glfw.Keys.W, self.moveForward)
        self.dispatchTable.registerKey(glfw.Keys.S, self.moveBackward)
        self.dispatchTable.registerKey(glfw.Keys.A, self.moveLeft)
        self.dispatchTable.registerKey(glfw.Keys.D, self.moveRight)

        self.dispatchTable.registerMouseButton(glfw.Mice.RIGHT,
                                               self.toggleMouseLook)

        self.renderer = Renderer(self.window)
        self.renderer.fov = pi / 4.

        self.camera = None

        self.gameData = GameData()

        self._mouseLook = False

        self._terminate = False
Exemplo n.º 3
0
    def __init__(self):
        # Translators: "New" refers to an alarm
        Clock.__init__(self, _("Alarm"), _("New"), True)

        self.liststore = Gtk.ListStore(bool, GdkPixbuf.Pixbuf, str, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)

        self.iconview = SelectableIconView(self.liststore, 0, 1, 2)

        contentview = ContentView(self.iconview, "alarm-symbolic", _("Select <b>New</b> to add an alarm"))
        self.add(contentview)

        self.iconview.connect("item-activated", self._on_item_activated)
        self.iconview.connect("selection-changed", self._on_selection_changed)

        self.storage = AlarmsStorage()

        self.load_alarms()
        self.show_all()

        self.timeout_id = GObject.timeout_add(1000, self._check_alarms)
Exemplo n.º 4
0
    def __init__(self):
        Clock.__init__(self, _("Timer"))
        self.state = Timer.State.STOPPED
        self.timeout_id = 0

        self.notebook = Gtk.Notebook()
        self.notebook.set_show_tabs(False)
        self.notebook.set_show_border(False)
        self.add(self.notebook)

        # force the time label and the spinner to the same size
        size_group = Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL);

        self.setup_screen = TimerSetupScreen(self, size_group)
        self.notebook.append_page(self.setup_screen, None)

        self.timer_screen = TimerScreen(self, size_group)
        self.notebook.append_page(self.timer_screen, None)

        self.alert = Alert("complete", "Ta Da !",
                           self._on_notification_activated)
    def __init__(self):
        Clock.__init__(self, _("Stopwatch"))

        self.state = Stopwatch.State.RESET

        self.timeout_id = 0

        self.start_time = 0
        self.time_diff = 0

        self.lap = 0
        self.lap_start_time = 0
        self.lap_time_diff = 0

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(vbox)

        grid = Gtk.Grid()
        grid.set_margin_top(12)
        grid.set_margin_bottom(48)
        grid.set_halign(Gtk.Align.CENTER)
        grid.set_row_spacing(24)
        grid.set_column_spacing(24)
        grid.set_column_homogeneous(True)
        vbox.pack_start(grid, False, False, 0)

        self.time_label = Gtk.Label()
        self.set_time_label(0, 0, 0)
        grid.attach(self.time_label, 0, 0, 2, 1)

        self.left_button = Gtk.Button()
        self.left_button.set_size_request(200, -1)
        self.left_label = Gtk.Label()
        self.left_label.set_markup(Stopwatch.BUTTON_MARKUP % (_("Start")))
        self.left_button.add(self.left_label)
        self.left_button.get_style_context().add_class("clocks-go")
        grid.attach(self.left_button, 0, 1, 1, 1)

        self.right_button = Gtk.Button()
        self.right_button.set_size_request(200, -1)
        self.right_label = Gtk.Label()
        self.right_label.set_markup(Stopwatch.BUTTON_MARKUP % (_("Reset")))
        self.right_button.add(self.right_label)
        self.right_button.set_sensitive(False)
        grid.attach(self.right_button, 1, 1, 1, 1)

        self.left_button.connect("clicked", self._on_left_button_clicked)
        self.right_button.connect("clicked", self._on_right_button_clicked)

        self.laps_store = Gtk.ListStore(str, str, str)
        cell = Gtk.CellRendererText()
        n_column = Gtk.TreeViewColumn(_("Lap"), cell, markup=0)
        n_column.set_expand(True)
        cell = Gtk.CellRendererText()
        split_column = Gtk.TreeViewColumn(_("Split"), cell, markup=1)
        split_column.set_expand(True)
        cell = Gtk.CellRendererText()
        tot_column = Gtk.TreeViewColumn(_("Total"), cell, markup=2)
        tot_column.set_expand(True)
        self.laps_view = Gtk.TreeView(self.laps_store)
        self.laps_view.get_style_context().add_class("clocks-laps")
        self.laps_view.append_column(n_column)
        self.laps_view.append_column(split_column)
        self.laps_view.append_column(tot_column)
        scroll = Gtk.ScrolledWindow()
        scroll.get_style_context().add_class("clocks-laps-scroll")
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.set_vexpand(True);
        scroll.add(self.laps_view)
        vbox.pack_start(scroll, True, True, 0)
Exemplo n.º 6
0
class Game(object):
    """
	The object containing all information about the game.
	"""
    def __init__(self):

        with open("config.json") as cfg_file:
            game_cfg = load_json(cfg_file)

        if not glfw.init():
            raise RuntimeError("Failed to initialise GLFW")

        GlfwWindow.hint(samples=game_cfg["aaSamples"])
        GlfwWindow.hint(context_ver_major=3)
        GlfwWindow.hint(context_ver_minor=3)
        GlfwWindow.hint(forward_compat=True)
        GlfwWindow.hint(resizable=True)
        GlfwWindow.hint(opengl_profile=GlfwWindow.CORE_PROFILE)

        primary_monitor = None
        if game_cfg["fullscreen"]:
            primary_monitor = glfw.get_primary_monitor()

        self.window = GlfwWindow(game_cfg["screenWidth"],
                                 game_cfg["screenHeight"], "Tutorial",
                                 primary_monitor)
        if not self.window:
            raise RuntimeError("Failed to initialise window.")

        self.window.make_current()

        self.clock = Clock()

        self.dispatchTable = DispatchTable(self.window)

        # setup keyboard and mouse controls
        self.dispatchTable.registerKey(glfw.Keys.ESCAPE, self.escape)
        self.dispatchTable.registerKey(glfw.Keys.W, self.moveForward)
        self.dispatchTable.registerKey(glfw.Keys.S, self.moveBackward)
        self.dispatchTable.registerKey(glfw.Keys.A, self.moveLeft)
        self.dispatchTable.registerKey(glfw.Keys.D, self.moveRight)

        self.dispatchTable.registerMouseButton(glfw.Mice.RIGHT,
                                               self.toggleMouseLook)

        self.renderer = Renderer(self.window)
        self.renderer.fov = pi / 4.

        self.camera = None

        self.gameData = GameData()

        self._mouseLook = False

        self._terminate = False

    def __del__(self):
        glfw.terminate()

    def run(self):
        """ Runs the game.  This method returns when the terminate flag is set. """

        while not self._terminate:

            time_passed = self.clock.tick(60.)
            print "{0:.3f}\r".format(self.clock.fps),

            self.gameData.update(time_passed)

            self.renderer.update(time_passed)

            glfw.poll_events()

            if self.window.should_close:
                self._terminate = True

    def terminate(self):
        """ Set the terminate flag, causing the program to tear-down and exit. """
        self._terminate = True

    def addEntity(self, entity):
        self.renderer.addEntity(entity)

    def removeEntity(self, entity):
        self.renderer.removeEntity(entity)

    def addCharacter(self, character):
        self.gameData.addCharacter(character)
        self.addEntity(character)

    def removeCharacter(self, character):
        self.gameData.removeCharacter(character)
        self.removeEntity(character)

    def setPlayerCharacter(self, pc):
        """ Set the specified items as the player character entity. """

        self.pc = pc
        self.addCharacter(pc)

        # set up third person camera following player entity
        camera = OrbitalCamera(self.pc, (0., 0., 5.))
        self.setCamera(camera)
        self.pc.setCamera(camera)

    def setCamera(self, camera):
        self.camera = camera
        self.renderer.camera = camera
        self.gameData.setCamera(camera)

    ## Control Methods ##

    def escape(self, key, action, mods):
        if action == GlfwWindow.PRESS:
            self.terminate()

    def toggleMouseLook(self, key, action, mods):
        if action == GlfwWindow.RELEASE:
            if not self._mouseLook:
                self.window.cursor_mode = None
                self.dispatchTable.registerMouseMotion(self.mouseLook)
                self._mouseLook = True
                self.window.cursor_pos = (1, 1)

            else:
                self.window.cursor_mode = True
                self.dispatchTable.unregisterMouseMotion()
                self._mouseLook = False

    def mouseLook(self, xpos, ypos):
        self.camera.yaw((xpos - 1) * 0.01)
        self.camera.pitch((ypos - 1) * 0.01)
        self.window.cursor_pos = (1, 1)

    def moveForward(self, key, action, mods):
        if action == GlfwWindow.PRESS:
            self.pc.forwardsBackwards(+1)
        elif action == GlfwWindow.RELEASE:
            self.pc.forwardsBackwards(-1)

    def moveBackward(self, key, action, mods):
        if action == GlfwWindow.PRESS:
            self.pc.forwardsBackwards(-1)
        elif action == GlfwWindow.RELEASE:
            self.pc.forwardsBackwards(+1)

    def moveLeft(self, key, action, mods):
        if action == GlfwWindow.PRESS:
            self.pc.leftRight(-1)
        elif action == GlfwWindow.RELEASE:
            self.pc.leftRight(+1)

    def moveRight(self, key, action, mods):
        if action == GlfwWindow.PRESS:
            self.pc.leftRight(+1)
        elif action == GlfwWindow.RELEASE:
            self.pc.leftRight(-1)