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

wxPython Discussion :

ouvrir un file dans une panel et visualiser dans une autre panel wxpython


Sujet :

wxPython

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut ouvrir un file dans une panel et visualiser dans une autre panel wxpython
    Bonjour,

    c'est un peu compliquer mais je vais essayer

    bon j'ai une panel ou y a un bouton 'file' pour le choix d'un file et l'ouvrir ce file c'est un fichier .nc ( netCDF4) donc j'aimerai le visualiser mais le problème j'aimerai le visualiser dans une autre panel qui sera comme un quicklook , et à chaque fois faut juste choisir un file de type .nc et directement va être visualiser sur l'autre panel automatiquement

    je sais comment lire et visualiser un fichier .nc sous python voilà un exemple :

    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
    import numpy as np
    import netCDF4
    import matplotlib.pyplot as plt
     
    #lecture du netcdf
    fic='g_xvxvxvxv_20190108T120000Z.nc'
     
    path='/home/globe/2019/01/08/'
     
    nc = netCDF4.Dataset(path+fic,'r')
    #lecture d'un variable 
    cm=nc.variables['cm'][:]
     
    #Affichage de la variable
    plt.pcolormesh(cm)
    plt.colorbar()
    plt.show()
    et voilà une partie de mon code pour 2 panels :

    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
    class LeftPanelTop(wx.Panel): #ici le choix de file 
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('snow2')
            List_choices = ["1Km","3Km"]
            List2 = ["3X3","5X5","7X7"]
            self.dateLbl = wx.StaticBox(self, -1, 'Outils ', size=(310, 320))
     
            self.dategraphSizer = wx.StaticBoxSizer(self.dateLbl, wx.VERTICAL)
            combobox1 = wx.ComboBox(self,choices = List_choices, size =(80,20),pos =(180,50))
            combobox2 = wx.ComboBox(self,choices = List2, size =(80,20),pos =(180,90))
            wx.StaticText(self, label='Reference:', pos=(70, 50))
            wx.StaticText(self, label='Taille :', pos=(70, 90))
            QuickLook = wx.Button(self ,-1, "Open file" , size =(80, 25),pos =(180,130))
            wx.StaticText(self, label='QuickLook:', pos=(70, 130))
            QuickLook.Bind(wx.EVT_BUTTON, self.onOpen)
     
        def onOpen(self, event):
            wildcard = "netCDF4 files (*.nc)|*.nc"
            dialog = wx.FileDialog(self, "Open netCDF4 Files", wildcard=wildcard,
                                   style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
     
            if dialog.ShowModal() == wx.ID_CANCEL:
                return
     
     
            path = dialog.GetPath()
     
    #visualisation ici 
    class LeftPanelBottom(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('whitesmoke')
            self.dateLbl = wx.StaticBox(self, -1, 'QuickLook', size=(310, 600))

    ce que j'aimerai faire c'est utiliser mon code pour lire visualisation des fichier .nc dans mon code et que mes utilisateurs peuvent choisir un file qui existe et après s'affiche automatiquement sur l'autre panel

    merci d'avance pour toute aide

  2. #2
    Membre confirmé

    Homme Profil pro
    Bidouilleur
    Inscrit en
    Avril 2016
    Messages
    721
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Bidouilleur

    Informations forums :
    Inscription : Avril 2016
    Messages : 721
    Points : 503
    Points
    503
    Billets dans le blog
    1
    Par défaut
    Salut.

    Il y a plusieurs façon de faire communiquer des objets.

    Soit en les fournissant en paramètres des instances/méthodes ayant besoin d'accéder à d'autres objets, cela peut être assez difficile selon le niveau de profondeur des objets créés.
    Soit en utilisant un objet référencant les objets partagés par l'application, une classe singleton, un module dédié (qui est déjà un singleton), autres.

    Mais avec wx, en fournissant des name aux widgets, il est possible d'accéder aux objets créés avec la méthode FindWindowByName.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    >>> import wx
    >>> app = wx.App()
    >>> win = wx.Frame(None, name='master')
    >>> p1 = wx.Panel(win, name='panel1')
    >>> p2 = wx.Panel(win, name='panel2')
    >>> p1.FindWindowByName('panel2')
    <wx._core.Panel object at 0x7f50bcc77ca8>
    >>> p1.FindWindowByName('master')
    <wx._core.Frame object at 0x7f50bcc77b88>
    Il faut bien faire attention à ne pas faire de doublons de name.

    Note que je suis comme toi, j'ai cherché l'info, le site de référence est https://docs.wxwidgets.org/3.0/page_class_cat.html (c'est pas pour python, mais cela ne dépayse pas trop vu que la doc est très bien fournie avec des liens pointant vers les autres widgets)
    De là, j'ai regardé ce qu'il y avait dans la doc du panel, pas garnd chose dessus, alors j'ai regardé sur les classes héritées, et paf, on trouve ce qu'il faut dans wxWindow
    Le temps ronge l'amour comme l'acide.

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour,

    mais j'aimerai savoir au moins ou je vais mettre mon code pour le fichier nectcdf5 genre ou mettre le path et le code et comment utiliser matplotlib dans la 2em panel ou la 1er

    c'est compliqué vraiment

    merci d'avance

  4. #4
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour,

    je pense qu il faut utiliser les packag matplotlib et le mettre dans la 2em panel mais comment lier les deux panels , pour que quand j selectionne un file dans openfile automatiquement il va etre visualiser sur l'autre panel , ?

    je pense faut utiliser matplotlib et le code que j ai mis pour la lecture des fichier .nc mais sur quel partie du code et comment indiquer le chemin et que l affichage devra être sur la 2em panel

    c'est compliquer c'est compliquer

    Nom : g.jpg
Affichages : 527
Taille : 16,5 Ko

  5. #5
    Membre confirmé

    Homme Profil pro
    Bidouilleur
    Inscrit en
    Avril 2016
    Messages
    721
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Bidouilleur

    Informations forums :
    Inscription : Avril 2016
    Messages : 721
    Points : 503
    Points
    503
    Billets dans le blog
    1
    Par défaut
    Salut.

    Citation Envoyé par soma12 Voir le message
    ... mais comment lier les deux panels , pour que quand j selectionne un file dans openfile automatiquement il va etre visualiser sur l'autre panel , ?
    Bah, c'est à toi d'organiser ton code comme il faut, si dans ton 1er panel il y a ouverture d'un fichier et que son contenu doit être fourni à un second panel, alors une méthode de ton cru devra être ajouté au 2nd panel afin que l'on puisse lui fournir ces données et qu'il sache quoi en faire pour afficher un graphique matplotlib.
    Le temps ronge l'amour comme l'acide.

  6. #6
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour ,

    j’essaie de trouver une solution je test comme ça quand j m bloque je poste pour voir où le problème

    merci d'avance

  7. #7
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour,

    je viens de faire une petit exemple mais pas dans mon appl seulement a part maintenant j'aimerai que la frame de visualisation soi pas séparer de mes panels j'aimerai que ça sera la leftpanelbottom

    bon voilà 1er code :

    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
    import wx
     
    import numpy as np
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    from matplotlib.figure import Figure
    import matplotlib.pyplot as plt
     
    import netCDF4 
    from netCDF4 import Dataset
     
    class MyFrame(wx.Frame):
        def __init__(self, *args, **kwargs):
            wx.Frame.__init__(self, *args, **kwargs)
            panel = wx.Panel(self)
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            self.select_button = wx.Button(panel, label="Select file")
            sizer.Add(self.select_button, 0, 0, 0)
            self.select_button.Bind(wx.EVT_BUTTON, self.pick_file)
            self.load_options = "netCDF4 files (nc)|*.nc| Text files (txt) |*.txt| All files |*.*"
            panel.SetSizer(sizer)
     
        def pick_file(self, event):
            with wx.FileDialog(self, "Pick files", wildcard=self.load_options,
                               style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE) as fileDialog:
                if fileDialog.ShowModal() != wx.ID_CANCEL:
                    chosen_file = fileDialog.GetPath()
                    if chosen_file.endswith('.txt'):
                        #Method pour utiliser autre frame
                        QuickLook(parent=self, text=chosen_file)
                    elif chosen_file.endswith('.nc'):
                        QuickLook_plot(parent=self, text=chosen_file)
     
     
     
    class QuickLook_plot(wx.Frame):
        def __init__(self, parent,text=None):
            wx.Frame.__init__(self, parent, wx.ID_ANY, "Quick Plot", size=(610,510))
            panel = wx.Panel(self, wx.ID_ANY, size=(600,500))
            self.figure = Figure()
            self.axes = self.figure.add_subplot(111)
            self.canvas = FigureCanvas(panel, -1, self.figure)
            Quit_button = wx.Button(panel, wx.ID_ANY, "&Quit")
            Quit_button.Bind(wx.EVT_BUTTON, self.OnQuit)
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
            self.sizer.Add(Quit_button, 0,wx.ALIGN_RIGHT)
            panel.SetSizerAndFit(self.sizer)
            #plot figure
     
            fic='S_NWC_CI-20180220T090000Z.nc'
     
            path='/net/stockage2018/02/20/'
     
            nc = netCDF4.Dataset(path+fic,'r')
            cma_recup=nc.variables['ci_prob30'][:]
     
            #Affichage de la variable
            plt.pcolormesh(cma_recup)
            plt.colorbar()
            plt.show()
     
        def OnQuit(self,event):
            self.Close()
            self.Destroy()
     
    class MyApp(wx.App):
        def OnInit(self):
            frame = MyFrame(None, -1, 'A test dialog')
            frame.Show()
            return True
     
    if __name__ == "__main__":
        app = MyApp()
        app.MainLoop()
    ça me donne une visualisation comme ça :

    Nom : Capture du 2019-03-26 09-56-15.png
Affichages : 516
Taille : 40,1 Ko
    et après j'ai essayé d’intégrer ce code dans le code de mon application voilà le code de l'application :

    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
    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
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    import wx
    import os
    import numpy as np
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    from matplotlib.figure import Figure
    import matplotlib.pyplot as plt
     
    import netCDF4 
    from netCDF4 import Dataset
     
     
    class MainFrame(wx.Frame):
     
        def __init__(self,parent):
            super().__init__(parent, title="QUICK", size=(2000, 1000))
     
            left = LeftPanel(self)
            middle = MiddlePanel(self)
            right = RightPanel(self)
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            sizer.Add(left, 3, wx.EXPAND)
            sizer.Add(middle, 5, wx.EXPAND)
            sizer.Add(right, 5, wx.EXPAND)
            self.SetSizer(sizer)
            sizer1 = wx.BoxSizer(wx.VERTICAL)
            sizer1.Add(left,2,wx.EXPAND)
            sizer1.Add(right,2,wx.EXPAND)
            sizer1.Add(middle,2,wx.EXPAND)
     
            self.Show()
     
     
    class LeftPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent)
            self.SetBackgroundColour('122')
     
     
    class MiddlePanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent)
            self.SetBackgroundColour('179')
     
     
    class RightPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent)
            self.SetBackgroundColour('179 ')
     
    class LeftPanelTop(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('snow2')
            List_choices = ["1Km","3Km"]
            List2 = ["3X3","5X5","7X7"]
            self.dateLbl = wx.StaticBox(self, -1, 'Outils ', size=(410, 320))
     
            self.dategraphSizer = wx.StaticBoxSizer(self.dateLbl, wx.VERTICAL)
            combobox1 = wx.ComboBox(self,choices = List_choices, size =(80,20),pos =(180,50))
            combobox2 = wx.ComboBox(self,choices = List2, size =(80,20),pos =(180,90))
            wx.StaticText(self, label='Résolution:', pos=(70, 50))
            wx.StaticText(self, label='Taille de cible:', pos=(70, 90))
            QuickLook = wx.Button(self ,-1, "Open file" , size =(80, 25),pos =(180,130))
            wx.StaticText(self, label='QuickLook:', pos=(70, 130))
            QuickLook.Bind(wx.EVT_BUTTON, self.onOpen)
            self.load_options = "netCDF4 files (nc)|*.nc| Text files (txt) |*.txt| All files |*.*"
     
        def onOpen(self, event):
            with wx.FileDialog(self, "On open", wildcard=self.load_options,
                               style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE) as fileDialog:
                if fileDialog.ShowModal() != wx.ID_CANCEL:
                    chosen_file = fileDialog.GetPath()
                    if fileDialog.ShowModal() != wx.ID_CANCEL:
                        chosen_file = fileDialog.GetPath()
                        if chosen_file.endswith('.txt'):
                            QuickLook(parent=self, text=chosen_file)
                        elif chosen_file.endswith('.nc'):
                            QuickLook_plot(parent=self, text=chosen_file)
     
     
    class LeftPanelBottom(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('whitesmoke')
     
     
    class LeftPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
     
            top = LeftPanelTop(self)
            bottom = LeftPanelBottom(self)
     
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(top, 1, wx.EXPAND)
            sizer.Add(bottom, 2, wx.EXPAND)
     
            self.SetSizer(sizer)
     
    class RightPanelTop(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('black')
            canal=wx.Button(self,-1,"Variable",size=(140,30),pos=(100,0))
            dynamique=wx.Button(self,-1,"Dynamique",size=(140,30),pos=(240,0))
            file = wx.Button(self,-1,"File", size = (110,30),pos=(0,0))
            dynamique.SetBackgroundColour('white')
            canal.SetBackgroundColour('white')
            file.SetBackgroundColour('white')
            dynamique.Bind(wx.EVT_BUTTON, self.OnClick)
            file.Bind(wx.EVT_BUTTON, self.onOpen)
     
        def onOpen(self, event):
            wildcard = "netCDF4 files (*.nc)|*.nc| HDF5 files (*.h5) |*.h5"
            dialog = wx.FileDialog(self, "Open netCDF4 Files| HDF5 files", wildcard=wildcard,
                                   style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
     
            if dialog.ShowModal() == wx.ID_CANCEL:
                return
     
     
            path = dialog.GetPath()
     
     
            if os.path.exists(path):
                with open(path) as fobj:
                    for line in fobj:
                        self.my_text.WriteText(line)
     
     
        def OnClick(self,event):
            dlg = wx.TextEntryDialog(self, 'Enter Dynamique of image','Dynamique de image') 
     
            if dlg.ShowModal() == wx.ID_OK: 
             self.text.SetValue("Dynamique:"+dlg.GetValue()) 
            dlg.Destroy()
     
     
     
    class RightPanelBottom(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('red')
     
     
    class RightPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent)
     
            top = RightPanelTop(self)
            bottom = RightPanelBottom(self)
     
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(top, 2, wx.EXPAND)
            sizer.Add(bottom, 2, wx.EXPAND)
            self.SetSizer(sizer)
     
    class MiddlePanelTop(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('black')
            canal=wx.Button(self,-1,label ="Variable",size=(140,30),pos=(100,0))
            dynamique=wx.Button(self,-1,"Dynamique",size=(140,30),pos=(240,0))
            file = wx.Button(self,-1,"File", size = (110,30),pos=(0,0))
            dynamique.SetBackgroundColour('white')
     
            canal.SetBackgroundColour('white')
            file.SetBackgroundColour('white')
            dynamique.Bind(wx.EVT_BUTTON, self.OnClick)
            file.Bind(wx.EVT_BUTTON, self.onOpen)
     
        def onOpen(self, event):
            wildcard = "netCDF4 files (*.nc)|*.nc"
            dialog = wx.FileDialog(self, "Open netCDF4 Files", wildcard=wildcard,
                                   style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
     
            if dialog.ShowModal() == wx.ID_CANCEL:
                return
     
     
            path = dialog.GetPath()
     
            if os.path.exists(path):
                with open(path) as fobj:
                    for line in fobj:
                        self.my_text.WriteText(line)
     
        def OnClick(self,event):
            dlg = wx.TextEntryDialog(self, 'Enter Dynamique of image','Dynamique de image') 
     
            if dlg.ShowModal() == wx.ID_OK: 
             self.text.SetValue("Dynamique:"+dlg.GetValue()) 
            dlg.Destroy()
     
     
    class MiddlePanelBottom(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('black')
            canal=wx.Button(self,-1,"Variable",size=(140,30),pos=(100,0))
            dynamique=wx.Button(self,-1,"Dynamique",size=(140,30),pos=(240,0))
            file = wx.Button(self,-1,"File", size = (110,30),pos=(0,0))
            dynamique.SetBackgroundColour('white')
            canal.SetBackgroundColour('white')
            file.SetBackgroundColour('white')
            dynamique.Bind(wx.EVT_BUTTON, self.OnClick)
            file.Bind(wx.EVT_BUTTON, self.onOpen)
            self.load_options = "netCDF4 files (nc)|*.nc| Text files (txt) |*.txt| All files |*.*"
     
     
        def onOpen(self, event):
            wildcard = "netCDF4 files (*.nc)|*.nc"
            dialog = wx.FileDialog(self, "Open netCDF4 Files", wildcard=wildcard,
                                   style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
     
            if dialog.ShowModal() == wx.ID_CANCEL:
                return
     
     
            path = dialog.GetPath()
     
            if os.path.exists(path):
                with open(path) as fobj:
                    for line in fobj:
                        self.my_text.WriteText(line)
     
        def OnClick(self,event):
            dlg = wx.TextEntryDialog(self, 'Enter Dynamique of image','Dynamique de image') 
     
            if dlg.ShowModal() == wx.ID_OK: 
             self.text.SetValue("Dynamique:"+dlg.GetValue()) 
            dlg.Destroy()
     
     
    class MiddlePanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent)
     
            top = MiddlePanelTop(self)
            bottom = MiddlePanelBottom(self)
     
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(top, 3, wx.EXPAND)
            sizer.Add(bottom, 3, wx.EXPAND)
            self.SetSizer(sizer)
     
     
     
    class PanelTop(wx.Panel):
        def __init__(self,parent):
            super().__init__(parent)
            self.SetBackgroundColour('black')
    class PanelBottom(wx.Panel):
        def __init__(self,parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('grey77')
            self.dateLbl = wx.StaticBox(self, -1, 'Info', size=(700, 280))
            self.dategraphSizer = wx.StaticBoxSizer(self.dateLbl, wx.VERTICAL)
     
    class RightPanelBottom(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent)
     
            top = PanelTop(self)
            bottom = PanelBottom(self)
            sizer1 = wx.BoxSizer(wx.VERTICAL)
            sizer1.Add(top,2, wx.EXPAND)
            sizer1.Add(bottom,4,wx.EXPAND)
            self.SetSizer(sizer1)
     
    class leftPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('black')
    class midllePanel(wx.Panel):
         def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('black')
     
    class rightPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.SetBackgroundColour('black')
     
     
     
     
    class PanelTop(wx.Panel):
        def __init__(self,parent):
            super().__init__(parent)
            left = leftPanel(self)
            right = rightPanel(self)
            midlle = midllePanel(self)
            sizer1 = wx.BoxSizer(wx.HORIZONTAL)
            sizer1.Add(left,2, wx.EXPAND)
            sizer1.Add(midlle,2,wx.EXPAND)
            sizer1.Add(right,2,wx.EXPAND)
            self.SetSizer(sizer1)
     
    class QuickLook_plot(wx.Frame):
        def __init__(self, parent,text=None):
            wx.Frame.__init__(self, parent, wx.ID_ANY, "Quick Plot", size=(610,510))
            panel = wx.Panel(self, wx.ID_ANY, size=(600,500))
            self.figure = Figure()
            self.axes = self.figure.add_subplot(111)
            self.canvas = FigureCanvas(panel, -1, self.figure)
            Quit_button = wx.Button(panel, wx.ID_ANY, "&Quit")
            Quit_button.Bind(wx.EVT_BUTTON, self.OnQuit)
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
            self.sizer.Add(Quit_button, 0,wx.ALIGN_RIGHT)
            panel.SetSizerAndFit(self.sizer)
            #plot figure
     
            fic='S_NWC_CI-VISIR_20180220T090000Z.nc'
     
            path='/net/stockag/safn/2018/02/20/'
     
            nc = netCDF4.Dataset(path+fic,'r')
            ci_recup=nc.variables['ci_prob30'][:]
     
            #Affichage de la variable
            plt.pcolormesh(ci_recup)
            plt.colorbar()
            plt.show()
     
        def OnQuit(self,event):
            self.Close()
            self.Destroy()
     
    class MyApp(wx.App):
        def OnInit(self):
            frame = MyFrame(None, -1, 'A test dialog')
            frame.Show()
            return True
     
    app = wx.App()
    frame = MainFrame(None).Show()
    app.MainLoop()

    donc ça marche pour le 1er exemple juste besoin d'un peu d'aide pour que le Quicklook_plot sera dans la leftpanelbottom pas dans une frame a part , voilà un exemple de fichier .nc faut juste changer le variable a plotter ici c'est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    nc = Dataset('.../air.departure.sig995.2012.nc')
     
            air_dep = nc.variables['air_dep'][:,:,:]
            air_dep = air_dep[0,:,:]
            plt.pcolormesh(air_dep)
            plt.colorbar()
            plt.show()



    lien de fichier .nc
    https://drive.google.com/open?id=1P8...BMKYNRTc9pL-LU

    Mr bistouille

    merci d'avance

  8. #8
    Membre confirmé

    Homme Profil pro
    Bidouilleur
    Inscrit en
    Avril 2016
    Messages
    721
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Bidouilleur

    Informations forums :
    Inscription : Avril 2016
    Messages : 721
    Points : 503
    Points
    503
    Billets dans le blog
    1
    Par défaut
    Salut.

    T'imagines bien que personne ne va tester ton exemple, car, de un il faut installer netCDF4, et de deux ton fichier nc fait plusieurs méga que l'on a pas forcément envie de télécharger.

    Je n'y connais quasiment rien à matplotlib, c'est une bibliothèque dont je ne me sert jamais.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    class QuickLook_plot(wx.Frame):
        def __init__(self, parent,text=None):
            wx.Frame.__init__(self, parent, wx.ID_ANY, "Quick Plot", size=(610,510))
            panel = wx.Panel(self, wx.ID_ANY, size=(600,500))
    Pourquoi déclarer une frame, si tu n'en veux pas ?
    Car là elle ne sert qu'à être le parent du panel, et ce panel puisque tu désires que ce soit celui de la classe LeftPanelBottom, bah il suffit d'intégrer le code de cette classe à la classe LeftPanelBottom.

    En fait le problème est tellement simple à résoudre que je me demande si j'ai bien tout compris où ton problème se situe ô_ô
    Le temps ronge l'amour comme l'acide.

  9. #9
    Membre confirmé

    Homme Profil pro
    Bidouilleur
    Inscrit en
    Avril 2016
    Messages
    721
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Bidouilleur

    Informations forums :
    Inscription : Avril 2016
    Messages : 721
    Points : 503
    Points
    503
    Billets dans le blog
    1
    Par défaut
    Partons de l'exemple de matplotlib https://matplotlib.org/examples/user...ng_in_wx4.html qui est à peu près la même chose que ta classe QuickLook_plot excepté évidemment le rendu graphique du canevas.

    Pour modifier cet exemple afin de l'intégrer à une classe MainFrame existante, alors on pourrait modifier ainsi.

    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
    from numpy import arange, sin, pi
    import matplotlib
     
    matplotlib.use('WXAgg')
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
     
    from matplotlib.backends.backend_wx import _load_bitmap
    from matplotlib.figure import Figure
    from numpy.random import rand
     
    import wx
     
    class MyNavigationToolbar(NavigationToolbar2WxAgg):
        """
        Extend the default wx toolbar with your own event handlers
        """
        ON_CUSTOM = wx.NewId()
        def __init__(self, canvas, cankill):
            NavigationToolbar2WxAgg.__init__(self, canvas)
            if 'phoenix' in wx.PlatformInfo:
                self.AddTool(self.ON_CUSTOM, 'Click me',
                             _load_bitmap('back.png'),
                             'Activate custom contol')
                self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
            else:
                self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('back.png'),
                                   'Click me', 'Activate custom contol')
                self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
     
        def _on_custom(self, evt):
            ax = self.canvas.figure.axes[0]
            x, y = tuple(rand(2))
            rgb = tuple(rand(3))
            ax.text(x, y, 'You clicked me',
                    transform=ax.transAxes,
                    color=rgb)
            self.canvas.draw()
            evt.Skip()
     
     
    class CanvasPanel(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent, size=(550, 400))
            self.figure = Figure(figsize=(5, 4), dpi=100)
            self.axes = self.figure.add_subplot(111)
            self.canvas = FigureCanvas(self, -1, self.figure)
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
            self.toolbar = MyNavigationToolbar(self.canvas, True)
            self.toolbar.Realize()
            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
            self.toolbar.update()
            self.SetSizer(self.sizer)
     
        def draw(self):
            t = arange(0.0, 5.01, 0.01)
            s = sin(2 * pi * t)
            self.axes.plot(t, s)
     
     
    class MainFrame(wx.Frame):
        def __init__(self):
            super().__init__(None, title='Main Window')
            canPanel = CanvasPanel(self)
            # Un autre Panel
            trucPanel = wx.Panel(self, size=(550, 50))
            trucPanel.SetBackgroundColour('orange')
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(canPanel)
            sizer.Add(trucPanel)
            self.SetSizer(sizer)
            canPanel.draw()
     
     
    class App(wx.App):
        def OnInit(self):
            'Create the main window and insert the custom frame'
            frame = MainFrame()
            frame.Show(True)
            return True
     
     
    app = App(0)
    app.MainLoop()
    Ce n'est pas très compliqué, il faut savoir simplement décomposer un problème qui nous semble compliqué en quelque chose de plus simple afin de tester comment faire.
    Le temps ronge l'amour comme l'acide.

  10. #10
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour,

    je me bloque parfois j'arrive pas à comprendre ce que j'aimerai faire

    après pour netcdf4 y a beaucoup personne qui travaillent maintenant sur ça mais bon

    j'ai mis le fichier ou cas ou quelqu'un a un problème comme le mieux ou il travaille avec netcdf4 ...

    sinon j'aimerai vous remercier pour l'aide ,

    ma tête est saturé aujourd’hui

    merci encore

  11. #11
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    BOnjour,

    mais cette partie sert à quoi exactement ? class MyNavigationToolbar(NavigationToolbar2WxAgg):

    j'ai essayé d'intégrer le code de cette classe à la classe LeftPanelBottom mais ça marche pas !!!!

Discussions similaires

  1. Réponses: 8
    Dernier message: 23/01/2024, 21h15
  2. Réponses: 6
    Dernier message: 24/11/2019, 09h16
  3. Ouvrir un fichier dans un autre editeur ?
    Par vnabet dans le forum Eclipse Java
    Réponses: 7
    Dernier message: 07/06/2018, 12h32
  4. Réponses: 6
    Dernier message: 03/04/2007, 10h19
  5. Ouvrir un page dans un autre fenetre
    Par Alec6 dans le forum JSF
    Réponses: 2
    Dernier message: 11/12/2006, 19h33

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