Fixing fullscreen
[gc-dialer] / src / dialcentral_qt.py
1 #!/usr/bin/env python
2 # -*- coding: UTF8 -*-
3
4 from __future__ import with_statement
5
6 import os
7 import base64
8 import ConfigParser
9 import functools
10 import logging
11
12 from PyQt4 import QtGui
13 from PyQt4 import QtCore
14
15 import constants
16 from util import qtpie
17 from util import qui_utils
18 from util import misc as misc_utils
19
20 import session
21
22
23 _moduleLogger = logging.getLogger(__name__)
24
25
26 class Dialcentral(object):
27
28         _DATA_PATHS = [
29                 os.path.join(os.path.dirname(__file__), "../share"),
30                 os.path.join(os.path.dirname(__file__), "../data"),
31         ]
32
33         def __init__(self, app):
34                 self._app = app
35                 self._recent = []
36                 self._hiddenCategories = set()
37                 self._hiddenUnits = {}
38                 self._clipboard = QtGui.QApplication.clipboard()
39                 self._dataPath = None
40
41                 self._mainWindow = None
42
43                 self._fullscreenAction = QtGui.QAction(None)
44                 self._fullscreenAction.setText("Fullscreen")
45                 self._fullscreenAction.setCheckable(True)
46                 self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter"))
47                 self._fullscreenAction.toggled.connect(self._on_toggle_fullscreen)
48
49                 self._logAction = QtGui.QAction(None)
50                 self._logAction.setText("Log")
51                 self._logAction.setShortcut(QtGui.QKeySequence("CTRL+l"))
52                 self._logAction.triggered.connect(self._on_log)
53
54                 self._quitAction = QtGui.QAction(None)
55                 self._quitAction.setText("Quit")
56                 self._quitAction.setShortcut(QtGui.QKeySequence("CTRL+q"))
57                 self._quitAction.triggered.connect(self._on_quit)
58
59                 self._app.lastWindowClosed.connect(self._on_app_quit)
60                 self._mainWindow = MainWindow(None, self)
61                 self._mainWindow.window.destroyed.connect(self._on_child_close)
62
63                 self.load_settings()
64
65                 self._mainWindow.show()
66                 self._idleDelay = QtCore.QTimer()
67                 self._idleDelay.setSingleShot(True)
68                 self._idleDelay.setInterval(0)
69                 self._idleDelay.timeout.connect(lambda: self._mainWindow.start())
70                 self._idleDelay.start()
71
72         def load_settings(self):
73                 try:
74                         config = ConfigParser.SafeConfigParser()
75                         config.read(constants._user_settings_)
76                 except IOError, e:
77                         _moduleLogger.info("No settings")
78                         return
79                 except ValueError:
80                         _moduleLogger.info("Settings were corrupt")
81                         return
82                 except ConfigParser.MissingSectionHeaderError:
83                         _moduleLogger.info("Settings were corrupt")
84                         return
85                 except Exception:
86                         _moduleLogger.exception("Unknown loading error")
87
88                 blobs = "", ""
89                 isFullscreen = False
90                 tabIndex = 0
91                 try:
92                         blobs = (
93                                 config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
94                                 for i in xrange(len(self._mainWindow.get_default_credentials()))
95                         )
96                         isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
97                         tabIndex = config.getint(constants.__pretty_app_name__, "tab")
98                 except ConfigParser.NoOptionError, e:
99                         _moduleLogger.info(
100                                 "Settings file %s is missing option %s" % (
101                                         constants._user_settings_,
102                                         e.option,
103                                 ),
104                         )
105                 except ConfigParser.NoSectionError, e:
106                         _moduleLogger.info(
107                                 "Settings file %s is missing section %s" % (
108                                         constants._user_settings_,
109                                         e.section,
110                                 ),
111                         )
112                         return
113                 except Exception:
114                         _moduleLogger.exception("Unknown loading error")
115                         return
116
117                 creds = (
118                         base64.b64decode(blob)
119                         for blob in blobs
120                 )
121                 self._mainWindow.set_default_credentials(*creds)
122                 self._fullscreenAction.setChecked(isFullscreen)
123                 self._mainWindow.set_current_tab(tabIndex)
124                 self._mainWindow.load_settings(config)
125
126         def save_settings(self):
127                 _moduleLogger.info("Saving settings")
128                 config = ConfigParser.SafeConfigParser()
129
130                 config.add_section(constants.__pretty_app_name__)
131                 config.set(constants.__pretty_app_name__, "tab", str(self._mainWindow.get_current_tab()))
132                 config.set(constants.__pretty_app_name__, "fullscreen", str(self._fullscreenAction.isChecked()))
133                 for i, value in enumerate(self._mainWindow.get_default_credentials()):
134                         blob = base64.b64encode(value)
135                         config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
136
137                 self._mainWindow.save_settings(config)
138
139                 with open(constants._user_settings_, "wb") as configFile:
140                         config.write(configFile)
141
142         def get_icon(self, name):
143                 if self._dataPath is None:
144                         for path in self._DATA_PATHS:
145                                 if os.path.exists(os.path.join(path, name)):
146                                         self._dataPath = path
147                                         break
148                 if self._dataPath is not None:
149                         icon = QtGui.QIcon(os.path.join(self._dataPath, name))
150                         return icon
151                 else:
152                         return None
153
154         @property
155         def fsContactsPath(self):
156                 return os.path.join(constants._data_path_, "contacts")
157
158         @property
159         def fullscreenAction(self):
160                 return self._fullscreenAction
161
162         @property
163         def logAction(self):
164                 return self._logAction
165
166         @property
167         def quitAction(self):
168                 return self._quitAction
169
170         def _walk_children(self):
171                 if self._mainWindow is not None:
172                         return (self._mainWindow, )
173                 else:
174                         return ()
175
176         def _close_windows(self):
177                 if self._mainWindow is not None:
178                         self.save_settings()
179                         self._mainWindow.window.destroyed.disconnect(self._on_child_close)
180                         self._mainWindow.close()
181                         self._mainWindow = None
182
183         @QtCore.pyqtSlot()
184         @QtCore.pyqtSlot(bool)
185         @misc_utils.log_exception(_moduleLogger)
186         def _on_app_quit(self, checked = False):
187                 if self._mainWindow is not None:
188                         self.save_settings()
189                         self._mainWindow.destroy()
190
191         @QtCore.pyqtSlot(QtCore.QObject)
192         @misc_utils.log_exception(_moduleLogger)
193         def _on_child_close(self, obj = None):
194                 if self._mainWindow is not None:
195                         self.save_settings()
196                         self._mainWindow = None
197
198         @QtCore.pyqtSlot()
199         @QtCore.pyqtSlot(bool)
200         @misc_utils.log_exception(_moduleLogger)
201         def _on_toggle_fullscreen(self, checked = False):
202                 for window in self._walk_children():
203                         window.set_fullscreen(checked)
204
205         @QtCore.pyqtSlot()
206         @QtCore.pyqtSlot(bool)
207         @misc_utils.log_exception(_moduleLogger)
208         def _on_log(self, checked = False):
209                 with open(constants._user_logpath_, "r") as f:
210                         logLines = f.xreadlines()
211                         log = "".join(logLines)
212                         self._clipboard.setText(log)
213
214         @QtCore.pyqtSlot()
215         @QtCore.pyqtSlot(bool)
216         @misc_utils.log_exception(_moduleLogger)
217         def _on_quit(self, checked = False):
218                 self._close_windows()
219
220
221 class DelayedWidget(object):
222
223         def __init__(self, app, settingsNames):
224                 self._layout = QtGui.QVBoxLayout()
225                 self._layout.setContentsMargins(0, 0, 0, 0)
226                 self._widget = QtGui.QWidget()
227                 self._widget.setContentsMargins(0, 0, 0, 0)
228                 self._widget.setLayout(self._layout)
229                 self._settings = dict((name, "") for name in settingsNames)
230
231                 self._child = None
232                 self._isEnabled = True
233
234         @property
235         def toplevel(self):
236                 return self._widget
237
238         def has_child(self):
239                 return self._child is not None
240
241         def set_child(self, child):
242                 if self._child is not None:
243                         self._layout.removeWidget(self._child.toplevel)
244                 self._child = child
245                 if self._child is not None:
246                         self._layout.addWidget(self._child.toplevel)
247
248                 self._child.set_settings(self._settings)
249
250                 if self._isEnabled:
251                         self._child.enable()
252                 else:
253                         self._child.disable()
254
255         def enable(self):
256                 self._isEnabled = True
257                 if self._child is not None:
258                         self._child.enable()
259
260         def disable(self):
261                 self._isEnabled = False
262                 if self._child is not None:
263                         self._child.disable()
264
265         def clear(self):
266                 if self._child is not None:
267                         self._child.clear()
268
269         def refresh(self, force=True):
270                 if self._child is not None:
271                         self._child.refresh(force)
272
273         def get_settings(self):
274                 if self._child is not None:
275                         return self._child.get_settings()
276                 else:
277                         return self._settings
278
279         def set_settings(self, settings):
280                 if self._child is not None:
281                         self._child.set_settings(settings)
282                 else:
283                         self._settings = settings
284
285
286 def _tab_factory(tab, app, session, errorLog):
287         import gv_views
288         return gv_views.__dict__[tab](app, session, errorLog)
289
290
291 class MainWindow(object):
292
293         KEYPAD_TAB = 0
294         RECENT_TAB = 1
295         MESSAGES_TAB = 2
296         CONTACTS_TAB = 3
297         MAX_TABS = 4
298
299         _TAB_TITLES = [
300                 "Dialpad",
301                 "History",
302                 "Messages",
303                 "Contacts",
304         ]
305         assert len(_TAB_TITLES) == MAX_TABS
306
307         _TAB_ICONS = [
308                 "dialpad.png",
309                 "history.png",
310                 "messages.png",
311                 "contacts.png",
312         ]
313         assert len(_TAB_ICONS) == MAX_TABS
314
315         _TAB_CLASS = [
316                 functools.partial(_tab_factory, "Dialpad"),
317                 functools.partial(_tab_factory, "History"),
318                 functools.partial(_tab_factory, "Messages"),
319                 functools.partial(_tab_factory, "Contacts"),
320         ]
321         assert len(_TAB_CLASS) == MAX_TABS
322
323         # Hack to allow delay importing/loading of tabs
324         _TAB_SETTINGS_NAMES = [
325                 (),
326                 ("filter", ),
327                 ("status", "type"),
328                 ("selectedAddressbook", ),
329         ]
330         assert len(_TAB_SETTINGS_NAMES) == MAX_TABS
331
332         def __init__(self, parent, app):
333                 self._app = app
334
335                 self._errorLog = qui_utils.QErrorLog()
336                 self._errorDisplay = qui_utils.ErrorDisplay(self._errorLog)
337
338                 self._session = session.Session(self._errorLog, constants._data_path_)
339                 self._session.error.connect(self._on_session_error)
340                 self._session.loggedIn.connect(self._on_login)
341                 self._session.loggedOut.connect(self._on_logout)
342                 self._session.draft.recipientsChanged.connect(self._on_recipients_changed)
343                 self._defaultCredentials = "", ""
344                 self._curentCredentials = "", ""
345                 self._currentTab = 0
346
347                 self._credentialsDialog = None
348                 self._smsEntryDialog = None
349                 self._accountDialog = None
350                 self._aboutDialog = None
351
352                 self._tabsContents = [
353                         DelayedWidget(self._app, self._TAB_SETTINGS_NAMES[i])
354                         for i in xrange(self.MAX_TABS)
355                 ]
356                 for tab in self._tabsContents:
357                         tab.disable()
358
359                 self._tabWidget = QtGui.QTabWidget()
360                 if qui_utils.screen_orientation() == QtCore.Qt.Vertical:
361                         self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
362                 else:
363                         self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
364                 for tabIndex, (tabTitle, tabIcon) in enumerate(
365                         zip(self._TAB_TITLES, self._TAB_ICONS)
366                 ):
367                         if constants.IS_MAEMO:
368                                 icon = self._app.get_icon(tabIcon)
369                                 if icon is None:
370                                         self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, tabTitle)
371                                 else:
372                                         self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, icon, "")
373                         else:
374                                 icon = self._app.get_icon(tabIcon)
375                                 self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, icon, tabTitle)
376                 self._tabWidget.currentChanged.connect(self._on_tab_changed)
377                 self._tabWidget.setContentsMargins(0, 0, 0, 0)
378
379                 self._layout = QtGui.QVBoxLayout()
380                 self._layout.setContentsMargins(0, 0, 0, 0)
381                 self._layout.addWidget(self._errorDisplay.toplevel)
382                 self._layout.addWidget(self._tabWidget)
383
384                 centralWidget = QtGui.QWidget()
385                 centralWidget.setLayout(self._layout)
386                 centralWidget.setContentsMargins(0, 0, 0, 0)
387
388                 self._window = QtGui.QMainWindow(parent)
389                 self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
390                 qui_utils.set_autorient(self._window, True)
391                 qui_utils.set_stackable(self._window, True)
392                 self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
393                 self._window.setCentralWidget(centralWidget)
394
395                 self._loginTabAction = QtGui.QAction(None)
396                 self._loginTabAction.setText("Login")
397                 self._loginTabAction.triggered.connect(self._on_login_requested)
398
399                 self._importTabAction = QtGui.QAction(None)
400                 self._importTabAction.setText("Import")
401                 self._importTabAction.triggered.connect(self._on_import)
402
403                 self._accountTabAction = QtGui.QAction(None)
404                 self._accountTabAction.setText("Account")
405                 self._accountTabAction.triggered.connect(self._on_account)
406
407                 self._refreshTabAction = QtGui.QAction(None)
408                 self._refreshTabAction.setText("Refresh")
409                 self._refreshTabAction.setShortcut(QtGui.QKeySequence("CTRL+r"))
410                 self._refreshTabAction.triggered.connect(self._on_refresh)
411
412                 self._aboutAction = QtGui.QAction(None)
413                 self._aboutAction.setText("About")
414                 self._aboutAction.triggered.connect(self._on_about)
415
416                 self._closeWindowAction = QtGui.QAction(None)
417                 self._closeWindowAction.setText("Close")
418                 self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
419                 self._closeWindowAction.triggered.connect(self._on_close_window)
420
421                 if constants.IS_MAEMO:
422                         fileMenu = self._window.menuBar().addMenu("&File")
423                         fileMenu.addAction(self._loginTabAction)
424                         fileMenu.addAction(self._refreshTabAction)
425
426                         toolsMenu = self._window.menuBar().addMenu("&Tools")
427                         toolsMenu.addAction(self._accountTabAction)
428                         toolsMenu.addAction(self._importTabAction)
429                         toolsMenu.addAction(self._aboutAction)
430
431                         self._window.addAction(self._closeWindowAction)
432                         self._window.addAction(self._app.quitAction)
433                         self._window.addAction(self._app.fullscreenAction)
434                 else:
435                         fileMenu = self._window.menuBar().addMenu("&File")
436                         fileMenu.addAction(self._loginTabAction)
437                         fileMenu.addAction(self._refreshTabAction)
438                         fileMenu.addAction(self._closeWindowAction)
439                         fileMenu.addAction(self._app.quitAction)
440
441                         viewMenu = self._window.menuBar().addMenu("&View")
442                         viewMenu.addAction(self._app.fullscreenAction)
443
444                         toolsMenu = self._window.menuBar().addMenu("&Tools")
445                         toolsMenu.addAction(self._accountTabAction)
446                         toolsMenu.addAction(self._importTabAction)
447                         toolsMenu.addAction(self._aboutAction)
448
449                 self._window.addAction(self._app.logAction)
450
451                 self._initialize_tab(self._tabWidget.currentIndex())
452                 self.set_fullscreen(self._app.fullscreenAction.isChecked())
453
454         @property
455         def window(self):
456                 return self._window
457
458         def set_default_credentials(self, username, password):
459                 self._defaultCredentials = username, password
460
461         def get_default_credentials(self):
462                 return self._defaultCredentials
463
464         def walk_children(self):
465                 return (diag for diag in (
466                         self._credentialsDialog,
467                         self._smsEntryDialog,
468                         self._accountDialog,
469                         self._aboutDialog,
470                         )
471                         if diag is not None
472                 )
473
474         def start(self):
475                 assert self._session.state == self._session.LOGGEDOUT_STATE, "Initialization messed up"
476                 if self._defaultCredentials != ("", ""):
477                         username, password = self._defaultCredentials[0], self._defaultCredentials[1]
478                         self._curentCredentials = username, password
479                         self._session.login(username, password)
480                 else:
481                         self._prompt_for_login()
482
483         def close(self):
484                 for child in self.walk_children():
485                         child.window.destroyed.disconnect(self._on_child_close)
486                         child.close()
487                 self._window.close()
488
489         def destroy(self):
490                 if self._session.state != self._session.LOGGEDOUT_STATE:
491                         self._session.logout()
492
493         def get_current_tab(self):
494                 return self._currentTab
495
496         def set_current_tab(self, tabIndex):
497                 self._tabWidget.setCurrentIndex(tabIndex)
498
499         def load_settings(self, config):
500                 backendId = 2 # For backwards compatibility
501                 for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
502                         sectionName = "%s - %s" % (backendId, tabTitle)
503                         settings = self._tabsContents[tabIndex].get_settings()
504                         for settingName in settings.iterkeys():
505                                 try:
506                                         settingValue = config.get(sectionName, settingName)
507                                 except ConfigParser.NoOptionError, e:
508                                         _moduleLogger.info(
509                                                 "Settings file %s is missing section %s" % (
510                                                         constants._user_settings_,
511                                                         e.section,
512                                                 ),
513                                         )
514                                         return
515                                 except ConfigParser.NoSectionError, e:
516                                         _moduleLogger.info(
517                                                 "Settings file %s is missing section %s" % (
518                                                         constants._user_settings_,
519                                                         e.section,
520                                                 ),
521                                         )
522                                         return
523                                 except Exception:
524                                         _moduleLogger.exception("Unknown loading error")
525                                         return
526                                 settings[settingName] = settingValue
527                         self._tabsContents[tabIndex].set_settings(settings)
528
529         def save_settings(self, config):
530                 backendId = 2 # For backwards compatibility
531                 for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
532                         sectionName = "%s - %s" % (backendId, tabTitle)
533                         config.add_section(sectionName)
534                         tabSettings = self._tabsContents[tabIndex].get_settings()
535                         for settingName, settingValue in tabSettings.iteritems():
536                                 config.set(sectionName, settingName, settingValue)
537
538         def show(self):
539                 self._window.show()
540                 for child in self.walk_children():
541                         child.show()
542
543         def hide(self):
544                 for child in self.walk_children():
545                         child.hide()
546                 self._window.hide()
547
548         def set_fullscreen(self, isFullscreen):
549                 if isFullscreen:
550                         self._window.showFullScreen()
551                 else:
552                         self._window.showNormal()
553                 for child in self.walk_children():
554                         child.set_fullscreen(isFullscreen)
555
556         def _initialize_tab(self, index):
557                 assert index < self.MAX_TABS, "Invalid tab"
558                 if not self._tabsContents[index].has_child():
559                         tab = self._TAB_CLASS[index](self._app, self._session, self._errorLog)
560                         self._tabsContents[index].set_child(tab)
561                         self._tabsContents[index].refresh(force=False)
562
563         def _prompt_for_login(self):
564                 if self._credentialsDialog is None:
565                         import dialogs
566                         self._credentialsDialog = dialogs.CredentialsDialog(self._app)
567                 username, password = self._credentialsDialog.run(
568                         self._defaultCredentials[0], self._defaultCredentials[1], self.window
569                 )
570                 self._curentCredentials = username, password
571                 self._session.login(username, password)
572
573         def _show_account_dialog(self):
574                 if self._accountDialog is None:
575                         import dialogs
576                         self._accountDialog = dialogs.AccountDialog(self._app)
577                 self._accountDialog.set_callbacks(
578                         self._session.get_callback_numbers(), self._session.get_callback_number()
579                 )
580                 self._accountDialog.accountNumber = self._session.get_account_number()
581                 response = self._accountDialog.run()
582                 if response == QtGui.QDialog.Accepted:
583                         if self._accountDialog.doClear:
584                                 self._session.logout_and_clear()
585                         else:
586                                 callbackNumber = self._accountDialog.selectedCallback
587                                 self._session.set_callback_number(callbackNumber)
588                 elif response == QtGui.QDialog.Rejected:
589                         _moduleLogger.info("Cancelled")
590                 else:
591                         _moduleLogger.info("Unknown response")
592
593         @QtCore.pyqtSlot(str)
594         @misc_utils.log_exception(_moduleLogger)
595         def _on_session_error(self, message):
596                 with qui_utils.notify_error(self._errorLog):
597                         self._errorLog.push_error(message)
598
599         @QtCore.pyqtSlot()
600         @misc_utils.log_exception(_moduleLogger)
601         def _on_login(self):
602                 with qui_utils.notify_error(self._errorLog):
603                         changedAccounts = self._defaultCredentials != self._curentCredentials
604                         noCallback = not self._session.get_callback_number()
605                         if changedAccounts or noCallback:
606                                 self._show_account_dialog()
607
608                         self._defaultCredentials = self._curentCredentials
609
610                         for tab in self._tabsContents:
611                                 tab.enable()
612
613         @QtCore.pyqtSlot()
614         @misc_utils.log_exception(_moduleLogger)
615         def _on_logout(self):
616                 with qui_utils.notify_error(self._errorLog):
617                         for tab in self._tabsContents:
618                                 tab.disable()
619
620         @QtCore.pyqtSlot()
621         @misc_utils.log_exception(_moduleLogger)
622         def _on_recipients_changed(self):
623                 with qui_utils.notify_error(self._errorLog):
624                         if self._session.draft.get_num_contacts() == 0:
625                                 return
626
627                         if self._smsEntryDialog is None:
628                                 import dialogs
629                                 self._smsEntryDialog = dialogs.SMSEntryWindow(self.window, self._app, self._session, self._errorLog)
630
631         @QtCore.pyqtSlot()
632         @QtCore.pyqtSlot(bool)
633         @misc_utils.log_exception(_moduleLogger)
634         def _on_login_requested(self, checked = True):
635                 with qui_utils.notify_error(self._errorLog):
636                         self._prompt_for_login()
637
638         @QtCore.pyqtSlot(int)
639         @misc_utils.log_exception(_moduleLogger)
640         def _on_tab_changed(self, index):
641                 with qui_utils.notify_error(self._errorLog):
642                         self._currentTab = index
643                         self._initialize_tab(index)
644
645         @QtCore.pyqtSlot()
646         @QtCore.pyqtSlot(bool)
647         @misc_utils.log_exception(_moduleLogger)
648         def _on_refresh(self, checked = True):
649                 with qui_utils.notify_error(self._errorLog):
650                         self._tabsContents[self._currentTab].refresh(force=True)
651
652         @QtCore.pyqtSlot()
653         @QtCore.pyqtSlot(bool)
654         @misc_utils.log_exception(_moduleLogger)
655         def _on_import(self, checked = True):
656                 with qui_utils.notify_error(self._errorLog):
657                         csvName = QtGui.QFileDialog.getOpenFileName(self._window, caption="Import", filter="CSV Files (*.csv)")
658                         if not csvName:
659                                 return
660                         import shutil
661                         shutil.copy2(csvName, self._app.fsContactsPath)
662                         self._tabsContents[self.CONTACTS_TAB].update_addressbooks()
663
664         @QtCore.pyqtSlot()
665         @QtCore.pyqtSlot(bool)
666         @misc_utils.log_exception(_moduleLogger)
667         def _on_account(self, checked = True):
668                 with qui_utils.notify_error(self._errorLog):
669                         self._show_account_dialog()
670
671         @QtCore.pyqtSlot()
672         @QtCore.pyqtSlot(bool)
673         @misc_utils.log_exception(_moduleLogger)
674         def _on_about(self, checked = True):
675                 with qui_utils.notify_error(self._errorLog):
676                         if self._aboutDialog is None:
677                                 import dialogs
678                                 self._aboutDialog = dialogs.AboutDialog(self._app)
679                         response = self._aboutDialog.run()
680
681         @QtCore.pyqtSlot()
682         @QtCore.pyqtSlot(bool)
683         @misc_utils.log_exception(_moduleLogger)
684         def _on_close_window(self, checked = True):
685                 self.close()
686
687
688 def run():
689         app = QtGui.QApplication([])
690         handle = Dialcentral(app)
691         qtpie.init_pies()
692         return app.exec_()
693
694
695 if __name__ == "__main__":
696         import sys
697
698         logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
699         logging.basicConfig(level=logging.DEBUG, format=logFormat)
700         try:
701                 os.makedirs(constants._data_path_)
702         except OSError, e:
703                 if e.errno != 17:
704                         raise
705
706         val = run()
707         sys.exit(val)