how to use python text editor in web page

hi all,
is there is a way that i can use to make the following wxPython app
used as a web page control in an html file???
please help me if you could here is the code

···

===========================================
#!/usr/bin/python
""""
أعوذ بالله من الشيطان الرجيم
بسم الله الرحمن الرحيم

يس والقرآن الحكيم انك لمن المرسلين على صراط مستقيم تنزيل العزيز الرحيم
لتنذر قوما ما أنذر آباؤهم فهم غافلون لقد حق القول على أكثرهم فهم لا
يؤمنون انا جعلنا فى أعناقهم أغلالاً فهى الى الأذقان فهم مقمحون وجعلنا
من بين أيديهم سدا ومن خلفهم سدا فأغشيناهم فهم لا يبصرون

الله لا اله الا هو الحى القيوم لا تأخذه سنة ولا نوم له ما فى السموات
وما فى الأرض من ذا الذى يشفع عنده الا باذنه يعلم ما بين أيديهم وما
خلفهم ولا يحيطون بشىء من علمه الا بما شاء وسع كرسيه السموات والأرض ولا
يؤده حفظهما وهو العلي العظيم

اللهم أكتب لى حسنة بهذا الكود واعدل الديركشن العربي فى الكود الانجليزى
الخاص بويندوز وانفعني بالكود الحالى يارب وأطعمنى منه من حلال
"""

import wx
import os
import codecs
import string

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        self.dirname=''
        # A "-1" in the size parameter instructs wxWidgets to use the
default size.
        # In this case, we select 200px width and the default height.
        wx.Frame.__init__(self, parent, title=title, size=(500,700))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE )
        self.sb=self.CreateStatusBar() # A Statusbar in the bottom of
the window

        self.sb.StatusText="text editor"
        f = wx.Font(18, wx.SWISS , wx.NORMAL, wx.BOLD, True)
        f.SetFaceName("KacstPoster")
        self.control.SetFont(f)

        # Setting up the menu.
        filemenu= wx.Menu()
        menuOpen = filemenu.Append(wx.ID_OPEN, "&Open\tCtrl+O", " Open
a file to edit")
        menuSave = filemenu.Append(wx.ID_SAVE, "&Save\tCtrl+S", " Save
the file")
        menuAbout= filemenu.Append(wx.ID_ABOUT, "&About", " about
program")
        menuExit= filemenu.Append(wx.ID_EXIT, "E&xit\tCtrl+X", "
Terminate the program")

        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to
the MenuBar
        self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
content.

        # Events.
        self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
        self.Bind(wx.EVT_MENU, self.OnSave, menuSave)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)

        self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.buttons = []
        #for i in range(0, 6):
         # self.buttons.append(wx.Button(self,wx.ID_CLEAR, "Button"+
str(i)))
         #self.sizer2.Add(self.buttons[i], 1, wx.EXPAND)
        self.AddButtons(self,self.sizer2)

        # Use some sizers to see layout options
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.control, 1, wx.EXPAND)
        self.sizer.Add(self.sizer2, 0, wx.EXPAND)

        self.file_name1=""
        self.file1=None
        self.current_directory="/data/python/"

        #Layout sizers
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.sizer.Fit(self)
        self.Show()

    def OnAbout(self,e):
        # Create a message dialog box
        dlg = wx.MessageDialog(self, " A sample editor \n in
wxPython", "About Sample Editor", wx.OK)
        dlg.ShowModal() # Shows it
        dlg.Destroy() # finally destroy it when finished.

    def OnExit(self,e):
        self.Close(True) # Close the frame.

    def OnOpen(self,e):
        """ Open a file"""
        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "",
"*.*", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            f = codecs.open(os.path.join(self.dirname, self.filename),
'r','utf-8','strict')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()

    def OnSave(self,e):
        """Save the file"""
        if self.filename is None:
            if self.dirname is None:
                self.dirname = '.'

            dlg = wx.FileDialog(self, "Choose a file", self.dirname,
"", "*.*", wx.SAVE)
            if dlg.ShowModal() == wx.ID_OK:
                self.filename = dlg.GetFilename()
                self.dirname = dlg.GetDirectory()
            dlg.Destroy()

        if os.path.isdir(self.dirname):
            fullName = os.path.join(self.dirname, self.filename)
            f = codecs.open(fullName, 'w','utf-8')
            f.write(self.control.GetValue())
            f.close()

    def NewButton(self, window, container, name, pos, size, handler):
            buttonId = wx.NewId()
            if pos == None or size == None:
                container.Add(wx.Button(window, buttonId, name), 0, 0)
            else:
                container.Add(wx.Button(window, buttonId, name, pos,
size), 0, 0)
            self.Bind(wx.EVT_BUTTON, handler, id=buttonId)
            return buttonId

        # override this to make more buttons
    def AddButtons(self, window, container):
            buttonPos = None
            buttonSize = None
            self.NewButton(window, container, "new file ", buttonPos,
buttonSize, self.OnNewFile)
            self.NewButton(window, container, "open file", buttonPos,
buttonSize, self.OnOpenFile)
            self.NewButton(window, container, "save file", buttonPos,
buttonSize, self.OnSaveFile)
            self.NewButton(window, container, "save file as",
buttonPos, buttonSize, self.OnSaveFile_as)
            self.NewButton(window, container, "close file", buttonPos,
buttonSize, self.OnCloseFile)
            self.NewButton(window, container, "arabic html rtl file",
buttonPos, buttonSize, self.arabic_html_rtl)
            self.NewButton(window, container, "english html ltr file",
buttonPos, buttonSize, self.english_html_ltr)
            self.NewButton(window, container, "arabic xml rtl file",
buttonPos, buttonSize, self.arabic_xml_rtl)
            self.NewButton(window, container, "english xml ltr file",
buttonPos, buttonSize, self.english_xml_ltr)

    def OnNewFile(self, event):
            print "new file"
            self.sb.StatusText="new file"
            self.file_name1=""
            self.file1=None
            self.control.SetValue("")
            self.sb.StatusText=self.sb.StatusText +"...
done"

    def OnCloseFile(self, event):
        print "close file"

        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="close file...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(self.control.GetValue())
          self.file1.close()
          self.file_name1=""
          self.control.SetValue("")
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def OnOpenFile(self, event):
        print "open file\n"

        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="open file...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'r','utf-8',
'strict')
          self.control.SetValue(self.file1.read())
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def OnSaveFile(self, event):
        print "save file"
        wildcard = "All files (*.*)|*.*"
        #dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
"", wildcard, wx.SAVE)
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.SAVE)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="save file...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(self.control.GetValue())
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def OnSaveFile_as(self, event):
        print "save file as"
        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.SAVE)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="save file as...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(self.control.GetValue())
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def arabic_html_rtl_split(self,str1,str2):
        temp=string.replace(str1,"&","&")
        temp=string.replace(temp,"<","&lt;")
        temp=string.replace(temp,">","&gt;")
        temp=string.replace(temp, '"', '&quot;')
        temp=string.replace(temp, "'", '&#39;')
        temp=string.replace(temp,"\n\n","\n")
        temp=string.replace(temp," "," ")

        arr= temp.split(str2)
        paragraphs= len(arr)
        result="<html><head> <meta http-equiv='Content-Type'
content='text/html; charset=utf-8'><title>test</title></head><body>"
        i=0
        while i < paragraphs:
            temp2= arr[i]
            if 0 < len(temp2)<= 60:
              result=result +"<p class='title' align='center' ><font
color='#880000'>"+temp2+"</font></p>\n"
            else:
              result=result +"<p class='p_rtl' align='right'><font
color='#000000'>"+temp2+"</font></p>\n"
            i=i+1
        result=result +"</html>"
        return(result)

    def arabic_html_rtl(self, event):
        print "arabic html right to left "
        temp=self.arabic_html_rtl_split(self.control.GetValue(),"\n")
        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.SAVE)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="arabic html right to
left...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(temp)
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def english_html_ltr_split(self,str1,str2):
        temp=string.replace(str1,"&","&amp;")
        temp=string.replace(temp,"<","&lt;")
        temp=string.replace(temp,">","&gt;")
        temp=string.replace(temp, '"', '&quot;')
        temp=string.replace(temp, "'", '&#39;')
        temp=string.replace(temp,"\n\n","\n")
        temp=string.replace(temp," "," ")

        arr= temp.split(str2)
        paragraphs= len(arr)
        result="<html><head> <meta http-equiv='Content-Type'
content='text/html; charset=utf-8'><title>test</title></head><body>"
        i=0
        while i < paragraphs:
            temp2= arr[i]
            if 0 < len(temp2)<= 60:
              result=result +"<p class='title' align='center' ><font
color='#880000'>"+temp2+"</font></p>\n"
            else:
              result=result +"<p class='p_rtl' align='left'><font
color='#000000'>"+temp2+"</font></p>\n"
            i=i+1
        result=result +"</html>"
        return(result)

    def english_html_ltr(self, event):
        print "english html left to right "
        temp=self.english_html_ltr_split(self.control.GetValue(),"\n")
        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.SAVE)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="english html left to
