Keep a progress bar on top. Linux - linux

Okay so I was just wondering if there is a way to have a progress bar on the top as the script is running to tell the user that x% of the process has been completed. Also is there a command that is built into the OS that would let me use a progress bar or would i have to design that as well in code?

Include in your script a percentage tracker, but will consume more resources...
For example if you are copying a bunch of files:
`
foreach $y (#files) {
$countline++;
$total = 1000;
$lastcount = $currentcount
$currentcount = $countline / $total
if ( $lastcount > $currentcount ) {
$progress_display == 1
$currentcount
if ($progress_display == 1) {
print ".";
}
}
print "\n";
`

There is zenity, a GTK application with GUI elements for scripts. It has a progress bar and much more.
The package dialog provides several UI elements for shell scripting. One of them is a gauge, a progress bar. Debian maintains a simplified version of dialog called whiptail.
There is also an X version of dialog: Xdialog, but I have never seen it myself.

Related

Can this code be changed to support a preview in the print dialog?

I am not sure if this is an issue that can be resolved with coding or is by design. I am running the latest version of Windows 11 with all updates. And my application is a MFC dialog application built with Visual Studio 2022.
My application uses a CHtmlView control and the user can trigger a Print Preview. This event will trigger the following code:
void CChristianLifeMinistryHtmlView::DoPrintPreview()
{
ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, nullptr, nullptr);
HWND HWND_PP = nullptr ;
const auto t1 = ::GetTickCount64();
auto t2 = ::GetTickCount64(); // Extra line required for 'while' rearrangement.
while (HWND_PP == nullptr && t2 - t1 <= 6000) // if found or Timeout reached...
{
HWND HWND_FG = ::GetForegroundWindow(); // Get the ForeGroundWindow
if (HWND_FG != nullptr)
{
TCHAR szClassName[256]{} ;
::GetClassName(HWND_FG, &szClassName[0], 256);
if (lstrcmp(&szClassName[0], IE_PPREVIEWCLASS) == 0) // Check for Print Preview Dialog
HWND_PP = HWND_FG ;
}
theApp.PumpMessage();
t2 = ::GetTickCount64();
}
if (HWND_PP != nullptr)
{
RECT workArea{};
::SystemParametersInfo( SPI_GETWORKAREA, 0, &workArea, 0 );
::MoveWindow(HWND_PP, workArea.left, workArea.top,
workArea.right - workArea.left, workArea.bottom - workArea.top, TRUE);
}
}
This code works fine, and I get a good print preview, resized to the display. For example:
Now, if I hit Print from here it displays:
Opting to print to PDF looks the same:
Prior to the recent Windows 11 Updates these latter "print dialogs" looked different with no preview anyway. But since this updated version of the system "print dialog" can cope with a preview, is there no way to get our existing CHtmlView preview displayed there?
This is only a cosmetic thing because I have a standard preview for the user to see anyway (snap 1). But it would be the icing on the cake if that preview could someone be fed into this popup print window.
Is this something we can do by code or is it a "system / by design issue"?

NSSplitViewItem collapse animation and window setFrame conflicting

I am trying to make a (new in 10.10) NSSplitViewItem collapse and uncollapse whilst moving its containing window so as to keep the whole thing "in place".
The problem is that I am getting a twitch in the animation (as seen here).
The code where I'm doing the collapsing is this:
func togglePanel(panelID: Int) {
if let splitViewItem = self.splitViewItems[panelID] as? NSSplitViewItem {
// Toggle the collapsed state
NSAnimationContext.runAnimationGroup({ context in
// special case for the left panel
if panelID == 0 {
var windowFrame = self.view.window.frame
let panelWidth = splitViewItem.viewController.view.frame.width
if splitViewItem.collapsed {
windowFrame.origin.x -= panelWidth
windowFrame.size.width += panelWidth
} else {
windowFrame.origin.x += panelWidth
windowFrame.size.width -= panelWidth
}
self.view.window.animator().setFrame(windowFrame, display: true)
}
splitViewItem.animator().collapsed = !splitViewItem.collapsed
}, completionHandler: nil)
}
}
I am aware of the "Don't cross the streams" issue (from session 213, WWDC'13) where a window resizing animation running on the main thread and a core animation collapse animation running on a separate thread interfere with each other. Putting the splitViewItem collapse animation onto the main thread seems like the wrong approach and I've got a nagging feeling there's a much better way of doing this that I'm missing.
Since I am not finding any documentation on the NSSplitViewItems anywhere (yet) I would appreciate any insights on this.
I have the little test project on GitHub here if anyone wants a look.
Update The project mentioned has now been updated with the solution.
Thanks,
Teo
The problem is similar to the "don't cross the streams" issue in that there are two drivers to the animation you've created: (1) the split view item (2) the window, and they're not in sync.
In the example from the '13 Cocoa Animations talk, constraints were setup to result in the correct within-window animation as only the window's frame was animated.
Something similar could be tried here -- only animating the window's frame and not the split view item, but since the item manages the constraints used to (un)collapse, the app can't control exactly how within-window content animates:
Instead the split view item animation could completely drive the animation and use NSWindow's -anchorAttributeForOrientation: to describe how the window's frame is affected.
if let splitViewItem = self.splitViewItems[panelID] as? NSSplitViewItem {
let window = self.view.window
if panelID == 0 {
// The Trailing edge of the window is "anchored", alternatively it could be the Right edge
window.setAnchorAttribute(.Trailing, forOrientation:.Horizontal)
}
splitViewItem.animator().collapsed = !splitViewItem.collapsed
}
For anyone using Objective C and targeting 10.11 El Capitan.
This did the trick for me, didn't need to set AnchorAttributes.
splitViewItem.collapsed = YES;

Perl gtk2 window update

Recently when i was writing gtk2 program in perl I've runned into a little problem. I've got a main window which uses variables in labels and buttons to display user some data.
my $label1 = Gtk2::Label->new ("IP ".$target_ip);
my $label2 = Gtk2::Label->new ("Port ".$target_port);
my $label3 = Gtk2::Label->new ("Threads ".$thread_number);
And after updating $target_ip variable (by pop up window) or any other variable used in my main window for that matter by user nothing happens, so my question is how can i update window in Gtk2 i've tried re drawing it by calling window function again but for some reasons the old one still stays up even after issuing Gtk2->main_quit. Also i'm aware this may be a lame question but i'm using Gtk2 library for the first time to write a major project and I'm not really expert in it yet.
Here's my code so far ($ok variable represents ok button in pop up window which updates other variables in main window)
$ok->signal_connect (clicked => sub {
$target_ip = $text_area->get_text;
Gtk2->main_quit; #Pop-up window
main_Gtk()
#Rebuild Attack window with given parameters / variables
#!/usr/bin/perl
use strict;
use warnings;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(300, 200);
my $target_ip = '127.0.0.1';
my $label1 = Gtk2::Label->new ("IP ".$target_ip);
my $vbox = Gtk2::VBox->new(FALSE, 3);
$vbox->pack_start($label1, FALSE, FALSE, 4);
my $button = Gtk2::Button->new("Ok");
$vbox->pack_end($button, FALSE, FALSE, 4);
$button->signal_connect(clicked => sub {
$target_ip = '88.88.88.88';
$label1->set_label("IP ".$target_ip); # That's what you need!!!
});
$window->add($vbox);
$window->show_all;
Gtk2->main();

Powershell: Freezing GUI

Just a quick one. I have a problem with a simple tool that I've created that gets the CPU usage for a set amount of time with a small box that appears to display the % of CPU being used (I've stripped out the GUI for the code below).
function loop
{
$get = read-host
for($start = 0; $start -le 100;$start++)
{
cls
$pro_percentage = Get-WmiObject win32_processor -computer $get -property Loadpercentage | select loadpercentage
$percentage = "Processor usage is: " + $pro_percentage.loadpercentage + "%"
$percentage
}
}
loop
There's a few other bits to the GUI that I've created but I've noticed one majour problem, and this goes for other GUI apps that I have created. Whenever the 'go' button is pressed to start the script from the dialog box, the GUI freezes. The menu bar that I've created inside the GUI freezes and no other button can be pressed.
Am I supposed to run each function in a different thread? Something like that?
Thanks
Try to add:
[System.Windows.Forms.Application]::DoEvents()
in your loop. Quick and dirty, however.

setProgress is no longer updating UIProgressView since iOS 5

I have a little trouble with a progress bar since iOS 5 came out. The code below was working fine before iOS 5 but with iOS 5 the progress bar is no longer displaying the new progress that is set within a loop.
The code is expected to work like this:
Create the progress bar (works)
In a new background process: Set an initial progress of 0.25 (works)
In the same background process: Update the progress while going thru the loop (worked in iOS 4)
Here's the code for the bar init:
// create a progress bar
UIProgressView *progressBar = [[UIProgressView alloc] initWithFrame:CGRectMake(coverSizeX*0.25, coverSizeY - 34.0, coverSizeX*0.5, 9.0)];
progressBar.progress = 0.0;
progressBar.progressViewStyle = UIProgressViewStyleBar;
and in a different thread it sets a starting point for the progress to 0.25:
// set an initial progress
[progressBar setProgress: 0.25];
a little later it is updating the progress within a loop to display the download progress:
// within a for-loop:
NSNumber *counterPercentage;
for ( pageDownload = 1; pageDownload < pagesToDownload; pageDownload++ ) {
counterPercentage = [[NSNumber alloc] initWithFloat: (float)pageDownload / (float)((float)pagesToDownload)];
[progressBar setProgress: [counterPercentage floatValue]];
[progressBar performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
}
… but the progress is not shown on the screen, the progress bar is stuck at the initial 0.25 progress that was set.
Were there any changes with the iOS 5 release that could have broken it?
I've seen a lot of questions like this one since the iOS 5 switch, and I'm not sure why there is a problem only in iOS 5. But mainly because I'm not sure why there wasn't a problem before.
In your code you call [progressBar setProgress: [counterPercentage floatValue]]; from a background thread. This is a UI call and should not be made from a background thread. Also you call setNeedsDisplay which is not necessary to update the progressBar since an UIProgressView knows how to display itself. iOS 5 seems to have made the requirements for updating the UI more stringent, but only to the point of what are best practices anyway.
To my eye this looks like a perfect use for blocks. Using blocks your for loop could be written this way:
for ( pageDownload = 1; pageDownload < pagesToDownload; pageDownload++ ) {
// Other stuff in background
dispatch_async(dispatch_get_main_queue(), ^{
progressBar.progress = ((float)pageDownload/(float)pagesToDownload);
});
// Other stuff in backgroud
}
It does work in iOS 5 and the easiest way to to it is here:
.h file:
IBOutlet UIProgressView *WhateverYouWantToCallIt;
.m file:
[WhateverYouWantToCallIt setProgress:(float) 0.3];
And where it says 0.3, you can put whatever value you like (within 0 to 1)

Resources