Removed some platform checks

This commit is contained in:
Manuel Cortez 2022-11-03 17:11:13 -06:00
parent b8637ba8ca
commit 1ded773e84
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
24 changed files with 67 additions and 246 deletions

View File

@ -1,13 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import platform import wx
if platform.system() == "Windows": from wxUI import buffers, dialogs, commonMessageDialogs, menus
import wx from controller import user
from wxUI import buffers, dialogs, commonMessageDialogs, menus
from controller import user
elif platform.system() == "Linux":
from gi.repository import Gtk
from gtkUI import buffers, dialogs, commonMessageDialogs
from controller import messages from controller import messages
import widgetUtils import widgetUtils
import arrow import arrow
@ -309,9 +304,6 @@ class BaseBuffer(base.Buffer):
self.buffer.list.insert_item(True, *tweet) self.buffer.list.insert_item(True, *tweet)
if self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: if self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False:
output.speak(" ".join(tweet[:2]), speech=self.session.settings["reporting"]["speech_reporting"], braille=self.session.settings["reporting"]["braille_reporting"]) output.speak(" ".join(tweet[:2]), speech=self.session.settings["reporting"]["speech_reporting"], braille=self.session.settings["reporting"]["braille_reporting"])
#Improve performance on Windows
# if platform.system() == "Windows":
# call_threaded(utils.is_audio,item)
def bind_events(self): def bind_events(self):
log.debug("Binding events...") log.debug("Binding events...")
@ -322,7 +314,6 @@ class BaseBuffer(base.Buffer):
widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.share_item, self.buffer.retweet) widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.share_item, self.buffer.retweet)
widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.send_message, self.buffer.dm) widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.send_message, self.buffer.dm)
widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.reply, self.buffer.reply) widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.reply, self.buffer.reply)
# Replace for the correct way in other platforms.
widgetUtils.connect_event(self.buffer.list.list, wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu) widgetUtils.connect_event(self.buffer.list.list, wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu)
widgetUtils.connect_event(self.buffer.list.list, wx.EVT_LIST_KEY_DOWN, self.show_menu_by_key) widgetUtils.connect_event(self.buffer.list.list, wx.EVT_LIST_KEY_DOWN, self.show_menu_by_key)
@ -480,7 +471,6 @@ class BaseBuffer(base.Buffer):
def onFocus(self, *args, **kwargs): def onFocus(self, *args, **kwargs):
tweet = self.get_tweet() tweet = self.get_tweet()
if platform.system() == "Windows" and self.session.settings["general"]["relative_times"] == True:
# fix this: # fix this:
original_date = arrow.get(self.session.db[self.name][self.buffer.list.get_selected()].created_at, locale="en") original_date = arrow.get(self.session.db[self.name][self.buffer.list.get_selected()].created_at, locale="en")
ts = original_date.humanize(locale=languageHandler.getLanguage()) ts = original_date.humanize(locale=languageHandler.getLanguage())

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import platform
import widgetUtils import widgetUtils
import arrow import arrow
import webbrowser import webbrowser
@ -99,7 +98,7 @@ class DirectMessagesBuffer(base.BaseBuffer):
def onFocus(self, *args, **kwargs): def onFocus(self, *args, **kwargs):
tweet = self.get_tweet() tweet = self.get_tweet()
if platform.system() == "Windows" and self.session.settings["general"]["relative_times"] == True: if self.session.settings["general"]["relative_times"] == True:
# fix this: # fix this:
original_date = arrow.get(int(tweet.created_timestamp)) original_date = arrow.get(int(tweet.created_timestamp))
ts = original_date.humanize(locale=languageHandler.getLanguage()) ts = original_date.humanize(locale=languageHandler.getLanguage())

View File

@ -1,10 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import platform from wxUI import dialogs, commonMessageDialogs
if platform.system() == "Windows":
from wxUI import dialogs, commonMessageDialogs
elif platform.system() == "Linux":
from gi.repository import Gtk
from gtkUI import dialogs, commonMessageDialogs
import widgetUtils import widgetUtils
import logging import logging
from tweepy.cursor import Cursor from tweepy.cursor import Cursor

View File

@ -1,12 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import platform from wxUI import commonMessageDialogs, menus
if platform.system() == "Windows": from controller import user
from wxUI import commonMessageDialogs, menus
from controller import user
elif platform.system() == "Linux":
from gi.repository import Gtk
from gtkUI import dialogs, commonMessageDialogs
from controller import messages from controller import messages
import widgetUtils import widgetUtils
import webbrowser import webbrowser

View File

