Exemplo n.º 1
0
    def load(self, gmwidg):

        self.gamemodel = gmwidg.board.view.model
        self.gmhandlers = [
            self.gamemodel.connect_after("game_changed", self.game_changed),
            self.gamemodel.connect_after("game_started", self.game_started),
            self.gamemodel.connect_after("moves_undone", self.moves_undone)
        ]

        widgets = Gtk.Builder()
        widgets.add_from_file(addDataPrefix("sidepanel/book.glade"))
        self.tv = widgets.get_object("treeview")
        scrollwin = widgets.get_object("scrolledwindow")
        scrollwin.unparent()

        self.store = Gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        uistuff.appendAutowrapColumn(self.tv, "Comment", text=0)

        self.tv.connect('cursor_changed', self.cursorChanged)
        self.boardview = gmwidg.board.view
        self.boardview.connect("shownChanged", self.shownChanged)

        self.frozen = Switch()

        return scrollwin
 def __init__ (self, widgets):
     # Put panels in trees
     self.widgets = widgets
     
     from pychess.widgets.gamewidget import sidePanels
     store = gtk.ListStore(bool, gtk.gdk.Pixbuf, str, object)
     for panel in sidePanels:
         checked = conf.get(panel.__name__, True)
         panel_icon = gtk.gdk.pixbuf_new_from_file_at_size(panel.__icon__, 32, 32)
         text = "<b>%s</b>\n%s" % (panel.__title__, panel.__desc__)
         store.append((checked, panel_icon, text, panel))
     
     self.tv = widgets["treeview1"]
     self.tv.set_model(store)
     
     self.widgets['panel_about_button'].connect('clicked', self.panel_about)
     self.widgets['panel_enable_button'].connect('toggled', self.panel_toggled)
     self.tv.get_selection().connect('changed', self.selection_changed)
     
     pixbuf = gtk.CellRendererPixbuf()
     pixbuf.props.yalign = 0
     pixbuf.props.ypad = 3
     pixbuf.props.xpad = 3
     self.tv.append_column(gtk.TreeViewColumn("Icon", pixbuf, pixbuf=1, sensitive=0))
     
     uistuff.appendAutowrapColumn(self.tv, 200, "Name", markup=2, sensitive=0)
     
     widgets['notebook1'].connect("switch-page", self.__on_switch_page)
     widgets["preferences"].connect("show", self.__on_show_window)
     widgets["preferences"].connect("hide", self.__on_hide_window)
Exemplo n.º 3
0
    def load(self, gmwidg):

        self.gamemodel = gmwidg.board.view.model
        self.model_cids = [
            self.gamemodel.connect_after("game_changed", self.game_changed),
            self.gamemodel.connect_after("game_started", self.game_started),
            self.gamemodel.connect_after("moves_undone", self.moves_undone),
            self.gamemodel.connect_after("game_terminated",
                                         self.on_game_terminated),
        ]

        scrollwin = Gtk.ScrolledWindow()
        self.tv = Gtk.TreeView()
        scrollwin.add(self.tv)
        scrollwin.show_all()

        self.store = Gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        uistuff.appendAutowrapColumn(self.tv, "Comment", text=0)
        self.tv_cid = self.tv.connect('cursor_changed', self.cursorChanged)

        self.boardview = gmwidg.board.view
        self.cid = self.boardview.connect("shownChanged", self.shownChanged)

        self.frozen = Switch()

        return scrollwin
Exemplo n.º 4
0
    def load (self, gmwidg):
        
        self.gamemodel = gmwidg.board.view.model
        self.gmhandlers = [
            glock_connect(self.gamemodel, "game_changed", self.game_changed),
            glock_connect(self.gamemodel, "game_started", self.game_started),
            glock_connect(self.gamemodel, "moves_undoing", self.moves_undoing)
        ]

        widgets = Gtk.Builder()
        widgets.add_from_file(addDataPrefix("sidepanel/book.glade"))
        self.tv = widgets.get_object("treeview")
        scrollwin = widgets.get_object("scrolledwindow")
        scrollwin.unparent()

        self.store = Gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        uistuff.appendAutowrapColumn(self.tv, "Comment", text=0)

        self.tv.get_selection().connect_after('changed', self.select_cursor_row)
        self.boardview = gmwidg.board.view
        self.boardview.connect("shown_changed", self.shown_changed)

        self.frozen = Switch()

        return scrollwin
