Seite 1 von 1

CreateDialog - StatusBar - XML

Verfasst: 04.01.2016 13:04
von alen
Hallo Zusammen,

ich wünsche ein frohes und erfolgreiches neues Jahr allen hier im Forum.

Aktuell spiele ich mit der neuen Funktion "CreateDialog" unter Linux.
Soweit funktioniert das auch.

Jedoch vermisse ich bei den XML Deklarationen in der Doku, die Möglichkeit, eine StatusBar zu definieren.
Habe ich hier was übersehen oder ist das noch nicht implementiert ?
Wie kann ich dem ganzen eine StatusBar spendieren ?

Der Eintrag "<statusbar id='statusbar'/>" im XML Code wird nicht angemeckert aber es passert auch nichts.
Statusbar bleibt unsichtbar.

Für Hinweise oder einen leichten Schlag auf den Hinterkopf wäre ich sehr dankbar.

Grüße
Alen

Aktueller Code:

Code: Alles auswählen

EnableExplicit

CompilerIf #PB_Compiler_Unicode
    #XmlEncoding = #PB_UTF8
CompilerElse 
    #XmlEncoding = #PB_Ascii
CompilerEndIf

#Dialog = 0
#Xml = 0

Define.s XML
Define.l Event

Runtime Enumeration Gadget
    #output
    #statusbar
EndEnumeration


