Skip to content

Commit

Permalink
Merge pull request #293 from Codaone/feature-cp-field-changes
Browse files Browse the repository at this point in the history
Bunch of small improvements to the GUI
  • Loading branch information
joelvai authored Aug 29, 2018
2 parents 0d8d47c + 8e1328b commit 17d0dd9
Show file tree
Hide file tree
Showing 8 changed files with 1,778 additions and 74 deletions.
77 changes: 58 additions & 19 deletions dexbot/controllers/strategy_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def values(self):
data = {}
for key, element in self.elements.items():
class_name = element.__class__.__name__
if class_name in ('QDoubleSpinBox', 'QSpinBox', 'QLineEdit'):
if class_name in ('QDoubleSpinBox', 'QSpinBox', 'QLineEdit', 'QSlider'):
data[key] = element.value()
elif class_name == 'QCheckBox':
data[key] = element.isChecked()
Expand All @@ -70,7 +70,8 @@ def elements(self):
QtWidgets.QSpinBox,
QtWidgets.QLineEdit,
QtWidgets.QCheckBox,
QtWidgets.QComboBox
QtWidgets.QComboBox,
QtWidgets.QSlider
)

for option in self.configure:
Expand All @@ -89,24 +90,29 @@ def __init__(self, view, configure, worker_controller, worker_data):
self.view = view
self.configure = configure
self.worker_controller = worker_controller

# Refresh center price market label
self.onchange_asset_labels()

# Refresh center price market label every time the text changes is base or quote asset input fields
worker_controller.view.base_asset_input.textChanged.connect(self.onchange_asset_labels)
worker_controller.view.quote_asset_input.textChanged.connect(self.onchange_asset_labels)

widget = self.view.strategy_widget

# Event connecting
widget.relative_order_size_input.clicked.connect(
self.onchange_relative_order_size_input
)
widget.center_price_dynamic_input.clicked.connect(
self.onchange_center_price_dynamic_input
)
widget.reset_on_partial_fill_input.clicked.connect(
self.onchange_reset_on_partial_fill_input
)
widget.reset_on_price_change_input.clicked.connect(
self.onchange_reset_on_price_change_input
)
widget.custom_expiration_input.clicked.connect(
self.onchange_custom_expiration_input
)
widget.relative_order_size_input.clicked.connect(self.onchange_relative_order_size_input)
widget.center_price_dynamic_input.clicked.connect(self.onchange_center_price_dynamic_input)
widget.manual_offset_input.valueChanged.connect(self.onchange_manual_offset_input)

# QSlider uses (int) values and manual_offset is stored as (float) with 0.1 precision.
# This reverts it so QSlider can handle the number, when fetching from config.
if worker_data:
worker_data['manual_offset'] = worker_data['manual_offset'] * 10

widget.reset_on_partial_fill_input.clicked.connect(self.onchange_reset_on_partial_fill_input)
widget.reset_on_price_change_input.clicked.connect(self.onchange_reset_on_price_change_input)
widget.custom_expiration_input.clicked.connect(self.onchange_custom_expiration_input)

# Trigger the onchange events once
self.onchange_relative_order_size_input(widget.relative_order_size_input.isChecked())
Expand All @@ -115,6 +121,18 @@ def __init__(self, view, configure, worker_controller, worker_data):
self.onchange_reset_on_price_change_input(widget.reset_on_price_change_input.isChecked())
self.onchange_custom_expiration_input(widget.custom_expiration_input.isChecked())

@property
def values(self):
# This turns the int value of manual_offset from QSlider to float with desired precision.
values = super().values
values['manual_offset'] = values['manual_offset'] / 10
return values

def onchange_manual_offset_input(self):
value = self.view.strategy_widget.manual_offset_input.value() / 10
text = "{}%".format(value)
self.view.strategy_widget.manual_offset_amount_label.setText(text)

def onchange_relative_order_size_input(self, checked):
if checked:
self.order_size_input_to_relative()
Expand Down Expand Up @@ -150,6 +168,21 @@ def onchange_custom_expiration_input(self, checked):
else:
self.view.strategy_widget.expiration_time_input.setDisabled(True)

def onchange_asset_labels(self):
base_symbol = self.worker_controller.view.base_asset_input.text()
quote_symbol = self.worker_controller.view.quote_asset_input.text()

if quote_symbol:
self.set_amount_asset_label(quote_symbol)
else:
self.set_amount_asset_label('')

if base_symbol and quote_symbol:
text = '{} / {}'.format(base_symbol, quote_symbol)
self.set_center_price_market_label(text)
else:
self.set_center_price_market_label('')

def order_size_input_to_relative(self):
self.view.strategy_widget.amount_input.setSuffix('%')
self.view.strategy_widget.amount_input.setDecimals(2)
Expand All @@ -161,6 +194,12 @@ def order_size_input_to_static(self):
self.view.strategy_widget.amount_input.setDecimals(8)
self.view.strategy_widget.amount_input.setMaximum(1000000000.000000)

def set_center_price_market_label(self, text):
self.view.strategy_widget.center_price_market_label.setText(text)

def set_amount_asset_label(self, text):
self.view.strategy_widget.amount_input_asset_label.setText(text)

def validation_errors(self):
error_texts = []
if not self.view.strategy_widget.amount_input.value():
Expand All @@ -177,7 +216,7 @@ def __init__(self, view, configure, worker_controller, worker_data):
self.configure = configure
self.worker_controller = worker_controller

worker_controller.view.base_asset_input.editTextChanged.connect(lambda: self.on_value_change())
worker_controller.view.base_asset_input.textChanged.connect(lambda: self.on_value_change())
worker_controller.view.quote_asset_input.textChanged.connect(lambda: self.on_value_change())
widget = self.view.strategy_widget
widget.amount_input.valueChanged.connect(lambda: self.on_value_change())
Expand All @@ -197,7 +236,7 @@ def __init__(self, view, configure, worker_controller, worker_data):

@gui_error
def on_value_change(self):
base_asset = self.worker_controller.view.base_asset_input.currentText()
base_asset = self.worker_controller.view.base_asset_input.text()
quote_asset = self.worker_controller.view.quote_asset_input.text()
try:
market = Market('{}:{}'.format(quote_asset, base_asset))
Expand Down
13 changes: 3 additions & 10 deletions dexbot/controllers/worker_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def strategies(self):
strategies = collections.OrderedDict()
strategies['dexbot.strategies.relative_orders'] = {
'name': 'Relative Orders',
'form_module': ''
'form_module': 'dexbot.views.ui.forms.relative_orders_widget_ui'
}
strategies['dexbot.strategies.staggered_orders'] = {
'name': 'Staggered Orders',
Expand All @@ -45,13 +45,6 @@ def get_strategies(cls):
"""
return cls(None, None, None).strategies

@property
def base_assets(self):
assets = [
'USD', 'OPEN.BTC', 'CNY', 'BTS', 'BTC'
]
return assets

def add_private_key(self, private_key):
wallet = self.bitshares.wallet
try:
Expand Down Expand Up @@ -184,7 +177,7 @@ def validate_account_not_in_use(cls, account):
@gui_error
def validate_form(self):
error_texts = []
base_asset = self.view.base_asset_input.currentText()
base_asset = self.view.base_asset_input.text()
quote_asset = self.view.quote_asset_input.text()
fee_asset = self.view.fee_asset_input.text()
worker_name = self.view.worker_name_input.text()
Expand Down Expand Up @@ -238,7 +231,7 @@ def handle_save(self):
else: # Edit
account = self.view.account_name.text()

base_asset = self.view.base_asset_input.currentText()
base_asset = self.view.base_asset_input.text()
quote_asset = self.view.quote_asset_input.text()
fee_asset = self.view.fee_asset_input.text()
strategy_module = self.view.strategy_input.currentData()
Expand Down
1 change: 0 additions & 1 deletion dexbot/views/create_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(self, bitshares_instance):
strategies = self.controller.strategies
for strategy in strategies:
self.strategy_input.addItem(strategies[strategy]['name'], strategy)
self.base_asset_input.addItems(self.controller.base_assets)

# Generate a name for the worker
self.worker_name = controller.get_unique_worker_name()
Expand Down
3 changes: 1 addition & 2 deletions dexbot/views/edit_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def __init__(self, parent_widget, bitshares_instance, worker_name, config):
index = self.strategy_input.findData(self.controller.get_strategy_module(worker_data))
self.strategy_input.setCurrentIndex(index)
self.worker_name_input.setText(worker_name)
self.base_asset_input.addItem(self.controller.get_base_asset(worker_data))
self.base_asset_input.addItems(self.controller.base_assets)
self.base_asset_input.setText(self.controller.get_base_asset(worker_data))
self.quote_asset_input.setText(self.controller.get_quote_asset(worker_data))
self.fee_asset_input.setText(worker_data.get('fee_asset', 'BTS'))
self.account_name.setText(self.controller.get_account(worker_data))
Expand Down
44 changes: 23 additions & 21 deletions dexbot/views/ui/create_worker_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>428</width>
<height>378</height>
<height>388</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -323,25 +323,6 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="base_asset_input">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>170</width>
<height>0</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QWidget" name="base_asset_wrap" native="true">
<property name="sizePolicy">
Expand Down Expand Up @@ -631,6 +612,28 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="base_asset_input">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>145</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand All @@ -657,7 +660,6 @@
<tabstops>
<tabstop>strategy_input</tabstop>
<tabstop>worker_name_input</tabstop>
<tabstop>base_asset_input</tabstop>
<tabstop>quote_asset_input</tabstop>
<tabstop>fee_asset_input</tabstop>
<tabstop>account_input</tabstop>
Expand Down
43 changes: 23 additions & 20 deletions dexbot/views/ui/edit_worker_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>428</width>
<height>347</height>
<height>351</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -74,25 +74,6 @@
<item row="1" column="1">
<widget class="QLineEdit" name="worker_name_input"/>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="base_asset_input">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>170</width>
<height>0</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="quote_asset_input">
<property name="sizePolicy">
Expand Down Expand Up @@ -398,6 +379,28 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="base_asset_input">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>145</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>145</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading

0 comments on commit 17d0dd9

Please sign in to comment.