Re: [pysystray-users] @systray.threaded Error when running sample.py
Status: Beta
Brought to you by:
essiene
From: Sajjad H. <shu...@ya...> - 2006-05-29 21:25:15
|
Hi, I replaced the original bases.py with the one you sent me. I commented out #@systray.threaded in sample.py. However now I am getting this error: [/cygdrive/c/design/Miscellaneous/Taskbar/ pysystray-sample-0.6.1]: python sample.py Traceback (most recent call last): File "sample.py", line 2, in ? from systray import systray File "C:\Python23\Lib\site-packages\systray\systray.py", line 13, in ? import bases File "C:\Python23\lib\site-packages\systray\bases.py", line 177 if _is_supported_version(): ^ SyntaxError: invalid syntax Also the line to be executed if the if statement is true is: @utils.threaded I don't want to play around with bases.py just because I know that I will most likely break it. I hope you would be able to send me another bases.py. Regards, Sajjad --- Essien Ita Essien <es...@da...> wrote: > Sajjad Hussain wrote: > > Hi, > > > > All of my company's software is written with > version > > 2.3.3. So it is very important that any tool, > script > > we write must be consistent with that version. I > don't > > want to break (not a likely chance) any of my code > by > > switching version. Anyways, is there a work around > to > > this problem? It would really shorten my work if I > > integrate pysystray in my project. > > > Hmmm... I've coded this quick 'untested' workaround. > I'm currently not > working from Windows so I don't know if this works. > The idea, is to check sys.version and if its less > than 2.4, I > conditionally define _start_control() to use or not > use the threading > decorator. Its a dirty hack. > > Replace your bases.py with the attached bases.py and > see if that solves > it. You won't for now be able to use the > @systray.threaded decorator > too, so you can comment that out of the sample. > Also, using App.start() > will *block* and won't return till the function > finishes, since it isn't > threaded *anymore* due to this hack. I guess my > *unvoiced* advice is > that you should attempt migrating to 2.4 (it's going > to be a pain to > keep this in sync with 2.3, since i don't use it > anymore, I wouldn't > know when I break it :( ) > > First though, let me know if this works. > > cheers, > Essien > > > > Regards, > > > > Sajjad > > > > --- Essien Ita Essien <es...@da...> > wrote: > > > > > >> Hi, > >> > >> Sorry for replying late... just came back from a > >> loooong weekend (public > >> holiday here :D) > >> > >> Sajjad Hussain wrote: > >> > >>> Hi everyone, > >>> > >>> I have just installed systray-0.6.1.win32.exe on > >>> > >> my > >> > >>> PythonWin 2.3.3. I downloaded > >>> pysystray-sample-0.6.1.zip, unzipped it and > tried > >>> running sample.py. I am getting this error: > >>> > >>> [/cygdrive/c/design/Miscellaneous/ > >>> Taskbar/pysystray-sample-0.6.1]: python > sample.py > >>> > >>> File "sample.py", line 17 > >>> @systray.threaded > >>> ^ > >>> SyntaxError: invalid syntax > >>> > >>> > >> Hmmm... it seems Python 2.3 doesn't support > >> decorators (that's the > >> syntax for decorators)? You should use Python 2.4 > or > >> newer. Any reason > >> you're using 2.3? > >> > >> Cheers, > >> Essien > >> > >> > >> > >> > > > ------------------------------------------------------- > > > >> All the advantages of Linux Managed > Hosting--Without > >> the Cost and Risk! > >> Fully trained technicians. The highest number of > Red > >> Hat certifications in > >> the hosting industry. Fanatical Support. Click to > >> learn more > >> > >> > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642 > > > >> _______________________________________________ > >> pysystray-users mailing list > >> pys...@li... > >> > >> > > > https://lists.sourceforge.net/lists/listinfo/pysystray-users > > > > > > > > __________________________________________________ > > Do You Yahoo!? > > Tired of spam? Yahoo! Mail has the best spam > protection around > > http://mail.yahoo.com > > > > > > > ------------------------------------------------------- > > All the advantages of Linux Managed > Hosting--Without the Cost and Risk! > > Fully trained technicians. The highest number of > Red Hat certifications in > > the hosting industry. Fanatical Support. Click to > learn more > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642 > > _______________________________________________ > > pysystray-users mailing list > > pys...@li... > > > https://lists.sourceforge.net/lists/listinfo/pysystray-users > > > > > import sys > import win32gui > import win32con > import thread > import SysTrayIcon > > import menu > import utils > > __all__ = ['AppBase'] > > > def _is_supported_version(): > supported_version = 2.4 > current_version = > float(sys.version.split()[0][:-2]) > if current_version >= supported_version: > return True > else: > return False > > > class _App(SysTrayIcon.SysTrayIcon): > ''' Inherits SysTrayIcon and adds usefull > properties and extentions ''' > > #TODO: add support for pop up notifier window > def __init__(self, title, icon, menu, > on_load=None, on_quit=None, on_double_click=None): > > self.title = title > self.menu = menu > self.on_double_click = on_double_click > SysTrayIcon.SysTrayIcon.__init__(self, icon, > self.title, > self.menu.get_tuple(), on_load, on_quit, > self.title, behave_traditional=False) #using > self.title as windows_class_name > self.visible = True > self.alive = True > > > def do_onload(self): > win32gui.SendMessage(self.hwnd, > self.WM_ONLOAD, self._get_quit_id(), > win32con.WM_LBUTTONUP) > > def quit(self): > win32gui.SendMessage(self.hwnd, > win32con.WM_COMMAND, self._get_quit_id(), > win32con.WM_LBUTTONUP) > self.visible = False > > def _get_quit_id(self): > for k, v in self.menu_actions_by_id.items(): > if v == self.QUIT: > return k > > def show_menu(self): > #print "showing menu" > self._prepare_menu(self.menu.get_tuple(), 0) > menu = win32gui.CreatePopupMenu() > self.create_menu(menu, self.menu_options) > #win32gui.SetMenuDefaultItem(menu, 1000, 0) > > pos = win32gui.GetCursorPos() > # See > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp > win32gui.SetForegroundWindow(self.hwnd) > win32gui.TrackPopupMenu(menu, > > win32con.TPM_LEFTALIGN, > pos[0], > pos[1], > 0, > self.hwnd, > None) > win32gui.PostMessage(self.hwnd, > win32con.WM_NULL, 0, 0) > > def show_tooltip(self, title, text, timeout=1, > icon=win32gui.NIIF_INFO): > if self.visible: > > self.notify_icon.show_balloon_tooltip(title, text, > icon, timeout) > > def show(self): > if not self.visible: > self.notify_icon.show() > self.visible = True > > def hide(self): > if self.visible: > # nid = (self.hwnd, 0) > # > win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid) > self.notify_icon.hide() > self.visible = False > > #overloaded message handler for WM_DESTROY > def destroy(self, hwnd, msg, wparam, lparam): > if self.on_quit: self.on_quit(self) > self.hide() > win32gui.PostQuitMessage(0) # Terminate the > app. > self.alive = False > > def notify(self, hwnd, msg, wparam, lparam): > if lparam==win32con.WM_LBUTTONDBLCLK: > #allow setting custom dbclick callback > if callable(self.on_double_click): > self.on_double_click(self) > > #self.execute_menu_option(self.default_menu_index + > self.FIRST_ID) > pass > elif lparam==win32con.WM_RBUTTONUP: > self.show_menu() > elif lparam==win32con.WM_LBUTTONUP: > pass > return True > > > def __set_text(self, s): > self.hover_text = s > self.refresh_icon() > > def __get_text(self): > return self.hover_text > > text = property(__get_text, __set_text, None, > "Text Shown On Mouse Hover") > > def __set_icon(self, s): > self._icon = s > self.refresh_icon() > > def __get_icon(self): > return self._icon > > icon = property(__get_icon, __set_icon, None, > "The Icon Shown on the tool bar") > > #TODO: make this guy pop up like Yahoo, but > semitransparent and cool like outlook messages > def set_status(self, message=None, icon=None): > if message is not None: > self.text = self.title + ' - ' + > str(message) > > if icon is not None: > try: > self.icon = icon > except: > #do nothing just let it go for now > #TODO: Raise and _App.Error('Invalid > Icon File') > pass > > def show_info(self, message): > #win32gui.MessageBox(self.hwnd, > str(message), self.title, > win32con.MB_ICONINFORMATION) > self.show_tooltip(self.title, str(message), > icon=win32gui.NIIF_INFO) > > def show_warning(self, message): > self.show_alert(message) > > #TODO: Deprecate This > def show_alert(self, message): > #win32gui.MessageBox(self.hwnd, > str(message), self.title, win32con.MB_ICONERROR) > self.show_tooltip(self.title, str(message), > icon=win32gui.NIIF_WARNING) > > def show_error(self, message): > self.show_tooltip(self.title, str(message), > icon=win32gui.NIIF_ERROR) > > def show_message(self, message): > self.show_tooltip(self.title, str(message), > icon=win32gui.NIIF_NONE) > > > > class AppBase(object): > ''' Creates an instance of a System Tray > Application. Call start() to run it ''' > > def __init__(self, title, icon=None): > self.icon = icon > self.title = title > self._on_quit = utils.DEFAULT_HANDLER > self._on_load = utils.DEFAULT_HANDLER > self._on_double_click = > utils.DEFAULT_HANDLER > self.menu = [] > self.nmenu = menu.MenuRoot() > #self.systray = _App(title, icon, tuple([])) > === message truncated === __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |