Seite 1 von 1

Eingabedialog

Verfasst: 02.03.2021 09:37
von Pelagio
Guten Morgen,
nach längerer Zeit und da ich gerade diese auch habe, wollte ich mich mit dem XML Dialog beschäftigen.
Seit mehreren Tagen versuche ich dabei ein Dialog, in dem drei untereinander stehende StringGadget mit voranstehenden Informationen (TextGadget), zu bauen.
Irgendwie klappt das nicht so wie ich es will, alle Gadget bleiben in einer Zeile.

Code: Alles auswählen

Procedure.s mEingabe (vE1.s=#Null$, vE2.s=#Null$, vE3.s=#Null$, vWinID.i = #Null)
	Protected n.i, pQuit.a, pXMLData.s, pReturn.s, pEvent.i
	Protected pXmlID.i    = Random (99,1)
	Protected pWinFlag.s  = "#PB_Window_ScreenCentered"
	Protected pWindowID.i = pXmlID + 1
	Protected pDialogID.i = pXmlID + 2
	Protected pStr1ID.i   = pXmlID + 3
	Protected pStr2ID.i   = pXmlID + 4
	Protected pStr3ID.i   = pXmlID + 5

	If vWinID: pWinFlag = "#PB_Window_WindowCentered": EndIf
	pXMLData =	"<window id='" + pWindowID + "' name='Eingabe'" +
					" text='Eingabedaten'" + 
					" minwidth='240'  maxwidth='240'"  +
					" minheight='150' maxheight='150'" +
					" flags='" + pWinFlag + "'>" +
					"    <vbox height='30' expand='item:3'>" +
					"       <hbox width='100' expand='item:2'>" +
					"           <text text='Eingabe 1:'/>" +
					"           <string id='" + pStr1ID + "'/>" +
					"           <text text='Eingabe 2:'/>" +
					"           <string id='" + pStr2ID + "'/>" +
					"           <text text='eingabe 3:'/>" +
					"           <string id='" + pStr3ID + "'/>" +
					"       </hbox>" +
					"    </vbox>" +
					"</window>"
	If ParseXML(pXmlID, pXMLData) And XMLStatus(pXmlID) = #PB_XML_Success
		If  CreateDialog(pDialogID) And OpenXMLDialog(pDIALOGID, pXmlID, "Eingabe")
			For n=pstr1ID To pstr3ID
				SetGadgetFont(n, FontID(LoadFont(#PB_Any, "Courier new", 12)))
			Next n
			AddKeyboardShortcut(pWindowID, #PB_Shortcut_Return, #True)
			AddKeyboardShortcut(pWindowID, #PB_Shortcut_Escape, #False)
			SetActiveGadget(pStr1ID)
			StickyWindow (pWindowID, #True)
			Repeat
				pEvent = WaitWindowEvent()
				Select pEvent
					Case #PB_Event_CloseWindow: pQuit = #True
					Case #PB_Event_Menu
						If EventMenu()
							; noch zu entwickeln
						EndIf
						pQuit = #True
				EndSelect
			Until pQuit 
			CloseWindow(pWindowID)
		Else  
			Debug "Dialog error: " + DialogError(pDialogID)
		EndIf
	Else
		Debug "XML error: " + XMLError(pXmlID) + " (Line: " + XMLErrorLine(pXmlID) + ")"
	EndIf
	ProcedureReturn pReturn
EndProcedure

mEingabe()
Ich komme einfach nicht dahinter wo mein gedanklicher Fehler liegt. :praise:

Re: Eingabedialog

Verfasst: 02.03.2021 10:16
von Lord
Versuch's mal so:

Code: Alles auswählen

Procedure.s mEingabe (vE1.s=#Null$, vE2.s=#Null$, vE3.s=#Null$, vWinID.i = #Null)
   Protected n.i, pQuit.a, pXMLData.s, pReturn.s, pEvent.i
   Protected pXmlID.i    = Random (99,1)
   Protected pWinFlag.s  = "#PB_Window_ScreenCentered"
   Protected pWindowID.i = pXmlID + 1
   Protected pDialogID.i = pXmlID + 2
   Protected pStr1ID.i   = pXmlID + 3
   Protected pStr2ID.i   = pXmlID + 4
   Protected pStr3ID.i   = pXmlID + 5

   If vWinID: pWinFlag = "#PB_Window_WindowCentered": EndIf
   pXMLData =   "<window id='" + pWindowID + "' name='Eingabe'" +
               " text='Eingabedaten'" +
               " minwidth='240'  maxwidth='240'"  +
               " minheight='150' maxheight='150'" +
               " flags='" + pWinFlag + "'>" +
               "    <vbox height='30' expand='item:3'>" +
               "       <hbox width='100' expand='item:2'>" +
               "           <text text='Eingabe 1:'/>" +
               "           <string id='" + pStr1ID + "'/>" +
               "       </hbox>" +
               "       <hbox width='100' expand='item:2'>" +
               "           <text text='Eingabe 2:'/>" +
               "           <string id='" + pStr2ID + "'/>" +
               "       </hbox>" +
               "       <hbox width='100' expand='item:2'>" +
               "           <text text='eingabe 3:'/>" +
               "           <string id='" + pStr3ID + "'/>" +
               "       </hbox>" +
               "    </vbox>" +
               "</window>"
   If ParseXML(pXmlID, pXMLData) And XMLStatus(pXmlID) = #PB_XML_Success
      If  CreateDialog(pDialogID) And OpenXMLDialog(pDIALOGID, pXmlID, "Eingabe")
         For n=pstr1ID To pstr3ID
            SetGadgetFont(n, FontID(LoadFont(#PB_Any, "Courier new", 12)))
         Next n
         AddKeyboardShortcut(pWindowID, #PB_Shortcut_Return, #True)
         AddKeyboardShortcut(pWindowID, #PB_Shortcut_Escape, #False)
         SetActiveGadget(pStr1ID)
         StickyWindow (pWindowID, #True)
         Repeat
            pEvent = WaitWindowEvent()
            Select pEvent
               Case #PB_Event_CloseWindow: pQuit = #True
               Case #PB_Event_Menu
                  If EventMenu()
                     ; noch zu entwickeln
                  EndIf
                  pQuit = #True
            EndSelect
         Until pQuit
         CloseWindow(pWindowID)
      Else 
         Debug "Dialog error: " + DialogError(pDialogID)
      EndIf
   Else
      Debug "XML error: " + XMLError(pXmlID) + " (Line: " + XMLErrorLine(pXmlID) + ")"
   EndIf
   ProcedureReturn pReturn
EndProcedure

mEingabe()

Re: Eingabedialog

Verfasst: 02.03.2021 10:32
von Kiffi
alternativ zu Lords Lösung kannst Du auch eine gridbox verwenden:

Code: Alles auswählen

   pXMLData =  "<window id='" + pWindowID + "' name='Eingabe'" +
               " text='Eingabedaten'" +
               " minwidth='240'  maxwidth='240'"  +
               " minheight='150' maxheight='150'" +
               " flags='" + pWinFlag + "'>" +
               "    <gridbox colexpand='item:2'>" +
               "      <text text='Eingabe 1:'/>" +
               "      <string id='" + pStr1ID + "'/>" +
               "      <text text='Eingabe 2:'/>" +
               "      <string id='" + pStr2ID + "'/>" +
               "      <text text='eingabe 3:'/>" +
               "      <string id='" + pStr3ID + "'/>" +
               "    </gridbox>" +
               "</window>"

Re: Eingabedialog

Verfasst: 02.03.2021 13:26
von Pelagio
Ich danke Euch beiden herzlichst für die Antworten.
Ich habe jetzt das Beispiel von Kiffi als Vorgabe genommen da es etwas kompakter ist aber auch das Beispiel von Lord werde ich genausten studieren um darüber auch andere Aufgaben erstellen zu können.
Danke :bounce:

Re: Eingabedialog

Verfasst: 02.03.2021 13:45
von HeX0R
zum Spielen und Lernen empfiehlt sich der DialogDesign0R.
Da kannst Du basteln und siehst immer gleich, wie sich das auswirkt.

Re: Eingabedialog

Verfasst: 03.03.2021 12:54
von Pelagio
Danke HeX0R,

mit dem DialogDesignOR kann man eine menge lernen und ich habe auch schon das eine oder andere besser begriffen.
Allerdings konnte ich nicht erkennen wie ich zum Beispiel in einem TextGadget Daten übergeben kann die ein LineFeed haben
zum Beisiel:

Code: Alles auswählen

Test$ = "Dies" + #LF$ + "ist" + #LF$ + "ein" + #LF$ + "Test"
If OpenWindow(0, 0, 0, 170, 100, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget(0, 10,  10, 150, 80, Test$)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
#LF$ wird in diesem Zusammenhang nicht erkannt, auch mit [~]\n hat es nicht geklappt.

Re: Eingabedialog

Verfasst: 03.03.2021 18:14
von HeX0R
Im DialogDesign0R meinst Du jetzt?
eins\nzwei\ndrei

Das wird dann zu

Code: Alles auswählen

<dialogs>
  <window name='window_1' flags=''>
    <text name='text_1' text='eins&#13;&#10;zwei&#13;&#10;drei'/>
  </window>
</dialogs>
Wobei &#10; eigentlich ausreichen sollte.

Re: Eingabedialog

Verfasst: 03.03.2021 18:50
von Pelagio
:praise: HeX0R

ich habe im DialogDesign0R leider nicht '\n' ausprobiert, einfach nicht daran gedacht, ansonsten hätte ich die SourceSequence '&#13;&#10;' sicherlich schon in meinem Versuchsbeispiel eingebaut.
Jedenfalls hat die Sourcesequence in meinem Versuchsbeispiel zu den von mir gewünschten Erfolg geführt.
Danke :bounce: