Esempio n. 1
0
 def getIconByRating (cls, rating, size=16):
     assert isinstance(rating, int), "rating not an int: %s" % str(rating)        
     if rating >= 1900:
         return load_icon(size, "weather-storm")
     elif rating >= 1600:
         return load_icon(size, "weather-showers")
     elif rating >= 1300:
         return load_icon(size, "weather-overcast")
     elif rating >= 1000:
         return load_icon(size, "weather-few-clouds")
     else:
         return load_icon(size, "weather-clear")
Esempio n. 2
0
 def getIconByRating(cls, rating, size=16):
     assert isinstance(rating, int), "rating not an int: %s" % str(rating)
     if rating >= 1900:
         return load_icon(size, "weather-storm")
     elif rating >= 1600:
         return load_icon(size, "weather-showers")
     elif rating >= 1300:
         return load_icon(size, "weather-overcast")
     elif rating >= 1000:
         return load_icon(size, "weather-few-clouds")
     else:
         return load_icon(size, "weather-clear")
Esempio n. 3
0
 def getIcon (self, size=16, gametype=None):
     assert isinstance(size, int), "size not an int: %s" % str(size)
     if self.isGuest():
         return load_icon(size, "stock_people", "system-users")
     elif self.isComputer():
         return load_icon(size, "computer", "stock_notebook")
     elif self.isAdmin():
         return load_icon(size, "security-high", "stock_book_blue")
     else:
         if gametype:
             rating = self.getRatingByGameType(gametype)
         else:
             rating = self.getStrength()
         return self.getIconByRating(rating, size)
Esempio n. 4
0
 def getIcon(self, size=16, gametype=None):
     assert isinstance(size, int), "size not an int: %s" % str(size)
     if self.isGuest():
         return load_icon(size, "stock_people", "system-users")
     elif self.isComputer():
         return load_icon(size, "computer", "stock_notebook")
     elif self.isAdmin():
         return load_icon(size, "security-high", "stock_book_blue")
     else:
         if gametype:
             rating = self.getRatingByGameType(gametype)
         else:
             rating = self.getStrength()
         return self.getIconByRating(rating, size)
Esempio n. 5
0
    def addItem(self, text, stock=None):
        if stock is None:
            item = Gtk.MenuItem(text)
        else:
            item = Gtk.ImageMenuItem()
            item.set_name(text)
            label = Gtk.Label(label=text)
            label.props.xalign = 0
            if isinstance(stock, str):
                stock = load_icon(12, stock)
            image = Gtk.Image()
            image.set_from_pixbuf(stock)
            hbox = Gtk.HBox()
            hbox.set_spacing(6)
            hbox.pack_start(image, False, False, 0)
            hbox.add(label)
            item.add(hbox)
            hbox.show_all()

        item.connect("activate", self.menu_item_activate, len(self._items))
        self.menu.append(item)
        self._items += [(text, stock)]
        item.show()
        if self.active < 0:
            self.active = 0
Esempio n. 6
0
    def addItem(self, text, stock=None):
        if stock is None:
            item = Gtk.MenuItem(text)
        else:
            item = Gtk.ImageMenuItem()
            item.set_name(text)
            label = Gtk.Label(label=text)
            label.props.xalign = 0
            if isinstance(stock, str):
                stock = load_icon(12, stock)
            image = Gtk.Image()
            image.set_from_pixbuf(stock)
            hbox = Gtk.HBox()
            hbox.set_spacing(6)
            hbox.pack_start(image, False, False, 0)
            hbox.add(label)
            item.add(hbox)
            hbox.show_all()

        item.connect("activate", self.menu_item_activate, len(self._items))
        self.menu.append(item)
        self._items += [(text, stock)]
        item.show()
        if self.active < 0:
            self.active = 0
Esempio n. 7
0
 def __init__(self, icon_name):
     GObject.GObject.__init__(self)
     self.id2iter = {}
     
     self.icon_name = icon_name
     pm = Gtk.ListStore(str,str,int)
     self.props.model = pm
     self.idSet = set()
     
     self.set_headers_visible(False)
     self.set_tooltip_column(1)
     self.set_search_column(1)
     
     # First column
     crt = Gtk.CellRendererText()
     crt.props.ellipsize = Pango.EllipsizeMode.END
     self.leftcol = Gtk.TreeViewColumn("", crt, text=1)
     self.leftcol.set_expand(True)
     self.append_column(self.leftcol)
     
     # Second column
     pixbuf = load_icon(16, icon_name)
     crp = Gtk.CellRendererPixbuf()
     crp.props.pixbuf = pixbuf
     self.rightcol = Gtk.TreeViewColumn("", crp)
     self.append_column(self.rightcol)
     
     # Mouse
     self.pressed = None
     self.stdcursor = Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR)
     self.linkcursor = Gdk.Cursor.new(Gdk.CursorType.HAND2)
     self.connect("button_press_event", self.button_press)
     self.connect("button_release_event", self.button_release)
     self.connect("motion_notify_event", self.motion_notify)
     self.connect("leave_notify_event", self.leave_notify)
     
     # Selection
     self.get_selection().connect("changed", self.selection_changed)
Esempio n. 8
0
    def __init__(self, icon_name):
        GObject.GObject.__init__(self)
        self.id2iter = {}

        self.icon_name = icon_name
        pm = Gtk.ListStore(str, str, int)
        self.props.model = pm
        self.idSet = set()

        self.set_headers_visible(False)
        self.set_tooltip_column(1)
        self.set_search_column(1)

        # First column
        crt = Gtk.CellRendererText()
        crt.props.ellipsize = Pango.EllipsizeMode.END
        self.leftcol = Gtk.TreeViewColumn("", crt, text=1)
        self.leftcol.set_expand(True)
        self.append_column(self.leftcol)

        # Second column
        pixbuf = load_icon(16, icon_name)
        crp = Gtk.CellRendererPixbuf()
        crp.props.pixbuf = pixbuf
        self.rightcol = Gtk.TreeViewColumn("", crp)
        self.append_column(self.rightcol)

        # Mouse
        self.pressed = None
        self.stdcursor = Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR)
        self.linkcursor = Gdk.Cursor.new(Gdk.CursorType.HAND2)
        self.connect("button_press_event", self.button_press)
        self.connect("button_release_event", self.button_release)
        self.connect("motion_notify_event", self.motion_notify)
        self.connect("leave_notify_event", self.leave_notify)

        # Selection
        self.get_selection().connect("changed", self.selection_changed)
