Improved HTML generation dialog.
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 6 Aug 2004 19:30:38 +0000 (19:30 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 6 Aug 2004 19:30:38 +0000 (19:30 +0000)
src/gkofoto/generatehtmldialog.py [new file with mode: 0644]
src/gkofoto/glade/gkofoto.glade
src/gkofoto/mainwindow.py

diff --git a/src/gkofoto/generatehtmldialog.py b/src/gkofoto/generatehtmldialog.py
new file mode 100644 (file)
index 0000000..ec8c7ef
--- /dev/null
@@ -0,0 +1,95 @@
+import gtk
+import os
+import re
+from sets import Set
+from environment import env
+import kofoto.generate
+
+class GenerateHTMLDialog:
+    def __init__(self, album):
+        self.album = album
+        self.widgets = gtk.glade.XML(
+            env.gladeFile, "generateHtmlDialog")
+        self.dialog = self.widgets.get_widget("generateHtmlDialog")
+        self.browseButton = self.widgets.get_widget("browseButton")
+        self.cancelButton = self.widgets.get_widget("cancelButton")
+        self.directoryTextEntry = self.widgets.get_widget("directoryTextEntry")
+        self.generateButton = self.widgets.get_widget("generateButton")
+
+        self.browseButton.connect("clicked", self._onBrowse)
+        self.cancelButton.connect("clicked", self._onCancel)
+        self.generateButton.connect("clicked", self._onGenerate)
+
+        self.directoryTextEntry.connect(
+            "changed", self._onDirectoryTextEntryModified)
+
+        self.generateButton.set_sensitive(False)
+
+    def run(self):
+        self.dialog.show()
+
+    def _onDirectoryTextEntryModified(self, *unused):
+        self.generateButton.set_sensitive(
+            os.path.isdir(self.directoryTextEntry.get_text()))
+
+    def _onBrowse(self, *unused):
+        def fileListChanged(widget):
+            model, iterator = widget.get_tree_view() \
+                .get_selection().get_selected()
+            dirDialog.ok_button.set_sensitive(iterator == None)
+        dirDialog = gtk.FileSelection(title="Choose directory")
+        dirDialog.file_list.get_selection().connect(
+            "changed", fileListChanged)
+        if dirDialog.run() == gtk.RESPONSE_OK:
+            self.directoryTextEntry.set_text(dirDialog.get_filename())
+        dirDialog.destroy()
+
+    def _onCancel(self, *unused):
+        self.dialog.destroy()
+
+    def _onGenerate(self, *unused):
+        for widget in [self.directoryTextEntry, self.browseButton,
+                       self.cancelButton, self.generateButton]:
+            widget.set_sensitive(False)
+        self._generate(self.directoryTextEntry.get_text())
+        self.dialog.destroy()
+
+    def _generate(self, directoryName):
+        # TODO: Rewrite this gross hack.
+
+        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()
+
+        progressBar = self.widgets.get_widget("progressBar")
+
+        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(self.album, None, directoryName, "latin1")
+        progressBar.set_fraction(1)
+        while gtk.events_pending():
+            gtk.main_iteration()
index cc081c5..504c95a 100644 (file)
@@ -2755,83 +2755,328 @@ The categories' children will not be destroyed, nor will the images associated w
   </child>
 </widget>
 
-<widget class="GtkDialog" id="generateHtmlProgressDialog">
+<widget class="GtkWindow" id="generateHtmlDialog">
   <property name="visible">True</property>
-  <property name="title" translatable="yes">Generating HTML...</property>
+  <property name="title" translatable="yes">Generate HTML</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
   <property name="window_position">GTK_WIN_POS_NONE</property>
   <property name="modal">True</property>
-  <property name="default_width">250</property>
   <property name="resizable">True</property>
   <property name="destroy_with_parent">False</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="has_separator">True</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
 
-  <child internal-child="vbox">
-    <widget class="GtkVBox" id="dialog-vbox8">
+  <child>
+    <widget class="GtkVBox" id="vbox15">
+      <property name="border_width">10</property>
       <property name="visible">True</property>
       <property name="homogeneous">False</property>
-      <property name="spacing">5</property>
+      <property name="spacing">0</property>
 
-      <child internal-child="action_area">
-       <widget class="GtkHButtonBox" id="dialog-action_area8">
+      <child>
+       <widget class="GtkLabel" id="label56">
          <property name="visible">True</property>
-         <property name="layout_style">GTK_BUTTONBOX_END</property>
+         <property name="label" translatable="yes">Please select a directory:</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">5</property>
+         <property name="expand">False</property>
+         <property name="fill">False</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkHBox" id="hbox12">
+         <property name="visible">True</property>
+         <property name="homogeneous">False</property>
+         <property name="spacing">0</property>
 
          <child>
-           <widget class="GtkButton" id="okButton">
+           <widget class="GtkEntry" id="directoryTextEntry">
+             <property name="visible">True</property>
+             <property name="can_focus">True</property>
+             <property name="editable">True</property>
+             <property name="visibility">True</property>
+             <property name="max_length">0</property>
+             <property name="text" translatable="yes"></property>
+             <property name="has_frame">True</property>
+             <property name="invisible_char" translatable="yes">*</property>
+             <property name="activates_default">False</property>
+           </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">True</property>
+             <property name="fill">True</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkButton" id="browseButton">
              <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="response_id">-5</property>
+             <property name="focus_on_click">True</property>
+
+             <child>
+               <widget class="GtkAlignment" id="alignment7">
+                 <property name="visible">True</property>
+                 <property name="xalign">0.5</property>
+                 <property name="yalign">0.5</property>
+                 <property name="xscale">0</property>
+                 <property name="yscale">0</property>
+                 <property name="top_padding">0</property>
+                 <property name="bottom_padding">0</property>
+                 <property name="left_padding">0</property>
+                 <property name="right_padding">0</property>
+
+                 <child>
+                   <widget class="GtkHBox" id="hbox14">
+                     <property name="visible">True</property>
+                     <property name="homogeneous">False</property>
+                     <property name="spacing">2</property>
+
+                     <child>
+                       <widget class="GtkImage" id="image219">
+                         <property name="visible">True</property>
+                         <property name="stock">gtk-open</property>
+                         <property name="icon_size">4</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="GtkLabel" id="label289">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">_Browse</property>
+                         <property name="use_underline">True</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>
+                   </widget>
+                 </child>
+               </widget>
+             </child>
            </widget>
+           <packing>
+             <property name="padding">15</property>
+             <property name="expand">False</property>
+             <property name="fill">False</property>
+           </packing>
          </child>
        </widget>
        <packing>
-         <property name="padding">0</property>
+         <property name="padding">5</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">
+       <widget class="GtkProgressBar" id="progressBar">
          <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>
+         <property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property>
+         <property name="fraction">2.23517e-10</property>
+         <property name="pulse_step">0.01</property>
        </widget>
        <packing>
-         <property name="padding">0</property>
+         <property name="padding">10</property>
          <property name="expand">False</property>
          <property name="fill">False</property>
        </packing>
       </child>
 
       <child>
-       <widget class="GtkProgressBar" id="progressBar">
+       <widget class="GtkHSeparator" id="hseparator1">
          <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>
+         <property name="fill">True</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkHButtonBox" id="hbuttonbox4">
+         <property name="visible">True</property>
+         <property name="layout_style">GTK_BUTTONBOX_END</property>
+         <property name="spacing">10</property>
+
+         <child>
+           <widget class="GtkButton" id="cancelButton">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+
+             <child>
+               <widget class="GtkAlignment" id="alignment11">
+                 <property name="visible">True</property>
+                 <property name="xalign">0.5</property>
+                 <property name="yalign">0.5</property>
+                 <property name="xscale">0</property>
+                 <property name="yscale">0</property>
+                 <property name="top_padding">0</property>
+                 <property name="bottom_padding">0</property>
+                 <property name="left_padding">0</property>
+                 <property name="right_padding">0</property>
+
+                 <child>
+                   <widget class="GtkHBox" id="hbox18">
+                     <property name="visible">True</property>
+                     <property name="homogeneous">False</property>
+                     <property name="spacing">2</property>
+
+                     <child>
+                       <widget class="GtkImage" id="image223">
+                         <property name="visible">True</property>
+                         <property name="stock">gtk-cancel</property>
+                         <property name="icon_size">4</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="GtkLabel" id="label67">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">_Cancel</property>
+                         <property name="use_underline">True</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>
+                   </widget>
+                 </child>
+               </widget>
+             </child>
+           </widget>
+         </child>
+
+         <child>
+           <widget class="GtkButton" id="generateButton">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="has_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+
+             <child>
+               <widget class="GtkAlignment" id="alignment12">
+                 <property name="visible">True</property>
+                 <property name="xalign">0.5</property>
+                 <property name="yalign">0.5</property>
+                 <property name="xscale">0</property>
+                 <property name="yscale">0</property>
+                 <property name="top_padding">0</property>
+                 <property name="bottom_padding">0</property>
+                 <property name="left_padding">0</property>
+                 <property name="right_padding">0</property>
+
+                 <child>
+                   <widget class="GtkHBox" id="hbox19">
+                     <property name="visible">True</property>
+                     <property name="homogeneous">False</property>
+                     <property name="spacing">2</property>
+
+                     <child>
+                       <widget class="GtkImage" id="image224">
+                         <property name="visible">True</property>
+                         <property name="stock">gtk-ok</property>
+                         <property name="icon_size">4</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="GtkLabel" id="label68">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">_Generate</property>
+                         <property name="use_underline">True</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>
+                   </widget>
+                 </child>
+               </widget>
+             </child>
+           </widget>
+         </child>
+       </widget>
+       <packing>
+         <property name="padding">10</property>
+         <property name="expand">False</property>
+         <property name="fill">True</property>
        </packing>
       </child>
     </widget>
index 32ba0de..ba90717 100644 (file)
@@ -12,6 +12,7 @@ from gkofoto.objectcollectionfactory import *
 from gkofoto.objectcollection import *
 from gkofoto.registerimagesdialog import RegisterImagesDialog
 from gkofoto.handleimagesdialog import HandleImagesDialog
+from gkofoto.generatehtmldialog import GenerateHTMLDialog
 
 class MainWindow(gtk.Window):
     def __init__(self):
@@ -116,72 +117,8 @@ class MainWindow(gtk.Window):
         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 = GenerateHTMLDialog(album)
         dialog.run()
-        dialog.destroy()
 
     def getIconImage(self, name):
         pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(env.iconDir, name))