Python Forum
Can anyone make sense of this?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can anyone make sense of this?
#1
I am a bit of a fan of the infi-systray module:
https://github.com/Infinidat/infi.systray

I have made 3 simple Windows apps so far.
Heres one of them: https://stevepython.wordpress.com/2020/0...older-sync

One of the downsides with the module is a lack of clear documentation,
not being cross platform, and little things like some of the commands
not working at all as described in the doc, systray.shutdown for example.

One of the more simple things that really need doing is to allow proper separator bars
in the systray menus. At the moment users have to use dashes or underscores, it looks crap.

In the github issues someone asked about this and the author says he has no spare time
to work on it. When I begged he posted this bit of "code" that is tottaly gobbledegook
to me.
https://github.com/Infinidat/infi.systray/issues/20
diff --git a/src/infi/systray/win32_adapter.py b/src/infi/systray/win32_adapter.py
index 1b9a9ef..ba4c37e 100755
--- a/src/infi/systray/win32_adapter.py
+++ b/src/infi/systray/win32_adapter.py
@@ -70,6 +70,7 @@ SM_CXSMICON = 49
 SM_CYSMICON = 50
 COLOR_MENU = 4
 DI_NORMAL = 3
+MFT_SEPARATOR = 0x00000800
 
 WPARAM = ctypes.wintypes.WPARAM
 LPARAM = ctypes.wintypes.LPARAM
@@ -148,6 +149,9 @@ class NOTIFYICONDATA(ctypes.Structure):
 def PackMENUITEMINFO(text=None, hbmpItem=None, wID=None, hSubMenu=None):
     res = MENUITEMINFO()
     res.cbSize = ctypes.sizeof(res)
+    if text == "-----":
+        res.fType = MFT_SEPARATOR
+        return res
     res.fMask = 0
     if hbmpItem is not None:
         res.fMask |= MIIM_BITMAP
Can anyone sort this into a simple function for me
because I can't and the author has not replied after a week
of me asking him to simplfy it.

I appreciate the author has moved on and is busy. I am not having a dig at him.


Steve.
Reply
#2
This is a "diff" file. The lines starting with + should be added to your copy of the win32_adapter.py file.

There are 4 lines in 2 sections that you need to add. The first section is near line 70, the second section is near line 148.
Reply
#3
Oh wow thanks for helping me on this I was totally lost, I will try this out. thanks.

(Apr-19-2020, 05:36 AM)bowlofred Wrote: This is a "diff" file. The lines starting with + should be added to your copy of the win32_adapter.py file.

There are 4 lines in 2 sections that you need to add. The first section is near line 70, the second section is near line 148.
Reply
#4
You can likely use git apply to apply the patch.
Reply
#5
I get this error:
File "C:\Python367\lib\site-packages\infi\systray\win32_adapter.py", line 152,
in PackMENUITEMINFO
res.fType = MFT_SEPARATOR
UnboundLocalError: local variable 'res' referenced before assignment

I have tried adding res = 0 at the start of the def and rse.ftype = 0,
same error.

I think I have the +++ code in the correct places according to the diff file.

SM_CXSMICON = 49
SM_CYSMICON = 50
COLOR_MENU = 4
DI_NORMAL = 3
MFT_SEPARATOR = 0x00000800
#etc
def PackMENUITEMINFO(text=None, hbmpItem=None, wID=None, hSubMenu=None):
    res = MENUITEMINFO()
    res.cbSize = ctypes.sizeof(res)
    
    if text == "-----":
        res.fType = MFT_SEPARATOR
        return res
    
    res.fMask = 0

#etc.
I only get the error if I have the 5 dashes as a separator "-----".
If I remove them or make a different amount the code runs without error.


Any idea what I have done wrong?

I will look into ndc85430 advice next, but
I haven't a clue how to do that either yet ;-)

Okay I have it working. I 'm not sure what I messed up earlier
but I did it right this time.

Many thanks for your help guys.
[Image: seperators.png]
So much better.
Reply
#6
Please excuse my ignorance about github, this is all quite confusing
for an old man.

I have "forked" infi-systray
replaced the changed file as above to support separators.

Do I now submit a "pull request" so
that the author can update the package?

Is that how it works?
Reply
#7
(Apr-19-2020, 10:45 AM)steve_shambles Wrote: Do I now submit a "pull request" so that the author can update the package?

Normally - yes, you can make a pull request and maintainer can review and merge your pull request.

Given their comment this is quick-and_dirty patch and that they don't have time to implement it properly as well as they provide you with diff file (i.e. they probably made the change locally, and produce the diff file, but didn't push to remote) they will probably not accept and merge your pull request. If they wanted, they can push their own change. Note there are 3 pull requests (of which 2 are 2-years old and they are neither merged nor rejected.)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
Okay that makes sense, thanks for the advice Buran.


(Apr-19-2020, 10:45 AM)steve_shambles Wrote: Please excuse my ignorance about github, this is all quite confusing
for an old man.

I have "forked" infi-systray
replaced the changed file as above to support separators.

Do I now submit a "pull request" so
that the author can update the package?

Is that how it works?

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Re writing poste to make sense please help me Nearrivers 10 5,707 Apr-02-2018, 11:52 PM
Last Post: Nearrivers
  These boolean statements don't make sense? Athenaeum 6 5,076 Oct-03-2017, 03:34 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020