Beispiel #1
0
    def __init__(self, width, height, collection=None):
        # Temporary placeholder for kwargs of the update() method.
        self.__lastargs = None

        ScrolledWindow.__init__(self, width, height)

        self._spacing = 0

        # The item cursor position within the list.
        self._cursor = None

        # Used for selections.
        self._last_direction = None

        self._signals[SIG_LISTCHANGED] = []
        self._signals[SIG_SELECTCHANGED] = []

        # Items and selection.
        self._itemcollection = None
        self._selectionmode = SELECTION_MULTIPLE
        if collection:
            self.set_items(collection)
        else:
            self._itemcollection = ListItemCollection()
            self._itemcollection.list_changed = self._list_has_changed
            self._itemcollection.item_changed = self._item_has_changed
        self.child = ListViewPort(self)
    def __init__ (self, width, height, collection=None):
        # Temporary placeholder for kwargs of the update() method.
        self.__lastargs = None

        ScrolledWindow.__init__ (self, width, height)

        self._spacing = 0

        # The item cursor position within the list.
        self._cursor = None

        # Used for selections.
        self._last_direction = None

        self._signals[SIG_LISTCHANGED] = []
        self._signals[SIG_SELECTCHANGED] = []

        # Items and selection.
        self._itemcollection = None
        self._selectionmode = SELECTION_MULTIPLE
        if collection:
            self.set_items (collection)
        else:
            self._itemcollection = ListItemCollection ()
            self._itemcollection.list_changed = self._list_has_changed
            self._itemcollection.item_changed = self._item_has_changed
        self.child = ListViewPort (self)
Beispiel #3
0
    def notify(self, event):
        """S.notify (...) -> None

        Notifies the ScrolledList about an event.
        """
        if not self.sensitive:
            return

        if self.focus and (event.signal == SIG_KEYDOWN):
            if len(self.items) > 0:
                self._navigate(event.data.key, event.data.mod)
                event.handled = True
        elif event.signal == SIG_MOUSEDOWN:
            eventarea = self.rect_to_client()
            if eventarea.collidepoint(event.data.pos):
                for c in self.controls:
                    c.notify(event)
                if not event.handled:
                    self.focus = True
                    self.run_signal_handlers(SIG_MOUSEDOWN, event.data)
                    if event.data.button == 1:
                        self._click(event.data.pos)
                    else:
                        ScrolledWindow.notify(self, event)
                event.handled = True
        else:
            ScrolledWindow.notify(self, event)
    def notify (self, event):
        """S.notify (...) -> None

        Notifies the ScrolledList about an event.
        """
        if not self.eventarea or not self.sensitive:
            return

        if event.signal == SIG_MOUSEDOWN:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "ScrolledList.MOUSEDOWN"
                self.focus = True
                self.run_signal_handlers (SIG_MOUSEDOWN)
                if event.data.button == 1:
                    # Get the item and toggle the selection.
                    item = self.child.get_item_at_pos (event.data.pos)
                    if item:
                        if item.selected:
                            if pygame.key.get_mods () & \
                                   pygame.locals.KMOD_CTRL:
                                self.deselect (item)
                        else:
                            self.select (item)
                else:
                    # TODO: Mouse wheel scrolling - one item per time.
                    ScrolledWindow.notify (self, event)
        else:
            ScrolledWindow.notify (self, event)
    def notify (self, event):
        """S.notify (...) -> None

        Notifies the ScrolledList about an event.
        """
        if not self.sensitive:
            return

        if self.focus and (event.signal == SIG_KEYDOWN):
            if len (self.items) > 0:
                self._navigate (event.data.key, event.data.mod)
                event.handled = True
        elif event.signal == SIG_MOUSEDOWN:
            eventarea = self.rect_to_client ()
            if eventarea.collidepoint (event.data.pos):
                for c in self.controls:
                    c.notify (event)
                if not event.handled:
                    self.focus = True
                    self.run_signal_handlers (SIG_MOUSEDOWN, event.data)
                    if event.data.button == 1:
                        self._click (event.data.pos)
                    else:
                        ScrolledWindow.notify (self, event)
                event.handled = True
        else:
            ScrolledWindow.notify (self, event)
    def __init__ (self, width, height, collection=None):
        ScrolledWindow.__init__ (self, width, height)
        self._spacing = 2
        
        # Items and selection.
        self._selectionmode = SELECTION_MULTIPLE
        self.child = _ListViewPort (self)
        if collection:
            self.set_items (collection)

        self._signals[SIG_LISTCHANGE] = []
        self._signals[SIG_SELECTCHANGE] = []
Beispiel #7
0
    def set_focus(self, focus=True):
        """S.set_focus (...) -> bool

        Sets the input and action focus of the ScrolledList.
        
        Sets the input and action focus of the ScrolledList and returns
        True upon success or False, if the focus could not be set.
        """
        if focus != self.focus:
            self.lock()
            if focus and not self._cursor and (len(self.items) > 0):
                self._cursor = self.items[0]
                self._cursor.selected = True
            ScrolledWindow.set_focus(self, focus)
            self.unlock()
        return self.focus
    def set_child (self, child=None):
        """B.set_child (...) -> None

        Sets (or resets) the child of the ScrolledList.

        Creates a parent-child relationship from the ScrolledLsit to the
        child by associating the ScrolledList with the child and vice versa.

        Raises a TypeError, if the passed argument does not inherit
        from the _ListViewPort class.
        """
        if child and not isinstance (child, _ListViewPort):
            raise TypeError ("child must inherit from _ListViewPort")
        ScrolledWindow.set_child (self, child)
        if child:
            self.child.itemcollection.list_changed = self._list_has_changed
    def set_focus (self, focus=True):
        """S.set_focus (...) -> bool

        Sets the input and action focus of the ScrolledList.
        
        Sets the input and action focus of the ScrolledList and returns
        True upon success or False, if the focus could not be set.
        """
        if focus != self.focus:
            self.lock ()
            if focus and not self._cursor and (len (self.items) > 0):
                self._cursor = self.items[0]
                self._cursor.selected = True
            ScrolledWindow.set_focus (self, focus)
            self.unlock ()
        return self.focus
Beispiel #10
0
    def __init__(self, obj, attr):
        super(TextEditor, self).__init__()
        self.obj = obj
        self.attr = attr
        self.set_title("Editing %s.%s" % (repr(obj), attr))
        self.set_default_size(400, 600)
        self.connect('destroy', self.on_close)

        self.text = gtk.TextView()
        buffer = self.text.get_buffer()
        buffer.set_text(getattr(obj, attr))

        #buffer.connect_object("changed", self.on_text_updated)
        #buffer.connect_object("mark_set", self.on_cursor_moved)
        self.add(ScrolledWindow(self.text))
        self.show_all()
