Added (crude and limited) possibility of generating HTML output from
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 31 Jul 2004 11:56:48 +0000 (11:56 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 31 Jul 2004 11:56:48 +0000 (11:56 +0000)
gkofoto.

src/gkofoto/albums.py
src/gkofoto/glade/gkofoto.glade
src/gkofoto/mainwindow.py
src/gkofoto/objectcollection.py
src/gkofoto/objectcollectionview.py
src/gkofoto/singleobjectview.py
src/gkofoto/tableview.py

index 281dd13..9f53690 100644 (file)
@@ -13,6 +13,7 @@ class Albums:
 
     __createAlbumLabel = "Create child album..."
     __registerImagesLabel = "Register and add images..."
+    __generateHtmlLabel = "Generate HTML..."
     __destroyAlbumLabel = "Destroy album..."
     __editAlbumLabel = "Album properties..."
 
@@ -69,6 +70,7 @@ class Albums:
         albumModel, iterator =  self.__albumView.get_selection().get_selected()
         createMenuItem = self.__menuGroup[self.__createAlbumLabel]
         registerMenuItem = self.__menuGroup[self.__registerImagesLabel]
+        generateHtmlMenuItem = self.__menuGroup[self.__generateHtmlLabel]
         destroyMenuItem = self.__menuGroup[self.__destroyAlbumLabel]
         editMenuItem = self.__menuGroup[self.__editAlbumLabel]
         if iterator:
@@ -81,6 +83,8 @@ class Albums:
             env.widgets["menubarCreateAlbumChild"].set_sensitive(album.isMutable())
             registerMenuItem.set_sensitive(album.isMutable())
             env.widgets["menubarRegisterAndAddImages"].set_sensitive(album.isMutable())
+            generateHtmlMenuItem.set_sensitive(True)
+            env.widgets["menubarGenerateHtml"].set_sensitive(True)
             destroyMenuItem.set_sensitive(album != env.shelf.getRootAlbum())
             env.widgets["menubarDestroy"].set_sensitive(album != env.shelf.getRootAlbum())
             editMenuItem.set_sensitive(True)
@@ -88,10 +92,12 @@ class Albums:
         else:
             createMenuItem.set_sensitive(False)
             registerMenuItem.set_sensitive(False)
+            generateHtmlMenuItem.set_sensitive(False)
             destroyMenuItem.set_sensitive(False)
             editMenuItem.set_sensitive(False)
             env.widgets["menubarCreateAlbumChild"].set_sensitive(False)
             env.widgets["menubarRegisterAndAddImages"].set_sensitive(False)
+            env.widgets["menubarGenerateHtml"].set_sensitive(False)
             env.widgets["menubarDestroy"].set_sensitive(False)
             env.widgets["menubarProperties"].set_sensitive(False)
 
@@ -104,9 +110,15 @@ class Albums:
         selectedAlbumId = albumModel.get_value(iterator, self.__COLUMN_ALBUM_ID)
         selectedAlbum = env.shelf.getAlbum(selectedAlbumId)
         dialog = RegisterImagesDialog(selectedAlbum)
-        dialog.run()
+        if dialog.run() == gtk.RESPONSE_OK:
+            self.__mainWindow.reload() # TODO: don't reload everything.
         dialog.destroy()
-        self.__mainWindow.reload() # TODO: don't reload everything.
+
+    def _generateHtml(self, *dummies):
+        albumModel, iterator =  self.__albumView.get_selection().get_selected()
+        selectedAlbumId = albumModel.get_value(iterator, self.__COLUMN_ALBUM_ID)
+        selectedAlbum = env.shelf.getAlbum(selectedAlbumId)
+        self.__mainWindow.generateHtml(selectedAlbum)
 
     def _createAlbumHelper(self, tag, desc):
         newAlbum = env.shelf.createAlbum(tag)
@@ -170,6 +182,7 @@ class Albums:
         for widgetName, function in [
                 ("menubarCreateAlbumChild", self._createChildAlbum),
                 ("menubarRegisterAndAddImages", self._registerImages),
+                ("menubarGenerateHtml", self._generateHtml),
                 ("menubarProperties", self._editAlbum),
                 ("menubarDestroy", self._destroyAlbum),
                 ]:
@@ -184,6 +197,7 @@ class Albums:
         for widgetName in [
                 "menubarCreateAlbumChild",
                 "menubarRegisterAndAddImages",
+                "menubarGenerateHtml",
                 "menubarProperties",
                 ]:
             env.widgets[widgetName].set_sensitive(False)
@@ -225,6 +239,8 @@ class Albums:
             self.__createAlbumLabel, self._createChildAlbum)
         self.__menuGroup.addMenuItem(
             self.__registerImagesLabel, self._registerImages)
+        self.__menuGroup.addMenuItem(
+            self.__generateHtmlLabel, self._generateHtml)
         self.__menuGroup.addMenuItem(
             self.__destroyAlbumLabel, self._destroyAlbum)
         self.__menuGroup.addStockImageMenuItem(
index 3d2124c..4cb362f 100644 (file)
                      <signal name="activate" handler="on_register_and_add_images1_activate" last_modification_time="Sun, 11 Jul 2004 19:57:53 GMT"/>
                    </widget>
                  </child>
+
+                 <child>
+                   <widget class="GtkMenuItem" id="menubarGenerateHtml">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">_Generate HTML...</property>
+                     <property name="use_underline">True</property>
+                     <signal name="activate" handler="on_menubarGenerateHtml_activate" last_modification_time="Thu, 29 Jul 2004 16:31:19 GMT"/>
+                   </widget>
+                 </child>
                </widget>
              </child>
            </widget>
@@ -2730,4 +2739,89 @@ The categories' children will not be destroyed, nor will the images associated w
   </child>
 </widget>
 
+<widget class="GtkDialog" id="generateHtmlProgressDialog">
+  <property name="visible">True</property>
+  <property name="title" translatable="yes">Generating HTML...</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="has_separator">True</property>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="dialog-vbox8">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">5</property>
+
+      <child internal-child="action_area">
+       <widget class="GtkHButtonBox" id="dialog-action_area8">
+         <property name="visible">True</property>
+         <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+         <child>
+           <widget class="GtkButton" id="okButton">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="label">gtk-ok</property>
+             <property name="use_stock">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="response_id">-5</property>
+           </widget>
+         </child>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">False</property>
+         <property name="fill">True</property>
+         <property name="pack_type">GTK_PACK_END</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkLabel" id="label52">
+         <property name="visible">True</property>
+         <property name="label" translatable="yes">Generating HTML...</property>
+         <property name="use_underline">False</property>
+         <property name="use_markup">False</property>
+         <property name="justify">GTK_JUSTIFY_LEFT</property>
+         <property name="wrap">False</property>
+         <property name="selectable">False</property>
+         <property name="xalign">0.5</property>
+         <property name="yalign">0.5</property>
+         <property name="xpad">0</property>
+         <property name="ypad">0</property>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">False</property>
+         <property name="fill">False</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkProgressBar" id="progressBar">
+         <property name="visible">True</property>
+         <property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property>
+         <property name="fraction">0</property>
+         <property name="pulse_step">0.01</property>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">False</property>
+         <property name="fill">False</property>
+       </packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
 </glade-interface>
index 0b766a7..32ba0de 100644 (file)
@@ -98,9 +98,9 @@ class MainWindow(gtk.Window):
 
     def registerImages(self, widget, data):
         dialog = RegisterImagesDialog()
-        dialog.run()
+        if dialog.run() == gtk.RESPONSE_OK:
+            self.reload() # TODO: don't reload everything.
         dialog.destroy()
-        self.reload() # TODO: don't reload everything.
 
     def handleModifiedOrRenamedImages(self, widget, data):
         dialog = HandleImagesDialog()
@@ -115,6 +115,74 @@ class MainWindow(gtk.Window):
         aboutDialog.run()
         aboutDialog.destroy()
 
+    def generateHtml(self, album):
+        # TODO: Rewrite this gross hack.
+
+        import kofoto.generate
+        import re
+
+        def outputParser(string):
+            m = re.match(
+                r"Creating album (\S+) \((\d+) of (\d+)\)",
+                string,
+                re.UNICODE)
+            if m:
+                progressBar.set_text(m.group(1).decode("latin1"))
+                progressBar.set_fraction(
+                    (int(m.group(2)) - 1) / float(m.group(3)))
+                while gtk.events_pending():
+                    gtk.main_iteration()
+
+        fileSelectionDialog = gtk.FileSelection(title="Generate HTML")
+        if fileSelectionDialog.run() != gtk.RESPONSE_OK:
+            fileSelectionDialog.destroy()
+            return
+
+        directoryName = fileSelectionDialog.get_filename()
+        if not os.path.isdir(directoryName):
+            dialog = gtk.MessageDialog(
+                type=gtk.MESSAGE_ERROR,
+                buttons=gtk.BUTTONS_OK,
+                message_format="Not a directory: %s" % directoryName)
+            dialog.run()
+            dialog.destroy()
+            fileSelectionDialog.destroy()
+            return
+
+        fileSelectionDialog.destroy()
+
+        widgets = gtk.glade.XML(env.gladeFile, "generateHtmlProgressDialog")
+        dialog = widgets.get_widget("generateHtmlProgressDialog")
+        progressBar = widgets.get_widget("progressBar")
+        okButton = widgets.get_widget("okButton")
+        okButton.set_sensitive(False)
+
+        env.out = outputParser
+        env.verbose = True
+        env.thumbnailsizelimit = env.config.getcoordlist(
+            "album generation", "thumbnail_size_limit")[0]
+        env.defaultsizelimit = env.config.getcoordlist(
+            "album generation", "default_image_size_limit")[0]
+
+        imgsizesval = env.config.getcoordlist(
+            "album generation", "other_image_size_limits")
+        imgsizesset = Set(imgsizesval) # Get rid of duplicates.
+        defaultlimit = env.config.getcoordlist(
+            "album generation", "default_image_size_limit")[0]
+        imgsizesset.add(defaultlimit)
+        imgsizes = list(imgsizesset)
+        imgsizes.sort(lambda x, y: cmp(x[0] * x[1], y[0] * y[1]))
+        env.imagesizelimits = imgsizes
+
+        generator = kofoto.generate.Generator(u"woolly", env)
+        generator.generate(album, None, directoryName, "latin1")
+        progressBar.set_fraction(1)
+        while gtk.events_pending():
+            gtk.main_iteration()
+        okButton.set_sensitive(True)
+        dialog.run()
+        dialog.destroy()
+
     def getIconImage(self, name):
         pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(env.iconDir, name))
         image = gtk.Image()
index 2a33d36..e00a4f1 100644 (file)
@@ -72,6 +72,9 @@ class ObjectCollection(object):
     def getRegisterImagesLabel(self):
         return "Register and add images..."
 
+    def getGenerateHtmlLabel(self):
+        return "Generate HTML..."
+
     def getAlbumPropertiesLabel(self):
         return "Album properties..."
 
@@ -337,12 +340,20 @@ class ObjectCollection(object):
         selectedAlbum.setChildren(children)
         env.mainwindow.reloadAlbumTree()
 
-    def registerAndAddImages(self, widget, data):
+    def registerAndAddImages(self, *unused):
         selectedObjects = self.__objectSelection.getSelectedObjects()
         assert len(selectedObjects) == 1 and selectedObjects[0].isAlbum()
         selectedAlbum = selectedObjects[0]
         dialog = RegisterImagesDialog(selectedAlbum)
-        dialog.run()
+        if dialog.run() == gtk.RESPONSE_OK:
+            env.mainwindow.reload() # TODO: Don't reload everything.
+        dialog.destroy()
+
+    def generateHtml(self, *unused):
+        selectedObjects = self.__objectSelection.getSelectedObjects()
+        assert len(selectedObjects) == 1 and selectedObjects[0].isAlbum()
+        selectedAlbum = selectedObjects[0]
+        env.mainwindow.generateHtml(selectedAlbum)
 
     def albumProperties(self, widget, data):
         selectedObjects = self.__objectSelection.getSelectedObjects()
