Beispiel #1
0
 def _find_controller_not_found_cb(self, find_controller):
     self.textsearch_matches_label.set_markup('<span foreground="red">' +
                                              str(0) + '</span>')
     self.textsearch_prev_button.set_sensitive(False)
     self.textsearch_next_button.set_sensitive(False)
     find_controller.search_finish()
     Gdk.beep()
Beispiel #2
0
 def on_entry_keypress(self, widegt, event):
     kv = event.keyval
     if kv == Gdk.KEY_Up:
         row = self.get_row(
         )  # Highlighted row path, or the last row's path
         if row.prev():
             self.view.set_cursor([
                 row,
             ], None, False)
         else:
             Gdk.beep()  # Complain if we are already on the top row
         return True
     elif kv == Gdk.KEY_Down:
         # For some odd reason row.next() returns None, instead of a bool
         # indication if the row is valid like row.prev() does, so we have
         # to do our own validation here.
         row = self.get_row(
         )  # Highlighted row path, or the last row's path
         last_row = Gtk.TreePath.new_from_indices([
             len(self.entry.model),
         ])
         row.next()
         if row != last_row:
             self.view.set_cursor([
                 row,
             ], None, False)
         else:
             Gdk.beep()  # Complain if we are already on the last row
         return True
Beispiel #3
0
    def new_text_notification(self,
                              message,
                              title=None,
                              priority=Gio.NotificationPriority.NORMAL):

        if title is None:
            title = GLib.get_application_name()

        try:
            if sys.platform == "win32":
                self.win_notification.notify(title=title, message=message)

                if config.sections["notifications"][
                        "notification_popup_sound"]:
                    import winsound
                    winsound.PlaySound("SystemAsterisk", winsound.SND_ALIAS)

                return

            notification_popup = Gio.Notification.new(title)
            notification_popup.set_body(message)

            if self.frame.images["notify"]:
                notification_popup.set_icon(self.frame.images["notify"])

            notification_popup.set_priority(priority)

            self.application.send_notification(None, notification_popup)

            if config.sections["notifications"]["notification_popup_sound"]:
                Gdk.beep()

        except Exception as error:
            log.add(_("Unable to show notification popup: %s"), str(error))
Beispiel #4
0
    def sellable_selected(self, sellable, batch=None):
        super(InventoryCountItemStep, self).sellable_selected(sellable, batch)
        if not self.proxy.model.sellable:
            return

        self._hide_error_message()
        Gdk.beep()
        self._add_sellable(reset_proxy=False)
Beispiel #5
0
    def on_activate(self, widget):
        '''Evaluate entry and set axis position to value.'''
        expr = self.entry.get_text()

        try:
            val = entry_eval.eval(expr)
            command.set_work_coordinate(self.axis_letter, val)
            self.unselect()
        except Exception as e:
            log.exception(e)
            self.style_context.add_class('error')
            Gdk.beep()
Beispiel #6
0
    def lock(self, msg, unlock_secs=None):
        """Lock the screen. Unlock after unlock_secs if it's not None."""
        screen = Gdk.Screen.get_default()
        swidth = screen.get_width()
        sheight = screen.get_height()
        smin = min(swidth, sheight)

        gtk_provider = Gtk.CssProvider()
        gtk_context = Gtk.StyleContext()
        gtk_context.add_provider_for_screen(
            screen, gtk_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        gtk_provider.load_from_data(
            bytes("""
* {{ transition-property: color;  transition-duration: 4s; }}
window, GtkWindow {{ background-color: black; }}
label, GtkLabel {{ font-size: {0:.0f}px; }}
label#black, GtkLabel#black {{ color: black; }}
label#white, GtkLabel#white {{ color: #e0e0e0; }}
""".format(swidth / 70).encode()))

        backlock = Gtk.Window(type=Gtk.WindowType.POPUP)
        self.backlock = backlock
        backlock.resize(1, 1)
        frontview = Gtk.Window()
        self.frontview = frontview
        frontview.resize(swidth, sheight)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                      spacing=smin / 12,
                      halign=Gtk.Align.CENTER,
                      valign=Gtk.Align.CENTER)
        image = Gtk.Image(pixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size(
            'lock.svg', smin / 3, smin / 3))
        box.pack_start(image, False, False, 0)
        self.label = Gtk.Label(label=msg, name="black")
        box.pack_start(self.label, False, False, 0)
        frontview.add(box)

        backlock.show_all()
        frontview.show_all()

        frontview.set_keep_above(True)
        frontview.fullscreen()
        Gdk.beep()
        Gdk.keyboard_grab(backlock.get_window(), False, 0)

        # Transitions need an event to start
        GLib.timeout_add(100, self.do_transition)

        # While developing, to only lock the screen for e.g. 5 seconds, run:
        # ./lock-screen "" 5
        if unlock_secs is not None:
            GLib.timeout_add(unlock_secs * 1000, self.unlock)
Beispiel #7
0
    def new_notification(self,
                         message,
                         title=None,
                         priority=Gio.NotificationPriority.NORMAL):

        if title is None:
            title = GLib.get_application_name()

        try:
            if sys.platform == "win32":
                """ Windows notification popup support via plyer
                Once https://gitlab.gnome.org/GNOME/glib/-/issues/1234 is implemented, we can drop plyer """

                from plyer import notification

                notification.notify(app_name=GLib.get_application_name(),
                                    title=title,
                                    message=message)

                if self.frame.np.config.sections["notifications"][
                        "notification_popup_sound"]:
                    import winsound
                    winsound.PlaySound("SystemAsterisk", winsound.SND_ALIAS)
                return

            notification_popup = Gio.Notification.new(title)
            notification_popup.set_body(message)

            if self.frame.images["notify"]:
                notification_popup.set_icon(self.frame.images["notify"])

            notification_popup.set_priority(priority)

            self.application.send_notification(None, notification_popup)

            if self.frame.np.config.sections["notifications"][
                    "notification_popup_sound"]:
                Gdk.beep()

        except Exception as error:
            log.add(_("Unable to show notification popup: %s"), str(error))
Beispiel #8
0
    def _on_delete_text(self, editable, start, end):
        if not self._mask or self._block_delete:
            return

        self.stop_emission_by_name('delete-text')

        if end == -1:
            end = len(self.get_text())

        # When deleting with backspace just after a static char, we
        # should delete the char before it. This is the only case that
        # _delete_char_at_position will not handle for us
        if end - start == 1 and not self._selecting:
            for pos in reversed(range(0, self.get_position() + 1)):
                validator = self._mask_validators[start]
                if isinstance(validator, str) or validator == ' ':
                    start -= 1
                    end -= 1
                else:
                    break
        else:
            pos = self.get_position()

        # This will happen if there was a static char at the beggining and
        # someone pressed backspace on it. Nothing to do
        if start < 0:
            Gdk.beep()
            return

        for pos in reversed(range(start, end)):
            validator = self._mask_validators[pos]
            # Only delete the char if it's not a static char. Since we are
            # threating the case where we are pressing del/backspace on that
            # char above, this is for sure a selection deletion.
            if isinstance(validator, str):
                continue
            self._delete_char_at_position(pos)

        # we just tried to delete, stop the selection.
        self._selecting = False
        self.set_position(start)
Beispiel #9
0
    def _on_delete_text(self, editable, start, end):
        if not self._mask or self._block_delete:
            return

        self.stop_emission_by_name('delete-text')

        if end == -1:
            end = len(self.get_text())

        # When deleting with backspace just after a static char, we
        # should delete the char before it. This is the only case that
        # _delete_char_at_position will not handle for us
        if end - start == 1 and not self._selecting:
            for pos in reversed(range(0, self.get_position() + 1)):
                validator = self._mask_validators[start]
                if isinstance(validator, str) or validator == ' ':
                    start -= 1
                    end -= 1
                else:
                    break
        else:
            pos = self.get_position()

        # This will happen if there was a static char at the beggining and
        # someone pressed backspace on it. Nothing to do
        if start < 0:
            Gdk.beep()
            return

        for pos in reversed(range(start, end)):
            validator = self._mask_validators[pos]
            # Only delete the char if it's not a static char. Since we are
            # threating the case where we are pressing del/backspace on that
            # char above, this is for sure a selection deletion.
            if isinstance(validator, str):
                continue
            self._delete_char_at_position(pos)

        # we just tried to delete, stop the selection.
        self._selecting = False
        self.set_position(start)
Beispiel #10
0
    def _can_insert_at_pos(self, new, pos):
        """
        Check if a chararcter can be inserted at some position

        :param new: The char that wants to be inserted.
        :param pos: The position where it wants to be inserted.
        :returns: Returns None if it can be inserted. If it cannot be, 
                  return the next position where it can be successfuly
                  inserted.
        """
        validators = self._mask_validators

        # Do not let insert if the field is full
        field = self._get_field_at_pos(pos)
        if field is not None:
            text = self.get_field_text(field)
            length = self.get_field_length(field)
            if len(text) == length:
                Gdk.beep()
                return pos

        # If the char confirms to the mask, but is a static char, return the
        # position after that static char.
        if (self._confirms_to_mask(pos, new) and
            not isinstance(validators[pos], int)):
            return pos+1

        # If does not confirms to mask:
        #  - Check if the char the user just tried to enter appers later.
        #  - If it does, Jump to the start of the field after that
        if not self._confirms_to_mask(pos, new):
            field = self._appers_later(new, pos)
            if field is not False:
                pos = self.get_field_pos(field+1)
                if pos is not None:
                    GLib.idle_add(self.set_position, pos)
            return pos

        return None
Beispiel #11
0
    def _can_insert_at_pos(self, new, pos):
        """
        Check if a chararcter can be inserted at some position

        :param new: The char that wants to be inserted.
        :param pos: The position where it wants to be inserted.
        :returns: Returns None if it can be inserted. If it cannot be, 
                  return the next position where it can be successfuly
                  inserted.
        """
        validators = self._mask_validators

        # Do not let insert if the field is full
        field = self._get_field_at_pos(pos)
        if field is not None:
            text = self.get_field_text(field)
            length = self.get_field_length(field)
            if len(text) == length:
                Gdk.beep()
                return pos

        # If the char confirms to the mask, but is a static char, return the
        # position after that static char.
        if (self._confirms_to_mask(pos, new) and
            not isinstance(validators[pos], int)):
            return pos+1

        # If does not confirms to mask:
        #  - Check if the char the user just tried to enter appers later.
        #  - If it does, Jump to the start of the field after that
        if not self._confirms_to_mask(pos, new):
            field = self._appers_later(new, pos)
            if field is not False:
                pos = self.get_field_pos(field+1)
                if pos is not None:
                    GLib.idle_add(self.set_position, pos)
            return pos

        return None
Beispiel #12
0
    def _on_insert_text(self, editable, new, length, position):
        if not self._mask or self._block_insert:
            return

        self.stop_emission_by_name('insert-text')

        text = self.get_text()
        pos = self.get_position()

        # self.set_text('') will fall into this
        if not len(new):
            return

        # If the first char on the mask is static and someone is trying to
        # insert it again (via set_text, ctrl+v, etc), remove it or it will
        # conflict with our optimization on _handle_position_change that
        # doesn't allow the position to be on 0 on and mess things here
        if self.is_empty() and pos != 0 and not self._selecting:
            for pos_ in range(0, len(text)):
                validator = self._mask_validators[pos_]
                if isinstance(validator, str) and new[0] == validator:
                    new = new[1:]
                else:
                    break
        else:
            pos = self.get_position()

        if pos >= len(text):
            Gdk.beep()
            return

        for c in new:
            pos = self._insert_char_at_position(pos, c)
            # If pos is None, the char is not valid. When typing, it will just
            # beep. When pasting something like 'vviv' (v for valid i for
            # invalid), it will insert vv and stop after that, beeping.
            # We cannot simply skip it as the order of a string matters
            if pos is None:
                Gdk.beep()
                return
            pos += 1

        # If the last char was inserted at a static char position (and thus,
        # it was really inserted at that pos + 1), put the cursor after that
        while pos < len(text):
            validator = self._mask_validators[pos]
            if not isinstance(validator, str):
                break
            pos += 1

        # FIXME: gtk_entry.c sends the position arg as a pointer to call
        # set_position later. We cannot modify the pointed value from here.
        # Because of that, after this another call to set_position will be
        # made to set the cursor on the pointed value that didn't change,
        # so we just need to ignore that second call.
        self._pos = None
        self._keep_next_position = True
        self.set_position(pos)

        # This is a specific workaround to when text is pasted in the entry.
        # When that happens, the call to set_position above will not notify
        # cursor-position neither selectiuon-bound and thus,
        # self._handle_position_change will not be called. By calling it by
        # hand we will be sure that it will keep next position the right way
        if self._pos is None:
            self._handle_position_change()
Beispiel #13
0
def _asynsound():
    #print("Thread start")
    Gdk.beep()
    #playsound("/usr/share/sounds/freedesktop/stereo/complete.oga")
    playsound("/usr/share/sounds/freedesktop/stereo/complete.oga")
Beispiel #14
0
    def interpret_packet(self, builder=None, users_manager=None):

        if self.packet_type is None:
            return

        if int(self.packet_type) == FIN_PACKET:
            return False
        elif int(self.packet_type) == ACK_PACKET:
            return True
        elif int(self.packet_type) == MSG_PACKET:
            assert builder is not None, "builder cannot be None"
            assert users_manager is not None, "Users manager is None"

            listbox = builder.get_object("users_listbox")

            uid = str(uuid.uuid4().hex)
            Gdk.beep()

            if int(self.userid) == int(users_manager.curr_receiver_user
                                       ):  #if sender is the one in focus
                list_display = listener.Custom_Message_Display(builder,
                                                               users_manager,
                                                               message=str(
                                                                   self.mesg))
                list_display.set_display_uid(uid)
                list_display.write_to_display()
                list_display.auto_scroll_listbox()

                tim = time.time()

                try:
                    users_manager.database_manager.cursor.execute(
                        "INSERT INTO messages \
                                                                VALUES('%s', %d, %d, %ld, %ld, %d, '%s') \
                                                                " % (
                            uid,  #unique id for messages
                            int(self.userid),  #sender id
                            int(self.receiverid),  #receiver id
                            tim,  #time sent(in seconds since unix epoch)
                            tim,  #time read(in seconds since unix epoch)
                            int(self.mesg_type),  #message type
                            self.mesg))  #message
                    users_manager.database_manager.db.commit()
                except Exception:
                    users_manager.database_manager.db.rollback()
            else:
                children = listbox.get_children()
                for child in children:
                    if int(child.userid) == int(self.userid):
                        count = int(
                            child.button.message_count_label.get_label())
                        count = count + 1
                        child.button.message_count_label.set_label("%d" %
                                                                   count)

                tim = time.time()

                try:
                    users_manager.database_manager.cursor.execute(
                        "INSERT INTO messages \
                                                                VALUES('%s', %d, %d, %ld, %ld, %d, '%s') \
                                                                " % (
                            uid,  #unique id for messages
                            int(self.userid),  #sender id
                            int(self.receiverid),  #receiver id
                            tim,  #time sent(in seconds since unix epoch)
                            int(-1),  #time read(in seconds since unix epoch)
                            int(self.mesg_type),  #message type
                            self.mesg))

                    users_manager.database_manager.db.commit()
                except Exception:
                    users_manager.database_manager.db.rollback()

            return True
