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

GUI Python Discussion :

Affichage dans Kivy Launcher


Sujet :

GUI Python

  1. #1
    Membre expérimenté
    Homme Profil pro
    Ingénieur Qualité (Microtechnique)
    Inscrit en
    Février 2016
    Messages
    188
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur Qualité (Microtechnique)
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2016
    Messages : 188
    Par défaut Affichage dans Kivy Launcher
    Bonjour,
    Déjà d’avance je vous remercie pour votre aide. Je suis assez nouveau dans le monde Python.
    J’ai un programme que j’ai fait et qui s’affiche parfaitement en mode desktop (MacOS) mais certaines chose ne marche pas quand je lance dans Kivy Launcher.

    main.py
    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
    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
    import kivy
    from math import sin
     
    import datetime
    from time import strftime
     
    from kivy.app import App
    from kivy.uix.label import Label
    from kivy.uix.gridlayout import GridLayout
    from kivy.uix.floatlayout import FloatLayout 
    from kivy.uix.textinput import TextInput
    from kivy.uix.image import Image
    from kivy.uix.button import Button
    from kivy.uix.widget import Widget
    from kivy.properties import ObjectProperty, NumericProperty
    from kivy.clock import Clock
    from kivy.uix.behaviors.button import ButtonBehavior
    from kivy.storage.jsonstore import JsonStore
    from datetime import date
    from kivy.lang import Builder
    from kivy.uix.screenmanager import ScreenManager, Screen
    from kivy.uix.boxlayout import BoxLayout
    from kivy.garden.graph import Graph, MeshLinePlot, LinePlot
     
    class MyGrid(Screen):
        texte_label=ObjectProperty(None)
        pourc=ObjectProperty(None)
        image_but=ObjectProperty(None)
        progbar=ObjectProperty(rebind = True)
        #line_bar=ObjectProperty(None)
        chrono_activ=False
        anglestop = NumericProperty(0)
        h=0
        m=0
        s=0
        fact_pourc=864
        chrono=0
     
        def __init__(self, **kwargs):
            super(MyGrid, self).__init__(**kwargs)
            self.leave_main=False
            self.store = JsonStore('date_time.json')
            if self.store.exists(str(date.today())):
                self.chrono=int(self.store.get(str(date.today()))['time'])-1
                self.change_time(0)
            else:
                chrono=0
        def btn(self):
            if self.chrono_activ==False and self.leave_main==False:
                self.chrono_activ=True
                self.image_but.source='logo.png'
                Clock.schedule_interval(self.change_time, 0.01)
            else:
                self.chrono_activ=False
                self.image_but.source='logo2.png'
                Clock.unschedule(self.change_time)
                self.save_time(self.chrono)
     
     
        def save_time(self,tp):
            self.store = JsonStore('date_time.json')
            self.store.put(str(date.today()), time=str(tp))
     
        def change_time(self,dt):
            self.chrono+=1
            m, s = divmod(self.chrono, 60)
            h, m = divmod(m, 60)
            self.texte_label.text='{:02d}:{:02d}:{:02d}'.format(h, m, s)
            self.pourc.text='{0:.0%}'.format(self.chrono/self.fact_pourc)
     
            if self.chrono/self.fact_pourc>0:
                self.anglestop=360*(self.chrono/self.fact_pourc-int(self.chrono/self.fact_pourc))
        def on_enter(self, *args):
            self.leave_main=False    
        def on_leave(self, *args):
            self.leave_main=True
     
            self.btn()
     
     
    class ImageButton(ButtonBehavior, Image):
        pass
     
     
    class graphScreen(Screen):
        def __init__(self, **kwargs):
            global canvas
            super(graphScreen, self).__init__(**kwargs)
     
        def on_enter(self, *args):
            self.create_date_graph(7)
     
        def create_date_graph(self,date_delta):
            self.store = JsonStore('date_time.json')
            for plot in self.ids.graph.plots:
                self.ids.graph.remove_plot(plot)
     
            plot = MeshLinePlot(color=[1, 0, 0, 1])
            date_start = date.today()
            date_range=[]
            time_range=[]
     
     
            for d in range(date_delta-1,-1,-1):
                date_act=str(date.today() - datetime.timedelta(days = d))
                date_range.append(str(date_act))
                if self.store.exists(date_act):
                    time_range.append(int(self.store.get(date_act)['time'])/8.64)
                else:
                    time_range.append(0)
     
            x_values=range(date_delta)
            y_values = time_range
            new_list = list(zip(x_values, y_values))
            plot = LinePlot(line_width=4, color=[0, 1, 0, 1])
     
     
            plot.points = new_list
            self.ids.graph._clear_buffer()
     
            self.ids.graph.add_plot(plot)
            self.ids.graph.ymax=max(y_values)*1.1
            self.ids.graph.xmax=date_delta-1
    class MyApp(App): # <- Main Class
     
        def build(self):
            self.root = Builder.load_file('my.kv')
            sm = ScreenManager()
            sm.add_widget(MyGrid(name='menu'))
            sm.add_widget(graphScreen(name='graph'))
            return sm
     
     
    if __name__ == "__main__":
     
        MyApp().run()
    my.kv
    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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    # Filename: my.kv
     
     
    <MyGrid>:
        texte_label: texte_label
        pourc: pourc
        image_but: image_but
     
        GridLayout:
            cols:1
            size: root.width, root.height
     
            GridLayout:
                cols:2
                font_size: 50
                Label:
                    id: texte_label
                    text: ""
                Label:
                    id: pourc
                    text: ""
            ImageButton:
                source: "logo2.png"
                id: image_but
                on_release: root.btn()
                size: 200,200
     
            GridLayout:
                cols:2
                ImageButton:
                    source: "graph.png"
                    on_press: root.manager.current = 'graph'
                Label:
                    text: ""
        FloatLayout:
            canvas:
     
                Color:
                    rgba: 0.086, 0.470, 0.501,1
                Line:
                    id: progbar
                    width: 3.
                    circle: self.center_x, self.center_y, 100, 0, root.anglestop
    <graphScreen>:
        graphJson: graphJson
        GridLayout:
            cols:1
            size: root.width, root.height
            BoxLayout:
                id: graphJson
                Graph:
                    id: graph
                    background_color: 0, 0, 0, 0
                    border_color: 1, 1, 1, 1
                    xlabel: 'days'
                    ylabel: '%'
                    y_grid_label: True
                    x_grid_label: False
                    xmin: 0
                    padding:5
                    x_grid: True
                    y_grid: False
                    y_ticks_major:100
     
            GridLayout:
                cols:2
                ImageButton:
                    source: "time.png"
                    on_press: root.manager.current = 'menu'
                Label:
                    text: ""
    Mon problème est que les lignes ne se mettent pas à jour dans Kivy Launcher:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    self.pourc.text='{0:.0%}'.format(self.chrono/self.fact_pourc)
    self.anglestop=360*(self.chrono/self.fact_pourc-int(self.chrono/self.fact_pourc))

    La première devrait afficher un pourcentage dans un label et l'autre changer l'angle d'une barre de progression.
    Qu'en pensez-vous?

  2. #2
    Membre expérimenté
    Homme Profil pro
    Ingénieur Qualité (Microtechnique)
    Inscrit en
    Février 2016
    Messages
    188
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur Qualité (Microtechnique)
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2016
    Messages : 188
    Par défaut
    J’ai trouvé mon problème.
    Cela venait de l’interprétation du calcul
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self.chrono/self.fact_pourc
    Dans Kivy Launcher, ce calcul était interprété en integer. Tant que la variable chrono n’était pas plus grande que le facteur de calcul, la valeur restait à zéro.
    Pour changer cela, j’ai changé la ligne :
    Le « . » permet de spécifier que la valeur est un float et cela permet d’interpréter les calculs aussi en float.

    J’espère que cela pourra aider d’autres personnes

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

Discussions similaires

  1. [CR8.5] Pbm d'affichage dans un While
    Par .:Tieri:. dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 14/07/2004, 11h17
  2. [mfc] affichage dans une boite de dialog
    Par chronos dans le forum MFC
    Réponses: 3
    Dernier message: 14/06/2004, 16h12
  3. [Flash MX] Pb d'affichage dans un textfield
    Par dens63 dans le forum Flash
    Réponses: 2
    Dernier message: 04/11/2003, 11h49
  4. Problème a l'affichage dans la console (printf)
    Par PhoneKilleR dans le forum C
    Réponses: 21
    Dernier message: 23/09/2003, 18h21
  5. affichage dans le front buffers ne marche pas!
    Par jamal24 dans le forum OpenGL
    Réponses: 3
    Dernier message: 22/08/2003, 20h14

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