Jump to content

Help needer for StdoutRead to ListView


rakibdepu
 Share

Go to solution Solved by rakibdepu,

Recommended Posts

Hi All,

I need help. I have been searching help files and browsing forums about this for the past 7 days. It's either I don't understand, or it's going over my head.

I am trying to create gui for ADB & Scrcpy.

I have pretty much everything under control, but I'm stuck on the StdoutRead to ListView part.

See the attached link for what I want with ListView.

https://github.com/gxj8885718/ScrcpyGui_New/raw/master/Preview.gif

Here is my Scrcpy Helper Gui.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#Include <GuiComboBox.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <GUIListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $ini = "settings.ini"

ReadSettings()

Func ReadSettings()
    Global $AlwaysOnTopV = IniRead($ini, "Main", "AlwaysOnTop", 1)
    Global $FullScreenV = IniRead($ini, "Main", "FullScreen", 0)
    Global $HideBorderV = IniRead($ini, "Main", "HideBorder", 1)
    Global $LastDevicesV = IniRead($ini, "Main", "LastDevices", "?")
    Global $LastWiFiAddressV = IniRead($ini, "Main", "LastWiFiAddress", "?")
    Global $NoPowerOnV = IniRead($ini, "Main", "NoPowerOn", 0)
    Global $NoScreenSaverV = IniRead($ini, "Main", "NoScreenSaver", 1)
    Global $PowerOffOnCloseV = IniRead($ini, "Main", "PowerOffOnClose", 1)
    Global $ReadOnlyModeV = IniRead($ini, "Main", "ReadOnlyMode", 0)
    Global $SerialV = IniRead($ini, "Main", "Serial", "?")
    Global $ShowTouchV = IniRead($ini, "Main", "ShowTouch", 0)
    Global $StayAwakeV = IniRead($ini, "Main", "StayAwake", 0)
    Global $TurnOffTheScreenV = IniRead($ini, "Main", "TurnOffTheScreen", 1)
    Global $Parameter = IniRead($ini, "Main", "Parameter", "")
    ADBReboot()
EndFunc   ;==>ReadSettings

#Region ### START Koda GUI section ### Form=hgui.kxf
$MainGUI = GUICreate("Scrcpy Helper", 405, 561, 184, 129)
GUISetOnEvent($GUI_EVENT_CLOSE, "Off")
$MainGroup = GUICtrlCreateGroup("", 10, 6, 380, 525)
$DeviceGroup = GUICtrlCreateGroup("Device", 20, 18, 360, 118, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER))
$DeviceList = GUICtrlCreateListView("Device Connected", 30, 36, 260, 90)
_GUICtrlListView_SetExtendedListViewStyle($DeviceList, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 255)
$ConnectedDevice = GUICtrlCreateListViewItem("", $DeviceList)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($DeviceList), 0, 2)
GUICtrlSetTip(-1, "Double click on serial")
$Refresh = GUICtrlCreateButton("Refresh", 300, 36, 70, 90)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetOnEvent($Refresh, "Refresh")
$ADBGroup = GUICtrlCreateGroup("ADB", 20, 142, 360, 58, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER))
$GoWireless = GUICtrlCreateButton("Go Wireless", 220, 160, 70, 30, $BS_MULTILINE)
GUICtrlSetTip(-1, "Enter IP address")
GUICtrlSetOnEvent($GoWireless, "GoWireless")
$ADBReboot = GUICtrlCreateButton("ADB Reboot", 300, 160, 70, 30, $BS_MULTILINE)
GUICtrlSetOnEvent($ADBReboot, "ADBReboot")
$IPAddress = _GUICtrlIpAddress_Create($MainGUI, 30, 160, 180, 30, -1, 0)
_GUICtrlIpAddress_Set($IPAddress,$LastWiFiAddressV)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;GUICtrlSetData(-1, Local $IPAddressV = $IPAddress, "")
$ScrcpyGroup = GUICtrlCreateGroup("Scrcpy", 20, 206, 360, 49, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER))
$Resolution = GUICtrlCreateCombo("", 300, 224, 70, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Auto|Max")
GUICtrlSetTip(-1, "Resolution")
_GUICtrlComboBox_SelectString($Resolution, IniRead($ini, "Main", "Size", ""))
$FullScreenC = GUICtrlCreateCheckbox("", 30, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Full Screen")
GUICtrlSetState($FullScreenC, $FullScreenV)
$PowerOffOnCloseC = GUICtrlCreateCheckbox("", 60, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Power Off On Close")
GUICtrlSetState($PowerOffOnCloseC, $PowerOffOnCloseV)
$AlwaysOnTopC = GUICtrlCreateCheckbox("", 90, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Always On Top")
GUICtrlSetState($AlwaysOnTopC, $AlwaysOnTopV)
$ReadOnlyModeC = GUICtrlCreateCheckbox("", 120, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Read Only Mode")
GUICtrlSetState($ReadOnlyModeC, $ReadOnlyModeV)
$ShowTouchC = GUICtrlCreateCheckbox("", 150, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Show Touch")
GUICtrlSetState($ShowTouchC, $ShowTouchV)
$NoScreenSaverC = GUICtrlCreateCheckbox("", 180, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "No Screensaver")
GUICtrlSetState($NoScreenSaverC, $NoScreenSaverV)
$TurnOffTheScreenC = GUICtrlCreateCheckbox("", 210, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Turn off the screen")
GUICtrlSetState($TurnOffTheScreenC, $TurnOffTheScreenV)
$StayAwakeC = GUICtrlCreateCheckbox("", 240, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Stay Awake")
GUICtrlSetState($StayAwakeC, $StayAwakeV)
$HideBorderC = GUICtrlCreateCheckbox("", 270, 224, 20, 20, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Hide Border")
GUICtrlSetState($HideBorderC, $HideBorderV)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$TouchGroup = GUICtrlCreateGroup("Touch", 20, 261, 260, 183, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER))
$ShortCutC = GUICtrlCreateRadio("", 120, 279, 20, 20, BitOR($GUI_SS_DEFAULT_RADIO, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Ctrl")
$ShortCutA = GUICtrlCreateRadio("", 160, 279, 20, 20, BitOR($GUI_SS_DEFAULT_RADIO, $BS_PUSHLIKE))
GUICtrlSetTip(-1, "Alt")
$VolumeUP = GUICtrlCreateButton("+", 30, 309, 50, 35)
GUICtrlSetTip(-1, "Volume UP")
$ScreenOn = GUICtrlCreateButton("Screen On", 90, 309, 50, 35, $BS_MULTILINE)
$NotificationOn = GUICtrlCreateButton("Notification On", 160, 309, 50, 35, $BS_MULTILINE)
$Menu = GUICtrlCreateButton("Menu", 220, 309, 50, 35)
GUICtrlSetTip(-1, "Menu")
$VolumeDown = GUICtrlCreateButton("-", 30, 354, 50, 35)
GUICtrlSetTip(-1, "Volume Down")
$ScreenOff = GUICtrlCreateButton("Screen Off", 90, 354, 50, 35, $BS_MULTILINE)
$NotificationOff = GUICtrlCreateButton("Notification Off", 160, 354, 50, 35, $BS_MULTILINE)
$Power = GUICtrlCreateButton("Power", 220, 354, 50, 35)
GUICtrlSetTip(-1, "Power On/Off")
$Back = GUICtrlCreateButton("<", 65, 399, 50, 35)
GUICtrlSetTip(-1, "Back")
$Home = GUICtrlCreateButton("?", 125, 399, 50, 35)
GUICtrlSetTip(-1, "Home")
$Switch = GUICtrlCreateButton("=", 185, 399, 50, 35)
GUICtrlSetTip(-1, "Switch")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$OnOFFGroup = GUICtrlCreateGroup("", 290, 261, 90, 183)
$On = GUICtrlCreateButton("On", 300, 276, 70, 74)
$Off = GUICtrlCreateButton("Off", 300, 360, 70, 74)
GUICtrlSetOnEvent($Off, "Off")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Parameter = GUICtrlCreateEdit("", 20, 446, 360, 75, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN), 0)
GUICtrlSetData(-1, "")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$StatusBar1 = _GUICtrlStatusBar_Create($MainGUI)
_GUICtrlStatusBar_SetBkColor($StatusBar1, 0xD1B499)
_GUICtrlStatusBar_SetMinHeight($StatusBar1, 20)
If IniRead($ini, "Main", "ShortCutCtrl", "0") = 1 Then
    GUICtrlSetState ($ShortCutC,$GUI_CHECKED)
    IniWrite($ini, "Main", "ShortCutCtrl", $ShortCutC)
ElseIf IniRead($ini, "Main", "ShortCutAlt", "0") = 1 Then
    GUICtrlSetState ($ShortCutA,$GUI_CHECKED)
    IniWrite($ini, "Main", "ShortCutCtrl", $ShortCutA)
EndIf
;If IniRead($ini, "Main", "ShortCutCtrl", "0") = 1 Then
;   GUICtrlSetState ($ShortCutC,$GUI_CHECKED)
;   IniWrite($ini, "Main", "ShortCut", $ShortCutC)
;ElseIf IniRead($ini, "Main", "ShortCutAlt", "0") = 1 Then
;   GUICtrlSetState ($ShortCutA,$GUI_CHECKED)
;   IniWrite($ini, "Main", "ShortCut", $ShortCutA)
;EndIf
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Refresh()

While 1
        Sleep(100) ; Sleep to reduce CPU usage
WEnd

;==>Func INICreate()
;==>    IniWrite($ini, "Main", "AlwaysOnTop", "")
;==>    IniWrite($ini, "Main", "FullScreen", "")
;==>    IniWrite($ini, "Main", "HideBorder", "")
;==>    IniWrite($ini, "Main", "LastDevices", "")
;==>    IniWrite($ini, "Main", "LastWiFiAddress", "")
;==>    IniWrite($ini, "Main", "NoPowerOn", "")
;==>    IniWrite($ini, "Main", "NoScreenSaver", "")
;==>    IniWrite($ini, "Main", "PowerOffOnClose", "")
;==>    IniWrite($ini, "Main", "ReadOnlyMode", "")
;==>    IniWrite($ini, "Main", "Serial", "")
;==>    IniWrite($ini, "Main", "ShortCut", "")
;==>    IniWrite($ini, "Main", "ShowTouch", "")
;==>    IniWrite($ini, "Main", "Size", "")
;==>    IniWrite($ini, "Main", "StayAwake", "")
;==>    IniWrite($ini, "Main", "TurnOffTheScreen", "")
;==>EndFunc   ;==>INICreate

Func Refresh()
    ;RunWait(@ComSpec & " /c " & "adb connect 192.168.255.251 & adb connect 192.168.255.252", "", @SW_HIDE)
    $adbdevices = Run("adb devices", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($adbdevices)
    $ADBOut = StringTrimLeft(StdoutRead($adbdevices), 26)
    $ADBOut1 = StringRegExpReplace($ADBOut, "(\s+device+\s)\s*", "|", 0)
    $ADBOutput = StringTrimRight(StringStripCR($ADBOut1), 1)
    GUICtrlSetData($SerialV, $ADBOutput)
    GUICtrlSetData($Parameter, GUICtrlRead($Parameter) & '' & $ADBOutput & @CRLF)
    ;_GUICtrlListView_DeleteAllItems($DeviceList)
    ;_GUICtrlListView_AddArray($DeviceList, $ADBOutput)
    ;IniWriteSection($ini, "Main", "Devices" & "=" & $ADBOutput)
    IniWrite($ini, "Main", "Devices", $ADBOutput)
EndFunc   ;==>Refresh

Func GoWireless()
    If _GUICtrlIpAddress_IsBlank($IPAddress) Then
        MsgBox($MB_SYSTEMMODAL, "", "Enter IP Address.")
        _GUICtrlIpAddress_SetFocus($IPAddress, 0)
    Else
        ;$GoWifi = Run("adb connect " & $IPAddress, "", @SW_HIDE)
        ;ProcessWaitClose($GoWifi)
        RunWait(@ComSpec & " /c " & "adb connect " & $IPAddress, "", @SW_HIDE)
        IniWrite($ini, "Main", "LastWiFiAddress", _GUICtrlIpAddress_Get($IPAddress))
        Refresh()
    EndIf
EndFunc   ;==>GoWireless

Func ADBReboot()
    RunWait(@ComSpec & " /c " & "adb" & " kill-server", "", @SW_HIDE)
    RunWait(@ComSpec & " /c " & "adb" & " start-server", "", @SW_HIDE)
EndFunc   ;==>ADBReboot

Func Off()
        RunWait(@ComSpec & " /c " & "adb" & " kill-server", "", @SW_HIDE)
        Exit
EndFunc   ;==>CLOSEButton

PS: Sorry for my English.

Link to comment
Share on other sites

I am no expert and I cannot test your code, but looking at these lines:

$adbdevices = Run("adb devices", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
 ProcessWaitClose($adbdevices)
 $ADBOut = StringTrimLeft(StdoutRead($adbdevices), 26)

It looks like you run the process, then you wait for it to close, then you try to read it. You cannot read something that is closed.

Also, I played with StdoutRead once before and my experience was I needed to read the output multiple times (in a For loop) to get all of the output. Otherwise, you will only get one line of the output. And there is a possibility that StdoutRead may not be able to read what you are trying to read. 

I hope this helps.

Link to comment
Share on other sites

Sorry, I didn't understand something, the help file says,

; Wait until the process has closed using the PID returned by Run.

 

; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
Link to comment
Share on other sites

18 hours ago, rakibdepu said:

    $adbdevices = Run("adb devices", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)     ProcessWaitClose($adbdevices)     $ADBOut = StringTrimLeft(StdoutRead($adbdevices), 26)

This might work, using a loop or not (test needed)
You should use ConsoleWrite in Scite to first visualize what is returned by the StdoutRead

Link to comment
Share on other sites

I know StdoutRead result.

adb devices result:

Quote

List of devices attached
4200349cce57438b    device
Y3123A0110SM010011780    device
192.168.1.148:5555    device
192.168.255.251:5555    device
192.168.255.252:5555    device

My question was how to redirect StdoutRead result in ListView.

Link to comment
Share on other sites

Sorry, my mistake. I didn't really notice.

Quote

needed to read the output multiple times (in a For loop) to get all of the output. Otherwise, you will only get one line of the output.

I tried, but StdoutRead result first line "List of devices attached" give me error. Then add StringTrimLeft, but no result.

Link to comment
Share on other sites

  • Solution

Finally . . .

Func Refresh()
    IniDelete ( $ini, "Devices" )
    Local $iPID = Run(@ComSpec & " /c adb devices", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($iPID)
    $adbdevices = StdoutRead($iPID)
    $ADBOutput = StringReplace(StringStripWS(StringTrimLeft($adbdevices, 26), $STR_STRIPTRAILING), @CR, " =")
    If $ADBOutput = "" Then
        IniWriteSection($ini, "Devices", $WiFiAddressV & "  device =")
    Else
        IniWriteSection($ini, "Devices", $ADBOutput & " =")
    EndIf
    _GUICtrlListView_DeleteAllItems($DeviceList)
    DeviceRefresh()
EndFunc   ;==>Refresh

Func DeviceRefresh()
    $aList = IniReadSection($ini, "Devices")
    _GUICtrlListView_BeginUpdate($DeviceList)
    For $i = 1 To $aList[0][0]
        _GUICtrlListView_AddItem($DeviceList, $i)
        $aStr = StringSplit($aList[$i][0], "    ", 1)
        _GUICtrlListView_AddSubItem($DeviceList, $i-1, $aStr[1], 1)
        _GUICtrlListView_AddSubItem($DeviceList, $i-1, $aStr[2], 2)
    Next
    _GUICtrlListView_EndUpdate($DeviceList)
    Param()
EndFunc

Thank you Zedna

Help got from your post ListView save/load checked scenarios - need an idea

I will publish when complete.

RHD

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...