IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques tierces Python Discussion :

Problème d'enregistrement dans le menu de plugin écrit en Python-fu sur GIMP 2


Sujet :

Bibliothèques tierces Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2016
    Messages : 14
    Points : 15
    Points
    15
    Par défaut Problème d'enregistrement dans le menu de plugin écrit en Python-fu sur GIMP 2
    Bonjour,

    J'ai un petit souci, je compte écrire un plugin pour GIMP, et j'ai déjà créé un prototype pour vérifier si la fonction register() fonctionnait bien... Seulement mon plugin n'est jamais pris en compte au démarrage de GIMP et je ne le voit jamais dans le menu. Pourtant j'ai un autre plugin téléchargé sur le net, qui lui est reconnu, et je ne vois pourtant pas de différence fondamentale entre nos fonctions d'enregistrement.

    Si quelqu'un pouvait m'éclairer ça m'aiderait grandement.

    Mon plugin :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #!/usr/bin/env python
     
    from gimpfu import *
     
    def xdemat_icon(image, drawable):
        # function code goes here...
        # img = gimp.image_list()[0]
        pdb.gimp_convert_rgb(img)
        # lyr = pdb.gimp_image_get_active_layer(img)
        green = pdb.gimp_image_pick_color(img, active_layer, 100, 15, FALSE, FALSE, 0)
        pdb.gimp_context_set_foreground(green)
        pdb.gimp_image_select_rectangle(img, 0, 10, 8, 16, 14)
        pdb.gimp_edit_bucket_fill(active_layer, 0, 0, 100, 0, FALSE, 10, 10)
     
    register(
        "python_fu_xdemat_icon",
        "Créer une icone xDemat à partir d'une existante",
        "Créer une icone xDemat en modifiant la couleur et le logo d'une ancienne",
        "Guillaume VANDEVELDE",
        "Guillaume VANDEVELDE",
        "2016",
        "Xdemat_icon",
        "",
        [
            (PF_IMAGE, "image", "takes current image", None),
            (PF_DRAWABLE, "drawable", "Input layer", None)
        ],
        [],
        xdemat_icon, menu="<Image>/File/Create")
     
    main()
    Le plugin qui fonctionne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    #!/usr/bin/env python
     
    # Hello World in GIMP Python
     
    from gimpfu import *
     
    def hello_world(initstr, font, size, color) :
        # First do a quick sanity check on the font
        if font == 'Comic Sans MS' :
            initstr = "Comic Sans? Are you sure?"
     
        # Make a new image. Size 10x10 for now -- we'll resize later.
        img = gimp.Image(1, 1, RGB)
     
        # Save the current foreground color:
        pdb.gimp_context_push()
     
        # Set the text color
        gimp.set_foreground(color)
     
        # Create a new text layer (-1 for the layer means create a new layer)
        layer = pdb.gimp_text_fontname(img, None, 0, 0, initstr, 10,
                                       True, size, PIXELS, font)
     
        # Resize the image to the size of the layer
        img.resize(layer.width, layer.height, 0, 0)
     
        # Background layer.
        # Can't add this first because we don't know the size of the text layer.
        background = gimp.Layer(img, "Background", layer.width, layer.height,
                                RGB_IMAGE, 100, NORMAL_MODE)
        background.fill(BACKGROUND_FILL)
        img.add_layer(background, 1)
     
        # Create a new image window
        gimp.Display(img)
        # Show the new image window
        gimp.displays_flush()
     
        # Restore the old foreground color:
        pdb.gimp_context_pop()
     
    register(
        "python_fu_hello_world",
        "Hello world image",
        "Create a new image with your text string",
        "Akkana Peck",
        "Akkana Peck",
        "2010",
        "Hello world (Py)...",
        "",      # Create a new image, don't work on an existing one
        [
            (PF_STRING, "string", "Text string", 'Hello, world!'),
            (PF_FONT, "font", "Font face", "Sans"),
            (PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
            (PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
        ],
        [],
        hello_world, menu="<Image>/File/Create")
     
    main()

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    Tu as un caractère exotique en ligne 1: Et rajoute # -*- coding: utf-8 -*- en ligne 2.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2016
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    La ligne 1 ne s'est pas affichée comme dans mon code, et j'ai rajouté l'encodage en utf-8 mais ça ne charge toujours pas. J'ai un peu amélioré mon code depuis ce matin, et je suis sur qu'il fonctionne puisqu'il s’exécute bien dans la console python de GIMP.
    Le souci vient forcément de la fonction register, j'ai pourtant essayé de modifier sa syntaxe par rapport aux autres possibilités que j'ai vu sur le net mais rien n'y fait...

    A noter que maintenant j’obtiens un message d'erreur au lancement de GIMP:

    (pythonw.exe:8268): LibGimpBase-ERROR **: gimp_wire_write_msg:the wire protocol has not been initialized

    Je vous laisse mon nouveau code, pour que vous ayez tous les éléments.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
     
    from gimpfu import *
     
    # Definition des couleurs a remplacer
    green_center_r = pdb.gimp_image_pick_color(image, drawable, 100, 15, FALSE, FALSE, 0)
    green_upper_r = pdb.gimp_image_pick_color(image, drawable, 9, 6, FALSE, FALSE, 0)
    green_lower_r = pdb.gimp_image_pick_color(image, drawable, 5, 26, FALSE, FALSE, 0)
    orange_r = pdb.gimp_image_pick_color(image, drawable, 125, 20, FALSE, FALSE, 0)
     
    # Definition des couleurs a ajouter
    light_grey = gimpcolor.RGB(0.8627450980392157, 0.8627450980392157, 0.8627450980392157, 1.0)
     
    # Fonction principale
    def xdemat_icon(image, drawable):
        pdb.gimp_convert_rgb(image)
        suppr_ico(image, drawable, green_center_r)
        replace_color(image, drawable, orange_r, light_grey)
     
    #Fonction de suppression d'icone
    def suppr_ico(image, drawable, color_r):
        pdb.gimp_image_select_rectangle(image, 0, 10, 8, 16, 14)
        pdb.gimp_context_set_foreground(color_r)
        pdb.gimp_edit_bucket_fill(drawable, 0, 0, 100, 0, FALSE, 10, 10)
        pdb.gimp_selection_none(image)
     
    # Fonction permettant de remplacer des couleurs
    def replace_color(image, drawable, color_r, color):
        pdb.gimp_image_select_color(image, 0, drawable, color_r)
        pdb.gimp_context_set_foreground(color)
        pdb.gimp_edit_bucket_fill(drawable, 0, 0, 100, 0, FALSE, 10, 10)
        pdb.gimp_selection_none(image)
     
    register(
        "python-fu-xdemat-icon",
        "Creer une icone xDemat a partir d'une existante",
        "Creer une icone xDemat en modifiant la couleur et le logo d'une ancienne",
        "Guillaume VANDEVELDE",
        "Guillaume VANDEVELDE",
        "2016",
        "/File/Create/Xdemat_icon...",
        "*",
        [
            (PF_IMAGE, "image", "takes current image", None),
            (PF_DRAWABLE, "drawable", "Input layer", None),
        ],
        [],
        xdemat_icon)
     
    main()

  4. #4
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Lance gimp dans un terminal avec l'argument --verbose, après énumération des tools-options il charge les plugins, s'il il en trouve. Peut-être qu'un message sera plus explicite à ce moment là.

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2016
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    Voilà le résultat de la commande au niveau du plugin.

    Querying plug-in: '/home/lambda/scripts/xdematicon.py'

    (process:1367): LibGimpBase-ERROR **: gimp_wire_write_msg: the wire protocol has not been initialized

    (gimp:1363): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
    Terminating plug-in: '/home/lambda/scripts/xdematicon.py'
    J'avoue que c'est un peu flou pour moi...

  6. #6
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2016
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    C'est bon, problème résolu.

    Il suffisait de placer les variable dans la définition de la fonction principale. Apparemment quand GIMP démarre et charge les plugins il ne prend que les références envers les fonctions et n'est pas capable d'enregistrer des variables en mémoire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] problème d'enregistrement dans la base
    Par zana74 dans le forum PHP & Base de données
    Réponses: 13
    Dernier message: 10/08/2006, 17h06
  2. Réponses: 1
    Dernier message: 30/07/2006, 20h02
  3. Probléme d'enregistrement dans un fichier ini
    Par jv2759 dans le forum Delphi
    Réponses: 2
    Dernier message: 19/05/2006, 15h30
  4. problème de couleur dans le Menu [MainMenu - ImageList]
    Par alec_002 dans le forum Composants VCL
    Réponses: 8
    Dernier message: 01/09/2005, 15h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo