Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1025144 // Process CPU % + (Host) Tray Icon

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (7097L/38K).

!7

cmodule ProcessCPUTrayIcon > DynBigNumber {
  transient BufferedImage trayImage;
  transient TrayIcon trayIcon; 
  
  switchable S color = "ADFF2F"; // green yellow
  switchable S backgroundColor = "228B22"; // forest green
  switchable int size = goodSystemTrayIconSize().x;
  switchable double interval = 1;
  
  transient double loadRelativeToAllCores, recentLoad;
  transient RollingAverage avg = new(5); // =10 seconds
  
  start {
    setDescription("STEFAN'S OS CPU %");
    setToolTip("Percentage is per core (total: " + numberOfCores()*100 + "%)");
    doEvery(interval, r actualUpdate);
    ownResource(tempTrayIcon(trayIcon = installTrayIcon(
      trayImage = newBufferedImage(size, size, colorFromHex(backgroundColor)), "Stefan's OS CPU", rThread dm_activateOSAndModule)));
  }
  
  void actualUpdate {
    recentLoad = processCPULoad();
    avg.add(recentLoad);
    loadRelativeToAllCores = avg!;
    setValue(toIntPercent_ceil(loadRelativeToAllCores*numberOfCores()) + " %");
    int w = trayImage.getWidth(), h = trayImage.getHeight();
    copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h);
    int y = iround((h-1)*(1 - loadRelativeToAllCores));
    fillRect(trayImage, w-1, 0, 1, y, colorFromHex(backgroundColor));
    fillRect(trayImage, w-1, y, 1, h-y, colorFromHex(color));
    setTrayIconImage(trayIcon, trayImage);
  }
}

Author comment

Began life as a copy of #1020927

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1025144
Snippet name: Process CPU % + (Host) Tray Icon
Eternal ID of this version: #1025144/9
Text MD5: 48a9aa4f5a450dfe2541efae684171f0
Transpilation MD5: 260480cf7fb7d1ec004b428cc4679921
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-04 12:19:46
Source code size: 1387 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 211 / 45637
Version history: 8 change(s)
Referenced in: