Is there some method which tells you the line number and column number of a Text widget in Perl/Tk?
According to the documentation, the widget has a method index() which returns the "line.char" of various positions in the widget. Pass it the name of the special mark "insert" to get the current position of the insertion cursor. Pass it the name of the special mark "current" to get the current position on the mouse.
Your question doesn't make it clear which of the two you want.
Related
I'm working with CodeMirror 6 and I'd like to render a non-editable code sample where you can modify one or more sub-strings of the sample value.
I am already set up to identify the ranges within a code sample where I'd like the text to be editable. I'm also aware of the Decorations reference, but it doesn't seem like you can simply mark a decorated range as "editable".
Currently, when constructing decorations, I just look at the decoration object to determine if a range is editable, and if it is insert an HTML text input widget, otherwise insert a decoration that styles the range such that it looks editable. Here's a little bit of what that looks like:
const positionLineStart = createPosition(item.startColumn);
// This range is being edited, so use a widget that inserts the text input
if (item.editing) {
const editableFieldWidget = Decoration.widget({
widget: new EditableFieldWidget(item),
});
return editableFieldWidget.range(positionLineStart);
// The range is not being edited, but is editable, so insert a mark deco
// that makes it look like you can click into it
} else {
const positionLineEnd = createPosition(item.endColumn);
const inlineDecoration = Decoration.mark(attributes);
return inlineDecoration.range(positionLineStart, positionLineEnd);
}
But going this route makes things pretty complicated: I need to handle a bunch of events - focus, blur, Enter, Escape to determine the new range value, resizing the range after saving to reflect the new value, communicating the value of the text input back to the code sample and replacing that range with it, etc.
I almost wish that I could simply set contenteditable on a decoration that exists within a non-editable CodeMirror instance - that way it's all edited in place, can still be copied out, and doesn't require swapping decorations.
Is what I'm after possible?
I simply want to set a room name using input fields and the fact that it can pass the input through as an argument, but this does not seem to work for some reason.
here is the function that is called
here is the output in the console when typing in the field
why does it send in a blank string?
I followed this tutorial: Youtube
When you add a listener (HostGame.SetRoomName) you have two sections from which you can choose your functions: Dynamic string and Static Parameters. Your function should be in both sections:
Dynaic string - SetRoomName
Static Parameters - SetRoomName(string)
You have to choose the first one if you want to receive as parameter the input field text. The parameter in the second option is whatever you put in the field below HostGame.SetRoomName in your first image (in your case blank).
I worked around this by creating a reference to the text in "SetRoomName" it's not ideal but works
It hasn't been explained well but you want to select the top method under dynamic value. If you look at this image, you will see two methods, selecting the bottom (static) one will show the input field as you see but the top (dynamic) one (which is what you want) will show no input field.
I'm looking for a widget which can be dynamically resized. I need to append and remove rows.
There are a methods coming with Grid, like gtk_grid_insert_row or gtk_grid_insert_next_to, but I don't find any xxx_remove_xxx method.
I'm developing a simple http client (to test an api). And I'm adding the possibility to append and remove "GET" variables dynamically.
The UI is made with rows containing a combobox (for variable selection), an entry (for its value) and on the last row a remove button.
Every time I set a variable, a new line (new available variable) is appended.
And every time I unset a variable, the corresponding line is removed.
thanks.
Gtk.Grid doesn't have a remove method; but Gtk.Container does. Since Grid is a Container, you can use gtk_container_remove.
The docs for this are here:
https://developer.gnome.org/gtk3/3.8/GtkContainer.html#gtk-container-remove
I think the widget you are looking for is Gtk.ListBox. It's a container so you can add and remove rows easily.
I want to create own widget that will be able to interpret the text between start and end tag, eg:
<p1:Btn ui:field="open" >Open</p1:Btn>
Now the UI binder throws error:
Unexpected text in element: "Open" Element <p1:Btn ui:field='open'> (:44)
I supose that the widget have to be somehow marked to allow elements inside.
The second thing is how read the element between tags.
Your widget needs simply implement the HasText interface.
I have a collection of GtkEntry widgets, some of which are editable and focusable, and some of which are not. I would like to find out which, if any, of them currently has text selected, in order to implement an Edit->Copy menu item. Is there any way to do this other than iterating over all the widgets until gtk_editable_get_selection_bounds returns true?
I am currently sidestepping the issue by calling gtk_clipboard_get(GDK_SELECTION_PRIMARY) but from what the docs say, that's not portable (and will also pick up text selected anywhere within the current display, not just from within my application).
Have you tried gtk_window_get_focus ()? Users are frequently interacting with entries, so it may work for you. The documentation says that it "retrieves the current focused widget within the window." You can look it by yourself here. Then, compare if the widget retrieved is one of your entries.
Once you get the focused entry, perhaps you would like to get its text using gtk_entry_get_text () , though, it will get all the text in the entry. If this does not fit your purposes, the solution might be using gtk_editable_copy_clipboard () which copies the contents of the currently selected content in the editable (of course, cast the entry to editable) and puts it on the clipboard. Then if it applies, paste what was copied using gtk_editable_paste_clipboard ().