CreateDialog - StatusBar - XML

Für allgemeine Fragen zur Programmierung mit PureBasic.
Benutzeravatar
alen
Beiträge: 107
Registriert: 09.04.2007 17:38
Computerausstattung: Main Hardware: AMD Ryzen 5 1600 - 6 Core / Gigabyte B450 Aorus Pro / Sapphire RX580 8GB
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64 on various Hardware Platforms
Wohnort: Duisburg
Kontaktdaten:

CreateDialog - StatusBar - XML

Beitrag 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
---
Main Hardware: AMD Ryzen 5 1600 - 6 Core / Asus B350M-A / Nvidia GTX650
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64
on various Hardware Platforms (Notebook and Desktop)
Benutzeravatar
Kiffi
Beiträge: 10719
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: CreateDialog - StatusBar - XML

Beitrag 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
a²+b²=mc²
Benutzeravatar
alen
Beiträge: 107
Registriert: 09.04.2007 17:38
Computerausstattung: Main Hardware: AMD Ryzen 5 1600 - 6 Core / Gigabyte B450 Aorus Pro / Sapphire RX580 8GB
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64 on various Hardware Platforms
Wohnort: Duisburg
Kontaktdaten:

Re: CreateDialog - StatusBar - XML

Beitrag 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
---
Main Hardware: AMD Ryzen 5 1600 - 6 Core / Asus B350M-A / Nvidia GTX650
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64
on various Hardware Platforms (Notebook and Desktop)
Andesdaf
Moderator
Beiträge: 2673
Registriert: 15.06.2008 18:22
Wohnort: Dresden

Re: CreateDialog - StatusBar - XML

Beitrag 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.
Win11 x64 | PB 6.20
Benutzeravatar
edel
Beiträge: 3667
Registriert: 28.07.2005 12:39
Computerausstattung: GameBoy
Kontaktdaten:

Re: CreateDialog - StatusBar - XML

Beitrag 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()
Benutzeravatar
alen
Beiträge: 107
Registriert: 09.04.2007 17:38
Computerausstattung: Main Hardware: AMD Ryzen 5 1600 - 6 Core / Gigabyte B450 Aorus Pro / Sapphire RX580 8GB
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64 on various Hardware Platforms
Wohnort: Duisburg
Kontaktdaten:

Re: CreateDialog - StatusBar - XML

Beitrag 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
---
Main Hardware: AMD Ryzen 5 1600 - 6 Core / Asus B350M-A / Nvidia GTX650
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64
on various Hardware Platforms (Notebook and Desktop)
Antworten