Beispiel #1
0
def create_toaster(first_line: str = 'Beskar',
                   second_line: str = 'An update for Beskar is available.',
                   new_version: str = None,
                   third_line: str = None,
                   update_action: bool = True,
                   whats_new: bool = True,
                   toaster_type=zroya.TemplateType.ImageAndText4):
    if zroya_init():
        toaster = zroya.Template(toaster_type)
        toaster.setFirstLine(first_line)
        toaster.setSecondLine(second_line)
        if third_line:
            toaster.setThirdLine(third_line)
        else:
            if new_version is None:
                raise TypeError(
                    'new_version and third_line cannot both be None.')
            else:
                toaster.setThirdLine(f'{__version__} ➡ {new_version}')

        if darkdetect.isDark():
            icon_loc = get_file('beskar-icon-white.png')
        else:
            icon_loc = get_file('beskar-icon.png')
        toaster.setImage(icon_loc)

        if update_action:
            toaster.addAction('Update')
        if whats_new:
            toaster.addAction("What's New?")

        return toaster
Beispiel #2
0
 def __init__(self, acts: Iterable[str] = []):
     if __class__._ is None:
         __class__._ = zroya.init('iHunch Escape No. 1', *APPID.split('.'))
     self._t = zroya.Template(zroya.TemplateType.Text4)
     for act in acts:
         self._t.addAction(act)
     self._nid = None
Beispiel #3
0
    def __init__(self):
        status = zroya.init("GitLFS Auto-Locker", "Your company",
                            "git-lfs-auto-locker", "main",
                            "v0.01")  # TODO: Company from config file
        if not status:
            logging.error("Zroya initialization failed")

        self._template_info = zroya.Template(zroya.TemplateType.Text1)
        self._template_info.setAudio(zroya.Audio.Default,
                                     mode=zroya.AudioMode.Silence)
        self._template_info.setExpiration(
            3600000)  # TODO: Buttons: Force unlock, show all locks

        self._template_warning = zroya.Template(
            zroya.TemplateType.ImageAndText4)

        self._template_error = zroya.Template(zroya.TemplateType.ImageAndText4)
Beispiel #4
0
 def create_notifier(first_line: str, second_line: str, attribution: str,
                     actions: list) -> zroya.Template:
     t = zroya.Template(zroya.TemplateType.Text4)
     t.setFirstLine(first_line)
     t.setSecondLine(second_line)
     t.setAttribution(attribution)
     for action in actions:
         t.addAction(action)
     return t
def notify_user(title, text):

    if sys.platform == 'linux':
        # https://pypi.org/project/py-notifier/#description
        # https://github.com/YuriyLisovskiy/pynotifier
        try:
            from pynotifier import Notification
            Notification(
                title=title,
                description=text,
                duration=5,  # Duration in seconds
                urgency=Notification.URGENCY_NORMAL
            ).send()
        except:
            pass

    elif sys.platform == 'darwin':
        try:
            # https://pypi.org/project/pync/
            import pync
            pync.notify(text, title=title)
        except:
            try:
                # https://stackoverflow.com/questions/17651017/python-post-osx-notification/41318195#41318195
                os.system("""
                osascript -e 'display notification "{}" with title "{}"'
                """.format(text, title))
            except:
                pass

    elif sys.platform.startswith('win'):
        # https://github.com/malja/zroya
        # https://malja.github.io/zroya/
        # https://www.devdungeon.com/content/windows-desktop-notifications-python
        try:
            import zroya
            zroya.init(title, "a", "b", "c", "d")
            t = zroya.Template(zroya.TemplateType.Text1)
            t.setFirstLine(text)
            zroya.show(t)
        except:
            pass
Beispiel #6
0
def notify_zroya():
    def onClick(nid, action_id):
        print("clicked")  # never called

    # Initialize zroya module. Make sure to call this function.
    # All parameters are required
    zroya.init("YourAppName", "CompanyName", "ProductName", "SubProduct",
               "Version")

    # Create notification template. TYPE_TEXT1 means one bold line withou image.
    template = zroya.Template(zroya.TemplateType.Text1)
    # Set first line
    template.setFirstLine("My First line")
    template.setSecondLine("It is nice to meet you.")
    template.setThirdLine("How are you?")

    # Save notification id for later use
    notificationID = zroya.show(template, on_click=onClick)

    sleep(10)

    # Hide notification
    zroya.hide(notificationID)
