Exemplo n.º 1
0
def test_basedir():
    assert fileutils.basedir().endswith("/slugathon")
    assert fileutils.basedir("images").endswith("/slugathon/images")
    assert fileutils.basedir("images/creature/titan").endswith(
        "/slugathon/images/creature/titan")
    assert fileutils.basedir(
        "images", "creature",
        "titan").endswith("/slugathon/images/creature/titan")
Exemplo n.º 2
0
    def __init__(self, number, hit=True, scale=15):
        self.name = "%s%d" % (("Miss", "Hit")[hit], number)
        self.chit_scale = CHIT_SCALE_FACTOR * scale

        path = fileutils.basedir("images/%s/%s.png" % (self.IMAGE_DIR,
                                                       self.name))
        input_surface = cairo.ImageSurface.create_from_png(path)
        self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.chit_scale,
                                          self.chit_scale)
        ctx = cairo.Context(self.surface)
        ctx.scale(float(self.chit_scale) / input_surface.get_width(),
                  float(self.chit_scale) / input_surface.get_height())
        ctx.set_source_surface(input_surface)
        ctx.paint()
        with tempfile.NamedTemporaryFile(prefix="slugathon",
                                         suffix=".png",
                                         delete=False) as tmp_file:
            tmp_path = tmp_file.name
        self.surface.write_to_png(tmp_path)
        pixbuf = gtk.gdk.pixbuf_new_from_file(tmp_path)
        os.remove(tmp_path)
        self.event_box = gtk.EventBox()
        self.event_box.chit = self
        self.image = gtk.Image()
        self.image.set_from_pixbuf(pixbuf)
        self.event_box.add(self.image)
        self.location = None    # (x, y) of top left corner
Exemplo n.º 3
0
    def __init__(self, playername, game_name, markers_left, def1, parent):
        title = "PickMarker - %s" % playername
        gtk.Dialog.__init__(self, title, parent)
        self.playername = playername
        self.game_name = game_name
        self.deferred = def1
        self.set_icon(icon.pixbuf)
        self.set_transient_for(parent)
        self.set_destroy_with_parent(True)

        previous_color = ""
        hbox = None
        for ii, button_name in enumerate(sorted_markers(markers_left)):
            button = gtk.Button()
            button.tag = button_name
            pixbuf = gtk.gdk.pixbuf_new_from_file(
                fileutils.basedir("images/legion/%s.png" % button_name))
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)
            button.add(image)
            button.connect("button-press-event", self.cb_click)
            if button_name[:2] != previous_color:
                previous_color = button_name[:2]
                hbox = gtk.HBox()
                self.vbox.add(hbox)
            hbox.add(button)

        self.connect("destroy", self.cb_destroy)
        self.show_all()
Exemplo n.º 4
0
    def __init__(self, playername, game_name, markers_left, def1, parent):
        title = "PickMarker - %s" % playername
        gtk.Dialog.__init__(self, title, parent)
        self.playername = playername
        self.game_name = game_name
        self.deferred = def1
        self.set_icon(icon.pixbuf)
        self.set_transient_for(parent)
        self.set_destroy_with_parent(True)

        previous_color = ""
        hbox = None
        for ii, button_name in enumerate(sorted_markers(markers_left)):
            button = gtk.Button()
            button.tag = button_name
            pixbuf = gtk.gdk.pixbuf_new_from_file(fileutils.basedir(
                                                  "images/legion/%s.png" %
                                                  button_name))
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)
            button.add(image)
            button.connect("button-press-event", self.cb_click)
            if button_name[:2] != previous_color:
                previous_color = button_name[:2]
                hbox = gtk.HBox()
                self.vbox.add(hbox)
            hbox.add(button)

        self.connect("destroy", self.cb_destroy)
        self.show_all()
Exemplo n.º 5
0
    def __init__(self, number, hit=True, scale=15):
        self.name = "%s%d" % (("Miss", "Hit")[hit], number)
        self.chit_scale = CHIT_SCALE_FACTOR * scale

        path = fileutils.basedir("images/%s/%s.png" %
                                 (self.IMAGE_DIR, self.name))
        input_surface = cairo.ImageSurface.create_from_png(path)
        self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.chit_scale,
                                          self.chit_scale)
        ctx = cairo.Context(self.surface)
        ctx.scale(
            float(self.chit_scale) / input_surface.get_width(),
            float(self.chit_scale) / input_surface.get_height())
        ctx.set_source_surface(input_surface)
        ctx.paint()
        with tempfile.NamedTemporaryFile(prefix="slugathon",
                                         suffix=".png",
                                         delete=False) as tmp_file:
            tmp_path = tmp_file.name
        self.surface.write_to_png(tmp_path)
        pixbuf = gtk.gdk.pixbuf_new_from_file(tmp_path)
        os.remove(tmp_path)
        self.event_box = gtk.EventBox()
        self.event_box.chit = self
        self.image = gtk.Image()
        self.image.set_from_pixbuf(pixbuf)
        self.event_box.add(self.image)
        self.location = None  # (x, y) of top left corner