@ -1,12 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import platform
import locale import locale
if platform.system() == "Windows": from wxUI import commonMessageDialogs
from wxUI import commonMessageDialogs
elif platform.system() == "Linux":
from gi.repository import Gtk
from gtkUI import commonMessageDialogs
import widgetUtils import widgetUtils
import logging import logging
from tweepy.errors import TweepyException from tweepy.errors import TweepyException

View File

@ -1,13 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import platform import wx
if platform.system() == "Windows": from wxUI import buffers, commonMessageDialogs, menus
import wx from controller import user, messages
from wxUI import buffers, commonMessageDialogs, menus
from controller import user, messages
elif platform.system() == "Linux":
from gi.repository import Gtk
from gtkUI import buffers, commonMessageDialogs
from controller import messages from controller import messages
import widgetUtils import widgetUtils
import output import output

View File

@ -1,26 +1,21 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import platform
system = platform.system()
import application import application
import wx import wx
import requests import requests
from audio_services import youtube_utils
import arrow import arrow
if system == "Windows": from audio_services import youtube_utils
from update import updater from update import updater
from wxUI import (view, dialogs, commonMessageDialogs, sysTrayIcon) from wxUI import (view, dialogs, commonMessageDialogs, sysTrayIcon)
from . import settings from . import settings
from extra import SoundsTutorial, ocr from extra import SoundsTutorial, ocr
import keystrokeEditor import keystrokeEditor
from keyboard_handler.wx_handler import WXKeyboardHandler from keyboard_handler.wx_handler import WXKeyboardHandler
from . import userActionsController from . import userActionsController
from . import trendingTopics from . import trendingTopics
from . import user from . import user
from . import listsController from . import listsController
from . import filterController from . import filterController
from . import userSelector from . import userSelector
elif system == "Linux":
from gtkUI import (view, commonMessageDialogs)
from sessions.twitter import utils, compose from sessions.twitter import utils, compose
from sessionmanager import manager, sessionManager from sessionmanager import manager, sessionManager
from controller import buffers from controller import buffers
@ -136,7 +131,6 @@ class Controller(object):
pub.subscribe(self.create_buffer, "createBuffer") pub.subscribe(self.create_buffer, "createBuffer")
pub.subscribe(self.toggle_share_settings, "toggleShare") pub.subscribe(self.toggle_share_settings, "toggleShare")
pub.subscribe(self.restart_streaming, "restartStreaming") pub.subscribe(self.restart_streaming, "restartStreaming")
if system == "Windows":
pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed") pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed")
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search)
@ -231,12 +225,10 @@ class Controller(object):
self.current_account = "" self.current_account = ""
self.view.prepare() self.view.prepare()
self.bind_other_events() self.bind_other_events()
if system == "Windows":
self.set_systray_icon() self.set_systray_icon()
def check_invisible_at_startup(self): def check_invisible_at_startup(self):
# Visibility check. It does only work for windows. # Visibility check.
if system != "Windows": return
if config.app["app-settings"]["hide_gui"] == True: if config.app["app-settings"]["hide_gui"] == True:
self.show_hide() self.show_hide()
self.view.Show() self.view.Show()
@ -641,7 +633,6 @@ class Controller(object):
sessions.sessions[item].sound.cleaner.cancel() sessions.sessions[item].sound.cleaner.cancel()
log.debug("Saving database for " + sessions.sessions[item].session_id) log.debug("Saving database for " + sessions.sessions[item].session_id)
sessions.sessions[item].save_persistent_data() sessions.sessions[item].save_persistent_data()
if system == "Windows":
self.systrayIcon.RemoveIcon() self.systrayIcon.RemoveIcon()
pidpath = os.path.join(os.getenv("temp"), "{}.pid".format(application.name)) pidpath = os.path.join(os.getenv("temp"), "{}.pid".format(application.name))
if os.path.exists(pidpath): if os.path.exists(pidpath):

View File

@ -1,3 +1 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from .soundsTutorial import soundsTutorial from .soundsTutorial import soundsTutorial

View File

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from gi.repository import Gtk
import widgetUtils
class soundsTutorialDialog(Gtk.Dialog):
def __init__(self, actions):
super(soundsTutorialDialog, self).__init__("Sounds tutorial", None, 0, (Gtk.STOCK_CANCEL, widgetUtils.CANCEL))
box = self.get_content_area()
label = Gtk.Label("Press enter for listen the sound")
self.list = widgetUtils.list("Action")
self.populate_actions(actions)
lBox = Gtk.Box(spacing=6)
lBox.add(label)
lBox.add(self.list.list)
box.add(lBox)
self.play = Gtk.Button("Play")
box.add(self.play)
self.show_all()
def populate_actions(self, actions):
for i in actions:
self.list.insert_item(i)
def get_selected(self):
return self.list.get_selected()