right...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(temp)
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def arabic_xml_rtl_split(self,str1,str2):
        temp=string.replace(str1,"&","&amp;")
        temp=string.replace(temp,"<","&lt;")
        temp=string.replace(temp,">","&gt;")
        temp=string.replace(temp, '"', '&quot;')
        temp=string.replace(temp, "'", '&#39;')
        temp=string.replace(temp,"\n\n","\n")
        temp=string.replace(temp," "," ")
        #temp=temp.replace(" ", "&nbsp;")

        arr= temp.split(str2)
        paragraphs= len(arr)
        result="<data>"
        i=0
        while i < paragraphs:
            temp2= arr[i]
            if temp2 !="\n":
              if 0 < len(temp2)<= 60:
                result=result +"<title>"+temp2+"</title>\n"
              else:
                result=result +"<para>"+temp2+"</para>\n"
            i=i+1
        result=result +"</data>"
        result.replace("<title></title>", "")
        result.replace("<para></para>", "")
        return(result)

    def arabic_xml_rtl(self, event):
        print "arabic xml right to left "
        temp=self.arabic_xml_rtl_split(self.control.GetValue(),"\n")
        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.SAVE)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="arabic xml right to
left...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(temp)
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

    def english_xml_ltr_split(self,str1,str2):
       temp=string.replace(str1,"&","&amp;")
       temp=string.replace(temp,"<","&lt;")
       temp=string.replace(temp,">","&gt;")
       temp=string.replace(temp, '"', '&quot;')
       temp=string.replace(temp, "'", '&#39;')
       temp=string.replace(temp,"\n\n","\n")
       temp=string.replace(temp," "," ")

       arr= temp.split(str2)
       paragraphs= len(arr)
       result="<data>"
       i=0
       while i < paragraphs:
            temp2= arr[i]
            if 0 < len(temp2) < 60:
              result=result +"<title>"+temp2+"</title>\n"
            else:
              result=result +"<para>"+temp2+"</para>\n"
            i=i+1
       result=result +"</data>"
       result.replace("<title></title>", "")
       result.replace("<para></para>", "")
       return(result)

    def english_xml_ltr(self, event):
        print "english xml left to right "
        temp=self.english_xml_ltr_split(self.control.GetValue(),"\n")
        wildcard = "All files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose a file",
self.current_directory, "", wildcard, wx.SAVE)
        if dialog.ShowModal() == wx.ID_OK:
          print dialog.GetPath()
          self.sb.StatusText="english xml left to
right ...."+dialog.GetPath() +""
          self.file_name1 =dialog.GetPath()
          self.file1=codecs.open(self.file_name1, 'w','utf-8')
          self.file1.write(temp)
          self.file1.close()
          self.sb.StatusText=self.sb.StatusText+"...done"
        dialog.Destroy()

app = wx.App(False)
frame = MainWindow(None, "text editor-te")
app.MainLoop()

===========================================
thanks in advance
Best Regards
hg

shang wrote:

hi all,
is there is a way that i can use to make the following wxPython app
used as a web page control in an html file???

I'm sorry, I don't understand what that means. You may need to explain better -- you have found wx.HtmlWindow, haven't you?

Also:
http://wiki.wxpython.org/MakingSampleApps

i.e. make you samples a small as possible.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hi Christopher Barker,

I mean if I have wxPython small application and I want it to be put as a plugin in html file just like java applet or windows ocx but on linux can that be done or not if the answer is yes can you please show me the syntax and a detailed how to

thanks in advance
Best Regards
hg

···

On Wed, Feb 10, 2010 at 7:37 PM, Christopher Barker Chris.Barker@noaa.gov wrote:

shang wrote:

hi all,

is there is a way that i can use to make the following wxPython app

used as a web page control in an html file???

I’m sorry, I don’t understand what that means. You may need to explain better – you have found wx.HtmlWindow, haven’t you?

Also:

http://wiki.wxpython.org/MakingSampleApps

i.e. make you samples a small as possible.

-Chris

Christopher Barker, Ph.D.

Oceanographer

Emergency Response Division

NOAA/NOS/OR&R (206) 526-6959 voice

7600 Sand Point Way NE (206) 526-6329 fax

Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

The simple answer is no. wxPython is not a web technology that you can
just embed in a web browser. However, it has been tried and I think
the following talks from PyCon covered the topic well:

http://us.pycon.org/2009/conference/schedule/event/92/
http://us.pycon.org/2009/conference/schedule/event/58/

As I recall, there are videos of the talks on blip.tv as well.

If you really need Python in the browser, then look at IronPython +
Silverlight (or Mono/Moonlight).

···

On Feb 11, 1:09 am, Hatem El-Zanaty <shang5...@gmail.com> wrote:

Hi Christopher Barker,I mean if I have wxPython small application and I want
it to be put as a plugin in html file just like java applet or windows ocx
but on linux can that be done or not if the answer is yes can you please
show me the syntax and a detailed how to
thanks in advance
Best Regards
hg

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/

wxPython does not have that capability.

···

On 2/10/10 11:09 PM, Hatem El-Zanaty wrote:

      Hi Christopher Barker,

I mean if I have wxPython small application and I want it to be put as a
plugin in html file just like java applet or windows ocx but on linux
can that be done or not if the answer is yes can you please show me the
syntax and a detailed how to

--
Robin Dunn
Software Craftsman