index b18a233..7f57d5c 100644 (file)
@@ -182,17 +182,20 @@ class ObjectCollectionView:
                     self.__albumMenuGroup.enable()
                     env.widgets["menubarCreateAlbumChild"].set_sensitive(True)
                     env.widgets["menubarRegisterAndAddImages"].set_sensitive(True)
+                    env.widgets["menubarGenerateHtml"].set_sensitive(True)
                     env.widgets["menubarProperties"].set_sensitive(True)
                 else:
                     self.__albumMenuGroup.disable()
                     self.__albumMenuGroup[self._objectCollection.getAlbumPropertiesLabel()].set_sensitive(True)
                     env.widgets["menubarCreateAlbumChild"].set_sensitive(False)
                     env.widgets["menubarRegisterAndAddImages"].set_sensitive(False)
+                    env.widgets["menubarGenerateHtml"].set_sensitive(True)
                     env.widgets["menubarProperties"].set_sensitive(True)
             else:
                 self.__albumMenuGroup.disable()
                 env.widgets["menubarCreateAlbumChild"].set_sensitive(False)
                 env.widgets["menubarRegisterAndAddImages"].set_sensitive(False)
+                env.widgets["menubarGenerateHtml"].set_sensitive(False)
                 env.widgets["menubarProperties"].set_sensitive(False)
             if albumsSelected == 0 and imagesSelected > 0:
                 self.__imageMenuGroup.enable()
@@ -216,6 +219,7 @@ class ObjectCollectionView:
             self.__albumMenuGroup.disable()
             env.widgets["menubarCreateAlbumChild"].set_sensitive(False)
             env.widgets["menubarRegisterAndAddImages"].set_sensitive(False)
+            env.widgets["menubarGenerateHtml"].set_sensitive(False)
             env.widgets["menubarProperties"].set_sensitive(False)
 
             self.__imageMenuGroup.disable()
@@ -299,6 +303,8 @@ class ObjectCollectionView:
             oc.getCreateAlbumChildLabel(), oc.createAlbumChild)
         menuGroup.addMenuItem(
             oc.getRegisterImagesLabel(), oc.registerAndAddImages)
+        menuGroup.addMenuItem(
+            oc.getGenerateHtmlLabel(), oc.generateHtml)
         menuGroup.addStockImageMenuItem(
             oc.getAlbumPropertiesLabel(),
             gtk.STOCK_PROPERTIES,
index 1162035..c4d7f2e 100644 (file)
@@ -75,6 +75,7 @@ class SingleObjectView(ObjectCollectionView, ImageView):
                 "menubarProperties",
                 "menubarCreateAlbumChild",
                 "menubarRegisterAndAddImages",
+                "menubarGenerateHtml",
                 ]:
             env.widgets[widgetName].set_sensitive(False)
 
index f1f963c..1710148 100644 (file)
@@ -159,6 +159,7 @@ class TableView(ObjectCollectionView):
                 ("menubarSelectAll", lambda x: widget.get_selection().select_all()),
                 ("menubarCreateAlbumChild", oc.createAlbumChild),
                 ("menubarRegisterAndAddImages", oc.registerAndAddImages),
+                ("menubarGenerateHtml", oc.generateHtml),
                 ("menubarProperties", oc.albumProperties),
                 ]:
             w = env.widgets[widgetName]
@@ -186,6 +187,7 @@ class TableView(ObjectCollectionView):
                 "menubarSelectAll",
                 "menubarCreateAlbumChild",
                 "menubarRegisterAndAddImages",
+                "menubarGenerateHtml",
                 "menubarProperties",
                 ]:
             env.widgets[widgetName].set_sensitive(False)