GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Sep 21, 2014 4:05 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [Solved]Can anyone explain how pygtkmvc connects signals?
PostPosted: Tue Jul 01, 2014 2:13 am 
Offline
Familiar Face

Joined: Tue Oct 08, 2013 5:16 am
Posts: 20
Thanks for your help.
I'm trying to understand how Pygtkmvc connects signals. I have a project called "Sandbox" that I'm developing with GTK3, so I can't use Pygtkmvc. I need to understand how the signals should be connected. Connecting the signals in the view is trivial, so how do I do it in the control module?

sandapp.py
Code:
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-

from gi.repository import Gtk


def setup_path():
    """Sets up the python include paths to include needed directories"""
    import os.path
    import sys
    from src.utils.globals import TOPDIR
    sys.path.insert(0, reduce(os.path.join, (TOPDIR, "resources", "external")))
    sys.path.insert(0, os.path.join(TOPDIR, "src"))
    return


def check_requirements():
    """Checks versions and other requirements"""
    import gtkmvc
    gtkmvc.require("1.99.1")
    return


def main(*args, **kargs):
    from models.sandmodel import SandModel as SandModel
    from ctrls.sandcontrol import SandCtrl as SandCtrl
    from views.sandview import SandView as SandView

    m = SandModel()
    v = SandView()
    SandCtrl(m, v)

    Gtk.main()
    return

if __name__ == "__main__":
    setup_path()
    #check_requirements()
    main()
    pass


sandcontrol.py
Code:
# -*- coding: utf-8 -*-

from gi.repository import Gtk


class SandCtrl(object):

    def __init__(self, m, v):
        #Controller.__init__(self, model, view)
        self.builder = v.builder
        #v.app_window()
        #self.register_view(v)
        return

    def register_view(self):
        # setup of widgets
        sigs = {'on_sandwindow_destroy': self.on_sandwindow_destroy,
            }
        self.builder.connect_signals(sigs)
        #self.builder.connect('on_sandwindow_delete_event',
                            #self.on_sandwindow_delete_event)
        return

    def register_adapters(self):
        # setup of adapters
        return

    # ---------------------------------------------------------------
    #        Signal handlers
    # ---------------------------------------------------------------
    def on_sandwindow_delete_event(self, win, event):
        Gtk.main_quit()  # say goodbye
        return True

    # ---------------------------------------------------------------
    #        Notifications from observable properties
    # ---------------------------------------------------------------

    # For value-change notifications
#     @Controller.observe("<property_name_here>", assign=True)
#     def value_change(self, model, prop_name, info):
#         # info contains 'new' and 'old' values
#         return

    # For value-change of containers like lists, maps, or method calls for
    # observable class instances.
    # There exist 'before' and 'after' versions, you can use both or only one,
    # depending on your need.
#     @Controller.observe("<property_name_here>", before=True, after=True)
#     def method_call(self, model, prop_name, info):
#         # Info contains:
#         # 'instance' is the object that is being changed
            # (the list for example)
#         # 'method_name' is the name of the method that is used to change it
            # ('append' for example)
#         # 'args' is the list of arguments of the invoked method 'name'
#         # 'kwargs' is the keywords map of the invoked method 'name'
#         # 'result' (only for 'after' notifications)
            # the value returned by the method after the call
#         return
#

    #@Controller.observe("somevalue", assign=True)
    def somevalue_change(self, model, prop_name, info):
        return

    pass  # end of class SandCtrl


sandview.py
Code:
# -*- coding: utf-8 -*-

import utils.globals

from gi.repository import Gtk
import os.path


class SandView (object):
    #glade = os.path.join(utils.globals.GLADE_DIR, "sandbox.glade")
    top = "window_appl"

    def __init__(self):
        #View.__init__(self)
        self.gladefile = os.path.join(utils.globals.GLADE_DIR, "sandbox.glade")
        self.builder = Gtk.Builder()
        self.builder.add_from_file(self.gladefile)
        self.sandwindow = self.builder.get_object("sandwindow")
        #sigs = {'on_sandwindow_destroy': self.on_sandwindow_destroy,
            #}
        #self.builder.connect_signals(sigs)
        self.sandwindow.show()

        # construction of manual widgets and other settings
        return

    def on_sandwindow_destroy(self, event):
        Gtk.main_quit()  # say goodbye
        return True

    pass  # end of class SandView

Edited to replace the file attachment with a corrected attachment.


Attachments:
sandbox-0.4.0.zip [24.31 KiB]
Not downloaded yet
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group