forked from Marzona/rig-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrig-remote.py
executable file
·162 lines (133 loc) · 5.05 KB
/
rig-remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
"""
Remote application that interacts with rigs using rigctl protocol.
Please refer to:
http://gqrx.dk/
http://gqrx.dk/doc/remote-control
http://sourceforge.net/apps/mediawiki/hamlib/index.php?title=Documentation
Author: Rafael Marmelo <[email protected]>
Author: Simone Marzona <[email protected]>
License: MIT License
Copyright (c) 2014 Rafael Marmelo
Copyright (c) 2015 Simone Marzona
Copyright (c) 2016 Tim Sweeney
"""
# import modules
import argparse
import logging
import os
import time
import textwrap
import Tkinter as tk
from rig_remote.ui import RigRemote
from rig_remote.app_config import AppConfig
from rig_remote.constants import DEFAULT_BOOKMARK_FILENAME
from rig_remote.constants import DEFAULT_CONFIG_FILENAME
from rig_remote.constants import DEFAULT_LOG_FILENAME
from rig_remote.constants import DEFAULT_PREFIX
from rig_remote.utility import process_path
# helper functions
def input_arguments():
"""Argument parser.
"""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(textwrap.fill(
"Rig controller that interacts with a rig using the rigctl protocol.\
")),
epilog="""Please refer to:
https://github.com/Marzona/rig-remote/wiki
http://gqrx.dk/,
http://gqrx.dk/doc/remote-control,
http://sourceforge.net/apps/mediawiki/hamlib/index.php?title=Documentation
Author: Simone Marzona <[email protected]>
Additional features: Tim Sweeney <mainetim@"GEE"mail.com>
License: MIT License
Copyright (c) 2015 Simone Marzona
Copyright (c) 2016 Tim Sweeney""")
parser.add_argument("--bookmarks",
"-b",
type=str,
required=False,
dest="alternate_bookmark_file",
help="Sets the full path for the bookmark file.")
parser.add_argument("--config",
"-c",
type=str,
required=False,
dest="alternate_config_file",
help="Sets the full path for the config file.")
parser.add_argument("--log",
"-l",
type=str,
required=False,
dest="alternate_log_file",
help="Sets the full path for the activity log file.")
parser.add_argument("--prefix",
"-p",
type=str,
required=False,
dest="alternate_prefix",
help="Sets the directory prefix for default working files. " +
"NOTE: Individual path options override this prefix.")
parser.add_argument("--verbose",
"-v",
dest="verbose",
action="store_true",
help="Increase log verbosity.")
return parser.parse_args()
def log_configuration(verbose):
"""Logger configuration: time/date formatting.
"""
os.environ["TZ"] = "UTC"
# Windows doesn't support tzset. Ignore for now.
try:
time.tzset()
except AttributeError:
pass
if verbose:
logging.basicConfig(level=logging.INFO,
format="%(asctime)s %(message)s",
datefmt="%m/%d/%Y %I:%M:%S %p %Z")
else:
logging.basicConfig(level=logging.WARNING,
format="%(asctime)s %(message)s",
datefmt="%m/%d/%Y %I:%M:%S %p %Z")
return logging.getLogger(__name__)
# entry point
if __name__ == "__main__":
args = input_arguments()
logger = log_configuration(args.verbose)
if args.alternate_prefix:
prefix = args.alternate_prefix
dir_prefix = os.path.expanduser(prefix)
else:
dir_prefix = DEFAULT_PREFIX
if args.alternate_config_file:
conf = args.alternate_config_file
config_file = process_path(conf)
else:
config_file = os.path.join(dir_prefix, DEFAULT_CONFIG_FILENAME)
root = tk.Tk()
ac = AppConfig(config_file)
# set bookmarks and log filename in this order:
# use command line alternate path
# use path from config file
# use default path
ac.read_conf()
if args.alternate_bookmark_file != None:
bookmarks = args.alternate_bookmark_file
ac.config['bookmark_filename'] = process_path(bookmarks)
elif ac.config["bookmark_filename"] == None:
ac.config["bookmark_filename"] = os.path.join(dir_prefix, DEFAULT_BOOKMARK_FILENAME)
# set activity log filename
if args.alternate_log_file != None:
log = args.alternate_log_file
ac.config['log_filename'] = process_path(log)
else:
ac.config['log_filename'] = os.path.join(dir_prefix, DEFAULT_LOG_FILENAME)
app = RigRemote(root, ac)
app.apply_config(ac)
app.mainloop()
if app.scan_thread != None :
app.scanning.terminate()