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
def notify(self, line1: str, line2: str, attr: Optional[str] = None, on_click: Optional[Callable] = None, on_action: Optional[Callable] = None, on_dismiss: Optional[Callable] = None, on_fail: Optional[Callable] = None) -> None: self._t.setFirstLine(line1) self._t.setSecondLine(line2) if attr is not None: self._t.setAttribution(attr) self._nid = zroya.show(self._t, on_click, on_action, on_dismiss, on_fail)
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)
def show(toaster, update_checker: 'UpdateChecker', setup_exe_filename: str, on_action: Callable = on_toaster_interaction, on_dismiss: Callable = None, on_fail: Callable = None) -> Union[bool, int]: on_action_partial = functools.partial(on_action, setup_exe=setup_exe_filename, update_checker=update_checker) kwargs = { 'on_action': on_action_partial, 'on_click': functools.partial(on_action_partial, action_id=0) } if on_dismiss: kwargs['on_dismiss'] = on_dismiss if on_fail: kwargs['on_fail'] = on_fail toaster_id = zroya.show(toaster, **kwargs) if isinstance(toaster_id, int): toasters.append(toaster_id) return toaster_id
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)
def test_ProperParams(self): t = zroya.Template(zroya.TemplateType.ImageAndText1) self.assertIsInstance(zroya.show(t), int)
def test_BadType(self): self.assertRaises(ValueError, lambda: zroya.show(None))
def test_FewParams(self): self.assertRaises(TypeError, lambda: zroya.show(on_click=on_click))
def test_NoParam(self): self.assertRaises(TypeError, lambda: zroya.show())
def show_warning(self, message) -> None: self._template_warning.setFirstLine(message) zroya.show(self._template_warning)
# # 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)
def test_ProperParamKeywords(self): t = zroya.Template(zroya.TemplateType.Text1) notID = zroya.show(t) self.assertTrue(zroya.hide(nid=notID))
def test_ProperParam(self): t = zroya.Template(zroya.TemplateType.Text1) nid = zroya.show(t) self.assertTrue(zroya.hide(nid))
def show_info(self, message) -> None: self._template_info.setFirstLine(message) zroya.show(self._template_info)
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)
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')
def show_error(self, message) -> None: self._template_error.setFirstLine(message) zroya.show(self._template_error)