Beispiel #7
0
    def test_basic_action_handler(self):

        # Make sure zroya is initialized
        status = zroya.init(app_name="a",
                            company_name="b",
                            product_name="c",
                            sub_product="d",
                            version="e")

        self.assertTrue(status)

        # Create a template with two lines of text
        template = zroya.Template(zroya.TemplateType.Text1)

        self.assertIsInstance(template, zroya.Template)

        # Add text to it
        template.setFirstLine("My first line is there")
        template.setSecondLine("My second line is super catchy.")

        # Add actions
        first_action_index = template.addAction("Click me!")
        second_action_index = template.addAction("Don't click me!")

        self.assertEqual(first_action_index, 0)
        self.assertEqual(second_action_index, 1)

        print("Index first index={}, second index={}".format(
            first_action_index, second_action_index))

        # Create a notification with on_action callback attached.
        status = zroya.show(template, on_action=action_handler)

        self.assertTrue(status)

        # Make sure application runs for a while
        time.sleep(5)
Beispiel #8
0
import zroya
import time


def onclick(data):
    print("Onclick event zroya handler {}".format(data))


def ondismiss(data, reason):
    print("Dismiss event zroya handler {}, reason {}".format(data, reason))
    print(reason == zroya.DismissReason.User)


zroya.init("zroya", "a", "b", "c", "d")

t = zroya.Template(zroya.TemplateType.Text1)
t.setFirstLine("Ahoj")

d = zroya.show(t, on_click=onclick, on_dismiss=ondismiss)
print("Status: {}".format(d))

time.sleep(2)
Beispiel #9
0
 def test_setImage_InvalidParams(self):
     template = zroya.Template(zroya.TemplateType.ImageAndText1)
     self.assertRaises(ValueError, lambda: template.setImage(-1))
Beispiel #10
0
def main():
    save_destination, recent_backup_destination = get_save_destination()

    setup_logging(save_destination)

    progress_update('Getting Credentials')
    credentials = get_credentials()
    progress_update('Verified Credentials')
    http = credentials.authorize(httplib2.Http(timeout=30))
    global service
    service = discovery.build('drive', 'v3', http=http)

    user_info = get_user()
    progress_update(
        f"Drive Account: {user_info['user']['displayName']} {user_info['user']['emailAddress']}"
    )

    source_folder = get_source_folder()
    if not source_folder:
        stop_backup()
    progress_update(f"Source Folder: {source_folder['name']}")

    progress_update(f'Backup Type: {flags.backup_type.capitalize()}')

    progress_update(f'Backup files to: {save_destination}')

    start_time = time.time()

    progress_update('Preparing Backup')
    global drive_file_system
    drive_file_system = build_dfsmap(source_folder)

    progress_update('Starting Backup')
    download_progress_update()

    get_folder(save_destination, recent_backup_destination)

    if flags.backup_type != 'complete':
        print()
        progress_update('Cleaning Up Backup')
        clean_backup(save_destination, recent_backup_destination)

    end_time = time.time()
    duration = time.gmtime(end_time - start_time)
    if duration.tm_hour > 0:
        duration_str = time.strftime('%H:%M:%S', duration)
    else:
        duration_str = time.strftime('%M:%S', duration)

    print()
    progress_update(f'Backup Complete! - Duration: {duration_str}')
    logging.shutdown()

    if sys.platform.startswith('win32'):
        import zroya
        zroya.init(APPLICATION_NAME, "GWaters", "Drive-Backup", "Backup",
                   "1.0")
        template = zroya.Template(zroya.TemplateType.ImageAndText2)
        template.setFirstLine(APPLICATION_NAME)
        template.setSecondLine("Drive Backup is complete!")
        template.setImage('drive-backup-icon.png')
        zroya.show(template)
    elif sys.platform.startswith('darwin'):
        import pync
        pync.notify('Drive Backup is complete!',
                    title=APPLICATION_NAME,
                    sender='org.python.python',
                    appIcon='drive-backup-icon.png',
                    sound='default')
Beispiel #11
0
 def test_setExpiration_EmptyParams(self):
     template = zroya.Template(zroya.TemplateType.Text1)
     self.assertRaises(TypeError, lambda: template.setExpiration())
Beispiel #12
0
 def test_setExpiration_InvalidParams(self):
     template = zroya.Template(zroya.TemplateType.Text1)
     self.assertRaises(TypeError, lambda: template.setExpiration("Test"))
Beispiel #13
0
    def test_constructor_EmptyParams(self):

        self.assertRaises(ValueError, lambda: zroya.Template())
Beispiel #14
0
 def test_constructor_InvalidParams2(self):
     self.assertRaises(ValueError, lambda: zroya.Template(50))
Beispiel #15
0
 def test_setImage_FileDoesNotExist(self):
     template = zroya.Template(zroya.TemplateType.ImageAndText1)
     self.assertRaises(FileNotFoundError,
                       lambda: template.setImage("./non_existing_file.png"))
Beispiel #16
0
 def test_ProperParamKeywords(self):
     t = zroya.Template(zroya.TemplateType.Text1)
     notID = zroya.show(t)
     self.assertTrue(zroya.hide(nid=notID))
Beispiel #17
0
 def test_setImage_ProperParams(self):
     template = zroya.Template(zroya.TemplateType.ImageAndText1)
     self.assertTrue(template.setImage("./tests/files/image.png"))
Beispiel #18
0
 def test_getSecondLine_ProperParams(self):
     template = zroya.Template(zroya.TemplateType.Text2)
     template.setFirstLine("Test")
     template.setSecondLine("Test Line 2")
     self.assertEqual(template.getSecondLine(), "Test Line 2")
Beispiel #19
0
 def test_setSecondLine_EmptyParams(self):
     template = zroya.Template(zroya.TemplateType.Text2)
     self.assertRaises(TypeError, lambda: template.setSecondLine())
Beispiel #20
0
 def test_setFirstLine_ProperParams(self):
     template = zroya.Template(zroya.TemplateType.Text1)
     self.assertTrue(template.setFirstLine("Test"))
Beispiel #21
0
 def test_constructor_ProperParams(self):
     self.assertIsInstance(zroya.Template(zroya.TemplateType.Text1),
                           zroya.Template)
Beispiel #22
0
 def test_setImage_EmptyParams(self):
     template = zroya.Template(zroya.TemplateType.ImageAndText1)
     self.assertRaises(TypeError, lambda: template.setImage())
Beispiel #23
0
 def test_setThirdLine_InvalidParams(self):
     template = zroya.Template(zroya.TemplateType.Text4)
     self.assertRaises(TypeError, lambda: template.setThirdLine(-1))
Beispiel #24
0
 def test_getImage_ProperParams(self):
     template = zroya.Template(zroya.TemplateType.ImageAndText1)
     path = os.path.abspath("./tests/files/image.png")
     template.setImage(path)
     self.assertEqual(template.getImage(), path)
Beispiel #25
0
 def test_ProperParam(self):
     t = zroya.Template(zroya.TemplateType.Text1)
     nid = zroya.show(t)
     self.assertTrue(zroya.hide(nid))
Beispiel #26
0
 def test_setThirdLine_ProperParams(self):
     template = zroya.Template(zroya.TemplateType.Text4)
     template.setFirstLine("Test")
     template.setSecondLine("Test2")
     self.assertTrue(template.setThirdLine("Test Line 3"))
Beispiel #27
0
#
# file_name = "session.json"
#
# with open(file_name) as f:
#     session = json.load(f)
# client = Client('*****@*****.**', '01652162621Trung', session_cookies=session)
# user = User("100014564863969")
# user_info = client.fetchUserInfo("100014564863969")["100014564863969"]

# from win32gui import PumpMessages
#
# PumpMessages()
# from selenium import webdriver

import zroya
import time


def send_message(nid, action_id):
    print('Sent')


zroya.init('Python', 'a', 'b', 'c', 'd')
t = zroya.Template(zroya.TemplateType.ImageAndText4)
t.setFirstLine('Hello My Friends')
t.setImage(
    'F:\\LapTrinh\\Python code\\fb_mess_noti\\iconfinder_facebook_313103.ico')
t.addAction("Send")
zroya.show(t, on_action=send_message)
time.sleep(10)
Beispiel #28
0
 def test_getThirdLine_ProperParams(self):
     template = zroya.Template(zroya.TemplateType.Text4)
     template.setThirdLine("Test Line 3")
     self.assertEqual(template.getThirdLine(), "Test Line 3")
Beispiel #29
0
 def test_ProperParams(self):
     t = zroya.Template(zroya.TemplateType.ImageAndText1)
     self.assertIsInstance(zroya.show(t), int)
Beispiel #30
0
 def test_thirdLine_UnsuportedTemplateType(self):
     template = zroya.Template(zroya.TemplateType.Text1)
     self.assertFalse(template.setThirdLine("Test Line 2"))