当前位置: 首页>>代码示例>>Python>>正文


Python ProxyComboBox.prefill方法代码示例

本文整理汇总了Python中kiwi.ui.widgets.combo.ProxyComboBox.prefill方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyComboBox.prefill方法的具体用法?Python ProxyComboBox.prefill怎么用?Python ProxyComboBox.prefill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kiwi.ui.widgets.combo.ProxyComboBox的用法示例。


在下文中一共展示了ProxyComboBox.prefill方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_combo

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
 def add_combo(self, data=None):
     """Add a combo for selecting an option"""
     combo = ProxyComboBox()
     self.pack_start(combo, False, False, 0)
     if data:
         combo.prefill(data)
     return combo
开发者ID:hackedbellini,项目名称:stoq,代码行数:9,代码来源:masseditordialog.py

示例2: ComboSearchFilter

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
class ComboSearchFilter(SearchFilter):
    """
    - a label
    - a combo with a set of predefined item to select from
    """
    __gtype_name__ = 'ComboSearchFilter'

    def __init__(self, label='', values=None):
        """
        Create a new ComboSearchFilter object.
        @param name: name of the search filter
        @param values: items to put in the combo, see
            L{kiwi.ui.widgets.combo.ProxyComboBox.prefill}
        """
        SearchFilter.__init__(self, label=label)
        label = gtk.Label(label)
        self.pack_start(label, False, False)
        label.show()
        self.title_label = label

        self.combo = ProxyComboBox()
        if values:
            self.combo.prefill(values)
        self.combo.connect('content-changed', self._on_combo__content_changed)
        self.pack_start(self.combo, False, False, 6)
        self.combo.show()

    #
    # SearchFilter
    #

    def get_state(self):
        return NumberQueryState(filter=self,
                                value=self.combo.get_selected_data())

    def get_title_label(self):
        return self.title_label

    def get_mode_combo(self):
        return self.combo

    #
    # Public API
    #

    def select(self, data):
        """
        selects an item in the combo
        @param data: what to select
        """
        self.combo.select(data)

    #
    # Callbacks
    #

    def _on_combo__content_changed(self, mode):
        self.emit('changed')
开发者ID:dsaran,项目名称:packagehelper,代码行数:60,代码来源:search.py

示例3: _setup_options_combo_slave

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
    def _setup_options_combo_slave(self):
        widget = ProxyComboBox()
        widget.props.sensitive = self.sensitive
        widget.model_attribute = "field_value"
        widget.data_type = unicode

        data = [(value, unicode(key)) for key, value in self.detail.options.items()]
        widget.prefill(data)
        self.proxy.add_widget("field_value", widget)
        self.container.add(widget)
        widget.show()
开发者ID:coletivoEITA,项目名称:stoq,代码行数:13,代码来源:parameterseditor.py

示例4: test_prefill_attr_none

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
    def test_prefill_attr_none(self):
        model = Settable(attr=None)
        proxy = Proxy(FakeView(), model)
        combo = ProxyComboBox()
        combo.data_type = int
        combo.model_attribute = 'attr'
        combo.prefill([('foo', 10), ('bar', 20)])
        proxy.add_widget('attr', combo)

        # Even though attr is None, the combo doesn't allow something
        # not prefilled in it to be selected. In this case, it will select
        # the first item (prefill actually does that) instead.
        self.assertEqual(model.attr, 10)
开发者ID:hackedbellini,项目名称:kiwi,代码行数:15,代码来源:test_ComboBox.py

示例5: WorkOrderQuoteItemStep

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]

