How to change active application in progress? - progress-4gl

In Progress 11.3.2 (Developer Studio 3.7 - Eclipse 3.8.2), not using dot net at all:
How do you switch the focus to another window/application/w file?
In windows 7/8 the order of what window that is focused acts a bit different than before and does not always show the window you want to have over all the other apps.
If you have 3 windows open, and close the 3rd one and want to focus on the second one that was minimized, the first one get focus instead.
You set it to normal with WINDOW-STATE = WINDOW-NORMAL. But how to focus on it too?

If you run the secondary windows persistent you can do something like this:
In calling window:
/* In definitions */
DEFINE VARIABLE ghSecondWindow AS HANDLE NO-UNDO.
/* In a trigger */
RUN secondWindow.w PERSISTENT SET ghSecondWindow.
/* Whenever you want to shift focus */
RUN setFocus IN ghSecondWindow.
In "SecondWindow":
PROCEDURE setFocus:
/* Replace FILL-IN-1 with any widget that can gain focus */
APPLY "ENTRY" TO FILL-IN-1 IN FRAME {&FRAME-NAME}.
END PROCEDURE.
If however you are not running persistent windows you can still achieve this by walking the widget trees, first of the current window and then of the second window (once you've localized it).
Quick and ugly code to put in the calling window wherever you want the focus to shift. This might not suit your needs exactly so it might require some rewriting. Also error checking is pretty much not here and dealing with possible eternal loops without error checking is not really best practice:
DEFINE VARIABLE hWin AS HANDLE NO-UNDO.
DEFINE VARIABLE hWidget AS HANDLE NO-UNDO.
/* Get the first child (widget) of the session */
ASSIGN
hWin = SESSION:FIRST-CHILD.
/* Loop through all widgets in the session */
loop:
DO WHILE VALID-HANDLE(hWin):
/* We've identified the correct Window! */
IF hWin:TYPE = "WINDOW" AND hWin:TITLE = "Secondary Window" THEN DO:
/* ** Very Ugly** this could use better error checking etc! */
/* Get the second field-group of the window */
/* This will depend on your layout with different frames etc */
/* What we really have is WINDOW:DEFAULT-FRAME:FIELD-GROUP:FIELD-GROUP */
/* Field groups are really only present in the widget tree - they lack visual */
/* representation */
/* Read about field-groups in the online help! */
ASSIGN
hWidget = hWin:FIRST-CHILD:FIRST-CHILD:FIRST-CHILD.
/* Loop through all widgets of the field-group */
DO WHILE VALID-HANDLE(hWidget).
/* We've found the correct fill-in, give it focus */
IF hWidget:TYPE = "FILL-IN" AND hWidget:LABEL = "Fill 1" THEN DO:
APPLY "ENTRY" TO hWidget.
LEAVE loop.
END.
/* Next window of the correct window */
hWidget = hWidget:NEXT-SIBLING.
END.
END.
/* Next widget of the session */
hWin = hWin:NEXT-SIBLING.
END.
You could also do the "widget tree walk" recursively if you feel like it!

Related

STM32 HAL Lib,Can not clear TIM SR register by use __HAL_TIM_CLEAR_FLAG?

The TIM SR register value always be 0x1F, And Can not use to clear the reg.
HAL Lib Always runs into time interrupt really fast, and Can not clear SR register.
How to fix the promble?
Cubemx set
NVIC
`
void TIM3_IRQHandler(void)
{
/* USER CODE BEGIN TIM3_IRQn 0 */
/* USER CODE END TIM3_IRQn 0 */
HAL_TIM_IRQHandler(&htim3);
/* USER CODE BEGIN TIM3_IRQn 1 */
/* USER CODE END TIM3_IRQn 1 */
}
`
`
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if ( htim == &htim3){
__HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_UPDATE) ;
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13) ;
}
}
`
I will base my explanation on STM32F746's TIM3. Timers across STM32 that share number are usually identical or very similar.
TIM3->SR has 0x1F? That's 5 flags set! TIM3 is a general purpose STM32 timer. These 5 flags mean you have counter interrupt and four capture/compare interrupt status flags set at the same time. Something weird is going on. Are you sure you're supposed to have those flags set? Well, if their interrupts are not enabled, it doesn't matter.
You can clear these flags in TIM3->SR by writing zero to the specific position you want to clear and 1 everywhere else. As per reference manual, this register ignores if you write 1. It doesn't set bits when you do that. It only resets when you write zero. So,
TIM3->SR = 0; //clear all interrupt flags
TIM3->SR = ~TIM_SR_UIF; //clear update interrupt flag only
This works because the bits in the reference manual are marked rc_w0 - read, clear by writing zero. If bits in your SR register work differently, you may have to clear them differently. For example, sometimes status register is read-only and you clear it via write to flag clear register. Check reference manual of your MCU.

Howto Maintain GtkSourceCompletion When Changing Buffers in a GtkSourceView?

All,
I have an editor that holds the open files in a treeview/treemodel on the left of the main window and displays the buffer associated with the highlighted treeview entry in the focused textview (sourceview) window on the right.
Each GtkSourceView shown is contained within an editor instance struct which also contains a pointer to its GtkSourceCompletionWords 'provider' (prov_words). The word-completion works fine for the first buffer shown in the window, but when I change files and display a different buffer in the sourceview window, word competion is not active for that buffer, even through I unregister the first buffer from the prov_words provider and register the current buffer for the words provider to use as its source.
Essentially I create the initial completion object as:
GtkSourceCompletion *completion;
GtkSourceCompletionWords *prov_words;
completion = gtk_source_view_get_completion (view);
prov_words = gtk_source_completion_words_new (NULL, NULL);
gtk_source_completion_words_register (prov_words,
gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
gtk_source_completion_add_provider (completion,
GTK_SOURCE_COMPLETION_PROVIDER (prov_words), NULL);
/* store a pointer to the completions words provider as part of
* the editor instance.
*/
einst->prov_words = prov_words;
When displaying a new buffer in the textview, I use the treeview "changed" signal to display the new buffer, update the window title, etc.. and to unregister the current buffer from the prov_words provider and then register the new buffer as the word source with:
GtkSourceCompletionWords *prov_words = einst->prov_words;
/* unregister current buffer from words completion provider */
gtk_source_completion_words_unregister (prov_words,
GTK_TEXT_BUFFER(oldbuf));
/* register new buffer with words completion provider */
gtk_source_completion_words_register (prov_words,
GTK_TEXT_BUFFER(newbuf));
This results in no completion functionality at all in the new buffer -- but when switching back to the first buffer, completion continues to work just fine. So it seems I am conceptually missing a piece of the puzzle for what is required to switch buffers associated with a sourceview window (where the completion object and provider remain unchanged) and have completion work with the new buffer in that same sourceview window.
Since the completion object is part of the sourceview, the provider part of the completion object and the words proposed by the provider are derived from the buffer, e.g.
-- GtkSourceView
|
-- GtkSourceCompletion
| |
| -- GtkSourceCompletionWords
|
-- GtkSourceBuffer
it seems the only requirement would be to unregister the words in the first buffer from the provider and then register the words in the new buffer with the provider -- but that does not seem to be the case. The documentation is silent on what is required in this instance (or it escapes me), Gtk SourceView Completion API
So how do you enable completion for a sourceview widget and then change the displayed buffer and have the completion continue to work using the words in the new bufffer?

Screenshot of an active Window in Progress-4GL

I am working In Progress 4GL , in my application i wish to take a screeenshot of an active window on any KeyStroke Event such as (CTRL + F9) and save the same in a prespecified folder. Can anyone Help me in this ?
As mentioned in the comments this can be done by calling .NET from Progress ABL. Here's an example that takes a screenshot of the entire screen. You will need to adapt this to your needs.
USING System.Drawing.*.
USING System.Drawing.Imaging.*.
USING System.Windows.Forms.Screen.
DEFINE VARIABLE bmpScreenshot AS Bitmap NO-UNDO.
DEFINE VARIABLE gfxScreenshot AS Graphics NO-UNDO.
bmpScreenshot = NEW Bitmap(Screen:PrimaryScreen:Bounds:Width,
Screen:PrimaryScreen:Bounds:Height,
PixelFormat:Format32bppArgb).
gfxScreenshot = Graphics:FromImage(bmpScreenshot).
gfxScreenshot:CopyFromScreen(Screen:PrimaryScreen:Bounds:X,
Screen:PrimaryScreen:Bounds:Y,
0,
0,
Screen:PrimaryScreen:Bounds:Size,
CopyPixelOperation:SourceCopy).
/* Use ImageFormat:[Png|Gif|Bmp|Tiff] etc for different image formats */
bmpScreenshot:SAVE("c:\temp\Screenshot.png", ImageFormat:Png).
This is a C# to ABL translation of this question on SO.

Hiding comments with hs-hide-level in Emacs hide-show mode

When I use hs-hide-level, it only hides code blocks at at the current level, but leaves comment blocks at the same level open. For example, if I take the following un-folded code:
top level code {
/* Level 2
* Multi-line
* Comment
*/
level 2 code block {
Code inside
level 2
block
}
}
And I use the hs-hide-level inside the top-level block, I will get
top level code {
/* Level 2
* Multi-line
* Comment
*/
level 2 code block { ... }
}
but I want
top level code {
/* Level 2 ...
level 2 code block {...}
}
I don't know if this feature only appeared since the question was asked, but there is the option hs-hide-comments-when-hiding-all, which according to the documentation does this:
Hide the comments too when you do an hs-hide-all.
This does not answer your question directly, but it might help nevertheless.
You can use library hide-comnt.el to hide only comments.
The description is here.
You can hide comments interactively or using Lisp macro with-comments-hidden. The effect of both is controlled by option ignore-comments-flag, which gives you additional control over the behavior.
Command hide/show-comments acts on the active region, or the whole buffer if the region is not active.

SciLab checkbox UIControl value not changing with state?

I'm trying to design a GUI in SciLab that updates it's properties depending on a checkmark. For example: A checkbox might enable and change the backrounds of several text boxes during a callback; or a pushbutton may require a certain number of checkboxes to be selected.
My problem is that I can't seem to develop a flow control statement for running instructions depending on the checkboxes state during a callback. My current UIControl element looks like this:
handles.chkS11En=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.02140625,0.791119360625398,0.0803125,0.0369667],'Relief','flat','SliderStep',[0.01,0.1],'String','S11','Style','checkbox','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','chkS11En','Callback','chkS11En_callback(handles)')
And my callback that runs when I check the checkbox is this:
cS11En = findobj('tag', 'chkS11En'); // checkbox option
tS11MagUpperBound = findobj('tag', 'txtS11MagUpperBound'); //edit box that is controlled
mprintf("%d\n",cS11En.Value);
if cS11En.Value == [1] then
mprintf("Checked = on \n");
set(tS11MagUpperBound,'BackgroundColor',[1,1,1]);
set(tS11MagUpperBound,"Enable",'on');
set(cS11Save,"Enable",'on');
elseif cS11En.Value == [0] then
mprintf("Checked = off \n");
set(tS11MagUpperBound,'BackgroundColor',[0.8,0.8,0.8]);
set(tS11MagUpperBound,'Enable','off');
set(cS11Save,"Enable",'off');
end
The problem with this code seems to be that the second path (Value = 1) never seems to run, even when i continually toggle the checkbox. I get an output like so:
0
Checked = off
0
Checked = off
0
Checked = off
0
Checked = off
Is there something I'm doing wrong in order to reload checking the element? I want to be able to run both paths, however I can never seem to get a value of 1 from the checkbox element. Does anyone have a solution to this? Thanks!
IF anyone is wondering and finds this through the googles or something, this is how I fixed it:
It turns out that SciLab sometimes doesn't clear all UI variables when the form is closed and a script is running.
The solution is to add a few lines in the top of each of your program that clears all variables, closes all forms, and initializes your variables.
Basically, add this:
// /////////////
// Lemon Pledge
// /////////////
mprintf("\n!!!!!!!!!!!!!!!!!!!\nCLEARING ALL VARIABLES\n!!!!!!!!!!!!!!!!!!!\n")
xdel(winsid());
clear;
clearglobal;
Another less complex solution would be:
Using the same checkbox I left the last attribute in blank.
handles.chkS11En=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','helvetica','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.02140625,0.791119360625398,0.0803125,0.0369667],'Relief','flat','SliderStep',[0.01,0.1],'String','S11','Style','checkbox','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','chkS11En','Callback','')
Then I make the callback
function chkS11En_callback(handles)
if handles.chkS11En.Value == [1] then
mprintf("Checked = on \n");
set(tS11MagUpperBound,'BackgroundColor',[1,1,1]);
set(tS11MagUpperBound,"Enable",'on');
set(cS11Save,"Enable",'on');
else
mprintf("Checked = off \n");
set(tS11MagUpperBound,'BackgroundColor',[0.8,0.8,0.8]);
set(tS11MagUpperBound,'Enable','off');
set(cS11Save,"Enable",'off');
end
And voilà, no need to clear your workspace.