Exemplo n.º 5
0
    def load(self, gmwidg):

        self.gamemodel = gmwidg.board.view.model
        self.model_cids = [
            self.gamemodel.connect_after("game_changed", self.game_changed),
            self.gamemodel.connect_after("game_started", self.game_started),
            self.gamemodel.connect_after("moves_undone", self.moves_undone),
            self.gamemodel.connect_after("game_terminated", self.on_game_terminated),
        ]

        scrollwin = Gtk.ScrolledWindow()
        self.tv = Gtk.TreeView()
        self.tv.set_headers_visible(False)
        scrollwin.add(self.tv)
        scrollwin.show_all()

        self.store = Gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        uistuff.appendAutowrapColumn(self.tv, "Comment", text=0)
        self.tv_cid = self.tv.connect('cursor_changed', self.cursorChanged)

        self.boardview = gmwidg.board.view
        self.cid = self.boardview.connect("shownChanged", self.shownChanged)

        return scrollwin
    def load(self, gmwidg):

        self.gamemodel = gmwidg.board.view.model
        self.gmhandlers = [
            glock_connect(self.gamemodel, "game_changed", self.game_changed),
            glock_connect(self.gamemodel, "game_started", self.game_started),
            glock_connect(self.gamemodel, "moves_undoing", self.moves_undoing)
        ]

        widgets = gtk.glade.XML(addDataPrefix("sidepanel/book.glade"))
        self.tv = widgets.get_widget("treeview")
        scrollwin = widgets.get_widget("scrolledwindow")
        scrollwin.unparent()

        self.store = gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(gtk.SELECTION_BROWSE)
        #r = gtk.CellRendererText()
        #r.set_property("wrap-width", 177) #FIXME: Fixed width size
        #r.set_property("wrap-mode", pango.WRAP_WORD)
        #self.tv.append_column(gtk.TreeViewColumn("Comment", r, text=0))
        uistuff.appendAutowrapColumn(self.tv, 200, "Comment", text=0)

        self.tv.get_selection().connect_after('changed',
                                              self.select_cursor_row)
        self.boardview = gmwidg.board.view
        self.boardview.connect("shown_changed", self.shown_changed)

        def changed(vadjust):
            if not hasattr(vadjust, "need_scroll") or vadjust.need_scroll:
                vadjust.set_value(vadjust.upper - vadjust.page_size)
                vadjust.need_scroll = True

        scrollwin.get_vadjustment().connect("changed", changed)

        def value_changed(vadjust):
            vadjust.need_scroll = abs(vadjust.value + vadjust.page_size - \
                    vadjust.upper) < vadjust.step_increment

        scrollwin.get_vadjustment().connect("value-changed", value_changed)

        self.frozen = Switch()

        return scrollwin
Exemplo n.º 7
0
    def __init__(self, widgets):
        # Put panels in trees
        self.widgets = widgets
        persp = perspective_manager.get_perspective("games")
        sidePanels = persp.sidePanels
        dockLocation = persp.dockLocation

        saved_panels = []
        xmlOK = os.path.isfile(dockLocation)
        if xmlOK:
            doc = minidom.parse(dockLocation)
            for elem in doc.getElementsByTagName("panel"):
                saved_panels.append(elem.getAttribute("id"))

        store = Gtk.ListStore(bool, GdkPixbuf.Pixbuf, str, object)
        for panel in sidePanels:
            checked = True if not xmlOK else panel.__name__ in saved_panels
            panel_icon = get_pixbuf(panel.__icon__, 32)
            text = "<b>%s</b>\n%s" % (panel.__title__, panel.__desc__)
            store.append((checked, panel_icon, text, panel))

        self.tv = widgets["panels_treeview"]
        self.tv.set_model(store)

        self.widgets['panel_about_button'].connect('clicked', self.panel_about)
        self.widgets['panel_enable_button'].connect('toggled',
                                                    self.panel_toggled)
        self.tv.get_selection().connect('changed', self.selection_changed)

        pixbuf = Gtk.CellRendererPixbuf()
        pixbuf.props.yalign = 0
        pixbuf.props.ypad = 3
        pixbuf.props.xpad = 3
        self.tv.append_column(Gtk.TreeViewColumn("Icon",
                                                 pixbuf,
                                                 pixbuf=1,
                                                 sensitive=0))

        uistuff.appendAutowrapColumn(self.tv, "Name", markup=2, sensitive=0)

        widgets['preferences_notebook'].connect("switch-page", self.__on_switch_page)
        widgets["preferences_dialog"].connect("show", self.__on_show_window)
        widgets["preferences_dialog"].connect("hide", self.__on_hide_window)
