Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

boa and normal coding ?

Help
2009-03-02
2013-05-01
  • steve smith
    steve smith
    2009-03-02

    Hello,
    i am following a book called python programming for absolute beginers. I cant get the following code to make a command box appear so as to give the user the message to hit enter. Its simple code, but will boa work with normal coding ?

    Print "game over"
    raw_input("\n\npress enter key to exit")

    Thats all the book says type in, it does work in idle but i really want to use boa for everything.

    I create a new module btw and that did not work as well creating a brand new python app...but still no joy ?

    Many thanks, steve.

     
    • Steve,

      Boa can run just about any Python code.  The one thing it has a problem with (due to the way it runs the code) is with things like raw_input, i.e. something which wants a response from stdin.

      Boa allows you to create GUI (using wxPython) and you could create a much nicer screen to show to the user that the game is over.

      Have a look at these:
      http://wiki.wxpython.org/Getting%20Started
      http://wiki.wxpython.org/How%20to%20Learn%20wxPython
      http://wiki.wxpython.org/How%20to%20Learn%20wxPython#head-ae8344fe65da52873bc26734fb67cac55e610681

      Ok, a lot more lines, but ...:
      #Boa:Frame:Frame1

      import wx

      def create(parent):
          return Frame1(parent)

      [wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1,
      ] = [wx.NewId() for _init_ctrls in range(3)]

      class Frame1(wx.Frame):
          def _init_coll_flexGridSizer1_Items(self, parent):
              # generated method, don't edit

              parent.AddWindow(self.staticText1, 0, border=10,
                    flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)

          def _init_coll_flexGridSizer1_Growables(self, parent):
              # generated method, don't edit

              parent.AddGrowableRow(0)
              parent.AddGrowableCol(0)

          def _init_sizers(self):
              # generated method, don't edit
              self.flexGridSizer1 = wx.FlexGridSizer(cols=0, hgap=0, rows=1, vgap=0)

              self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
              self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)

              self.panel1.SetSizer(self.flexGridSizer1)

          def _init_ctrls(self, prnt):
              # generated method, don't edit
              wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
                    pos=wx.Point(600, 304), size=wx.Size(400, 250),
                    style=wx.DEFAULT_FRAME_STYLE,
                    title=u'The main screen of the app')
              self.SetClientSize(wx.Size(384, 214))
              self.Bind(wx.EVT_CLOSE, self.OnFrame1Close)

              self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
                    pos=wx.Point(0, 0), size=wx.Size(384, 214),
                    style=wx.TAB_TRAVERSAL)

              self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
                    label=u'this would be the main screen', name='staticText1',
                    parent=self.panel1, pos=wx.Point(121, 100), size=wx.Size(142, 13),
                    style=0)

              self._init_sizers()

          def __init__(self, parent):
              self._init_ctrls(parent)

          def OnFrame1Close(self, event):
              dlg = wx.MessageDialog(self, 'Already finished playing?', 'Are you sure', wx.YES_NO | wx.ICON_QUESTION)
              try:
                  result = dlg.ShowModal()
                  if result == wx.ID_NO:
                      event.Veto()
                      return
                  else:
                      event.Skip()
              finally:
                  dlg.Destroy()

      if __name__ == '__main__':
          app = wx.PySimpleApp()
          frame = create(None)
          frame.Show()

          app.MainLoop()

       
    • Should have know better then to paste code into the message.

      Sourceforge doesn't handle the indentation, so the code needs manual edit to make it run.

      Werner

       
    • steve smith
      steve smith
      2009-03-02

      So in short, boa is not able to replicate normal python coding in its simplist form ?

      This is a pity as i dont really want to use VB but it does work and its simple....it just isnt any good at cross platform.

      Cheers anyhow,
      steve.

       
      • Steve,

        """So in short, boa is not able to replicate normal python coding in its simplist form ? """

        If you need and/or want to write mostly Python code which uses raw_input then Boa is probably not the right editor/ide for you.  Although I am not sure which editor lets you run this kind of code directly, I just checked UliPad which I use for some things and it has the same issue.

        I guess you would just need to have a command window open and run that kind of code outside the IDE/Editor or find one which reads the stdin.

        Werner

         
      • Chelonian
        Chelonian
        2009-03-04

        > So in short, boa is not able to replicate normal python coding in its simplist form ?

        Steve, 

        As Werner said, I don´t think this is the right way to look at it.  First, if you write a simple Python program using the Boa editor and then run it in an interactive shell environment--including the one that comes with Boa (so you could use the Boa shell or IDLE or others)--it will work as you want.  In this use, the editor is just an editor, not unlike Editra or Ulipad or whatever.  In this regard, Boa does what you want, as does all other decent code editors.

        For most applications, though, using raw input is not how users interact with their programs--they use a GUI.  One of Boa´s (many) strengths is the visual GUI builder.

        So, to answer your question above:  Boa IS able to replicate normal python coding in its simplest form, and a lot more, too.