Exemplo n.º 6
0
 def __init__(self, legion, show_height, scale=15):
     self.legion = legion
     self.name = legion.markerid
     self.chit_scale = CHIT_SCALE_FACTOR * scale
     self.show_height = show_height
     self.image_path = fileutils.basedir("images/legion/%s.png" % self.name)
     self.location = None  # (x, y) of top left corner
     self.build_image()
Exemplo n.º 7
0
 def __init__(self, legion, show_height, scale=15):
     self.legion = legion
     self.name = legion.markerid
     self.chit_scale = CHIT_SCALE_FACTOR * scale
     self.show_height = show_height
     self.image_path = fileutils.basedir("images/legion/%s.png" % self.name)
     self.location = None    # (x, y) of top left corner
     self.build_image()
Exemplo n.º 8
0
    def __init__(self, parent):
        gtk.AboutDialog.__init__(self)
        self.set_icon(icon.pixbuf)
        self.set_position(gtk.WIN_POS_MOUSE)
        self.set_transient_for(parent)
        self.set_destroy_with_parent(True)
        self.set_name("Slugathon")
        self.set_copyright("Copyright (c) 2003-2012 David Ripton")

        license_fn = fileutils.basedir(os.path.join("docs", "COPYING.txt"))
        with open(license_fn) as fil:
            st = fil.read()
        self.set_license(st)
        self.set_wrap_license(False)

        version_fn = fileutils.basedir(os.path.join("docs", "version.txt"))
        try:
            with open(version_fn) as fil:
                version = fil.read().strip()
        except IOError:
            version = "unknown"
        self.set_version(version)

        self.set_authors([
            "David Ripton",
        ])
        self.set_artists([
            "Chris Byler",
            "Keith Carter",
            "Chris Howe",
            "Klint Hull",
            "David Lum",
            "John Lum",
            "Agustin Martin",
            "Tchula Ripton",
            "Jerry Reiger",
            "Josh Smith",
            "Sakis Spyropoulos",
            "D. U. Thibault",
        ])

        self.set_logo(icon.pixbuf)
        self.set_website("http://github.com/dripton/Slugathon")
        self.connect("response", self.cb_response)
        self.show()
Exemplo n.º 9
0
 def __init__(self, legion, show_height, location=(0,0), scale=15):
     size = CHIT_SCALE_FACTOR * scale
     super().__init__(location, (size, size))
     self.legion = legion
     self.name = legion.markerid
     self.chit_scale = CHIT_SCALE_FACTOR * scale
     self.show_height = show_height
     self.image_path = fileutils.basedir("images/legion/{}.png".format(self.name))
     self.location = None    # (x, y) of top left corner
     image = self.render_image()
     self.add(image)
Exemplo n.º 10
0
    def __init__(self, parent):
        gtk.AboutDialog.__init__(self)
        self.set_icon(icon.pixbuf)
        self.set_position(gtk.WIN_POS_MOUSE)
        self.set_transient_for(parent)
        self.set_destroy_with_parent(True)
        self.set_name("Slugathon")
        self.set_copyright("Copyright (c) 2003-2012 David Ripton")

        license_fn = fileutils.basedir(os.path.join("docs", "COPYING.txt"))
        with open(license_fn) as fil:
            st = fil.read()
        self.set_license(st)
        self.set_wrap_license(False)

        version_fn = fileutils.basedir(os.path.join("docs", "version.txt"))
        try:
            with open(version_fn) as fil:
                version = fil.read().strip()
        except IOError:
            version = "unknown"
        self.set_version(version)

        self.set_authors(["David Ripton", ])
        self.set_artists(["Chris Byler",
                          "Keith Carter",
                          "Chris Howe",
                          "Klint Hull",
                          "David Lum",
                          "John Lum",
                          "Agustin Martin",
                          "Tchula Ripton",
                          "Jerry Reiger",
                          "Josh Smith",
                          "Sakis Spyropoulos",
                          "D. U. Thibault", ])

        self.set_logo(icon.pixbuf)
        self.set_website("http://github.com/dripton/Slugathon")
        self.connect("response", self.cb_response)
        self.show()
