Python wx.Bell() Examples

The following are 25 code examples of wx.Bell(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: TimeCtrl.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def _TimeCtrl__IncrementValue(self, key, pos):
        text = self.GetValue()
        field = self._FindField(pos)
        start, end = field._extent
        slice = text[start:end]
        if slice == 'A':
            newslice = 'P'
        elif slice == 'P':
            newslice = 'A'
        else:
            top = 24 if field._index == 0 else 60
            increment = 1 if key == wx.WXK_UP else -1
            newslice = "%02d" % ((int(slice) + increment) % top)
        newvalue = text[:start] + newslice + text[end:]
        try:
            self._SetValue(newvalue)
        except ValueError:  # must not be in bounds:
            if not wx.Validator_IsSilent():
                wx.Bell() 
Example #2
Source File: DigitOnlyValidator.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def OnChar(self, event):
        key = event.GetKeyCode()

        if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
            event.Skip()
            return

        if chr(key) in string.digits:
            event.Skip()
            return

        if not wx.Validator_IsSilent():
            wx.Bell()

        # Returning without calling event.Skip eats the event before it
        # gets to the text control
        return 
Example #3
Source File: new_properties.py    From wxGlade with MIT License 6 votes vote down vote up
def _on_text(self, event):
        if self.deactivated or self.blocked: return
        text = event.GetString()
        if not self.validation_re:
            if self.control_re.search(text):
                # strip most ASCII control characters
                self.text.SetValue(self.control_re.sub("", text))
                wx.Bell()
                return
        elif self.check(text):
            self.text.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) )
            self.text.Refresh()
        else:
            self.text.SetBackgroundColour(wx.RED)
            self.text.Refresh()
        event.Skip() 
Example #4
Source File: menubar.py    From wxGlade with MIT License 6 votes vote down vote up
def move_item_right(self, event):
        """moves the selected menu item one level down in the hierarchy, i.e.
        shifts its label 4 spaces right in self.menu_items"""
        index = self.selected_index
        if index <= 0:
            wx.Bell()
            return
        level = self.item_level(index)
        if level > self.item_level(index-1):
            wx.Bell()
            return
        level += 1
        label = self._get_item_text(index, "label")
        self._set_item_string(index, "label", misc.wxstr(" "*4) + label)
        self._set_item_string(index, "level", level)
        self.items.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
        self._enable_buttons() 
Example #5
Source File: menubar.py    From wxGlade with MIT License 6 votes vote down vote up
def move_item_left(self, event=None, index=None):
        """moves the selected menu item one level up in the hierarchy, i.e.
        shifts its label 4 spaces left in self.menu_items"""
        if index is None:
            index = self.selected_index
        if index <= 0:
            wx.Bell()
            return
        level = self.item_level(index)
        if level==0 or ( index+1 < self.items.GetItemCount() and (level < self.item_level(index+1)) ):
            wx.Bell()
            return
        level -= 1
        label = self._get_item_text(index, "label")
        self._set_item_string(index, "label", label[4:])
        self._set_item_string(index, "level", level)
        self.items.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
        self._enable_buttons() 
Example #6
Source File: APDUHexValidator.py    From pyscard with GNU Lesser General Public License v2.1 6 votes vote down vote up
def OnChar(self, event):
        key = event.GetKeyCode()

        if wx.WXK_SPACE == key or chr(key) in string.hexdigits:
            value = event.GetEventObject().GetValue() + chr(key)
            if apduregexp.match(value):
                event.Skip()
            return

        if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
            event.Skip()
            return

        if not wx.Validator_IsSilent():
            wx.Bell()

        return 
Example #7
Source File: new_properties.py    From wxGlade with MIT License 5 votes vote down vote up
def _validate(self, row, col, value, bell=True):
        if not self.validation_res or not self.validation_res[col]:
            return True
        validation_re = self.validation_res[col]
        match = validation_re.match(value)
        if match: return True
        if bell: wx.Bell()
        return False 
Example #8
Source File: CellEditor.py    From bookhub with MIT License 5 votes vote down vote up
def _OnChar(self, event):
        "Handle the OnChar event by rejecting non-numerics"
        if event.GetModifiers() != 0 and event.GetModifiers() != wx.MOD_SHIFT:
            event.Skip()
            return

        if event.GetKeyCode() in self.acceptableCodes:
            event.Skip()
            return

        wx.Bell()

#---------------------------------------------------------------------------- 
Example #9
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def OnChar(self, event):
        key = event.KeyCode

        if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
            event.Skip()
            return

        textCtrl = self.GetWindow()
        startPos, endPos = textCtrl.GetSelection()
        length = textCtrl.GetLastPosition() - (endPos - startPos)
        if length >= self.maxLength:
            if not wx.Validator_IsSilent():
                wx.Bell()
            return

        if(
            self.allowRaw
            and textCtrl.GetInsertionPoint() == 0
            and chr(key).upper() == "R"
        ):
            textCtrl.WriteText("R")
            return

        if chr(key) in hexdigits:
            textCtrl.WriteText(chr(key).upper())
            return

        if not wx.Validator_IsSilent():
            wx.Bell()

        # Returning without calling event.Skip eats the event before it
        # gets to the text control
        return 
Example #10
Source File: toolbar.py    From wxGlade with MIT License 5 votes vote down vote up
def _do_move_item(self, event, index, is_down):
        """internal function used by move_item_up and move_item_down.
        Returns the new index of the moved item, or None if no change occurred"""
        i = index+1 if is_down else index-1
        if i < 0 or i>=self.items.GetItemCount():
            wx.Bell()
            return None

        item = self._get_all_texts(index)
        self.items.DeleteItem(index)
        self._insert_item(i, item)
        self._select_item(i, force=True) 
Example #11
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def _FindByTyping(self, searchColumn, prefix):
        """
        Select the first row passed the currently focused row that has a string representation
        that begins with 'prefix' in the given column
        """
        start = max(self.GetFocusedRow(), 0)

        # If the user is starting a new search, we don't want to consider the current row
        if len(prefix) == 1:
            start = (start + 1) % self.GetItemCount()

        # If we are searching on a sorted column, use a binary search
        if self._CanUseBisect(searchColumn):
            if self._FindByBisect(searchColumn, prefix, start, self.GetItemCount()):
                return
            if self._FindByBisect(searchColumn, prefix, 0, start):
                return
        else:
            # A binary search on a sorted column can handle any number of rows. A linear
            # search cannot. So we impose an arbitrary limit on the number of rows to
            # consider. Above that, we don't even try
            if self.GetItemCount() > self.MAX_ROWS_FOR_UNSORTED_SEARCH:
                self._SelectAndFocus(0)
                return

            # Do a linear, wrapping search to find the next match. To wrap, we consider
            # the rows in two partitions: start to the end of the collection, and then
            # from the beginning to the start position. Expressing this in other languages
            # is a pain, but it's elegant in Python. I just love Python :)
            for i in itertools.chain(range(start, self.GetItemCount()), range(0, start)):
                #self.__rows += 1
                model = self.GetObjectAt(i)
                if model is not None:
                    strValue = searchColumn.GetStringValue(model)
                    if strValue.lower().startswith(prefix):
                        self._SelectAndFocus(i)
                        return
        wx.Bell() 
Example #12
Source File: menubar.py    From wxGlade with MIT License 5 votes vote down vote up
def _do_move_item(self, event, index, is_down):
        """internal function used by move_item_up and move_item_down.
        Returns the new index of the moved item, or None if no change occurred"""
        if index <= 0:
            wx.Bell()
            return

        level = self.item_level(index)
        items_to_move = [ self._get_all_texts(index) ]
        i = index+1
        while i < self.items.GetItemCount():
            # collect the items to move up
            if self.item_level(i) > level:
                items_to_move.append(self._get_all_texts(i))
                i += 1
            else: break
        i = index-1
        while i >= 0:
            lvl = self.item_level(i)
            if level == lvl: break
            elif level > lvl:
                wx.Bell()
                return
            i -= 1
        for j in range(len(items_to_move)-1, -1, -1):
            self.items.DeleteItem(index+j)
        items_to_move.reverse()
        for level, label, event_handler, name, type_, help_str, id in items_to_move:
            i = self._insert_item_string(i, level)
            self._set_item_string(i, "label", label)
            self._set_item_string(i, "name", name)
            self._set_item_string(i, "help_str", help_str)
            self._set_item_string(i, "type", type_)
            self._set_item_string(i, "event_handler", event_handler)
            self._set_item_string(i, "id", id)
        ret_idx = i
        if is_down: ret_idx += len(items_to_move)
        self._select_item(ret_idx, True) 
Example #13
Source File: menubar.py    From wxGlade with MIT License 5 votes vote down vote up
def move_item_up(self, event):
        "moves the selected menu item before the previous one at the same level in self.menu_items"
        if self.selected_index<=0:
            wx.Bell()
            return
        self._do_move_item(event, self.selected_index, False) 
Example #14
Source File: new_properties.py    From wxGlade with MIT License 5 votes vote down vote up
def _check_for_user_modification(self, new_value=None, force=False, activate=False):
        if new_value is None:
            new_value = self._convert_from_text(self.text.GetValue())
        if new_value is None:  # e.g. validation failed
            wx.Bell()
            self.text.SetValue( self._convert_to_text(self.value))
            return
        self.previous_value = self.value
        return Property._check_for_user_modification(self, new_value, force, activate) 
Example #15
Source File: misc.py    From wxGlade with MIT License 5 votes vote down vote up
def drop():
    global focused_widget
    method = None
    if not focused_widget: return
    if not focused_widget.check_drop_compatibility():
        wx.Bell()
        return
    if focused_widget.IS_SLOT:
        method = getattr(focused_widget, "on_drop_widget", None)
    elif common.adding_sizer:
        method = getattr(focused_widget, "drop_sizer", None)
    #if not method:
        #if not hasattr(focused_widget, "sizer"): return
        #method = getattr(focused_widget.sizer, "add_slot", None)
    if method: method(None, False)  # don't reset, but continue adding 
Example #16
Source File: misc.py    From wxGlade with MIT License 5 votes vote down vote up
def _paste():
    if focused_widget is None: return
    if not hasattr(focused_widget, "clipboard_paste"):
        wx.Bell()
        return
    clipboard.paste(focused_widget) 
Example #17
Source File: misc.py    From wxGlade with MIT License 5 votes vote down vote up
def _cut():
    global focused_widget
    if not _can_remove():
        wx.Bell()
        return
    clipboard.cut(focused_widget)
    #focused_widget = None 
Example #18
Source File: misc.py    From wxGlade with MIT License 5 votes vote down vote up
def _can_remove():
    global focused_widget
    if focused_widget is None or not hasattr(focused_widget, "remove"): return False
    if focused_widget.IS_SLOT:
        # XXX change this later on, to remove e.g. notebook pages, but not when parent.CHILDREN is an int
        if focused_widget.parent.CHILDREN == -1: return True
        if focused_widget.parent.WX_CLASS in ("wxNotebook",): return True
        if not focused_widget.parent.IS_SIZER or focused_widget.sizer._IS_GRIDBAG:
            wx.Bell()
            return False
    return True 
Example #19
Source File: clipboard.py    From wxGlade with MIT License 5 votes vote down vote up
def paste(widget):
    """Copies a widget (and all its children) from the clipboard to the given
    destination (parent, sizer and position inside the sizer). Returns True on success."""
    error = None
    if not wx.TheClipboard.Open():
        misc.error_message( "Clipboard can't be opened." )
        return False

    try:
        data_object = None
        for fmt in [widget_data_format, sizer_data_format, window_data_format,
                    menubar_data_format, toolbar_data_format]:
            if wx.TheClipboard.IsSupported(fmt):
                data_object = wx.CustomDataObject(fmt)
                break
        if data_object is None:
            misc.info_message( "The clipboard doesn't contain wxGlade widget data." )
            return False
        if not wx.TheClipboard.GetData(data_object):
            misc.error_message( "Data can't be copied from clipboard." )
            return False
    finally:
        wx.TheClipboard.Close()
    format_name = data_object.GetFormat().GetId().split(".")[1]  # e.g. 'wxglade.widget' -> 'widget'
    compatible, message = widget.check_compatibility(None, format_name)
    if not compatible:
        wx.Bell()
        if message:
            misc.error_message(message)
        return False
    if not widget.clipboard_paste(data_object.GetData()):
        misc.error_message("Paste failed") 
Example #20
Source File: main.py    From wxGlade with MIT License 5 votes vote down vote up
def on_char(self, event):
        key = (event.GetKeyCode(), event.GetModifiers())    # modifiers: 1,2,4 for Alt, Ctrl, Shift

        focused = self.FindFocus()
        if not focused or not focused.Id in self._id_to_coordinate:
            return event.Skip()

        row, col = self._id_to_coordinate[focused.Id]
        new_row = new_col = None
        if key[0]==wx.WXK_UP:
            if row>0: new_row = row-1
        elif key[0]==wx.WXK_DOWN:
            if row < len(self._ids_by_row)-1: new_row = row+1
        elif key[0]==wx.WXK_LEFT:
            if col>0: new_col = col-1
        elif key[0]==wx.WXK_RIGHT:
            if col < len(self._ids_by_row[row])-1: new_col = col+1
        elif key[0]==wx.WXK_HOME:
            new_col = 0
        elif key[0]==wx.WXK_END:
            new_col = len(self._ids_by_row[row])-1
        elif key[0]==wx.WXK_PAGEUP:
            new_row = 0
        elif key[0]==wx.WXK_PAGEDOWN:
            new_row = len(self._ids_by_row)-1
        elif (ord("A") <= key[0] <= ord("Z")) and chr(key[0]) in misc.palette_hotkeys:
            section = misc.palette_hotkeys[chr(key[0])]
            new_row = self._section_to_row[section]
            new_col = 0
        else:
            return event.Skip()

        if new_row is None and new_col is None:
            # limits hit
            wx.Bell()
        else:
            if new_col is None: new_col = min(col, len(self._ids_by_row[new_row])-1)
            if new_row is None: new_row = row
            focus = self.FindWindowById(self._ids_by_row[new_row][new_col])
            if focus: focus.SetFocus() 
Example #21
Source File: matplotlib_example.py    From wxGlade with MIT License 5 votes vote down vote up
def _get_float(self, control):
        # returns a float or None if not a valid float
        try:
            ret = float( control.GetValue() )
            colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
            control.SetBackgroundColour(colour)
        except:
            control.SetBackgroundColour(wx.RED)
            wx.Bell()
            ret = None
        control.Refresh()
        return ret

    ####################################################################################################################
    # mouse actions 
Example #22
Source File: Util.py    From pyResMan with GNU General Public License v2.0 5 votes vote down vote up
def OnChar(self, event):
        """Process values as they are entered into the control
        @param event: event that called this handler

        """
        key = event.GetKeyCode()
        if event.CmdDown() or key < wx.WXK_SPACE or key == wx.WXK_DELETE or \
           key > 255 or chr(key) in Util.HEXCHARS:
            event.Skip()
            return

        if not wx.Validator_IsSilent():
            wx.Bell()

        return 
Example #23
Source File: ObjectListView.py    From bookhub with MIT License 4 votes vote down vote up
def StartCellEdit(self, rowIndex, subItemIndex):
        """
        Begin an edit operation on the given cell.
        """

        # Collect the information we need for the StartingEditEvent
        modelObject = self.GetObjectAt(rowIndex)
        cellValue = self.GetValueAt(modelObject, subItemIndex)

        # Make sure the user can see where the editor is going to be. If the bounds are
        # null, this means we needed to scroll horizontally but were unable (this can only
        # happen on non-Windows platforms). In that case we can't let the edit happen
        # since the user won't be able to see the cell
        cellBounds = self.EnsureCellVisible(rowIndex, subItemIndex)
        if cellBounds is None:
            wx.Bell()
            return

        # Give the world the chance to veto the edit, or to change its characteristics
        defaultEditor = self._MakeDefaultCellEditor(rowIndex, subItemIndex, cellValue)
        evt = OLVEvent.CellEditStartingEvent(self, rowIndex, subItemIndex, modelObject,
                                             cellValue, cellBounds, defaultEditor)
        self.GetEventHandler().ProcessEvent(evt)
        if evt.IsVetoed():
            defaultEditor.Destroy()
            return

        # Remember that we are editing something (and make sure we can see it)
        self.selectionBeforeCellEdit = self.GetSelectedObjects()
        self.DeselectAll()
        self.cellEditor = evt.newEditor or evt.editor
        self.cellBeingEdited = (rowIndex, subItemIndex)

        # If we aren't using the default editor, destroy it
        if self.cellEditor != defaultEditor:
            defaultEditor.Destroy()

        # If the event handler hasn't already configured the editor, do it now.
        if evt.shouldConfigureEditor:
            self.cellEditor.SetFocus()
            self.cellEditor.SetValue(evt.cellValue)
            self._ConfigureCellEditor(self.cellEditor, evt.cellBounds, rowIndex, subItemIndex)

        # Let the world know the cell editing has started
        evt = OLVEvent.CellEditStartedEvent(self, rowIndex, subItemIndex, modelObject,
                                             cellValue, cellBounds, defaultEditor)
        self.GetEventHandler().ProcessEvent(evt)

        self.cellEditor.Show()
        self.cellEditor.Raise() 
