Allow to load multiple widgets with get_builder()
This commit is contained in:
		
							parent
							
								
									c43714e4c2
								
							
						
					
					
						commit
						6c43c0f408
					
				
					 2 changed files with 14 additions and 10 deletions
				
			
		| 
						 | 
					@ -12,8 +12,10 @@
 | 
				
			||||||
# You should have received a copy of the GNU General Public License
 | 
					# You should have received a copy of the GNU General Public License
 | 
				
			||||||
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from typing import Tuple
 | 
					 | 
				
			||||||
from typing import Any
 | 
					from typing import Any
 | 
				
			||||||
 | 
					from typing import List
 | 
				
			||||||
 | 
					from typing import Tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
| 
						 | 
					@ -38,7 +40,7 @@ log = logging.getLogger('gajim.gtk.util')
 | 
				
			||||||
class Builder:
 | 
					class Builder:
 | 
				
			||||||
    def __init__(self,
 | 
					    def __init__(self,
 | 
				
			||||||
                 filename: str,
 | 
					                 filename: str,
 | 
				
			||||||
                 widget: str = None,
 | 
					                 widgets: List[str] = None,
 | 
				
			||||||
                 domain: str = None,
 | 
					                 domain: str = None,
 | 
				
			||||||
                 gettext_: Any = None) -> None:
 | 
					                 gettext_: Any = None) -> None:
 | 
				
			||||||
        self._builder = Gtk.Builder()
 | 
					        self._builder = Gtk.Builder()
 | 
				
			||||||
| 
						 | 
					@ -63,16 +65,16 @@ class Builder:
 | 
				
			||||||
                                   encoding='unicode',
 | 
					                                   encoding='unicode',
 | 
				
			||||||
                                   method='xml')
 | 
					                                   method='xml')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if widget is not None:
 | 
					            if widgets is not None:
 | 
				
			||||||
                self._builder.add_objects_from_string(xml_text, [widget])
 | 
					                self._builder.add_objects_from_string(xml_text, widgets)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                # Workaround
 | 
					                # Workaround
 | 
				
			||||||
                # https://gitlab.gnome.org/GNOME/pygobject/issues/255
 | 
					                # https://gitlab.gnome.org/GNOME/pygobject/issues/255
 | 
				
			||||||
                Gtk.Builder.__mro__[1].add_from_string(
 | 
					                Gtk.Builder.__mro__[1].add_from_string(
 | 
				
			||||||
                    self._builder, xml_text, len(xml_text.encode("utf-8")))
 | 
					                    self._builder, xml_text, len(xml_text.encode("utf-8")))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            if widget is not None:
 | 
					            if widgets is not None:
 | 
				
			||||||
                self._builder.add_objects_from_file(file_path, [widget])
 | 
					                self._builder.add_objects_from_file(file_path, widgets)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                self._builder.add_from_file(file_path)
 | 
					                self._builder.add_from_file(file_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,8 +85,8 @@ class Builder:
 | 
				
			||||||
            return self._builder.get_object(name)
 | 
					            return self._builder.get_object(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_builder(file_name: str, widget: str = None) -> Builder:
 | 
					def get_builder(file_name: str, widgets: List[str] = None) -> Builder:
 | 
				
			||||||
    return Builder(file_name, widget)
 | 
					    return Builder(file_name, widgets)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def load_icon(icon_name, widget, size=16, pixbuf=False,
 | 
					def load_icon(icon_name, widget, size=16, pixbuf=False,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,8 @@ Helper code related to plug-ins management system.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__all__ = ['log', 'log_calls', 'Singleton']
 | 
					__all__ = ['log', 'log_calls', 'Singleton']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from typing import List
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import functools
 | 
					import functools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,8 +137,8 @@ class Singleton(type):
 | 
				
			||||||
        return cls.instance
 | 
					        return cls.instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_builder(file_name: str, widget: str = None) -> Builder:
 | 
					def get_builder(file_name: str, widgets: List[str] = None) -> Builder:
 | 
				
			||||||
    return Builder(file_name,
 | 
					    return Builder(file_name,
 | 
				
			||||||
                   widget,
 | 
					                   widgets,
 | 
				
			||||||
                   domain=plugins_i18n.DOMAIN,
 | 
					                   domain=plugins_i18n.DOMAIN,
 | 
				
			||||||
                   gettext_=plugins_i18n._)
 | 
					                   gettext_=plugins_i18n._)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue