<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<?xul-overlay href="chrome://pyxultest/content/js_overlay.xul"?>
<?xul-overlay href="chrome://pyxultest/content/python_overlay.xul"?>
  
<window
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  id="mainWindow" orient="vertical"
  screenX="100" screenY="100"
  height="450" width="600"
  script-type="application/x-python"
  onload="write('hello from the inline window load event')"
  title="Python in XUL demos and tests"
  >
  <script type="application/x-python" src="chrome://pyxultest/content/pyxultest.py"/>
  <script>
    <![CDATA[

dump("Scrollbar visible = %s", window.scrollbars.visible)
dump("Window location is %s", window.location.href)

#promptService =  xpcom.components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(xpcom.components.interfaces.nsIPromptService)
#promptService.alert(window, "title", "Hello from Python");

    ]]>
  </script>
  <script type="application/javascript">
    // a 'write' function that writes to our window - like the Python one
    // although this version does *not* auto-append a '\n' char.  This keeps
    // 'write' like 'dump', but also serves as a useful test that the wrong
    // language isn't accidently being used.
    function write(msg) {
      tb = document.getElementById("output_box");
      tb.value = tb.value + msg;
    }
  </script>

  <!-- This commandset drags in commands from our overlays, each
       implemented in different languages
  -->
  <commandset id="cmdset">
    <!-- and one define inline -->
    <command id="menu-file-close:command"
             oncommand="print 'Python closing the window';window.close()"/>
  </commandset>

  <!-- this keyset and menu reference commands implemented in multiple
       languages
  -->
  <keyset id="mainkeys">
    <key
       id        =  "menu-file-close:key"
       key       =  "q"
       observes  =  "menu-file-close:command"
       modifiers =  "accel" />
    <key
       id        =  "menu-file-test-js:key"
       key       =  "j"
       observes  =  "menu-file-test-js:command"
       modifiers =  "accel" />
    <key
       id        =  "menu-file-test-python:key"
       key       =  "p"
       observes  =  "menu-file-test-python:command"
       modifiers =  "accel" />
  </keyset>

  <toolbox id="main-toolbox"> 
    <menubar id="menu">
      <menu id="menu-file" label="File" accesskey="f">
        <menupopup id="menu-file-popup">
          <menuitem
             id        =  "menu-file-test-js"
             key       =  "menu-file-test-js:key"
             label     =  "Test JS"
             command   =  "menu-file-test-js:command"
             accesskey = "J"/>
          <menuitem
             id        =  "menu-file-test-python"
             key       =  "menu-file-test-python:key"
             label     =  "Test Python"
             command   =  "menu-file-test-python:command"
             accesskey =  "P"/>
          <menuitem
             id        =  "menu-file-test-inline"
             key       =  "menu-file-test-inline:key"
             label     =  "Test Inline menu handler"
             oncommand =  "write('Hello from an inline menu handler')"
             accesskey =  "I"/>
          <menuitem
             id        =  "menu-file-close"
             key       =  "menu-file-close:key"
             label     =  "Close"
             command   =  "menu-file-close:command"
             accesskey =  "C"/>
        </menupopup>
      </menu>
    </menubar>
  </toolbox>

  <textbox id="output_box" style="width:100%"
           value = "If you can see this, things aren't working well!"
           rows="15" multiline="true" flex="1"
  />
<!--
  <iframe src="chrome://pyxultest/content/html_content.html" height="30"/>
-->
  <groupbox>
    <caption label="Items from Overlays"/>
    <!-- A box from our overlay - it will have one button using js events
         and another using Python events -->
    <hbox>
      <hbox id="language_box"/>
      <button id="but_multi" label="click for both"/>
    </hbox>
  </groupbox>

  <hbox>
    <groupbox>
      <caption label="Random Buttons"/>

      <hbox>
        <!-- Here we have a script element defined at a parent node -->
        <vbox oncommand="write('You clicked on a %s with id=%s and type=%s' % (event.target.tagName, event.target.id, event.target.type))">
          <hbox>
            <button id="some-button" label = "click here"/>
            <button id="another-button" label = "or here"/>
            <!-- a button that overrides script-type and oncommand in a different language -->
            <button id="js-button" label = "JS"
                    script-type="application/javascript" 
                    oncommand="write('This is a JS button with ID ' + event.target.id + '\n');"
            />
          </hbox>
          <button type="checkbox" autocheck="1" id="some-checkbox" label="Click on this checkbox too"/>
        </vbox>
        <button id="but_dialog" label="open dialog"
                oncommand="on_but_dialog_click()"/>
      </hbox>
    </groupbox>
    <groupbox flex="1">
      <caption label="Key Event Tests"/>
      <textbox id="input_test_intrinsic" value="Type something and press Enter"
               onkeypress="return do_textbox_keypress(event)"/>
    </groupbox>
  </hbox>

  <groupbox>
    <caption label="Automated tests"/>
    <hbox>
      <button id="test_error" label="Run tests" oncommand="run_tests()"/>
      <vbox flex="1">
        <text class="label"
              value="The test window is not shown (or closes quickly) if the tests work"/>
        <checkbox id="keep_tests_open" label="Always keep test window open"/>
      </vbox>
      <image id="image-python" src="http://www.python.org/pics/PyBanner011.gif"
             width="150" height="35" flex="0"
             onclick="change_image()"/>
    </hbox>

  </groupbox>
</window>