Beispiel #15
0
    def _on_insert_text(self, editable, new, length, position):
        if not self._mask or self._block_insert:
            return

        self.stop_emission_by_name('insert-text')

        text = self.get_text()
        pos = self.get_position()

        # self.set_text('') will fall into this
        if not len(new):
            return

        # If the first char on the mask is static and someone is trying to
        # insert it again (via set_text, ctrl+v, etc), remove it or it will
        # conflict with our optimization on _handle_position_change that
        # doesn't allow the position to be on 0 on and mess things here
        if self.is_empty() and pos != 0 and not self._selecting:
            for pos_ in range(0, len(text)):
                validator = self._mask_validators[pos_]
                if isinstance(validator, str) and new[0] == validator:
                    new = new[1:]
                else:
                    break
        else:
            pos = self.get_position()

        if pos >= len(text):
            Gdk.beep()
            return

        for c in new:
            pos = self._insert_char_at_position(pos, c)
            # If pos is None, the char is not valid. When typing, it will just
            # beep. When pasting something like 'vviv' (v for valid i for
            # invalid), it will insert vv and stop after that, beeping.
            # We cannot simply skip it as the order of a string matters
            if pos is None:
                Gdk.beep()
                return
            pos += 1

        # If the last char was inserted at a static char position (and thus,
        # it was really inserted at that pos + 1), put the cursor after that
        while pos < len(text):
            validator = self._mask_validators[pos]
            if not isinstance(validator, str):
                break
            pos += 1

        # FIXME: gtk_entry.c sends the position arg as a pointer to call
        # set_position later. We cannot modify the pointed value from here.
        # Because of that, after this another call to set_position will be
        # made to set the cursor on the pointed value that didn't change,
        # so we just need to ignore that second call.
        self._pos = None
        self._keep_next_position = True
        self.set_position(pos)

        # This is a specific workaround to when text is pasted in the entry.
        # When that happens, the call to set_position above will not notify
        # cursor-position neither selectiuon-bound and thus,
        # self._handle_position_change will not be called. By calling it by
        # hand we will be sure that it will keep next position the right way
        if self._pos is None:
            self._handle_position_change()
Beispiel #16
0
  def key_press(self, view, event):
    if self.popup!=None:
      # handle maneuvering inside the completion popup 
      if event.keyval == gdk.KEY_Up or \
         event.keyval == gdk.KEY_ISO_Left_Tab or \
        (event.keyval == gdk.KEY_p and event.state & gdk.ModifierType.CONTROL_MASK):
        self.popup.prev()
        return True 
      elif event.keyval == gdk.KEY_Page_Up:
        self.popup.prev(page=True)
        return True
      elif event.keyval == gdk.KEY_Down or \
           event.keyval == gdk.KEY_Tab or \
          (event.keyval == gdk.KEY_n and event.state & gdk.ModifierType.CONTROL_MASK):
        self.popup.next()
        return True 
      elif event.keyval == gdk.KEY_Page_Down:
        self.popup.next(page=True)
        return True
      elif event.keyval in [gdk.KEY_Return, gdk.KEY_KP_Enter]:
        self.popup.sel_confirmed()
        self.popup=None
        return True 
      elif event.keyval in [ gdk.KEY_Control_L, gdk.KEY_Control_R,
                             gdk.KEY_Shift_L,   gdk.KEY_Shift_R,
                             gdk.KEY_Alt_L,     gdk.KEY_Alt_R ]:
        return False
      else:
        self.popup.hide()
        self.popup=None
    else:
      end=self.buffer.get_end_iter()
      start=self.buffer.get_iter_at_line(end.get_line())

      if event.keyval ==gdk.KEY_Up or \
        (event.keyval == gdk.KEY_p and event.state & gdk.ModifierType.CONTROL_MASK):
        # emacs style
        if self.history_pos > 0:
          if self.history_pos == len(self.history):
            # save current edits for later...
            self.tmp_current_line = self.get_line()

          # remove text into the line...
          start.forward_chars(4)
          self.buffer.delete(start,end)
          #inset the new text
          pos=self.buffer.get_end_iter()
          self.history_pos-=1
          self.buffer.insert(pos, self.history[self.history_pos])
        else:
          gdk.beep()
        self.view.emit_stop_by_name("key-press-event")
        return True
        
      elif event.keyval ==gdk.KEY_Down or \
          (event.keyval == gdk.KEY_n and event.state & gdk.ModifierType.CONTROL_MASK):
        # emacs style
        if self.history_pos < len(self.history):
          # remove text into the line...
          start.forward_chars(4)
          self.buffer.delete(start,end)
          #inset the new text
          pos=self.buffer.get_end_iter()
          self.history_pos+=1
          if self.history_pos == len(self.history):
            txt = self.tmp_current_line
            self.tmp_current_line = ''
          else:
            txt = self.history[self.history_pos]
          self.buffer.insert(pos, txt)

        else:
          gdk.beep()
        self.view.emit_stop_by_name("key-press-event")
        return True

      elif event.keyval ==gdk.KEY_f and event.state & gdk.ModifierType.CONTROL_MASK:
        # emacs style
        iter=self.buffer.get_iter_at_mark(self.buffer.get_insert())
        iter.forward_cursor_position()
        self.buffer.place_cursor(iter)
        return True

      elif event.keyval ==gdk.KEY_b and event.state & gdk.ModifierType.CONTROL_MASK:
        # emacs style
        iter=self.buffer.get_iter_at_mark(self.buffer.get_insert())
        iter.backward_cursor_position()
        if iter.editable(True):
          self.buffer.place_cursor(iter)
        return True

      elif event.keyval == gdk.KEY_Left:
        iter=self.buffer.get_iter_at_mark(self.buffer.get_insert())
        iter.backward_cursor_position()
        if not iter.editable(True):
          return True
        return False

      elif event.keyval == gdk.KEY_Home or \
          (event.keyval == gdk.KEY_a and
           event.state & gdk.ModifierType.CONTROL_MASK):
        # emacs style
        start,end=self.get_line_iters()
        self.buffer.place_cursor( start )
        return True

      elif event.keyval ==gdk.KEY_e and event.state & gdk.ModifierType.CONTROL_MASK:
        # emacs style
        start,end=self.get_line_iters()
        self.buffer.place_cursor( end )
        return True

      elif event.keyval == gdk.KEY_d and event.state & gdk.ModifierType.CONTROL_MASK:
        # emacs style
        iter=self.buffer.get_iter_at_mark(self.buffer.get_insert())
        next_iter = iter.copy()
        next_iter.forward_cursor_position()
        self.buffer.delete(iter, next_iter)
        return True

      elif event.keyval == gdk.KEY_u and event.state & gdk.ModifierType.CONTROL_MASK:
        # emacs style
        start,end=self.get_line_iters()
        iter=self.buffer.get_iter_at_mark(self.buffer.get_insert())
        self.buffer.delete(start, iter)
        return True

      elif event.keyval ==gdk.KEY_Tab:
        if not self.get_line().strip():
          iter=self.buffer.get_iter_at_mark(self.buffer.get_insert())
          self.buffer.insert(iter,TAB_WIDTH*" ")
        else:
          self.complete_text()
        return True

      elif event.keyval in [gdk.KEY_Return, gdk.KEY_KP_Enter]:
        command=self.get_line()
        self.exec_code(command)
        start,end=self.buffer.get_bounds()
        self.buffer.apply_tag_by_name("no_edit",start,end)
        self.buffer.place_cursor(end)

        return True

      elif event.keyval ==gdk.KEY_space and event.state & gdk.ModifierType.CONTROL_MASK:
        self.complete_text()
        return True