Translated using Weblate.
[wammu.git] / Wammu / Thread.py
blob55ee6eb6f6b7f40672a4d70cbc58a8673c317f38
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Generic thread wrapper used for reading things from phone
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 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
19 more details.
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
24 '''
26 import sys
27 import threading
28 import wx
29 import Wammu.Events
31 class Thread(threading.Thread):
32 def __init__(self, win, sm):
33 threading.Thread.__init__(self)
34 self.win = win
35 self.sm = sm
36 self.canceled = False
38 def run(self):
39 try:
40 self.Run()
41 except:
42 evt = Wammu.Events.ExceptionEvent(data = sys.exc_info())
43 wx.PostEvent(self.win, evt)
44 self.ShowProgress(100)
46 def Cancel(self):
47 self.canceled = True
49 def ShowError(self, info, finish = False):
50 if finish:
51 self.ShowProgress(100)
52 lck = threading.Lock()
53 lck.acquire()
54 evt = Wammu.Events.ShowMessageEvent(
55 message = Wammu.Utils.FormatError(
56 _('Error while communicating with phone'),
57 info),
58 title = _('Error Occured'),
59 type = wx.ICON_ERROR,
60 errortype = 'gammu',
61 lock = lck)
62 wx.PostEvent(self.win, evt)
63 lck.acquire()
65 def ShowMessage(self, title, text):
66 lck = threading.Lock()
67 lck.acquire()
68 evt = Wammu.Events.ShowMessageEvent(
69 message = text,
70 title = title,
71 type = wx.ICON_INFORMATION,
72 lock = lck)
73 wx.PostEvent(self.win, evt)
74 lck.acquire()
76 def ShowProgress(self, progress):
77 evt = Wammu.Events.ProgressEvent(
78 progress = progress,
79 cancel = self.Cancel)
80 wx.PostEvent(self.win, evt)
82 def SendData(self, datatype, data, last = True):
83 evt = Wammu.Events.DataEvent(
84 type = datatype,
85 data = data,
86 last = last)
87 wx.PostEvent(self.win, evt)
89 def Canceled(self):
90 lck = threading.Lock()
91 lck.acquire()
92 evt = Wammu.Events.ShowMessageEvent(
93 message = _('Action canceled by user!'),
94 title = _('Action canceled'),
95 type = wx.ICON_WARNING,
96 lock = lck)
97 wx.PostEvent(self.win, evt)
98 lck.acquire()
99 self.ShowProgress(100)