Exemplo n.º 11
0
    def __init__(self,
                 creature,
                 playercolor,
                 scale=15,
                 dead=False,
                 rotate=0,
                 outlined=False,
                 name=None):
        self.creature = creature
        if creature is None:
            if name is None:
                self.name = "QuestionMark"
            else:
                self.name = name
        else:
            self.name = creature.name
        self.dead = dead
        # Convert from degrees to radians, and from GTK rotation direction
        # to Cairo.
        self.rotate = -rotate * math.pi / 180
        self.outlined = outlined
        self.location = None  # (x, y) of top left corner
        self.chit_scale = CHIT_SCALE_FACTOR * scale

        if creature and creature.name in ["Titan", "Angel"]:
            self.bases = [self.name + playercolor]
        else:
            self.bases = [self.name]
        if creature:
            color_name = creature.color_name
            if creature.flies and creature.rangestrikes:
                self.bases.append("FlyingRangestrikeBase")
            elif creature.flies:
                self.bases.append("FlyingBase")
            elif creature.rangestrikes:
                self.bases.append("RangestrikeBase")
        else:
            color_name = "black"
        if color_name == "by_player":
            color_name = "titan_%s" % playercolor.lower()
        self.rgb = guiutils.rgb_to_float(colors.rgb_colors[color_name])

        self.paths = [
            fileutils.basedir("images/%s/%s.png" % (self.IMAGE_DIR, base))
            for base in self.bases
        ]

        self.event_box = gtk.EventBox()
        self.event_box.chit = self
        self.image = gtk.Image()
        self.event_box.add(self.image)
        self.build_image()
Exemplo n.º 12
0
    def __init__(self, creature, playercolor, scale=15, dead=False,
                 rotate=0, outlined=False, name=None):
        self.creature = creature
        if creature is None:
            if name is None:
                self.name = "QuestionMark"
            else:
                self.name = name
        else:
            self.name = creature.name
        self.dead = dead
        # Convert from degrees to radians, and from GTK rotation direction
        # to Cairo.
        self.rotate = -rotate * math.pi / 180
        self.outlined = outlined
        self.location = None    # (x, y) of top left corner
        self.chit_scale = CHIT_SCALE_FACTOR * scale

        if creature and creature.name in ["Titan", "Angel"]:
            self.bases = [self.name + playercolor]
        else:
            self.bases = [self.name]
        if creature:
            color_name = creature.color_name
            if creature.flies and creature.rangestrikes:
                self.bases.append("FlyingRangestrikeBase")
            elif creature.flies:
                self.bases.append("FlyingBase")
            elif creature.rangestrikes:
                self.bases.append("RangestrikeBase")
        else:
            color_name = "black"
        if color_name == "by_player":
            color_name = "titan_%s" % playercolor.lower()
        self.rgb = guiutils.rgb_to_float(colors.rgb_colors[color_name])

        self.paths = [fileutils.basedir("images/%s/%s.png" %
                      (self.IMAGE_DIR, base)) for base in self.bases]

        self.event_box = Gtk.EventBox()
        self.event_box.chit = self
        self.image = Gtk.Image()
        self.event_box.add(self.image)
        self.build_image()
Exemplo n.º 13
0
    def init_overlay(self):
        """Setup the overlay with terrain name and image."""
        scale = self.guiboard.scale
        self.bboxsize = (6 * scale, int(3 * SQRT3 * scale))

        myboxsize = [0.85 * mag for mag in self.bboxsize]
        self.dest_x = int(round(self.center[0] - myboxsize[0] / 2.))
        self.dest_y = int(round(self.center[1] - myboxsize[1] / 2.))

        image_filename = fileutils.basedir("images/masterhex",
                                           self.masterhex.overlay_filename)
        input_surface = cairo.ImageSurface.create_from_png(image_filename)
        input_width = input_surface.get_width()
        input_height = input_surface.get_height()
        output_width = int(round(myboxsize[0]))
        output_height = int(round(myboxsize[1]))
        self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                          output_width, output_height)
        ctx = cairo.Context(self.surface)
        ctx.scale(float(output_width) / input_width,
                  float(output_height) / input_height)
        ctx.move_to(0, 0)
        ctx.set_source_surface(input_surface)
        ctx.paint()
Exemplo n.º 14
0
    def init_overlay(self):
        """Setup the overlay with terrain name and image."""
        scale = self.guiboard.scale
        self.bboxsize = (6 * scale, int(3 * SQRT3 * scale))

        myboxsize = [0.85 * mag for mag in self.bboxsize]
        self.dest_x = int(round(self.center[0] - myboxsize[0] / 2.))
        self.dest_y = int(round(self.center[1] - myboxsize[1] / 2.))

        image_filename = fileutils.basedir("images/masterhex",
                                           self.masterhex.overlay_filename)
        input_surface = cairo.ImageSurface.create_from_png(image_filename)
        input_width = input_surface.get_width()
        input_height = input_surface.get_height()
        output_width = int(round(myboxsize[0]))
        output_height = int(round(myboxsize[1]))
        self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                          output_width, output_height)
        ctx = cairo.Context(self.surface)
        ctx.scale(float(output_width) / input_width,
                  float(output_height) / input_height)
        ctx.move_to(0, 0)
        ctx.set_source_surface(input_surface)
        ctx.paint()
