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

GTK+ avec C & C++ Discussion :

gestion des entrées !


Sujet :

GTK+ avec C & C++

  1. #1
    Membre confirmé Avatar de coax81
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    180
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 180
    Par défaut gestion des entrées !
    bonjours j'aimerai faire une gestion des valeurs entrées sur des gtkentry , afin que si l'oppérateur n'entre pas des chiffres ca affiche une erreure ...
    est il possible ?

  2. #2
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840
    Par défaut
    Bonjour,

    Celà n'existe pas dans GTK, mais celà peux être codé, voici un exemple en PHP-GTK :
    Code php : 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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    <?php
    /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
     
    /**
    * GtkEntry with mask validation
    *
    * @category   Gtk2
    * @package    Gtk2_EntryMask
    * @author     Pablo Dall'Oglio <pablo@php.net>
    * @author      Leonardo Castilhos Thibes <leonardothibes@yahoo.com.br>
    * @license    LGPL
    * @version    $Id: EntryMask.class.php,v 1.0 2007/01/30 11:37:43 leonardo Exp $
    */
    class EntryMask {
     
        /**
         * Characters used to format mask
         * @var array
         */
        private $chars;
     
        /**
         * The Mask applied to the GtkEntry
         * @var string
         */
        private $mask;
     
        /**
         * The GtkEntry object
         * @var $object
         */
        private $object;
     
        /**
         * The Signal handler that is fired when the user types something
         * @var integer
         */
        private $handler;
     
        /**
         * constructor.
         */
        public function __construct() {}
     
        /**
         * Setando máscara.
         * 
         * @param string $mask the allowed mask
         * @param object $object GtkEntry Object
         */
        public function setMask($object, $mask) {
     
            /** Obtebdo objeto GtkEntry **/
            $this->obj = $object;
     
            /** Obtendo máscara **/
            $this->mask = $mask;
     
            /** Setando tamanho máximo do campo **/
            $this->obj->set_max_length(strlen(trim($mask)));
     
            /** Array de separadores **/
            $this->chars = array('-', '_', '.', ',', '/', '\\', ':', '|', '(', ')', '[', ']', '{', '}');
     
            /** Conectando o sinal "changed" ao metodo onChange **/
            $this->handler = $this->obj->connect('changed', array($this, 'onChange'));        
        }
     
        /**
         * whenever the user types something the content is validated according to
         * the mask.
         */
        public function onChange() {
     
            /** Setando o texto **/
            $text = $this->obj->get_text();
     
            /** Removendo separadores **/
            $text = $this->unMask($text);
     
            /** Obtendo o tamanho do texto **/
            $len = strlen(trim($text));
     
            /** Aplicando a máscara **/
            $new = $this->Mask($this->mask, $text);
     
            /** Agendando novo conteúdo **/
            Gtk::timeout_add(1, array($this, 'Set'), $new);
            Gtk::timeout_add(1, array($this, 'Validate'));
        }
     
        /**
         * changes the Entry contents without fire "changed" signal
         * @param string $text the new text
         */
        public function Set($text) {
     
            /** Desconectando o sinal "changed" do metodo "onChange" **/
            $this->obj->disconnect($this->handler);
     
            /** Setando o texto do entry **/
            $this->obj->set_text($text);
     
            /** Posicionando o cursor no final do texto **/
            $this->obj->select_region(-1,-1);
     
            /** Conectando novamente o sinal "changed" no metodo "onChange" **/
            $this->handler = $this->obj->connect_after('changed', array($this, 'onChange'));
        }
     
        /**
         * Validate the content of GtkEntry
         */
        public function Validate() {
     
            /** Obtendo texto do objeto **/
            $text = $this->obj->get_text();
     
            /** Obtendo máscara **/
            $mask = $this->mask;
     
            /** Obtendo tamanho do texto **/
            $len = strlen($text);
     
            $text_char = substr($text, $len-1, 1);
            $mask_char = substr($mask, $len-1, 1);
     
            /** Comparando os caracteres digitados com a máscara **/
            if ($mask_char == '9')
                $valid = ereg('([0-9])', $text_char);
            elseif ($mask_char == 'a')
                $valid = ereg('([a-z])', $text_char);
            elseif ($mask_char == 'A')
                $valid = ereg('([A-Z])', $text_char);
            elseif ($mask_char == 'X')
                $valid = (ereg('([a-z])', $text_char) or
                         ereg('([A-Z])', $text_char) or
                         ereg('([0-9])', $text_char));
            /** Comparando os caracteres digitados com a máscara **/
     
            /** Caracteres que não se aplicam no escopo da máscara são removidos **/
            if (!$valid) {
                $this->Set(substr($text, 0, -1));
            }
        }
     
        /**
         * put the typed content in the mask format
         * @param string $mask the mask
         * @param string $text the content
         */
        public function Mask($mask, $text) {
     
            /** Run through the mask chars **/
            $z = 0;
            for ($n=0; $n < strlen($mask); $n++) {
                $mask_char = substr($mask, $n, 1);
                $text_char = substr($text, $z, 1);
     
                /** Check when has to concatenate with the separator **/
                if(in_array($mask_char, $this->chars)) {
                    if($z < strlen($text)) {
                        $result .= $mask_char;
                    }
                } else {
                    $result .= $text_char;
                    $z++;
                }
            }
     
            return $result;
        }
     
        /**
         * removes the mask from text
         * @param string $text the content
         */
        public function unMask($text) {
     
            /** Run through the content **/
            for ($n=0; $n <= strlen($text); $n++) {
                $char = substr($text, $n, 1);
     
                /** Check if it's a separator **/
                if (!in_array($char, $this->chars)) {
                    $result .= $char;
                }
            }
     
            return $result;
        }
     
    }
     
    ?>

    Tiré de http://www.php-gtk.com.br/article_79 (en espagnol)

    Et oui avec GTK il faut être multi-langue et multi-langage

Discussions similaires

  1. Gestion des entrées
    Par habilité dans le forum Tcl/Tk
    Réponses: 5
    Dernier message: 20/03/2008, 18h16
  2. Gestion des entrées clavier
    Par piotrr dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 20/10/2007, 11h59
  3. Gestion des entrées utilisateur
    Par piotrr dans le forum Windows Forms
    Réponses: 8
    Dernier message: 26/09/2007, 21h00
  4. gestion des entrées-sorties
    Par bandit_debutant dans le forum Entrée/Sortie
    Réponses: 8
    Dernier message: 25/11/2006, 14h55
  5. gestion des entrées et sortie en java
    Par lecyberax dans le forum Entrée/Sortie
    Réponses: 3
    Dernier message: 14/05/2006, 22h51

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