Пример #1
0
func windowClosed() bool {
	window = nil
	if timeout != 0 {
		glib.GSourceRemove(timeout)
		timeout = 0
	}
	return false
}
Пример #2
0
func DoListStore(w gtk3.WidgetLike) gtk3.WidgetLike {
	var model *gtk3.ListStore
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetTitle("GtkListStore demo")
		window.Connect("destroy", func() { window = nil })
		window.SetBorderWidth(8)

		vbox := gtk3.NewVBox(8)
		window.Add(vbox)

		label := gtk3.NewLabel("This is the bug list (note: not based on real data...)")
		vbox.PackStart(label, false, false, 0)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetShadowType(gtk3.GtkShadow.ETCHED_IN)
		sw.SetPolicy(gtk3.GtkPolicy.NEVER, gtk3.GtkPolicy.AUTOMATIC)
		vbox.PackStart(sw, true, true, 0)

		// create tree model
		model = createModel()

		// create tree view
		treeview := gtk3.NewTreeViewWithModel(model)
		treeview.SetRulesHint(true)
		treeview.SetSearchColumn(ColumnDescription)
		sw.Add(treeview)

		// Add columns to treeview
		addColumns(treeview)

		// Finish & Show
		window.SetDefaultSize(280, 250)
		window.Connect("delete-event", windowClosed)
	}

	if !window.GetVisible() {
		window.ShowAll()
		timeout = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 80,
			func() {
				var sIter gtk3.TreeIter
				model.GetIterFirst(&sIter)
				pulse := model.GetValue(&sIter, ColumnPulse).(uint)

				if pulse == ^uint(0) {
					pulse = 0
				} else {
					pulse++
				}
				model.SetValues(&sIter, gtk3.V{ColumnPulse: pulse, ColumnActive: true})
			})

	} else {
		window.Destroy()
		window = nil
		if timeout != 0 {
			glib.GSourceRemove(timeout)
			timeout = 0
		}
		return nil
	}

	return window
}
Пример #3
0
func DoSearchEntry(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		var searchProgressId, finishSearchId uint

		window = gtk3.NewDialogWithButtons("Search Entry", w.(*gtk3.Window),
			0, gtk3.B{{gtk3.GtkStock.CLOSE, gtk3.GtkResponse.NONE}})
		window.SetResizable(false)
		window.Connect("response", func() { window.Destroy() })
		window.Connect("destroy", func() {
			if finishSearchId != 0 {
				glib.GSourceRemove(finishSearchId)
			}
			if searchProgressId != 0 {
				glib.GSourceRemove(searchProgressId)
			}

			window = nil
		})

		contentArea := window.GetContentArea().(*gtk3.Box)

		vbox := gtk3.NewVBox(5)
		contentArea.PackStart(vbox, true, true, 0)
		vbox.SetBorderWidth(5)

		label := gtk3.NewLabel("")
		label.SetMarkup("Search entry demo")
		vbox.PackStart(label, false, false, 0)

		hbox := gtk3.NewHBox(10)
		vbox.PackStart(hbox, true, true, 0)
		hbox.SetBorderWidth(0)

		// Create our entry
		entry := gtk3.NewEntry()
		hbox.PackStart(entry, false, false, 0)

		// Create the find and cancel buttons
		notebook := gtk3.NewNotebook()
		notebook.SetShowTabs(false)
		notebook.SetShowBorder(false)
		hbox.PackStart(notebook, false, false, 0)

		startSearchFunc := func() { entry.ProgressPulse() }

		finishSearchFunc := func() bool {
			notebook.SetCurrentPage(0)
			glib.GSourceRemove(searchProgressId)
			searchProgressId = 0
			entry.SetProgressFraction(0.0)
			return false
		}

		findButton := gtk3.NewButtonWithLabel("Find")
		findButton.Connect("clicked", func() {
			notebook.SetCurrentPage(1)

			searchProgressId = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 100, startSearchFunc)

			finishSearchId = glib.GTimeoutAddSecondsFull(glib.GPriority.DEFAULT, 15, finishSearchFunc)
		})
		notebook.AppendPage(findButton, nil)
		findButton.Show()

		cancelButton := gtk3.NewButtonWithLabel("Cancel")
		cancelButton.Connect("clicked", func() {
			glib.GSourceRemove(finishSearchId)
			finishSearchFunc()
		})
		notebook.AppendPage(cancelButton, nil)
		cancelButton.Show()

		// Set up the search icon
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.FIND)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by name\nClick here to change the search type")
		entry.SetPlaceholderText("name")

		// Set up the clear icon
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.SECONDARY, gtk3.GtkStock.CLEAR)

		menu := createSearchMenu(entry)
		menu.AttachToWidget(entry, nil)

		textChangedFunc := func() {
			hasText := entry.GetTextLength() > 0
			entry.SetIconSensitive(gtk3.GtkEntryIconPosition.SECONDARY, hasText)
			findButton.SetSensitive(hasText)
		}

		textChangedFunc()

		entry.Connect("icon-press", iconPressCallback, menu)
		entry.Connect("notify::text", textChangedFunc)

		entry.Connect("activate", func() {
			if searchProgressId != 0 {
				return
			}
			notebook.SetCurrentPage(1)

			searchProgressId = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 100, startSearchFunc)

			finishSearchId = glib.GTimeoutAddSecondsFull(glib.GPriority.DEFAULT, 15, finishSearchFunc)

		})

		entry.Connect("populate-popup", entryPopulatePopup)

		button := window.GetWidgetForResponse(gtk3.GtkResponse.NONE)
		button.W().GrabFocus()
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}

	return window
}