Пример #1
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
Пример #2
0
 def test_EmptyParamsKeywoards(self):
     self.assertRaises(
         ValueError, lambda: zroya.init(app_name="",
                                        company_name="",
                                        product_name="",
                                        sub_product="",
                                        version=""))
Пример #3
0
 def test_ProperInitKeywords(self):
     self.assertTrue(
         zroya.init(app_name="a",
                    company_name="b",
                    product_name="c",
                    sub_product="d",
                    version="e"))
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
Пример #5
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)
Пример #6
0
def zroya_init(app_name='Beskar',
               company_name='Ahsoka',
               product_name='Beskar',
               sub_product='main',
               version=__version__) -> bool:
    init = zroya.init(app_name=app_name,
                      company_name=company_name,
                      product_name=product_name,
                      sub_product=sub_product,
                      version=version)
    if init:
        logger.info('Succesfully initialized zroya.')
    else:
        logger.warning('Initializing zroya for toaster notifications failed.')
    return init
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
0
 def test_FewParams(self):
     self.assertRaises(ValueError, lambda: zroya.init("a", "b"))
Пример #12
0
 def test_NoParam(self):
     self.assertRaises(ValueError, lambda: zroya.init())
Пример #13
0
 def test_ProperInit(self):
     self.assertTrue(zroya.init("a", "b", "c", "d", "e"))
Пример #14
0
 def test_EmptyParams(self):
     self.assertRaises(ValueError, lambda: zroya.init("", "", "", "", ""))
Пример #15
0
 def test_FewParamsKeywords(self):
     self.assertRaises(ValueError,
                       lambda: zroya.init(app_name="a", company_name="b"))
Пример #16
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')