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