Applying changes from template
[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 _close_windows(self):
171                 if self._mainWindow is not None:
172                         self.save_settings()
173                         self._mainWindow.window.destroyed.disconnect(self._on_child_close)
174                         self._mainWindow.close()
175                         self._mainWindow = None
176
177         @QtCore.pyqtSlot()
178         @QtCore.pyqtSlot(bool)
179         @misc_utils.log_exception(_moduleLogger)
180         def _on_app_quit(self, checked = False):
181                 if self._mainWindow is not None:
182                         self.save_settings()
183                         self._mainWindow.destroy()
184
185         @QtCore.pyqtSlot(QtCore.QObject)
186         @misc_utils.log_exception(_moduleLogger)
187         def _on_child_close(self, obj = None):
188                 if self._mainWindow is not None:
189                         self.save_settings()
190                         self._mainWindow = None
191
192         @QtCore.pyqtSlot()
193         @QtCore.pyqtSlot(bool)
194         @misc_utils.log_exception(_moduleLogger)
195         def _on_toggle_fullscreen(self, checked = False):
196                 for window in self._walk_children():
197                         window.set_fullscreen(checked)
198
199         @QtCore.pyqtSlot()
200         @QtCore.pyqtSlot(bool)
201         @misc_utils.log_exception(_moduleLogger)
202         def _on_log(self, checked = False):
203                 with open(constants._user_logpath_, "r") as f:
204                         logLines = f.xreadlines()
205                         log = "".join(logLines)
206                         self._clipboard.setText(log)
207
208         @QtCore.pyqtSlot()
209         @QtCore.pyqtSlot(bool)
210         @misc_utils.log_exception(_moduleLogger)
211         def _on_quit(self, checked = False):
212                 self._close_windows()
213
214
215 class DelayedWidget(object):
216
217         def __init__(self, app, settingsNames):
218                 self._layout = QtGui.QVBoxLayout()
219                 self._layout.setContentsMargins(0, 0, 0, 0)
220                 self._widget = QtGui.QWidget()
221                 self._widget.setContentsMargins(0, 0, 0, 0)
222                 self._widget.setLayout(self._layout)
223                 self._settings = dict((name, "") for name in settingsNames)
224
225                 self._child = None
226                 self._isEnabled = True
227
228         @property
229         def toplevel(self):
230                 return self._widget
231
232         def has_child(self):
233                 return self._child is not None
234
235         def set_child(self, child):
236                 if self._child is not None:
237                         self._layout.removeWidget(self._child.toplevel)
238                 self._child = child
239                 if self._child is not None:
240                         self._layout.addWidget(self._child.toplevel)
241
242                 self._child.set_settings(self._settings)
243
244                 if self._isEnabled:
245                         self._child.enable()
246                 else:
247                         self._child.disable()
248
249         def enable(self):
250                 self._isEnabled = True
251                 if self._child is not None:
252                         self._child.enable()
253
254         def disable(self):
255                 self._isEnabled = False
256                 if self._child is not None:
257                         self._child.disable()
258
259         def clear(self):
260                 if self._child is not None:
261                         self._child.clear()
262
263         def refresh(self, force=True):
264                 if self._child is not None:
265                         self._child.refresh(force)
266
267         def get_settings(self):
268                 if self._child is not None:
269                         return self._child.get_settings()
270                 else:
271                         return self._settings
272
273         def set_settings(self, settings):
274                 if self._child is not None:
275                         self._child.set_settings(settings)
276                 else:
277                         self._settings = settings
278
279
280 def _tab_factory(tab, app, session, errorLog):
281         import gv_views
282         return gv_views.__dict__[tab](app, session, errorLog)
283
284
285 class MainWindow(object):
286
287         KEYPAD_TAB = 0
288         RECENT_TAB = 1
289         MESSAGES_TAB = 2
290         CONTACTS_TAB = 3
291         MAX_TABS = 4
292
293         _TAB_TITLES = [
294                 "Dialpad",
295                 "History",
296                 "Messages",
297                 "Contacts",
298         ]
299         assert len(_TAB_TITLES) == MAX_TABS
300
301         _TAB_ICONS = [
302                 "dialpad.png",
303                 "history.png",
304                 "messages.png",
305                 "contacts.png",
306         ]
307         assert len(_TAB_ICONS) == MAX_TABS
308
309         _TAB_CLASS = [
310                 functools.partial(_tab_factory, "Dialpad"),
311                 functools.partial(_tab_factory, "History"),
312                 functools.partial(_tab_factory, "Messages"),
313                 functools.partial(_tab_factory, "Contacts"),
314         ]
315         assert len(_TAB_CLASS) == MAX_TABS
316
317         # Hack to allow delay importing/loading of tabs
318         _TAB_SETTINGS_NAMES = [
319                 (),
320                 ("filter", ),
321                 ("status", "type"),
322                 ("selectedAddressbook", ),
323         ]
324         assert len(_TAB_SETTINGS_NAMES) == MAX_TABS
325
326         def __init__(self, parent, app):
327                 self._app = app
328
329                 self._errorLog = qui_utils.QErrorLog()
330                 self._errorDisplay = qui_utils.ErrorDisplay(self._errorLog)
331
332                 self._session = session.Session(self._errorLog, constants._data_path_)
333                 self._session.error.connect(self._on_session_error)
334                 self._session.loggedIn.connect(self._on_login)
335                 self._session.loggedOut.connect(self._on_logout)
336                 self._session.draft.recipientsChanged.connect(self._on_recipients_changed)
337                 self._defaultCredentials = "", ""
338                 self._curentCredentials = "", ""
339                 self._currentTab = 0
340
341                 self._credentialsDialog = None
342                 self._smsEntryDialog = None
343                 self._accountDialog = None
344                 self._aboutDialog = None
345
346                 self._tabsContents = [
347                         DelayedWidget(self._app, self._TAB_SETTINGS_NAMES[i])
348                         for i in xrange(self.MAX_TABS)
349                 ]
350                 for tab in self._tabsContents:
351                         tab.disable()
352
353                 self._tabWidget = QtGui.QTabWidget()
354                 if qui_utils.screen_orientation() == QtCore.Qt.Vertical:
355                         self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
356                 else:
357                         self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
358                 for tabIndex, (tabTitle, tabIcon) in enumerate(
359                         zip(self._TAB_TITLES, self._TAB_ICONS)
360                 ):
361                         if constants.IS_MAEMO:
362                                 icon = self._app.get_icon(tabIcon)
363                                 if icon is None:
364                                         self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, tabTitle)
365                                 else:
366                                         self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, icon, "")
367                         else:
368                                 icon = self._app.get_icon(tabIcon)
369                                 self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, icon, tabTitle)
370                 self._tabWidget.currentChanged.connect(self._on_tab_changed)
371                 self._tabWidget.setContentsMargins(0, 0, 0, 0)
372
373                 self._layout = QtGui.QVBoxLayout()
374                 self._layout.setContentsMargins(0, 0, 0, 0)
375                 self._layout.addWidget(self._errorDisplay.toplevel)
376                 self._layout.addWidget(self._tabWidget)
377
378                 centralWidget = QtGui.QWidget()
379                 centralWidget.setLayout(self._layout)
380                 centralWidget.setContentsMargins(0, 0, 0, 0)
381
382                 self._window = QtGui.QMainWindow(parent)
383                 self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
384                 qui_utils.set_autorient(self._window, True)
385                 qui_utils.set_stackable(self._window, True)
386                 self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
387                 self._window.setCentralWidget(centralWidget)
388
389                 self._loginTabAction = QtGui.QAction(None)
390                 self._loginTabAction.setText("Login")
391                 self._loginTabAction.triggered.connect(self._on_login_requested)
392
393                 self._importTabAction = QtGui.QAction(None)
394                 self._importTabAction.setText("Import")
395                 self._importTabAction.triggered.connect(self._on_import)
396
397                 self._accountTabAction = QtGui.QAction(None)
398                 self._accountTabAction.setText("Account")
399                 self._accountTabAction.triggered.connect(self._on_account)
400
401                 self._refreshTabAction = QtGui.QAction(None)
402                 self._refreshTabAction.setText("Refresh")
403                 self._refreshTabAction.setShortcut(QtGui.QKeySequence("CTRL+r"))
404                 self._refreshTabAction.triggered.connect(self._on_refresh)
405
406                 self._aboutAction = QtGui.QAction(None)
407                 self._aboutAction.setText("About")
408                 self._aboutAction.triggered.connect(self._on_about)
409
410                 self._closeWindowAction = QtGui.QAction(None)
411                 self._closeWindowAction.setText("Close")
412                 self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
413                 self._closeWindowAction.triggered.connect(self._on_close_window)
414
415                 if constants.IS_MAEMO:
416                         fileMenu = self._window.menuBar().addMenu("&File")
417                         fileMenu.addAction(self._loginTabAction)
418                         fileMenu.addAction(self._refreshTabAction)
419
420                         toolsMenu = self._window.menuBar().addMenu("&Tools")
421                         toolsMenu.addAction(self._accountTabAction)
422                         toolsMenu.addAction(self._importTabAction)
423                         toolsMenu.addAction(self._aboutAction)
424
425                         self._window.addAction(self._closeWindowAction)
426                         self._window.addAction(self._app.quitAction)
427                         self._window.addAction(self._app.fullscreenAction)
428                 else:
429                         fileMenu = self._window.menuBar().addMenu("&File")
430                         fileMenu.addAction(self._loginTabAction)
431                         fileMenu.addAction(self._refreshTabAction)
432                         fileMenu.addAction(self._closeWindowAction)
433                         fileMenu.addAction(self._app.quitAction)
434
435                         viewMenu = self._window.menuBar().addMenu("&View")
436                         viewMenu.addAction(self._app.fullscreenAction)
437
438                         toolsMenu = self._window.menuBar().addMenu("&Tools")
439                         toolsMenu.addAction(self._accountTabAction)
440                         toolsMenu.addAction(self._importTabAction)
441                         toolsMenu.addAction(self._aboutAction)
442
443                 self._window.addAction(self._app.logAction)
444
445                 self._initialize_tab(self._tabWidget.currentIndex())
446                 self.set_fullscreen(self._app.fullscreenAction.isChecked())
447
448         @property
449         def window(self):
450                 return self._window
451
452         def set_default_credentials(self, username, password):
453                 self._defaultCredentials = username, password
454
455         def get_default_credentials(self):
456                 return self._defaultCredentials
457
458         def walk_children(self):
459                 return (diag for diag in (
460                         self._credentialsDialog,
461                         self._smsEntryDialog,
462                         self._accountDialog,
463                         self._aboutDialog,
464                         )
465                         if diag is not None
466                 )
467
468         def start(self):
469                 assert self._session.state == self._session.LOGGEDOUT_STATE, "Initialization messed up"
470                 if self._defaultCredentials != ("", ""):
471                         username, password = self._defaultCredentials[0], self._defaultCredentials[1]
472                         self._curentCredentials = username, password
473                         self._session.login(username, password)
474                 else:
475                         self._prompt_for_login()
476
477         def close(self):
478                 for child in self.walk_children():
479                         child.window.destroyed.disconnect(self._on_child_close)
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                         changedAccounts = self._defaultCredentials != self._curentCredentials
598                         noCallback = not self._session.get_callback_number()
599                         if changedAccounts or noCallback:
600                                 self._show_account_dialog()
601
602                         self._defaultCredentials = self._curentCredentials
603
604                         for tab in self._tabsContents:
605                                 tab.enable()
606
607         @QtCore.pyqtSlot()
608         @misc_utils.log_exception(_moduleLogger)
609         def _on_logout(self):
610                 with qui_utils.notify_error(self._errorLog):
611                         for tab in self._tabsContents:
612                                 tab.disable()
613
614         @QtCore.pyqtSlot()
615         @misc_utils.log_exception(_moduleLogger)
616         def _on_recipients_changed(self):
617                 with qui_utils.notify_error(self._errorLog):
618                         if self._session.draft.get_num_contacts() == 0:
619                                 return
620
621                         if self._smsEntryDialog is None:
622                                 import dialogs
623                                 self._smsEntryDialog = dialogs.SMSEntryWindow(self.window, self._app, self._session, self._errorLog)
624
625         @QtCore.pyqtSlot()
626         @QtCore.pyqtSlot(bool)
627         @misc_utils.log_exception(_moduleLogger)
628         def _on_login_requested(self, checked = True):
629                 with qui_utils.notify_error(self._errorLog):
630                         self._prompt_for_login()
631
632         @QtCore.pyqtSlot(int)
633         @misc_utils.log_exception(_moduleLogger)
634         def _on_tab_changed(self, index):
635                 with qui_utils.notify_error(self._errorLog):
636                         self._currentTab = index
637                         self._initialize_tab(index)
638
639         @QtCore.pyqtSlot()
640         @QtCore.pyqtSlot(bool)
641         @misc_utils.log_exception(_moduleLogger)
642         def _on_refresh(self, checked = True):
643                 with qui_utils.notify_error(self._errorLog):
644                         self._tabsContents[self._currentTab].refresh(force=True)
645
646         @QtCore.pyqtSlot()
647         @QtCore.pyqtSlot(bool)
648         @misc_utils.log_exception(_moduleLogger)
649         def _on_import(self, checked = True):
650                 with qui_utils.notify_error(self._errorLog):
651                         csvName = QtGui.QFileDialog.getOpenFileName(self._window, caption="Import", filter="CSV Files (*.csv)")
652                         if not csvName:
653                                 return
654                         import shutil
655                         shutil.copy2(csvName, self._app.fsContactsPath)
656                         self._tabsContents[self.CONTACTS_TAB].update_addressbooks()
657
658         @QtCore.pyqtSlot()
659         @QtCore.pyqtSlot(bool)
660         @misc_utils.log_exception(_moduleLogger)
661         def _on_account(self, checked = True):
662                 with qui_utils.notify_error(self._errorLog):
663                         self._show_account_dialog()
664
665         @QtCore.pyqtSlot()
666         @QtCore.pyqtSlot(bool)
667         def _on_about(self, checked = True):
668                 with qui_utils.notify_error(self._errorLog):
669                         if self._aboutDialog is None:
670                                 import dialogs
671                                 self._aboutDialog = dialogs.AboutDialog(self._app)
672                         response = self._aboutDialog.run()
673
674         @QtCore.pyqtSlot()
675         @QtCore.pyqtSlot(bool)
676         @misc_utils.log_exception(_moduleLogger)
677         def _on_close_window(self, checked = True):
678                 self.close()
679
680
681 def run():
682         app = QtGui.QApplication([])
683         handle = Dialcentral(app)
684         qtpie.init_pies()
685         return app.exec_()
686
687
688 if __name__ == "__main__":
689         import sys
690
691         logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
692         logging.basicConfig(level=logging.DEBUG, format=logFormat)
693         try:
694                 os.makedirs(constants._data_path_)
695         except OSError, e:
696                 if e.errno != 17:
697                         raise
698
699         val = run()
700         sys.exit(val)