File: multifilebuilder.py

package info (click to toggle)
linuxcnc 1%3A2.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 285,604 kB
  • sloc: python: 202,568; ansic: 109,036; cpp: 99,239; tcl: 16,054; xml: 10,631; sh: 10,303; makefile: 1,255; javascript: 138; sql: 72; asm: 15
file content (53 lines) | stat: -rw-r--r-- 1,905 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- python -*-
#    Copyright (C) 2014 Jeff Epler <jepler@unpythonic.net>
#
#    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 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from gi.repository import Gtk

__all__ = ['MultiFileBuilder']

class MultiFileBuilder:
    def __init__(self):
        self.builders = []
        self.domain = None

    def set_translation_domain(self, domain):
        self.domain = domain

    def connect_signals(self, obj):
        for b in self.builders: b.connect_signals(obj)

    def add_from_file(self, fn):
        builder = Gtk.Builder()
        if self.domain is not None: builder.set_translation_domain(self.domain)

        self.builders.append(builder)
        builder.add_from_file(fn)

    def add_from_string(self, strg):
        builder = Gtk.Builder()
        if self.domain is not None: builder.set_translation_domain(self.domain)

        self.builders.append(builder)
        builder.add_from_string(strg)

    def get_object(self, obj):
        objects = [builder.get_object(obj) for builder in self.builders]
        objects = [o for o in objects if o]
        if not objects: return None
        if len(objects) > 1: raise ValueError("""Use of object with duplicate ID -> '%s'"""% obj)
        return objects[0]