Beispiel #1
0
func (self *Message) setupBuilder(msgType MessageType, gladeStr string) {
	var err error
	self.msgBuilder, err = gtk.BuilderNew()
	if err != nil {
		goline.LoggerPanicln(err)
	}

	switch msgType {
	case MESSAGE_NORMAL:
		err = self.msgBuilder.AddFromString(glade.Message)
	case MESSAGE_YOU:
		err = self.msgBuilder.AddFromString(glade.YouMessage)
	}

	if err != nil {
		goline.LoggerPanicln(err)
	}

	self.builder, err = gtk.BuilderNew()
	if err != nil {
		goline.LoggerPanicln(err)
	}

	err = self.builder.AddFromString(gladeStr)
	if err != nil {
		goline.LoggerPanicln(err)
	}
}
Beispiel #2
0
func (self *LineWindow) setupBuilder(glade string) {
	var err error
	self.builder, err = gtk.BuilderNew()
	if err != nil {
		goline.LoggerPanicln(err)
	}

	err = self.builder.AddFromString(glade)
	if err != nil {
		goline.LoggerPanicln(err)
	}
}
func NewFriendsTypeLabel(text string) *FriendsTypeLabel {
	builder, err := gtk.BuilderNew()
	if err != nil {
		goline.LoggerPanicln(err)
	}
	err = builder.AddFromString(glade.FriendsTypeLabel)
	if err != nil {
		goline.LoggerPanicln(err)
	}

	label := getIObjectWithType(builder, "FriendsType", &gtk.Label{}).(*gtk.Label)
	label.SetText(text)
	return &FriendsTypeLabel{builder: builder, label: label}
}
func (app *Application) Run() {

	gtk.Init(nil)

	app.active_dicts = make(map[string]bool)

	builder, err := gtk.BuilderNew()
	if err != nil {
		log.Fatal(err)
	}
	builder.AddFromFile("dictsearch.glade")
	w, err := builder.GetObject("win")
	if err != nil {
		log.Fatal(err)
	}

	app.win = w.(*gtk.Window)
	app.win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Box, containing list of dictionary chaeckbuttons
	dict_list_box, err := builder.GetObject("dict_list_box")
	if err != nil {
		log.Fatal(err)
	}
	app.dict_list = dict_list_box.(*gtk.Box)

	// Search Entry
	s_e, err := builder.GetObject("search_entry")
	if err != nil {
		log.Fatal(err)
	}
	app.search_entry = s_e.(*gtk.Entry)
	app.search_entry.Connect("activate", func() {
		text, err := app.search_entry.GetText()
		if err != nil {
			log.Fatal(err)
		}
		go app.Search(text, app.ch, app.done_flag)
	})

	// Search Button
	s_b, err := builder.GetObject("search_button")
	if err != nil {
		log.Fatal(err)
	}
	app.search_button = s_b.(*gtk.Button)
	app.search_button.Connect("clicked", func() {
		text, err := app.search_entry.GetText()
		if err != nil {
			log.Fatal(err)
		}
		go app.Search(text, app.ch, app.done_flag)
	})

	// Text View
	tv, err := builder.GetObject("textview")
	if err != nil {
		log.Fatal(err)
	}
	app.text_view = tv.(*gtk.TextView)
	app.text_view.SetEditable(false)
	app.text_view.SetWrapMode(gtk.WRAP_WORD)

	// Adding dictionary checkbuttons
	for i, dic := range app.GetDictList(dict_path) {
		dict_button, err := gtk.CheckButtonNew()
		if err != nil {
			log.Fatal(err)
		}
		label := dic
		dict_button.SetLabel(label)
		name := fmt.Sprintf("checkbutton%d", i)
		dict_button.SetName(name)
		dict_button.SetFocusOnClick(false)
		dict_button.Connect("toggled", func() {
			if dict_button.GetActive() {
				app.active_dicts[label] = true
			} else {
				delete(app.active_dicts, label)
			}
		})
		app.dict_list.Add(dict_button)
	}

	// StatusBar
	stb, err := builder.GetObject("statusbar")
	if err != nil {
		log.Fatal(err)
	}
	app.status_bar = stb.(*gtk.Statusbar)

	app.search_entry.GrabFocus()

	app.win.ShowAll()
	gtk.Main()

}