1 | import gi |
---|
2 | gi.require_version('Gtk', '3.0') |
---|
3 | from gi.repository import Gtk, Pango, GdkPixbuf, Gdk, Gio, GObject,GLib |
---|
4 | |
---|
5 | import copy |
---|
6 | import gettext |
---|
7 | import Core |
---|
8 | |
---|
9 | import Dialog |
---|
10 | import time |
---|
11 | import threading |
---|
12 | import sys |
---|
13 | import os |
---|
14 | |
---|
15 | _=gettext.gettext |
---|
16 | |
---|
17 | |
---|
18 | RSRC="./" |
---|
19 | PROFILE_IMAGE=RSRC+"rsrc/profile.svg" |
---|
20 | FOLDER_IMAGE=RSRC+"rsrc/folder.svg" |
---|
21 | MOUNT_ON_IMAGE=RSRC+"rsrc/mount_on.svg" |
---|
22 | MOUNT_OFF_IMAGE=RSRC+"rsrc/mount_off.svg" |
---|
23 | EDIT_IMAGE=RSRC+"rsrc/edit.svg" |
---|
24 | DELETE_IMAGE=RSRC+"rsrc/trash.svg" |
---|
25 | |
---|
26 | class ProfileBox(Gtk.VBox): |
---|
27 | |
---|
28 | def __init__(self): |
---|
29 | |
---|
30 | Gtk.VBox.__init__(self) |
---|
31 | |
---|
32 | self.core=Core.Core.get_core() |
---|
33 | |
---|
34 | builder=Gtk.Builder() |
---|
35 | ui_path=RSRC + "/rsrc/lliurex-gdrive.ui" |
---|
36 | builder.add_from_file(ui_path) |
---|
37 | self.main_box=builder.get_object("profile_data_box") |
---|
38 | self.profiles_list_label=builder.get_object("profiles_list_label") |
---|
39 | self.profile_list_box=builder.get_object("profile_list_box") |
---|
40 | self.profile_list_vp=builder.get_object("profile_list_viewport") |
---|
41 | self.add_new_profile_button=builder.get_object("add_new_profile_button") |
---|
42 | self.exit_button=builder.get_object("exit_button") |
---|
43 | self.new_profile_window=builder.get_object("new_profile_window") |
---|
44 | self.profile_label=builder.get_object("profile_label") |
---|
45 | self.profile_entry=builder.get_object("profile_entry") |
---|
46 | self.email_label=builder.get_object("email_label") |
---|
47 | self.email_entry=builder.get_object("email_entry") |
---|
48 | self.mountpoint_label=builder.get_object("mountpoint_label") |
---|
49 | self.mountpoint_entry=builder.get_object("mountpoint_entry") |
---|
50 | self.automount_label=builder.get_object("automount_label") |
---|
51 | self.automount_entry=builder.get_object("automount_entry") |
---|
52 | self.accept_add_profile_button=builder.get_object("accept_add_profile_button") |
---|
53 | self.cancel_add_profile_button=builder.get_object("cancel_add_profile_button") |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | self.pack_start(self.main_box,True,True,0) |
---|
60 | |
---|
61 | self.connect_signals() |
---|
62 | self.set_css_info() |
---|
63 | |
---|
64 | #self.current_var=None |
---|
65 | #self.current_id=None |
---|
66 | |
---|
67 | #self.thread=threading.Thread() |
---|
68 | #self.thread_ret=None |
---|
69 | |
---|
70 | #def __init__ |
---|
71 | |
---|
72 | |
---|
73 | def set_css_info(self): |
---|
74 | |
---|
75 | self.style_provider=Gtk.CssProvider() |
---|
76 | f=Gio.File.new_for_path("lliurex-gdrive.css") |
---|
77 | self.style_provider.load_from_file(f) |
---|
78 | Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) |
---|
79 | self.profiles_list_label.set_name("OPTION_LABEL") |
---|
80 | self.profile_label.set_name("OPTION_LABEL") |
---|
81 | self.email_label.set_name("OPTION_LABEL") |
---|
82 | self.mountpoint_label.set_name("OPTION_LABEL") |
---|
83 | self.automount_label.set_name("OPTION_LABEL") |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | #def set-css_info |
---|
89 | |
---|
90 | |
---|
91 | def connect_signals(self): |
---|
92 | |
---|
93 | self.add_new_profile_button.connect("clicked",self.add_new_profile_button_clicked) |
---|
94 | self.exit_button.connect("clicked",self.quit) |
---|
95 | self.accept_add_profile_button.connect("clicked",self.accept_add_profile_clicked) |
---|
96 | #self.cancel_add_profile_button.connect("clicked",self.cancel_add_profile_button) |
---|
97 | self.new_profile_window.connect("delete_event",self.hide_window) |
---|
98 | |
---|
99 | |
---|
100 | #def connect_signals |
---|
101 | |
---|
102 | def load_info(self,info): |
---|
103 | |
---|
104 | for item in info: |
---|
105 | profile=item |
---|
106 | email=info[item]["email"] |
---|
107 | mountpoint=info[item]["mountpoint"] |
---|
108 | self.new_profile_button(profile,email,mountpoint) |
---|
109 | |
---|
110 | def hide_window(self,widget,event): |
---|
111 | |
---|
112 | widget.hide() |
---|
113 | return True |
---|
114 | |
---|
115 | def add_new_profile_button_clicked(self,widget): |
---|
116 | |
---|
117 | self.profile_entry.set_text("") |
---|
118 | self.email_entry.set_text("") |
---|
119 | self.mountpoint_entry.set_filename(os.environ["HOME"]) |
---|
120 | self.automount_entry.set_state(False) |
---|
121 | self.new_profile_window.show() |
---|
122 | |
---|
123 | |
---|
124 | def new_profile_button(self,profile_name,email,mountpoint): |
---|
125 | |
---|
126 | hbox=Gtk.HBox() |
---|
127 | profile_image=Gtk.Image.new_from_file(PROFILE_IMAGE) |
---|
128 | profile_image.set_margin_left(10) |
---|
129 | profile_image.set_halign(Gtk.Align.CENTER) |
---|
130 | profile_image.set_valign(Gtk.Align.CENTER) |
---|
131 | profile_info="<span font='Roboto'><b>"+profile_name+"</b></span>\n"+"<span font='Roboto'>"+email+"</span>" |
---|
132 | profile=Gtk.Label() |
---|
133 | profile.set_markup(profile_info) |
---|
134 | profile.set_margin_left(10) |
---|
135 | profile.set_margin_right(20) |
---|
136 | profile.set_margin_top(20) |
---|
137 | profile.set_margin_bottom(20) |
---|
138 | folder_image=Gtk.Image.new_from_file(FOLDER_IMAGE) |
---|
139 | folder_image.set_margin_left(20) |
---|
140 | folder_image.set_halign(Gtk.Align.CENTER) |
---|
141 | folder_image.set_valign(Gtk.Align.CENTER) |
---|
142 | folder=Gtk.Label() |
---|
143 | folder.set_text(mountpoint) |
---|
144 | folder.set_margin_left(10) |
---|
145 | delete=Gtk.Button() |
---|
146 | delete_image=Gtk.Image.new_from_file(DELETE_IMAGE) |
---|
147 | delete.add(delete_image) |
---|
148 | delete.set_halign(Gtk.Align.CENTER) |
---|
149 | delete.set_valign(Gtk.Align.CENTER) |
---|
150 | delete.set_name("DELETE_ITEM_BUTTON") |
---|
151 | delete.connect("clicked",self.delete_profile_clicked,hbox) |
---|
152 | delete.set_tooltip_text(_("Delete profile")) |
---|
153 | edit=Gtk.Button() |
---|
154 | edit_image=Gtk.Image.new_from_file(EDIT_IMAGE) |
---|
155 | edit.add(edit_image) |
---|
156 | edit.set_halign(Gtk.Align.CENTER) |
---|
157 | edit.set_valign(Gtk.Align.CENTER) |
---|
158 | edit.set_name("EDIT_ITEM_BUTTON") |
---|
159 | edit.connect("clicked",self.edit_profile_clicked,hbox) |
---|
160 | edit.set_tooltip_text(_("Edit profile")) |
---|
161 | mount=Gtk.Button() |
---|
162 | mount_image=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
163 | mount.add(mount_image) |
---|
164 | mount.set_halign(Gtk.Align.CENTER) |
---|
165 | mount.set_valign(Gtk.Align.CENTER) |
---|
166 | mount.set_name("MOUNT_ITEM_BUTTON") |
---|
167 | mount.connect("clicked",self.mount_profile_clicked,hbox) |
---|
168 | mount.set_tooltip_text(_("Mount profile")) |
---|
169 | hbox.pack_start(profile_image,False,False,0) |
---|
170 | hbox.pack_start(profile,False,False,0) |
---|
171 | hbox.pack_start(folder_image,False,False,0) |
---|
172 | hbox.pack_start(folder,False,False,0) |
---|
173 | hbox.pack_end(delete,False,False,10) |
---|
174 | hbox.pack_end(edit,False,False,10) |
---|
175 | hbox.pack_end(mount,False,False,10) |
---|
176 | hbox.show_all() |
---|
177 | hbox.set_name("PROFILE_BOX") |
---|
178 | self.profile_list_box.pack_start(hbox,False,False,5) |
---|
179 | self.profile_list_box.queue_draw() |
---|
180 | hbox.queue_draw() |
---|
181 | |
---|
182 | #def new_package_button |
---|
183 | |
---|
184 | def accept_add_profile_clicked(self,widget): |
---|
185 | |
---|
186 | profile=self.profile_entry.get_text() |
---|
187 | profile=profile.strip(" ") |
---|
188 | email=self.email_entry.get_text() |
---|
189 | email=email.strip(" ") |
---|
190 | |
---|
191 | self.new_profile_button(profile,email) |
---|
192 | |
---|
193 | self.new_profile_window.hide() |
---|
194 | |
---|
195 | |
---|
196 | def delete_profile_clicked(self,button,hbox): |
---|
197 | print "BORRANDO" |
---|
198 | |
---|
199 | def mount_profile_clicked(self,button,hbox): |
---|
200 | print "SINCRONIZANDO" |
---|
201 | mount_image=Gtk.Image.new_from_file(MOUNT_OFF_IMAGE) |
---|
202 | hbox.get_children()[4].set_image(mount_image) |
---|
203 | |
---|
204 | def edit_profile_clicked(self,button,hbox): |
---|
205 | |
---|
206 | profile=hbox.get_children()[1].get_text().split("\n")[0] |
---|
207 | self.profile_entry.set_text(profile) |
---|
208 | self.profile_entry.set_editable(False) |
---|
209 | email=hbox.get_children()[1].get_text().split("\n")[1] |
---|
210 | self.email_entry.set_text(email) |
---|
211 | self.email_entry.set_editable(False) |
---|
212 | self.new_profile_window.show() |
---|
213 | |
---|
214 | |
---|
215 | def quit(self,widget): |
---|
216 | |
---|
217 | Gtk.main_quit() |
---|
218 | |
---|
219 | #class profilebox |
---|