Exemplo n.º 1
0
 def  on_row_deleted(self, model, path):
     if self.dnd_started !=None:
         self.handler.update_after_dnd(path.to_string(), self.dnd_started)
         log.debug("DND from %s to %s", path.to_string(), self.dnd_started )
     else:
         log.debug("Row deleted %s", path.to_string())
     self.dnd_started=None
Exemplo n.º 2
0
    def __initVariantRadio(cls, confid, radiobutton, configImage):
        model = Gtk.TreeStore(str)
        treeview = Gtk.TreeView(model)
        treeview.set_headers_visible(False)
        treeview.append_column(Gtk.TreeViewColumn(None,
                                                  Gtk.CellRendererText(),
                                                  text=0))
        alignment = Gtk.Alignment.new(1, 1, 1, 1)
        alignment.set_padding(6, 6, 12, 12)
        alignment.add(treeview)
        ImageMenu.switchWithImage(configImage, alignment)

        groupNames = {VARIANTS_BLINDFOLD: _("Blindfold"),
                      VARIANTS_ODDS: _("Odds"),
                      VARIANTS_SHUFFLE: _("Shuffle"),
                      VARIANTS_OTHER: _("Other (standard rules)"),
                      VARIANTS_OTHER_NONSTANDARD:
                      _("Other (non standard rules)"),
                      VARIANTS_ASEAN: _("Asian variants"), }

        specialVariants = [v
                           for v in variants.values()
                           if v != NormalBoard and v.variant not in UNSUPPORTED
                           ]
        specialVariants = sorted(specialVariants,
                                 key=attrgetter("variant_group"))
        groups = groupby(specialVariants, attrgetter("variant_group"))
        pathToVariant = {}
        variantToPath = {}
        for i, (id, group) in enumerate(groups):
            iter = model.append(None, (groupNames[id], ))
            for variant in group:
                subiter = model.append(iter, (variant.name, ))
                path = model.get_path(subiter)
                pathToVariant[path.to_string()] = variant.variant
                variantToPath[variant.variant] = path.to_string()
            treeview.expand_row(Gtk.TreePath(i), True)

        selection = treeview.get_selection()
        selection.set_mode(Gtk.SelectionMode.BROWSE)

        def selfunc(selection, store, path, path_selected, data):
            return path.get_depth() > 1

        selection.set_select_function(selfunc, None)
        variant = conf.get(confid)
        if variant in variantToPath:
            selection.select_path(variantToPath[variant])

        def callback(selection):
            model, iter = selection.get_selected()
            if iter:
                radiobutton.set_label("%s" % model.get(iter, 0) + _(" chess"))
                path = model.get_path(iter)
                variant = pathToVariant[path.to_string()]
                conf.set(confid, variant)

        selection.connect("changed", callback)
        callback(selection)
Exemplo n.º 3
0
    def __initVariantRadio(cls, confid, radiobutton, configImage, default):
        model = Gtk.TreeStore(str)
        treeview = Gtk.TreeView(model)
        treeview.set_headers_visible(False)
        treeview.append_column(
            Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=0))
        alignment = Gtk.Alignment.new(1, 1, 1, 1)
        alignment.set_padding(6, 6, 12, 12)
        alignment.add(treeview)
        ImageMenu.switchWithImage(configImage, alignment)

        groupNames = {
            VARIANTS_BLINDFOLD: _("Blindfold"),
            VARIANTS_ODDS: _("Odds"),
            VARIANTS_SHUFFLE: _("Shuffle"),
            VARIANTS_OTHER: _("Other (standard rules)"),
            VARIANTS_OTHER_NONSTANDARD: _("Other (non standard rules)"),
            VARIANTS_ASEAN: _("Asian variants"),
        }

        specialVariants = [
            v for v in variants.values()
            if v != NormalBoard and v.variant not in UNSUPPORTED
        ]
        specialVariants = sorted(specialVariants,
                                 key=attrgetter("variant_group"))
        groups = groupby(specialVariants, attrgetter("variant_group"))
        pathToVariant = {}
        variantToPath = {}
        for i, (id, group) in enumerate(groups):
            iter = model.append(None, (groupNames[id], ))
            for variant in group:
                subiter = model.append(iter, (variant.name, ))
                path = model.get_path(subiter)
                pathToVariant[path.to_string()] = variant.variant
                variantToPath[variant.variant] = path.to_string()
            treeview.expand_row(Gtk.TreePath(i), True)

        selection = treeview.get_selection()
        selection.set_mode(Gtk.SelectionMode.BROWSE)

        def selfunc(selection, store, path, path_selected, data):
            return path.get_depth() > 1

        selection.set_select_function(selfunc, None)
        variant = conf.get(confid, default)
        if variant in variantToPath:
            selection.select_path(variantToPath[variant])

        def callback(selection):
            model, iter = selection.get_selected()
            if iter:
                radiobutton.set_label("%s" % model.get(iter, 0) + _(" chess"))
                path = model.get_path(iter)
                variant = pathToVariant[path.to_string()]
                conf.set(confid, variant)

        selection.connect("changed", callback)
        callback(selection)
Exemplo n.º 4
0
 def on_row_inserted(self, model, path, iter):
     pathi,name=model[iter][:]
     if pathi==None and name==None:
         log.debug("possible DND on row %s", path.to_string())
         self.dnd_started=path.to_string()
     else:
         log.debug("Row inserted %s %s", path.to_string(), [path, name])
         self.dnd_start=False
Exemplo n.º 5
0
 def callback(selection):
     model, iter = selection.get_selected()
     if iter:
         radiobutton.set_label("%s" % model.get(iter, 0) + _(" chess"))
         path = model.get_path(iter)
         variant = pathToVariant[path.to_string()]
         conf.set(confid, variant)
Exemplo n.º 6
0
 def callback(selection):
     model, iter = selection.get_selected()
     if iter:
         radiobutton.set_label("%s" % model.get(iter, 0) + _(" chess"))
         path = model.get_path(iter)
         variant = pathToVariant[path.to_string()]
         conf.set(confid, variant)
Exemplo n.º 7
0
def trav_get_path_stamped_row(model, treeiter, out):
    """Function for use with traverse_treemodel which retrieves a traversed 
    row from a GTK TreeModel in the form of a list.

    Arguments
    =========
    * model - GTK TreeModel to get data from

    * treeiter - GTK TreeIter pointing to the target row in ``model`` to
        get the data from

    * out - Python list (or similar collection) to collect the output

    """
    row = model[treeiter][:]
    path = model.get_path(treeiter)
    row[0] = path.to_string()
    out.append(row)