#.........这里部分代码省略.........
            wo_item.order.remove_item(wo_item)

        super(WorkOrderQuoteItemStep, self).remove_items(items)

    def get_columns(self):
        columns = [
            Column('sellable.code', title=_(u'Code'),
                   data_type=str, visible=False),
            Column('sellable.barcode', title=_(u'Barcode'),
                   data_type=str, visible=False),
            Column('sellable.description', title=_('Description'),
                   data_type=str, expand=True,
                   format_func=self._format_description, format_func_data=True),
        ]
        columns.extend(self.get_extra_columns())
        columns.extend([
            Column('quantity', title=_(u'Quantity'),
                   data_type=decimal.Decimal, format_func=format_quantity),
            Column('base_price', title=_('Original Price'), data_type=currency),
            Column('price', title=_('Sale Price'), data_type=currency),
            Column('sale_discount', title=_('Discount'),
                   data_type=decimal.Decimal,
                   format_func=get_formatted_percentage),
            Column('total', title=_(u'Total'),
                   data_type=currency),
        ])
        return columns

    def validate_step(self):
        # When finishing the wizard, make sure that all modifications on
        # sale items on this step are propagated to their work order items
        for sale_item in self.model.get_items():
            wo_item = WorkOrderItem.get_from_sale_item(self.store, sale_item)
            wo_item.quantity = sale_item.quantity
            wo_item.quantity_decreased = sale_item.quantity_decreased
            wo_item.price = sale_item.price

        return super(WorkOrderQuoteItemStep, self).validate_step()

    #
    #  Private
    #

    def _format_description(self, item, data):
        return format_sellable_description(item.sellable, item.batch)

    def _setup_work_orders_widgets(self):
        self._work_orders_hbox = gtk.HBox(spacing=6)
        self.item_vbox.pack_start(self._work_orders_hbox, False, True, 6)
        self.item_vbox.reorder_child(self._work_orders_hbox, 0)
        self._work_orders_hbox.show()

        label = gtk.Label(_("Work order:"))
        self._work_orders_hbox.pack_start(label, False, True)

        data = []
        for wo in self.wizard.workorders:
            # The work order might be already approved if we are editing a sale
            if wo.can_approve():
                wo.approve()

            self.setup_work_order(wo)
            data.append([wo.description, wo])

        if len(data) <= _MAX_WORK_ORDERS_FOR_RADIO:
            self.work_orders_combo = None
            for desc, wo in data:
                self._add_work_order_radio(desc, wo)
        else:
            self.work_orders_combo = ProxyComboBox()
            self.work_orders_combo.prefill(data)
            self._selected_workorder = self.work_orders_combo.get_selected()
            self._work_orders_hbox.pack_start(self.work_orders_combo,
                                              False, False)

        self._work_orders_hbox.show_all()

    def _add_work_order_radio(self, desc, workorder):
        radio = gtk.RadioButton(group=self._radio_group, label=desc)
        radio.set_data('workorder', workorder)
        radio.connect('toggled', self._on_work_order_radio__toggled)

        if self._radio_group is None:
            self._radio_group = radio
            self._selected_workorder = workorder

        self._work_orders_hbox.pack_start(radio, False, False, 6)
        radio.show_all()

    #
    #  Callbacks
    #

    def on_work_orders_combo__content_changed(self, combo):
        self._selected_workorder = combo.get_selected()

    def _on_work_order_radio__toggled(self, radio):
        if not radio.get_active():
            return
        self._selected_workorder = radio.get_data('workorder')
开发者ID:pkaislan,项目名称:stoq,代码行数:104,代码来源:workorderquotewizard.py

示例6: ChartDialog

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
class ChartDialog(gtk.Window):
    def __init__(self):
        self._js_data = None
        self._js_options = None
        self._current = None

        gtk.Window.__init__(self)
        self.set_size_request(800, 480)

        self.vbox = gtk.VBox()
        self.add(self.vbox)
        self.vbox.show()

        hbox = gtk.HBox()
        self.vbox.pack_start(hbox, False, False, 6)
        hbox.show()

        label = gtk.Label('Period:')
        hbox.pack_start(label, False, False, 6)
        label.show()

        self.chart_type = ProxyComboBox()
        self.chart_type.connect(
            'content-changed',
            self._on_chart_type__content_changed)
        hbox.pack_start(self.chart_type, False, False, 6)
        self.chart_type.show()

        self.period_values = ProxyComboBox()
        self.period_values.connect(
            'content-changed',
            self._on_period_values__content_changed)
        hbox.pack_start(self.period_values, False, False, 6)
        self.period_values.show()

        self._view = WebView()
        self._view.get_view().connect(
            'load-finished',
            self._on_view__document_load_finished)
        self.vbox.pack_start(self._view, True, True)

        self.results = ObjectList()
        self.results.connect(
            'row-activated',
            self._on_results__row_activated)
        self.vbox.pack_start(self.results, True, True)

        self._setup_daemon()

    @api.async
    def _setup_daemon(self):
        daemon = yield start_daemon()
        self._daemon_uri = daemon.base_uri

        proxy = daemon.get_client()
        yield proxy.callRemote('start_webservice')

        self.chart_type.prefill([
            ('Year', 'YearlyPayments'),
            ('Month', 'MonthlyPayments'),
            ('Day', 'DailyPayments'),
        ])

    @api.async
    def _invoke_chart(self, chart_type_name, **report_kwargs):
        def _get_chart_url(**kwargs):
            params = []
            for key, value in kwargs.items():
                params.append(key + '=' + str(value))
            return '%s/web/chart.json?%s' % (
                self._daemon_uri, '&'.join(params))

        url = _get_chart_url(type=chart_type_name, **report_kwargs)
        page = yield getPage(url)
        data = json.loads(page)
        api.asyncReturn(data)

    def _render_chart(self, chart_class, response):
        self._render_javascript(chart_class, response)
        self._render_objectlist(chart_class, response)

    def _render_javascript(self, chart_class, response):
        ticks = [item['short_title'] for item in response['items']]

        self._js_data = response['data']

        options = {}
        options['description'] = response['description']
        options['series'] = [dict(label=c['title']) for c in chart_class.columns][1:]
        options['xaxis_ticks'] = ticks
        self._js_options = options

        self._view.load_uri('%s/web/static/chart.html' % (
                            self._daemon_uri,))

    def _render_objectlist(self, chart_class, response):
        columns = []
        for kwargs in chart_class.columns:
            kwargs = kwargs.copy()
            name = kwargs.pop('name')
