1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
5 Generic thread wrapper used for reading things from phone
7 __author__
= 'Michal Čihař'
8 __email__
= 'michal@cihar.com'
10 Copyright © 2003 - 2008 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 class Thread(threading
.Thread
):
32 def __init__(self
, win
, sm
):
33 threading
.Thread
.__init
__(self
)
42 evt
= Wammu
.Events
.ExceptionEvent(data
= sys
.exc_info())
43 wx
.PostEvent(self
.win
, evt
)
44 self
.ShowProgress(100)
49 def ShowError(self
, info
, finish
= False):
51 self
.ShowProgress(100)
52 lck
= threading
.Lock()
54 evt
= Wammu
.Events
.ShowMessageEvent(
55 message
= Wammu
.Utils
.FormatError(
56 _('Error while communicating with phone'),
58 title
= _('Error Occured'),
62 wx
.PostEvent(self
.win
, evt
)
65 def ShowMessage(self
, title
, text
):
66 lck
= threading
.Lock()
68 evt
= Wammu
.Events
.ShowMessageEvent(
71 type = wx
.ICON_INFORMATION
,
73 wx
.PostEvent(self
.win
, evt
)
76 def ShowProgress(self
, progress
):
77 evt
= Wammu
.Events
.ProgressEvent(
80 wx
.PostEvent(self
.win
, evt
)
82 def SendData(self
, datatype
, data
, last
= True):
83 evt
= Wammu
.Events
.DataEvent(
87 wx
.PostEvent(self
.win
, evt
)
90 lck
= threading
.Lock()
92 evt
= Wammu
.Events
.ShowMessageEvent(
93 message
= _('Action canceled by user!'),
94 title
= _('Action canceled'),
95 type = wx
.ICON_WARNING
,
97 wx
.PostEvent(self
.win
, evt
)
99 self
.ShowProgress(100)