コード例 #1
0
ファイル: editor.py プロジェクト: wo4wangle/anki
def create_button(self,
                  name,
                  func,
                  key=None,
                  tip=None,
                  size=True,
                  text="",
                  check=False,
                  native=False,
                  canDisable=True):

    button = QPushButton(text)

    if check:
        button.clicked[bool].connect(func)
    else:
        button.clicked.connect(func)

    if size:
        button.setFixedHeight(20)
        button.setFixedWidth(20)

    if not native:
        if self.plastiqueStyle:
            button.setStyle(self.plastiqueStyle)
        button.setFocusPolicy(Qt.NoFocus)
    else:
        button.setAutoDefault(False)

    if key:
        button.setShortcut(key)

    if tip:
        button.setToolTip(shortcut(tip))

    if check:
        button.setCheckable(True)

    if canDisable:
        self._buttons[name] = button

    PrefHelper.set_icon(button, name)

    const.BUTTONS.append(button)

    button_placement_pref = preferences.PREFS.get(const.BUTTON_PLACEMENT)

    if button_placement_pref == "adjacent":
        self.iconsBox.addWidget(button)
    else:
        self.supp_buttons_hbox.addWidget(button)

    return button
コード例 #2
0
 def on_reset_defaults(self):
     default_keybindings = PrefHelper.get_default_keybindings()
     self.new_keybindings = default_keybindings
     self.refill_table(default_keybindings)
コード例 #3
0
 def accept(self):
     if PrefHelper.are_dicts_different(self.keybindings,
                                       self.new_keybindings):
         PrefHelper.save_keybindings(self.new_keybindings)
         preferences.KEYS = self.new_keybindings
     self.close()
コード例 #4
0
 def test_normalize_user_prefs_empty_input_dicts_return_empty_dict(self):
     default_prefs   = dict()
     user_prefs      = dict()
     expected        = dict()
     result = PrefHelper.normalize_user_prefs(default_prefs, user_prefs)
     self.assertEqual(expected, result)
コード例 #5
0
 def test_normalize_user_prefs_add_and_delete_key_from_user_dict(self):
     default_prefs   = dict(b=u"two")
     user_prefs      = dict(a=u"one")
     expected        = dict(b=u"two")
     result = PrefHelper.normalize_user_prefs(default_prefs, user_prefs)
     self.assertEqual(expected, result)
コード例 #6
0
 def test_normalize_user_prefs_deletes_key_that_is_not_in_default_prefs(self):
     default_prefs   = dict()
     user_prefs      = dict(a=u"one")
     expected        = dict()
     result = PrefHelper.normalize_user_prefs(default_prefs, user_prefs)
     self.assertEqual(expected, result)