View File

@ -1,4 +1,3 @@
from __future__ import unicode_literals
#Reverse sort, by Bill Dengler <codeofdusk@gmail.com> for use in TWBlue http://twblue.es #Reverse sort, by Bill Dengler <codeofdusk@gmail.com> for use in TWBlue http://twblue.es
def invert_tuples(t): def invert_tuples(t):
"Invert a list of tuples, so that the 0th element becomes the -1th, and the -1th becomes the 0th." "Invert a list of tuples, so that the 0th element becomes the -1th, and the -1th becomes the 0th."

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from builtins import object
import platform import platform
import widgetUtils import widgetUtils
import os import os
@ -9,10 +6,7 @@ import paths
import logging import logging
log = logging.getLogger("extra.SoundsTutorial.soundsTutorial") log = logging.getLogger("extra.SoundsTutorial.soundsTutorial")
from . import soundsTutorial_constants from . import soundsTutorial_constants
if platform.system() == "Windows": from . import wx_ui as UI
from . import wx_ui as UI
elif platform.system() == "Linux":
from . import gtk_ui as UI
class soundsTutorial(object): class soundsTutorial(object):
def __init__(self, sessionObject): def __init__(self, sessionObject):

View File

@ -1,7 +1,4 @@
#-*- coding: utf-8 -*- #-*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
#-*- coding: utf-8 -*-
from . import reverse_sort from . import reverse_sort
import application import application
actions = reverse_sort.reverse_sort([ ("audio", _(u"Audio tweet.")), actions = reverse_sort.reverse_sort([ ("audio", _(u"Audio tweet.")),

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
import wx import wx
import widgetUtils import widgetUtils

View File

@ -1,8 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from builtins import next
from builtins import object
import os import os
import logging import logging
from . import wx_ui from . import wx_ui

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re import re
from enchant.tokenize import Filter from enchant.tokenize import Filter

View File

@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################ ############################################################
from __future__ import unicode_literals
import wx import wx
import application import application

View File

@ -2,7 +2,4 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import unicode_literals from __future__ import unicode_literals
from . import translator from . import translator
import platform from . import wx_ui as gui
if platform.system() == "Windows":
from . import wx_ui as gui

View File

@ -7,4 +7,3 @@ Contents of this package:
manager: Handles multiple sessions, setting the configuration files and check if the session is valid. Part of the model. manager: Handles multiple sessions, setting the configuration files and check if the session is valid. Part of the model.
session: Creates a twitter session for an user. The other part of the model. session: Creates a twitter session for an user. The other part of the model.
""" """
from __future__ import unicode_literals

View File

@ -1,57 +0,0 @@
from __future__ import unicode_literals
from gi.repository import Gtk
import widgetUtils
class sessionManagerWindow(widgetUtils.baseDialog):
def __init__(self):
super(sessionManagerWindow, self).__init__("Session Manager", None, 0, (Gtk.STOCK_OK, widgetUtils.OK, Gtk.STOCK_CANCEL, widgetUtils.CANCEL))
self.list = widgetUtils.list("Session")
self.box.add(self.list.list)
btnBox = Gtk.Box(spacing=6)
self.new = Gtk.Button("New account")
self.remove = Gtk.Button("Remove account")
self.configuration = Gtk.Button("Configuration")
btnBox.add(self.new)
btnBox.add(self.remove)
btnBox.add(self.configuration)
self.box.add(btnBox)
self.show_all()
def fill_list(self, sessionsList):
for i in sessionsList:
self.list.insert_item(False, i)
if self.list.get_count() > 0:
self.list.select_item(0)
def new_account_dialog(self):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Authorization")
dialog.format_secondary_text("The request to authorize your Twitter account will be opened in your browser. You only need to do this once. Would you like to continue?")
answer = dialog.run()
dialog.destroy()
return answer
def add_new_session_to_list(self):
total = self.list.get_count()
name = "Authorized account %d" % (total+1)
self.list.insert_item(name)
if self.list.get_count() == 1:
self.list.select_item(0)
def show_unauthorised_error(self):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, "Invalid user token")
dialog.format_secondary_text("Your access token is invalid or the authorization has failed. Please try again.")
answer = dialog.run()
return answer
def remove_account_dialog(self):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Remove account")
dialog.format_secondary_text("Do you really want delete this account?")
answer = dialog.run()
return answer
def get_selected(self):
return self.list.get_selected()
def remove_session(self, sessionID):
self.list.remove_item(sessionID)

View File

@ -1,13 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import shutil import shutil
import widgetUtils import widgetUtils
import platform
import output import output
if platform.system() == "Windows": from . import wxUI as view
from . import wxUI as view from controller import settings
from controller import settings
elif platform.system() == "Linux":
from . import gtkUI as view
import paths import paths
import time import time
import os import os

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import platform
system = platform.system()
from . import utils from . import utils
import re import re
import time import time
@ -17,14 +15,11 @@ chars = "abcdefghijklmnopqrstuvwxyz"
def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=None): def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=None):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
if system == "Windows":
original_date = arrow.get(tweet.created_at, locale="en") original_date = arrow.get(tweet.created_at, locale="en")
if relative_times == True: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else:
ts = tweet.created_at
if hasattr(tweet, "message"): if hasattr(tweet, "message"):
value = "message" value = "message"
elif hasattr(tweet, "full_text"): elif hasattr(tweet, "full_text"):
@ -58,7 +53,6 @@ def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=No
return [user+", ", text, ts+", ", source] return [user+", ", text, ts+", ", source]
def compose_direct_message(item, db, relative_times, show_screen_names=False, session=None): def compose_direct_message(item, db, relative_times, show_screen_names=False, session=None):
if system == "Windows":
# Let's remove the last 3 digits in the timestamp string. # Let's remove the last 3 digits in the timestamp string.
# Twitter sends their "epoch" timestamp with 3 digits for milliseconds and arrow doesn't like it. # Twitter sends their "epoch" timestamp with 3 digits for milliseconds and arrow doesn't like it.
original_date = arrow.get(int(item.created_timestamp)) original_date = arrow.get(int(item.created_timestamp))
@ -66,8 +60,6 @@ def compose_direct_message(item, db, relative_times, show_screen_names=False, se
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else:
ts = item.created_timestamp
text = StripChars(item.message_create["message_data"]["text"]) text = StripChars(item.message_create["message_data"]["text"])
source = "DM" source = "DM"
sender = session.get_user(item.message_create["sender_id"]) sender = session.get_user(item.message_create["sender_id"])
@ -125,16 +117,12 @@ def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False,
return quoted_tweet return quoted_tweet
def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None): def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None):
if system == "Windows":
original_date = arrow.get(tweet.created_at, locale="en") original_date = arrow.get(tweet.created_at, locale="en")
if relative_times == True: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else:
ts = tweet.created_at
if hasattr(tweet, "status"): if hasattr(tweet, "status"):
if system == "Windows":
original_date2 = arrow.get(tweet.status.created_at, locale="en") original_date2 = arrow.get(tweet.status.created_at, locale="en")
if relative_times: if relative_times:
ts2 = original_date2.humanize(locale=languageHandler.curLang[:2]) ts2 = original_date2.humanize(locale=languageHandler.curLang[:2])
@ -142,8 +130,6 @@ def compose_followers_list(tweet, db, relative_times=True, show_screen_names=Fal
ts2 = original_date2.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts2 = original_date2.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts2 = _("Unavailable") ts2 = _("Unavailable")
else:
ts2 = _("Unavailable")
return [_(u"%s (@%s). %s followers, %s friends, %s tweets. Last tweeted %s. Joined Twitter %s") % (tweet.name, tweet.screen_name, tweet.followers_count, tweet.friends_count, tweet.statuses_count, ts2, ts)] return [_(u"%s (@%s). %s followers, %s friends, %s tweets. Last tweeted %s. Joined Twitter %s") % (tweet.name, tweet.screen_name, tweet.followers_count, tweet.friends_count, tweet.statuses_count, ts2, ts)]
def compose_list(list): def compose_list(list):

View File

@ -1,3 +1,2 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" this package holds different modules to extract information regarding long tweets. A long tweet contains more than one tweet (such a quoted tweet), or is made via services like twishort.""" """ this package holds different modules to extract information regarding long tweets. A long tweet contains more than one tweet (such a quoted tweet), or is made via services like twishort."""
from __future__ import unicode_literals

View File

@ -1,13 +0,0 @@
from __future__ import unicode_literals
import glob
import os.path
import platform
def find_datafiles():
system = platform.system()
if system == 'Windows':
file_ext = '*.exe'
else:
file_ext = '*.sh'
path = os.path.abspath(os.path.join(__path__[0], 'bootstrappers', file_ext))
return [('', glob.glob(path))]

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import application import application
from . import update from . import update
import platform
import logging import logging
import output import output
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError