Add line when end of the window is reached using curses? - curses

I have a small repl app using curses but I'm facing a problem to add new lines when end of window is reach. Output looks like the following, being --- the window limits:
---
REPL> :dothis
====> Well done!
REPL> :dothat
====> OK, done
REPL> :dothatagain====> All right...REPL> // can't add more lines :(
---
How do I addstr when end of window is reached just like a normal terminal buffer? I don't need to scroll back, just write a trail of lines. Is there any window setting to get an infinite vertical window?
Answers in any common language are fine (C preferred)

After some research on curses native API I noticed there is a int scrollok(WINDOW *win, bool bf); function:
scrollok(*window, true);
I didn't find the function before because the curses biding library I was using didn't have this function implemented so I just made a wrapper for it. Conclusion is to always look at the native curses API when using external language API bidings.

Related

How to force refresh in Curses with Ruby

I created a main window win:
win = Curses::Window.new(Curses.lines / 2, Curses.cols, 0, 0)
Then I sometimes need to create a message window, that covers the main one. After I close the message window, I refreshed win:
win.refresh
But unless I change anything in the main window using something like:
win.addstr("asd")
refresh doesn't redraw the window.
Is there a way to force redrawing the window?
It depends.
That's done using touchwin (or whatever name a Ruby binding may happen to use for the C function).
In ruby 2.0.0, the standard curses binding for Ruby lacked touchwin and touchline. Oddly enough, it included bindings for several of the ncurses extensions (resizeterm, the mouse interface, default-colors), but lacks many of the standard features (see X/Open Curses for reference).
In 2.4.1, curses is not a standard Ruby module, but the site for the module does have touchwin.
There is a method Curses::Window#touch which marks window as changed and to be redrawn by next refresh. There is also method Curses::Window#redraw which simply redraw the window.
Additional problem is getch method, which in my program is little bit unpredictable if I use Curses.getch - sometimes it causes that the window wont refresh, sometimes it causes whole screen to disappear... Using getch on window object solves the problem e.g. win.getch

OCaml + LablGTK2: Multi-Line Text Box

I am trying to figure out how to instantiate a multi-line text box inside a graphical widget. LablGTK2 appears to be quite limited in terms of documentation and the API is scarce for the things that start to look like what I want.
I have started to cross-reference the original GTK2 documentation, https://developer.gnome.org/gtk3/stable/gtkobjects.html, against the Lablgtk2 documentation, http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/lablgtk/html/GText.html.
However, the best tutorial or simple/clear example I have found makes use of the very limiting single line text entry box:
http://plus.kaist.ac.kr/~shoh/ocaml/lablgtk2/lablgtk2-tutorial/x1155.html
I have found that some clear simple, derived examples are great for learning the basics. Does anyone have sample vignette that shows how to set up a multi-line text using OCaml & Lablgtk/lablgtk2? Or better recommendations for tutorials that will show to develop a multi-line text box (which is a pretty important feature in any GUI-based program)? Ideally, I want to connect the text input into this multi-line text to an OCaml module I have written that will process that text and then the GUI will display that processing results back on the GUI. Any help would be greatly appreciated.
You can use GtkTextView widget for multi-line text:
let _ =
(* prepare main window *)
let window = GWindow.window () in
window#connect#destroy ~callback:GMain.Main.quit;
(* add text view with scroll bars *)
let scroll = GBin.scrolled_window
~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC
~packing:window#add () in
let textview = GText.view ~packing:scroll#add_with_viewport () in
(* set text *)
textview#buffer#set_text "multi-\nline\ntext";
(* show everything and enter main loop *)
window#show ();
GMain.Main.main ()
You're right that the docs are very sparse. Therefore we must learn by copying each other. Like monkeys...
I would wager that the ocamleditor should contain an example of how to do this: https://forge.ocamlcore.org/projects/ocamleditor/
Also OCP is creating a simple OCaml editor which should also be helpful: https://github.com/OCamlPro/ocp-edit-simple
The lablgtk2 source code provides basic code snippets that are easy to understand for the beginning (at least easier than real world code)
If you use godi, they are installed under $GODI_PRFIX/doc/godi-lablgtk2/examples .
You can see them in action from the command line with the script lablgtk2, e.g
lablgtk2 /opt/wodi32/doc/godi-lablgtk2/examples/editor.ml
lablgtk2 /opt/wodi32/doc/godi-lablgtk2/examples/text/text-demo.ml

Matlab GUI Attempt to reference field of non-structure array

I have a GUI menu on Matlab with 4 buttons (menu.fig). Then I have 4 .fig file that I want to open when I click on the buttons. Here it's all ok, when I open a .fig from menu and insert value to do a plot I get this error:
???? Attempt to reference field of non-structure array.
If I try to open 1.fig directly, everything works perfectly.
I read that the problem is with eval(), but I can't solve it.
I changed the variable names on each .fig file
One 1.fig:
function pbutton1_Callback(hObject, eventdata, handles)
A1=get(handles.edtSAmp,'String');
f1=get(handles.edtSFreq, 'String');
fi1=get(handles.edtSFase, 'String');
t1=get(handles.popTipo, 'Value');
A1=str2double(A1);
f1=str2double(f1);
fi=str2double(fi1);
SinalSinusoidal(A1,f1,fi,t1);
I got the error on the that 1st line.
I guess this is something MATLAB GUI not handled well. I know it used to work, but when you tweaking your UI or UI related code a bit and accidentally you modified some area MATLAB told you not to touch, this kind of issue begin to happen.
The workaournd is to start the GUI from M editor by clicking run
I know it works, but originally, when I directly lauch it , it works too. so, this is not the end of it, people are just not getting to the end of it.
The problem is with probably with handles1. It's not a structure array like you expect it to be. In GUI's created with GUIDE, this variable is usually called handles, if you have both handles and handles1 make sure handles1 contains handles to the objects in the figure. If you're using handles1 only, make sure you're initializing it properly.

Win32API replicate Spy++ window-information capabilities within Python

I have a third-party GUI program that I'm wrapping with a Python class (using ctypes).
Are there Win32 API functions that can do the following?
1) Obtain the window handle for a window at a given screen location.
2) Obtain the window handle for a Button or Static window with a given caption.
3) Send text to an Edit window.
4) Extract text from a RICHEDIT instance.
I have WinSpy (a Spy++-type app) and know that it's possible to obtain window handles and captions using that tool, but I need something that works within Python.
I assume that Python's ctypes gives me access to any function within the Win32 API, so I've been scanning MSDN (especially this windows/messages section). I can't seem to find anything that works.
Thanks,
Mike
WindowFromPoint
FindWindowEx to find a child of a window with a given class and name (caption). Repeat operation to get through each parent-child indirection. EnumChildWindows can be helpful too.
SendMessageTimeout + WM_SETTEXT
SendMessageTimeout + WM_GETTEXT or EM_STREAMOUT
I had trouble finding a very simple example for WM_GETTEXT with pywin32 and figured here might be a good place to add one, since it answers part of the question:
MAX_LENGTH = 1024
handle = # A handle returned from FindWindowEx, for example
buffer = win32gui.PyMakeBuffer(MAX_LENGTH)
length = win32gui.SendMessage(handle, win32con.WM_GETTEXT, MAX_LENGTH, buffer)
result = buffer[:length]

How to take a partial screen capture using Ruby?

I need to run a ruby client that wakes up every 10 minutes, takes a screen-shot (ss) of a users screen, crops part of the (ss) out and use's OCR to check for a matching word....its basically a program to make sure remote employees are actually working by checking that they have a specific application open & the case numbers shown change.
Not sure where to even start when it comes to taking a screen-shot and cropping it, has anyone done any kind of screen capture work using Ruby?
The app will run on OSX using Ruby 1.9
Thanks!
On OS X you can use the screencapture command in the terminal to capture the screen, so capturing the screen from Ruby shouldn't be more than
def screen_capture(path)
`screencapture #{path}`
end

Resources