Browse Source

init

master
rra 4 years ago
commit
650ec62401
  1. 18
      README.md
  2. 143
      main.glade
  3. 111
      pom.py

18
README.md

@ -0,0 +1,18 @@
# pom
You need python3 and also:
`sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0`
To run: `python3 pom.py`
To edit interface: open `main.glade` in Glade
Useful resources:
<https://python-gtk-3-tutorial.readthedocs.io/en/latest/index.html>
<https://pygobject.readthedocs.io/en/latest/guide/index.html>

143
main.glade

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">preferences-other</property>
</object>
<object class="GtkApplicationWindow" id="Main">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="icon_name">dialog-ok</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="time_display">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xpad">12</property>
<property name="label" translatable="yes">0:00:00</property>
<attributes>
<attribute name="font-desc" value="Recursive Heavy 14"/>
<attribute name="weight" value="book"/>
<attribute name="scale" value="6"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">4</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">18</property>
<property name="margin_end">18</property>
<property name="margin_bottom">8</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Start</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="startCountdown" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">4</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Pause</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Pause the timer</property>
<signal name="clicked" handler="pauseCountdown" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">4</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Restart</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Stop the timer</property>
<signal name="clicked" handler="restartCountdown" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">4</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">8</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">0</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkSwitch" id="modeSwitch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Switch to work or break mode</property>
<property name="halign">center</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkStackSwitcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_start">6</property>
<property name="image">image1</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">5</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

111
pom.py

@ -0,0 +1,111 @@
import gi
import time
import datetime
import timeit
import threading
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
class Main:
def __init__(self):
self.timer = None
self.event = None
self.timer_running = False
self.builder = Gtk.Builder()
self.builder.add_from_file('main.glade')
#self.builder.add_from_file('secondtry.glade')
self.builder.connect_signals(self)
# button = self.builder.get_object("button")
# button.connect("clicked", self.printText)
window = self.builder.get_object("Main")
window.connect('delete-event', Gtk.main_quit)
window.show()
self.time_display = self.builder.get_object("time_display")
self.mode_switch = self.builder.get_object('modeSwitch')
self.mode_switch.connect('notify::active', self.work_break_switch)
self.POMTIME = 25 * 60
self.BREAKTIME = 5 * 60
self.LONGBREAK = 30 * 60
self.time_left = self.POMTIME
def updateDisplay(self,time_left):
self.clock = str(datetime.timedelta(seconds = self.time_left))
self.time_display.set_text(self.clock)
def countdown(self):
#self.time_left
future = datetime.datetime.now() + datetime.timedelta(seconds=self.time_left)
if self.timer_running:
while not self.event.is_set():
self.updateDisplay(self.time_left)
self.time_left -= 1
time.sleep(1)
if datetime.datetime.now() >= future:
if self.mode_switch.get_active():
self.time_left = self.POMTIME
print('swith on')
self.mode_switch.set_active(False)
else:
self.time_left = self.BREAKTIME
print('swith off')
self.mode_switch.set_active(True)
# add alarm or whatev here
#can add an auto continue?
self.pauseCountdown('')
def work_break_switch(self, switch, active):
if self.mode_switch.get_active():
state = "Pomtime"
self.time_left = self.POMTIME
else:
state = "Breaktime"
self.time_left = self.BREAKTIME
print("Switch was turned to", state)
self.updateDisplay(self.time_left)
self.pauseCountdown('')
def startCountdown(self,button):
print('Pressed start')
if not self.timer_running:
print('Started timer')
self.timer_running = True
self.timer = threading.Thread(target=self.countdown)
self.event = threading.Event()
self.timer.daemon=True
self.timer.start()
def pauseCountdown(self,button):
print('Pressed stop')
self.event.set()
self.timer.join()
self.timer_running = False
def restartCountdown(self, button):
print('Pressed restart')
self.time_left = self.POMTIME
self.work_break_switch(self.mode_switch,'')
self.event.set()
self.startCountdown(button)
if __name__ == '__main__':
main = Main()
Gtk.main()
Loading…
Cancel
Save