#.........这里部分代码省略.........
开发者ID:leandrorchaves,项目名称:stoq,代码行数:103,代码来源:chartdialog.py

示例7: AccountEditor

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
class AccountEditor(BaseEditor):
    """ Account Editor """
    gladefile = "AccountEditor"
    proxy_widgets = ['description', 'code']
    model_type = Account
    model_name = _('Account')

    def __init__(self, store, model=None, parent_account=None):
        self._last_account_type = None
        self._bank_number = -1
        self._bank_widgets = []
        self._bank_option_widgets = []
        self._option_fields = {}
        self._test_button = None
        self.existing = model is not None
        self.parent_account = parent_account
        self.bank_model = _TemporaryBankAccount()
        BaseEditor.__init__(self, store, model)

        action_area = self.main_dialog.action_area
        action_area.set_layout(gtk.BUTTONBOX_END)
        action_area.pack_start(self._test_button, expand=False, fill=False)
        action_area.set_child_secondary(self._test_button, True)
        self._test_button.show()

    #
    # BaseEditor hooks
    #

    def create_model(self, store):
        return Account(description=u"",
                       account_type=Account.TYPE_CASH,
                       store=store)

    def _setup_widgets(self):
        self._test_button = gtk.Button(_("Print a test bill"))
        self._test_button.connect('clicked',
                                  self._on_test_button__clicked)
        self.parent_accounts = AccountTree(with_code=False, create_mode=True)
        self.parent_accounts.connect('selection-changed',
                                     self._on_parent_accounts__selection_changed)
        self.tree_box.pack_start(self.parent_accounts)
        self.tree_box.reorder_child(self.parent_accounts, 0)

        if self.model == sysparam(self.store).IMBALANCE_ACCOUNT:
            self.account_type.set_sensitive(False)

        self.account_type.prefill(Account.account_type_descriptions)
        account_type = self.model.account_type

        self.parent_accounts.insert_initial(self.store,
                                            edited_account=self.model)
        if self.parent_account:
            account = self.parent_accounts.get_account_by_id(
                self.parent_account.id)
            self.parent_accounts.select(account)
            if not self.existing:
                account_type = account.account_type
        self.account_type.select(account_type)
        self.parent_accounts.show()

    def setup_proxies(self):
        self._setup_widgets()
        self.add_proxy(self.model, AccountEditor.proxy_widgets)

    def validate_confirm(self):
        if not self.model.description:
            return False
        account = self.parent_accounts.get_selected()
        if not account:
            return True
        return account.selectable

    def on_confirm(self):
        new_parent = self.parent_accounts.get_selected()
        if new_parent:
            new_parent = new_parent.account
        if new_parent != self.model:
            self.model.parent = new_parent
        self.model.account_type = self.account_type.get_selected()
        self._save_bank()

    def refresh_ok(self, value):
        BaseEditor.refresh_ok(self, value)

        account_type = self.account_type.get_selected()
        if account_type != Account.TYPE_BANK:
            value = False
        self._test_button.set_sensitive(value)

    # Private

    def _save_bank(self):
        bank_account = self.model.bank
        if not bank_account:
            bank_account = BankAccount(account=self.model,
                                       store=self.store)
        # FIXME: Who sets this to a str?
        bank_account.bank_account = unicode(self.bank_model.bank_account)
        bank_account.bank_branch = unicode(self.bank_model.bank_branch)
#.........这里部分代码省略.........
开发者ID:romaia,项目名称:stoq,代码行数:103,代码来源:accounteditor.py

示例8: TestComboBox

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
class TestComboBox(unittest.TestCase):
    def setUp(self):
        self.combo = ProxyComboBox()

    def _prefill(self):
        self.combo.prefill((('Johan', 1981),
                            ('Lorenzo', 1979),
                            ('Christian', 1976)))

    def testPrefill(self):
        self.combo.prefill(('foo', 'bar'))
        model = self.combo.get_model()
        self.assertEqual(tuple(model[0]), ('foo', None))
        self.assertEqual(tuple(model[1]), ('bar', None))

    def testPrefillWithData(self):
        self.combo.prefill((('foo', 42), ('bar', 138)))
        model = self.combo.get_model()
        self.assertEqual(tuple(model[0]), ('foo', 42))
        self.assertEqual(tuple(model[1]), ('bar', 138))
        self.combo.prefill([])
        self.assertEqual(len(self.combo.get_model()), 0)
        self.assertEqual(len(model), 0)
        self.assertEqual(len(self.combo), 0)

    def testSelectItemByPosition(self):
        self._prefill()
        self.combo.select_item_by_position(1)
        model = self.combo.get_model()
        iter = self.combo.get_active_iter()
        self.assertEqual(model.get_value(iter, 0), 'Lorenzo')
        self.assertEqual(model.get_value(iter, 1), 1979)
        self.assertRaises(KeyError, self.combo.select_item_by_label, 4)

    def testSelectItemByLabel(self):
        self._prefill()
        self.combo.select_item_by_label('Christian')
        model = self.combo.get_model()
        iter = self.combo.get_active_iter()
        rowNo = model.get_path(iter)[0]
        self.assertEqual(rowNo, 2)
        self.assertRaises(KeyError, self.combo.select_item_by_label, 'Salgado')

    def testSelectByData(self):
        self._prefill()
        self.combo.select_item_by_data(1976)
        model = self.combo.get_model()
        iter = self.combo.get_active_iter()
        rowNo = model.get_path(iter)[0]
        self.assertEqual(rowNo, 2)
        self.assertEqual(model.get_value(iter, 0), 'Christian')
        self.assertEqual(model.get_value(iter, 1), 1976)
        self.assertRaises(KeyError, self.combo.select_item_by_data, 1980)

    def testGetSelectedData(self):
        self._prefill()
        self.combo.select_item_by_position(0)
        self.assertEqual(self.combo.get_selected_data(), 1981)
        self.assertRaises(TypeError,
                          self.combo.select_item_by_position, 'foobar')

    def testGetSelectedLabel(self):
        self._prefill()

    def testClear(self):
        self._prefill()
        self.combo.clear()
        self.assertEqual(map(list, self.combo.get_model()), [])
开发者ID:rcaferraz,项目名称:kiwi,代码行数:70,代码来源:test_ComboBox.py

示例9: ComboSearchFilter

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
class ComboSearchFilter(SearchFilter):
    """
    - a label
    - a combo with a set of predefined item to select from
    """
    __gtype_name__ = 'ComboSearchFilter'

    def __init__(self, label='', values=None):
        """
        Create a new ComboSearchFilter object.
        :param label: label of the search filter
        :param values: items to put in the combo, see
            :class:`kiwi.ui.widgets.combo.ProxyComboBox.prefill`
        """
        self._block_updates = False
        SearchFilter.__init__(self, label=label)
        label = gtk.Label(label)
        self.pack_start(label, False, False)
        label.show()
        self.title_label = label

        # We create the mode, but it will only be added to this box when
        # enable_advanced is called
        self.mode = ProxyComboBox()
        self.mode.connect('content-changed', self._on_mode__content_changed)
        for option in (ComboEquals, ComboDifferent):
            self.add_option(option)
        self.mode.select_item_by_position(0)

        self.combo = ProxyComboBox()
        if values:
            self.update_values(values)
        self.combo.connect('content-changed', self._on_combo__content_changed)
        self.pack_start(self.combo, False, False, 6)
        self.combo.show()

    #
    # SearchFilter
    #

    def get_state(self):
        value = self.combo.get_selected_data()
        mode = self.mode.get_selected_data()
        state = NumberQueryState(filter=self, value=value, mode=mode.mode)
        if hasattr(value, 'id'):
            state.value_id = value.id
        return state

    def set_state(self, value, value_id=None, mode=None):
        if mode is None:
            mode = NumberQueryState.EQUALS
        if value_id is not None:
            for item in self.combo.get_model_items().values():
                if item is None:
                    continue
                if item.id == value_id:
                    value = item
                    break
        self.select(value)

    def update_values(self, values):
        self._block_updates = True
        self.combo.prefill(values)
        self._block_updates = False

    def get_title_label(self):
        return self.title_label

    def get_mode_combo(self):
        return self.combo

    def get_description(self):
        desc = ''
        data = self.combo.get_selected_data()
        if data is not None:
            desc += self.combo.get_selected_label()
            return '%s %s' % (self.title_label.get_text(), desc,)

    #
    # Public API
    #

    def add_option(self, option_type, position=0):
        """
        Adds an option
        :param option_type: option to add
        :type option_type: a :class:`ComboSearchOption` subclass
        """
        option = option_type()
        num = len(self.mode) + position
        self.mode.insert_item(num, option.name, option_type)

    def select(self, data):
        """
        selects an item in the combo
        :param data: what to select
        """
        self.combo.select(data)

    def enable_advanced(self):
#.........这里部分代码省略.........
开发者ID:EasyDevSolutions,项目名称:stoq,代码行数:103,代码来源:searchfilters.py

示例10: ComboSearchFilter

# 需要导入模块: from kiwi.ui.widgets.combo import ProxyComboBox [as 别名]
# 或者: from kiwi.ui.widgets.combo.ProxyComboBox import prefill [as 别名]
class ComboSearchFilter(SearchFilter):
    """
    - a label
    - a combo with a set of predefined item to select from
    """
    __gtype_name__ = 'ComboSearchFilter'

    def __init__(self, label='', values=None):
        """
        Create a new ComboSearchFilter object.
        :param label: label of the search filter
        :param values: items to put in the combo, see
            :class:`kiwi.ui.widgets.combo.ProxyComboBox.prefill`
        """
        self._block_updates = False
        SearchFilter.__init__(self, label=label)
        label = gtk.Label(label)
        self.pack_start(label, False, False)
        label.show()
        self.title_label = label

        self.combo = ProxyComboBox()
        if values:
            self.update_values(values)
        self.combo.connect('content-changed', self._on_combo__content_changed)
        self.pack_start(self.combo, False, False, 6)
        self.combo.show()

    #
    # SearchFilter
    #

    def get_state(self):
        value = self.combo.get_selected_data()
        state = NumberQueryState(filter=self,
                                 value=value)
        if hasattr(value, 'id'):
            state.value_id = value.id
        return state

    def set_state(self, value, value_id=None):
        if value_id is not None:
            for item in self.combo.get_model_items().values():
                if item is None:
                    continue
                if item.id == value_id:
                    value = item
                    break
        self.select(value)

    def update_values(self, values):
        self._block_updates = True
        self.combo.prefill(values)
        self._block_updates = False

    def get_title_label(self):
        return self.title_label

    def get_mode_combo(self):
        return self.combo

    def get_description(self):
        desc = ''
        data = self.combo.get_selected_data()
        if data is not None:
            desc += self.combo.get_selected_label()
            return '%s %s' % (self.title_label.get_text(), desc,)

    #
    # Public API
    #

    def select(self, data):
        """
        selects an item in the combo
        :param data: what to select
        """
        self.combo.select(data)

    #
    # Callbacks
    #

    def _on_combo__content_changed(self, mode):
        if not self._block_updates:
            self.emit('changed')
开发者ID:LeonamSilva,项目名称:stoq,代码行数:88,代码来源:searchfilters.py


注:本文中的kiwi.ui.widgets.combo.ProxyComboBox.prefill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。