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

63
LINES

< > BotCompany Repo | #1026796 // Combined Process+System 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 (7967L/41K).

1  
!7
2  
3  
cmodule CombinedCPUTrayIcon > DynBigNumber {
4  
  transient BufferedImage trayImage;
5  
  transient TrayIcon trayIcon; 
6  
  
7  
  switchable S processColor = "ADFF2F"; // green yellow
8  
  switchable S restColor = "6666FF";
9  
  switchable S backgroundColor = "000000";
10  
  switchable int size = goodSystemTrayIconSize().x;
11  
  switchable double interval = 1;
12  
  switchable bool postToServer;
13  
  
14  
  transient double systemLoad;
15  
  transient int systemPercent;
16  
  
17  
  // these are for the process
18  
  transient double loadRelativeToAllCores, recentLoad;
19  
  transient RollingAverage avg = new(5); // =10 seconds
20  
  
21  
  start {
22  
    setDescription("STEFAN'S OS/SYSTEM CPU %");
23  
    setToolTip("Percentage is per core (total: " + numberOfCores()*100 + "%)");
24  
    doEvery(interval, r actualUpdate);
25  
    ownResource(tempTrayIcon(trayIcon = installTrayIcon(
26  
      trayImage = newBufferedImage(size, size, colorFromHex(backgroundColor)),
27  
      "Stefan's OS + System CPU (" + nCores(numberOfCores()) + ")",
28  
      rThread dm_activateOSAndModule)));
29  
    dm_registerAs_direct combinedCPUTrayIcon();
30  
  }
31  
  
32  
  void grabSystemLoad {
33  
    systemLoad = systemCPULoad();
34  
    systemPercent = toIntPercent_ceil(systemLoad*numberOfCores());
35  
    
36  
    if (postToServer)
37  
      dm_postCPULoadToServer(systemPercent);
38  
  }
39  
  
40  
  void actualUpdate {
41  
    grabSystemLoad();
42  
    recentLoad = processCPULoad();
43  
    avg.add(recentLoad);
44  
    loadRelativeToAllCores = avg!;
45  
    setValue(
46  
      toIntPercent_ceil(loadRelativeToAllCores*numberOfCores()) + " / " +
47  
      systemPercent + " %");
48  
49  
    int w = trayImage.getWidth(), h = trayImage.getHeight();
50  
    copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h);
51  
    int y1 = iround(h*(1 - loadRelativeToAllCores));
52  
    int y2 = min(y1, iround(h*(1 - systemLoad)));
53  
    fillRect(trayImage, w-1, 0, 1, y2, colorFromHex(backgroundColor));
54  
    fillRect(trayImage, w-1, y2, 1, y1-y2, colorFromHex(restColor));
55  
    fillRect(trayImage, w-1, y1, 1, h-y1, colorFromHex(processColor));
56  
    setTrayIconImage(trayIcon, trayImage);
57  
    vmBus_send newCombinedCPUTrayImage(module(), trayImage);
58  
  }
59  
  
60  
  // API
61  
  
62  
  BufferedImage getImage() { ret trayImage; }
63  
}

Author comment

Began life as a copy of #1020927

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xkfnxevppnqj, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026796
Snippet name: Combined Process+System CPU % Host Tray Icon
Eternal ID of this version: #1026796/13
Text MD5: 4e8b140d742cd958f1b9d3cce1ad8ed7
Transpilation MD5: c913c7a1451ecc37b1d92aeae833695d
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-28 01:48:57
Source code size: 2194 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 229 / 257947
Version history: 12 change(s)
Referenced in: [show references]