Showing posts with label go. Show all posts
Showing posts with label go. Show all posts

Wednesday, November 11, 2020

Kenapa ngerubah nilai golang ( gui ) itu lama?

dapet chat dari C# junior developer.
"Bang, kenapa cuma nambahin fungsi Limiter(INTEGER) kenapa 2 jam sih?"

Okay sebagai programmer c#, aku tahu kok ngasih limiter itu tinggal drag and drop numericupdown lalu bind dengan app data (automatic ), and youre done ( 5 menit paling lama)

Oke, tak breakdown satu persatu di golang.

Konsepnya adalah CLIENT ngerubah nilai limiter ( di program ), dan otomatis ke save dan berubah tiap program di eksekusi.

Di golang.
GUI:
di golang kamu bikin dulu gui nya, aku gunain lxn/walk, tentuin ukurannya columnspan, lalu build and test ( berkali2), karena nggak ada VISUAL DESIGNER di golang ( kecuali pake qt, tapi karena itu harus compiling sendiri dsbnya. RIBET (baca males)).

done dengan urusan GUI.

 

STRUCT
=================
create struct untuk nyimpan baca dan simpen valuenya

type DelayApp struct {
    DelayMsg    int `json:"delayMsg"`
    DelayPerRun int `json:"delayPerRun"`
    DelaySmart  int `json:"delaySmart"`
}

 

lalu create function

READ delay
=================


func readDelayApp() DelayApp {
    var delayapp DelayApp
    filename := "delayapp.json"

    //filename is the path to the json config file
    file, _ := os.Open(filename)
    byteValue, _ := ioutil.ReadAll(file)
    defer file.Close()

    //fmt.Println(byteValue)
    //var result map[string]interface{}
    json.Unmarshal([]byte(byteValue), &delayapp)

    //fmt.Println(delayapp.delayMsg)
    return delayapp
}

lalu bikin fungsi menyimpan data ( jika user mau mengubah nilai dari limiter)

func writeDelayApp(delayMsg, delayPerRun, delaySmart float64) {

    appDelay := DelayApp{
        DelayMsg:    int(delayMsg),
        DelayPerRun: int(delayPerRun),
        DelaySmart:  int(delaySmart),
    }
    file, _ := json.MarshalIndent(appDelay, "", " ")
    _ = ioutil.WriteFile("delayapp.json", file, 0644)
}

udah selesai? no no

create global variable yang bisa di baca di seluruh fungsi
=========================

var delayMsg *walk.NumberEdit
var delayPerRun *walk.NumberEdit
var delaySmart *walk.NumberEdit


Then buat fungsi untuk load datanya pas user membuka gui nya
==========================
func LoadDataFirstId() {
    cookiesString := models.ReadCookies("cookies.txt")
    dataCookieSafe := models.ParsingJsonfyJs(cookiesString)
    models.GetUserIdFromCookiesJson(dataCookieSafe)

    delaydefault := readDelayApp()
    //fmt.Println(delaydefault)

    boxProfile.SetEnabled(true)
    boxStarting.SetEnabled(true)
    timeOption.SetEnabled(true)


    delayMsg.SetValue(float64(delaydefault.DelayMsg))
    delayPerRun.SetValue(float64(delaydefault.DelayPerRun))
    delaySmart.SetValue(float64(delaydefault.DelaySmart))

    fbuserIDLineEdit.SetText(models.Fbuser_id)


}
oke sekarang gabungin seluruh fungsi ke button click ( gui nya)
===========================
OnClicked: func() {
    go func() {
    writeDelayApp(delayMsg.Value(), delayPerRun.Value(), delaySmart.Value())
    dlg.Accept()
    }()

},


oke DONE.

padahal cuma ngerubah ini lho:

Changing this



NOTE:
Ini ngomong hasilnya, pass ngodingnya error bisa beratus2 kali ( sambil berkata kasar, emosi dan stress)

Saturday, April 18, 2020

GoDataGoodReads, data scraper GoodReads

GoDataGoodReads, is more complete than https://tulisanlain.blogspot.com/2020/02/scraper-goodreads-ebook-scraper.html

but its will take longer time cause its will scraping more complete data.

The Result is : ID, Title, Cover Image, Author , JumlahPage, Publisher, ISBN, Language, Description.


And I will enforcing delay cause its public community.

Join our Groups


ScreenSHOT


And shout for Kang Hasan for his donation.

https://www.mediafire.com/file/tochz59f85ibqfm/GoDataGoodReads_v1.4.zip/file

Thursday, March 26, 2020

Icon in Application Golang, using rsrc & lxn/walk

 


 

Taken from https://stackoverflow.com/questions/25602600/how-do-you-set-the-application-icon-in-golang as my note



You can use a tool like akavel/rsrc in order to generate a .syso file with specified resources embedded in .rsrc section, aimed for consumption by Go linker when building Win32 excecutables.

See as an example the lxn/walk application, which embeds other metadata in its executable.

rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
-ico="":

comma-separated list of paths to .ico files to embed


For more detail in GOLANG APPS from https://github.com/lxn/walk/issues/361#issuecomment-468228063



his only sets the Icon for the console window but not for the Walk GUI window.
To have those also use that same Icon use:

var appIcon, _ = walk.NewIconFromResourceId(3) // number 3 is resource ID printed by RSRC.exe while making accounting.syso

and then add this to each MainWindow or Dialog:

 Icon:     appIcon,

The build would look something like this example (after which the icon also works from in the Visual Studio Code IDE)

cd C:\Build\accounting
C:\Build\Go_tools\rsrc.exe -manifest accounting.manifest -ico accounting.ico -o accounting.syso
go build -ldflags -H=windowsgui

Tuesday, March 24, 2020

Golang UI template NOTE

 


 

Golang UI template note.


I use golang framework lxn/walk 

Walk currently requires Go 1.11.x or later.

DEFAULT


test.go

package main

import (
 "github.com/lxn/walk"
 . "github.com/lxn/walk/declarative"
 "strings"
)

func main() {
 var inTE, outTE *walk.TextEdit

 MainWindow{
  Title:   "SCREAMO",
  MinSize: Size{600, 400},
  Layout:  VBox{},
  Children: []Widget{
   HSplitter{
    Children: []Widget{
     TextEdit{AssignTo: &inTE},
     TextEdit{AssignTo: &outTE, ReadOnly: true},
    },
   },
   PushButton{
    Text: "SCREAM",
    OnClicked: func() {
     outTE.SetText(strings.ToUpper(inTE.Text()))
    },
   },
  },
 }.Run()
}
Create Manifest test.manifest 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestversion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyidentity name="SomeFunkyNameHere" processorarchitecture="*" type="win32" version="1.0.0.0">
    <dependency>
        <dependentassembly>
            <assemblyidentity language="*" name="Microsoft.Windows.Common-Controls" processorarchitecture="*" publickeytoken="6595b64144ccf1df" type="win32" version="6.0.0.0">
        </assemblyidentity></dependentassembly>
    </dependency>
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowssettings>
            <dpiawareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiawareness>
            <dpiaware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiaware>
        </windowssettings>
    </application>
</assemblyidentity></assembly>
Then either compile the manifest using the rsrc tool, like this:
go get github.com/akavel/rsrc
rsrc -manifest test.manifest -o rsrc.syso
or rename the test.manifest file to test.exe.manifest and distribute it with the application instead.


MY OWN MODIFIED Dialog 


package main

import (
 "log"

 "github.com/lxn/walk"
 . "github.com/lxn/walk/declarative"
)

func main() {
 var dlg *walk.Dialog
 var acceptPB, cancelPB *walk.PushButton

 Dialog{
  Title:         "Scremo",
  DefaultButton: &acceptPB,
  CancelButton:  &cancelPB,
  MinSize:       Size{300, 300},
  Layout:        VBox{},
  Children: []Widget{
   Composite{
    Layout: Grid{Columns: 2},
    Children: []Widget{
     Label{
      Text: "Name:",
     },
     LineEdit{
      Text: Bind("Name"),
     },

     Label{
      Text: "Arrival Date:",
     },
     DateEdit{
      Date: Bind("ArrivalDate"),
     },

     Label{
      Text: "Species:",
     },
     ComboBox{
      Value:         Bind("SpeciesId", SelRequired{}),
      BindingMember: "Id",
      DisplayMember: "Name",
      //Model:         KnownSpecies(),
     },

     Label{
      Text: "Speed:",
     },
     Slider{
      Value: Bind("Speed"),
     },

     RadioButtonGroupBox{
      ColumnSpan: 2,
      Title:      "Sex",
      Layout:     HBox{},
      DataMember: "Sex",
      Buttons: []RadioButton{
       RadioButton{
        Name:  "aRB",
        Text:  "A",
        Value: "a",
       },
       RadioButton{
        Name:  "bRB",
        Text:  "B",
        Value: "b",
       },
      },
     },

     Label{
      Text: "Weight:",
     },
     NumberEdit{
      Value:    Bind("Weight", Range{0.01, 9999.99}),
      Suffix:   " kg",
      Decimals: 2,
     },

     Label{
      Text: "Preferred Food:",
     },
     ComboBox{
      Editable: true,
      Value:    Bind("PreferredFood"),
      Model:    []string{"Fruit", "Grass", "Fish", "Meat"},
     },

     Label{
      Text: "Domesticated:",
     },
     CheckBox{
      Checked: Bind("Domesticated"),
     },

     VSpacer{
      ColumnSpan: 2,
      Size:       8,
     },

     Label{
      ColumnSpan: 2,
      Text:       "Remarks:",
     },
     TextEdit{
      ColumnSpan: 2,
      MinSize:    Size{100, 50},
      Text:       Bind("Remarks"),
     },

     Label{
      ColumnSpan: 2,
      Text:       "Patience:",
     },
     LineEdit{
      ColumnSpan: 2,
      Text:       Bind("PatienceField"),
     },
    },
   },
   Composite{
    Layout: HBox{},
    Children: []Widget{
     HSpacer{},
     PushButton{
      AssignTo: &acceptPB,
      Text:     "OK",
      OnClicked: func() {
       dlg.Accept()
      },
     },
     PushButton{
      AssignTo:  &cancelPB,
      Text:      "Cancel",
      OnClicked: func() { dlg.Cancel() },
     },
    },
   },
  },
 }.Run(nil)
}

func RunAnimalDialog(owner walk.Form) (int, error) {
 var dlg *walk.Dialog
 var db *walk.DataBinder
 var acceptPB, cancelPB *walk.PushButton

 return Dialog{
  AssignTo:      &dlg,
  Title:         Bind("'Animal Details' + (animal.Name == '' ? '' : ' - ' + animal.Name)"),
  DefaultButton: &acceptPB,
  CancelButton:  &cancelPB,
  DataBinder: DataBinder{
   AssignTo: &db,
   Name:     "animal",
   //DataSource:     animal,
   ErrorPresenter: ToolTipErrorPresenter{},
  },
  MinSize: Size{300, 300},
  Layout:  VBox{},
  Children: []Widget{
   Composite{
    Layout: Grid{Columns: 2},
    Children: []Widget{
     Label{
      Text: "Name:",
     },
     LineEdit{
      Text: Bind("Name"),
     },

     Label{
      Text: "Arrival Date:",
     },
     DateEdit{
      Date: Bind("ArrivalDate"),
     },

     Label{
      Text: "Species:",
     },
     ComboBox{
      Value:         Bind("SpeciesId", SelRequired{}),
      BindingMember: "Id",
      DisplayMember: "Name",
      //Model:         KnownSpecies(),
     },

     Label{
      Text: "Speed:",
     },
     Slider{
      Value: Bind("Speed"),
     },

     RadioButtonGroupBox{
      ColumnSpan: 2,
      Title:      "Sex",
      Layout:     HBox{},
      DataMember: "Sex",
      Buttons: []RadioButton{
       RadioButton{
        Name:  "aRB",
        Text:  "A",
        Value: "a",
       },
       RadioButton{
        Name:  "bRB",
        Text:  "B",
        Value: "b",
       },
      },
     },

     Label{
      Text: "Weight:",
     },
     NumberEdit{
      Value:    Bind("Weight", Range{0.01, 9999.99}),
      Suffix:   " kg",
      Decimals: 2,
     },

     Label{
      Text: "Preferred Food:",
     },
     ComboBox{
      Editable: true,
      Value:    Bind("PreferredFood"),
      Model:    []string{"Fruit", "Grass", "Fish", "Meat"},
     },

     Label{
      Text: "Domesticated:",
     },
     CheckBox{
      Checked: Bind("Domesticated"),
     },

     VSpacer{
      ColumnSpan: 2,
      Size:       8,
     },

     Label{
      ColumnSpan: 2,
      Text:       "Remarks:",
     },
     TextEdit{
      ColumnSpan: 2,
      MinSize:    Size{100, 50},
      Text:       Bind("Remarks"),
     },

     Label{
      ColumnSpan: 2,
      Text:       "Patience:",
     },
     LineEdit{
      ColumnSpan: 2,
      Text:       Bind("PatienceField"),
     },
    },
   },
   Composite{
    Layout: HBox{},
    Children: []Widget{
     HSpacer{},
     PushButton{
      AssignTo: &acceptPB,
      Text:     "OK",
      OnClicked: func() {
       if err := db.Submit(); err != nil {
        log.Print(err)
        return
       }

       dlg.Accept()
      },
     },
     PushButton{
      AssignTo:  &cancelPB,
      Text:      "Cancel",
      OnClicked: func() { dlg.Cancel() },
     },
    },
   },
  },
 }.Run(owner)
}

Monday, August 27, 2018

Go build without console

 

 
The documentation found online says I can compile with something along the lines of,
go build -ldflags -Hwindowsgui filename.go
But this gives an error: unknown flag -Hwindowsgui
With more recent (1.1?) versions of the compiler, this should work:
go build -ldflags -H=windowsgui filename.go
When I continued searching around I found a note that the official documentation should be updated soon, but in the meantime there are a lot of older-style example answers out there that error.