Procedure RunMe(cmd.s, parms.s, workdir.s = "")
    Define.l flags, pid
    Define.s cmd, params
    
    flags = #PB_Program_Open | #PB_Program_Read | #PB_Program_Connect
    flags = flags | #PB_Program_Error | #PB_Program_UTF8
    
    pid = RunProgram(cmd, parms, workdir, flags)
    
    If pid
        While ProgramRunning(pid)
            If AvailableProgramOutput(pid)
                AddGadgetItem(#output, -1, ReadProgramString(pid))
            EndIf
        Wend
        
        If ProgramExitCode(pid) <> 0
            AddGadgetItem(#output, -1, "")
            AddGadgetItem(#output, -1, "Exitcode: " + Str(ProgramExitCode(pid)))
        EndIf
        
        AddGadgetItem(#output, -1, "")
        
        CloseProgram(pid)
    EndIf
    
EndProcedure

  
Runtime Procedure RunAction(line.s) 
    ;RunMe("hostname", "-f")
    ;RunMe("uname", "-a")
    ;RunMe("uptime", "")
    RunMe("du", "-hs " + GetHomeDirectory())
    RunMe("tree", "-d --du --si -s " + GetHomeDirectory())
EndProcedure

Runtime Procedure ClearOutput() 
  SetGadgetText(#output, "")
EndProcedure


XML.s = "<window id='#PB_Any' name='test' text='RunCommand Test' minwidth='800' minheight='600' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
        "      <vbox expand='item:2'>" +
        "        <hbox>" +
        "          <button text='Run Command' onevent='RunAction()'/>" +
        "          <button text='Clear Output' onevent='ClearOutput()'/>" +
        "        </hbox>" +
        "        <editor id='output' text='' height='150'/>" +
        "      </vbox>" +
        "      <statusbar id='statusbar'/>" +
     "</window>"

If CatchXML(#Xml, @XML, StringByteLength(XML), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
    If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")        
        
      Repeat
        Event = WaitWindowEvent()
      Until Event = #PB_Event_CloseWindow 
      
    Else  
      SetGadgetText(#output, "Dialog error: " + DialogError(#Dialog))
    EndIf
Else
    SetGadgetText(#output, "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")")
EndIf

Re: CreateDialog - StatusBar - XML

Verfasst: 04.01.2016 13:26
von Kiffi
sieht schlecht aus. Unter Windows erscheint auch keine Statusbar. Und in der Hilfe ist sie unter "Supported gadgets" nicht aufgelistet. Ich schätze mal, dass sie schlicht und einfach nicht unterstützt wird.

Vielleicht reicht es Dir, wenn Du eine Statusbar simulierst, indem Du ein disabletes StringGadget verwendest:

Code: Alles auswählen

EnableExplicit

CompilerIf #PB_Compiler_Unicode
  #XmlEncoding = #PB_UTF8
CompilerElse 
  #XmlEncoding = #PB_Ascii
CompilerEndIf

#Dialog = 0
#Xml = 0

Define.s XML
Define.l Event

Runtime Enumeration Gadget
  #output
  #statusbar
EndEnumeration


Procedure RunMe(cmd.s, parms.s, workdir.s = "")
  Define.l flags, pid
  Define.s cmd, params
  
  flags = #PB_Program_Open | #PB_Program_Read | #PB_Program_Connect
  flags = flags | #PB_Program_Error | #PB_Program_UTF8
  
  pid = RunProgram(cmd, parms, workdir, flags)
  
  If pid
    While ProgramRunning(pid)
      If AvailableProgramOutput(pid)
        AddGadgetItem(#output, -1, ReadProgramString(pid))
      EndIf
    Wend
    
    If ProgramExitCode(pid) <> 0
      AddGadgetItem(#output, -1, "")
      AddGadgetItem(#output, -1, "Exitcode: " + Str(ProgramExitCode(pid)))
    EndIf
    
    AddGadgetItem(#output, -1, "")
    
    CloseProgram(pid)
  EndIf
  
EndProcedure


Runtime Procedure RunAction(line.s) 
  ;RunMe("hostname", "-f")
  ;RunMe("uname", "-a")
  ;RunMe("uptime", "")
  RunMe("du", "-hs " + GetHomeDirectory())
  RunMe("tree", "-d --du --si -s " + GetHomeDirectory())
EndProcedure

Runtime Procedure ClearOutput() 
  SetGadgetText(#output, "")
EndProcedure

XML.s = "<window id='#PB_Any' name='test' text='RunCommand Test' minwidth='800' minheight='600' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
        "  <vbox expand='item:2'>" +
        "    <hbox>" +
        "      <button text='Run Command' onevent='RunAction()'/>" +
        "      <button text='Clear Output' onevent='ClearOutput()'/>" +
        "    </hbox>" +
        "    <editor id='output' text='' height='150'/>" +
        "    <string id='#statusbar' /> " +
        "  </vbox>" +
        "</window>"

If CatchXML(#Xml, @XML, StringByteLength(XML), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")        
    
    DisableGadget(#statusbar, #True)
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow 
    
  Else  
    SetGadgetText(#output, "Dialog error: " + DialogError(#Dialog))
  EndIf
Else
  SetGadgetText(#output, "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")")
EndIf
Grüße ... Peter

Re: CreateDialog - StatusBar - XML

Verfasst: 04.01.2016 16:28
von alen
Hallo Kiffi,

danke für den Workaround. Dann werde ich Deinen Vorschlag mal antesten.

Blöd, ist dann aber erstmal so. :D

Grüße
Alen

Re: CreateDialog - StatusBar - XML

Verfasst: 04.01.2016 21:59
von Andesdaf
eine Statusbar lässt sich genau wie ein Menü aber auch noch nachträglich per CreateStatusBar() in
ein mit CreateXMLDialog() erstelltes Fenster einfügen.

Re: CreateDialog - StatusBar - XML

Verfasst: 05.01.2016 10:44
von edel
Ich finde es auch schade, dass einige Dinge nicht unterstuetzt werden. Aber man kann es leicht "nachruesten"

Code: Alles auswählen

;######################################################################
Procedure StatusbarDialog(node.i, statusbarid =-1, Window = -1)  
  Protected Index.i
  Protected ItemText.s
  Protected ItemWidth.i
  
  ; tags durchlaufen
  While node And statusbarid = -1
    
    If LCase(GetXMLNodeName(node)) = "statusbar"
      ; statusbar gefunden
      StatusbarDialog(ChildXMLNode(node), Val(GetXMLAttribute(node, "id")), window)
    EndIf
    
    ; Childnode durchlaufen
    If ChildXMLNode(node)
      StatusbarDialog(ChildXMLNode(node), -1, Window)
    EndIf       
    
    node = NextXMLNode(node)
  Wend
  
  If statusbarid > -1
    
    CreateStatusBar(statusbarid, WindowID(window))
    
    ; childnodes durchlaufen
    While node
      
      ; statusbar feld gefunden und einfuegen
      If LCase(GetXMLNodeName(node)) = "field"
        
        ; breite auslesen
        ItemWidth = Val(GetXMLAttribute(node, "width"))
        ; Text auslesen
        ItemText  = GetXMLNodeText(node)      
        
        ; Feld einfügen
        AddStatusBarField(ItemWidth)
        ; Text einfügen
        StatusBarText(statusbarid, index, ItemText)
        
        Index + 1
      EndIf      
      
      node = NextXMLNode(node)
    Wend
    
  EndIf  
  
EndProcedure

;######################################################################
Procedure OpenXMLDialog2(Dialog, xml, Name.s, x, y, w, h, parent)
    
  Protected result
  
  result = OpenXMLDialog(Dialog, xml, Name.s, x, y, w, h, parent)  
  
  If result
    StatusbarDialog(MainXMLNode(xml), -1, DialogWindow(Dialog))
  EndIf  
  
  ProcedureReturn result
EndProcedure

;######################################################################
Macro OpenXMLDialog(Dialog, xml, Name, x=0, y=0, w=0, h=0, parent=0)
  OpenXMLDialog2(Dialog, xml, Name, x, y, w, h, parent)
EndMacro

;######################################################################
Procedure Main()
  
  Protected dialog 
  Protected xml 
  Protected xmlstring.s
  
  xmlstring = "<window id='#PB_Any' width='300' height='300' name='test' text='test' flags='#PB_Window_SizeGadget| #PB_Window_ScreenCentered | #PB_Window_SystemMenu'>" + 
              "<statusbar id='0'>"+
              " <field width='150'>Lalala</field>"+
              " <field width='50'/>"+
              " <field width='50'/>"+
              " <field width='50'/>"+              
              "</statusbar>"+
              "</window>"

  
  dialog = CreateDialog(#PB_Any)
  
  If dialog
    
    xml = CatchXML(#PB_Any, @xmlstring, StringByteLength(xmlstring));LoadXML(#PB_Any, "ui.xml")
    
    If xml
      
      If OpenXMLDialog(dialog, xml, "test", #PB_Ignore, #PB_Ignore)
        
        While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend      
        
      EndIf    
      
      FreeXML(xml)      
    EndIf    
    
    FreeDialog(dialog)
  EndIf
  
EndProcedure:End Main()

Re: CreateDialog - StatusBar - XML

Verfasst: 05.01.2016 11:17
von alen
Hallo edel,

das ist auch eine nette Lösung. Gefällt mir.
Wäre halt schöner wenn es ohne Umwege schon eingebaut wäre.

So ist das halt manchmal.

Grüße
Alen