123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776 |
- import os
- os.system("chmod u+x flbry/lbrynet")
- import gi
- import threading
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- from gi.repository import Gdk
- from gi.repository import GLib
- from flbry import connect
- from flbry import parse
- from flbry import settings
- from flbry import url
- from flbry import ui
- from flbry import claim_search
- from flbry import fetch
- from flbry import publish
- from flbry import downloads
- from flbry import analytics
- settings.make_sure_file_exists()
- win = Gtk.Window()
- win.connect("destroy", Gtk.main_quit)
- win.set_title("FastLBRY GTK")
- win.set_default_icon_from_file("icon.png")
- win.set_size_request(800, 900)
- win.settings = settings.load()
- win.SDK_running = connect.check()
- win.resolved = {}
- win.commenting = {}
- win.subs = []
- win.tabs = []
- win.resolve_tab = 0
- win.notebook = Gtk.Notebook()
- win.download_buttons = {}
- win.downloads = {}
- pannel = Gtk.HeaderBar()
- pannel.set_show_close_button(True)
- win.set_titlebar(pannel)
- restofpannel = Gtk.HBox()
- pannel.pack_end(restofpannel)
- icon_connect = ui.icon(win, "network-wired")
- icon_disconnect = ui.icon(win, "network-wired-disconnected")
- connect_box = Gtk.HBox()
- disconnect_box = Gtk.HBox()
- connect_box.pack_start(icon_connect, False, False, False)
- connect_box.set_tooltip_text("Connect to LBRY Network")
- connect_box.pack_start(Gtk.Label("Connect "), False, False, False)
- disconnect_box.pack_start(icon_disconnect, False, False, False)
- disconnect_box.set_tooltip_text("Disconnect from LBRY Network")
- disconnect_box.pack_start(Gtk.Label("Disconnect "), False, False, False)
- if win.SDK_running:
- title = disconnect_box
- restofpannel.set_sensitive(True)
- else:
- title = connect_box
- restofpannel.set_sensitive(False)
- connect_disconncet_button = Gtk.Button()
- connect_disconncet_button.add(title)
- connect_disconncet_button.set_relief(Gtk.ReliefStyle.NONE)
- pannel.pack_start(connect_disconncet_button)
- def connect_disconnect_function(w):
-
- w.set_sensitive(False)
- dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
- for i in dynamic_box.get_children():
- i.destroy()
- progress_connect = Gtk.ProgressBar(show_text=True)
- dynamic_box.pack_start(progress_connect, True, True, 30)
- win.show_all()
- def do_sdk(w, pb):
- wasrunning = win.SDK_running
- if win.SDK_running == 1:
- connect.stop()
- else:
- connect.start()
- def update_pb(pb):
- pb.set_fraction(win.SDK_running)
- pb.set_text("Connecting: "+str(int(round(win.SDK_running*100)))+"%")
-
- def update_buttons(w):
- for i in dynamic_box.get_children():
- i.destroy()
- w.get_child().destroy()
- if win.SDK_running == 1:
- w.add(disconnect_box)
- restofpannel.set_sensitive(True)
- else:
- w.add(connect_box)
- restofpannel.set_sensitive(False)
- w.show_all()
- w.set_sensitive(True)
- if win.SDK_running == 1:
- load_following()
- load_channel(win)
- check_lock_button()
- ui.notify(win, "Connected to LBRY")
- if wasrunning == 0:
- while True:
- win.SDK_running = connect.check()
- if win.SDK_running == 1:
- break
- GLib.idle_add(update_pb, pb)
-
- GLib.idle_add(update_buttons, w)
-
- load_thread = threading.Thread(target=do_sdk, args=(w, progress_connect))
- load_thread.setDaemon(True)
- load_thread.start()
-
- connect_disconncet_button.connect("clicked", connect_disconnect_function)
- win.lock_button = Gtk.ToggleButton()
- def check_lock_button():
- try:
- wallet_status = fetch.lbrynet("wallet_status")
- except:
- wallet_status = {}
- if wallet_status.get("is_locked"):
- win.lock_button.set_active(True)
- if not win.settings["lock_password"]:
- win.lock_button.set_sensitive(False)
- else:
- win.lock_button.set_sensitive(True)
- check_lock_button()
- win.lock_button.set_tooltip_text("Lock / Unlock LBRY wallet. \n\n While the wallet is locked, no transaction could be signed. So nobody could use the running SDK to harm you.\n\nTo set the password look into settings.")
- win.lock_button.set_relief(Gtk.ReliefStyle.NONE)
- win.lock_button.add(ui.icon(win, "system-lock-screen-symbolic"))
- restofpannel.pack_start(win.lock_button, False, False, False)
- def lock_unlock(w):
- passw = win.settings["lock_password"]
- wallets = fetch.lbrynet("wallet_list")
- ID = wallets["items"][0]["id"]
-
- if w.get_active():
-
- print(fetch.lbrynet("wallet_encrypt", {"new_password":passw}))
- print(fetch.lbrynet("wallet_lock", {"wallet_id":ID}))
- else:
-
- print(fetch.lbrynet("wallet_unlock", {"password":passw, "wallet_id":ID}))
- print(fetch.lbrynet("wallet_decrypt", {"wallet_id":ID}))
-
- print("I AM FUCKING PRESSED")
-
- win.lock_button.connect("clicked", lock_unlock)
- restofpannel.pack_start(Gtk.VSeparator(), True, True, 20)
- publ = Gtk.Button()
- publ.set_tooltip_text("Publish to LBRY")
- publ.set_relief(Gtk.ReliefStyle.NONE)
- publ.add(ui.icon(win, "list-add"))
- restofpannel.pack_start(publ, False, False, False)
- def do_publish(w):
- publish.window(win)
- publ.connect("clicked", do_publish)
- restofpannel.pack_start(Gtk.VSeparator(), True, True, 20)
- win.url = Gtk.Entry()
- win.url.set_size_request(400,40)
- restofpannel.pack_start(win.url, True, True, False)
- def search(w):
- if win.resolve_tab == "current":
- win.resolve_tab = win.notebook.get_current_page()
-
- try:
- dynamic_box = win.tabs[win.resolve_tab]["box"]
- except:
- new_tab()
- dynamic_box = win.tabs[win.resolve_tab]["box"]
-
-
-
-
- if win.url.get_text().startswith("file://") or os.path.exists(win.url.get_text()):
-
-
-
- filepath = win.url.get_text().replace("file://", "")
- publish.window(win, {"file_path":filepath})
- win.url.set_text("")
- return
- for i in dynamic_box.get_children():
- i.destroy()
-
-
- if not force_search.get_active() or win.url.get_text().startswith("lbry://"):
- win.url.set_text(parse.bar(win.url.get_text()))
- ltext = win.url.get_text()
- ltext = ltext[ltext.rfind("/")+1:]
- win.tabs[win.resolve_tab]["label"].set_text(ltext[:10]+"...")
- win.tabs[win.resolve_tab]["label"].set_tooltip_text(win.url.get_text())
-
- resolve = ui.load(win, url.resolve, url.render_resolve, w, win, win.url.get_text())
- dynamic_box.pack_start(resolve, True, True, True)
- win.show_all()
- else:
- resolve = ui.load(win, claim_search.find, claim_search.render, win, win.url.get_text(), [], 1, {"order_by":""})
- dynamic_box.pack_start(resolve, True, True, True)
- win.show_all()
- ltext = win.url.get_text()
- win.tabs[win.resolve_tab]["label"].set_text(ltext[:10]+"...")
- win.tabs[win.resolve_tab]["label"].set_tooltip_text(win.url.get_text())
-
- dynamic_box.show_all()
- win.notebook.set_current_page(win.resolve_tab)
- win.resolve_tab = "current"
- search_button = Gtk.Button()
- search_icon = ui.icon(win, "system-search")
- search_button.add(search_icon)
- search_button.set_relief(Gtk.ReliefStyle.NONE)
- search_button.connect("clicked", search)
- win.url.connect("activate", search)
- restofpannel.pack_start(search_button, False, False, False)
-
- hamburger = Gtk.Popover()
- hambutton = Gtk.MenuButton(popover=hamburger)
- hambutton_icon = ui.icon(win, "system-users")
- hambutton.add(hambutton_icon)
- hambutton.set_relief(Gtk.ReliefStyle.NONE)
- pannel.pack_start(hambutton)
- hambox = Gtk.HBox()
- hamscrl = Gtk.ScrolledWindow()
- hamscrl.set_size_request(200,200)
- hamburger.add(hambox)
- hambox.pack_start(hamscrl, False, False, False)
- hamchannelbox = Gtk.VBox()
- hamscrl.add_with_viewport(hamchannelbox)
- win.channel = False
- def load_channel(win):
- def change_channel(w, win, channel ):
- win.channel = channel
- win.settings["channel"] = win.channel["claim_id"]
- settings.save(win.settings)
- try:
- hambutton.get_child().destroy()
- try:
- newicon = ui.load(win, ui.net_image_calculation, ui.net_image_render, channel["value"]["thumbnail"]["url"], 40, "", False )
- except:
- newicon = ui.icon(win, "system-users")
- hambutton.add(newicon)
- pannel.show_all()
- except Exception as e:
- print("What?", e)
-
- out = fetch.lbrynet("channel_list")
- win.my_channels = out
-
-
-
- try:
- first = out["items"][0]
- win.channel = first
- except:
- pass
- if "channel" in win.settings:
- try:
- for i in out["items"]:
- if i["claim_id"] == win.settings["channel"]:
- first = i
- break
- except:
- pass
-
- try:
- change_channel(False, win, first)
- except:
- pass
- try:
-
-
- go.set_sensitive(True)
-
- for i in out["items"]:
- channel_button = ui.go_to_channel(win, i, resolve=False)
- channel_button.connect("clicked", change_channel, win, i)
- hamchannelbox.pack_start(channel_button, False, False, False)
- hamchannelbox.show_all()
- second_raw.show_all()
- except Exception as e:
- print("CHANNEL ERROR:", e)
- second_raw = Gtk.VBox()
- hambox.pack_start(Gtk.VSeparator(), False, False, 5)
- hambox.pack_start(second_raw, False, False, False)
-
- def go_to_channel(w):
- channel_url = win.channel["name"]
- try:
- channel_url = channel_url + "#" + win.channel["claim_id"]
- except:
- pass
-
- win.url.set_text(channel_url)
- win.url.activate()
-
- go = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "folder-remote"), False, False, False)
- b.pack_start(Gtk.Label(" Go To Channel "), True, True, False)
- go.add(b)
- go.set_sensitive(False)
- go.set_relief(Gtk.ReliefStyle.NONE)
- go.connect("clicked", go_to_channel)
- second_raw.pack_start(go, False, False, False)
- def load_uploads(w=False):
- dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
-
- for i in dynamic_box.get_children():
- i.destroy()
-
- send = {"method":"claim_list"}
- resolve = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
- dynamic_box.pack_start(resolve, True, True, True)
- dynamic_box.show_all()
-
- win.tabs[win.notebook.get_current_page()]["label"].set_text("Uploads")
- win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text("Uploads")
- following = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "go-up-symbolic"), False, False, False)
- b.pack_start(Gtk.Label(" Uploads "), True, True, False)
- following.add(b)
- following.set_relief(Gtk.ReliefStyle.NONE)
- following.connect("clicked", load_uploads)
- second_raw.pack_start(following, False, False,False)
- def load_analytics(w):
- analytics.window(win)
- following = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "text-csv"), False, False, False)
- b.pack_start(Gtk.Label(" Wallet "), True, True, False)
- following.add(b)
- following.set_relief(Gtk.ReliefStyle.NONE)
- following.connect("clicked", load_analytics)
- second_raw.pack_start(following, False, False,False)
- second_raw.pack_start(Gtk.HSeparator(), False, False,5)
- def load_following( w=False):
- dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
-
- for i in dynamic_box.get_children():
- i.destroy()
-
- try:
- if not win.subs:
- out = fetch.lbrynet("preference_get")
- win.subs = out["shared"]["value"]["subscriptions"]
- subs_raw = fetch.lbrynet("resolve", {"urls":win.subs})
- subs = []
- for i in subs_raw:
- try:
- subs.append(subs_raw[i]["claim_id"])
- except:
- pass
- except Exception as e:
- print("\n\nERROR:", e, "\n\n")
- subs = []
-
-
- resolve = ui.load(win, claim_search.find, claim_search.render, win, "", subs)
- dynamic_box.pack_start(resolve, True, True, True)
- dynamic_box.show_all()
- win.tabs[win.notebook.get_current_page()]["label"].set_text("Following")
- win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text("Following")
-
- following = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "emblem-favorite"), False, False, False)
- b.pack_start(Gtk.Label(" Following "), True, True, False)
- following.add(b)
- following.set_relief(Gtk.ReliefStyle.NONE)
- following.connect("clicked", load_following)
- second_raw.pack_start(following, False, False,False)
- def load_trending(w=False, articles=False):
- dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
-
- for i in dynamic_box.get_children():
- i.destroy()
-
- send = {"order_by":"trending_mixed"}
- if articles:
- send["media_types"] = ["text/markdown"]
- resolve = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
- dynamic_box.pack_start(resolve, True, True, True)
- dynamic_box.show_all()
- if articles:
- lname = "Articles"
- else:
- lname = "Trending"
-
- win.tabs[win.notebook.get_current_page()]["label"].set_text(lname)
- win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text(lname)
-
-
-
- following = Gtk.Button()
- b = Gtk.HBox()
-
- b.pack_start(ui.icon(win, "emblem-shared"), False, False, False)
- b.pack_start(Gtk.Label(" Trending "), True, True, False)
- following.add(b)
- following.set_relief(Gtk.ReliefStyle.NONE)
- following.connect("clicked", load_trending)
- second_raw.pack_start(following, False, False,False)
- following = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "text-x-generic"), False, False, False)
- b.pack_start(Gtk.Label(" Articles "), True, True, False)
- following.add(b)
- following.set_relief(Gtk.ReliefStyle.NONE)
- following.connect("clicked", load_trending, True)
- second_raw.pack_start(following, False, False,False)
- second_raw.pack_start(Gtk.HSeparator(), False, False,5)
- def load_downloads(w):
- downloads.window(win)
- following = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "go-down-symbolic"), False, False, False)
- b.pack_start(Gtk.Label(" Downloads "), True, True, False)
- following.add(b)
- following.set_relief(Gtk.ReliefStyle.NONE)
- following.connect("clicked", load_downloads)
- second_raw.pack_start(following, False, False,False)
- second_raw.pack_start(Gtk.HSeparator(), False, False,5)
- second_raw.pack_start(Gtk.HSeparator(), False, False,5)
- settings_button = Gtk.Button()
- b = Gtk.HBox()
- b.pack_start(ui.icon(win, "preferences-system"), False, False, False)
- b.pack_start(Gtk.Label(" Settings "), True, True, False)
- settings_button.add(b)
- settings_button.set_relief(Gtk.ReliefStyle.NONE)
- settings_button.connect("clicked", settings.dialogue, win)
- second_raw.pack_start(settings_button, False, False, False)
- second_raw.pack_start(Gtk.HSeparator(), False, False,5)
- force_search_box = Gtk.HBox()
- force_search = Gtk.Switch()
- force_search_box.pack_end(force_search, False, False, 0)
- force_search_box.pack_start(ui.icon(win, "system-search"), False, False, 0)
- force_search_box.pack_start(Gtk.Label(" Force Search "), True, True, 0)
- force_search.set_tooltip_text("If not activated it will try to resolve the claim first.")
- second_raw.pack_start(force_search_box, False, False, False)
- hambox.show_all()
- box = Gtk.VBox()
- win.add(box)
- win.notebook.set_scrollable(True)
- def new_tab():
- dynamic_box = Gtk.VBox()
- label = Gtk.Label("Tab "+str(len(win.tabs)+1))
-
- kill = Gtk.Button()
-
- kill.add(ui.icon(win, "delete"))
- kill.set_relief(Gtk.ReliefStyle.NONE)
- box = Gtk.HBox()
- box.pack_start(label, False, False, 5)
- box.pack_start(kill, False, False, 0)
- box.show_all()
-
- tab = {"box":dynamic_box, "label":label, "index":len(win.tabs)}
- def on_kill(w, tab):
- if len(win.tabs) == 1:
- load_following()
- return
-
- i = tab["index"]
- win.notebook.remove_page(i)
- del win.tabs[i]
- for r, t in enumerate(win.tabs):
- t["index"] = r
-
-
- kill.connect("clicked", on_kill, tab)
-
- win.tabs.append(tab)
- win.resolve_tab = len(win.tabs) - 1
- win.notebook.append_page(win.tabs[-1]["box"], box)
-
-
-
- new_tab()
-
- box.pack_start(win.notebook, True, True, False)
- if win.SDK_running == 1:
- load_following()
- load_channel(win)
- else:
- win.tabs[0]["box"].pack_start(Gtk.Label("LBRY is not connected. Please connect."), True, True, 20)
- def on_drop(widget, drag_context, x, y, data, info, time):
- win.url.set_text(data.get_text())
- win.url.activate()
-
- enforce_target = Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags(4), 129)
- box.drag_dest_set(Gtk.DestDefaults.ALL, [enforce_target], Gdk.DragAction.COPY)
- box.connect("drag-data-received", on_drop)
-
-
- win.show_all()
- Gtk.main()
- ui.clean_image_cache()
|