Exemplo n.º 8
0
    def __init__(self, widgets):
        # Put panels in trees
        self.widgets = widgets
        persp = perspective_manager.get_perspective("games")
        sidePanels = persp.sidePanels
        dockLocation = persp.dockLocation

        saved_panels = []
        xmlOK = os.path.isfile(dockLocation)
        if xmlOK:
            doc = minidom.parse(dockLocation)
            for elem in doc.getElementsByTagName("panel"):
                saved_panels.append(elem.getAttribute("id"))

        store = Gtk.ListStore(bool, GdkPixbuf.Pixbuf, str, object)
        for panel in sidePanels:
            checked = True if not xmlOK else panel.__name__ in saved_panels
            panel_icon = get_pixbuf(panel.__icon__, 32)
            text = "<b>%s</b>\n%s" % (panel.__title__, panel.__desc__)
            store.append((checked, panel_icon, text, panel))

        self.tv = widgets["panels_treeview"]
        self.tv.set_model(store)

        self.widgets['panel_about_button'].connect('clicked', self.panel_about)
        self.widgets['panel_enable_button'].connect('toggled',
                                                    self.panel_toggled)
        self.tv.get_selection().connect('changed', self.selection_changed)

        pixbuf = Gtk.CellRendererPixbuf()
        pixbuf.props.yalign = 0
        pixbuf.props.ypad = 3
        pixbuf.props.xpad = 3
        self.tv.append_column(Gtk.TreeViewColumn("Icon",
                                                 pixbuf,
                                                 pixbuf=1,
                                                 sensitive=0))

        uistuff.appendAutowrapColumn(self.tv, "Name", markup=2, sensitive=0)

        widgets['preferences_notebook'].connect("switch-page", self.__on_switch_page)
        widgets["preferences_dialog"].connect("show", self.__on_show_window)
        widgets["preferences_dialog"].connect("hide", self.__on_hide_window)
    def load (self, gmwidg):
        
        self.gamemodel = gmwidg.board.view.model
        self.gmhandlers = [
            glock_connect(self.gamemodel, "game_changed", self.game_changed),
            glock_connect(self.gamemodel, "game_started", self.game_started),
            glock_connect(self.gamemodel, "moves_undoing", self.moves_undoing)
        ]

        widgets = gtk.glade.XML(addDataPrefix("sidepanel/book.glade"))
        self.tv = widgets.get_widget("treeview")
        scrollwin = widgets.get_widget("scrolledwindow")
        scrollwin.unparent()

        self.store = gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(gtk.SELECTION_BROWSE)
        #r = gtk.CellRendererText()
        #r.set_property("wrap-width", 177) #FIXME: Fixed width size
        #r.set_property("wrap-mode", pango.WRAP_WORD)
        #self.tv.append_column(gtk.TreeViewColumn("Comment", r, text=0))
        uistuff.appendAutowrapColumn(self.tv, 200, "Comment", text=0)

        self.tv.get_selection().connect_after('changed', self.select_cursor_row)
        self.boardview = gmwidg.board.view
        self.boardview.connect("shown_changed", self.shown_changed)

        def changed (vadjust):
            if not hasattr(vadjust, "need_scroll") or vadjust.need_scroll:
                vadjust.set_value(vadjust.upper-vadjust.page_size)
                vadjust.need_scroll = True
        scrollwin.get_vadjustment().connect("changed", changed)

        def value_changed (vadjust):
            vadjust.need_scroll = abs(vadjust.value + vadjust.page_size - \
                    vadjust.upper) < vadjust.step_increment
        scrollwin.get_vadjustment().connect("value-changed", value_changed)
        
        self.frozen = Switch()

        return scrollwin
    def __init__(self, widgets):
        # Put panels in trees
        self.widgets = widgets

        from pychess.widgets.gamewidget import sidePanels
        store = gtk.ListStore(bool, gtk.gdk.Pixbuf, str, object)
        for panel in sidePanels:
            checked = conf.get(panel.__name__, True)
            panel_icon = gtk.gdk.pixbuf_new_from_file_at_size(
                panel.__icon__, 32, 32)
            text = "<b>%s</b>\n%s" % (panel.__title__, panel.__desc__)
            store.append((checked, panel_icon, text, panel))

        self.tv = widgets["treeview1"]
        self.tv.set_model(store)

        self.widgets['panel_about_button'].connect('clicked', self.panel_about)
        self.widgets['panel_enable_button'].connect('toggled',
                                                    self.panel_toggled)
        self.tv.get_selection().connect('changed', self.selection_changed)

        pixbuf = gtk.CellRendererPixbuf()
        pixbuf.props.yalign = 0
        pixbuf.props.ypad = 3
        pixbuf.props.xpad = 3
        self.tv.append_column(
            gtk.TreeViewColumn("Icon", pixbuf, pixbuf=1, sensitive=0))

        uistuff.appendAutowrapColumn(self.tv,
                                     200,
                                     "Name",
                                     markup=2,
                                     sensitive=0)

        widgets['notebook1'].connect("switch-page", self.__on_switch_page)
        widgets["preferences"].connect("show", self.__on_show_window)
        widgets["preferences"].connect("hide", self.__on_hide_window)
Exemplo n.º 11
0
        def onFingeringFinished(self, fm, finger, playername):
            if not isinstance(self.get_child(), Gtk.Label) or \
                    finger.getName().lower() != playername.lower():
                return
            self.fm.disconnect(self.handle_id)

            label = Gtk.Label()
            label.set_markup("<b>%s</b>" % playername)
            widget = Gtk.Frame()
            widget.set_label_widget(label)
            widget.set_shadow_type(Gtk.ShadowType.NONE)

            alignment = Gtk.Alignment.new(0, 0, 1, 1)
            alignment.set_padding(3, 0, 12, 0)
            widget.add(alignment)

            store = Gtk.ListStore(str, str)
            for i, note in enumerate(finger.getNotes()):
                if note:
                    store.append([str(i + 1), note])
            tv = Gtk.TreeView(store)
            tv.get_selection().set_mode(Gtk.SelectionMode.NONE)
            tv.set_headers_visible(False)

            sc = tv.get_style_context()
            bool1, bg_color = sc.lookup_color("p_bg_color")
            bool1, bg_active = sc.lookup_color("p_bg_active")
            tv.override_background_color(Gtk.StateFlags.NORMAL, bg_color)

            cell = Gtk.CellRendererText()
            cell.props.background_rgba = bg_active

            cell.props.cell_background_set = True
            cell.props.yalign = 0
            tv.append_column(Gtk.TreeViewColumn("", cell, text=0))
            cell = uistuff.appendAutowrapColumn(tv, "Notes", text=1)
            cell.props.background_rgba = bg_color
            cell.props.cell_background_set = True
            sw = Gtk.ScrolledWindow()
            sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
            sw.add(tv)
            alignment.add(sw)

            self.remove(self.get_child())
            self.add(widget)
            widget.show_all()
Exemplo n.º 12
0
        def onFingeringFinished (self, fm, finger, playername):
            if not isinstance(self.get_child(), Gtk.Label) or \
                    finger.getName().lower() != playername.lower():
                return
            self.fm.disconnect(self.handle_id)

            label = Gtk.Label()
            label.set_markup("<b>%s</b>" % playername)
            widget = Gtk.Frame()
            widget.set_label_widget(label)
            widget.set_shadow_type(Gtk.ShadowType.NONE)

            alignment = Gtk.Alignment.new(0, 0, 1, 1)
            alignment.set_padding(3, 0, 12, 0)
            widget.add(alignment)

            store = Gtk.ListStore(str,str)
            for i, note in enumerate(finger.getNotes()):
                if note:
                    store.append([str(i+1),note])
            tv = Gtk.TreeView(store)
            tv.get_selection().set_mode(Gtk.SelectionMode.NONE)
            tv.set_headers_visible(False)

            sc = tv.get_style_context()
            bool1, bg_color = sc.lookup_color("p_bg_color")
            bool1, bg_active = sc.lookup_color("p_bg_active")
            tv.override_background_color(Gtk.StateFlags.NORMAL, bg_color)

            cell = Gtk.CellRendererText()
            cell.props.background_rgba = bg_active

            cell.props.cell_background_set = True
            cell.props.yalign = 0
            tv.append_column(Gtk.TreeViewColumn("", cell, text=0))
            cell = uistuff.appendAutowrapColumn(tv, "Notes", text=1)
            cell.props.background_rgba = bg_color
            cell.props.cell_background_set = True
            sw = Gtk.ScrolledWindow()
            sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            sw.add(tv)
            alignment.add(sw)

            self.remove(self.get_child())
            self.add(widget)
            widget.show_all()
Exemplo n.º 13
0
 def onFingeringFinished (self, fm, finger, playername):
     if not isinstance(self.get_child(), gtk.Label) or \
             finger.getName().lower() != playername.lower():
         return
     self.fm.disconnect(self.handle_id)
     
     label = gtk.Label()
     label.set_markup("<b>%s</b>" % playername)
     widget = gtk.Frame()
     widget.set_label_widget(label)
     widget.set_shadow_type(gtk.SHADOW_NONE)
     
     alignment = gtk.Alignment(0, 0, 1, 1)
     alignment.set_padding(3, 0, 12, 0)
     widget.add(alignment)
     
     store = gtk.ListStore(str,str)
     for i, note in enumerate(finger.getNotes()):
         if note:
             store.append([str(i+1),note])
     tv = gtk.TreeView(store)
     tv.get_selection().set_mode(gtk.SELECTION_NONE)
     tv.set_headers_visible(False)
     tv.modify_base(gtk.STATE_NORMAL, self.get_style().bg[gtk.STATE_NORMAL].copy())
     cell = gtk.CellRendererText()
     cell.props.cell_background_gdk = self.get_style().bg[gtk.STATE_ACTIVE].copy()
     cell.props.cell_background_set = True 
     cell.props.yalign = 0
     tv.append_column(gtk.TreeViewColumn("", cell, text=0))
     cell = uistuff.appendAutowrapColumn(tv, 50, "Notes", text=1)
     cell.props.cell_background_gdk = self.get_style().bg[gtk.STATE_NORMAL].copy()
     cell.props.cell_background_set = True 
     sw = gtk.ScrolledWindow()
     sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
     sw.add(tv)
     alignment.add(sw)
     
     self.remove(self.get_child())
     self.add(widget)
     widget.show_all()
Exemplo n.º 14
0
 def onFingeringFinished (self, fm, finger, text):
     if not isinstance(self.get_child(), gtk.Label) or \
             finger.getName().lower() != text.lower():
         return
     self.fm.disconnect(self.handle_id)
     
     label = gtk.Label()
     label.set_markup("<b>%s</b>" % text)
     widget = gtk.Frame()
     widget.set_label_widget(label)
     widget.set_shadow_type(gtk.SHADOW_NONE)
     
     alignment = gtk.Alignment(0, 0, 1, 1)
     alignment.set_padding(3, 0, 12, 0)
     widget.add(alignment)
     
     store = gtk.ListStore(str,str)
     for i, note in enumerate(finger.getNotes()):
         if note:
             store.append([str(i+1),note])
     tv = gtk.TreeView(store)
     tv.get_selection().set_mode(gtk.SELECTION_NONE)
     tv.set_headers_visible(False)
     tv.modify_base(gtk.STATE_NORMAL, self.get_style().bg[gtk.STATE_NORMAL].copy())
     cell = gtk.CellRendererText()
     cell.props.cell_background_gdk = self.get_style().bg[gtk.STATE_ACTIVE].copy()
     cell.props.cell_background_set = True 
     cell.props.yalign = 0
     tv.append_column(gtk.TreeViewColumn("", cell, text=0))
     cell = uistuff.appendAutowrapColumn(tv, 50, "Notes", text=1)
     cell.props.cell_background_gdk = self.get_style().bg[gtk.STATE_NORMAL].copy()
     cell.props.cell_background_set = True 
     sw = gtk.ScrolledWindow()
     sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
     sw.add(tv)
     alignment.add(sw)
     
     self.remove(self.get_child())
     self.add(widget)
     widget.show_all()