Exemplo n.º 15
0
def test_basedir_MEIPASS2():
    exepath = "/src/Slugathon/dist/slugathon.exe"
    os.environ["_MEIPASS2"] = exepath
    assert fileutils.basedir("images").startswith(exepath)
Exemplo n.º 16
0
def test_basedir_MEIPASS2():
    exepath = "/src/Slugathon/dist/slugathon.exe"
    os.environ["_MEIPASS2"] = exepath
    assert fileutils.basedir("images").startswith(exepath)
Exemplo n.º 17
0
"""Just a place to load the icon image."""

__copyright__ = "Copyright (c) 2005-2011 David Ripton"
__license__ = "GNU GPL v2"

import os

import gtk

from slugathon.util import fileutils


pixbuf = gtk.gdk.pixbuf_new_from_file(fileutils.basedir(
    os.path.join("images", "creature", "Serpent.png")))
Exemplo n.º 18
0
import cairo
from gi.repository import Pango, PangoCairo

from slugathon.util import guiutils, colors, sliceborder, fileutils


SQRT3 = math.sqrt(3.0)
RAD_TO_DEG = 180. / math.pi

# Where to place the label, by hexside.  Derived experimentally.
x_font_position = [0.5, 0.7, 0.7, 0.5, 0.35, 0.35]
y_font_position = [0.2, 0.2, 0.8, 0.8, 0.8, 0.2]

rp = guiutils.roundpoint

IMAGE_DIR = fileutils.basedir("images/battlehex")


class GUIBattleHex(object):

    def __init__(self, battlehex, guimap):
        self.battlehex = battlehex
        self.guimap = guimap
        scale = self.guimap.scale
        # Leftmost point
        self.cx = (battlehex.x + 1) * 3 * scale
        # Uppermost point
        self.cy = battlehex.y * 2 * SQRT3 * scale
        if battlehex.down:
            self.cy += SQRT3 * scale
        self.fillcolor = self.find_fillcolor()
Exemplo n.º 19
0
"""Just a place to load the icon image."""

__copyright__ = "Copyright (c) 2005-2011 David Ripton"
__license__ = "GNU GPL v2"

import os

import gtk

from slugathon.util import fileutils

pixbuf = gtk.gdk.pixbuf_new_from_file(
    fileutils.basedir(os.path.join("images", "creature", "Serpent.png")))
Exemplo n.º 20
0
def test_basedir():
    assert fileutils.basedir().endswith("/slugathon")
    assert fileutils.basedir("images").endswith("/slugathon/images")
    assert fileutils.basedir("images/creature/titan").endswith("/slugathon/images/creature/titan")
    assert fileutils.basedir("images", "creature", "titan").endswith("/slugathon/images/creature/titan")
Exemplo n.º 21
0
"""Just a place to load the icon image."""

__copyright__ = "Copyright (c) 2005-2011 David Ripton"
__license__ = "GNU GPL v2"

import os

from gi.repository import GdkPixbuf

from slugathon.util import fileutils


pixbuf = GdkPixbuf.Pixbuf.new_from_file(fileutils.basedir(
    os.path.join("images", "creature", "Serpent.png")))
Exemplo n.º 22
0
import cairo
import pango
import pangocairo

from slugathon.util import guiutils, colors, sliceborder, fileutils

SQRT3 = math.sqrt(3.0)
RAD_TO_DEG = 180. / math.pi

# Where to place the label, by hexside.  Derived experimentally.
x_font_position = [0.5, 0.7, 0.7, 0.5, 0.35, 0.35]
y_font_position = [0.2, 0.2, 0.8, 0.8, 0.8, 0.2]

rp = guiutils.roundpoint

IMAGE_DIR = fileutils.basedir("images/battlehex")


class GUIBattleHex(object):
    def __init__(self, battlehex, guimap):
        self.battlehex = battlehex
        self.guimap = guimap
        scale = self.guimap.scale
        # Leftmost point
        self.cx = (battlehex.x + 1) * 3 * scale
        # Uppermost point
        self.cy = battlehex.y * 2 * SQRT3 * scale
        if battlehex.down:
            self.cy += SQRT3 * scale
        self.fillcolor = self.find_fillcolor()
        self.selected = False