Example #24
Source File: toolbar.py    From wxGlade with MIT License 4 votes vote down vote up
def on_char(self, event):
        # keyboard navigation: up/down arrows and also Tab on some buttons
        focus = self.FindFocus()
        k = event.GetKeyCode()

        if k==wx.WXK_TAB:
            if focus is self.type:
                self.label.SetFocus()
            else:
                event.Skip()
            return

        if k in (wx.WXK_DOWN, wx.WXK_UP) and focus is self.type:
            event.Skip()
            return

        if event.AltDown():
            if k==wx.WXK_RETURN or k==ord("O"):
                self.EndModal(wx.ID_OK)
                return
            if k==ord("C"):
                self.EndModal(wx.ID_CANCEL)
                return

        if event.ControlDown() and k==wx.WXK_RETURN:
            self.EndModal(wx.ID_OK)
            return

        if k==wx.WXK_RETURN:  # ignore Enter key
            return
        if k==wx.WXK_DOWN:
            if event.AltDown():
                self.move_item_down(event)
            else:
                if self.selected_index+1 < self.items.GetItemCount():
                    self._select_item(self.selected_index+1)
                else:
                    wx.Bell()
            return
        if k==wx.WXK_UP:
            if event.AltDown():
                self.move_item_up(event)
            else:
                if self.selected_index>0:
                    self._select_item(self.selected_index-1)
                else:
                    wx.Bell()
            return
        event.Skip() 
Example #25
Source File: menubar.py    From wxGlade with MIT License 4 votes vote down vote up
def on_char(self, event):
        # keyboard navigation: up/down arrows
        focus = self.FindFocus()
        k = event.GetKeyCode()
        if k==wx.WXK_TAB:
            if focus is self.type:
                self.label.SetFocus()
            else:
                event.Skip()
            return

        if k in (wx.WXK_DOWN, wx.WXK_UP) and focus is self.type:
            event.Skip()
            return

        if event.AltDown():
            if k==wx.WXK_RETURN or k==ord("O"):
                self.EndModal(wx.ID_OK)
                return
            if k==ord("C"):
                self.EndModal(wx.ID_CANCEL)
                return

        if event.ControlDown() and k==wx.WXK_RETURN:
            self.EndModal(wx.ID_OK)
            return

        if k==wx.WXK_RETURN:  # ignore Enter key
            return
        if k==wx.WXK_DOWN:
            if event.AltDown():
                self.move_item_down(event)
            else:
                if self.selected_index+1 < self.items.GetItemCount():
                    self._select_item(self.selected_index+1)
                else:
                    wx.Bell()
            return
        if k==wx.WXK_UP:
            if event.AltDown():
                self.move_item_up(event)
            else:
                if self.selected_index>0:
                    self._select_item(self.selected_index-1)
                else:
                    wx.Bell()
            return
        if k==wx.WXK_RIGHT and event.AltDown():
            self.move_item_right(event)
            return
        if k==wx.WXK_LEFT and event.AltDown():
            self.move_item_left(event)
            return
        event.Skip()