Adding fullscreen support
[gonvert] / src / gonvert_qt.py
1 #!/usr/bin/env python
2 # -*- coding: UTF8 -*-
3
4 from __future__ import with_statement
5
6 import sys
7 import os
8 import math
9 import logging
10
11 from PyQt4 import QtGui
12 from PyQt4 import QtCore
13
14 import constants
15 from util import misc as misc_utils
16 import unit_data
17
18
19 _moduleLogger = logging.getLogger("gonvert_glade")
20
21
22 def change_menu_label(widgets, labelname, newtext):
23         item_label = widgets.get_widget(labelname).get_children()[0]
24         item_label.set_text(newtext)
25
26
27 def split_number(number):
28         try:
29                 fractional, integer = math.modf(number)
30         except TypeError:
31                 integerDisplay = number
32                 fractionalDisplay = ""
33         else:
34                 integerDisplay = str(integer)
35                 fractionalDisplay = str(fractional)
36                 if "e+" in integerDisplay:
37                         integerDisplay = number
38                         fractionalDisplay = ""
39                 elif "e-" in fractionalDisplay and 0.0 < integer:
40                         integerDisplay = number
41                         fractionalDisplay = ""
42                 elif "e-" in fractionalDisplay:
43                         integerDisplay = ""
44                         fractionalDisplay = number
45                 else:
46                         integerDisplay = integerDisplay.split(".", 1)[0] + "."
47                         fractionalDisplay = fractionalDisplay.rsplit(".", 1)[-1]
48
49         return integerDisplay, fractionalDisplay
50
51
52 class Gonvert(object):
53
54         # @todo Persist settings
55         # @todo Favorites
56         # @todo Add menus to all windows
57         # @bug Fix the resurrecting window problem
58         # @todo Close Window / Quit keyboard shortcuts
59         # @todo Ctrl+l support
60         # @todo Unit conversion window: focus always on input, arrows switch units
61
62         _DATA_PATHS = [
63                 os.path.dirname(__file__),
64                 os.path.join(os.path.dirname(__file__), "../data"),
65                 os.path.join(os.path.dirname(__file__), "../lib"),
66                 '/usr/share/gonvert',
67                 '/usr/lib/gonvert',
68         ]
69
70         def __init__(self):
71                 self._dataPath = ""
72                 for dataPath in self._DATA_PATHS:
73                         appIconPath = os.path.join(dataPath, "pixmaps", "gonvert.png")
74                         if os.path.isfile(appIconPath):
75                                 self._dataPath = dataPath
76                                 break
77                 else:
78                         raise RuntimeError("UI Descriptor not found!")
79                 self._appIconPath = appIconPath
80                 self._recent = []
81                 self._isFullscreen = False
82
83                 self._jumpWindow = None
84                 self._recentWindow = None
85                 self._catWindow = None
86
87                 self._jumpAction = QtGui.QAction(None)
88                 self._jumpAction.setText("Quick Jump")
89                 self._jumpAction.setStatusTip("Search for a unit and jump straight to it")
90                 self._jumpAction.setToolTip("Search for a unit and jump straight to it")
91                 self._jumpAction.setShortcut(QtGui.QKeySequence("CTRL+j"))
92                 self._jumpAction.triggered.connect(self._on_jump_start)
93
94                 self._recentAction = QtGui.QAction(None)
95                 self._recentAction.setText("Recent Units")
96                 self._recentAction.setStatusTip("View the recent units")
97                 self._recentAction.setToolTip("View the recent units")
98                 self._recentAction.setShortcut(QtGui.QKeySequence("CTRL+r"))
99                 self._recentAction.triggered.connect(self._on_recent_start)
100
101                 self._fullscreenAction = QtGui.QAction(None)
102                 self._fullscreenAction.setText("Toggle Fullscreen")
103                 self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter"))
104                 self._fullscreenAction.triggered.connect(self._on_toggle_fullscreen)
105
106                 self.request_category()
107
108         def request_category(self):
109                 if self._catWindow is not None:
110                         self._catWindow.close()
111                         self._catWindow = None
112                 self._catWindow = CategoryWindow(None, self)
113                 return self._catWindow
114
115         def search_units(self):
116                 if self._jumpWindow is not None:
117                         self._jumpWindow.close()
118                         self._jumpWindow = None
119                 self._jumpWindow = QuickJump(None, self)
120                 return self._jumpWindow
121
122         def show_recent(self):
123                 if self._recentWindow is not None:
124                         self._recentWindow.close()
125                         self._recentWindow = None
126                 self._recentWindow = Recent(None, self)
127                 return self._recentWindow
128
129         def add_recent(self, categoryName, unitName):
130                 catUnit = categoryName, unitName
131                 try:
132                         self._recent.remove(catUnit)
133                 except ValueError:
134                         pass # ignore if its not already in the recent history
135                 self._recent.append(catUnit)
136
137         def get_recent_unit(self, categoryName):
138                 for catName, unitName in reversed(self._recent):
139                         if catName == categoryName:
140                                 return unitName
141                 else:
142                         return ""
143
144         def get_recent(self):
145                 return reversed(self._recent)
146
147         @property
148         def appIconPath(self):
149                 return self._appIconPath
150
151         @property
152         def jumpAction(self):
153                 return self._jumpAction
154
155         @property
156         def recentAction(self):
157                 return self._recentAction
158
159         @property
160         def fullscreenAction(self):
161                 return self._fullscreenAction
162
163         def _walk_children(self):
164                 if self._catWindow is not None:
165                         yield self._catWindow
166                 if self._jumpWindow is not None:
167                         yield self._jumpWindow
168                 if self._recentWindow is not None:
169                         yield self._recentWindow
170
171         @misc_utils.log_exception(_moduleLogger)
172         def _on_toggle_fullscreen(self, checked = False):
173                 self._isFullscreen = not self._isFullscreen
174                 for window in self._walk_children():
175                         window.setFullscreen(self._isFullscreen)
176
177         @misc_utils.log_exception(_moduleLogger)
178         def _on_jump_start(self, checked = False):
179                 self.search_units()
180
181         @misc_utils.log_exception(_moduleLogger)
182         def _on_recent_start(self, checked = False):
183                 self.show_recent()
184
185
186 class CategoryWindow(object):
187
188         def __init__(self, parent, app):
189                 self._app = app
190                 self._unitWindow = None
191
192                 self._categories = QtGui.QTreeWidget()
193                 self._categories.setHeaderLabels(["Categories"])
194                 self._categories.itemClicked.connect(self._on_category_clicked)
195                 self._categories.setHeaderHidden(True)
196                 self._categories.setAlternatingRowColors(True)
197                 for catName in unit_data.UNIT_CATEGORIES:
198                         twi = QtGui.QTreeWidgetItem(self._categories)
199                         twi.setText(0, catName)
200
201                 self._layout = QtGui.QVBoxLayout()
202                 self._layout.addWidget(self._categories)
203
204                 centralWidget = QtGui.QWidget()
205                 centralWidget.setLayout(self._layout)
206
207                 self._window = QtGui.QMainWindow(parent)
208                 if parent is not None:
209                         self._window.setWindowModality(QtCore.Qt.WindowModal)
210                 self._window.setWindowTitle("%s - Categories" % constants.__pretty_app_name__)
211                 self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
212                 self._window.setCentralWidget(centralWidget)
213
214                 viewMenu = self._window.menuBar().addMenu("&View")
215                 viewMenu.addAction(self._app.fullscreenAction)
216                 viewMenu.addSeparator()
217                 viewMenu.addAction(self._app.jumpAction)
218                 viewMenu.addAction(self._app.recentAction)
219
220                 self._window.show()
221
222         def walk_children(self):
223                 if self._unitWindow is not None:
224                         yield self._unitWindow
225
226         def close(self):
227                 for child in self.walk_children():
228                         child.close()
229                 self._window.close()
230
231         def selectCategory(self, categoryName):
232                 for child in self.walk_children():
233                         child.close()
234                 self._unitWindow = UnitWindow(self._window, categoryName, self._app)
235                 return self._unitWindow
236
237         def setFullscreen(self, isFullscreen):
238                 if isFullscreen:
239                         self._window.showFullScreen()
240                 else:
241                         self._window.showNormal()
242                 for child in self.walk_children():
243                         child.setFullscreen(isFullscreen)
244
245         @misc_utils.log_exception(_moduleLogger)
246         def _on_category_clicked(self, item, columnIndex):
247                 categoryName = unicode(item.text(0))
248                 self.selectCategory(categoryName)
249
250
251 class QuickJump(object):
252
253         MINIMAL_ENTRY = 3
254
255         def __init__(self, parent, app):
256                 self._app = app
257
258                 self._searchLabel = QtGui.QLabel("Search:")
259                 self._searchEntry = QtGui.QLineEdit("")
260                 self._searchEntry.textEdited.connect(self._on_search_edited)
261
262                 self._entryLayout = QtGui.QHBoxLayout()
263                 self._entryLayout.addWidget(self._searchLabel)
264                 self._entryLayout.addWidget(self._searchEntry)
265
266                 self._resultsBox = QtGui.QTreeWidget()
267                 self._resultsBox.setHeaderLabels(["Categories", "Units"])
268                 self._resultsBox.setHeaderHidden(True)
269                 self._resultsBox.setAlternatingRowColors(True)
270                 self._resultsBox.itemClicked.connect(self._on_result_clicked)
271
272                 self._layout = QtGui.QVBoxLayout()
273                 self._layout.addLayout(self._entryLayout)
274                 self._layout.addWidget(self._resultsBox)
275
276                 centralWidget = QtGui.QWidget()
277                 centralWidget.setLayout(self._layout)
278
279                 self._window = QtGui.QMainWindow(parent)
280                 if parent is not None:
281                         self._window.setWindowModality(QtCore.Qt.WindowModal)
282                 self._window.setWindowTitle("%s - Quick Jump" % constants.__pretty_app_name__)
283                 self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
284                 self._window.setCentralWidget(centralWidget)
285
286                 self._window.show()
287
288         def close(self):
289                 self._window.close()
290
291         def setFullscreen(self, isFullscreen):
292                 if isFullscreen:
293                         self._window.showFullScreen()
294                 else:
295                         self._window.showNormal()
296
297         @misc_utils.log_exception(_moduleLogger)
298         def _on_result_clicked(self, item, columnIndex):
299                 categoryName = unicode(item.text(0))
300                 unitName = unicode(item.text(1))
301                 catWindow = self._app.request_category()
302                 unitsWindow = catWindow.selectCategory(categoryName)
303                 unitsWindow.select_unit(unitName)
304                 self.close()
305
306         @misc_utils.log_exception(_moduleLogger)
307         def _on_search_edited(self, *args):
308                 userInput = self._searchEntry.text()
309                 if len(userInput) <  self.MINIMAL_ENTRY:
310                         return
311
312                 self._resultsBox.clear()
313                 lowerInput = str(userInput).lower()
314                 for catIndex, category in enumerate(unit_data.UNIT_CATEGORIES):
315                         units = unit_data.get_units(category)
316                         for unitIndex, unit in enumerate(units):
317                                 loweredUnit = unit.lower()
318                                 if lowerInput in loweredUnit:
319                                         twi = QtGui.QTreeWidgetItem(self._resultsBox)
320                                         twi.setText(0, category)
321                                         twi.setText(1, unit)
322
323
324 class Recent(object):
325
326         def __init__(self, parent, app):
327                 self._app = app
328
329                 self._resultsBox = QtGui.QTreeWidget()
330                 self._resultsBox.setHeaderLabels(["Categories", "Units"])
331                 self._resultsBox.setHeaderHidden(True)
332                 self._resultsBox.setAlternatingRowColors(True)
333                 self._resultsBox.itemClicked.connect(self._on_result_clicked)
334
335                 self._layout = QtGui.QVBoxLayout()
336                 self._layout.addWidget(self._resultsBox)
337
338                 centralWidget = QtGui.QWidget()
339                 centralWidget.setLayout(self._layout)
340
341                 self._window = QtGui.QMainWindow(parent)
342                 if parent is not None:
343                         self._window.setWindowModality(QtCore.Qt.WindowModal)
344                 self._window.setWindowTitle("%s - Recent" % constants.__pretty_app_name__)
345                 self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
346                 self._window.setCentralWidget(centralWidget)
347
348                 for cat, unit in self._app.get_recent():
349                         twi = QtGui.QTreeWidgetItem(self._resultsBox)
350                         twi.setText(0, cat)
351                         twi.setText(1, unit)
352
353                 self._window.show()
354
355         def close(self):
356                 self._window.close()
357
358         def setFullscreen(self, isFullscreen):
359                 if isFullscreen:
360                         self._window.showFullScreen()
361                 else:
362                         self._window.showNormal()
363
364         @misc_utils.log_exception(_moduleLogger)
365         def _on_result_clicked(self, item, columnIndex):
366                 categoryName = unicode(item.text(0))
367                 unitName = unicode(item.text(1))
368                 catWindow = self._app.request_category()
369                 unitsWindow = catWindow.selectCategory(categoryName)
370                 unitsWindow.select_unit(unitName)
371                 self.close()
372
373
374 class UnitData(object):
375
376         HEADERS = ["Name", "Value", "", "Unit"]
377         ALIGNMENT = [QtCore.Qt.AlignLeft, QtCore.Qt.AlignRight, QtCore.Qt.AlignLeft, QtCore.Qt.AlignLeft]
378
379         def __init__(self, name, unit, description, conversion):
380                 self._name = name
381                 self._unit = unit
382                 self._description = description
383                 self._conversion = conversion
384
385                 self._value = 0.0
386                 self._integerDisplay, self._fractionalDisplay = split_number(self._value)
387
388         @property
389         def name(self):
390                 return self._name
391
392         @property
393         def value(self):
394                 return self._value
395
396         def update_value(self, newValue):
397                 self._value = newValue
398                 self._integerDisplay, self._fractionalDisplay = split_number(newValue)
399
400         @property
401         def unit(self):
402                 return self._unit
403
404         @property
405         def conversion(self):
406                 return self._conversion
407
408         def data(self, column):
409                 try:
410                         return [self._name, self._integerDisplay, self._fractionalDisplay, self._unit][column]
411                 except IndexError:
412                         return None
413
414
415 class UnitModel(QtCore.QAbstractItemModel):
416
417         def __init__(self, categoryName, parent=None):
418                 super(UnitModel, self).__init__(parent)
419                 self._categoryName = categoryName
420                 self._unitData = unit_data.UNIT_DESCRIPTIONS[self._categoryName]
421
422                 self._children = []
423                 for key in unit_data.get_units(self._categoryName):
424                         conversion, unit, description = self._unitData[key]
425                         self._children.append(UnitData(key, unit, description, conversion))
426
427         @misc_utils.log_exception(_moduleLogger)
428         def columnCount(self, parent):
429                 if parent.isValid():
430                         return 0
431                 else:
432                         return len(UnitData.HEADERS)
433
434         @misc_utils.log_exception(_moduleLogger)
435         def data(self, index, role):
436                 if not index.isValid():
437                         return None
438                 elif role == QtCore.Qt.TextAlignmentRole:
439                         return UnitData.ALIGNMENT[index.column()]
440                 elif role != QtCore.Qt.DisplayRole:
441                         return None
442
443                 item = index.internalPointer()
444                 if isinstance(item, UnitData):
445                         return item.data(index.column())
446                 elif item is UnitData.HEADERS:
447                         return item[index.column()]
448
449         @misc_utils.log_exception(_moduleLogger)
450         def sort(self, column, order = QtCore.Qt.AscendingOrder):
451                 isReverse = order == QtCore.Qt.AscendingOrder
452                 if column == 0:
453                         key_func = lambda item: item.name
454                 elif column in [1, 2]:
455                         key_func = lambda item: item.value
456                 elif column == 3:
457                         key_func = lambda item: item.unit
458                 self._children.sort(key=key_func, reverse = isReverse)
459
460                 self._all_changed()
461
462         @misc_utils.log_exception(_moduleLogger)
463         def flags(self, index):
464                 if not index.isValid():
465                         return QtCore.Qt.NoItemFlags
466
467                 return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
468
469         @misc_utils.log_exception(_moduleLogger)
470         def headerData(self, section, orientation, role):
471                 if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
472                         return UnitData.HEADERS[section]
473
474                 return None
475
476         @misc_utils.log_exception(_moduleLogger)
477         def index(self, row, column, parent):
478                 if not self.hasIndex(row, column, parent):
479                         return QtCore.QModelIndex()
480
481                 if parent.isValid():
482                         return QtCore.QModelIndex()
483
484                 parentItem = UnitData.HEADERS
485                 childItem = self._children[row]
486                 if childItem:
487                         return self.createIndex(row, column, childItem)
488                 else:
489                         return QtCore.QModelIndex()
490
491         @misc_utils.log_exception(_moduleLogger)
492         def parent(self, index):
493                 if not index.isValid():
494                         return QtCore.QModelIndex()
495
496                 childItem = index.internalPointer()
497                 if isinstance(childItem, UnitData):
498                         return QtCore.QModelIndex()
499                 elif childItem is UnitData.HEADERS:
500                         return None
501
502         @misc_utils.log_exception(_moduleLogger)
503         def rowCount(self, parent):
504                 if 0 < parent.column():
505                         return 0
506
507                 if not parent.isValid():
508                         return len(self._children)
509                 else:
510                         return len(self._children)
511
512         def get_unit(self, index):
513                 return self._children[index]
514
515         def index_unit(self, unitName):
516                 for i, child in enumerate(self._children):
517                         if child.name == unitName:
518                                 return i
519                 else:
520                         raise RuntimeError("Unit not found")
521
522         def update_values(self, fromIndex, userInput):
523                 value = self._sanitize_value(userInput)
524                 func, arg = self._children[fromIndex].conversion
525                 base = func.to_base(value, arg)
526                 for i, child in enumerate(self._children):
527                         if i == fromIndex:
528                                 continue
529                         func, arg = child.conversion
530                         newValue = func.from_base(base, arg)
531                         child.update_value(newValue)
532
533                 self._all_changed()
534
535         def _all_changed(self):
536                 topLeft = self.createIndex(0, 1, self._children[0])
537                 bottomRight = self.createIndex(len(self._children)-1, 2, self._children[-1])
538                 self.dataChanged.emit(topLeft, bottomRight)
539
540         def _sanitize_value(self, userEntry):
541                 if self._categoryName == "Computer Numbers":
542                         if userEntry == '':
543                                 value = '0'
544                         else:
545                                 value = userEntry
546                 else:
547                         if userEntry == '':
548                                 value = 0.0
549                         else:
550                                 value = float(userEntry)
551                 return value
552
553
554 class UnitWindow(object):
555
556         def __init__(self, parent, category, app):
557                 self._app = app
558                 self._categoryName = category
559                 self._selectedIndex = 0
560
561                 self._selectedUnitName = QtGui.QLabel()
562                 self._selectedUnitValue = QtGui.QLineEdit()
563                 self._selectedUnitValue.textEdited.connect(self._on_value_edited)
564                 self._selectedUnitSymbol = QtGui.QLabel()
565
566                 self._selectedUnitLayout = QtGui.QHBoxLayout()
567                 self._selectedUnitLayout.addWidget(self._selectedUnitName)
568                 self._selectedUnitLayout.addWidget(self._selectedUnitValue)
569                 self._selectedUnitLayout.addWidget(self._selectedUnitSymbol)
570
571                 self._unitsModel = UnitModel(self._categoryName)
572                 self._unitsView = QtGui.QTreeView()
573                 self._unitsView.setModel(self._unitsModel)
574                 self._unitsView.clicked.connect(self._on_unit_clicked)
575                 self._unitsView.setUniformRowHeights(True)
576                 self._unitsView.header().setSortIndicatorShown(True)
577                 self._unitsView.header().setClickable(True)
578                 self._unitsView.setSortingEnabled(True)
579                 self._unitsView.setAlternatingRowColors(True)
580                 if True:
581                         self._unitsView.setHeaderHidden(True)
582
583                 self._layout = QtGui.QVBoxLayout()
584                 self._layout.addLayout(self._selectedUnitLayout)
585                 self._layout.addWidget(self._unitsView)
586
587                 centralWidget = QtGui.QWidget()
588                 centralWidget.setLayout(self._layout)
589
590                 self._window = QtGui.QMainWindow(parent)
591                 if parent is not None:
592                         self._window.setWindowModality(QtCore.Qt.WindowModal)
593                 self._window.setWindowTitle("%s - %s" % (constants.__pretty_app_name__, category))
594                 self._window.setWindowIcon(QtGui.QIcon(app.appIconPath))
595                 self._window.setCentralWidget(centralWidget)
596
597                 defaultUnitName = self._app.get_recent_unit(self._categoryName)
598                 if defaultUnitName:
599                         self.select_unit(defaultUnitName)
600                 else:
601                         self._select_unit(0)
602                 self._unitsModel.sort(1)
603
604                 self._sortActionGroup = QtGui.QActionGroup(None)
605                 self._sortByNameAction = QtGui.QAction(self._sortActionGroup)
606                 self._sortByNameAction.setText("Sort By Name")
607                 self._sortByNameAction.setStatusTip("Sort the units by name")
608                 self._sortByNameAction.setToolTip("Sort the units by name")
609                 self._sortByValueAction = QtGui.QAction(self._sortActionGroup)
610                 self._sortByValueAction.setText("Sort By Value")
611                 self._sortByValueAction.setStatusTip("Sort the units by value")
612                 self._sortByValueAction.setToolTip("Sort the units by value")
613                 self._sortByUnitAction = QtGui.QAction(self._sortActionGroup)
614                 self._sortByUnitAction.setText("Sort By Unit")
615                 self._sortByUnitAction.setStatusTip("Sort the units by unit")
616                 self._sortByUnitAction.setToolTip("Sort the units by unit")
617
618                 self._sortByValueAction.setChecked(True)
619
620                 viewMenu = self._window.menuBar().addMenu("&View")
621                 viewMenu.addAction(self._app.fullscreenAction)
622                 viewMenu.addSeparator()
623                 viewMenu.addAction(self._app.jumpAction)
624                 viewMenu.addAction(self._app.recentAction)
625                 viewMenu.addSeparator()
626                 viewMenu.addAction(self._sortByNameAction)
627                 viewMenu.addAction(self._sortByValueAction)
628                 viewMenu.addAction(self._sortByUnitAction)
629
630                 self._sortByNameAction.triggered.connect(self._on_sort_by_name)
631                 self._sortByValueAction.triggered.connect(self._on_sort_by_value)
632                 self._sortByUnitAction.triggered.connect(self._on_sort_by_unit)
633
634                 self._window.show()
635
636         def close(self):
637                 self._window.close()
638
639         def setFullscreen(self, isFullscreen):
640                 if isFullscreen:
641                         self._window.showFullScreen()
642                 else:
643                         self._window.showNormal()
644
645         def select_unit(self, unitName):
646                 index = self._unitsModel.index_unit(unitName)
647                 self._select_unit(index)
648
649         @misc_utils.log_exception(_moduleLogger)
650         def _on_sort_by_name(self, checked = False):
651                 self._unitsModel.sort(0, QtCore.Qt.DescendingOrder)
652
653         @misc_utils.log_exception(_moduleLogger)
654         def _on_sort_by_value(self, checked = False):
655                 self._unitsModel.sort(1)
656
657         @misc_utils.log_exception(_moduleLogger)
658         def _on_sort_by_unit(self, checked = False):
659                 self._unitsModel.sort(3, QtCore.Qt.DescendingOrder)
660
661         @misc_utils.log_exception(_moduleLogger)
662         def _on_unit_clicked(self, index):
663                 self._select_unit(index.row())
664
665         @misc_utils.log_exception(_moduleLogger)
666         def _on_value_edited(self, *args):
667                 userInput = self._selectedUnitValue.text()
668                 self._unitsModel.update_values(self._selectedIndex, str(userInput))
669
670         def _select_unit(self, index):
671                 unit = self._unitsModel.get_unit(index)
672                 self._selectedUnitName.setText(unit.name)
673                 self._selectedUnitValue.setText(str(unit.value))
674                 self._selectedUnitSymbol.setText(unit.unit)
675
676                 self._selectedIndex = index
677                 qindex = self._unitsModel.createIndex(index, 0, self._unitsModel.get_unit(index))
678                 self._unitsView.scrollTo(qindex)
679                 self._app.add_recent(self._categoryName, self._unitsModel.get_unit(index).name)
680
681
682 def run_gonvert():
683         app = QtGui.QApplication([])
684         handle = Gonvert()
685         return app.exec_()
686
687
688 if __name__ == "__main__":
689         logging.basicConfig(level = logging.DEBUG)
690         try:
691                 os.makedirs(constants._data_path_)
692         except OSError, e:
693                 if e.errno != 17:
694                         raise
695
696         val = run_gonvert()
697         sys.exit(val)