func (w *MainWindow) saveFile(fileName string) bool { file := ui.NewQFileWithName(fileName) defer file.Delete() if !file.Open(ui.QIODevice_WriteOnly | ui.QIODevice_Text) { return false } file.Write([]byte(w.edit.ToPlainText())) w.setCurrentFile(fileName) w.StatusBar().ShowMessageWithTextTimeout("File saved", 2000) return true }
func (w *MainWindow) loadFile(filename string) { file := ui.NewQFileWithName(filename) defer file.Delete() if !file.Open(ui.QIODevice_ReadOnly) { return } w.edit.SetPlainText(string(file.ReadAll())) w.setCurrentFile(filename) w.StatusBar().ShowMessageWithTextTimeout("File loaded", 2000) }
func NewCalclatorForm() (*CalclatorForm, error) { w := &CalclatorForm{} w.QWidget = ui.NewQWidget() file := ui.NewQFileWithName(":/forms/calculatorform.ui") if !file.Open(ui.QIODevice_ReadOnly) { return nil, errors.New("error load ui") } loader := ui.NewQUiLoader() formWidget := loader.Load(file) if formWidget == nil { return nil, errors.New("error load form widget") } w.spinBox1 = ui.NewQSpinBoxFromDriver(formWidget.FindChild("inputSpinBox1")) w.spinBox2 = ui.NewQSpinBoxFromDriver(formWidget.FindChild("inputSpinBox2")) w.outputLable = ui.NewQLabelFromDriver(formWidget.FindChild("outputWidget")) if ui.IsValidDriver(w.spinBox1) && ui.IsValidDriver(w.spinBox2) && ui.IsValidDriver(w.outputLable) { fnChanged := func() { w.outputLable.SetText(fmt.Sprintf("%d", w.spinBox1.Value()+w.spinBox2.Value())) } w.spinBox1.OnValueChanged(func(string) { fnChanged() }) w.spinBox2.OnValueChanged(func(string) { fnChanged() }) } layout := ui.NewQVBoxLayout() layout.AddWidget(formWidget) w.SetLayout(layout) w.SetWindowTitle("Calculator Builder") return w, nil }