Changeset 91 for pykoticon

Show
Ignore:
Timestamp:
01/27/06 00:08:36 (18 years ago)
Author:
jerome
Message:

Confirmation dialog seems to work fine.

Location:
pykoticon/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykoticon/trunk/bin/pykoticon

    r89 r91  
    8989        return True 
    9090         
    91     def export_openDialog(self) :     
    92         """Opens a dialog to ask username, password, etc...""" 
    93         self.logDebug("Open dialog !") 
    94         return ("jerome", "blah") 
     91    def export_openConfirmDialog(self, printername, username, jobid, jobtitle, jobsize) :     
     92        """Opens a dialog to ask the user to confirm or cancel the print job. 
     93         
     94           Returns True to confirm, False to cancel. 
     95        """    
     96        wx.CallAfter(self.frame.askConfirmation, printername, username, jobid, jobtitle, jobsize) 
     97        while self.frame.askConfirmationResult is None : 
     98            time.sleep(0.5) 
     99        retcode = self.frame.askConfirmationResult     
     100        self.frame.askConfirmationResult = None 
     101        return retcode 
    95102         
    96103    def export_nop(self) :     
     
    116123    def mainloop(self) : 
    117124        """XML-RPC Server's main loop.""" 
    118         self.register_function(self.export_openDialog) 
     125        self.register_function(self.export_openConfirmDialog) 
    119126        self.register_function(self.export_quitApplication) 
    120127        self.register_function(self.export_nop) 
     
    134141    """Main class.""" 
    135142    def __init__(self, parent, id): 
    136         wx.Frame.__init__(self, parent, -1, \ 
     143        self.askConfirmationResult = None 
     144        self.closing = False 
     145        wx.Frame.__init__(self, parent, wx.ID_ANY, \ 
    137146               _("PyKota for user %s") % getCurrentUserName(), \ 
    138147               size = (-1, -1), \ 
     
    140149                     | wxPython.wx.wxSIZE_AUTO_HEIGHT \ 
    141150                     | wxPython.wx.wxSIZE_AUTO_WIDTH \ 
    142                      | wxPython.wx.wxICONIZE \ 
    143151                     | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 
    144         try :              
    145             self.tbicon = wxPython.wx.wxTaskBarIcon() 
    146         except AttributeError :     
    147             self.tbicon = None # No taskbar icon facility, old wxWidgets maybe 
    148          
    149         self.greenicon = wxPython.wx.wxIcon(os.path.join(iconsdir, "pykoticon-green.ico"), \ 
    150                                   wxPython.wx.wxBITMAP_TYPE_ICO) 
    151         self.redicon = wxPython.wx.wxIcon(os.path.join(iconsdir, "pykoticon-red.ico"), \ 
    152                                   wxPython.wx.wxBITMAP_TYPE_ICO) 
    153          
    154         self.SetIcon(self.greenicon) 
    155         if self.tbicon is not None : 
    156             self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 
    157             wxPython.wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) 
    158             wxPython.wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) 
    159          
    160             self.TBMENU_RESTORE = wx.NewId() 
    161             self.TBMENU_CLOSE = wx.NewId() 
    162             wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, \ 
    163                                               self.OnTaskBarActivate) 
    164             wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, \ 
    165                                               self.OnTaskBarClose) 
    166             self.menu = wxPython.wx.wxMenu() 
    167             self.menu.Append(self.TBMENU_RESTORE, _("Show Print Quota")) 
    168             self.menu.Append(self.TBMENU_CLOSE, _("Quit")) 
    169          
     152#        try :              
     153#            self.tbicon = wxPython.wx.wxTaskBarIcon() 
     154#        except AttributeError :     
     155#            self.tbicon = None # No taskbar icon facility, old wxWidgets maybe 
     156#         
     157#        self.greenicon = wxPython.wx.wxIcon(os.path.join(iconsdir, "pykoticon-green.ico"), \ 
     158#                                  wxPython.wx.wxBITMAP_TYPE_ICO) 
     159#        self.redicon = wxPython.wx.wxIcon(os.path.join(iconsdir, "pykoticon-red.ico"), \ 
     160#                                  wxPython.wx.wxBITMAP_TYPE_ICO) 
     161#         
     162#        self.SetIcon(self.greenicon) 
     163#        if self.tbicon is not None : 
     164#            self.tbicon.SetIcon(self.greenicon, "PyKotIcon") 
     165#            wxPython.wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) 
     166#            wxPython.wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) 
     167#         
     168#            self.TBMENU_RESTORE = wx.NewId() 
     169#            self.TBMENU_CLOSE = wx.NewId() 
     170#            wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, \ 
     171#                                              self.OnTaskBarActivate) 
     172#            wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, \ 
     173#                                              self.OnTaskBarClose) 
     174#            self.menu = wxPython.wx.wxMenu() 
     175#            self.menu.Append(self.TBMENU_RESTORE, _("Show Print Quota")) 
     176#            self.menu.Append(self.TBMENU_CLOSE, _("Quit")) 
     177#         
    170178        wxPython.wx.EVT_ICONIZE(self, self.OnIconify) 
    171179        wxPython.wx.EVT_CLOSE(self, self.OnClose) 
    172          
    173         self.closing = False 
     180        self.Show(True) 
    174181         
    175182    def closeServer(self) :     
     
    194201 
    195202    def OnTaskBarActivate(self, event) : 
    196         if self.IsIconized() : 
    197             self.Iconize(False) 
     203        #if self.IsIconized() : 
     204        #    self.Iconize(False) 
    198205        if not self.IsShown() : 
    199206            self.Show(True) 
     
    212219        self.Destroy() 
    213220 
    214     def OnTaskBarMenu(self, evt) : 
    215         if self.tbicon : 
    216             self.tbicon.PopupMenu(self.menu) 
    217  
    218     def OnTaskBarClose(self, evt) : 
     221    def OnTaskBarMenu(self, event) : 
     222        #if self.tbicon : 
     223        #    self.tbicon.PopupMenu(self.menu) 
     224        pass 
     225 
     226    def OnTaskBarClose(self, event) : 
    219227        self.Close() 
     228         
     229    def askConfirmation(self, printername, username, jobid, jobtitle, jobsize) : 
     230        """Asks for confirmation before printing.""" 
     231        message = _("""Hello %(username)s, 
     232         
     233                     You sent job %(jobid)s (%(jobtitle)s) to printer %(printername)s. 
     234                                     
     235                     This job seems to be %(jobsize)s pages long.  
     236                                     
     237                     Please confirm or cancel.""") % locals() 
     238                      
     239        dialog = wx.MessageDialog(self, message, _("Confirmation"), wx.OK | wx.CANCEL) 
     240        self.askConfirmationResult = dialog.ShowModal() 
     241        dialog.Destroy() 
    220242 
    221243class PyKotIconApp(wx.PySimpleApp): 
    222244    def OnInit(self) : 
    223         try : 
    224             self.frame = PyKotIcon(None, -1) 
    225         except :     
    226             crashed() 
     245        self.frame = PyKotIcon(None, -1) 
    227246        return True 
    228247         
  • pykoticon/trunk/tests/test.py

    r90 r91  
    2525import sys 
    2626import os 
     27import time 
    2728import xmlrpclib 
    2829 
     
    3132    server = xmlrpclib.ServerProxy("http://%s:%s" % (arguments[0], arguments[1])) 
    3233    server.nop() 
    33     print server.openDialog() 
     34    print "Result : %s" % server.openConfirmDialog("HP2100", "jerome", "345", "this is the title", 5) 
    3435    server.nop() 
     36    time.sleep(10) 
    3537    server.quitApplication() 
    3638