Commit 67f19b3d authored by Danial Behzadi's avatar Danial Behzadi
Browse files

sidebar completed

parent 4175c2ba
......@@ -14,15 +14,17 @@ from subprocess import PIPE, Popen
from sys import exit
from threading import Thread
command = "tractor "
#command = "tractor "
command = "/home/danialbehzadi/Documents/Sources/tractor/tractor "
dconf = Gio.Settings.new("org.tractor")
try:
localedir = [skel_path for skel_path in GLib.get_system_data_dirs() if os.path.exists(skel_path) and "carburetor" in os.listdir(skel_path)][-1]+"/carburetor/locales"
translate = gettext.translation('messages', localedir=localedir, fallback=True)
_ = translate.gettext
except IndexError:
print("There is a problem with your packaging. Report it to package maintainer.")
s_data_dir = [skel_path for skel_path in GLib.get_system_data_dirs() if os.path.exists(skel_path) and "carburetor" in os.listdir(skel_path)][-1]+"/carburetor"
except IndexError as e:
print("There is a problem with your packaging. Report it to the package maintainer: ", e)
exit(1)
locale_dir = s_data_dir+"/locales"
translate = gettext.translation('messages', localedir=locale_dir, fallback=True)
_ = translate.gettext
app_name = _("Carburetor")
notify2.init(app_name)
......@@ -310,7 +312,6 @@ class BridgeConfig(Gtk.Box):
self.pack_start(vbox, False, True, 0)
class BridgeList(Gtk.Box):
config_dir = GLib.get_user_config_dir() + "/tractor"
def __init__(self):
Gtk.Box.__init__(self)
self.set_homogeneous(False)
......@@ -323,17 +324,13 @@ class BridgeList(Gtk.Box):
self.pack_start(vbox, False, False, 0)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_min_content_height(150)
self.get_style_context().add_class("bridgeslist")
text_view = Gtk.TextView()
text_view.set_wrap_mode(1)
text_buffer = text_view.get_buffer()
bridges_file = self.config_dir + "/Bridges"
if not os.path.isfile(bridges_file):
try:
bridges_file = [skel_path for skel_path in GLib.get_system_data_dirs() if os.path.exists(skel_path) and "tractor" in os.listdir(skel_path)][-1]+"/tractor/SampleBridges"
except IndexError:
print("There is a problem with your packaging. Report it to package maintainer.")
exit(1)
get_bridges = Popen(command + "bridgesfile", stdout=PIPE, shell=True)
bridges = get_bridges.stdout.read()
bridges_file = bridges.decode("utf-8").strip('\n')
with open(bridges_file) as file:
text = file.read()
text_buffer.set_text(str(text))
......@@ -344,17 +341,14 @@ class BridgeList(Gtk.Box):
vbox.set_homogeneous(False)
button = Gtk.Button()
button.set_label(_("Save"))
button.connect("clicked", self.on_save_clicked, text_buffer)
button.connect("clicked", self.on_save_clicked, text_buffer, bridges_file)
vbox.pack_start(button, False, False, 0)
self.pack_start(vbox, False, False, 0)
def on_save_clicked(self, button, text_buffer):
bridges_file = self.config_dir + "/Bridges"
def on_save_clicked(self, button, text_buffer, bridges_file):
text = text_buffer.get_text(text_buffer.get_start_iter(), text_buffer.get_end_iter(), 0)
bridge_regex = re.compile(r'^( )*([Bb][Rr][Ii][Dd][Gg][Ee])?( )*', re.MULTILINE)
if text == bridge_regex.sub('Bridge ', text):
if not os.path.exists(self.config_dir):
os.makedirs(self.config_dir)
with open(bridges_file, 'w') as file:
file.write(text)
else:
......@@ -400,33 +394,38 @@ class ObfsPath (Gtk.Box):
class MainContainer(Gtk.Box):
def __init__(self):
Gtk.Box.__init__(self)
self.get_style_context().add_class("maincontainer")
side_bar = Gtk.ListBox()
side_bar.connect("row_selected", self.on_row_selected)
side_bar.set_header_func(self.sidebar_separators)
listbox_row_general = ListBoxRowGeneral()
general = _("General")
ports = _("Ports")
bridges = _("Bridges")
listbox_row_general = ListBoxRow(general)
side_bar.add(listbox_row_general)
listbox_row_ports = ListBoxRowPorts()
listbox_row_ports = ListBoxRow(ports)
side_bar.add(listbox_row_ports)
listbox_row_bridges = ListBoxRowBridges()
listbox_row_bridges = ListBoxRow(bridges)
side_bar.add(listbox_row_bridges)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.add(side_bar)
scrolled_window.props.hscrollbar_policy = Gtk.PolicyType.NEVER
self.pack_start(scrolled_window, True, True, 0)
self.pack_start(scrolled_window, False, False, 0)
separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
self.pack_start(separator, False, False, 0)
self.main_content = Gtk.Stack()
stack_general = StackGeneral()
self.main_content.add_named(stack_general, _("General"))
stack_ports = StackPorts()
self.main_content.add_named(stack_ports, _("Ports"))
self.main_content.add_named(stack_general, general)
stack_ports = StackPorts()
self.main_content.add_named(stack_ports, ports)
stack_bridges = StackBridges()
self.main_content.add_named(stack_bridges, _("Bridges"))
self.main_content.add_named(stack_bridges, bridges)
self.pack_start(self.main_content, True, True, 0)
def on_row_selected(self, box, row):
......@@ -442,27 +441,11 @@ class MainContainer(Gtk.Box):
class ListBoxRow(Gtk.ListBoxRow):
def __init__(self):
def __init__(self, name):
Gtk.ListBoxRow.__init__(self)
self.props.halign = Gtk.Align.START
self.get_style_context().add_class("listboxrow")
class ListBoxRowGeneral(ListBoxRow):
def __init__(self):
ListBoxRow.__init__(self)
label = Gtk.Label(_("General"))
self.add(label)
class ListBoxRowPorts(ListBoxRow):
def __init__(self):
ListBoxRow.__init__(self)
label = Gtk.Label(_("Ports"))
self.add(label)
class ListBoxRowBridges(ListBoxRow):
def __init__(self):
ListBoxRow.__init__(self)
label = Gtk.Label(_("Bridges"))
label = Gtk.Label(name)
label.props.xalign = 0.0
self.add(label)
class StackGeneral(Gtk.ScrolledWindow):
......@@ -505,14 +488,15 @@ class Window(Gtk.ApplicationWindow):
def __init__(self):
Gtk.ApplicationWindow.__init__(self)
self.set_size_request(600, 400)
self.set_icon_name("carburetor")
self.load_css()
def load_css(self):
css_provider = Gtk.CssProvider()
#TODO: fix it for packaging
css_provider.load_from_path('style.css')
try:
css_provider.load_from_path(s_data_dir+'/style.css')
except gi.repository.GLib.Error as e:
print("Can't load css file. This means there is a problem with your packaging. Report it to the package maintainer: ", e)
screen = Gdk.Screen.get_default()
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
......
carburetor (2.5-1) bionic; urgency=medium
* Use sidebar design
* copy bridges file via tractor
-- Danial Behzadi <dani.behzi@ubuntu.com> Wed, 28 Nov 2018 16:45:00 +0330
carburetor (2.4-1) bionic; urgency=medium
* Use threading for Popens
......
carburetor /usr/bin
desktop/carburetor.desktop /usr/share/applications
desktop/carburetor.svg /usr/share/icons/hicolor/scalable/apps
desktop/style.css /usr/share/carburetor
locales /usr/share/carburetor
stack box {
margin: 0.2em;
}
.listboxrow {
padding: 0.7em;
min-width: 10em;
}
.maincontainer {
min-width: 45em;
min-height : 25em;
}
.bridgeslist {
min-height: 15em;
}
stack box {
margin: 0.2em;
}
.listboxrow {
padding: 0.5em;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment