import sys
import os.path
import ssl
import urllib.error
import json
from PyQt5.
QtWidgets import
QApplication,
QMainWindow,
QPushButton,
QLineEdit,
QLabel,
QVBoxLayout,
QWidget,
QSystemTrayIcon,
QMenu,
QAction,
QMessageBoxfrom PyQt5.
QtGui import
QIconfrom PyQt5.
QtCore import
QTimerimport shutil
import os
app_path = os.path.dirname(os.path.realpath(__file__))+'/'
def __init__(self):
super().__init__()
self.file_name = 'orders'
# Global variable for source folder
self.source_folder = 'MQL4/Files'
# Global variable for destination folder
self.destination_folder = 'MQL4/Files'
self.source_folder_input.setPlaceholderText('Source folder path')
self.
destination_folder_input = QLineEdit(self
) self.destination_folder_input.setPlaceholderText(
'Destination folder path')
self.start_button.clicked.connect(self.start_stop)
self.
layout.
addWidget(QLabel('Source Folder:')) self.layout.addWidget(self.source_folder_input)
self.
layout.
addWidget(QLabel('Destination Folder:')) self.layout.addWidget(self.destination_folder_input)
self.layout.addWidget(self.start_button)
self.central_widget.setLayout(self.layout)
self.setCentralWidget(self.central_widget)
self.timer.timeout.connect(self.copy_file)
self.tray_icon.activated.connect(self.show)
self.
exit_action = QAction('Exit', self
) self.exit_action.triggered.connect(self.confirm_exit)
self.tray_menu.addAction(self.exit_action)
self.tray_icon.setContextMenu(self.tray_menu)
self.tray_icon.show()
self.setWindowTitle('My Application')
self.
setWindowIcon(QIcon(app_path
+ 'app_icon.png'))
self.paths_file = '.paths.json'
self.load_paths()
def load_paths(self):
if os.path.exists(self.paths_file):
with open(self.paths_file, 'r') as f:
paths = json.load(f)
self.source_folder_input.setText(paths['source'])
self.destination_folder_input.setText(paths['destination'])
def save_paths(self):
paths = {
'source': self.source_folder_input.text(),
'destination': self.destination_folder_input.text()
}
with open(self.paths_file, 'w') as f:
json.dump(paths, f)
def start_stop(self):
if not self.source_folder_input.text() or not self.destination_folder_input.text():
self, 'Input Error', 'Please provide both source and destination folder paths.')
return
self.source_folder = os.path.join(
self.source_folder_input.text(), self.source_folder)
self.destination_folder = os.path.join(
self.destination_folder_input.text(), self.destination_folder)
if not os.path.isdir(self.source_folder) or not os.path.isdir(self.destination_folder):
'Please provide valid directory paths.')
return
if self.timer.isActive():
self.timer.stop()
self.start_button.setText('Start')
self.
tray_icon.
setIcon(QIcon(app_path
+ 'red.png')) else:
self.save_paths()
self.timer.start(1000)
self.start_button.setText('Stop')
self.
tray_icon.
setIcon(QIcon(app_path
+ 'green.png'))
def copy_file(self):
source_file = os.path.join(self.source_folder, self.file_name)
destination_file = os.path.join(
self.destination_folder, self.file_name)
if not os.path.exists(source_file):
with open(source_file, 'w') as f:
f.write(
'Ticket,Time,Symbol,Type,OrderType,Price,Vol,TP,SL,Comment,EXPIRE\n')
if not os.path.exists(destination_file):
with open(destination_file, 'w') as f:
f.write(
'Ticket,Time,Symbol,Type,OrderType,Price,Vol,TP,SL,Comment,EXPIRE\n')
shutil.copy(source_file, destination_file)
def closeEvent(self, event):
if not self.timer.isActive():
event.accept()
else:
event.ignore()
else:
print("heeeerreeee")
event.ignore()
self.hide()
def confirm_exit(self):
self.save_paths()
print(format(reply))
# if reply == QMessageBox.Yes:
# sys.exit()
# print("Im here")
# else:
# print("sssss")
window = MainWindow()
window.setFixedSize(556, 213)
window.show()
sys.exit(app.exec_())
import sys
import os.path
import ssl
import urllib.error
import json
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLineEdit, QLabel, QVBoxLayout, QWidget, QSystemTrayIcon, QMenu, QAction, QMessageBox
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QTimer
import shutil
import os
app_path = os.path.dirname(os.path.realpath(__file__))+'/'
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.file_name = 'orders'
# Global variable for source folder
self.source_folder = 'MQL4/Files'
# Global variable for destination folder
self.destination_folder = 'MQL4/Files'
self.source_folder_input = QLineEdit(self)
self.source_folder_input.setPlaceholderText('Source folder path')
self.destination_folder_input = QLineEdit(self)
self.destination_folder_input.setPlaceholderText(
'Destination folder path')
self.start_button = QPushButton('Start', self)
self.start_button.clicked.connect(self.start_stop)
self.layout = QVBoxLayout()
self.layout.addWidget(QLabel('Source Folder:'))
self.layout.addWidget(self.source_folder_input)
self.layout.addWidget(QLabel('Destination Folder:'))
self.layout.addWidget(self.destination_folder_input)
self.layout.addWidget(self.start_button)
self.central_widget = QWidget()
self.central_widget.setLayout(self.layout)
self.setCentralWidget(self.central_widget)
self.timer = QTimer()
self.timer.timeout.connect(self.copy_file)
self.tray_icon = QSystemTrayIcon(QIcon(app_path + 'red.png'), self)
self.tray_icon.activated.connect(self.show)
self.tray_menu = QMenu()
self.exit_action = QAction('Exit', self)
self.exit_action.triggered.connect(self.confirm_exit)
self.tray_menu.addAction(self.exit_action)
self.tray_icon.setContextMenu(self.tray_menu)
self.tray_icon.show()
self.setWindowTitle('My Application')
self.setWindowIcon(QIcon(app_path + 'app_icon.png'))
self.paths_file = '.paths.json'
self.load_paths()
def load_paths(self):
if os.path.exists(self.paths_file):
with open(self.paths_file, 'r') as f:
paths = json.load(f)
self.source_folder_input.setText(paths['source'])
self.destination_folder_input.setText(paths['destination'])
def save_paths(self):
paths = {
'source': self.source_folder_input.text(),
'destination': self.destination_folder_input.text()
}
with open(self.paths_file, 'w') as f:
json.dump(paths, f)
def start_stop(self):
if not self.source_folder_input.text() or not self.destination_folder_input.text():
QMessageBox.warning(
self, 'Input Error', 'Please provide both source and destination folder paths.')
return
self.source_folder = os.path.join(
self.source_folder_input.text(), self.source_folder)
self.destination_folder = os.path.join(
self.destination_folder_input.text(), self.destination_folder)
if not os.path.isdir(self.source_folder) or not os.path.isdir(self.destination_folder):
QMessageBox.warning(self, 'Directory Error',
'Please provide valid directory paths.')
return
if self.timer.isActive():
self.timer.stop()
self.start_button.setText('Start')
self.tray_icon.setIcon(QIcon(app_path + 'red.png'))
else:
self.save_paths()
self.timer.start(1000)
self.start_button.setText('Stop')
self.tray_icon.setIcon(QIcon(app_path + 'green.png'))
def copy_file(self):
source_file = os.path.join(self.source_folder, self.file_name)
destination_file = os.path.join(
self.destination_folder, self.file_name)
if not os.path.exists(source_file):
with open(source_file, 'w') as f:
f.write(
'Ticket,Time,Symbol,Type,OrderType,Price,Vol,TP,SL,Comment,EXPIRE\n')
if not os.path.exists(destination_file):
with open(destination_file, 'w') as f:
f.write(
'Ticket,Time,Symbol,Type,OrderType,Price,Vol,TP,SL,Comment,EXPIRE\n')
shutil.copy(source_file, destination_file)
def closeEvent(self, event):
if not self.timer.isActive():
reply = QMessageBox.question(
self, 'Exit Confirmation', 'Are you sure you want to exit?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
else:
print("heeeerreeee")
event.ignore()
self.hide()
def confirm_exit(self):
self.save_paths()
reply = QMessageBox.question(
self, 'Exit Confirmation', 'Are you sure you want to exit?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
print(format(reply))
# if reply == QMessageBox.Yes:
# sys.exit()
# print("Im here")
# else:
# print("sssss")
app = QApplication(sys.argv)
window = MainWindow()
window.setFixedSize(556, 213)
window.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks