moved size_convert function and about dialog outside MVC scope mosfet/mvc
authorEugene Gagarin <mosfet07@ya.ru>
Fri, 10 Apr 2009 14:04:15 +0000 (18:04 +0400)
committerEugene Gagarin <mosfet07@ya.ru>
Fri, 10 Apr 2009 14:04:15 +0000 (18:04 +0400)
src/mvc/controllers/application.py
src/mvc/controllers/debsearch.py
src/mvc/controllers/filesearch.py
src/mvc/misc/__init__.py [new file with mode: 0755]
src/mvc/misc/about.py [new file with mode: 0755]
src/mvc/misc/functions.py [new file with mode: 0755]

index c4cf508..023c167 100755 (executable)
@@ -4,7 +4,7 @@ import gtk
 from filesearch import FilesearchCtrl
 from debsearch import DebsearchCtrl
 
-from views.about import AboutView
+import misc.about
 
 
 class ApplicationCtrl(Controller):
@@ -42,7 +42,7 @@ class ApplicationCtrl(Controller):
     # -----------------------------------------------------
 
     def on_about_btn_clicked(self, tb):
-        AboutView() # this runs in modal mode
+        misc.about.About() # this runs in modal mode
 
     def on_quit_btn_clicked(self, bt):
         self.quit()
index 2a2a5f8..675c71b 100755 (executable)
@@ -10,6 +10,7 @@ import apt_pkg
 from heapq import nlargest
 
 from views.debsearch import DebsearchView
+from misc.functions import *
 
 
 class DebsearchCtrl(Controller):
@@ -44,14 +45,6 @@ class DebsearchCtrl(Controller):
                 pkgsize = [version.InstalledSize for version in pkg.VersionList][0]
                 yield pkgsize, pkg.Name
 
-    def size_convert(self, size):
-        """Return string with package size in b or Kb or Mb or Gb or Tb."""
-
-        for i, unit in enumerate(['%d b', '%.1f Kb', '%.2f Mb', '%.3f Gb', '%.4f Tb']):
-            if size < 1024**(i+1):
-                return unit % (size/1024.**i)
-        return '>1024 Tb'
-
     # -----------------------------------------------------
     #                    gtk signals
     # -----------------------------------------------------
@@ -75,7 +68,7 @@ class DebsearchCtrl(Controller):
         # Get biggest packages
         for psize, packg in nlargest(self.model.quantity, self.debgetter()):
             # Fill treemodel: package name, size as string, byte size
-            self.view['liststore'].append([packg, self.size_convert(psize), psize])
+            self.view['liststore'].append([packg, size_convert(psize), psize])
 
         self.view['start_btn'].set_sensitive(True)
         self.view['stop_btn'].set_sensitive(False)
index dbb2bee..17e1d8c 100755 (executable)
@@ -10,8 +10,8 @@ from os import walk
 from os.path import join, abspath, normcase, getsize
 from heapq import nlargest
 
-#from filesearch import FilesearchCtrl
 from views.filesearch import FilesearchView
+from misc.functions import *
 
 
 class FilesearchCtrl(Controller):
@@ -66,14 +66,6 @@ class FilesearchCtrl(Controller):
                 except OSError:
                     continue
 
-    def size_convert(self, size):
-        """Return string with file size in b or Kb or Mb or Gb or Tb."""
-
-        for i, unit in enumerate(['%d b', '%.1f Kb', '%.2f Mb', '%.3f Gb', '%.4f Tb']):
-            if size < 1024**(i+1):
-                return unit % (size/1024.**i)
-        return '>1024 Tb'
-
     # -----------------------------------------------------
     #                    gtk signals
     # -----------------------------------------------------
@@ -102,7 +94,7 @@ class FilesearchCtrl(Controller):
         for fsize, fpath in nlargest(self.model.quantity, self.filegetter(start_path)):
             # Заполняем treemodel: путь, размер в Мб строкой, размер в байтах
 #             try:
-                self.view['liststore'].append([fpath, self.size_convert(fsize), fsize])
+                self.view['liststore'].append([fpath, size_convert(fsize), fsize])
 #             except:
 #                 print type(fpath), type(self.size_convert(fsize)), type(fsize)
 
diff --git a/src/mvc/misc/__init__.py b/src/mvc/misc/__init__.py
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/src/mvc/misc/about.py b/src/mvc/misc/about.py
new file mode 100755 (executable)
index 0000000..9565119
--- /dev/null
@@ -0,0 +1,33 @@
+import gtk
+
+from __main__ import __version__, __progname__
+
+
+class About(gtk.AboutDialog):
+    """About dialog window."""
+
+    def __init__(self):
+        """Create&show about dialog."""
+        gtk.AboutDialog.__init__(self)
+
+        self.progname = __progname__
+        self.version = __version__
+        self.authors = [    'Alex Taker\n   * Email: alteker@gmail.com\n',
+                        'Eugene Gagarin\n   * Email: mosfet07@ya.ru\n',
+                        'Alexandr Popov\n   * Email: popov2al@gmail.com' ]
+        self.comments = 'Tool for find some information on computer.'
+        self.license = \
+'This program is free software; you can redistribute it and/or\nmodify it \
+under the terms of the GNU General Public License\nas published by the Free \
+Software Foundation; either version 3\nof the License, or (at your option) \
+any later version.'
+
+        self.set_name(self.progname)
+        self.set_version(self.version)
+        self.set_authors(self.authors)
+        self.set_comments(self.comments)
+        self.set_license(self.license)
+
+        self.show_all()
+        self.run()
+        self.destroy()
diff --git a/src/mvc/misc/functions.py b/src/mvc/misc/functions.py
new file mode 100755 (executable)
index 0000000..915119b
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+# -*-coding: utf-8 -*-
+# vim: sw=4 ts=4 expandtab ai
+# pylint: disable-msg=C0301
+
+
+def size_convert(size):
+    """Return string with package size in b or Kb or Mb or Gb or Tb."""
+
+    for i, unit in enumerate(['%d b', '%.1f Kb', '%.2f Mb', '%.3f Gb', '%.4f Tb']):
+        if size < 1024**(i+1):
+            return unit % (size/1024.**i)
+    return '>1024 Tb'