Exemplo n.º 15
0
    def load(self, gmwidg):
        self.gmwidg = gmwidg
        self.boardview = gmwidg.board.view

        self.sw = Gtk.ScrolledWindow()
        self.tv = Gtk.TreeView()
        self.tv.set_property("headers_visible", False)
        self.sw.add(self.tv)
        self.sw.show_all()

        self.store = Gtk.TreeStore(GObject.TYPE_PYOBJECT,
                                   GObject.TYPE_PYOBJECT, int, bool, str, bool,
                                   bool)
        self.tv.set_model(self.store)

        # ## move suggested
        moveRenderer = Gtk.CellRendererText()
        moveRenderer.set_property("xalign", 1.0)
        moveRenderer.set_property("yalign", 0)
        c0 = Gtk.TreeViewColumn("Move", moveRenderer)

        def getMoveText(column, cell, store, iter, data):
            board, move, pv = store[iter][0]
            if not move:
                cell.set_property("text", "")
            else:
                if conf.get("figuresInNotation", False):
                    cell.set_property("text", toFAN(board, move))
                else:
                    cell.set_property("text", toSAN(board, move, True))

        c0.set_cell_data_func(moveRenderer, getMoveText)

        # ## strength of the move
        c1 = Gtk.TreeViewColumn("Strength", StrengthCellRenderer(), data=1)

        # ## multipv (number of analysis lines)
        self.multipvRenderer = Gtk.CellRendererSpin()
        adjustment = Gtk.Adjustment(value=conf.get("multipv", 1),
                                    lower=1,
                                    upper=9,
                                    step_incr=1)
        self.multipvRenderer.set_property("adjustment", adjustment)
        self.multipvRenderer.set_property("editable", True)
        self.multipvRenderer.set_property("width_chars", 1)
        c2 = Gtk.TreeViewColumn("PV", self.multipvRenderer, editable=3)
        c2.set_property("min_width", 80)

        def spin_visible(column, cell, store, iter, data):
            if store[iter][2] == 0:
                cell.set_property('visible', False)
            else:
                cell.set_property("text", str(store[iter][2]))
                cell.set_property('visible', True)

        c2.set_cell_data_func(self.multipvRenderer, spin_visible)

        def multipv_edited(renderer, path, text):
            iter = self.store.get_iter(path)
            self.store.set_value(iter, 2, int(text))
            self.advisors[int(path[0])].multipv_edited(int(text))

        self.multipv_cid = self.multipvRenderer.connect(
            'edited', multipv_edited)

        # ## start/stop button for analysis engines
        self.toggleRenderer = CellRendererPixbufXt()
        self.toggleRenderer.set_property("stock-id", "gtk-add")
        c4 = Gtk.TreeViewColumn("StartStop", self.toggleRenderer)

        def cb_visible(column, cell, store, iter, data):
            if not store[iter][6]:
                cell.set_property('visible', False)
            else:
                cell.set_property('visible', True)

            if store[iter][5]:
                cell.set_property("stock-id", "gtk-add")
            else:
                cell.set_property("stock-id", "gtk-remove")

        c4.set_cell_data_func(self.toggleRenderer, cb_visible)

        def toggled_cb(cell, path):
            self.store[path][5] = not self.store[path][5]
            self.advisors[int(path[0])].start_stop(self.store[path][5])

        self.toggle_cid = self.toggleRenderer.connect('clicked', toggled_cb)

        self.tv.append_column(c4)
        self.tv.append_column(c0)
        self.tv.append_column(c1)
        self.tv.append_column(c2)
        # ## header text, or analysis line
        uistuff.appendAutowrapColumn(self.tv, "Details", text=4)

        self.cid = self.boardview.connect("shownChanged", self.shownChanged)
        self.tv_cids = [
            self.tv.connect("cursor_changed", self.selection_changed),
            self.tv.connect("select_cursor_row", self.selection_changed),
            self.tv.connect("row-activated", self.row_activated),
            self.tv.connect("query-tooltip", self.query_tooltip),
        ]
        self.tv.props.has_tooltip = True
        self.tv.set_property("show-expanders", False)

        self.advisors = []
        self.conf_conids = []

        if conf.get("opening_check", 0):
            self.advisors.append(OpeningAdvisor(self.store, self.tv))
        if conf.get("endgame_check", 0):
            advisor = EndgameAdvisor(self.store, self.tv, self.boardview)
            self.advisors.append(advisor)

        self.model_cids = [
            gmwidg.gamemodel.connect("analyzer_added", self.on_analyzer_added),
            gmwidg.gamemodel.connect("analyzer_removed",
                                     self.on_analyzer_removed),
            gmwidg.gamemodel.connect("analyzer_paused",
                                     self.on_analyzer_paused),
            gmwidg.gamemodel.connect("analyzer_resumed",
                                     self.on_analyzer_resumed),
            gmwidg.gamemodel.connect_after("game_terminated",
                                           self.on_game_terminated),
        ]

        def on_opening_check(none):
            if conf.get("opening_check", 0) and self.boardview is not None:
                advisor = OpeningAdvisor(self.store, self.tv)
                self.advisors.append(advisor)
                advisor.shownChanged(self.boardview, self.boardview.shown)
            else:
                for advisor in self.advisors:
                    if advisor.mode == OPENING:
                        parent = advisor.empty_parent()
                        self.store.remove(parent)
                        self.advisors.remove(advisor)

        self.conf_conids.append(
            conf.notify_add("opening_check", on_opening_check))

        def on_opening_file_entry_changed(none):
            default_path = os.path.join(addDataPrefix("pychess_book.bin"))
            path = conf.get("opening_file_entry", default_path)
            if os.path.isfile(path):
                for advisor in self.advisors:
                    if advisor.mode == OPENING and self.boardview is not None:
                        advisor.shownChanged(self.boardview,
                                             self.boardview.shown)

        self.conf_conids.append(
            conf.notify_add("opening_file_entry",
                            on_opening_file_entry_changed))

        def on_endgame_check(none):
            if conf.get("endgame_check", 0):
                advisor = EndgameAdvisor(self.store, self.tv, self.boardview)
                self.advisors.append(advisor)
                advisor.shownChanged(self.boardview, self.boardview.shown)
            else:
                for advisor in self.advisors:
                    if advisor.mode == ENDGAME:
                        advisor._del()
                        parent = advisor.empty_parent()
                        self.store.remove(parent)
                        self.advisors.remove(advisor)

        self.conf_conids.append(
            conf.notify_add("endgame_check", on_endgame_check))

        return self.sw
