當前位置: 首頁>>代碼示例>>Python>>正文


Python Button.connect方法代碼示例

本文整理匯總了Python中gtk.Button.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python Button.connect方法的具體用法?Python Button.connect怎麽用?Python Button.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gtk.Button的用法示例。


在下文中一共展示了Button.connect方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: command_dialog

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class command_dialog(Window):

    def __init__(self, icon):

        Window.__init__(self, WINDOW_TOPLEVEL)
        self.set_property("skip-taskbar-hint", True)
        self.set_property("destroy-with-parent", True)
        self.set_modal(True)
        self.set_position(WIN_POS_CENTER)

        self.vbox = VBox(False, 0)
        
        self.terminal = terminal()
        self.terminal.connect("child-exited",
                              lambda _: self.close_button.show())
        self.terminal.show()
        
        self.close_button = Button(stock=STOCK_CLOSE)
        self.close_button.connect("clicked", lambda _: self.destroy())

        self.vbox.pack_start(self.terminal, False, False, 0)
        self.vbox.pack_start(self.close_button, False, False, 0)
        self.vbox.show()

        self.add(self.vbox)

        self.set_icon(pixbuf_new_from_file(icon))

    def run(self, command):
        self.show()
        
        self.terminal.fork_command()
        self.terminal.feed_child("pacman --noconfirm -%s;exit\n" %command)
開發者ID:BackupTheBerlios,項目名稱:gtkpacman-svn,代碼行數:35,代碼來源:dialogs.py

示例2: __init__

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
 def __init__(self):
     tip=Tooltips()
     ok=Button(stock=STOCK_OK)
     ok.connect("clicked",self.ok_pressed)
     apply=Button(stock=STOCK_APPLY)
     apply.connect("clicked",self.apply_pressed)
     reset=Button(stock=STOCK_REDO)
     reset.connect("clicked",self.reset_pressed)
     cancel=Button(stock=STOCK_CANCEL)
     cancel.connect("clicked",self.cancel_pressed)
     self.add(ok)
     self.add(apply)
     self.add(reset)
     self.add(cancel)
開發者ID:LucyScott,項目名稱:mdsplus,代碼行數:16,代碼來源:mdsplusokbuttons.py

示例3: _GenDialog

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class _GenDialog(gtkDialog):
    def __init__(self, name='GenDialog'):
        gtkDialog.__init__(self)
        self.set_name(name)
        self.ok_button = Button('ok', 'gtk-ok')
        self.ok_button.set_name(name)
        self.cancel_button = Button('cancel', 'gtk-cancel')
        self.cancel_button.set_name(name)
        self.action_area.pack_start(self.ok_button, TRUE, TRUE, 0)
        self.action_area.pack_end(self.cancel_button, TRUE, TRUE, 0)
        self.ok_button.show()
        self.cancel_button.show()
        self.cancel_button.connect('clicked', lambda *x : self.destroy())
        self._buttons_ = {}
        self.show()

    def set_ok(self, ok_fun):
        self.ok_button.connect('clicked', ok_fun)

    def set_cancel(self, cancel_fun):
        self.cancel_button.connect('clicked', cancel_fun)
        self.connect('destroy', cancel_fun)

    def add_button(self, name, func, label='foo'):
        if name not in self._buttons_.keys():
            self._buttons_[name] = Button(label)
            self._buttons_[name].show()
            self._buttons_[name].connect('clicked', func)
            self.action_area.add(self._buttons_[name])
開發者ID:BackupTheBerlios,項目名稱:useless-svn,代碼行數:31,代碼來源:dialogs.py

示例4: initXdbox

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
 def initXdbox(self):
     self.xdbox=Window()
     try:
         self.xdbox.set_title(str(self.node))
     except:
         pass
     vbox=VBox()
     self.xdbox.expr=MDSplusExprWidget()
     vbox.pack_start(self.xdbox.expr,True,True,20)
     close=Button(stock=STOCK_CLOSE)
     close.connect("clicked",self.xdbox_close)
     redo=Button(stock=STOCK_REDO)
     redo.connect("clicked",self.xdbox_redo)
     cancel=Button(stock=STOCK_CANCEL)
     cancel.connect("clicked",self.xdbox_cancel)
     hbox=HBox()
     hbox.pack_start(close,False,False,20)
     hbox.pack_start(redo,False,False,20)
     hbox.pack_start(cancel,False,False,20)
     vbox.pack_start(hbox,False,False,20)
     self.xdbox.add(vbox)
     self.xdbox.expr.set_text(self.node_value())