Esempio n. 9
0
    def addItem(self, text, stock=None):
        if stock == None:
            item = gtk.MenuItem(text)
        else:
            item = gtk.MenuItem()
            label = gtk.Label(text)
            label.props.xalign = 0
            if type(stock) == str:
                stock = load_icon(12, stock)
            image = gtk.Image()
            image.set_from_pixbuf(stock)
            hbox = gtk.HBox()
            hbox.set_spacing(6)
            hbox.pack_start(image, expand=False, fill=False)
            hbox.add(label)
            item.add(hbox)
            hbox.show_all()

        item.connect("activate", self.menu_item_activate, len(self._items))
        self.menu.append(item)
        self._items += [(text, stock)]
        item.show()
        if self.active < 0: self.active = 0
 def addItem (self, text, stock=None):
     if stock == None:
         item = gtk.MenuItem(text)
     else:
         item = gtk.MenuItem()
         label = gtk.Label(text)
         label.props.xalign = 0
         if type(stock) == str:
             stock = load_icon(12, stock)
         image = gtk.Image()
         image.set_from_pixbuf(stock)            
         hbox = gtk.HBox()
         hbox.set_spacing(6)
         hbox.pack_start(image, expand=False, fill=False)
         hbox.add(label)
         item.add(hbox)
         hbox.show_all()
     
     item.connect("activate", self.menu_item_activate, len(self._items))
     self.menu.append(item)
     self._items += [(text, stock)]
     item.show()
     if self.active < 0: self.active = 0
    def __init__(self, widgets):

        # Init open dialog

        opendialog = gtk.FileChooserDialog(
            _("Open Sound File"), None, gtk.FILE_CHOOSER_ACTION_OPEN,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
             gtk.RESPONSE_ACCEPT))

        for dir in self.SOUND_DIRS:
            if os.path.isdir(dir):
                opendialog.set_current_folder(dir)
                break

        soundfilter = gtk.FileFilter()
        soundfilter.add_custom(
            soundfilter.get_needed(),
            lambda data: data[3] and data[3].startswith("audio/"))
        opendialog.add_filter(soundfilter)
        opendialog.set_filter(soundfilter)

        # Get combo icons

        icons = ((_("No sound"), "audio-volume-muted", "audio-volume-muted"),
                 (_("Beep"), "stock_bell", "audio-x-generic"),
                 (_("Select sound file..."), "gtk-open", "document-open"))

        items = []
        for level, stock, altstock in icons:
            image = load_icon(16, stock, altstock)
            items += [(image, level)]

        audioIco = load_icon(16, "audio-x-generic")

        # Set-up combos

        def callback(combobox, index):
            if combobox.get_active() == SOUND_SELECT:
                if opendialog.run() == gtk.RESPONSE_ACCEPT:
                    uri = opendialog.get_uri()
                    model = combobox.get_model()
                    conf.set("sounduri%d" % index, uri)
                    label = os.path.split(uri)[1]
                    if len(model) == 3:
                        model.append([audioIco, label])
                    else:
                        model.set(model.get_iter((3, )), 1, label)
                    combobox.set_active(3)
                else:
                    combobox.set_active(
                        conf.get("soundcombo%d" % index, SOUND_MUTE))
                opendialog.hide()

        for i in xrange(self.COUNT_OF_SOUNDS):
            combo = widgets["soundcombo%d" % i]
            uistuff.createCombo(combo, items)
            combo.set_active(0)
            combo.connect("changed", callback, i)

            label = widgets["soundlabel%d" % i]
            label.props.mnemonic_widget = combo

            uri = conf.get("sounduri%d" % i, "")
            if os.path.isfile(uri[7:]):
                model = combo.get_model()
                model.append([audioIco, os.path.split(uri)[1]])
                combo.set_active(3)

        for i in xrange(self.COUNT_OF_SOUNDS):
            if conf.get("soundcombo%d"%i, SOUND_MUTE) == SOUND_URI and \
                    not os.path.isfile(conf.get("sounduri%d"%i,"")[7:]):
                conf.set("soundcombo%d" % i, SOUND_MUTE)
            uistuff.keep(widgets["soundcombo%d" % i], "soundcombo%d" % i)
            #widgets["soundcombo%d"%i].set_active(conf.get("soundcombo%d"%i, SOUND_MUTE))

        # Init play button

        def playCallback(button, index):
            SoundTab.playAction(index)

        for i in range(self.COUNT_OF_SOUNDS):
            button = widgets["soundbutton%d" % i]
            button.connect("clicked", playCallback, i)

        # Init 'use sound" checkbutton

        def checkCallBack(*args):
            checkbox = widgets["useSounds"]
            widgets["frame23"].set_property("sensitive", checkbox.get_active())

        conf.notify_add("useSounds", checkCallBack)
        widgets["useSounds"].set_active(True)
        uistuff.keep(widgets["useSounds"], "useSounds")
        checkCallBack()

        def soundError(player, gstmessage):
            widgets["useSounds"].set_sensitive(False)
            widgets["useSounds"].set_active(False)

        self.getPlayer().connect("error", soundError)
Esempio n. 12
0
    def __init__(self, gamemodel=None):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
        self.gamemodel = gamemodel

        # States for the color generator
        self.colors = {}
        self.startpoint = random.random()

        # Inits the read view
        self.readView = Gtk.TextView()
        set_textview_color(self.readView)

        self.sw = Gtk.ScrolledWindow()
        self.sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)

        self.sw.add(self.readView)
        self.readView.set_editable(False)
        self.readView.set_cursor_visible(False)
        self.readView.props.wrap_mode = Gtk.WrapMode.WORD
        self.readView.props.pixels_below_lines = 1
        self.readView.props.pixels_above_lines = 2
        self.readView.props.left_margin = 2

        if isinstance(self.gamemodel, ICGameModel):
            self.refresh = Gtk.Image()
            self.refresh.set_from_pixbuf(load_icon(16, "view-refresh",
                                                   "stock-refresh"))
            label = _("Observers")
            self.obs_btn = Gtk.Button()
            self.obs_btn.set_image(self.refresh)
            self.obs_btn.set_label(label)
            self.obs_btn.connect("clicked", self.on_obs_btn_clicked)

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

            # Inits the observers view
            self.obsView = Gtk.TextView()
            self.obsView.set_cursor_visible(False)
            set_textview_color(self.obsView)

            self.obsView.set_editable(False)
            self.obsView.props.wrap_mode = Gtk.WrapMode.WORD
            self.obsView.props.pixels_below_lines = 1
            self.obsView.props.pixels_above_lines = 2
            self.obsView.props.left_margin = 2

            text_buffer = self.obsView.get_buffer()
            iter = text_buffer.get_end_iter()
            anchor1 = text_buffer.create_child_anchor(iter)
            self.obsView.add_child_at_anchor(self.obs_btn, anchor1)
            self.button_tag = text_buffer.create_tag("observers")
            text_buffer.insert_with_tags_by_name(iter, " ", "observers")
            text_buffer.insert(iter, "\n")

            vbox.pack_start(self.obsView, False, True, 0)
            vbox.pack_start(self.sw, True, True, 0)

            self.pack_start(vbox, True, True, 0)
        else:
            self.pack_start(self.sw, True, True, 0)

        # Create a 'log mark' in the beginning of the text buffer. Because we
        # query the log asynchronously and in chunks, we can use this to insert
        # it correctly after previous log messages, but before the new messages.
        start = self.readView.get_buffer().get_start_iter()
        self.readView.get_buffer().create_mark("logMark", start)

        # Inits the write view
        self.writeView = Gtk.Entry()
        self.pack_start(self.writeView, False, False, 0)

        self.writeView.connect("key-press-event", self.onKeyPress)
Esempio n. 13
0
# -*- coding: UTF-8 -*-
from __future__ import print_function

import os

from gi.repository import Gtk, GObject
from gi.repository.GdkPixbuf import Pixbuf

from pychess.perspectives import perspective_manager
from pychess.Utils.IconLoader import load_icon
from pychess.Savers.database import Database
from pychess.System import uistuff

pdb_icon = load_icon(32, "pychess")
pgn_icon = load_icon(32, "application-x-chess-pgn", "pychess")
CLIPBASE = "Clipbase"


class SwitcherPanel(Gtk.IconView):
    __gsignals__ = {
        'chessfile_switched':
        (GObject.SignalFlags.RUN_FIRST, None, (object, )),
    }

    def __init__(self, gamelist):
        GObject.GObject.__init__(self)
        self.gamelist = gamelist
        self.widgets = uistuff.GladeWidgets("PyChess.glade")

        self.persp = perspective_manager.get_perspective("database")
        self.persp.connect("chessfile_opened", self.on_chessfile_opened)
Esempio n. 14
0
from pychess.widgets import ImageMenu
from pychess.widgets import mainwindow
from pychess.widgets.BoardControl import BoardControl
from pychess.Savers import fen, pgn
from pychess.Savers.ChessFile import LoadingError
from pychess.Variants import variants
from pychess.Variants.normal import NormalBoard
from pychess.perspectives import perspective_manager
from pychess.perspectives.games import enddir

# ===============================================================================
# We init most dialog icons global to make them accessibly to the
# Background.Taskers so they have a similar look.
# ===============================================================================
big_time = get_pixbuf("glade/stock_alarm.svg")
big_people = load_icon(48, "stock_people", "system-users")
iwheels = load_icon(24, "gtk-execute", "system-run")
ipeople = load_icon(24, "stock_people", "system-users")
inotebook = load_icon(24, "stock_notebook", "computer")

weather_icons = ("clear", "clear-night", "few-clouds", "few-clouds-night",
                 "fog", "overcast", "severe-alert", "showers-scattered",
                 "showers", "storm")
skillToIcon = {}
# Used by TaskerManager. Put here to help synchronization
skillToIconLarge = {}
for i, icon in enumerate(weather_icons, start=1):
    skillToIcon[2 * i - 1] = get_pixbuf("glade/16x16/weather-%s.png" % icon)
    skillToIcon[2 * i] = get_pixbuf("glade/16x16/weather-%s.png" % icon)
    skillToIconLarge[2 * i - 1] = get_pixbuf("glade/48x48/weather-%s.png" % icon)
    skillToIconLarge[2 * i] = get_pixbuf("glade/48x48/weather-%s.png" % icon)
Esempio n. 15
0
from pychess.widgets import ImageMenu
from pychess.widgets import mainwindow
from pychess.widgets.BoardControl import BoardControl
from pychess.Savers import fen, pgn
from pychess.Savers.ChessFile import LoadingError
from pychess.Variants import variants
from pychess.Variants.normal import NormalBoard
from pychess.perspectives import perspective_manager
from pychess.perspectives.games import enddir

# ===============================================================================
# We init most dialog icons global to make them accessibly to the
# Background.Taskers so they have a similar look.
# ===============================================================================
big_time = get_pixbuf("glade/stock_alarm.svg")
big_people = load_icon(48, "stock_people", "system-users")
iwheels = load_icon(24, "gtk-execute", "system-run")
ipeople = load_icon(24, "stock_people", "system-users")
inotebook = load_icon(24, "stock_notebook", "computer")

weather_icons = ("clear", "clear-night", "few-clouds", "few-clouds-night",
                 "fog", "overcast", "severe-alert", "showers-scattered",
                 "showers", "storm")
skillToIcon = {}
# Used by TaskerManager. Put here to help synchronization
skillToIconLarge = {}
for i, icon in enumerate(weather_icons, start=1):
    skillToIcon[2 * i - 1] = get_pixbuf("glade/16x16/weather-%s.png" % icon)
    skillToIcon[2 * i] = get_pixbuf("glade/16x16/weather-%s.png" % icon)
    skillToIconLarge[2 * i - 1] = get_pixbuf("glade/48x48/weather-%s.png" %
                                             icon)
Esempio n. 16
0
                          self.height - 3)
        context.stroke()

    def on_get_size(self, widget, cell_area=None):
        if cell_area:
            y_loc = int(cell_area.height / 2. - self.height / 2.) + cell_area.y
            x_loc = cell_area.x
        else:
            y_loc = 0
            x_loc = 0
        return (x_loc + 1, y_loc + 1, self.width + 2, self.height + 2)


GObject.type_register(BulletCellRenderer)

add_icon = load_icon(16, "gtk-add", "list-add")
remove_icon = load_icon(16, "gtk-remove", "list-remove")


class TextImageTree(Gtk.TreeView):
    """ :Description: Defines a tree with two columns.
        The first one has text. The second one a clickable stock_icon
    """

    __gsignals__ = {
        'activated': (GObject.SignalFlags.RUN_FIRST, None, (str, str, int)),
        'selected': (GObject.SignalFlags.RUN_FIRST, None, (str, int))
    }

    def __init__(self, icon):
        GObject.GObject.__init__(self)
Esempio n. 17
0
from gi.repository import Gtk

from pychess.Utils.IconLoader import get_pixbuf, load_icon
# from pychess.widgets.WebKitBrowser import open_link

main_window = None

gtk_close = load_icon(16, "gtk-close", "window-close")


def mainwindow():
    return main_window


def createImage(pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image


def createAlignment(top, right, bottom, left):
    align = Gtk.Alignment.new(.5, .5, 1, 1)
    align.set_property("top-padding", top)
    align.set_property("right-padding", right)
    align.set_property("bottom-padding", bottom)
    align.set_property("left-padding", left)
    return align


def new_notebook(name=None):
    def customGetTabLabelText(child):
Esempio n. 18
0
from pychess.perspectives.database.OpeningTreePanel import OpeningTreePanel
from pychess.perspectives.database.FilterPanel import FilterPanel
from pychess.perspectives.database.PreviewPanel import PreviewPanel
from pychess.System.prefix import addUserConfigPrefix
from pychess.widgets.pydock.PyDockTop import PyDockTop
from pychess.widgets.pydock import EAST, SOUTH, CENTER
from pychess.widgets import mainwindow, new_notebook, createImage, createAlignment, gtk_close
from pychess.widgets import gamewidget
from pychess.Database.model import create_indexes, drop_indexes
from pychess.Database.PgnImport import PgnImport, download_file
from pychess.Database.JvR import JvR
from pychess.Savers import fen, epd, olv
from pychess.Savers.pgn import PGNFile
from pychess.System.protoopen import protoopen

pgn_icon = load_icon(24, "application-x-chess-pgn", "pychess")
BOOK_DEPTH = 8


class Database(GObject.GObject, Perspective):
    __gsignals__ = {
        'chessfile_opened0': (GObject.SignalFlags.RUN_FIRST, None, (object, )),
        'chessfile_opened': (GObject.SignalFlags.RUN_FIRST, None, (object, )),
        'chessfile_closed': (GObject.SignalFlags.RUN_FIRST, None, ()),
        'chessfile_imported':
        (GObject.SignalFlags.RUN_FIRST, None, (object, )),
        'bookfile_created': (GObject.SignalFlags.RUN_FIRST, None, ()),
    }

    def __init__(self):
        GObject.GObject.__init__(self)
Esempio n. 19
0
    align.set_property("bottom-padding", bottom)
    align.set_property("left-padding", left)
    return align

def cleanNotebook ():
    notebook = Gtk.Notebook()
    notebook.set_show_tabs(False)
    notebook.set_show_border(False)
    return notebook

def createImage (pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image

light_on = load_icon(16, "stock_3d-light-on", "weather-clear")
light_off = load_icon(16, "stock_3d-light-off", "weather-clear-night")
gtk_close = load_icon(16, "gtk-close")

media_previous = load_icon(16, "gtk-media-previous-ltr")
media_rewind = load_icon(16, "gtk-media-rewind-ltr")
media_forward = load_icon(16, "gtk-media-forward-ltr")
media_next = load_icon(16, "gtk-media-next-ltr")

path = prefix.addDataPrefix("sidepanel")
postfix = "Panel.py"
files = [f[:-3] for f in os.listdir(path) if f.endswith(postfix)]
sidePanels = [imp.load_module(f, *imp.find_module(f, [path])) for f in files]

dockLocation = addUserConfigPrefix("pydock.xml")
Esempio n. 20
0
        context.rectangle (x+1.5, y+1.5, self.width-3, self.height-3)
        context.stroke ()

    def on_get_size(self, widget, cell_area=None):
        if cell_area:
            y = int(cell_area.height/2.-self.height/2.) + cell_area.y
            x = cell_area.x
        else:
            y = 0
            x = 0
        return (x+1, y+1, self.width+2, self.height+2)

GObject.type_register(BulletCellRenderer)


add_icon = load_icon(16, "gtk-add", "list-add")
remove_icon = load_icon(16, "gtk-remove", "list-remove")

class TextImageTree (Gtk.TreeView):
    """ Defines a tree with two columns.
        The first one has text. The seccond one a clickable stock_icon """

    __gsignals__ = {
        'activated' : (GObject.SignalFlags.RUN_FIRST, None, (str,str,int)),
        'selected' : (GObject.SignalFlags.RUN_FIRST, None, (str,int))
    }

    def __init__(self, icon):
        GObject.GObject.__init__(self)
        self.id2iter = {}
Esempio n. 21
0
    def load(self, widgets, connection, lounge):
        self.widgets = widgets
        self.connection = connection
        self.lounge = lounge

        __widget__ = lounge.games_list

        self.games = {}
        self.recpix = load_icon(16, "media-record")
        self.clearpix = get_pixbuf("glade/board.png")
        self.tv = self.widgets["gametreeview"]
        self.store = Gtk.ListStore(FICSGame, GdkPixbuf.Pixbuf, str, int, str,
                                   int, str, str)

        self.game_filter = self.store.filter_new()
        self.game_filter.set_visible_func(self.game_filter_func)

        self.filter_toggles = {}
        self.filter_buttons = ("standard_toggle", "blitz_toggle", "lightning_toggle", "variant_toggle")
        for widget in self.filter_buttons:
            uistuff.keep(self.widgets[widget], widget)
            self.widgets[widget].connect("toggled", self.on_filter_button_toggled)
            initial = conf.get(widget, True)
            self.filter_toggles[widget] = initial
            self.widgets[widget].set_active(initial)

        self.model = self.game_filter.sort_new_with_model()
        self.tv.set_model(self.model)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
        self.addColumns(self.tv,
                        "FICSGame",
                        "",
                        _("White"),
                        _("Rating"),
                        _("Black"),
                        _("Rating"),
                        _("Type"),
                        _("Rated"),
                        hide=[0],
                        pix=[1])

        self.tv.get_model().set_sort_func(0, self.pixCompareFunction, 1)
        for i in range(1, 7):
            self.tv.get_model().set_sort_func(i, self.compareFunction, i)
        self.prev_sort_column_id = []
        self.model.connect("sort-column-changed", self.on_sort_column_change)

        self.tv.set_has_tooltip(True)
        self.tv.connect("query-tooltip", self.on_query_tooltip)
        self.selection = self.tv.get_selection()
        self.selection.connect("changed", self.onSelectionChanged)
        self.onSelectionChanged(self.selection)

        try:
            self.tv.set_search_position_func(self.lowLeftSearchPosFunc, None)
        except AttributeError:
            # Unknow signal name is raised by gtk < 2.10
            pass

        def searchCallback(model, column, key, sel_iter, user_data):
            if model.get_value(sel_iter, 2).lower().startswith(key) or \
                    model.get_value(sel_iter, 4).lower().startswith(key):
                return False
            return True

        self.tv.set_search_equal_func(searchCallback, None)

        self.connection.games.connect("FICSGameCreated", self.onGameAdd)
        self.connection.games.connect("FICSGameEnded", self.onGameRemove)
        self.widgets["observeButton"].connect("clicked", self.on_observe)
        self.tv.connect("row-activated", self.on_observe)
        self.connection.bm.connect("obsGameCreated", self.onGameObserved)
        self.connection.bm.connect("obsGameUnobserved", self.onGameUnobserved)

        self.tv.connect('button-press-event', self.button_press_event)
        self.createLocalMenu((OBSERVE, FOLLOW, SEPARATOR, FINGER, ARCHIVED))

        return __widget__
Esempio n. 22
0
    notebook = Gtk.Notebook()
    if name is not None:
        notebook.set_name(name)
    notebook.get_tab_label_text = customGetTabLabelText
    notebook.set_show_tabs(False)
    notebook.set_show_border(False)
    return notebook


def createImage(pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image


light_on = load_icon(16, "stock_3d-light-on", "weather-clear")
light_off = load_icon(16, "stock_3d-light-off", "weather-clear-night")
gtk_close = load_icon(16, "gtk-close", "window-close")

media_previous = load_icon(24, "gtk-media-previous-ltr", "media-skip-backward")
media_rewind = load_icon(24, "gtk-media-rewind-ltr", "media-seek-backward")
media_forward = load_icon(24, "gtk-media-forward-ltr", "media-seek-forward")
media_next = load_icon(24, "gtk-media-next-ltr", "media-skip-forward")
media_eject = load_icon(24, "player-eject", "media-eject")

path = prefix.addDataPrefix("sidepanel")
postfix = "Panel.py"
files = [f[:-3] for f in os.listdir(path) if f.endswith(postfix)]
sidePanels = [imp.load_module(f, *imp.find_module(f, [path])) for f in files]

dockLocation = addUserConfigPrefix("pydock.xml")
Esempio n. 23
0
    align.set_property("bottom-padding", bottom)
    align.set_property("left-padding", left)
    return align

def cleanNotebook ():
    notebook = Gtk.Notebook()
    notebook.set_show_tabs(False)
    notebook.set_show_border(False)
    return notebook

def createImage (pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image

light_on = load_icon(16, "stock_3d-light-on", "weather-clear")
light_off = load_icon(16, "stock_3d-light-off", "weather-clear-night")
gtk_close = load_icon(16, "gtk-close")

media_previous = load_icon(24, "gtk-media-previous-ltr")
media_rewind = load_icon(24, "gtk-media-rewind-ltr")
media_forward = load_icon(24, "gtk-media-forward-ltr")
media_next = load_icon(24, "gtk-media-next-ltr")

path = prefix.addDataPrefix("sidepanel")
postfix = "Panel.py"
files = [f[:-3] for f in os.listdir(path) if f.endswith(postfix)]
sidePanels = [imp.load_module(f, *imp.find_module(f, [path])) for f in files]

dockLocation = addUserConfigPrefix("pydock.xml")
Esempio n. 24
0
    def __init__(self, widgets):

        # Init open dialog

        opendialog = Gtk.FileChooserDialog(
            _("Open Sound File"), None, Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
             Gtk.ResponseType.ACCEPT))

        for dir in self.SOUND_DIRS:
            if os.path.isdir(dir):
                opendialog.set_current_folder(dir)
                break

        soundfilter = Gtk.FileFilter()
        soundfilter.set_name(_("Sound files"))
        soundfilter.add_mime_type("audio/%s" % EXT)
        soundfilter.add_pattern("*.%s" % EXT)
        opendialog.add_filter(soundfilter)

        # Get combo icons

        icons = ((_("No sound"), "audio-volume-muted", "audio-volume-muted"),
                 (_("Beep"), "stock_bell", "audio-x-generic"),
                 (_("Select sound file..."), "gtk-open", "document-open"))

        items = []
        for level, stock, altstock in icons:
            image = load_icon(16, stock, altstock)
            items += [(image, level)]

        audioIco = load_icon(16, "audio-x-generic")

        # Set-up combos

        def callback(combobox, index):
            if combobox.get_active() == SOUND_SELECT:
                if opendialog.run() == Gtk.ResponseType.ACCEPT:
                    uri = opendialog.get_uri()
                    model = combobox.get_model()
                    conf.set("sounduri%d" % index, uri)
                    label = unquote(os.path.split(uri)[1])
                    if len(model) == 3:
                        model.append([audioIco, label])
                    else:
                        model.set(model.get_iter((3, )), 1, label)
                    combobox.set_active(3)
                else:
                    combobox.set_active(conf.get("soundcombo%d" % index,
                                                 SOUND_MUTE))
                opendialog.hide()

        for i in range(self.COUNT_OF_SOUNDS):
            combo = widgets["sound%dcombo" % i]
            uistuff.createCombo(combo, items, name="soundcombo%d" % i)
            # combo.set_active(0)
            combo.connect("changed", callback, i)

            label = widgets["soundlabel%d" % i]
            label.props.mnemonic_widget = combo

            uri = conf.get("sounduri%d" % i, "")
            if os.path.isfile(url2pathname(uri[5:])):
                model = combo.get_model()
                model.append([audioIco, unquote(os.path.split(uri)[1])])
                # combo.set_active(3)

        for i in range(self.COUNT_OF_SOUNDS):
            if conf.get("soundcombo%d" % i, SOUND_MUTE) == SOUND_URI and \
                    not os.path.isfile(url2pathname(conf.get("sounduri%d" % i, "")[5:])):
                conf.set("soundcombo%d" % i, SOUND_MUTE)
            uistuff.keep(widgets["sound%dcombo" % i], "soundcombo%d" % i)

        # Init play button

        def playCallback(button, index):
            SoundTab.playAction(index)

        for i in range(self.COUNT_OF_SOUNDS):
            button = widgets["sound%dbutton" % i]
            button.connect("clicked", playCallback, i)

        # Init 'use sound" checkbutton

        def checkCallBack(*args):
            checkbox = widgets["useSounds"]
            widgets["sounds_frame"].set_property("sensitive", checkbox.get_active())

        conf.notify_add("useSounds", checkCallBack)
        widgets["useSounds"].set_active(True)
        uistuff.keep(widgets["useSounds"], "useSounds")
        checkCallBack()

        if not self.getPlayer().ready:
            widgets["useSounds"].set_sensitive(False)
            widgets["useSounds"].set_active(False)

        uistuff.keep(widgets["alarm_spin"], "alarm_spin", first_value=15)
 def __init__ (self, widgets):
     
     # Init open dialog
     
     opendialog = gtk.FileChooserDialog (
             _("Open Sound File"), None, gtk.FILE_CHOOSER_ACTION_OPEN,
              (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
               gtk.RESPONSE_ACCEPT))
     
     for dir in self.SOUND_DIRS:
         if os.path.isdir(dir):
             opendialog.set_current_folder(dir)
             break
     
     soundfilter = gtk.FileFilter()
     soundfilter.add_custom(soundfilter.get_needed(),
                            lambda data: data[3] and data[3].startswith("audio/"))
     opendialog.add_filter(soundfilter)
     opendialog.set_filter(soundfilter)
     
     # Get combo icons
     
     icons = ((_("No sound"), "audio-volume-muted", "audio-volume-muted"),
              (_("Beep"), "stock_bell", "audio-x-generic"), 
              (_("Select sound file..."), "gtk-open", "document-open"))
     
     items = []
     for level, stock, altstock in icons:
         image = load_icon(16, stock, altstock)
         items += [(image, level)]
     
     audioIco = load_icon(16, "audio-x-generic")
     
     # Set-up combos
     
     def callback (combobox, index):
         if combobox.get_active() == SOUND_SELECT:
             if opendialog.run() == gtk.RESPONSE_ACCEPT:
                 uri = opendialog.get_uri()
                 model = combobox.get_model()
                 conf.set("sounduri%d"%index, uri)
                 label = os.path.split(uri)[1]
                 if len(model) == 3:
                     model.append([audioIco, label])
                 else:
                     model.set(model.get_iter((3,)), 1, label)
                 combobox.set_active(3)
             else:
                 combobox.set_active(conf.get("soundcombo%d"%index,SOUND_MUTE))
             opendialog.hide()
     
     for i in xrange(self.COUNT_OF_SOUNDS):
         combo = widgets["soundcombo%d"%i]
         uistuff.createCombo (combo, items)
         combo.set_active(0)
         combo.connect("changed", callback, i)
         
         label = widgets["soundlabel%d"%i]
         label.props.mnemonic_widget = combo
         
         uri = conf.get("sounduri%d"%i,"")
         if os.path.isfile(uri[7:]):
             model = combo.get_model()
             model.append([audioIco, os.path.split(uri)[1]])
             combo.set_active(3)
     
     for i in xrange(self.COUNT_OF_SOUNDS):
         if conf.get("soundcombo%d"%i, SOUND_MUTE) == SOUND_URI and \
                 not os.path.isfile(conf.get("sounduri%d"%i,"")[7:]):
             conf.set("soundcombo%d"%i, SOUND_MUTE)
         uistuff.keep(widgets["soundcombo%d"%i], "soundcombo%d"%i)
         #widgets["soundcombo%d"%i].set_active(conf.get("soundcombo%d"%i, SOUND_MUTE))
     
     # Init play button
     
     def playCallback (button, index):
         SoundTab.playAction(index)
     
     for i in range (self.COUNT_OF_SOUNDS):
         button = widgets["soundbutton%d"%i]
         button.connect("clicked", playCallback, i)
     
     # Init 'use sound" checkbutton
     
     def checkCallBack (*args):
         checkbox = widgets["useSounds"]
         widgets["frame23"].set_property("sensitive", checkbox.get_active())
     conf.notify_add("useSounds", checkCallBack)
     widgets["useSounds"].set_active(True)
     uistuff.keep(widgets["useSounds"], "useSounds")
     checkCallBack()
     
     def soundError (player, gstmessage):
         widgets["useSounds"].set_sensitive(False)
         widgets["useSounds"].set_active(False)
     self.getPlayer().connect("error", soundError)
Esempio n. 26
0
from pychess.Players.Human import Human
from pychess.widgets import BoardPreview
from pychess.widgets import ionest
from pychess.widgets import ImageMenu
from pychess.widgets.BoardControl import BoardControl
from pychess.Savers import fen, pgn
from pychess.Savers.ChessFile import LoadingError
from pychess.Variants import variants
from pychess.Variants.normal import NormalBoard

#===============================================================================
# We init most dialog icons global to make them accessibly to the
# Background.Taskers so they have a similar look.
#===============================================================================
big_time = get_pixbuf("glade/stock_alarm.svg")
big_people = load_icon(48, "stock_people", "system-users")
iwheels = load_icon(24, "gtk-execute", "system-run")
ipeople = load_icon(24, "stock_people", "system-users")
inotebook = load_icon(24, "stock_notebook", "computer")
speople = load_icon(16, "stock_people", "system-users")
snotebook = load_icon(16, "stock_notebook", "computer")

weather_icons = ("clear", "clear-night", "few-clouds", "few-clouds-night", "fog", "overcast", "severe-alert", "showers-scattered", "showers", "storm")
skillToIcon = {}
# Used by TaskerManager. Put here to help synchronization
skillToIconLarge = {}
for i, icon in enumerate(weather_icons, start=1):
    skillToIcon[2*i-1] = load_icon(16, "weather-%s" % icon)
    skillToIcon[2*i] = load_icon(16, "weather-%s" % icon)
    skillToIconLarge[2*i-1] = load_icon(48, "weather-%s" % icon)
    skillToIconLarge[2*i] = load_icon(48, "weather-%s" % icon)
Esempio n. 27
0
from pychess.perspectives.database.OpeningTreePanel import OpeningTreePanel
from pychess.perspectives.database.FilterPanel import FilterPanel
from pychess.perspectives.database.PreviewPanel import PreviewPanel
from pychess.System.prefix import addUserConfigPrefix
from pychess.widgets.pydock.PyDockTop import PyDockTop
from pychess.widgets.pydock import EAST, SOUTH, CENTER
from pychess.widgets import mainwindow, new_notebook, createImage, createAlignment, gtk_close
from pychess.widgets import gamewidget
from pychess.Database.model import create_indexes, drop_indexes
from pychess.Database.PgnImport import PgnImport, download_file
from pychess.Database.JvR import JvR
from pychess.Savers import fen, epd, olv
from pychess.Savers.pgn import PGNFile
from pychess.System.protoopen import protoopen

pgn_icon = load_icon(24, "application-x-chess-pgn", "pychess")


class Database(GObject.GObject, Perspective):
    __gsignals__ = {
        'chessfile_opened0': (GObject.SignalFlags.RUN_FIRST, None, (object, )),
        'chessfile_opened': (GObject.SignalFlags.RUN_FIRST, None, (object, )),
        'chessfile_closed': (GObject.SignalFlags.RUN_FIRST, None, ()),
        'chessfile_imported': (GObject.SignalFlags.RUN_FIRST, None, (object, )),
    }

    def __init__(self):
        GObject.GObject.__init__(self)
        Perspective.__init__(self, "database", _("Database"))
        self.widgets = gamewidget.getWidgets()
        self.first_run = True
Esempio n. 28
0
def createAlignment(top, right, bottom, left):
    align = Gtk.Alignment.new(.5, .5, 1, 1)
    align.set_property("top-padding", top)
    align.set_property("right-padding", right)
    align.set_property("bottom-padding", bottom)
    align.set_property("left-padding", left)
    return align


def createImage(pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image


light_on = load_icon(16, "stock_3d-light-on", "weather-clear")
light_off = load_icon(16, "stock_3d-light-off", "weather-clear-night")
gtk_close = load_icon(16, "gtk-close", "window-close")

# ###############################################################################
# Initialize module variables                                                  #
# ###############################################################################

widgets = None


def setWidgets(w):
    global widgets
    widgets = w
    pychess.widgets.main_window = widgets["main_window"]
Esempio n. 29
0
from pychess.Players.Human import Human
from pychess.widgets import BoardPreview
from pychess.widgets import ionest
from pychess.widgets import ImageMenu
from pychess.widgets.BoardControl import BoardControl
from pychess.Savers import fen, pgn
from pychess.Savers.ChessFile import LoadingError
from pychess.Variants import variants
from pychess.Variants.normal import NormalBoard

#===============================================================================
# We init most dialog icons global to make them accessibly to the
# Background.Taskers so they have a similar look.
#===============================================================================
big_time = get_pixbuf("glade/stock_alarm.svg")
big_people = load_icon(48, "stock_people", "system-users")
iwheels = load_icon(24, "gtk-execute", "system-run")
ipeople = load_icon(24, "stock_people", "system-users")
inotebook = load_icon(24, "stock_notebook", "computer")
speople = load_icon(16, "stock_people", "system-users")
snotebook = load_icon(16, "stock_notebook", "computer")

weather_icons = ("clear", "clear-night", "few-clouds", "few-clouds-night",
                 "fog", "overcast", "severe-alert", "showers-scattered",
                 "showers", "storm")
skillToIcon = {}
# Used by TaskerManager. Put here to help synchronization
skillToIconLarge = {}
for i, icon in enumerate(weather_icons, start=1):
    skillToIcon[2 * i - 1] = load_icon(16, "weather-%s" % icon)
    skillToIcon[2 * i] = load_icon(16, "weather-%s" % icon)
Esempio n. 30
0
            name = conf.get("secondName", _("Guest"))
            player1tup = (LOCAL, Human, (1 - color, name), name)
        else:
            engine = discoverer.getEngineN(opponent - 1)
            name = discoverer.getName(engine)
            player1tup = (ARTIFICIAL, discoverer.initPlayerEngine,
                          (engine, 1 - color, difficulty,
                           variants[NORMALCHESS], 5 * 60, 0), name)

        if color == WHITE:
            game_handler.generalStart(gamemodel, player0tup, player1tup)
        else:
            game_handler.generalStart(gamemodel, player1tup, player0tup)


big_start = load_icon(48, "stock_init", "gnome-globe", "applications-internet")


class InternetGameTasker(Gtk.Alignment):
    def __init__(self):
        GObject.GObject.__init__(self)
        self.widgets = uistuff.GladeWidgets("taskers.glade")
        tasker = self.widgets["internetGameTasker"]
        tasker.unparent()
        self.add(tasker)

        def asGuestCallback(check):
            names = ICLogon.get_user_names()
            self.widgets["usernameEntry"].set_text(
                names[1] if check.get_active() else names[0])
            self.widgets["passwordLabel"].set_sensitive(not check.get_active())
Esempio n. 31
0
    def __init__(self, widgets):

        # Init open dialog

        opendialog = Gtk.FileChooserDialog(
            _("Open Sound File"), mainwindow(), Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
             Gtk.ResponseType.ACCEPT))

        for dir in self.SOUND_DIRS:
            if os.path.isdir(dir):
                opendialog.set_current_folder(dir)
                break

        soundfilter = Gtk.FileFilter()
        soundfilter.set_name(_("Sound files"))
        soundfilter.add_mime_type("audio/%s" % EXT)
        soundfilter.add_pattern("*.%s" % EXT)
        opendialog.add_filter(soundfilter)

        # Get combo icons

        icons = ((_("No sound"), "audio-volume-muted", "audio-volume-muted"),
                 (_("Beep"), "stock_bell", "audio-x-generic"),
                 (_("Select sound file..."), "gtk-open", "document-open"))

        items = []
        for level, stock, altstock in icons:
            image = load_icon(16, stock, altstock)
            items += [(image, level)]

        audioIco = load_icon(16, "audio-x-generic")

        # Set-up combos

        def callback(combobox, index):
            if combobox.get_active() == SOUND_SELECT:
                if opendialog.run() == Gtk.ResponseType.ACCEPT:
                    uri = opendialog.get_uri()
                    model = combobox.get_model()
                    conf.set("sounduri%d" % index, uri)
                    label = unquote(os.path.split(uri)[1])
                    if len(model) == 3:
                        model.append([audioIco, label])
                    else:
                        model.set(model.get_iter((3, )), 1, label)
                    combobox.set_active(3)
                else:
                    combobox.set_active(
                        conf.get("soundcombo%d" % index, SOUND_MUTE))
                opendialog.hide()

        for i in range(self.COUNT_OF_SOUNDS):
            combo = widgets["sound%dcombo" % i]
            uistuff.createCombo(combo, items, name="soundcombo%d" % i)
            # combo.set_active(0)
            combo.connect("changed", callback, i)

            label = widgets["soundlabel%d" % i]
            label.props.mnemonic_widget = combo

            uri = conf.get("sounduri%d" % i, "")
            if os.path.isfile(url2pathname(uri[5:])):
                model = combo.get_model()
                model.append([audioIco, unquote(os.path.split(uri)[1])])
                # combo.set_active(3)

        for i in range(self.COUNT_OF_SOUNDS):
            if conf.get("soundcombo%d" % i, SOUND_MUTE) == SOUND_URI and \
                    not os.path.isfile(url2pathname(conf.get("sounduri%d" % i, "")[5:])):
                conf.set("soundcombo%d" % i, SOUND_MUTE)
            uistuff.keep(widgets["sound%dcombo" % i], "soundcombo%d" % i)

        # Init play button

        def playCallback(button, index):
            SoundTab.playAction(index)

        for i in range(self.COUNT_OF_SOUNDS):
            button = widgets["sound%dbutton" % i]
            button.connect("clicked", playCallback, i)

        # Init 'use sound" checkbutton

        def checkCallBack(*args):
            checkbox = widgets["useSounds"]
            widgets["sounds_frame"].set_property("sensitive",
                                                 checkbox.get_active())

        conf.notify_add("useSounds", checkCallBack)
        widgets["useSounds"].set_active(True)
        uistuff.keep(widgets["useSounds"], "useSounds")
        checkCallBack()

        if not self.getPlayer().ready:
            widgets["useSounds"].set_sensitive(False)
            widgets["useSounds"].set_active(False)

        uistuff.keep(widgets["alarm_spin"], "alarm_spin", first_value=15)
Esempio n. 32
0
from pychess.System.prefix import getDataPrefix, isInstalled, addDataPrefix
from pychess.Players.engineNest import discoverer
from pychess.Players.Human import Human
from pychess.widgets import BoardPreview
from pychess.widgets import ionest
from pychess.widgets import ImageMenu
from pychess.Savers import pgn
from pychess.Variants import variants
from pychess.Variants.normal import NormalChess

#===============================================================================
# We init most dialog icons global to make them accessibly to the
# Background.Taskers so they have a similar look.
#===============================================================================

big_time = load_icon(48, "stock_alarm", "appointment-soon")
big_people = load_icon(48, "stock_people", "system-users")
iwheels = load_icon(24, "gtk-execute")
ipeople = load_icon(24, "stock_people", "system-users")
inotebook = load_icon(24, "stock_notebook", "computer")
speople = load_icon(16, "stock_people", "system-users")
snotebook = load_icon(16, "stock_notebook", "computer")

skillToIcon = {
    1: load_icon(16, "weather-clear"),
    2: load_icon(16, "weather-few-clouds"),
    3: load_icon(16, "weather-few-clouds"),
    4: load_icon(16, "weather-overcast"),
    5: load_icon(16, "weather-overcast"),
    6: load_icon(16, "weather-showers"),
    7: load_icon(16, "weather-showers"),
Esempio n. 33
0
    notebook = Gtk.Notebook()
    if name is not None:
        notebook.set_name(name)
    notebook.get_tab_label_text = customGetTabLabelText
    notebook.set_show_tabs(False)
    notebook.set_show_border(False)
    return notebook


def createImage(pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image


light_on = load_icon(16, "stock_3d-light-on", "weather-clear")
light_off = load_icon(16, "stock_3d-light-off", "weather-clear-night")
gtk_close = load_icon(16, "gtk-close", "window-close")

media_previous = load_icon(24, "gtk-media-previous-ltr", "media-skip-backward")
media_rewind = load_icon(24, "gtk-media-rewind-ltr", "media-seek-backward")
media_forward = load_icon(24, "gtk-media-forward-ltr", "media-seek-forward")
media_next = load_icon(24, "gtk-media-next-ltr", "media-skip-forward")
media_eject = load_icon(24, "player-eject", "media-eject")

path = prefix.addDataPrefix("sidepanel")
postfix = "Panel.py"
files = [f[:-3] for f in os.listdir(path) if f.endswith(postfix)]
sidePanels = [imp.load_module(f, *imp.find_module(f, [path])) for f in files]

dockLocation = addUserConfigPrefix("pydock.xml")
Esempio n. 34
0
    def load(self, widgets, connection, lounge):
        self.widgets = widgets
        self.connection = connection
        self.lounge = lounge

        __widget__ = lounge.games_list

        self.games = {}
        self.recpix = load_icon(16, "media-record")
        self.clearpix = get_pixbuf("glade/board.png")
        self.tv = self.widgets["gametreeview"]
        self.store = Gtk.ListStore(FICSGame, GdkPixbuf.Pixbuf, str, int, str,
                                   int, str, str)

        self.game_filter = self.store.filter_new()
        self.game_filter.set_visible_func(self.game_filter_func)

        self.filter_toggles = {}
        self.filter_buttons = ("standard_toggle", "blitz_toggle",
                               "lightning_toggle", "variant_toggle")
        for widget in self.filter_buttons:
            uistuff.keep(self.widgets[widget], widget)
            self.widgets[widget].connect("toggled",
                                         self.on_filter_button_toggled)
            initial = conf.get(widget, True)
            self.filter_toggles[widget] = initial
            self.widgets[widget].set_active(initial)

        self.model = self.game_filter.sort_new_with_model()
        self.tv.set_model(self.model)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
        self.addColumns(self.tv,
                        "FICSGame",
                        "",
                        _("White"),
                        _("Rating"),
                        _("Black"),
                        _("Rating"),
                        _("Type"),
                        _("Rated"),
                        hide=[0],
                        pix=[1])

        self.tv.get_model().set_sort_func(0, self.pixCompareFunction, 1)
        for i in range(1, 7):
            self.tv.get_model().set_sort_func(i, self.compareFunction, i)
        self.prev_sort_column_id = []
        self.model.connect("sort-column-changed", self.on_sort_column_change)

        self.tv.set_has_tooltip(True)
        self.tv.connect("query-tooltip", self.on_query_tooltip)
        self.selection = self.tv.get_selection()
        self.selection.connect("changed", self.onSelectionChanged)
        self.onSelectionChanged(self.selection)

        try:
            self.tv.set_search_position_func(self.lowLeftSearchPosFunc, None)
        except AttributeError:
            # Unknow signal name is raised by gtk < 2.10
            pass

        def searchCallback(model, column, key, sel_iter, user_data):
            if model.get_value(sel_iter, 2).lower().startswith(key) or \
                    model.get_value(sel_iter, 4).lower().startswith(key):
                return False
            return True

        self.tv.set_search_equal_func(searchCallback, None)

        self.connection.games.connect("FICSGameCreated", self.onGameAdd)
        self.connection.games.connect("FICSGameEnded", self.onGameRemove)
        self.widgets["observeButton"].connect("clicked", self.on_observe)
        self.tv.connect("row-activated", self.on_observe)
        self.connection.bm.connect("obsGameCreated", self.onGameObserved)
        self.connection.bm.connect("obsGameUnobserved", self.onGameUnobserved)

        self.tv.connect('button-press-event', self.button_press_event)
        self.createLocalMenu((OBSERVE, FOLLOW, SEPARATOR, FINGER, ARCHIVED))

        return __widget__
Esempio n. 35
0
# -*- coding: UTF-8 -*-
from __future__ import print_function

from gi.repository import Gtk, GObject

from pychess.Utils.const import DRAW, LOCAL, WHITE, BLACK, WAITING_TO_START, reprResult
from pychess.Players.Human import Human
from pychess.widgets.ionest import game_handler
from pychess.Utils.GameModel import GameModel
from pychess.perspectives import perspective_manager
from pychess.Utils.IconLoader import load_icon

media_previous = load_icon(16, "gtk-media-previous-ltr", "media-skip-backward")
media_rewind = load_icon(16, "gtk-media-rewind-ltr", "media-seek-backward")
media_forward = load_icon(16, "gtk-media-forward-ltr", "media-seek-forward")
media_next = load_icon(16, "gtk-media-next-ltr", "media-skip-forward")


def createImage(pixbuf):
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    return image


class GameList(Gtk.TreeView):
    LIMIT = 1000

    def __init__(self, chessfile):
        GObject.GObject.__init__(self)
        self.chessfile = chessfile
        self.chessfiles = [
Esempio n. 36
0
    def __init__ (self, gamemodel=None):
        GObject.GObject.__init__(self)
        self.gamemodel = gamemodel

        # States for the color generator
        self.colors = {}
        self.startpoint = random.random()

        # Inits the read view
        self.readView = Gtk.TextView()
        #self.readView.set_size_request(-1, 30)
        set_textview_color(self.readView)

        sw1 = Gtk.ScrolledWindow()
        sw1.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        sw1.set_shadow_type(Gtk.ShadowType.NONE)
        #sw1.set_size_request(-1, 300)
        uistuff.keepDown(sw1)

        sw1.add(self.readView)
        self.readView.set_editable(False)
        self.readView.set_cursor_visible(False)
        self.readView.props.wrap_mode = Gtk.WrapMode.WORD
        self.readView.props.pixels_below_lines = 1
        self.readView.props.pixels_above_lines = 2
        self.readView.props.left_margin = 2
        #self.readView.get_buffer().create_tag("log",
        #        foreground = self.readView.get_style().fg[Gtk.StateType.INSENSITIVE])

        if isinstance(self.gamemodel, ICGameModel):
            self.refresh = Gtk.Image()
            self.refresh.set_from_pixbuf(load_icon(16, "view-refresh", "stock-refresh"))

            vp = Gtk.VPaned()

            # Inits the observers view
            self.obsView = Gtk.TextView()
            self.obsView.set_cursor_visible(False)
            #self.obsView.set_size_request(-1, 3)
            set_textview_color(self.obsView)

            sw0 = Gtk.ScrolledWindow()
            sw0.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            sw0.set_shadow_type(Gtk.ShadowType.NONE)
            sw0.set_size_request(-1, 3)
            uistuff.keepDown(sw0)
            sw0.add(self.obsView)
            self.obsView.set_editable(False)
            self.obsView.props.wrap_mode = Gtk.WrapMode.WORD
            self.obsView.props.pixels_below_lines = 1
            self.obsView.props.pixels_above_lines = 2
            self.obsView.props.left_margin = 2

            vp.pack1(BorderBox(sw0, bottom=True), resize=False, shrink=False)
            vp.pack2(BorderBox(sw1, top=True), resize=True, shrink=False)

            self.pack1(BorderBox(vp, bottom=True), resize=True, shrink=True)
        else:
            self.pack1(BorderBox(sw1, bottom=True), resize=True, shrink=True)

        # Create a 'log mark' in the beginning of the text buffer. Because we
        # query the log asynchronously and in chunks, we can use this to insert
        # it correctly after previous log messages, but before the new messages.
        start = self.readView.get_buffer().get_start_iter()
        self.readView.get_buffer().create_mark("logMark", start)

        # Inits the write view
        self.writeView = Gtk.TextView()
        set_textview_color(self.writeView)

        sw2 = Gtk.ScrolledWindow()
        sw2.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        sw2.set_shadow_type(Gtk.ShadowType.NONE)
        sw2.set_size_request(-1, 3)
        sw2.add(self.writeView)
        self.writeView.props.wrap_mode = Gtk.WrapMode.WORD
        self.writeView.props.pixels_below_lines = 1
        self.writeView.props.pixels_above_lines = 2
        self.writeView.props.left_margin = 2
        self.pack2(BorderBox(sw2, top=True), resize=False, shrink=False)

        # Forces are reasonable position for the panner.
        def callback (widget, ctx):
            widget.disconnect(handle_id)
            allocation = widget.get_allocation()
            self.set_position(int(max(0.70*allocation.height, allocation.height-60)))
        handle_id = self.connect("draw", callback)

        self.writeView.connect("key-press-event", self.onKeyPress)
Esempio n. 37
0
            name = conf.get("secondName", _("Guest"))
            player1tup = (LOCAL, Human, (1 - color, name), name)
        else:
            engine = discoverer.getEngineN(opponent - 1)
            name = discoverer.getName(engine)
            player1tup = (ARTIFICIAL, discoverer.initPlayerEngine,
                          (engine, 1 - color, difficulty,
                           variants[NORMALCHESS], 5 * 60, 0), name)

        if color == WHITE:
            ionest.generalStart(gamemodel, player0tup, player1tup)
        else:
            ionest.generalStart(gamemodel, player1tup, player0tup)


big_start = load_icon(48, "stock_init", "gnome-globe", "applications-internet")


class InternetGameTasker(Gtk.Alignment):
    def __init__(self):
        #GObject.GObject.__init__(self,0,0,0,0)
        GObject.GObject.__init__(self)
        self.widgets = uistuff.GladeWidgets("taskers.glade")
        tasker = self.widgets["internetGameTasker"]
        tasker.unparent()
        self.add(tasker)

        def asGuestCallback(check):
            names = ICLogon.get_user_names()
            self.widgets["usernameEntry"].set_text(names[1] \
                                                   if check.get_active() else names[0])
Esempio n. 38
0
from pychess.Savers.ChessFile import LoadingError
from pychess.Variants import variants
from pychess.Variants.normal import NormalBoard
from pychess.perspectives import perspective_manager
from pychess.perspectives.games import enddir
from pychess.Utils.eco import find_opening_fen

# ===============================================================================
# We init most dialog icons global to make them accessibly to the
# Background.Taskers so they have a similar look.
# ===============================================================================
big_time = get_pixbuf("glade/stock_alarm.svg")
big_people = get_pixbuf("glade/people48.png")
iwheels = get_pixbuf("glade/wheel.png")
ipeople = get_pixbuf("glade/people24.png")
inotebook = load_icon(24, "stock_notebook", "computer")

weather_icons = ("clear", "clear-night", "few-clouds", "few-clouds-night",
                 "fog", "overcast", "severe-alert", "showers-scattered",
                 "showers", "storm")
skillToIcon = {}
# Used by TaskerManager. Put here to help synchronization
skillToIconLarge = {}
for i, icon in enumerate(weather_icons, start=1):
    skillToIcon[2 * i - 1] = get_pixbuf("glade/16x16/weather-%s.png" % icon)
    skillToIcon[2 * i] = get_pixbuf("glade/16x16/weather-%s.png" % icon)
    skillToIconLarge[2 * i - 1] = get_pixbuf("glade/48x48/weather-%s.png" % icon)
    skillToIconLarge[2 * i] = get_pixbuf("glade/48x48/weather-%s.png" % icon)

playerItems = []
analyzerItems = []