How to add dividers to rumps menu

Question:

I have made a python script which creates a MacOS Status bar item which displays youtube statistics.
I want to add dividers to the drop down menu when you click the text but I am unable to do this. (Image of what I mean under the text). I have found many examples but all of them only work with an __init__ function in the class. If I try adding an __init__ function to the class I get an error saying AttributeError: 'Sub_Counter' object has no attribute '_menu'. Why is this happening and how can it be fixed?

Code I added to the __init_ function

self.menu = [
            "About",
            "No Icon",
            None,
            "Detailed Statistics:",
            None,
            "Quit",
            ]

Normal Code without the __init__ function

import rumps
import time
import sys
import os
from sty import fg
from googleapiclient.discovery import build


key = open(os.path.join(sys.path[0], './key.txt')).read().strip()
service = build('youtube', 'v3', developerKey=key)

subs = service.channels().list(
    part='statistics',
    id='UCERizKQbgpBXOck0R6t_--Q'
).execute()['items'][0]['statistics']['subscriberCount']

timers = ["1 secs","5 secs","10 secs","15 secs","20 secs","25 secs","30 secs","35 secs","45 secs","50 secs","1 Min"]

EXEC_TIMER = 60

class Sub_Counter(rumps.App):

    @rumps.timer(EXEC_TIMER)   
    def pull_data(self, _):
        self.sub_menu = timers
        subs = service.channels().list(
            part='statistics',
            id='UCERizKQbgpBXOck0R6t_--Q'
        ).execute()['items'][0]['statistics']['subscriberCount']

        a = (str(subs))
        self.icon = "logo.png"
        self.title = "Subscribers: " + str(a)
        self.notification = str(a) + " Subscribers"

    @rumps.clicked("About")
    def about(self, _=):
        rumps.notification("Youtube Subscriber Count", "Made by Roxiun using Python & rumps", "Shows Youtube Subscriber counts")


    @rumps.clicked("No Icon")
    def noicon(self, sender):
        sender.state = not sender.state
        self.icon = None


    @rumps.clicked("Detailed Statistics")
    def Detailed_Statistics(self, _):
        rumps.notification("You have:", self.notification , "Veiws Comming Soon")

if __name__ == "__main__":
    Sub_Counter("Loading...").run() #debug=True

Image of what I want to do [circled in red – (Yes it is the line)]
Image of the divider line

Thanks in advance!

Asked By: Roxiun

||

Answers:

Fixed by doing

app = Sub_Counter("Loading...")
app.menu[
    "About",
    "No Icon",
    None,
    "Detailed Statistics:",
    None,
    "Quit",
]
app.run()
Answered By: Roxiun

You can add a separator by doing:

self.menu.add(rumps.separator)

Link to source code.

Answered By: ggrelet
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.