Example #1
0
    def on_settings_action(self, button):
        if button.props.label == "Add Shortcut":
            Gtk.show_uri_on_window(self, "settings://input/keyboard/shortcuts",
                                   GLib.get_current_time())

        if button.props.label == "Quit Stashed":
            self.destroy()
        if button.props.label == "Buy Me Coffee":
            Gtk.show_uri_on_window(None, "https://www.buymeacoffee.com/hezral",
                                   GLib.get_current_time())
Example #2
0
    def maybe_sync_appstream(self, executor, source):
        """ Check if appstream data needs updating """

        # Do we need appstream data update?
        fremote = source.get_remote()
        modtime = 0
        try:
            updatefile = fremote.get_appstream_timestamp()
            finfo = updatefile.query_info("*", 0, None)
            modtime = finfo.get_modification_time().tv_sec
            print(modtime)
        except Exception as e:
            print(e)

        time_now = GLib.get_current_time()

        if time_now - modtime < APPSTREAM_THRESHOLD_SECS:
            print("AppStream data for {} is up to date".format(source.name))
            print(time_now - modtime)
            return

        self.executor.set_progress_string(_("Updating AppStream data"))
        self.client.update_appstream_sync(
            source.name,
            Flatpak.get_default_arch(),  # Use local architecture
            None)

        self.executor = None
        print("flatpak appstream synced")
Example #3
0
    def maybe_sync_appstream(self, executor, source):
        """ Check if appstream data needs updating """

        # Do we need appstream data update?
        fremote = source.get_remote()
        modtime = 0
        try:
            updatefile = fremote.get_appstream_timestamp()
            finfo = updatefile.query_info("*", 0, None)
            modtime = finfo.get_modification_time().tv_sec
            print(modtime)
        except Exception as e:
            print(e)

        time_now = GLib.get_current_time()

        if time_now - modtime < APPSTREAM_THRESHOLD_SECS:
            print("AppStream data for {} is up to date".format(source.name))
            print(time_now - modtime)
            return

        self.executor.set_progress_string(_("Updating AppStream data"))
        self.client.update_appstream_sync(
            source.name,
            Flatpak.get_default_arch(),  # Use local architecture
            None)

        self.executor = None
        print("flatpak appstream synced")
Example #4
0
    def test_current_time(self):
        with warnings.catch_warnings(record=True) as warn:
            warnings.simplefilter('always')
            tm = GLib.get_current_time()
            self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))

        self.assertTrue(isinstance(tm, float))
        self.assertGreater(tm, 1350000000.0)
Example #5
0
    def test_current_time(self):
        with warnings.catch_warnings(record=True) as warn:
            warnings.simplefilter('always')
            tm = GLib.get_current_time()
            self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))

        self.assertTrue(isinstance(tm, float))
        self.assertGreater(tm, 1350000000.0)
Example #6
0
 def _timer_reset(self):
     ''' Reset the timer for each level '''
     self._start_time = GLib.get_current_time()
     if self._timer_id is not None:
         GLib.source_remove(self._timer_id)
         self._timer_id = None
     self.score += self._seconds
     self._time_increment()
Example #7
0
 def showBreakMessageUI(self, action):
     #Destroy any previous break message windows
     self.destroyBreakMsgWindow()
         
     #Update Label Timer 
     self.timerStart = GLib.get_current_time()
     self.timerEnd = self.timerStart + self.interval
     
     #Show UI
     self.breakMessageWindow = Gtk.Window()
     self.isBreakMsgWindowDestroyed = False
     self.breakMessageWindow.set_resizable(False)
     self.breakMessageWindow.set_position(Gtk.WindowPosition.CENTER)
     self.breakMessageWindow.set_size_request(375, 100)
     
     self.breakBox = Gtk.Box()
     self.breakBox.set_orientation(Gtk.Orientation.VERTICAL)
     
     self.breakReminderText = self.breakMsg
     self.breakReminderLabel = Gtk.Label(self.breakReminderText)
     self.breakReminderLabel.modify_font(self.mainWindow.ui.getFont("heading"))
     
     self.breakActionBox = Gtk.Box()
     self.breakActionBox.set_margin_top(10)
     self.breakActionBox.set_orientation(Gtk.Orientation.HORIZONTAL)
     
     self.breakOkBtn = Gtk.Button()
     self.breakOkBtn.set_label("OK")
     self.breakOkBtn.modify_font(self.mainWindow.ui.getFont("heading"))
     self.breakOkBtn.set_size_request(60, 30)
     self.breakOkBtn.set_margin_left(140)
     self.breakOkBtn.connect("clicked", self.destroyBreakMsgWindow)
     
     self.exerciseBtnText = "Show me some Exercises"
     self.exerciseBtn = Gtk.Button()
     self.exerciseBtn.set_label(self.exerciseBtnText)
     self.exerciseBtn.set_margin_left(5)
     self.exerciseBtn.set_size_request(200, 30)
     self.exerciseBtn.modify_font(self.mainWindow.ui.getFont("heading"))
     self.exerciseBtn.connect("clicked", self.showExerciseTab)
     
     self.breakActionBox.pack_start(self.breakOkBtn, False, False, 0)
     self.breakActionBox.pack_start(self.exerciseBtn, False, False, 0)
     
     self.breakBox.pack_start(self.breakReminderLabel, True, True, 0)
     self.breakBox.pack_start(self.breakActionBox, False, False, 0)
     
     self.breakMessageWindow.add(self.breakBox)
     
     self.breakMessageWindow.set_title("Break My Work - Take a break")
     self.breakMessageWindow.set_border_width(15)
     self.breakMessageWindow.show_all()
     
     debugLog("Action = %s, Interval = %d" % (self.action, self.interval))
     
     return True
Example #8
0
 def start(self):
     if not self.isRunning:
         self.timerStart = GLib.get_current_time()
         self._timer = GLib.timeout_add_seconds(self.interval, self.showBreakMessageUI, self.action)
         self.timerEnd = self.timerStart + self.interval
         self._labelTimer = GLib.timeout_add_seconds(self.labelInterval, self.updateAppLabel)
         #Call immediately to update the appLabel
         debugLog("Trying to update app label first time")
         self.updateAppLabel()
         self.isRunning = True
Example #9
0
 def updateAppLabel(self):
     self.currTime = GLib.get_current_time()
     debugLog("Inside UpdateAppLabel, currTime = %d, timerStart = %d, timerEnd = %d" % (self.currTime, self.timerStart, self.timerEnd))
     if(self.currTime < self.timerEnd):
         if(self.minuteMode):
             diff = int((self.timerEnd - self.currTime) / 60)
             self.mainWindow.updateAppIndicatorLabelInMins(diff)
         else:
             diff = int(self.timerEnd - self.currTime)
             self.mainWindow.updateAppIndicatorLabelInSecs(diff)
     return True
Example #10
0
 def __hscroll_out_init(self, distance, draw_area, duration, fps):
     self.__scroller = GLib.timeout_add(
         int(1000.0 / fps),  # interval
         self.__hscroll_out_cb,
         distance,
         duration*0.001,   # 1 over duration (converted to seconds)
         GLib.get_current_time(),
         draw_area.x,
         draw_area.y,
         draw_area.width,
         draw_area.height)
     return
Example #11
0
    def do_open(self, files, n_files, hint):
        """ Handle opening files. In practice we only open once, the last one.

        Args:
            files (`list` of :class:`~Gio.File`s): representing an array of files to open
            n_files (`int`): the number of files passed.
            hint (`str`): a hint, such as view, edit, etc. Should always be the empty string.
        """
        if not n_files:
            return

        self.do_activate(timestamp=GLib.get_current_time())
        self.gui.swap_document(files[-1].get_uri())
Example #12
0
    def __hscroll_out_cb(self, distance, duration, start_t, x, y, w, h):
        cur_t = GLib.get_current_time()
        xO = distance - distance*((cur_t - start_t) / duration)

        if xO > 0:
            self.__scroll_xO = xO
            self.queue_draw_area(x, y, w, h)
        else:   # final frame
            self.__scroll_xO = 0
            # redraw the entire widget
            # incase some timeouts are skipped due to high system load
            self.queue_draw()
            self.__scroller = None
            return False
        return True
 def advance(self, time=None):
   if time is None:
     time = GLib.get_current_time()
   if self.start_time == -1:
     self.start_time = time
     self.current_frame = 0
   else:
     elapsed = (time - self.start_time) * 1000
     diff = 0
     frame_id = -1
     while diff < elapsed:
       frame_id += 1
       frame_id = frame_id % len(self.frames)
       frame = self.frames[frame_id]
       diff += frame.getDelay()
     self.current_frame = frame_id
Example #14
0
    def do_activate(self, timestamp=GLib.get_current_time()):
        """ Activate: show UI windows.

        Build them if they do not exist, otherwise bring to front.
        """
        if self.gui is None:
            if self.auto_log_level:
                self.activate_action('log-level', logging.INFO)
                self.action_startup_queue.append(('log-level', logging.ERROR))

            # Build the UI and windows
            self.gui = ui.UI(self, self.config)

            while self.action_startup_queue:
                self.activate_action(*self.action_startup_queue.pop(0))

        Gtk.Application.do_activate(self)
        self.gui.p_win.present_with_time(timestamp)
 def mouseDrag(self, widget, event):
   self.last_move_time = GLib.get_current_time()
   if not self.drag:
     # show mouse
     self.showPointer(True)
   else:
     scrolled_window = self.builder.get_object('ScrolledWindow')
     # x drag
     offset_x = event.x - self.drag_x
     adjust_x = scrolled_window.get_hadjustment()
     new_value = adjust_x.get_value() - offset_x
     adjust_x.set_value(new_value)
     # y drag
     offset_y = event.y - self.drag_y
     adjust_y = scrolled_window.get_vadjustment()
     new_value = adjust_y.get_value() - offset_y
     adjust_y.set_value(new_value)
     # update drag
     self.drag_x = event.x
     self.drag_y = event.y
Example #16
0
File: shell.py Project: upman/sugar
 def close_window(self):
     self.get_window().close(GLib.get_current_time())
Example #17
0
 def close_window(self):
     self.get_window().close(GLib.get_current_time())
Example #18
0
    def close(self, request):
        self._activity.get_window().close(GLib.get_current_time())

        self._client.send_result(request, [])
Example #19
0
    def close_window(self):
        if self.get_window() is not None:
            self.get_window().close(GLib.get_current_time())

        for w in self._shell_windows:
            w.destroy()
 def checkMouseFade(self):
   if self.main_window_fullscreen:
     now = GLib.get_current_time()
     if now - self.last_move_time >= 1.0:
       self.showPointer(False)
   return True
Example #21
0
    def close(self, request):
        self._activity.get_window().close(GLib.get_current_time())

        self._client.send_result(request, [])
Example #22
0
 def _time_increment(self):
     ''' Track seconds since start_time. '''
     self._seconds = int(GLib.get_current_time() - self._start_time)
     self.timer_id = GLib.timeout_add(1000, self._time_increment)
Example #23
0
    def close_window(self):
        if self.get_window() is not None:
            self.get_window().close(GLib.get_current_time())

        for w in self._shell_windows:
            w.destroy()
 def __init__(self, image_viewer):
   self.image_viewer = image_viewer
   
   # set program class
   Gdk.set_program_class("IW Image Viewer")
   
   # setup ui builder
   self.builder = Gtk.Builder.new()
   ui_file = os.path.join(MAIN_FOLDER, 'ui/Main.glade')
   self.builder.add_from_file(ui_file)
   self.loadHeaderBar()
   
   self.main_window = self.builder.get_object('MainWindow')
   self.image_widget = self.builder.get_object('Image')
   #self.image_widget.set_name('image-checked')
   #self.main_window.add_events(Gdk.EventMask.STRUCTURE_MASK)
   self.main_window.set_size_request(*DEFAULT_SIZE)
   self.main_window.set_title('Image Viewer')
   
   self.width = 0
   self.height = 0
   
   scrolled_window = self.builder.get_object('ScrolledWindow')
   scrolled_window.set_min_content_width(MIN_CONTENT_SIZE)
   scrolled_window.set_min_content_height(MIN_CONTENT_SIZE)
   scrolled_window.add_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK)
   
   self.setErrorImage()
   
   self.loadCss()
   self.loadAccels()
   self.setupHeaderBar()
   self.applyColourSettings()
   self.setupSettingsWindow()
   
   self.main_window_fullscreen = False
   
   self.image = None
   self.current_factor = None
   self.user_set_zoom = False
   # Zoom
   self.mouse_delta = 0
   self.scroll_zoom_number = 0
   self.scroll_position_x = 0
   self.scroll_position_y = 0
   adjust_h = scrolled_window.get_hadjustment()
   adjust_h.connect('changed', self.scrollRelativeToMouse, SCROLL_ADJUST_HORIZONTAL)
   adjust_v = scrolled_window.get_vadjustment()
   adjust_v.connect('changed', self.scrollRelativeToMouse, SCROLL_ADJUST_VERTICAL)
   # Drag
   self.drag = False
   self.drag_x = 0
   self.drag_y = 0
   # Mouse fade
   self.last_move_time = GLib.get_current_time()
   self.fade_timeout = GObject.timeout_add(500, self.checkMouseFade)
   # Timeouts
   self.open_image_timeout = None
   self.inotify_timeout = None
   self.animation_update_timeout = None
   
   # Connect signals
   self.builder.connect_signals(SHandler(self))