It is currently April 23rd, 2024, 4:40 pm

Plugin measure value formatting on context menu?

Get help with creating, editing & fixing problems with skins
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Plugin measure value formatting on context menu?

Post by MetalTxus »

I went with the minimal approach and wrote a recycle bin skin which consists in no more than an icon with a context menu (code in the spoiler at the end of the post).

What I would like to achieve now is to add a new context menu option, right below the "empty Bin" one, which listed the count and size of deleted items. So far, I haven't been able to find a working way to format the file size. Is such a feat impossible?

Recycle Bin.ini

Code: Select all

[Metadata]
Version = 1.0
Description = Recycle Bin icon with custom contextual menu
Author = MetalTxus
License = Creative Commons BY-NC 3.0

[Metadata]
Version = 1.0
Description = Recycle Bin icon with custom contextual menu
Author = MetalTxus
License = Creative Commons BY-NC 3.0

[Rainmeter]
Update = 1000
ContextTitle = Open Recycle Bin
ContextAction = [!CommandMeasure MeasureCount "OpenBin"]
ContextTitle2=Empty Recycle Bin
ContextAction2=[!CommandMeasure MeasureCount "EmptyBin"]
ContextTitle3=----
ContextTitle4=[MeasureCount] file(s), [MeasureSize]
ContextAction4=[]
ContextTitle5=Skin Settings
ContextAction5=[!SkinMenu]

[MeasureCount]
Measure = Plugin
Plugin = RecycleManager.dll
RecycleType = Count

IfBelowValue = 1
IfBelowAction = [!SetOption ImageTrash ImageName "#@#icons/Recycle Bin (empty).png"]
IfAboveValue = 0
IfAboveAction = [!SetOption ImageTrash ImageName "#@#icons/Recycle Bin (full).png"]
OnUpdateAction = [!Redraw]

[MeasureSize]
Measure = Plugin
Plugin = RecycleManager.dll
RecycleType = Size

[ImageTrash]
Meter = Image
ImageName = #@#icons/Recycle Bin (full).png
ImageAlpha = 204

LeftMouseUpAction = [!CommandMeasure MeasureCount "OpenBin"]
MiddleMouseUpAction = [!SkinMenu]
RightMouseUpAction = [!SkinCustomMenu]
Last edited by MetalTxus on July 25th, 2017, 2:02 pm, edited 2 times in total.
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Plugin measure value formatting on context menu?

Post by balala »

MetalTxus wrote:What I would like to achieve now is to add a new context menu option, right below the "empty Bin" one, which listed the count and size of deleted items. So far, I haven't been able to find a working way to format the file size. Is such a feat impossible?
I don't think it would be, just have to add the appropriate bang(s) to the ContextAction4 option. You can't leave empty this option. So, replace the ContextAction4=[] option, with for example ContextAction4=[!CommandMeasure MeasureCount "OpenBin"] (or obviously with anything else you want to do with this menu).
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Plugin measure value formatting on context menu?

Post by jsmorley »

Code: Select all

[Rainmeter]
Update = 1000
ContextTitle = Open Recycle Bin
ContextAction = [!CommandMeasure MeasureCount "OpenBin"]
ContextTitle2=Empty Recycle Bin
ContextAction2=[!CommandMeasure MeasureCount "EmptyBin"]
ContextTitle3=----
ContextTitle4=Size:	[MeasureSize:/1048576,1] MB
ContextAction4=[]
ContextTitle5=Count:	[MeasureCount:]
ContextAction5=[]
ContextTitle6=----
ContextTitle7=Skin Settings
ContextAction7=[!SkinMenu]
https://docs.rainmeter.net/manual-beta/variables/section-variables/#Scale
https://docs.rainmeter.net/manual-beta/variables/section-variables/#Decimals
1.png
You do not have the required permissions to view the files attached to this post.
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Re: Plugin measure value formatting on context menu?

Post by MetalTxus »

jsmorley wrote: ContextTitle4=Size: [MeasureSize:/1048576,1] MB
ContextAction4=[]
Kind of works, but not really. It's better than nothing, but it wouldn't be much informative in case the trash contained many gigabytes worth of data.
Image

Could IfBelowValue and IfAboveValue be used to apply either MB or GB formatting?
Edit: I've tried to but then the option text remains static.
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Plugin measure value formatting on context menu?

Post by jsmorley »

That is a little trickier to get "autoscale" into it, but not impossible...

Code: Select all

[Rainmeter]
Update = 1000
ContextTitle = Open Recycle Bin
ContextAction = [!CommandMeasure MeasureCount "OpenBin"]
ContextTitle2=Empty Recycle Bin
ContextAction2=[!CommandMeasure MeasureCount "EmptyBin"]
ContextTitle3=----
ContextTitle4=Size:	[MeasureBinScale:] [MeasureBinScalePostfix]
ContextAction4=[]
ContextTitle5=Count:	[MeasureCount:]
ContextAction5=[]
ContextTitle6=----
ContextTitle7=Skin Settings
ContextAction7=[!SkinMenu]

...

[MeasureBinScale]
Measure=Calc
Formula=((( MeasureSize / ( 1024 ** 3 )) >= 1 ) ? ( Round ( MeasureSize / ( 1024 ** 3 ),1)) : ((( MeasureSize / ( 1024 ** 2 )) >= 1 ) ? ( Round ( MeasureSize / ( 1024 ** 2 ),1)) : ((( MeasureSize / 1024 ) >= 1 ) ? ( Round ( MeasureSize / 1024,1 )) : MeasureSize )))

[MeasureBinScalePostfix]
Measure=Calc
Formula=((( MeasureSize / ( 1024 ** 3 )) >= 1 ) ? 3 : ((( MeasureSize / ( 1024 ** 2 )) >= 1 ) ? 2 : ((( MeasureSize / 1024 ) >= 1 ) ? 1 : 0 )))
Substitute="0":"B","1":"kB","2":"MB","3":"GB"
1.png
2.png
https://docs.rainmeter.net/manual-beta/formulas/#Formulas
https://docs.rainmeter.net/manual-beta/formulas/#Conditional
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Plugin measure value formatting on context menu?

Post by jsmorley »

Another approach, one that is probably a bit simpler to understand, is:

Code: Select all

[Rainmeter]
Update = 1000
ContextTitle = Open Recycle Bin
ContextAction = [!CommandMeasure MeasureCount "OpenBin"]
ContextTitle2=Empty Recycle Bin
ContextAction2=[!CommandMeasure MeasureCount "EmptyBin"]
ContextTitle3=----
ContextTitle4=Size:	[ContextFormat]
ContextAction4=[]
ContextTitle5=Count:	[MeasureCount:]
ContextAction5=[]
ContextTitle6=----
ContextTitle7=Skin Settings
ContextAction7=[!SkinMenu]


[MeasureSize]
Measure = Plugin
Plugin = RecycleManager.dll
RecycleType = Size
IfCondition=MeasureSize < 1024
IfTrueAction=[!SetOption ContextFormat String "Size [MeasureSize:] B"]
IfCondition2=MeasureSize >= 1024
IfTrueAction2=[!SetOption ContextFormat String "Size [MeasureSize:/1024,1] kB"]
IfCondition3=MeasureSize >= (1024 ** 2)
IfTrueAction3=[!SetOption ContextFormat String "Size [MeasureSize:/1048576,1] MB"]
IfCondition4=MeasureSize >= (1024 ** 3)
IfTrueAction4=[!SetOption ContextFormat String "Size [MeasureSize:/1073741824,1] GB"]

[ContextFormat]
Measure=String
String=[MeasureSize:] B
1.png
You do not have the required permissions to view the files attached to this post.
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Re: Plugin measure value formatting on context menu?

Post by MetalTxus »

I've actually been spending this last half an hour trying to implement your first solution, which I did in fact understand and actually prefer.

The formatting works as expected, but I have the issue that the values don't update. It always displays 2 files, 1.7 GB; no matter how many files I have on the bin nor their sizes and I can't even start to figure out why.

EDIT: What's the difference between using [MeasureCount:] and using [MeasureCount]? I've tried both and noticed none.
EDIT2: It seems it only refreshes when the total size is >= 1GB.
EDIT3: This keeps getting weirder. It always refreshes when the size is 0 but if the size unit gets to GB and drops to MB it doesn't refresh. If then I empty the bin and delete something smaller than 1 GB, then it refreshes and displays the MB. If I then delete something >= 1GB, it refreshes. If I delete from the bin the >= 1GB file, then it still displays 2 files, 1.7 GB.

Recycle Bin.ini

Code: Select all

[Metadata]
Version = 1.0
Description = Recycle Bin icon with custom contextual menu
Author = MetalTxus
License = Creative Commons BY-NC 3.0

[Rainmeter]
Update = 1000
ContextTitle = Open Recycle Bin
ContextAction = [!CommandMeasure MeasureCount "OpenBin"]
ContextTitle2 = Empty Recycle Bin
ContextAction2 = [!CommandMeasure MeasureCount "EmptyBin"]
ContextTitle3 = ----
ContextTitle4 = [MeasureCount] file(s), [MeasureFormattedSize] [MeasureSizeUnit]
ContextAction4 = []
ContextTitle5 = ----
ContextTitle6 = Skin Settings
ContextAction6 = [!SkinMenu]

[MeasureCount]
Measure = Plugin
Plugin = RecycleManager.dll
RecycleType = Count

IfBelowValue = 1
IfBelowAction = [!SetOption ImageTrash ImageName "#@#icons/Recycle Bin (empty).png"]
IfAboveValue = 0
IfAboveAction = [!SetOption ImageTrash ImageName "#@#icons/Recycle Bin (full).png"]
OnUpdateAction = [!Redraw]

[MeasureSize]
Measure = Plugin
Plugin = RecycleManager.dll
RecycleType = Size

[MeasureFormattedSize]
Measure = Calc
Formula = ((( MeasureSize / ( 1024 ** 3 )) >= 1 ) ? ( Round ( MeasureSize / ( 1024 ** 3 ),1)) : ((( MeasureSize / ( 1024 ** 2 )) >= 1 ) ? ( Round ( MeasureSize / ( 1024 ** 2 ),1)) : ((( MeasureSize / 1024 ) >= 1 ) ? ( Round ( MeasureSize / 1024,1 )) : MeasureSize )))

[MeasureSizeUnit]
Measure = Calc
Formula = ((( MeasureSize / ( 1024 ** 3 )) >= 1 ) ? 3 : ((( MeasureSize / ( 1024 ** 2 )) >= 1 ) ? 2 : ((( MeasureSize / 1024 ) >= 1 ) ? 1 : 0 )))
Substitute = "0":"B", "1":"kB", "2":"MB", "3":"GB"

[ImageBackground]
Meter = Image
W = 64
H = 64
SolidColor = 0, 0, 0, 1

LeftMouseUpAction = [!CommandMeasure MeasureCount "OpenBin"]
RightMouseUpAction = [!SkinCustomMenu]

[ImageTrash]
Meter = Image
ImageName = #@#icons/Recycle Bin (full).png
ImageAlpha = 204
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Plugin measure value formatting on context menu?

Post by jsmorley »

No idea what you are seeing. The values used in a custom context menu are always dynamic, and are updated at the time you open the context menu. They won't update while the menu is open, but if you close it and open it again, they should have the current value.
User avatar
MetalTxus
Posts: 46
Joined: October 19th, 2016, 9:03 pm
Location: Spain

Re: Plugin measure value formatting on context menu?

Post by MetalTxus »

jsmorley wrote:No idea what you are seeing. The values used in a custom context menu are always dynamic, and are updated at the time you open the context menu. They won't update while the menu is open, but if you close it and open it again, they should have the current value.
I understand this is not logical but I am afraid this is no temporal issue. I tried refreshing al skins and even restarting the computer, but the issue persists. Once the bin size is shown in GB, it will no longer be shown in MB and will keep showing the previous outdated values until the bin is emptied. It refreshes without any issues when the displayed units don't change and when changing from MB to GB, but not backwards. Nothing is outputted to the log either, so I have already given up on solving it on my own.
Image
• GitHub | • DeviantArt
OS: W10 x64 / GPU: GTX 1050 Ti / CPU: i3-4160 / RAM: 8GB
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Plugin measure value formatting on context menu?

Post by jsmorley »

I believe the issue is a known "feature" of the Recycle plugin. If you "add" things to the recycle bin, that will trigger a re-evaluation of the size of the contents. However, if you "remove" ("restore") stuff without fully emptying the bin, it is my understanding that that won't trigger it to see the change. The root cause of this is due to the fact that the API calls we use to measure the recycle bin are VERY CPU intensive when they are monitoring to detect a reduction in the contents.

I'm not an expert in the code, but my understanding is that the act of "adding to" or "emptying" the bin in Windows sends a "signal" that the action was done, and our code can react to that. Just "restoring" some files from the bin sends no "signal", and so you end up having to constantly "poll" the bin to catch those changes.

So if you "add" stuff, it will see it right away. If you "empty" the bin, it will see it right away. However, if you "restore" stuff, that won't be seen unless you refresh the skin. (or again "add" something)

The way most humans use the recycle bin is to delete stuff as they need, and at some point, presumably often, but that varies by person, they will right click and empty the bin. We decided that given that, not having the plugin using a ton of CPU watching for the off chance that the size or count reduces, was the right thing to do. As the amount in the bin increases, watching for it to get smaller is a HUGE CPU hit. The way we have it working, the CPU usage of it it pretty much rounds to zero.

The times you left click and "restore" things from out of the bin are pretty rare. That would pretty much only be when you go "Ooops! Oh crap, I didn't mean to delete that!"