errors.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
  2. //
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 2.1 of the License, or (at your option) any later version.
  7. //
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this library; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. // MA 02110-1301 USA
  17. package main
  18. import (
  19. "fmt"
  20. "os"
  21. "gopkg.in/qml.v1"
  22. )
  23. func ErrorWindow(err error) {
  24. engine := qml.NewEngine()
  25. component, e := engine.LoadString("local", qmlErr)
  26. if e != nil {
  27. fmt.Println("err:", err)
  28. os.Exit(1)
  29. }
  30. win := component.CreateWindow(nil)
  31. win.Root().ObjectByName("label").Set("text", err.Error())
  32. win.Show()
  33. win.Wait()
  34. }
  35. const qmlErr = `
  36. import QtQuick 2.0; import QtQuick.Controls 1.0;
  37. ApplicationWindow {
  38. width: 600; height: 150;
  39. flags: Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint
  40. title: "Error"
  41. Text {
  42. x: parent.width / 2 - this.width / 2;
  43. y: parent.height / 2 - this.height / 2;
  44. objectName: "label";
  45. }
  46. }
  47. `