Beispiel #11
0
 def addPageSorts(self, persoVw, sortsSuppl=[], sortsDebtCombatSuppl=[]):
     tab_names = [persoVw.caracsNotebk.tab(i, option="text") for i in persoVw.caracsNotebk.tabs()]
     if "Sorts" in tab_names:
         persoVw.caracsNotebk.forget(tab_names.index("Sorts"))
     classe = persoVw.perso["Perso"]["Classe"]
     lvl = persoVw.perso["Perso"]["Level"]
     frameSorts = LabelFrame(persoVw.framePerso, text="Sorts")
     sorts, sortsDebtCombat = Personnages.Personnage.chargerSorts(classe, lvl, {}, True)
     sorts += sortsSuppl
     sortsDebtCombat += sortsDebtCombatSuppl
     for extSort in [x for x in persoVw.perso["Sorts"] if "::" in x]:
         classe, nom_sort = extSort.split("::")
         sortsSuppl, sortsDebtCombatSuppl = Personnages.Personnage.chargerSorts(classe, lvl, {nom_sort:1}, False, 1)
         for sortSuppl in sortsSuppl:
             sortSuppl.nom = classe+"::"+nom_sort
         for sortDebtCombatSuppl in sortsDebtCombatSuppl:
             sortDebtCombatSuppl.nom = classe+"::"+nom_sort
         sorts += sortsSuppl
         sortsDebtCombat += sortsDebtCombatSuppl
     self.variantesFrame = ScrolledWindow(frameSorts, width=400, height=400)
     persoVw.sortsLignes = 0
     persoVw.images = []
     if "Sorts" not in persoVw.inputs:
         persoVw.inputs["Sorts"] = dict()
     addedSpells = {}
     for sort in sorts+sortsDebtCombat:
         if not sort.lancableParJoueur:
             continue
         isVariante = sort.nom_variante != "" and sort.nom_variante in addedSpells
         root_pic1 = Image.open(sort.image)                       # Open the image like this first
         persoVw.images.append(ImageTk.PhotoImage(root_pic1))
         if not isVariante:
             persoVw.sortsLignes += 1
         ind = persoVw.sortsLignes
         imgLbl = Label(self.variantesFrame.scrollwindow, image=persoVw.images[-1], anchor="nw")
         imgLbl.grid(row=ind, column=2 if isVariante else 0, sticky="e")
         varSort = IntVar()
         varSort.set(persoVw.perso["Sorts"].get(sort.nom, 0))
         persoVw.inputs["Sorts"][sort.nom] = varSort
         cbSort = Checkbutton(self.variantesFrame.scrollwindow, text=sort.nom, variable=varSort, onvalue=1, offvalue=0, anchor="w")
         cbSort.grid(row=ind, column=3 if isVariante else 1, sticky="w")
         addedSpells[sort.nom] = ind
     
     addSortButton = Button(frameSorts, text="Ajout Sort/Item", command=self.ajoutSort)
     addSortButton.grid()
     persoVw.caracsNotebk.add(frameSorts, text="Sorts")
Beispiel #12
0
    def __init__(self, tab):
        super(ValidationWindow, self).__init__()
        self.tab = tab
        self.set_title("Validation errors in %s" % tab.get_name())

        self.connect('delete_event', self.on_close)

        self.tv = ValidationView()
        self.tv.on_select_object = tab.window.navigate
        self.tv.set_errors(tab.document.validation_result.errors)

        self.add(ScrolledWindow(self.tv._treeview))
        width, height = self.tv._treeview.size_request()
        width = min(width + 10, max(self.width, self.max_width))
        height = min(height + 10, max(self.height, self.max_height))
        self.set_default_size(width, height)

        self.show_all()
Beispiel #13
0
class EditorWindow(gtk.Window):
    odMLHomepage = "http://www.g-node.org/projects/odml"
    registry = DocumentRegistry()
    editors = set()
    welcome_disabled_actions = ["Save", "SaveAs", "NewSection", "NewProperty", "NewValue", "Delete", "CloneTab", "Map", "Validate"]

    def __init__(self, parent=None):
        gtk.Window.__init__(self)
        self.editors.add(self)
        try:
            self.set_screen(parent.get_screen())
        except AttributeError:
            self.connect('delete-event', self.close)

        self.set_title("odML Editor")
        self.set_default_size(800, 600)

        icons = load_icon_pixbufs("odml-logo")
        self.set_icon_list(*icons)

        merge = gtk.UIManager()
        merge.connect('connect-proxy', self.on_uimanager__connect_proxy)
        merge.connect('disconnect-proxy', self.on_uimanager__disconnect_proxy)
        self.set_data("ui-manager", merge)
        merge.insert_action_group(self.__create_action_group(), 0)
        self.add_accel_group(merge.get_accel_group())

        try:
            mergeid = merge.add_ui_from_string(ui_info)
        except gobject.GError, msg:
            print "building menus failed: %s" % msg
        bar = merge.get_widget("/MenuBar")
        bar.show()

        table = gtk.Table(2, 6, False)
        self.add(table)

        table.attach(bar,
                     # X direction #          # Y direction
                     0, 2,                      0, 1,
                     gtk.EXPAND | gtk.FILL,     0,
                     0,                         0);

        bar = merge.get_widget("/ToolBar")
        bar.set_tooltips(True)
        bar.show()
        table.attach(bar,
                     # X direction #       # Y direction
                     0, 2,                   1, 2,
                     gtk.EXPAND | gtk.FILL,  0,
                     0,                      0)

        tool_button = merge.get_widget("/ToolBar/Open")
        tool_button.connect("clicked", self.open_file)
        tool_button.set_arrow_tooltip_text("Open a recently used file")
        tool_button.set_label("Open")
        tool_button.set_tooltip_text("Open Files")

        navigation_bar = NavigationBar()
#        table.attach(navigation_bar,
#                     # X direction           Y direction
#                     1, 2,                   1, 2,
#                     0,                      0,
#                     0,                      0)
        navigation_bar.on_selection_change = self.on_navigate
        self._navigation_bar = navigation_bar

        # schematic organization
        #  -vpaned---------------------------
        # | -hpaned-----+-------------------
        # ||            | -property_view(vbox)
        # || scrolled:  | | info_bar
        # ||  section_tv| +----------------
        # ||            | | scrolled: property_tv
        # ||            | \----------------
        # |\------------+-------------------
        # +----------------------------------
        # |  --frame: navigation bar -------
        # | +-------------------------------
        # | | scrolled: _property_view
        # | \-------------------------------
        # \----------------------------------
        hpaned = gtk.HPaned()
        hpaned.show()
        hpaned.set_position(150)

        section_tv = SectionView(self.registry)
        section_tv.execute = self.execute
        section_tv.on_section_change = self.on_section_change
        section_view = gtk.VBox(homogeneous=False, spacing=0)
        tmp = gtk.Frame("Sections")
        tmp.add(ScrolledWindow(section_tv._treeview))
        tmp.show()
        section_view.pack_start(tmp, True, True, 1)
        section_view.show()
        hpaned.add1(section_view)

        property_tv = PropertyView(self.registry)
        property_tv.execute = self.execute
        property_tv.on_property_select = self.on_object_select
        property_view = gtk.VBox(homogeneous=False, spacing=0)

        info_bar = EditorInfoBar ()
        self._info_bar = info_bar
        property_view.pack_start(info_bar, False, False, 1)
        tmp = gtk.Frame("Properties")
        tmp.add(ScrolledWindow(property_tv._treeview))
        tmp.show()
        property_view.pack_start(tmp, True, True, 1)
        property_view.show()
        hpaned.add2(property_view)

        self._property_tv = property_tv
        self._section_tv = section_tv

        # property_view to edit ODML-Properties

        # to edit properties of Document, Section or Property:
        self._property_view = AttributeView(self.execute)
        frame = gtk.Frame()
        frame.set_label_widget(navigation_bar)
        frame.add(ScrolledWindow(self._property_view._treeview))
        frame.show()

        vpaned = gtk.VPaned()
        vpaned.show()
        vpaned.set_position(350)
        vpaned.pack1(hpaned, resize=True, shrink=False)
        vpaned.pack2(frame, resize=False, shrink=True)

        class Tab(gtk.HBox):
            """
            a tab container
            """
            child = vpaned

        self.Tab = Tab

        notebook = gtk.Notebook() # we want tabs
        notebook.connect("switch-page", self.on_tab_select)
        notebook.connect("create-window", self.on_new_tab_window)
        notebook.show()
        self.notebook = notebook

        table.attach (notebook,
                      # X direction           Y direction
                      0, 2,                   3, 4,
                      gtk.EXPAND | gtk.FILL,  gtk.EXPAND | gtk.FILL,
                      0,                      0)

        statusbar = gtk.Statusbar()
        table.attach(statusbar,
                     # X direction           Y direction
                     0, 2,                   5, 6,
                     gtk.EXPAND | gtk.FILL,  0,
                     0,                      0)
        self._statusbar = statusbar
        statusbar.show()

        #if not filename is None:
        #    self.load_document(filename)
        #else:
        #    self._info_bar.show_info("Welcome to the G-Node odML Editor 0.1")
        #    self.new_file(None)

        self.show_all()
Beispiel #14
0
 def init(self):
     self.view = CheckableSectionView(None)
     self.pack_start(ScrolledWindow(self.view._treeview), True, True, 0)