Exemplo n.º 16
0
    def load (self, gmwidg):
        self.boardcontrol = gmwidg.board
        self.boardview = self.boardcontrol.view
        
        widgets = Gtk.Builder()
        widgets.add_from_file(addDataPrefix("sidepanel/book.glade"))
        self.tv = widgets.get_object("treeview")
        self.sw = widgets.get_object("scrolledwindow")
        self.sw.unparent()
        self.store = Gtk.TreeStore(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, int, bool, str, bool, bool)
        self.tv.set_model(self.store)
        
        ### move suggested
        moveRenderer = Gtk.CellRendererText()
        moveRenderer.set_property("xalign", 1.0)
        moveRenderer.set_property("yalign", 0)
        c0 = Gtk.TreeViewColumn("Move", moveRenderer)

        def getMoveText(column, cell, store, iter, data):
            board, move, pv = store[iter][0]
            if not move:
                cell.set_property("text", "")
            else:
                if conf.get("figuresInNotation", False):
                    cell.set_property("text", toFAN(board, move))
                else:
                    cell.set_property("text", toSAN(board, move, True))
        c0.set_cell_data_func(moveRenderer, getMoveText)

        ### strength of the move       
        c1 = Gtk.TreeViewColumn("Strength", StrengthCellRenderer(), data=1)       

        ### multipv (number of analysis lines)
        multipvRenderer = Gtk.CellRendererSpin()
        adjustment = Gtk.Adjustment(value=conf.get("multipv", 1), lower=1, upper=9, step_incr=1)
        multipvRenderer.set_property("adjustment", adjustment)
        multipvRenderer.set_property("editable", True)
        multipvRenderer.set_property("width_chars", 1)
        c2 = Gtk.TreeViewColumn("PV", multipvRenderer, editable=3)
        c2.set_property("min_width", 80)

        def spin_visible(column, cell, store, iter, data):           
            if store[iter][2] == 0:
                cell.set_property('visible', False)
            else:
                cell.set_property("text", str(store[iter][2]))
                cell.set_property('visible', True)
        c2.set_cell_data_func(multipvRenderer, spin_visible)

        def multipv_edited(renderer, path, text):
            iter = self.store.get_iter(path)
            self.store.set_value(iter, 2, int(text))
            self.advisors[int(path[0])].multipv_edited(int(text))
        multipvRenderer.connect('edited', multipv_edited)

        ### start/stop button for analysis engines
        toggleRenderer = CellRendererPixbufXt()
        toggleRenderer.set_property("stock-id", "gtk-add")
        c4 = Gtk.TreeViewColumn("StartStop", toggleRenderer)

        def cb_visible(column, cell, store, iter, data):
            if not store[iter][6]:
                cell.set_property('visible', False)
            else:
                cell.set_property('visible', True)
            
            if store[iter][5]:
                cell.set_property("stock-id", "gtk-add")
            else:
                cell.set_property("stock-id", "gtk-remove")
        c4.set_cell_data_func(toggleRenderer, cb_visible)

        def toggled_cb(cell, path):
            self.store[path][5] = not self.store[path][5]
            self.advisors[int(path[0])].start_stop(self.store[path][5])
        toggleRenderer.connect('clicked', toggled_cb)

        self.tv.append_column(c4)
        self.tv.append_column(c0)
        self.tv.append_column(c1)
        self.tv.append_column(c2)
        ### header text, or analysis line
        uistuff.appendAutowrapColumn(self.tv, "Details", text=4)
        
        self.boardview.connect("shown_changed", self.shown_changed)
        self.tv.connect("cursor_changed", self.selection_changed)
        self.tv.connect("select_cursor_row", self.selection_changed)
        self.tv.connect("row-activated", self.row_activated)
        self.tv.connect("query-tooltip", self.query_tooltip)
        
        self.tv.props.has_tooltip = True
        self.tv.set_property("show-expanders", False)
        
        self.advisors = []

        if conf.get("opening_check", 0):
            self.advisors.append(OpeningAdvisor(self.store, self.tv))
        if conf.get("endgame_check", 0):
            advisor = EndgameAdvisor(self.store, self.tv, self.boardview)
            self.advisors.append(advisor)
            gmwidg.connect("closed", advisor.gamewidget_closed)
            
        gmwidg.gamemodel.connect("analyzer_added", self.on_analyzer_added)
        gmwidg.gamemodel.connect("analyzer_removed", self.on_analyzer_removed)
        gmwidg.gamemodel.connect("analyzer_paused", self.on_analyzer_paused)
        gmwidg.gamemodel.connect("analyzer_resumed", self.on_analyzer_resumed)
        
        def on_opening_check(none):
            if conf.get("opening_check", 0):
                advisor = OpeningAdvisor(self.store, self.tv)
                self.advisors.append(advisor)
                advisor.shown_changed(self.boardview, self.boardview.shown)
            else:
                for advisor in self.advisors:
                    if advisor.mode == OPENING:
                        parent = advisor.empty_parent()
                        self.store.remove(parent)
                        self.advisors.remove(advisor)
        conf.notify_add("opening_check", on_opening_check)

        def on_opening_file_entry_changed(none):
            default_path = os.path.join(addDataPrefix("pychess_book.bin"))
            path = conf.get("opening_file_entry", default_path) 
            if os.path.isfile(path):
                for advisor in self.advisors:
                    if advisor.mode == OPENING:
                        advisor.shown_changed(self.boardview, self.boardview.shown)
        conf.notify_add("opening_file_entry", on_opening_file_entry_changed)

        def on_endgame_check(none):
            if conf.get("endgame_check", 0):
                advisor = EndgameAdvisor(self.store, self.tv, self.boardview)
                self.advisors.append(advisor)
                advisor.shown_changed(self.boardview, self.boardview.shown)
                gmwidg.connect("closed", advisor.gamewidget_closed)
            else:
                for advisor in self.advisors:
                    if advisor.mode == ENDGAME:
                        advisor.gamewidget_closed(gmwidg)
                        parent = advisor.empty_parent()
                        self.store.remove(parent)
                        self.advisors.remove(advisor)
        conf.notify_add("endgame_check", on_endgame_check)

        return self.sw