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 :

[WxPython] exemple de navigateur graphique mais bogué


Sujet :

wxPython

  1. #1
    Membre du Club Avatar de Kyti
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 182
    Points : 59
    Points
    59
    Par défaut [WxPython] exemple de navigateur graphique mais bogué
    Bonjour,
    je débute en python, et j'ai trouvé un exemple de navigateur graphique :
    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
    from wxPython.wx import *
    from wxPython.html import *
    import httplib
     
    class MyApp(wxApp):
    	def OnInit(self):
                frame = Myframe(None, -1, "Un navigateur web en Python !!")
                frame.Show(true)
                self.SetTopWindow(frame)
                return true
     
    class Myframe(wxFrame):
    	def __init__(self, parent, id, title):
    		wxFrame.__init__(self,parent,id,title)
    		self.SetSize(wxSize(400,400))
    		self.Center(wxBOTH)
    		StatusBar = wxStatusBar(self, -1)
    		StatusBar.SetFieldsCount(2)
    		self.SetStatusBar(StatusBar)
    		MainMenu = wxMenuBar()
    		MenuFichier =wxMenu()
    		idNav = wxNewId()
    		MenuFichier.Append(idNav, 'Naviguer', 'Page de garde de http://localhost')
    		EVT_MENU(self, idNav,self.OnNavigate())
    		MenuFichier.Append(wxID_EXIT,self.OnCloseWindow(EVT_MENU))
    		MainMenu.Append(MenuFichier, 'Fichier')
    		Self.SetMenuBar(MainMenu)
    		Self.myhtml_window = MyHtmlWindow(self, -1)
     
            def OnCloseWindow(self, event):
                self.Destroy()
     
            def OnNavigate(self, event):
                self.myhtml_window.GetDoc('/')
     
    class MyHtmlWindow(wxHtmlWindow):
    	def __init__(self, parent, id):
    		wxHtmlWindow.__init__(self, parent, id)
    		self.http = httplib.HTTP('localhost')
     
    	def GetDoc(self, doc):
    		self.http.putrequest('GET', doc)
    		self.http.putheader('Accept', '/text/html')
    		self.http.purheader('Accept','text/plain')
    		self.http.endheaders()
                    errcode, errmsg, headers = self.http.getreply()
                    if not errcode == 200:
                        self.SetPage("Impossible de charger la page : ",errcode)
                    #return
     
                    handle = self.http.getfile()
                    document = handle.read()
                    handle.close()
                    print headers
                    print document
                    self.SetPage(document)
     
            def OnlinkClicked(self, linkinfo):
                self.GetDoc('/' + linkinfo.GetHref())
     
    app = MyApp(0)
    app.MainLoop()
    mais ça ne marche pas. j'obtiens des erreurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Traceback (most recent call last):
      File "F:/[...]/navigGraph.py", line 61, in ?
        app = MyApp(0)
      File "F:\PROGRA~1\PROGRA~1\Python23\Lib\site-packages\wx-2.5.5-msw-ansi\wx\_core.py", line 5691, in __init__
        self._BootstrapApp()
      File "F:\PROGRA~1\PROGRA~1\Python23\Lib\site-packages\wx-2.5.5-msw-ansi\wx\_core.py", line 5343, in _BootstrapApp
        return _core_.PyApp__BootstrapApp(*args, **kwargs)
      File "F:/[...]/navigGraph.py", line 7, in OnInit
        frame = Myframe(None, -1, "Un navigateur web en Python !!")
      File "F:/[...]/navigGraph.py", line 24, in __init__
        EVT_MENU(self, idNav,self.OnNavigate())
    TypeError: OnNavigate() takes exactly 2 arguments (1 given)
    pour la fonction OnNavigate, je ne sais pas quoi lui passer en paramètre.

    Dans la fonctionOnInit, je ne comprends pas ce qui ne va pas.

    S'IL VOUS PLAIT A L'AIDE !!! j'y comprends rien !

    sinon est-ce que quelqu'un connait un bon tutoriel, précis et en français, pour programmer un navigateur ?

    MERCI

    Titre modifié par Guigui_

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    19
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2003
    Messages : 19
    Points : 14
    Points
    14
    Par défaut
    Salut

    t'as bien installer Wxpython.

    vérifie si elle correspond avec la version de python que tu as.

  3. #3
    Membre averti
    Avatar de Alain_72
    Inscrit en
    Août 2004
    Messages
    180
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 180
    Points : 342
    Points
    342
    Par défaut
    Il y avait pas mal d'erreurs dans ton code...

    Le voila corrigé:

    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
    from wxPython.wx import *
    from wxPython.html import *
    import httplib
     
    class MyApp(wxApp):
      def OnInit(self):
        frame = Myframe(None, -1, "Un navigateur web en Python !!")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true
     
    class Myframe(wxFrame):
      def __init__(self, parent, id, title):
        wxFrame.__init__(self,parent,id,title)
        self.SetSize(wxSize(400,400))
        self.Center(wxBOTH)
        StatusBar = wxStatusBar(self, -1)
        StatusBar.SetFieldsCount(2)
        self.SetStatusBar(StatusBar)
        MainMenu = wxMenuBar()
        MenuFichier =wxMenu()
        idNav = wxNewId()
        MenuFichier.Append(wxID_OPEN, 'Naviguer', 'Page de garde de http://localhost')
        MenuFichier.Append(wxID_EXIT, "Fermer")
        MainMenu.Append(MenuFichier, 'Fichier')
        self.SetMenuBar(MainMenu)
        self.myhtml_window = MyHtmlWindow(self, -1)
        self.Bind(EVT_MENU, self.OnCloseWindow, id = wxID_EXIT)
        self.Bind(EVT_MENU, self.OnNavigate, id = wxID_OPEN)
     
      def OnCloseWindow(self, event):
        self.Destroy()
     
      def OnNavigate(self, event):
        self.myhtml_window.GetDoc('/')
     
    class MyHtmlWindow(wxHtmlWindow):
      def __init__(self, parent, id):
        wxHtmlWindow.__init__(self, parent, id)
        self.http = httplib.HTTP('localhost')
     
      def GetDoc(self, doc):
        self.http.putrequest('GET', doc)
        self.http.putheader('Accept', '/text/html')
        self.http.putheader('Accept','text/plain')
        self.http.endheaders()
        errcode, errmsg, headers = self.http.getreply()
        if not errcode == 200:
          self.SetPage("Impossible de charger la page : ",errcode)
          #return
     
        handle = self.http.getfile()
        document = handle.read()
        handle.close()
        print headers
        print document
        self.SetPage(document)
     
      def OnlinkClicked(self, linkinfo):
        self.GetDoc('/' + linkinfo.GetHref())
     
    app = MyApp(0)
    app.MainLoop()
    Compares ton code avec le mien pour comprendre tes erreurs.

    Par contre, je n'ai pas étudié les problèmes de connexion...

  4. #4
    Membre du Club Avatar de Kyti
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 182
    Points : 59
    Points
    59
    Par défaut
    Citation Envoyé par reolik
    Salut

    t'as bien installer Wxpython.

    vérifie si elle correspond avec la version de python que tu as.
    oui j'ai la bonne version de wxpython, j'ai demandé ici laquelle je devais installer avant de le faire car je ne savais pas.

  5. #5
    Membre du Club Avatar de Kyti
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 182
    Points : 59
    Points
    59
    Par défaut
    Alain_72 je te remercie pour ton aide, je corrigerai et je testerai ça ce soir !

    Merci beaucoup

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

Discussions similaires

  1. Réponses: 6
    Dernier message: 20/11/2009, 18h17
  2. Réponses: 1
    Dernier message: 23/03/2009, 18h17
  3. Réponses: 4
    Dernier message: 21/02/2007, 12h04
  4. Exemple de navigateur Wap
    Par tony4758 dans le forum Java ME
    Réponses: 6
    Dernier message: 08/10/2006, 16h37
  5. bon exemple d'interface graphique
    Par hysah dans le forum AWT/Swing
    Réponses: 16
    Dernier message: 02/06/2006, 00h11

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