開發者ID:LucyScott,項目名稱:mdsplus,代碼行數:24,代碼來源:mdsplusnidoptionwidget.py

示例5: MDSplusXdBox

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class MDSplusXdBox(props, MDSplusDtypeSelWidget, MDSplusWidget, Window):

    __gtype_name__ = "MDSplusXdBox"

    def inHBox(self, w):
        hb = HBox()
        hb.pack_start(w, False, False, 0)
        return hb

    def __init__(self, node=None, value=None):
        Window.__init__(self)
        MDSplusWidget.__init__(self)
        if node is not None:
            self.node = node
        else:
            self.value = value
        hbtop = HBox(homogeneous=False)
        self.on = CheckButton(label="On")
        self.parent_on = CheckButton(label="Parent")
        self.parent_on.set_sensitive(False)
        self.path = MDSplusPathWidget()
        if node is not None:
            self.path._node = self._node
        hbtags = HBox(homogeneous=False)
        self.tags = Entry()
        self.tags.set_width_chars(60)
        expression_menu = self.dtype_menu(tuple(), varname="dtype_expression", no_show=True)
        axis_menu = self.dtype_menu(("Range",), varname="dtype_axis", no_show=True)
        window_menu = self.dtype_menu(("Window",), varname="dtype_window", no_show=True)
        dispatch_menu = self.dtype_menu(("Dispatch",), varname="dtype_dispatch", no_show=True)
        action_menu = self.dtype_menu(("Action",), varname="dtype_action", no_show=True)
        task_menu = self.dtype_menu(("Method", "Routine"), varname="dtype_task", no_show=True)
        any_menu = self.dtype_menu(
            ("Range", "Window", "Dispatch", "Action", "Method", "Routine"), varname="dtype_any", no_show=True
        )
        menus = (
            self.dtype_expression,
            self.dtype_axis,
            self.dtype_dispatch,
            self.dtype_action,
            self.dtype_task,
            self.dtype_window,
            self.dtype_any,
        )
        hbtop.pack_start(self.on, False, False, 10)
        hbtop.pack_start(self.parent_on, False, False, 10)
        hbtop.pack_start(self.path, False, False, 0)
        hbtags.pack_start(Label("Tags:"), False, False, 10)
        hbtags.pack_start(self.tags, False, False, 0)
        self.action = MDSplusActionWidget()
        self.windoww = MDSplusWindowWidget()
        self.sequential = MDSplusSequentialWidget()
        self.expression = MDSplusExpressionWidget()
        self.method = MDSplusMethodWidget()
        self.routine = MDSplusRoutineWidget()
        self.dispatch = MDSplusDispatchWidget()
        self.range = MDSplusRangeWidget()
        self.widgets = (
            self.action,
            self.sequential,
            self.expression,
            self.method,
            self.routine,
            self.dispatch,
            self.range,
            self.windoww,
        )
        self.ok = Button(stock=STOCK_OK)
        self.cancel = Button(stock=STOCK_CANCEL)
        self.redo = Button(stock=STOCK_REDO)
        self.ok.connect("clicked", self.do_ok)
        self.cancel.connect("clicked", self.do_cancel)
        self.redo.connect("clicked", self.do_redo)
        hb2 = HBox()
        hb2.add(self.ok)
        hb2.add(self.redo)
        hb2.add(self.cancel)
        vb = VBox(homogeneous=False)
        vb.set_border_width(10)
        vb.pack_start(hbtop, False, False, 0)
        vb.pack_start(hbtags, False, False, 0)
        vb.pack_start(expression_menu, False, False, 0)
        vb.pack_start(axis_menu, False, False, 0)
        vb.pack_start(window_menu, False, False, 0)
        vb.pack_start(dispatch_menu, False, False, 0)
        vb.pack_start(action_menu, False, False, 0)
        vb.pack_start(task_menu, False, False, 0)
        vb.pack_start(any_menu, False, False, 0)
        for w in self.widgets:
            w.set_no_show_all(True)
            vb.pack_start(w, False, False, 0)
        vb.pack_start(hb2, False, False, 20)
        self.add(vb)
        self.do_redo(self.redo)
        self.putOnApply = True
        self.nidOffset = -1

    def set_dtype(self):
        if hasattr(self, "_node"):
            try:
#.........這裏部分代碼省略.........
開發者ID:LucyScott,項目名稱:mdsplus,代碼行數:103,代碼來源:mdsplusxdbox.py

示例6: MDSplusOnOffXdBoxWidget

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class MDSplusOnOffXdBoxWidget(props,MDSplusWidget,HBox):

    __gtype_name__ = 'MDSplusOnOffXdBoxWidget'
    __gproperties__= props.__gproperties__

    def reset(self):
        self.node_state.set_active(self.node.on)
        self.node_state.set_label('')
        if hasattr(self,'xdbox'):
            self.xdbox.reset()

    def apply(self):
        if self.putOnApply:
            if self.node.on != self.node_state.get_active():
                try:
                    self.node.on=self.node_state.get_active()
                except Exception:
                    if self.node_state.get_active():
                        state='on'
                    else:
                        state='off'
                    MDSplusErrorMsg('Error setting node on/off state','Error turning node %s %s\n\n%s' % (self.node.minpath,state,sys.exc_info()[1]))
                    raise
            if hasattr(self,'xdbox'):
                try:
                    if self.node.compare(self.xdbox.value) != 1:
                        self.node.record=self.xdbox.value
                    self.reset()
                except Exception:
                    MDSplusErrorMsg('Error storing value','Error storing value in to %s\n\n%s' % (self.node.minpath,sys.exc_info()[1]))

    def xd_state_changed(self,button):
        self.node_state.set_active(self.xdbox.on.get_active())

    def node_state_changed(self,button):
        self.xdbox.on.set_active(self.node_state.get_active())
        
    def popupXd(self,button):
        if not hasattr(self,'xdbox'):
            self.xdbox=MDSplusXdBox(self.node)
            self.xdbox.putOnApply=False
            self.xdbox.on.connect('toggled',self.xd_state_changed)
            self.node_state.connect('toggled',self.node_state_changed)
        self.xdbox.node=self.getNode()
        self.xdbox.set_title(self.buttonLabel)
        self.xdbox.on.set_active(self.node_state.get_active())
        self.xdbox.show()

    def setButtonLabel(self,button):
        self.button.set_label(self.buttonLabel)

    def __init__(self):
        HBox.__init__(self)
        MDSplusWidget.__init__(self)
        HBox.set_homogeneous(self,False)
        self.node_state=CheckButton('')
        self.button=Button()
        HBox.pack_start(self,self.node_state,False,False,0)
        HBox.pack_start(self,self.button,False,False,0)
        HBox.pack_start(self,Label(''),True,False,0)
        if not guibuilder:
            self.button.connect("clicked",self.popupXd)
        self.button.connect("realize",self.setButtonLabel)

    def show(self):
        self.show_all()
開發者ID:MDSplus,項目名稱:Python-TDISHR,代碼行數:68,代碼來源:mdsplusonoffxdbox.py

示例7: MDSplusXdBox

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class MDSplusXdBox(props,MDSplusDtypeSelWidget,MDSplusWidget,Window):

    __gtype_name__ = 'MDSplusXdBox'

    def inHBox(self,w):
        hb=HBox()
        hb.pack_start(w,False,False,0)
        return hb
        
    def __init__(self,node=None,value=None):
        Window.__init__(self)
        MDSplusWidget.__init__(self)
        if node is not None:
            self.node=node
        else:
            self.value=value
        hbtop=HBox(homogeneous=False)
        self.on=CheckButton(label="On")
        self.parent_on=CheckButton(label="Parent")
        self.parent_on.set_sensitive(False)
        self.path=MDSplusPathWidget()
        if node is not None:
            self.path._node=self._node
        hbtags=HBox(homogeneous=False)
        self.tags=Entry()
        self.tags.set_width_chars(60)
        expression_menu=self.dtype_menu(tuple(),varname='dtype_expression',no_show=True)
        axis_menu=self.dtype_menu(('Range',),varname='dtype_axis',no_show=True)
        window_menu=self.dtype_menu(('Window',),varname='dtype_window',no_show=True)
        dispatch_menu=self.dtype_menu(('Dispatch',),varname='dtype_dispatch',no_show=True)
        action_menu=self.dtype_menu(('Action',),varname='dtype_action',no_show=True)
        task_menu=self.dtype_menu(('Method','Routine'),varname='dtype_task',no_show=True)
        any_menu=self.dtype_menu(('Range','Window','Dispatch','Action','Method','Routine'),varname='dtype_any',no_show=True)
        menus=(self.dtype_expression,self.dtype_axis,self.dtype_dispatch,self.dtype_action,self.dtype_task,self.dtype_window,self.dtype_any)
        hbtop.pack_start(self.on,False,False,10)
        hbtop.pack_start(self.parent_on,False,False,10)
        hbtop.pack_start(self.path,False,False,0)
        hbtags.pack_start(Label("Tags:"),False,False,10)
        hbtags.pack_start(self.tags,False,False,0)
        self.action=MDSplusActionWidget()
        self.windoww=MDSplusWindowWidget()
        self.sequential=MDSplusSequentialWidget()
        self.expression=MDSplusExpressionWidget()
        self.method=MDSplusMethodWidget()
        self.routine=MDSplusRoutineWidget()
        self.dispatch=MDSplusDispatchWidget()
        self.range=MDSplusRangeWidget()
        self.widgets=(self.action,self.sequential,self.expression,self.method,self.routine,self.dispatch,self.range,self.windoww)
        self.ok=Button(stock=STOCK_OK)
        self.cancel=Button(stock=STOCK_CANCEL)
        self.redo=Button(stock=STOCK_REDO)
        self.ok.connect("clicked",self.do_ok)
        self.cancel.connect("clicked",self.do_cancel)
        self.redo.connect("clicked",self.do_redo)
        hb2=HBox()
        hb2.add(self.ok)
        hb2.add(self.redo)
        hb2.add(self.cancel)
        vb=VBox(homogeneous=False)
        vb.set_border_width(10)
        vb.pack_start(hbtop,False,False,0)
        vb.pack_start(hbtags,False,False,0)
        vb.pack_start(expression_menu,False,False,0)
        vb.pack_start(axis_menu,False,False,0)
        vb.pack_start(window_menu,False,False,0)
        vb.pack_start(dispatch_menu,False,False,0)
        vb.pack_start(action_menu,False,False,0)
        vb.pack_start(task_menu,False,False,0)
        vb.pack_start(any_menu,False,False,0)
        for w in self.widgets:
            w.set_no_show_all(True)
            vb.pack_start(w,False,False,0)
        vb.pack_start(hb2,False,False,20)
        self.add(vb)
        self.do_redo(self.redo)
        self.putOnApply = True
        self.nidOffset = -1

    def set_dtype(self):
        if hasattr(self,'_node'):
            try:
                exec 'self.dtype=self.dtype_%s' % (self.node.usage.lower(),)
            except Exception,e:
                self.dtype=self.dtype_expression
        else:
開發者ID:dgarnier,項目名稱:MDSplus-forked,代碼行數:87,代碼來源:mdsplusxdbox.py

示例8: upgrade_dialog

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class upgrade_dialog(Window):

    def __init__(self, to_upgrade, icon):

        Window.__init__(self, WINDOW_TOPLEVEL)
        self.set_property("skip-taskbar-hint", True)
        self.set_property("modal", True)
        self.set_property("destroy-with-parent", True)
        self.set_position(WIN_POS_CENTER)
        self.set_default_size (300, 300)

        self.set_icon(pixbuf_new_from_file(icon))
        self._setup_tree(to_upgrade)
        self._setup_layout()

    def _setup_layout(self):
        self.vbox = VBox(False, 0)
        self.vbox.show()

        self.terminal = terminal()
        self.terminal.connect("child-exited", lambda _: self.close_button.show())
        
        self.expander = expander_new_with_mnemonic(_("_Terminal"))
        self.expander.set_expanded(False)
        self.expander.add(self.terminal)
        self.expander.show_all()
        
        self.close_button = Button(stock=STOCK_CLOSE)
        self.close_button.connect("clicked", lambda _: self.destroy())

        scr = ScrolledWindow()
        scr.set_policy ("automatic", "automatic")
        scr.add (self.tree)
        scr.show()

        vpaned = VPaned()
        vpaned.add1(scr)
        vpaned.add2(self.expander)
        vpaned.set_position (260)
        vpaned.show()

        self.vbox.pack_start(vpaned, True, True, 0)
        self.vbox.pack_start(self.close_button, False, False, 0)

        self.add(self.vbox)
        return

    def _setup_tree(self, pacs):
        self.model = ListStore(str, str, str)

        for pac in pacs:
            self.model.append(["yellow", pac.name, pac.version])
            continue

        self.tree = TreeView()
        self.tree.show()

        self.tree.insert_column_with_attributes(-1, "", CellRendererPixbuf(),
                                                stock_id = 0)
        self.tree.insert_column_with_attributes(-1, "Package",
                                                CellRendererText(), text = 1)
        self.tree.insert_column_with_attributes(-1, "Version",
                                                CellRendererText(), text = 2)

        self.tree.set_model(self.model)
        return
    
    def run(self):
        self.show()
        self.terminal.do_upgrade()
開發者ID:BackupTheBerlios,項目名稱:gtkpacman-svn,代碼行數:72,代碼來源:dialogs.py

示例9: do_dialog

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class do_dialog(Window):

    def __init__(self, queues, icon):

        Window.__init__(self, WINDOW_TOPLEVEL)
        self.set_property("skip-taskbar-hint", True)
        self.set_property("destroy-with-parent", True)
        self.set_modal(True)
        self.connect("delete-event", self._stop_closing)
        self.set_position(WIN_POS_CENTER)

        self.set_icon(pixbuf_new_from_file(icon))
        self._setup_trees(queues)
        self._setup_layout()

        self.queues = queues

    def _setup_trees(self, queues):

        self._setup_install_tree(queues["add"])
        self._setup_remove_tree(queues["remove"])

    def _setup_install_tree(self, add_queue):

        self.inst_model = ListStore(str, str, str)

        for pac in add_queue:
            if pac.isold:
                image = "yellow"
            elif pac.installed:
                image = "green"
            else:
                image = "red"

            self.inst_model.append([image, pac.name, pac.version])
            continue

        self.inst_tree = TreeView()

        self.inst_tree.insert_column_with_attributes(-1, "",
                                                     CellRendererPixbuf(),
                                                     stock_id = 0)
        self.inst_tree.insert_column_with_attributes(-1, _("Package"),
                                                     CellRendererText(),
                                                     text = 1)
        self.inst_tree.insert_column_with_attributes(-1, _("Version"),
                                                     CellRendererText(),
                                                     text = 2)
        self.inst_tree.set_model(self.inst_model)

    def _setup_remove_tree(self, remove_queue):

        self.rem_model = ListStore(str, str, str)

        for pac in remove_queue:
            if pac.isold:
                image = "yellow"
            elif pac.installed:
                image = "green"
            else:
                image = "red"

            self.rem_model.append([image, pac.name, pac.inst_ver])
            continue

        self.rem_tree = TreeView()

        self.rem_tree.insert_column_with_attributes(-1, "",
                                                    CellRendererPixbuf(),
                                                    stock_id = 0)
        self.rem_tree.insert_column_with_attributes(-1, _("Package"),
                                                    CellRendererText(),
                                                    text = 1)
        self.rem_tree.insert_column_with_attributes(-1, _("Installed Version"),
                                                    CellRendererText(),
                                                    text = 2)

        self.rem_tree.set_model(self.rem_model)

    def _set_size (self, widget, event, data=None):
        if self.expander.get_expanded():
            self.size = self.get_size()
            self.expander.add(self.terminal)
            self.terminal.show()
        else:
            self.expander.remove(self.terminal)
            self.resize(self.size[0], self.size[1])
            self.show_all()

    def _setup_layout(self):

        self.hpaned = HPaned()
        self.hpaned.add1(self.inst_tree)
        self.hpaned.add2(self.rem_tree)
        self.hpaned.show_all()

        self.close_button = Button(stock=STOCK_CLOSE)
        self.close_button.connect("clicked", lambda _: self.destroy())

        self.terminal = terminal()
#.........這裏部分代碼省略.........
開發者ID:BackupTheBerlios,項目名稱:gtkpacman-svn,代碼行數:103,代碼來源:dialogs.py

示例10: __on_plugin_directories_button_click

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
 def __on_plugin_directories_button_click(self, button):
     """Present a dialog to the user for selecting extra plugin directories
     and process the request."""
     
     dia = Dialog('Plugin Directories',
          None, DIALOG_MODAL,
          (STOCK_OK, RESPONSE_OK,
          STOCK_CANCEL, RESPONSE_CANCEL ) )
     dia.resize(500, 300)
     dia.vbox.set_spacing(8)
     
     # Setup the tree view of plugin directories.
     model = ListStore(str) # each row contains a single string
     tv = TreeView(model)
     cell = CellRendererText()
     column = TreeViewColumn('Directory', cell, text = 0)
     tv.append_column(column)
     dia.vbox.pack_start(tv)
     
     # Populate the tree view.
     plugin_directories = \
         get_plugins_directories_from_config(self.config, self.config_path)
     for plugin_directory in plugin_directories:
         row = (plugin_directory,)
         model.append(row)
     
     modify_box = HBox(spacing = 8)
     
     # Setup the remove directory button.
     remove_button = Button('Remove')
     remove_button.set_sensitive(False) # no directory selected initially
     remove_button.connect('clicked', self.__on_remove, tv)
     modify_box.pack_end(remove_button, expand = False)
     
     tv.connect('cursor-changed', self.__on_select, remove_button)
     
     # Setup the add directory button.
     add_button = Button('Add')
     add_button.connect('clicked', self.__on_add, tv)
     modify_box.pack_end(add_button, expand = False)
     
     dia.vbox.pack_start(modify_box, expand = False)
     
     # Setup the "already included directories" label.
     included_label = Label('Plugins in the PYTHONPATH are already ' +
                            'available to BoKeep.')
     # Use a horizontal box to left-justify the label.  For some reason,
     # the label's set_justification property doesn't work for me.
     label_box = HBox()
     label_box.pack_start(included_label, expand = False)
     dia.vbox.pack_start(label_box, expand = False)
     
     dia.show_all()
     dia_result = dia.run()
     
     if dia_result == RESPONSE_OK:            
         # Remove the old plugin directories from the program's path.
         plugin_directories = \
             get_plugins_directories_from_config(self.config,
                                                 self.config_path)
         for plugin_directory in plugin_directories:
             path.remove(plugin_directory)
         
         # Get the new plugin directories from the dialog.
         plugin_directories = []
         for row in model:
             plugin_directory = row[0]
             plugin_directories.append(plugin_directory)
         
         # Update the BoKeep PYTHONPATH so that new plugins can be loaded and
         # populate the list of possible new plugins.
         for plugin_directory in plugin_directories:
             path.append(plugin_directory)
         self.__populate_possible_plugins()
         
         # Save the new plugin directories in the configuration file.
         set_plugin_directories_in_config(self.config,
             self.config_path, plugin_directories)
     
     dia.destroy()
開發者ID:paritworkercoop,項目名稱:bokeep-mirror,代碼行數:82,代碼來源:bokeepdb.py

示例11: GeoForm

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class GeoForm(Table):
    
    __gsignals__ = {
        'search': (SIGNAL_ACTION, TYPE_NONE, (TYPE_FLOAT, TYPE_FLOAT))
    }
    
    def __init__(self):
        
        Table.__init__(self, 1, 5)
        
        self.entry1 = Entry()
        self.entry2 = Entry()
        
        self.button = Button("Search")
        
        self.attach(self.entry1, 0, 1, 0, 1) 
        self.attach(self.entry2, 1, 2, 0, 1) 
        self.attach(self.button, 2, 3, 0, 1)
        
        self.entry1.set_width_chars(12)
        self.entry2.set_width_chars(12)
        
        self.entry1.set_text("59.666042")
        self.entry2.set_text("16.481794")
        
        self.button.connect('clicked', self.clicked)
        
    
    def get_lat_long(self):
        
        s1 = self.entry1.get_text()
        s2 = self.entry2.get_text()
        
        re1 = FMT1.match(s1)
        re2 = FMT1.match(s2)
        
        if re1 and re2:
            return float(re1.group(0)), float(re2.group(0))
        
        re1 = FMT2.match(s1)
        re2 = FMT3.match(s2)
        
        if re1 and re2:
            c1 = re1.group(3), re1.group(1), re1.group(2)
            c2 = re2.group(3), re2.group(1), re2.group(2)
            return geo2dec(c1, c2)
        
        re1 = FMT4.match(s1)
        re2 = FMT5.match(s2)
        
        if re1 and re1:
            c1 = re1.group(1), re1.group(2), re1.group(3)
            c2 = re2.group(1), re2.group(2), re2.group(3)
            return geo2dec(c1, c2)
        
        raise SyntaxError()
        
    
    def clicked(self, event):
        
        try:
            self.emit('search', *self.get_lat_long())
        except SyntaxError: pass
開發者ID:LinusU,項目名稱:geocache,代碼行數:65,代碼來源:GeoForm.py

示例12: Base

# 需要導入模塊: from gtk import Button [as 別名]
# 或者: from gtk.Button import connect [as 別名]
class Base(object):
    def __init__(self):
        from gtk import Window,WINDOW_TOPLEVEL,Button,Label,HBox,Entry,VBox,VSeparator
        self.window =  Window(WINDOW_TOPLEVEL)
        self.window.set_title("Slideshow")
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(10)
        self.vbox = VBox(False, 0)
        self.window.add(self.vbox)
        self.hbox1 = HBox(False, 0)
        self.vbox.pack_start(self.hbox1, True, True, 1)
        self.hbox = HBox(False, 0)
        self.vbox.pack_start(self.hbox, False, False, 1)
        self.hbox2 = HBox(False, 0)
        self.vbox.pack_start(self.hbox2, True, True, 1)
        self.label = Label('Identifikační číslo:')
        self.hbox.pack_start(self.label, False, False, 1)
        self.label.show()
        self.editable = Entry()
        self.editable.connect('key_press_event', self.key_press_event)
        self.hbox.pack_start(self.editable, True, True, 1)
        self.editable.show()
        self.button = Button("Začít")
        self.button.connect("clicked", self.callback)
        self.button.set_receives_default(True)
        self.button.set_can_focus(True)
        self.hbox.pack_start(self.button, False, False, 1)
        self.button.show()
        self.hbox1.show()
        self.hbox.show()
        self.hbox2.show()
        self.vbox.show()
        self.window.show()
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False
    def key_press_event(self, widget, event):
        from gtk.gdk import keyval_from_name,keyval_name
        if event.keyval in (keyval_from_name('Return'),keyval_from_name('KP_Enter')):
            self.callback(widget)
    def _getFilePaths(self, fileTypes, recursive=True):
        import os
        import re
        from sys import argv
        pt = re.compile(r'.*([%(0)s][^%(0)s]*)'%{'0':os.path.extsep})
        path = [a for m,a in ((pt.match(os.path.basename(a)),a) for a in argv[1:]) if m and m.group(1) in fileTypes]
        if not path:
            path = '/home/pi/img/*.jpg'
        if isinstance(path, str):
            ## Returns list containing paths of files in /path/ that are of a file type in /fileTypes/,
            ##	if /recursive/ is False subdirectories are not checked.
            paths = []
            if recursive:
                for root, folders, files in os.walk(path, followlinks=True):
                    for file in files:
                        for fileType in fileTypes:
                            if file.endswith(fileType):
                                paths.append(os.path.join(root, file))
            else:
                for item in os.listdir(path):
                    for fileType in fileTypes:
                        if item.endswith(fileType):
                            paths.append(os.path.join(root, item))
            return paths
        elif iterable(path):
            return path
        else:
            return []
    def _init_cb(self,trans):
        from threading import Thread
        if not iterable(trans):
            trans = trans,
        callbacks  = []
        for name,cb in trans:
            t = Thread(target=cb, name='%sThread'%name)
            t.daemon = True
            t.start()
            callbacks.append(cb.enqueue)
        def wrap(msg):
            for cb in callbacks:
                if not cb(msg):
                    return False
            return True
        return wrap
    def callback(self, widget):
        from slideshow import SlideShow
        from trans import Message,GpioTransceiver,JsonTransceiver

        if not self.editable.get_text():
            return False
        img_cbs = self._init_cb([('ImgGpioCallback',GpioTransceiver(24)),('ImgJsonCallback',JsonTransceiver('img.json'))])
        kp_cbs = self._init_cb([('KpGpioCallback',GpioTransceiver(26,bcd=False)),('KpJsonCallback',JsonTransceiver('kp.json'))])
        def ordfnc(path):
            from numpy.random import permutation
            gray = path[0]
            result = []
            for p in permutation(path[1:]):
                result.append(p)
                result.append(gray)
            return result
#.........這裏部分代碼省略.........
開發者ID:pborky,項目名稱:pyslides,代碼行數:103,代碼來源:startslideshow.py


注:本文中的gtk.Button.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。