Get and display location to the preference UI
This commit is contained in:
@@ -1204,43 +1204,21 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBoxRow" id="lbr_custom_location_longitude">
|
||||
<object class="GtkListBoxRow" id="lbr_current_location">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkLabel" id="lb_current_location">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">8</property>
|
||||
<property name="margin-end">8</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Longitude</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="etr_longitude">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<signal name="changed" handler="on_etr_longitude_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
<attributes>
|
||||
<attribute name="style" value="italic"/>
|
||||
</attributes>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
@@ -1288,6 +1266,48 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBoxRow" id="lbr_custom_location_longitude">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">8</property>
|
||||
<property name="margin-end">8</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Longitude</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="etr_longitude">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<signal name="changed" handler="on_etr_longitude_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBoxRow" id="lbr_time_periods">
|
||||
<property name="visible">True</property>
|
||||
|
||||
@@ -15,7 +15,8 @@ from gi.repository import Gtk, GdkPixbuf
|
||||
|
||||
|
||||
# Global definitions
|
||||
GLADE_URI = os.path.dirname(os.path.abspath(__file__)) + "/preferences.glade"
|
||||
PREFERENCES_URI = os.path.dirname(os.path.abspath(__file__))
|
||||
GLADE_URI = PREFERENCES_URI + "/preferences.glade"
|
||||
|
||||
|
||||
|
||||
@@ -93,6 +94,8 @@ class Preferences:
|
||||
|
||||
## Location & Times
|
||||
self.tb_network_location = self.builder.get_object("tb_network_location")
|
||||
self.lb_current_location = self.builder.get_object("lb_current_location")
|
||||
self.lbr_current_location = self.builder.get_object("lbr_current_location")
|
||||
self.tb_custom_location = self.builder.get_object("tb_custom_location")
|
||||
self.tb_time_periods = self.builder.get_object("tb_time_periods")
|
||||
self.lbr_network_location = self.builder.get_object("lbr_network_location")
|
||||
@@ -149,10 +152,10 @@ class Preferences:
|
||||
time_periods_min.append(time_range[0].hour * 60 + time_range[0].minute)
|
||||
|
||||
# Create time bar
|
||||
self.time_bar_chart.create_bar_chart(1200, 150, time_periods_min)
|
||||
self.time_bar_chart.create_bar_chart(PREFERENCES_URI, 1200, 150, time_periods_min)
|
||||
|
||||
# Load to the view
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file("time_bar.svg")
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(PREFERENCES_URI + "/time_bar.svg")
|
||||
self.img_bar.set_from_pixbuf(pixbuf)
|
||||
|
||||
|
||||
@@ -210,10 +213,27 @@ class Preferences:
|
||||
self.tb_time_periods.set_active(False)
|
||||
|
||||
self.lbr_network_location.set_visible(True)
|
||||
self.lbr_current_location.set_visible(True)
|
||||
self.lbr_custom_location_longitude.set_visible(False)
|
||||
self.lbr_custom_location_latitude.set_visible(False)
|
||||
self.lbr_time_periods.set_visible(False)
|
||||
|
||||
# Start a thread to get the current location
|
||||
locationThread = Location()
|
||||
locationThread.start()
|
||||
locationThread.join()
|
||||
|
||||
location = locationThread.result
|
||||
|
||||
# Display the location in the UI
|
||||
self.lb_current_location.set_text("Latitude: " + str(location["latitude"]) + ", Longitude: " + \
|
||||
str(location["longitude"]))
|
||||
|
||||
# Store the location to the preferences
|
||||
self.settings_dict[PrefenceEnums.LATITUDE] = location["latitude"]
|
||||
self.settings_dict[PrefenceEnums.LONGITUDE] = location["longitude"]
|
||||
|
||||
|
||||
def on_toggle_button_custom_location_clicked(self, button):
|
||||
if button.get_active():
|
||||
self.settings_dict[PrefenceEnums.PERIOD_SOURCE] = PeriodSourceEnum.CUSTOMLOCATION
|
||||
@@ -221,10 +241,12 @@ class Preferences:
|
||||
self.tb_time_periods.set_active(False)
|
||||
|
||||
self.lbr_network_location.set_visible(False)
|
||||
self.lbr_current_location.set_visible(False)
|
||||
self.lbr_custom_location_longitude.set_visible(True)
|
||||
self.lbr_custom_location_latitude.set_visible(True)
|
||||
self.lbr_time_periods.set_visible(False)
|
||||
|
||||
|
||||
def on_toggle_button_time_periods_clicked(self, button):
|
||||
if button.get_active():
|
||||
self.settings_dict[PrefenceEnums.PERIOD_SOURCE] = PeriodSourceEnum.CUSTOMTIMEPERIODS
|
||||
@@ -232,16 +254,20 @@ class Preferences:
|
||||
self.tb_custom_location.set_active(False)
|
||||
|
||||
self.lbr_network_location.set_visible(False)
|
||||
self.lbr_current_location.set_visible(False)
|
||||
self.lbr_custom_location_longitude.set_visible(False)
|
||||
self.lbr_custom_location_latitude.set_visible(False)
|
||||
self.lbr_time_periods.set_visible(True)
|
||||
|
||||
|
||||
def on_spb_network_location_refresh_time_changed(self, spin_button):
|
||||
self.settings_dict[PrefenceEnums.LOCATION_REFRESH_INTERVALS] = spin_button.get_value()
|
||||
|
||||
|
||||
def on_etr_longitude_changed(self, entry):
|
||||
self.settings_dict[PrefenceEnums.LONGITUDE] = entry.get_text()
|
||||
|
||||
|
||||
def on_etr_latitude_changed(self, entry):
|
||||
self.settings_dict[PrefenceEnums.LATITUDE] = entry.get_text()
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
def get_location_by_network() -> list:
|
||||
#todo
|
||||
return []
|
||||
import urllib.request, json
|
||||
from threading import Thread
|
||||
|
||||
class Location(Thread):
|
||||
def __init__(self):
|
||||
Thread.__init__(self)
|
||||
self.GEO_URL = "https://get.geojs.io/v1/ip/geo.json"
|
||||
|
||||
def run(self) -> dict:
|
||||
request = urllib.request.urlopen(self.GEO_URL)
|
||||
|
||||
data = json.load(request)
|
||||
|
||||
self.result = {
|
||||
"latitude": data["latitude"],
|
||||
"longitude": data["longitude"]
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Time_Bar_Chart:
|
||||
self.bar_pos_x = []
|
||||
|
||||
|
||||
def create_bar_chart(self, image_width: int, image_height: int, times: list):
|
||||
def create_bar_chart(self, save_location: str, image_width: int, image_height: int, times: list):
|
||||
""" Create a time bar chart
|
||||
|
||||
Args:
|
||||
@@ -36,7 +36,7 @@ class Time_Bar_Chart:
|
||||
self.image_code.insert(0, '<svg xmlns="http://www.w3.org/2000/svg" width="%s" height="%s">' % (image_width, image_height))
|
||||
self.image_code.append('</svg>')
|
||||
|
||||
file = open("time_bar.svg", "w")
|
||||
file = open(save_location + "/time_bar.svg", "w")
|
||||
for i in self.image_code:
|
||||
file.write(i + '\n')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user