[pybliographer/gtk3: 10/25] search: Port dialog to gtk+3



commit 8da814be51e11958b88b996e987e439015ade179
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Sun Jun 2 22:35:53 2013 -0700

    search: Port dialog to gtk+3
    
    Signed-off-by: Germán Poo-Caamaño <gpoo gnome org>

 Pyblio/GnomeUI/Search.py          |  167 +++++++-------
 Pyblio/GnomeUI/glade/search.glade |  454 -------------------------------------
 Pyblio/GnomeUI/glade/search.ui    |  260 +++++++++++++++++++++
 3 files changed, 343 insertions(+), 538 deletions(-)
---
diff --git a/Pyblio/GnomeUI/Search.py b/Pyblio/GnomeUI/Search.py
index e3b94de..0ddd15d 100644
--- a/Pyblio/GnomeUI/Search.py
+++ b/Pyblio/GnomeUI/Search.py
@@ -1,8 +1,9 @@
+# -*- coding: utf-8 -*-
 # This file is part of pybliographer
 # 
-# Copyright (C) 1998-2004 Frederic GOBRY
-# Email : gobry pybliographer org
-#         
+# Copyright (C) 1998-2004 Frederic GOBRY <gobry pybliographer org>
+# Copyright (C) 2013 Germán Poo-Caamaño <gpoo gnome org>
+#
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2 
@@ -24,8 +25,7 @@
 
 import os
 
-# from gnome import ui
-from gi.repository import Gtk, GObject
+from gi.repository import Gdk, Gtk, GObject
 
 import string, re, sys, traceback, copy
 
@@ -46,72 +46,71 @@ class SearchDialog (Connector.Publisher, Utils.GladeWindow):
     
     '''
 
-    gladeinfo = { 'name': 'search',
-                  'file': 'search.glade',
-                  'root': '_w_search'
+    gladeinfo = { 'file': 'search.ui',
+                  'root': '_w_search',
+                  'name': 'search'
                   }
     
-    def __init__ (self, parent = None):
-
-        Utils.GladeWindow.__init__ (self, parent)
+    def __init__(self, parent=None):
+        Utils.GladeWindow.__init__(self, parent)
 
         # the tree model contains a string that explains the query,
         # and a python object representing the actual query.
         
-        self._model = Gtk.TreeStore (str, GObject.TYPE_PYOBJECT)
-        self._w_tree.set_model (self._model)
+        self._model = Gtk.TreeStore(str, GObject.TYPE_PYOBJECT)
+        self._w_tree.set_model(self._model)
 
         # the view does not display the python column, of course.
-        col = Gtk.TreeViewColumn ('field', Gtk.CellRendererText (), text = 0)
-        self._w_tree.append_column (col)
+        col = Gtk.TreeViewColumn('field', Gtk.CellRendererText(), text=0)
+        self._w_tree.append_column(col)
 
-        self._w_tree.expand_all ()
+        self._w_tree.expand_all()
         
         # The root of the search tree is the full database
-        self._model.append (None, (_("Full database"), None))
+        self._model.append(None, (_("Full database"), None))
 
 
         # Monitor the selected items
-        self._selection = self._w_tree.get_selection ()
-        self._selection.connect ('changed', self.selection)
-        
-        # fill the combo containing the available fields
-        self._w_field.set_popdown_strings ([' - any field - '] +
-                                          list (Config.get
-                                                ('gnome/searched').data) +
-                                          [' - type - ', ' - key - '])
+        self._selection = self._w_tree.get_selection()
+        self._selection.connect('changed', self.selection)
+
+        field_items = [' - any field - '] + \
+                      list(Config.get('gnome/searched').data) + \
+                      [' - type - ', ' - key - ']
+        for fields in field_items:
+            self._w_field.append_text(fields)
+
+        self._w_field.set_active(0)
 
         # connect a menu to the right button
-        self.menu = Gtk.Menu ()
-        self.delete_button = Utils.popup_add (self.menu, _("Delete"),
-                                              self.search_delete)
-        self.menu.show ()
+        self.menu = Gtk.Menu()
+        self.delete_button = Utils.popup_add(self.menu, _("Delete"),
+                                             self.search_delete)
 
         # We are set up.
-        self.show ()
-        return
+        self.show()
 
 
-    def show (self):
+    def show(self):
         ''' Invoked to show the interface again when it has been closed '''
         
-        self._w_search.show ()
+        self._w_search.show()
         return
 
 
-    def close_cb (self, widget):
+    def close_cb(self, widget):
         ''' Invoked to hide the interface when clicking on "Close" '''
 
-        self.size_save ()
-        self._w_search.hide ()
+        self.size_save()
+        self._w_search.hide()
         return
     
 
-    def apply_cb (self, widget):
+    def apply_cb(self, widget):
 
         ''' Construct the new query and add it to the query tree '''
         
-        page = self._w_notebook.get_current_page ()
+        page = self._w_notebook.get_current_page()
 
         name = None
         
@@ -128,29 +127,29 @@ class SearchDialog (Connector.Publisher, Utils.GladeWindow):
                 'after' :    TextUI.after,
                 }
             
-            search = self._w_expert_text.get_text ().encode ('latin-1')
+            search = self._w_expert.get_active_text().encode('latin-1')
             
             try:
                 exec ('tester = ' + search, user_global)
             except:
-                etype, value, tb = sys.exc_info ()
-               traceback.print_exception (etype, value, tb)
-
-                d = Gtk.MessageDialog (self._w_search,
-                                       Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
-                                       Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
-                                       _("internal error during evaluation"))
-                d.run ()
-                d.destroy ()
+                etype, value, tb = sys.exc_info()
+                traceback.print_exception(etype, value, tb)
+
+                d = Gtk.MessageDialog(self._w_search,
+                                      Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
+                                      Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
+                                      _("internal error during evaluation"))
+                d.run()
+                d.destroy()
                 return
 
-            test = user_global ['tester']
+            test = user_global['tester']
 
         # Simple Search
         elif page == 0:
             
-            field = self._w_field_text.get_text ().lower ()
-            match = self._w_pattern_text.get_text ()
+            field = self._w_field.get_active_text().lower()
+            match = self._w_pattern.get_active_text()
             
             if match == '': return
 
@@ -158,7 +157,7 @@ class SearchDialog (Connector.Publisher, Utils.GladeWindow):
 
             if field == ' - any field - ' or field == '':
                 try:
-                    test = Search.AnyTester (match.encode ('latin-1'))
+                    test = Search.AnyTester(match.encode('latin-1'))
                 except re.error, err:
                     error = 1
                     
@@ -166,37 +165,37 @@ class SearchDialog (Connector.Publisher, Utils.GladeWindow):
 
             elif field == ' - type - ':
                 # get the type description
-                the_type = Types.get_entry (string.lower (match), 0)
+                the_type = Types.get_entry(string.lower(match), 0)
 
                 if the_type is None:
                     err = ['No such Entry type']
                     error = 1
                 else:
                     try:
-                        test = Search.TypeTester (the_type)
+                        test = Search.TypeTester(the_type)
                     except re.error, err:
                         error = 1
 
             elif field == ' - key - ':
                 try:
-                    test = Search.KeyTester (match)
+                    test = Search.KeyTester(match)
                 except re.error, err:
                     error = 1
 
             else:
                 try:
-                    test = Search.Tester (field, match)
+                    test = Search.Tester(field, match)
                 except re.error, err:
                     error = 1
                 
             if error:
-                d = Gtk.MessageDialog (self._w_search,
-                                       Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
-                                       Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
-                                       _("while compiling %s\nerror: %s") %
-                                       (match, err [0]))
-                d.run ()
-                d.destroy ()
+                d = Gtk.MessageDialog(self._w_search,
+                                      Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
+                                      Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
+                                      _("while compiling %s\nerror: %s") %
+                                      (match, err [0]))
+                d.run()
+                d.destroy()
                 return
             
         # No search
@@ -204,69 +203,69 @@ class SearchDialog (Connector.Publisher, Utils.GladeWindow):
             return
 
         if name is None:
-            name = str (test)
+            name = str(test)
 
         # Get the path to the query being refined
-        s, iter = self._selection.get_selected ()
-        if iter is None: iter = s.get_iter ((0,))
+        s, parent = self._selection.get_selected()
+        if parent is None: parent = s.get_iter((0,))
 
-        i = s.get_path (iter)
+        parent_path = s.get_path(parent)
 
         # If we are refining a previous query, build the new query as
         # a logical and of the previous and new query.
         
-        current = self._model [i] [1]
+        current = self._model[parent_path][1]
         if current: test = current & test
 
         # Add the new query in the tree and ensure it is visible and selected.
-        iter = self._model.append (iter, (name, test))
-        path = s.get_path (iter)
+        child = self._model.append(parent, (name, test))
+        path = s.get_path(child)
         
-        self._w_tree.expand_row (path [:-1], True)
-        self._selection.select_path (path)
+        self._w_tree.expand_row(parent_path, True)
+        self._selection.select_path(path)
         return
 
     
-    def selection (self, *arg):
+    def selection(self, *arg):
 
         ''' Called when the user clicks on a specific query '''
         
-        s, i = self._selection.get_selected ()
+        s, i = self._selection.get_selected()
         if i is None: return
         
-        data = self._model [s.get_path (i)]
+        data = self._model[s.get_path (i)]
 
-        self.issue ('search-data', * data)
+        self.issue('search-data', * data)
         return
 
     
-    def popup_menu (self, w, event, *arg):
+    def popup_menu(self, w, event, *arg):
 
         ''' Called when the user right-clicks in the query tree '''
         
         if (event.type != Gdk.EventType.BUTTON_PRESS or
             event.button != 3): return
         
-        self.menu.popup (None, None, None, event.button, event.time)
+        self.menu.popup (None, None, None, None, event.button, event.time)
 
         # Only allow removal when a valid query is selected
-        s, i = self._selection.get_selected ()
-        self.delete_button.set_sensitive (i is not None and
-                                          s [i][1] is not None)
+        s, i = self._selection.get_selected()
+        self.delete_button.set_sensitive(i is not None and
+                                         s [i][1] is not None)
         return
     
 
-    def search_delete (self, *arg):
+    def search_delete(self, *arg):
         
         ''' Called when the user deletes a query in the tree '''
 
-        s, i = self._selection.get_selected ()
+        s, i = self._selection.get_selected()
         if i is None: return
 
         # Do not allow removal of the root.
         if s [i][1] is None: return
         
-        self._model.remove (i)
+        self._model.remove(i)
         return
 
 
diff --git a/Pyblio/GnomeUI/glade/search.ui b/Pyblio/GnomeUI/glade/search.ui
new file mode 100644
index 0000000..e11696f
--- /dev/null
+++ b/Pyblio/GnomeUI/glade/search.ui
@@ -0,0 +1,260 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="_w_search">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Search</property>
+    <property name="type_hint">normal</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-close</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+                <property name="yalign">0.47999998927116394</property>
+                <signal name="clicked" handler="close_cb" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button2">
+                <property name="label" translatable="yes">_Search</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <signal name="clicked" handler="apply_cb" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkNotebook" id="_w_notebook">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hexpand">False</property>
+                <property name="vexpand">False</property>
+                <child>
+                  <object class="GtkTable" id="table1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="valign">start</property>
+                    <property name="border_width">6</property>
+                    <property name="n_rows">2</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">6</property>
+                    <property name="row_spacing">6</property>
+                    <child>
+                      <object class="GtkLabel" id="label5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Field</property>
+                      </object>
+                      <packing>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label6">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Pattern</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="_w_field">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="has_entry">True</property>
+                        <property name="entry_text_column">0</property>
+                        <property name="id_column">1</property>
+                        <child internal-child="entry">
+                          <object class="GtkEntry" id="field-entry">
+                            <property name="can_focus">False</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="_w_pattern">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="has_entry">True</property>
+                        <property name="entry_text_column">0</property>
+                        <property name="id_column">1</property>
+                        <child internal-child="entry">
+                          <object class="GtkEntry" id="pattern-entry">
+                            <property name="can_focus">True</property>
+                            <property name="has_focus">True</property>
+                            <signal name="activate" handler="apply_cb" swapped="no"/>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+                <child type="tab">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Simple Search</property>
+                  </object>
+                  <packing>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="box1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="border_width">6</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkLabel" id="label4">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Query</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="_w_expert">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="valign">center</property>
+                        <property name="has_entry">True</property>
+                        <property name="entry_text_column">0</property>
+                        <property name="id_column">1</property>
+                        <child internal-child="entry">
+                          <object class="GtkEntry" id="comboboxtext-entry5">
+                            <property name="can_focus">True</property>
+                            <signal name="activate" handler="apply_cb" swapped="no"/>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child type="tab">
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Expert Search</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">always</property>
+                <property name="vscrollbar_policy">always</property>
+                <child>
+                  <object class="GtkTreeView" id="_w_tree">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="headers_visible">False</property>
+                    <signal name="button-press-event" handler="popup_menu" swapped="no"/>
+                    <child internal-child="selection">
+                      <object class="GtkTreeSelection" id="treeview-selection"/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">button1</action-widget>
+      <action-widget response="0">button2</action-widget>
+    </action-widgets>
+  </object>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]