Added properties dialog
authorEugene Gagarin <mosfet07@ya.ru>
Tue, 17 Feb 2009 14:39:49 +0000 (17:39 +0300)
committerEugene Gagarin <mosfet07@ya.ru>
Tue, 17 Feb 2009 14:39:49 +0000 (17:39 +0300)
findit.py
ru.po
ru/LC_MESSAGES/findit.mo
welcome

index 09e8f4d..9f22d55 100755 (executable)
--- a/findit.py
+++ b/findit.py
@@ -6,22 +6,30 @@ import gtk
 import gobject
 import pango
 from os import walk
-from os.path import getsize, join, isdir, abspath, normcase
+from os.path import join, abspath, normcase, basename
+from os.path import isdir, getsize, getatime, getmtime
 from heapq import nlargest
 import gettext
 import sys
+import time
 
 try: import hildon; hildonFound = True
 except: hildonFound = False
 
+
 try:
-    # Подразумевается, что ru/LC_MESSAGES/program.mo находится в текущем каталоге (sys.path[0])
-    # Для стандартного /usr/share/locale писать gettext.translation('findit')
-    langRU = gettext.translation('findit', sys.path[0], languages=['ru'])
-    langRU.install()
+    # Ищем перевод в /usr/share/locale
+    lang = gettext.translation('findit')
+    lang.install()
 except:
-    # Закомментировать перед использованием pygettext
-    def _(text): return text
+    try:
+        # Иначе, ищем в ./ru/LC_MESSAGES/findit.mo
+        langRU = gettext.translation('findit', sys.path[0], languages=['ru'])
+        langRU.install()
+    except:
+        # Нет и там - используем захардкоженный текст
+        # (закомментировать перед использованием pygettext)
+        def _(text): return text
 
 
 ### Common functions ###########################################################
@@ -47,9 +55,9 @@ def filegetter(startpath, obj):
                     ignore_dirs.remove(ign_dir)
 
         for fname in fnames:
-            flpath = join(dirpath, fname)
+            flpath = abspath(join(dirpath, fname))
             # Выводим текущий опрашиваемый файл в строку статуса
-            obj.currFileLbl.set_text(abspath(flpath))
+            obj.currFileLbl.set_text(flpath)
             # обновляем окно
             gtk.main_iteration()
             # Останавливаем цикл по нажатию кнопки стоп
@@ -60,7 +68,7 @@ def filegetter(startpath, obj):
             try:    flsize = getsize(flpath)
             except: continue
             # Возвращаем размер и полный путь файла
-            yield flsize, abspath(flpath)
+            yield flsize, flpath
 
 # Fullscreen
 def toggle_fullscreen(obj):
@@ -74,6 +82,52 @@ def on_key_press(obj, event):
     if hildonFound and event.keyval == gtk.keysyms.F6:
         toggle_fullscreen(obj)
 
+### Properties dialog ##########################################################
+
+class PropertiesDialog(gtk.Dialog):
+    def __init__(self, path, size, bytesize):
+        gtk.Dialog.__init__(self)
+        self.set_title( _('File properties') )
+        self.set_transient_for(app)
+        self.set_wmclass('PropertiesDialog', 'FindIT')
+        self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+        name = basename(path)
+
+        access = time.strftime('%x %X', time.localtime(getatime(path)))
+        modified = time.strftime('%x %X', time.localtime(getmtime(path)))
+
+        table = gtk.Table(2, 2, True)
+        table.set_border_width(10)
+        table.set_col_spacings(10)
+        table.set_row_spacings(10)
+
+        nameLbl = gtk.Label( _('Name') )
+        nameValueLbl = gtk.Label(name)
+
+        sizeLbl = gtk.Label( _('Size') )
+        sizeValueLbl = gtk.Label(size + ' (' + `bytesize` + ' b)')
+
+        accessLbl = gtk.Label( _('Opened') )
+        accessValueLbl = gtk.Label(access)
+
+        modifiedLbl = gtk.Label( _('Modified') )
+        modifiedValueLbl = gtk.Label(modified)
+
+        table.attach(nameLbl, 0, 1, 0, 1)
+        table.attach(nameValueLbl, 1, 2, 0, 1)
+        table.attach(sizeLbl, 0, 1, 1, 2)
+        table.attach(sizeValueLbl, 1, 2, 1, 2)
+        table.attach(accessLbl, 0, 1, 2, 3)
+        table.attach(accessValueLbl, 1, 2, 2, 3)
+        table.attach(modifiedLbl, 0, 1, 3, 4)
+        table.attach(modifiedValueLbl, 1, 2, 3, 4)
+
+        self.vbox.add(table)
+        self.show_all()
+        self.run()
+        self.destroy()
+
 ### Main window ################################################################
 
 class MainWindow(gtk.Window):
@@ -83,6 +137,7 @@ class MainWindow(gtk.Window):
         dialog = gtk.MessageDialog(parent=self, flags=gtk.DIALOG_MODAL,
                                    type=mestype, buttons=gtk.BUTTONS_OK,
                                    message_format=content)
+        dialog.set_wmclass('ErrorDialog', 'FindIT')
         dialog.set_title( _('Error!') )
         dialog.run()
         dialog.destroy()
@@ -94,6 +149,7 @@ class MainWindow(gtk.Window):
         if isdir(self.start_path):
             self.butt_start.set_sensitive(False)
             self.butt_stop.set_sensitive(True)
+            self.propertiesBtn.set_sensitive(False)
             # Получаем значение количества файлов из SpinButton
             self.fl_cnt = int( self.file_cnt.get_value() )
             # Очищаем список
@@ -111,13 +167,28 @@ class MainWindow(gtk.Window):
                 except: 'error', fpath, size_convert(fsize), fsize
             self.butt_start.set_sensitive(True)
             self.butt_stop.set_sensitive(False)
+            self.propertiesBtn.set_sensitive(True)
         else:
             # Иначе выводим окошко с ошибкой
-            self.mess_window(gtk.MESSAGE_ERROR, _('Invalid directory') )
+            self.mess_window('error', _('Invalid directory') )
 
+    # Функция выполняющаяся при нажатии на кнопку "Стоп"
     def stop_print(self, widget):
         self.stopit = True
 
+    # Функция выполняющаяся при нажатии на кнопку "Свойства файла"
+    def show_properties_dialog(self, btn):
+        selection = self.treeview.get_selection()
+        (model, it) = selection.get_selected()
+        try:
+            path = model.get_value(it, 0)
+            size = model.get_value(it, 1)
+            bytesize = model.get_value(it, 2)
+        except:
+            self.mess_window('error', _('Please select file') )
+            return
+        PropertiesDialog(path, size, bytesize)
+
     ### Window initialization ##################################################
 
     def __init__(self, win_width, win_height, st_path):
@@ -128,6 +199,7 @@ class MainWindow(gtk.Window):
         self.fullscreen = False
         self.connect('delete_event', gtk.main_quit)
         self.connect("key-press-event", on_key_press)
+        self.set_wmclass('MainWindow', 'FindIT')
 
         #########  Добавляем элементы ################
         # 1. Строка ввода каталога с которого начинать поиск
@@ -166,6 +238,11 @@ class MainWindow(gtk.Window):
         self.butt_stop.connect('clicked', self.stop_print)
         self.stopit = False
 
+        # 5.3 Кнопка "Свойства файла"
+        self.propertiesBtn = gtk.Button( _('File properties') )
+        self.propertiesBtn.connect('clicked', self.show_properties_dialog)
+        self.propertiesBtn.set_sensitive(False)
+
         # 6. Закладки
 
         # 6.1 Список файлов
@@ -174,10 +251,10 @@ class MainWindow(gtk.Window):
 
         # Определяем переменную в которой будет храниться выводимый список
         self.treestore = gtk.TreeStore(str, str, int)
-        treeview = gtk.TreeView(self.treestore)
+        self.treeview = gtk.TreeView(self.treestore)
         # На таблетке не отображаються заголовки столбцов по умолчанию -
         # след строка заставляет их отображаться принудительно
-        treeview.set_headers_visible(1)
+        self.treeview.set_headers_visible(1)
 
         self.treestore.append(None, ['','', 0])
 
@@ -187,16 +264,16 @@ class MainWindow(gtk.Window):
         cell.set_property('width', 90)
         size_col.pack_start(cell, True)
         size_col.add_attribute(cell, 'text', 1)
-        treeview.append_column(size_col)
+        self.treeview.append_column(size_col)
         # Создаем и настраиваем колонку с именем файла
         path_col = gtk.TreeViewColumn( _('Path') )
         cell2 = gtk.CellRendererText()
         path_col.pack_start(cell2, True)
         path_col.add_attribute(cell2, 'text', 0)
-        treeview.append_column(path_col)
+        self.treeview.append_column(path_col)
 
         # Добавляем сортировку для колонок
-        treeview.set_search_column(1)
+        self.treeview.set_search_column(1)
         path_col.set_sort_column_id(0)
         size_col.set_sort_column_id(2)
 
@@ -219,11 +296,12 @@ class MainWindow(gtk.Window):
         hbox1.pack_start(self.file_cnt, False, False, 0)
         hbox1.pack_start(self.butt_start, True, True, 0)
         hbox1.pack_start(self.butt_stop, True, True, 0)
+        hbox1.pack_start(self.propertiesBtn, True, True, 0)
 
         # Добавляем элементы в основной контейнер
         main_Vbox.pack_start(self.srch_p_entr, False, False, 0)
         main_Vbox.pack_start(hbox1, False, False, 0)
-        scrollwind.add(treeview)
+        scrollwind.add(self.treeview)
         main_Vbox.pack_start(scrollwind, True, True, 0)
         main_Vbox.pack_start(self.currFileLbl, False, False, 0)
 
@@ -239,4 +317,5 @@ class MainWindow(gtk.Window):
 
 if __name__ == '__main__':
 #    gobject.set_application_name( _('FindIT') )
-    MainWindow(575, 345, '/').run()
+    app = MainWindow(575, 345, '.')
+    app.run()
diff --git a/ru.po b/ru.po
index aa059d5..6df3ed1 100755 (executable)
--- a/ru.po
+++ b/ru.po
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2009-02-16 21:30+Московское время (зима)\n"
+"POT-Creation-Date: 2009-02-17 15:19+Russian Standard Time\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -15,31 +15,51 @@ msgstr ""
 "Generated-By: pygettext.py 1.5\n"
 
 
-#: findit.py:86
+#: findit.py:83 findit.py:231
+msgid "File properties"
+msgstr "Свойства файла"
+
+#: findit.py:96
+msgid "Name"
+msgstr "Имя"
+
+#: findit.py:99 findit.py:251
+msgid "Size"
+msgstr "Размер"
+
+#: findit.py:102
+msgid "Opened"
+msgstr "Открыт"
+
+#: findit.py:105
+msgid "Modified"
+msgstr "Изменен"
+
+#: findit.py:131
 msgid "Error!"
 msgstr "Ошибка!"
 
-#: findit.py:115
+#: findit.py:163
 msgid "Invalid directory"
 msgstr "Каталог не существует"
 
-#: findit.py:146
+#: findit.py:178
+msgid "Please select file"
+msgstr "Выберите файл в списке"
+
+#: findit.py:208
 msgid "Files quantity"
 msgstr "Количество файлов"
 
-#: findit.py:159
+#: findit.py:221
 msgid "Go"
 msgstr "Пуск"
 
-#: findit.py:163
+#: findit.py:225
 msgid "Stop"
 msgstr "Стоп"
 
-#: findit.py:184
-msgid "Size"
-msgstr "Размер"
-
-#: findit.py:191
+#: findit.py:258
 msgid "Path"
 msgstr "Путь"
 
index ebcd4af..22b22e4 100755 (executable)
Binary files a/ru/LC_MESSAGES/findit.mo and b/ru/LC_MESSAGES/findit.mo differ
diff --git a/welcome b/welcome
index e69de29..161b095 100644 (file)
--- a/welcome
+++ b/welcome
@@ -0,0 +1 @@
+Preved
\ No newline at end of file