Skip to content

Commit

Permalink
Implement the compile feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RMPR committed Mar 13, 2020
1 parent b9960aa commit af9dde5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Actually it's not really formal, but if you spot any issue, you can always submit a PR :)
# Optimizations
To enable optimizations, you may want to install `upx` which is easily done on Fedora:
```
sudo dnf install -y upx
```
# Known issues

## Wxpython and Linux
Expand Down
46 changes: 45 additions & 1 deletion atbswp/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
from pynput import keyboard
from pynput import mouse


import wx
import wx.adv

from PyInstaller.__main__ import run


TMP_PATH = os.path.join(tempfile.gettempdir(),
"atbswp-" + date.today().strftime("%Y%m%w"))
HEADER = (
Expand Down Expand Up @@ -463,6 +465,48 @@ def action(self, event):
play_thread._stop() # Can be deprecated
toggle_button.Value = False

class CompileCtrl:
@staticmethod
def compile(event):
path = Path(__file__).parent.absolute()
if TMP_PATH is None or not os.path.isfile(TMP_PATH):
wx.LogError("No capture loaded")
return
executable_path = Path(TMP_PATH).parent.absolute()
os.chdir(executable_path)
try:
os.mkdir("dist")
except FileExistsError:
shutil.rmtree("dist", ignore_errors=True)
try:
os.mkdir("build")
except FileExistsError:
shutil.rmtree("build", ignore_errors=True)
dist_dir = os.path.join(executable_path, "dist")
build_dir = os.path.join(executable_path, "build")
run([TMP_PATH, '--onefile', '--noconfirm', '--specpath='+str(executable_path),
'--distpath='+dist_dir, '--workpath='+build_dir, '--icon='])
if platform.system() == "Darwin":
default_file = "capture.app"
elif platform.system() == "Windows":
default_file = "capture.exe"
else:
default_file = "capture"
executable_name = os.listdir(dist_dir)
executable_path = os.path.join(executable_path, "dist", executable_name[0])
with wx.FileDialog(parent=event.GetEventObject().Parent, message="Save capture executable",
defaultDir=os.path.expanduser("~"), defaultFile=default_file, wildcard="*",
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:

if fileDialog.ShowModal() == wx.ID_CANCEL:
return # the user changed their mind
pathname = fileDialog.GetPath()
try:
shutil.copy(executable_path, pathname)
except IOError:
wx.LogError(f"Cannot save current data in file {pathname}.")



class SettingsCtrl:
"""
Expand Down
11 changes: 7 additions & 4 deletions atbswp/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

APP_TEXT = ["Load Capture", "Save", "Start/Stop Capture", "Play",
"Compile to executable", "Preferences", "Help"]
SETTINGS_TEXT = ["Play &Speed: Fast", "&Continuous Playback",
"&Repeat Playback Loops", "Recording &Hotkey",
"&Playback Hotkey", "Always on &Top", "&About",
SETTINGS_TEXT = ["Play &Speed: Fast", "&Continuous Playback",
"Set &Repeat Count", "Recording &Hotkey",
"&Playback Hotkey", "Always on &Top", "&About",
"&Exit"]


Expand Down Expand Up @@ -154,6 +154,9 @@ def __add_bindings(self):
pbc = control.PlayCtrl()
self.Bind(wx.EVT_TOGGLEBUTTON, pbc.action, self.play_button)

# compile_button_ctrl
self.Bind(wx.EVT_BUTTON, control.CompileCtrl.compile, self.compile_button)

# help_button_ctrl
hbc = control.HelpCtrl()
self.Bind(wx.EVT_BUTTON, hbc.action, self.help_button)
Expand Down Expand Up @@ -210,7 +213,7 @@ def on_exit_app(self, event):
def on_close_dialog(self, event):
dialog = wx.MessageDialog(self,
message="Are you sure you want to quit?",
caption="Caption",
caption="Confirm Exit",
style=wx.YES_NO,
pos=wx.DefaultPosition)
response = dialog.ShowModal()
Expand Down
Binary file modified atbswp/img/icon-recording.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 32 additions & 2 deletions atbswp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,39 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Handle the config file of the program

import configparser
import os
import platform


def load_parameters(path):
pass
config = configparser.ConfigParser()


# Check the location of the configuration file, default to the home directory
filename = "atbswp.cfg"
if platform.system() == "Linux":
config_location = os.path.join(os.environ.get("HOME"), ".config")
elif platform.system() == "Windows":
config_location = os.environ.get("APPDATA")
else:
config_location = os.environ.get("HOME")

config_location = os.path.join(config_location, filename)


def save_config():
with open(config_location, "w") as config_file:
config.write(config_file)

try:
with open(config_location) as config_file:
config.read(config_location)
except OSError:
config['DEFAULT'] = {'Play Speed: Fast': False,
'Continuous Playback': False,
'Repeat Count': 1,
'Recording Hotkey': 'F9',
'Playback Hotkey': 'F10',
'Always On Top': False}

0 comments on commit af9dde5

Please sign in to comment.