connect and disconnect from IMAP server
This commit is contained in:
parent
2c83245947
commit
cf46b1b454
17
Window.py
17
Window.py
@ -5,6 +5,8 @@ import imaplib
|
|||||||
class Window(object):
|
class Window(object):
|
||||||
def __init__(self, title, conf):
|
def __init__(self, title, conf):
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
self.connection = None
|
||||||
|
|
||||||
if not 'width' in self.conf:
|
if not 'width' in self.conf:
|
||||||
self.conf['width'] = 32
|
self.conf['width'] = 32
|
||||||
if not 'height' in self.conf:
|
if not 'height' in self.conf:
|
||||||
@ -26,6 +28,8 @@ class Window(object):
|
|||||||
|
|
||||||
self.window.add(self.label)
|
self.window.add(self.label)
|
||||||
|
|
||||||
|
self.connect()
|
||||||
|
|
||||||
self.window.show_all()
|
self.window.show_all()
|
||||||
|
|
||||||
if 'x' in self.conf and 'y' in self.conf:
|
if 'x' in self.conf and 'y' in self.conf:
|
||||||
@ -35,6 +39,18 @@ class Window(object):
|
|||||||
def run(self):
|
def run(self):
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
try:
|
||||||
|
self.connection = imaplib.IMAP4_SSL(
|
||||||
|
self.conf['server'], self.conf['port'])
|
||||||
|
self.connection.login(self.conf['user'], self.conf['password'])
|
||||||
|
except:
|
||||||
|
self.connection = None
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
if self.connection is not None:
|
||||||
|
self.connection = None
|
||||||
|
|
||||||
def update_conf(self):
|
def update_conf(self):
|
||||||
w, h = self.window.get_size()
|
w, h = self.window.get_size()
|
||||||
self.conf['width'] = w
|
self.conf['width'] = w
|
||||||
@ -44,6 +60,7 @@ class Window(object):
|
|||||||
self.conf['y'] = y
|
self.conf['y'] = y
|
||||||
|
|
||||||
def destroy_event(self):
|
def destroy_event(self):
|
||||||
|
self.disconnect()
|
||||||
self.update_conf()
|
self.update_conf()
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user